Changeset 09b290d in ammosreader


Ignore:
Timestamp:
07/01/22 12:53:22 (3 years ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
AmmosSource, guix
Children:
d2f9280
Parents:
577ce87
Message:

respect cycle and offset entry on click on update button

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sample_scripts/ammos_viewer.py

    r577ce87 r09b290d  
    1919        self.file = open(self.file_name, 'rb')
    2020        self.bytes = self.file.read(-1)
    21         self.cycle = self.ammos_container.unique_frame_sizes()[0]
    22         self.cache = 500000000
     21        self.cycle = tk.IntVar()
     22        self.cycle.set(self.ammos_container.unique_frame_sizes()[0])
     23        self.cache = tk.IntVar()
     24        self.cache.set(500000000)
    2325        self.canvas_size = (800, 600)
    24         self.offset = 0
     26        self.offset = tk.IntVar()
     27        self.offset.set(0)
    2528        self.buildup()
    2629
     
    3437        self.canvas = tk.Canvas(image_frame, bg="#000000", width=self.canvas_size[0], height=self.canvas_size[1])
    3538        self.canvas.pack()
    36         # display_size = self.canvas_size[0] * self.canvas_size[1]
    37         # bytes_to_display = randbytes(display_size)
    38         # if len(self.bytes) < display_size:
    39         #    bytes_to_display = self.bytes[self.offset:] + bytearray([0xff] * (display_size-len(self.bytes)-self.offset))
    40         current_bytes = b"".join([self.bytes[each: each+self.canvas_size[0]] for each in range(0, len(self.bytes),
    41                                                                                                self.cycle)])
    42         print("Bytes size", len(current_bytes))
    43         pil_image = Image.frombytes("L", self.canvas_size, current_bytes)
     39        pil_image = Image.frombytes("L", self.canvas_size, self.current_bytes())
    4440        self.image = ImageTk.PhotoImage(pil_image)
    4541        # pil_image.show()
    4642        button_frame = tk.Frame(self)
    47         self.canvas.create_image(0, 0, anchor='nw', image=self.image)
     43        self.image_id = self.canvas.create_image(0, 0, anchor='nw', image=self.image)
    4844        button_frame.pack(side="right")
    4945
    50         tk.Label(button_frame, text='Cycle in bits').pack(side=tk.TOP)
    51         self.cycle_entry = tk.Entry(button_frame)
    52         # self.cycle_entry.set()
     46        tk.Label(button_frame, text='Cycle in bytes').pack(side=tk.TOP)
     47        self.cycle_entry = tk.Entry(button_frame, text=self.cycle)
    5348        self.cycle_entry.pack(side=tk.TOP)
    5449
    5550        tk.Label(button_frame, text='Cache in bytes').pack(side=tk.TOP)
    56         self.cache_entry = tk.Entry(button_frame)
     51        self.cache_entry = tk.Entry(button_frame, text=self.cache)
    5752        self.cache_entry.pack(side=tk.TOP)
    5853
    59         tk.Label(button_frame, text='Offset in bits').pack(side=tk.TOP)
    60         self.offset_entry = tk.Entry(button_frame)
     54        tk.Label(button_frame, text='Offset in bytes').pack(side=tk.TOP)
     55        self.offset_entry = tk.Entry(button_frame, text=self.offset)
    6156        self.offset_entry.pack(side=tk.TOP)
     57
     58        tk.Button(button_frame,
     59                  text="Update",
     60                  width=self.default_button_width,
     61                  command=self.update_canvas).pack(side=tk.TOP, fill=tk.BOTH, expand=True)
    6262
    6363        tk.Button(
     
    7272            width=self.default_button_width,
    7373            command=self.quit).pack(side="top", fill="both", expand=True)
     74
     75    def current_bytes(self):
     76        return b"".join([self.bytes[each: each+self.canvas_size[0]] for each in range(self.offset.get(),
     77                                                                                      len(self.bytes),
     78                                                                                      self.cycle.get())])
     79    def update_canvas(self):
     80        self.image = ImageTk.PhotoImage(Image.frombytes("L", self.canvas_size, self.current_bytes()))
     81        self.canvas.itemconfig(self.image_id, image=self.image)
    7482
    7583    def load_file(self):
Note: See TracChangeset for help on using the changeset viewer.