source: ammosreader/sample_scripts/ammos_viewer.py@ bcacddc

AmmosSource guix
Last change on this file since bcacddc was bcacddc, checked in by Enrico Schwass <ennoausberlin@…>, 3 years ago

initial version of ammos_reader.py added

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[bcacddc]1"""I provide a simple bit viewer specialized for AMMOS files."""
2
3import tkinter as tk
4from PIL import Image, ImageTk
5from random import randbytes
6
7class MainApplication(tk.Frame):
8 """I implement a simple bit viewer specialized for AMMOS files."""
9
10 def __init__(self, parent):
11 """I create the application window."""
12 super().__init__(parent)
13
14 self.parent = parent
15 self.file_name = "../sample_data/audio_data_sample.bin"
16 self.file = open(self.file_name, 'rb')
17 self.bytes = self.file.read(2116*50)
18 self.cycle = 2116
19 self.cache = 500000000
20 self.offset = 0
21 self.buildup()
22
23 def buildup(self):
24 """I build up the initial user interface."""
25 self.parent.title("File name:" + self.file_name + " Size:" + str(len(self.bytes)))
26 self.pack(fill="both", expand=True)
27 self.default_button_width = 10
28 image_frame = tk.Frame(self)
29 image_frame.pack(side=tk.LEFT)
30 self.canvas = tk.Canvas(image_frame, bg="#000000", width=self.cycle, height=600)
31 self.canvas.pack()
32 random_bytes = randbytes(480000)
33 if len(self.bytes) < 480000:
34 random_bytes = self.bytes[self.offset:] + bytearray([0xff] * (480000-len(self.bytes)-self.offset))
35 self.image = ImageTk.PhotoImage(Image.frombytes("L", (self.cycle, int(len(random_bytes) / self.cycle)), random_bytes))
36 # self.image.show()
37 button_frame = tk.Frame(self)
38 self.canvas.create_image(0, 0, anchor='nw', image=self.image)
39 # image_label. = self.image
40 button_frame.pack(side="right")
41
42 tk.Label(button_frame, text='Cycle in bits').pack(side=tk.TOP)
43 self.cycle_entry = tk.Entry(button_frame)
44 # self.cycle_entry.set()
45 self.cycle_entry.pack(side=tk.TOP)
46
47 tk.Label(button_frame, text='Cache in bytes').pack(side=tk.TOP)
48 self.cache_entry = tk.Entry(button_frame)
49 self.cache_entry.pack(side=tk.TOP)
50
51 tk.Label(button_frame, text='Offset in bits').pack(side=tk.TOP)
52 self.offset_entry = tk.Entry(button_frame)
53 self.offset_entry.pack(side=tk.TOP)
54
55 tk.Button(
56 button_frame,
57 text="Load file",
58 width=self.default_button_width,
59 command=self.load_file).pack(side="top", fill="both", expand=True)
60
61 tk.Button(
62 button_frame,
63 text="Quit",
64 width=self.default_button_width,
65 command=self.quit).pack(side="top", fill="both", expand=True)
66
67 def load_file(self):
68 pass
69
70 def quit(self):
71 self.parent.destroy()
72
73
74if __name__ == '__main__':
75 root = tk.Tk()
76 root.geometry("1920x1200")
77
78 app = MainApplication(root)
79
80 root.mainloop()
Note: See TracBrowser for help on using the repository browser.