def _add_toolbar_button(self, image, command_label, accelerator, handler, tester, toolbar_group): slaves = self._toolbar.grid_slaves(0, toolbar_group) if len(slaves) == 0: group_frame = ttk.Frame(self._toolbar) group_frame.grid(row=0, column=toolbar_group, padx=(0, 10)) else: group_frame = slaves[0] button = ttk.Button( group_frame, command=handler, image=image, style="Toolbutton", # TODO: does this cause problems in some Macs? state=tk.NORMAL) button.pack(side=tk.LEFT) button.tester = tester tooltip_text = command_label if accelerator and self.get_option("theme.shortcuts_in_tooltips", True): tooltip_text += " (" + accelerator + ")" create_tooltip( button, tooltip_text, **self.get_option("theme.tooltip_options", { 'padx': 3, 'pady': 1 }))
def add_checkbox( self, flag_name, description, row=None, column=0, padx=0, pady=0, columnspan=1, tooltip=None ): variable = get_workbench().get_variable(flag_name) checkbox = ttk.Checkbutton(self, text=description, variable=variable) checkbox.grid(row=row, column=column, sticky=tk.W, padx=padx, pady=pady, columnspan=columnspan) if tooltip is not None: ui_utils.create_tooltip(checkbox, tooltip)
def create_navigation_link(col, image_filename, action, tooltip, padx=0): button = ttk.Button( toolbar, # command=handler, image=get_workbench().get_image(image_filename), style="ViewToolbar.Toolbutton", # TODO: does this cause problems in some Macs? state=tk.NORMAL, ) ui_utils.create_tooltip(button, tooltip) button.grid(row=0, column=col, sticky=tk.NE, padx=padx, pady=4) button.bind("<Button-1>", action) return button
def _add_toolbar_button(self, image, command_label, accelerator, handler, tester, toolbar_group): slaves = self._toolbar.grid_slaves(0, toolbar_group) if len(slaves) == 0: group_frame = ttk.Frame(self._toolbar) group_frame.grid(row=0, column=toolbar_group, padx=(0, 10)) else: group_frame = slaves[0] button = ttk.Button( group_frame, command=handler, image=image, style="Toolbutton", # TODO: does this cause problems in some Macs? state=tk.NORMAL) button.pack(side=tk.LEFT) button.tester = tester create_tooltip( button, command_label + (" (" + accelerator + ")" if accelerator else ""))
def _apply_io_event(self, data, stream_name, extra_tags=set()): if not data: return original_data = data if re.match(OUTPUT_SPLIT_REGEX, data): if data == "\b": self._change_io_cursor_offset(-1) elif data == "\r": self._change_io_cursor_offset("line") elif data.endswith("D") or data.endswith("C"): self._change_io_cursor_offset_csi(data) elif stream_name == "stdout": # According to https://github.com/tartley/colorama/blob/master/demos/demo04.py # codes sent to stderr shouldn't affect later output in stdout # It makes sense, but Ubuntu terminal does not confirm it. # For now I'm just trimming stderr color codes self._update_ansi_attributes(data) else: tags = extra_tags | {"io", stream_name} if stream_name == "stdout": tags |= self._get_ansi_tags() if len(data) > self._get_squeeze_threshold() and "\n" not in data: self._io_cursor_offset = 0 # ignore the effect of preceding \r and \b button_text = (data[:40] + " …") btn = tk.Label( self, text=button_text, #width=len(button_text), cursor="arrow", borderwidth=2, relief="raised", font="IOFont", ) btn.bind("<1>", lambda e: self._show_squeezed_text(btn), True) btn.contained_text = data btn.tags = tags self._squeeze_buttons.add(btn) create_tooltip( btn, "%d characters squeezed. " % len(data) + "Click for details.") self.window_create("output_insert", window=btn) data = "" elif self._io_cursor_offset < 0: overwrite_len = min(len(data), -self._io_cursor_offset) if 0 <= data.find("\n") < overwrite_len: overwrite_len = data.find("\n") overwrite_data = data[:overwrite_len] self.direct_insert( "output_insert -%d chars" % -self._io_cursor_offset, overwrite_data, tuple(tags)) del_start = self.index("output_insert -%d chars" % -self._io_cursor_offset) del_end = self.index("output_insert -%d chars" % (-self._io_cursor_offset - overwrite_len)) self.direct_delete(del_start, del_end) # compute leftover data to be printed normally data = data[overwrite_len:] if "\n" in data: # cursor offset doesn't apply on new line self._io_cursor_offset = 0 else: # offset becomes closer to 0 self._io_cursor_offset + overwrite_len elif self._io_cursor_offset > 0: # insert spaces before actual data # NB! Print without formatting tags self._insert_text_directly(" " * self._io_cursor_offset, ("io", stream_name)) self._io_cursor_offset = 0 if data: # if any data is still left, then this should be output normally self._insert_text_directly(data, tuple(tags)) self._applied_io_events.append((original_data, stream_name))