def create_menu(self): self.__menu = Menu(self.__root, font=Cfg.get_font_label(), bg=Cfg.get_bg_color(), fg=Cfg.get_font_label_color()) self.__root.config(menu=self.__menu) action_menu = Menu(self.__menu) action_menu.configure(cnf=self.__gui_config) self.__menu.add_cascade(label="Action", menu=action_menu) action_menu.add_command(label="Update", command=self.__update) action_menu.add_separator() action_menu.add_command(label="Exit", command=self.__close_main_window) settings_menu = Menu(self.__menu) settings_menu.configure(cnf=self.__gui_config) self.__menu.add_cascade(label="Settings", menu=settings_menu) settings_menu.add_command(label="Update interval", command=ut_window.UpdateTimeWindow) settings_menu.add_command(label="Max news in frame", command=len_window.LenNewsWindow) settings_menu.add_separator() settings_menu.add_command(label="Colors", command=color_win.SettingsColorWindows) settings_menu.add_command(label="Fonts", command=SelectFontWindow) settings_menu.add_separator() settings_menu.add_command(label="Logfile", command=LoggingWindowParam) help_menu = Menu(self.__menu) help_menu.configure(cnf=self.__gui_config) self.__menu.add_cascade(label="Help", menu=help_menu) help_menu.add_command(label="About", command=about_window.AboutWindow)
def __init__(self): def submit(): Cfg.set_max_len_news_stack(val.get()) win.destroy() gui_cfg = { "bg": Cfg.get_bg_color(), "fg": Cfg.get_font_label_color(), "font": Cfg.get_font_label() } win = tk.Toplevel() win.title("Select max news in frame") win.resizable(False, False) frame = tk.Frame(win, bg=Cfg.get_bg_color(), bd=2, relief=tk.SUNKEN) frame.pack() val = tk.IntVar() tk.Label(frame, text="Select new value to maximum news in frame:", cnf=gui_cfg).pack(fill=tk.BOTH) tk.Entry(frame, justify=tk.CENTER, textvariable=val, cnf=gui_cfg).pack(fill=tk.BOTH) val.set(Cfg.get_max_len_stack()) tk.Button(frame, text="Submit", command=submit, cnf=gui_cfg).pack(fill=tk.BOTH) win.mainloop()
def __init__(self): ut_window = tk.Toplevel() gui_cfg = { "bg": Cfg.get_bg_color(), "fg": Cfg.get_font_label_color(), "font": Cfg.get_font_label() } def close_window(): Cfg.set_time_to_update(v.get()) ut_window.destroy() ut_window.title("Setting time updates") ut_window.resizable(False, False) frame = tk.Frame(ut_window, bg=Cfg.get_bg_color()) frame.pack() tk.Label(frame, text="Select time:", cnf=gui_cfg).pack() v = tk.IntVar() for txt, num in update_intervals(): tk.Radiobutton(frame, text=txt, variable=v, value=num, cnf=gui_cfg).pack() v.set(5 * 60 * 1000) bt = tk.Button(ut_window, text="Submit", cnf=gui_cfg, command=close_window) bt.pack() ut_window.mainloop()
def showtip(self): x = y = 0 try: x, y, cx, cy = self.widget.bbox("insert") except TypeError: logging.error( "Type Error Exception. Tkinter ToolTip object not iterable") try: x += self.widget.winfo_rootx() + delta_x() y += self.widget.winfo_rooty() + delta_y() self.tw = tk.Toplevel(self.widget) self.tw.wm_overrideredirect(True) self.tw.wm_geometry("+%d+%d" % (x, y)) label = tk.Label(self.tw, text=self.text, justify='left', background=Cfg.get_tool_tip_bg(), relief='solid', borderwidth=1, wraplength=self.wraplength, fg=Cfg.get_tool_tip_font_color(), font=Cfg.get_font_label()) label.pack(ipadx=1) except tk.TclError: logging.error("Except in create tooltip window")
def __init__(self, widget, text='widget info'): self.waittime = Cfg.get_waittime_tooltip() # miliseconds self.wraplength = Cfg.get_wraplength_tool_tip() # pixels self.widget = widget self.text = text self.widget.bind("<Enter>", self.enter) self.widget.bind("<Leave>", self.leave) self.widget.bind("<ButtonPress>", self.leave) self.id = None self.tw = None
def __init__(self): font = askfont() if font: param = [ 'bold' if font['weight'] == 'bold' else "", 'italic' if font['slant'] == 'italic' else "", 'underline' if font['underline'] != 0 else "", 'overstrike' if font['overstrike'] != 0 else "" ] Cfg.set_font_label(font["family"], font["size"], " ".join(param)) GuiSignals.set_update_gui_menu_flag() else: logging.error("Error in window set font")
def __init__(self): if MainGui.__instance is None: MainGui.__instance = self self.__cfg = Cfg() if self.__active_frame == news(): self.__lor = LOR_news() elif self.__active_frame == tracker(): self.__lor = LOR_track() else: pass self.create_gui_config() self.create_frame_config() self.__root = Tk() self.__root.title(self.__lor.resource_name()) self.__root.resizable(False, False) self.create_menu() self.__print_news() self.__root.protocol("WM_DELETE_WINDOW", self.__close_main_window) self.__root.mainloop() else: pass
def __get_tracker(self): self.__topicks = [] req = requests.get(self.__server_name + "/tracker/") data = bs4.BeautifulSoup(req.text, "html.parser") all_msgs = str(data.select(".forum")[0]) ind = all_msgs.index("<tbody>") + len("<tbody>") all_msgs = all_msgs[ind:] threads = [] while "<tr>" in all_msgs: ind = all_msgs.index("<tr>") all_msgs = all_msgs[ind + len("<tr>"):] ind = all_msgs.index("</tr>") tmp = all_msgs[:ind] ind0 = tmp.index("</a></td>") tmp = tmp[ind0 + len("</a></td>"):] ind1 = tmp.index("<a href=") ind2 = tmp[ind1:].index(">") link = self.__server_name + tmp[ind1 + len("<a href=") + 1:ind1 + ind2 - 1].strip() ind4 = tmp.index("</a>") ind3 = ind4 - 1 while tmp[ind3] != ">": ind3 -= 1 title = tmp[ind3 + 1:ind4].strip() threads.append(urlreader.TopicFromTracker(title, link)) threads[-1].start() for elem in threads: self.__topicks.append(elem.join()) if len(self.__topicks) > Cfg.get_max_len_stack(): self.__topicks = self.__topicks[:Cfg.get_max_len_stack()]
def __init__(self): def submit(): Cfg.set_backup_count(val_bac.get()) Cfg.update_handler() win.destroy() gui_cfg = { "bg": Cfg.get_bg_color(), "fg": Cfg.get_font_label_color(), "font": Cfg.get_font_label() } frame_cfg = {"bg": Cfg.get_bg_color(), "relief": tk.SUNKEN, "bd": 2} win = tk.Toplevel() win.configure(background=Cfg.get_bg_color()) win.resizable(False, False) frame1 = tk.Frame(win, cnf=frame_cfg) label1 = tk.Label(frame1, cnf=gui_cfg, text="Select the number of backups:") label1.pack(fill=tk.BOTH) val_bac = tk.IntVar() frame2 = tk.Frame(win, cnf=frame_cfg) ent1 = tk.Entry(frame2, cnf=gui_cfg, justify=tk.CENTER, textvariable=val_bac) val_bac.set(Cfg.get_backup_count()) ent1.pack(fill=tk.BOTH) frame3 = tk.Frame(win, cnf=frame_cfg) but1 = tk.Button(frame3, cnf=gui_cfg, text="Submit", command=submit) but1.pack(fill=tk.BOTH) frame1.pack(fill=tk.BOTH) frame2.pack(fill=tk.BOTH) frame3.pack(fill=tk.BOTH) win.mainloop()
def __print_news(self): if self.__active_frame == news(): logging.info("Update news database") elif self.__active_frame == tracker(): logging.info("Update tracking info") else: pass def __leftclick(s): tmp = s.widget.get(1.0, END) tmp = tmp[:len(tmp) - 1] for news_top in self.__lor: if news_top.title() == tmp: webbrowser.open_new_tab(news_top.link()) break self.__root.configure(background=Cfg.get_bg_color()) self.__load_news() self.__main_frames = [] self.__labels = [] self.__ttp = [] mll = self.__max_len_label() self.__main_frames.append(Frame(self.__root, cnf=self.__frame_config)) frame_left = Frame(self.__main_frames[0], cnf=self.__frame_config) frame_right = Frame(self.__main_frames[0], cnf=self.__frame_config) btn1 = Button(frame_left, text=self.title_button(news()), command=self.__set_news_frame, cnf=self.__gui_config) btn2 = Button(frame_right, text=self.title_button(tracker()), command=self.__set_tracker_frame, cnf=self.__gui_config) frame_left.pack(fill=BOTH, side=LEFT) frame_right.pack(fill=BOTH, side=LEFT) btn1.pack(fill=BOTH) btn2.pack(fill=BOTH) for new_top in self.__lor: self.__main_frames.append(Frame(self.__root, cnf=self.__frame_config)) self.__labels.append(Text(self.__main_frames[-1], width=mll, height=2, cursor="hand2")) self.__labels[-1].configure(cnf=self.__gui_config) self.__labels[-1].tag_configure(centred(), justify="center") self.__labels[-1].insert(1.0, new_top.title()) self.__labels[-1].tag_add(centred(), 1.0, END) self.__labels[-1].bind('<Button-1>', __leftclick) self.__ttp.append(ctp.CreateToolTip(self.__labels[-1], new_top.text())) for frame in self.__main_frames: frame.pack() for label in self.__labels: label.pack() self.__current_after = self.__root.after(self.__cfg.get_time_to_update(), self.__update)
def create_frame_config(self): self.__frame_config = {"bg": Cfg.get_bg_color(), "bd": 2, "relief": SUNKEN}
def create_gui_config(self): self.__gui_config = {"bg": Cfg.get_bg_color(), "fg": Cfg.get_font_label_color(), "font": Cfg.get_font_label()}
class MainGui: __instance = None __cfg = None __lor = None __root = None __main_frames = [] __labels = [] __ttp = [] __active_frame = news() __gui_config = {} __frame_config = {} __menu = None __current_after = None def title_button(self, s): return s.upper() if s == self.__active_frame else s[0].upper() + s[1:] def __close_main_window(self): logging.info("Terminate run LOR viewer") self.__root.destroy() def __init__(self): if MainGui.__instance is None: MainGui.__instance = self self.__cfg = Cfg() if self.__active_frame == news(): self.__lor = LOR_news() elif self.__active_frame == tracker(): self.__lor = LOR_track() else: pass self.create_gui_config() self.create_frame_config() self.__root = Tk() self.__root.title(self.__lor.resource_name()) self.__root.resizable(False, False) self.create_menu() self.__print_news() self.__root.protocol("WM_DELETE_WINDOW", self.__close_main_window) self.__root.mainloop() else: pass def __load_news(self): if self.__active_frame == news(): return self.__lor.get_news() elif self.__active_frame == tracker(): return self.__lor.get_tracker() else: pass def __max_len_label(self): max_chars = max(len(new_top.title()) for new_top in self.__lor) max_chars = min_width() if max_chars < min_width() else \ (max_chars % max_width() + max_width() if max_chars > max_width() else max_chars) return max_chars @staticmethod def __open_link(link): logging.info("Open new link in webbrowser : " + str(link)) webbrowser.open_new_tab(link) def __print_news(self): if self.__active_frame == news(): logging.info("Update news database") elif self.__active_frame == tracker(): logging.info("Update tracking info") else: pass def __leftclick(s): tmp = s.widget.get(1.0, END) tmp = tmp[:len(tmp) - 1] for news_top in self.__lor: if news_top.title() == tmp: webbrowser.open_new_tab(news_top.link()) break self.__root.configure(background=Cfg.get_bg_color()) self.__load_news() self.__main_frames = [] self.__labels = [] self.__ttp = [] mll = self.__max_len_label() self.__main_frames.append(Frame(self.__root, cnf=self.__frame_config)) frame_left = Frame(self.__main_frames[0], cnf=self.__frame_config) frame_right = Frame(self.__main_frames[0], cnf=self.__frame_config) btn1 = Button(frame_left, text=self.title_button(news()), command=self.__set_news_frame, cnf=self.__gui_config) btn2 = Button(frame_right, text=self.title_button(tracker()), command=self.__set_tracker_frame, cnf=self.__gui_config) frame_left.pack(fill=BOTH, side=LEFT) frame_right.pack(fill=BOTH, side=LEFT) btn1.pack(fill=BOTH) btn2.pack(fill=BOTH) for new_top in self.__lor: self.__main_frames.append(Frame(self.__root, cnf=self.__frame_config)) self.__labels.append(Text(self.__main_frames[-1], width=mll, height=2, cursor="hand2")) self.__labels[-1].configure(cnf=self.__gui_config) self.__labels[-1].tag_configure(centred(), justify="center") self.__labels[-1].insert(1.0, new_top.title()) self.__labels[-1].tag_add(centred(), 1.0, END) self.__labels[-1].bind('<Button-1>', __leftclick) self.__ttp.append(ctp.CreateToolTip(self.__labels[-1], new_top.text())) for frame in self.__main_frames: frame.pack() for label in self.__labels: label.pack() self.__current_after = self.__root.after(self.__cfg.get_time_to_update(), self.__update) def __update(self): if not (self.__current_after is None): self.__root.after_cancel(self.__current_after) for frame in self.__main_frames: frame.destroy() self.create_frame_config() self.create_gui_config() if GuiSignals.update_gui_menu_flag(): self.__menu.destroy() self.create_menu() GuiSignals.set_update_gui_menu_flag(False) self.__print_news() def __set_news_frame(self): self.__active_frame = news() self.__root.title(LOR_news.resource_name()) self.__lor = LOR_news() self.__update() def __set_tracker_frame(self): self.__active_frame = tracker() self.__root.title(LOR_track.resource_name()) self.__lor = LOR_track() self.__update() def create_gui_config(self): self.__gui_config = {"bg": Cfg.get_bg_color(), "fg": Cfg.get_font_label_color(), "font": Cfg.get_font_label()} def create_menu(self): self.__menu = Menu(self.__root, font=Cfg.get_font_label(), bg=Cfg.get_bg_color(), fg=Cfg.get_font_label_color()) self.__root.config(menu=self.__menu) action_menu = Menu(self.__menu) action_menu.configure(cnf=self.__gui_config) self.__menu.add_cascade(label="Action", menu=action_menu) action_menu.add_command(label="Update", command=self.__update) action_menu.add_separator() action_menu.add_command(label="Exit", command=self.__close_main_window) settings_menu = Menu(self.__menu) settings_menu.configure(cnf=self.__gui_config) self.__menu.add_cascade(label="Settings", menu=settings_menu) settings_menu.add_command(label="Update interval", command=ut_window.UpdateTimeWindow) settings_menu.add_command(label="Max news in frame", command=len_window.LenNewsWindow) settings_menu.add_separator() settings_menu.add_command(label="Colors", command=color_win.SettingsColorWindows) settings_menu.add_command(label="Fonts", command=SelectFontWindow) settings_menu.add_separator() settings_menu.add_command(label="Logfile", command=LoggingWindowParam) help_menu = Menu(self.__menu) help_menu.configure(cnf=self.__gui_config) self.__menu.add_cascade(label="Help", menu=help_menu) help_menu.add_command(label="About", command=about_window.AboutWindow) def create_frame_config(self): self.__frame_config = {"bg": Cfg.get_bg_color(), "bd": 2, "relief": SUNKEN}
def submit(): Cfg.set_max_len_news_stack(val.get()) win.destroy()
def submit(): Cfg.set_backup_count(val_bac.get()) Cfg.update_handler() win.destroy()
def close_window(): Cfg.set_time_to_update(v.get()) ut_window.destroy()