def reset_connection(com_socket, window, text1, text2): """ Resets all variables and closes given socket. Updates GUI to respond to connection loss. Returns a fresh socket that can be used to connect to ls. """ if runtime_info["timer_running"]: runtime_info["timer_running"] = False runtime_info["active_split"] = -1 runtime_info["ls_connected"] = False update_icon(False, window) update_GUI(window, com_socket, text1, text2) # Close old and return a fresh socket con.close_socket(com_socket) return con.init_socket()
def init_UI(root): """Draws default UI and creates event bindings.""" # Create communication socket com_socket = con.init_socket() # Load Settings settings = setting_handler.load_settings() runtime_info["server_port"] = int(settings["server_port"]) runtime_info["settings"] = settings # Graphical components root.geometry(settings["width"] + "x" + settings["height"]) box1 = tkinter.Frame(root) box2 = tkinter.Frame(root) scroll1 = tkinter.Scrollbar(box1, width=config.SCROLLBAR_WIDTH) scroll2 = tkinter.Scrollbar(box2, width=config.SCROLLBAR_WIDTH) scroll1.pack(side=tkinter.RIGHT, fill=tkinter.Y) scroll2.pack(side=tkinter.RIGHT, fill=tkinter.Y) text1 = tkinter.Text(box1, yscrollcommand=scroll1.set, wrap=tkinter.WORD, cursor="arrow") text1.insert(tkinter.END, config.DEFAULT_MSG) text1.config(state=tkinter.DISABLED) text1.pack(fill=tkinter.BOTH, expand=True) text2 = tkinter.Text(box2, yscrollcommand=scroll2.set, wrap=tkinter.WORD, cursor="arrow") text2.insert(tkinter.END, config.DEFAULT_MSG) text2.config(state=tkinter.DISABLED) text2.pack(fill=tkinter.BOTH, expand=True) scroll1.config(command=text1.yview) scroll2.config(command=text2.yview) # Set font and color for text text_font = (settings["font"], int(settings["font_size"])) text1.config(font=text_font) text2.config(font=text_font) text1.config(fg=settings["text_color"], bg=settings["background_color"]) text2.config(fg=settings["text_color"], bg=settings["background_color"]) if setting_handler.decode_boolean_setting(settings["double_layout"]): set_double_layout(root, box1, box2) else: set_single_layout(root, box1, box2) # create popup menu popup = tkinter.Menu(root, tearoff=0) popup.add_command( label=config.MENU_OPTIONS["LOAD"], command=(lambda: menu_load_notes(root, text1, text2, com_socket))) popup.add_command(label=config.MENU_OPTIONS["SETTINGS"], command=(lambda: menu_open_settings( root, box1, box2, text1, text2, com_socket))) # Set default window icon and title root.tk.call('wm', 'iconphoto', root._w, red_icon) update_title(config.DEFAULT_WINDOW["TITLE"], root) # Check if notes can be loaded from settings settings = setting_handler.load_settings() if settings["notes"] and noter.file_exists(settings["notes"]): notes = noter.get_notes(settings["notes"], settings["separator"]) if notes: runtime_info["notes"] = notes update_GUI(root, com_socket, text1, text2) # Event binds root.bind("<Configure>", (lambda e: adjust_content(root, box1, box2))) root.bind("<Button-3>", (lambda e: show_popup(e, popup))) root.bind("<Right>", (lambda e: right_arrow(root, com_socket, text1, text2))) root.bind("<Left>", (lambda e: left_arrow(root, com_socket, text1, text2))) # Window close bind root.protocol("WM_DELETE_WINDOW", (lambda: do_on_close(root))) # call update loop update(root, com_socket, text1, text2) root.geometry(settings["width"] + "x" + settings["height"])
def init_UI(root): """Draws default UI and creates event bindings.""" # Create communication socket com_socket = con.init_socket() # Load Settings settings = setting_handler.load_settings() runtime_info["server_port"] = int(settings["server_port"]) runtime_info["settings"] = settings # Graphical components root.geometry(settings["width"] + "x" + settings["height"]) box1 = tkinter.Frame(root) box2 = tkinter.Frame(root) scroll1 = tkinter.Scrollbar(box1, width=config.SCROLLBAR_WIDTH) scroll2 = tkinter.Scrollbar(box2, width=config.SCROLLBAR_WIDTH) scroll1.pack(side=tkinter.RIGHT, fill=tkinter.Y) scroll2.pack(side=tkinter.RIGHT, fill=tkinter.Y) text1 = tkinter.Text( box1, yscrollcommand=scroll1.set, wrap=tkinter.WORD, cursor="arrow" ) text1.insert(tkinter.END, config.DEFAULT_MSG) text1.config(state=tkinter.DISABLED) text1.pack(fill=tkinter.BOTH, expand=True) text2 = tkinter.Text( box2, yscrollcommand=scroll2.set, wrap=tkinter.WORD, cursor="arrow" ) text2.insert(tkinter.END, config.DEFAULT_MSG) text2.config(state=tkinter.DISABLED) text2.pack(fill=tkinter.BOTH, expand=True) scroll1.config(command=text1.yview) scroll2.config(command=text2.yview) # Set font and color for text text_font = (settings["font"], int(settings["font_size"])) text1.config(font=text_font) text2.config(font=text_font) text1.config(fg=settings["text_color"], bg=settings["background_color"]) text2.config(fg=settings["text_color"], bg=settings["background_color"]) if setting_handler.decode_boolean_setting(settings["double_layout"]): set_double_layout(root, box1, box2) else: set_single_layout(root, box1, box2) # create popup menu popup = tkinter.Menu(root, tearoff=0) popup.add_command( label=config.MENU_OPTIONS["LOAD"], command=(lambda: menu_load_notes(root, text1, text2, com_socket)) ) popup.add_command( label=config.MENU_OPTIONS["SETTINGS"], command=(lambda: menu_open_settings(root, box1, box2, text1, text2, com_socket)) ) # Set default window icon and title root.tk.call('wm', 'iconphoto', root._w, red_icon) update_title(config.DEFAULT_WINDOW["TITLE"], root) # Check if notes can be loaded from settings settings = setting_handler.load_settings() if settings["notes"] and noter.file_exists(settings["notes"]): notes = noter.get_notes(settings["notes"], settings["separator"]) if notes: runtime_info["notes"] = notes update_GUI(root, com_socket, text1, text2) # Event binds root.bind("<Configure>", (lambda e: adjust_content(root, box1, box2))) root.bind("<Button-3>", (lambda e: show_popup(e, popup))) root.bind("<Right>", (lambda e: right_arrow(root, com_socket, text1, text2))) root.bind("<Left>", (lambda e: left_arrow(root, com_socket, text1, text2))) # Window close bind root.protocol("WM_DELETE_WINDOW", (lambda: do_on_close(root))) # call update loop update(root, com_socket, text1, text2) root.geometry(settings["width"] + "x" + settings["height"])