def __loop(self): try: self.__window = tk.Tk() self.__main = tk.Frame(self.__window) except tk.TclError as e: eprint(e) self.__app_q.put(Msg(Type.CLOSE)) return setup_window(self.__window, self.__gen_title(), self.__cfg, self.__on_closing) self.__set_geometry() self.__create_widgets() self.__order_widgets() self.__colors.set_widget(self.__window) self.__state_machine = WindowStateMachine( self.__menu_items, self.__menu, self.__dirb, self.__openb, self.__open_settingsb, self.__saveb, self.__save_delb, self.__startb, self.__stopb, self.__progressbar, self.__elapsede, self.__lefte, self.__set_state) while self.__window_q_processor(): self.__state_machine.step() self.__window.update_idletasks() self.__window.update()
def __write(self): """ Overwrite the entire configuration """ try: with open(self.__cfg_file, 'w') as config: for key, value in self.__cfg.items(): config.write("{}={}\n".format(key, value)) except IOError as e: eprint(e)
def __read(self): """ Read the entire configuration """ try: with open(self.__cfg_file) as config: for line in config: key, value = tuple(line.split('=')) self.__cfg[key] = "".join(value.split()) except IOError as e: eprint(e)
def set_window_icon(window, cfg): icon_path = cfg.get("icon") if icon_path is not None and os.path.isfile(icon_path): try: img = ImageTk.PhotoImage(file=icon_path) # window._w is where the image is stored! It is freed up otherwise window.tk.call('wm', 'iconphoto', window._w, img) except tk.TclError as e: eprint(e) else: eprint("ERROR: Cannot open icon file: '{}'!".format(icon_path))
def __save_output(self): try: out = tk.filedialog.asksaveasfile( defaultextension=".avi", filetypes=[(self.__lang.text("file-types"), "*.avi")]) if out: if ' ' in out.name: self.__set_state("err-space-in-path") else: self.__set_state() self.__savee.set_path(out.name) self.__app_q.put(Msg(Type.OUTPUT_FILE, out.name)) self.__state_machine.notify(WindowEvent.OUTPUT_AVAIL) except IOError as err: eprint(err) self.__savee.set_path() self.__state_machine.notify(WindowEvent.OUTPUT_PERMISSION_ERROR)
def __load_logo(self): logo_path = self.__cfg.get("logo") if logo_path is not None and os.path.isfile(logo_path): try: logo_image = Image.open(logo_path) except tk.TclError as e: eprint(e) return else: eprint("ERROR: Cannot open logo file: '{}'!".format(logo_path)) return lh = 64 lw = int(lh * (logo_image.size[0] / logo_image.size[1])) logo_image = logo_image.resize((lw, lh), Image.ANTIALIAS) logo = ImageTk.PhotoImage(logo_image) self.__logo_canvas = tk.Label(self.__main, image=logo) self.__logo_canvas.image = logo