def __init__(self): super(Application, self).__init__() self.title("Blu-res v0.0.1") self.iconbitmap("data/br.ico") self.config(menu=self.generate_menu(self, self.menudata)) self.bind_bindings() self.avisynth = AvisynthThread(self) self.after(1, self.check_x32) self.editor = None self.filename = None
class Application(Tk, object): menudata = [ ("File", [ ("Open Video", ("open_avs", ("Ctrl-O", "<Control-o>"))), ("Detect Resolution", ("detect_res", ("F1", "<F1>"))), None, ("Exit", ("quit", ("Alt-F4", None))), ]), ("Help", [ ("About", ("open_about", None)), ]) ] bindings = { } def __init__(self): super(Application, self).__init__() self.title("Blu-res v0.0.1") self.iconbitmap("data/br.ico") self.config(menu=self.generate_menu(self, self.menudata)) self.bind_bindings() self.avisynth = AvisynthThread(self) self.after(1, self.check_x32) self.editor = None self.filename = None def check_x32(self): if sys.maxsize > 2**32: showerror("Invalid Python Version", "You need to use a 32-bit python version to run this program.") self.destroy() print("Running x32") self.after(1, self.run_avisynth) def run_avisynth(self): self.avisynth.start() def bind_bindings(self): for event, funcs in self.bindings.items(): for func in funcs: self.bind(event, getattr(self, func)) def generate_menu(self, parent, menu): """ Generates the menu for the gui. :param parent: The parent object. :param menu: The menu. :return: A menu. """ result = Menu(parent, tearoff=False) for item in menu: if item is None: result.add_separator() continue title, data = item if isinstance(data, list): result.add_cascade(label=title, menu=self.generate_menu(result, data)) elif isinstance(data, tuple): func = getattr(self, data[0]) if data[1] is not None: result.add_command(label=title, command=func, accelerator=data[1][0]) if data[1][1] is not None: self.bind_all(data[1][1], func) else: result.add_command(label=title, command=func) return result def open_avs(self, event=None): self.filename = askopenfilename(parent=self, title="Open video file") if not self.filename: return if self.editor is not None: self.editor.pack_forget() self.editor = VideoViewer(self.avisynth, self, self.filename) self.editor.pack(fill=BOTH, expand=1) def open_about(self): showinfo(title="About", message="Blu-res by stux!\nIdea by Ninelpinel", parent=self) def detect_res(self, event=None): if self.editor is None: return Autodetector(self, self.filename, lambda:[int(float(self.editor.frame_chooser.get()))]) def open_tab(self, tester, height): self.editor.open_tab(tester, height) def quit(self): self.destroy()