def listener(msgList: tkinter.Text, s: socket, clientEncryptor: PKCS1OAEP_Cipher): while True: if s.fileno() == -1: # socket closed break r, _, _ = select.select([s], [], []) for rs in r: if s == rs: try: data = rs.recv(4096) except OSError: # connection terminated (for some reason) break if not data: break msg = clientEncryptor.decrypt(data) msg = pickle.loads(msg) if msg[0]: message = "<SERVER>: " + msg[3] else: message = msg[2] + ": " + msg[3] msgList.tag_config(str(msg[1]), foreground=str(msg[1])) msgList.config(state=tkinter.NORMAL) msgList.insert(tkinter.END, message + '\n', str(msg[1])) msgList.config(state=tkinter.DISABLED)
def __init__(self, widget: tk.Text, level=logging.NOTSET): self.widget = widget super().__init__(level) # Assign colours for each logging level for level, colour in LVL_COLOURS.items(): widget.tag_config( logging.getLevelName(level), foreground=colour, # For multi-line messages, indent this much. lmargin2=30, ) widget.tag_config( logging.getLevelName(logging.CRITICAL), background='red', ) # If multi-line messages contain carriage returns, lmargin2 doesn't # work. Add an additional tag for that. widget.tag_config( 'INDENT', lmargin1=30, lmargin2=30, ) self.has_text = False widget['state'] = "disabled"
def __init__(self, widget: tk.Text, level=logging.NOTSET): self.widget = widget super().__init__(level) # Assign colours for each logging level for level, colour in LVL_COLOURS.items(): widget.tag_config( logging.getLevelName(level), foreground=colour, # For multi-line messages, indent this much. lmargin2=30, ) widget.tag_config( logging.getLevelName(logging.CRITICAL), background='red', ) # If multi-line messages contain carriage returns, lmargin2 doesn't # work. Add an additional tag for that. widget.tag_config( 'INDENT', lmargin1=30, lmargin2=30, ) widget['state'] = "disabled"
def __init__( self, textwidget: tkinter.Text, start_lineno: int, middle_lineno: int, end_lineno: int ) -> None: self.textwidget = textwidget n = next(tag_counter) self.part1_tag = f"merge_conflict_{n}_part1" self.middle_tag = f"merge_conflict_{n}_middle" self.part2_tag = f"merge_conflict_{n}_part2" part1_color = utils.mix_colors(self.textwidget["bg"], "magenta", 0.8) manual_color = utils.mix_colors(self.textwidget["bg"], "tomato", 0.8) part2_color = utils.mix_colors(self.textwidget["bg"], "cyan", 0.8) # TODO: also specify fg color self.part1_button = self.make_button( start_lineno, part1_color, text="Use this", command=self.use_part1 ) self.manual_button = self.make_button( middle_lineno, manual_color, text="Edit manually", command=self.stop_displaying ) self.part2_button = self.make_button( end_lineno, part2_color, text="Use this", command=self.use_part2 ) textwidget.tag_config(self.part1_tag, background=part1_color) textwidget.tag_config(self.middle_tag, background=manual_color) textwidget.tag_config(self.part2_tag, background=part2_color) textwidget.tag_lower(self.part1_tag, "sel") textwidget.tag_lower(self.middle_tag, "sel") textwidget.tag_lower(self.part2_tag, "sel") textwidget.tag_add(self.part1_tag, f"{start_lineno}.0", f"{middle_lineno}.0") textwidget.tag_add(self.middle_tag, f"{middle_lineno}.0", f"{middle_lineno + 1}.0") textwidget.tag_add(self.part2_tag, f"{middle_lineno + 1}.0", f"{end_lineno + 1}.0") self._stopped = False
def on_pygments_theme_changed(text: tkinter.Text, fg: str, bg: str) -> None: # use a custom background with a little bit of the theme's foreground mixed in text.tag_config('matching_paren', background=mix_colors(fg, bg, 0.2))
def __init__(self, parent: tkinter.Tk, textwidget: tkinter.Text, **kwargs: Any) -> None: super().__init__(parent, **kwargs) # type: ignore self._textwidget = textwidget # grid layout: # column 0 column 1 column 2 column 3 # ,---------------------------------------------------------------. # row0| Find: | text entry | | [x] Full words only | # |---------------|---------------|-------|-----------------------| # row1| Replace with: | text entry | | [x] Ignore case | # |---------------------------------------------------------------| # row2| button frame, this thing contains a bunch of buttons | # |---------------------------------------------------------------| # row3| status label with useful-ish text | # |---------------------------------------------------------------| # row4| separator | # `---------------------------------------------------------------' # # note that column 2 is used just for spacing, the separator helps # distinguish this from e.g. status bar below this self.grid_columnconfigure(2, minsize=30) self.grid_columnconfigure(3, weight=1) # TODO: use the pygments theme somehow? textwidget.tag_config('find_highlight', foreground='black', background='yellow') self._textwidget.tag_lower('find_highlight', 'sel') self.find_entry = self._add_entry(0, "Find:") find_var = tkinter.StringVar() self.find_entry.config(textvariable=find_var) find_var.trace_add('write', self.highlight_all_matches) # because cpython gc cast(Any, self.find_entry).lol = find_var self.replace_entry = self._add_entry(1, "Replace with:") self.find_entry.bind('<Shift-Return>', self._go_to_previous_match, add=True) self.find_entry.bind('<Return>', self._go_to_next_match, add=True) # commented out because pressing tab in self.find_entry unselects the # text in textwidget for some reason #self.replace_entry.bind('<Return>', self._replace_this) buttonframe = ttk.Frame(self) buttonframe.grid(row=2, column=0, columnspan=4, sticky='we') self.previous_button = ttk.Button(buttonframe, text="Previous match", command=self._go_to_previous_match) self.next_button = ttk.Button(buttonframe, text="Next match", command=self._go_to_next_match) self.replace_this_button = ttk.Button(buttonframe, text="Replace this match", command=self._replace_this) self.replace_all_button = ttk.Button(buttonframe, text="Replace all", command=self._replace_all) self.previous_button.pack(side='left') self.next_button.pack(side='left') self.replace_this_button.pack(side='left') self.replace_all_button.pack(side='left') self._update_buttons() self.full_words_var = tkinter.BooleanVar() self.full_words_var.trace_add('write', self.highlight_all_matches) self.ignore_case_var = tkinter.BooleanVar() self.ignore_case_var.trace_add('write', self.highlight_all_matches) # TODO: add keyboard shortcut for "Full words only". I use it all the # time and reaching mouse is annoying. Tabbing through everything # is also annoying. ttk.Checkbutton(self, text="Full words only", variable=self.full_words_var).grid(row=0, column=3, sticky='w') ttk.Checkbutton(self, text="Ignore case", variable=self.ignore_case_var).grid(row=1, column=3, sticky='w') self.statuslabel = ttk.Label(self) self.statuslabel.grid(row=3, column=0, columnspan=4, sticky='we') ttk.Separator(self, orient='horizontal').grid(row=4, column=0, columnspan=4, sticky='we') closebutton = ttk.Label(self, cursor='hand2') closebutton.place(relx=1, rely=0, anchor='ne') closebutton.bind('<Button-1>', self.hide, add=True) closebutton.config(image=images.get('closebutton')) # explained in test_find_plugin.py textwidget.bind('<<Selection>>', self._update_buttons, add=True)