def _treeview_settings() -> BasicUiThemeSettings: light_blue = "#ADD8E6" light_grey = "#D3D3D3" if running_on_linux() or running_on_mac_os(): bg_sel_focus = light_blue fg_sel_focus = "black" fg_sel_notfocus = "black" else: bg_sel_focus = "SystemHighlight" fg_sel_focus = "SystemHighlightText" fg_sel_notfocus = "SystemWindowText" return { "Treeview": { "configure": {"font": "TreeviewFont"}, "map": { "background": [ ("selected", "focus", bg_sel_focus), ("selected", "!focus", light_grey), ], "foreground": [ ("selected", "focus", fg_sel_focus), ("selected", "!focus", fg_sel_notfocus), ], }, "layout": [ # get rid of borders ("Treeview.treearea", {"sticky": "nswe"}) ], }, "treearea": {"configure": {"borderwidth": 0}}, }
def select_sequence(win_version, mac_version, linux_version=None): if running_on_windows(): return win_version elif running_on_mac_os(): return mac_version elif running_on_linux() and linux_version: return linux_version else: return win_version
def open_path_in_system_file_manager(path): if running_on_mac_os(): # http://stackoverflow.com/a/3520693/261181 subprocess.Popen(["open", "-R", path]) elif running_on_linux(): subprocess.Popen(["xdg-open", path]) else: assert running_on_windows() subprocess.Popen(["explorer", path])
def _init_window(self): self.set_default("layout.zoomed", False) self.set_default("layout.top", 15) self.set_default("layout.left", 150) self.set_default("layout.width", 700) self.set_default("layout.height", 650) self.set_default("layout.w_width", 200) self.set_default("layout.e_width", 200) self.set_default("layout.s_height", 200) # I don't actually need saved options for Full screen/maximize view, # but it's easier to create menu items, if I use configuration manager's variables self.set_default("view.full_screen", False) self.set_default("view.maximize_view", False) # In order to avoid confusion set these settings to False # even if they were True when Thonny was last run self.set_option("view.full_screen", False) self.set_option("view.maximize_view", False) self.geometry("{0}x{1}+{2}+{3}".format( self.get_option("layout.width"), self.get_option("layout.height"), self.get_option("layout.left"), self.get_option("layout.top"))) if self.get_option("layout.zoomed"): ui_utils.set_zoomed(self, True) self.protocol("WM_DELETE_WINDOW", self._on_close) # Window icons window_icons = self.get_option("theme.window_icons") if window_icons: imgs = [self.get_image(filename) for filename in window_icons] self.iconphoto(True, *imgs) elif running_on_linux() and ui_utils.get_tk_version_info() >= (8, 6): self.iconphoto(True, self.get_image("thonny.png")) else: icon_file = os.path.join(self.get_package_dir(), "res", "thonny.ico") try: self.iconbitmap(icon_file, default=icon_file) except: try: # seems to work in mac self.iconbitmap(icon_file) except: pass # TODO: try to get working in Ubuntu self.bind("<Configure>", self._on_configure, True)
def become_topmost_window(self): # Looks like at least on Windows all following is required for the window to get focus # (deiconify, ..., iconify, deiconify) self.deiconify() self.attributes('-topmost', True) self.after_idle(self.attributes, '-topmost', False) self.lift() if not running_on_linux(): # http://stackoverflow.com/a/13867710/261181 self.iconify() self.deiconify() editor = self.get_current_editor() if editor is not None: # This method is meant to be called when new file is opened, so it's safe to # send the focus to the editor editor.focus_set() else: self.focus_set()
def tweak_treeviews(): style = ttk.Style() # get rid of Treeview borders style.layout("Treeview", [('Treeview.treearea', {'sticky': 'nswe'})]) # necessary for Python 2.7 TODO: doesn't help for aqua style.configure("Treeview", background="white") #style.configure("Treeview", font='helvetica 14 bold') style.configure("Treeview", font=get_workbench().get_font("TreeviewFont")) #print(style.map("Treeview")) #print(style.layout("Treeview")) #style.configure("Treeview.treearea", font=TREE_FONT) # NB! Some Python or Tk versions (Eg. Py 3.2.3 + Tk 8.5.11 on Raspbian) # can't handle multi word color names in style.map light_blue = "#ADD8E6" light_grey = "#D3D3D3" if running_on_linux(): style.map( "Treeview", background=[ ('selected', 'focus', light_blue), ('selected', '!focus', light_grey), ], foreground=[ ('selected', 'black'), ], ) else: style.map( "Treeview", background=[ ('selected', 'focus', 'SystemHighlight'), ('selected', '!focus', light_grey), ], foreground=[('selected', 'SystemHighlightText')], )
def load_plugin(workbench): style = ttk.Style() if 'xpnative' in style.theme_names(): # gives better scrollbars in empty editors theme = 'xpnative' elif 'aqua' in style.theme_names(): theme = 'clam' elif 'clam' in style.theme_names(): theme = 'clam' else: theme = style.theme_use() style.theme_use(theme) style.configure("Sash", sashthickness=10) # get rid of Treeview borders style.layout("Treeview", [ ('Treeview.treearea', {'sticky': 'nswe'}) ]) # necessary for Python 2.7 TODO: doesn't help for aqua style.configure("Treeview", background="white") """ _images[1] = tk.PhotoImage("img_close", file=os.path.join(imgdir, '1x1_white.gif')) _images[2] = tk.PhotoImage("img_closeactive", file=os.path.join(imgdir, 'close_active.gif')) _images[3] = tk.PhotoImage("img_closepressed", file=os.path.join(imgdir, 'close_pressed.gif')) style.element_create("close", "image", "img_close", ("active", "pressed", "!disabled", "img_closepressed"), ("active", "!disabled", "img_closeactive"), border=8, sticky='') """ global _IMG_GRAY_LINE # Saving the reference, otherwise Tk will garbage collect the images _IMG_GRAY_LINE = tk.PhotoImage("gray_line", file=os.path.join(workbench.get_resource_dir(), 'gray_line.gif')) style.element_create("gray_line", "image", "gray_line", ("!selected", "gray_line"), height=1, width=10, border=1) if theme == "xpnative": # add a line below active tab to separate it from content style.layout("Tab", [ ('Notebook.tab', {'sticky': 'nswe', 'children': [ ('Notebook.padding', {'sticky': 'nswe', 'children': [ ('Notebook.focus', {'sticky': 'nswe', 'children': [ ('Notebook.label', {'sticky': '', 'side': 'left'}), #("close", {"side": "left", "sticky": ''}) ], 'side': 'top'}) ], 'side': 'top'}), ('gray_line', {'sticky': 'we', 'side': 'bottom'}), ]}), ]) style.configure("Tab", padding=(4,1,0,0)) elif theme == "aqua": style.map("TNotebook.Tab", foreground=[('selected', 'white'), ('!selected', 'black')]) """ ################ #print(style.layout("TMenubutton")) style.layout("TMenubutton", [ ('Menubutton.dropdown', {'side': 'right', 'sticky': 'ns'}), ('Menubutton.button', {'children': [ #('Menubutton.padding', {'children': [ ('Menubutton.label', {'sticky': ''}) #], 'expand': '1', 'sticky': 'we'}) ], 'expand': '1', 'sticky': 'nswe'}) ]) style.configure("TMenubutton", padding=14) """ #print(style.map("Treeview")) #print(style.layout("Treeview")) #style.configure("Treeview.treearea", font=TREE_FONT) # NB! Some Python or Tk versions (Eg. Py 3.2.3 + Tk 8.5.11 on Raspbian) # can't handle multi word color names in style.map light_blue = "#ADD8E6" light_grey = "#D3D3D3" if running_on_linux(): style.map("Treeview", background=[('selected', 'focus', light_blue), ('selected', '!focus', light_grey), ], foreground=[('selected', 'black'), ], ) else: style.map("Treeview", background=[('selected', 'focus', 'SystemHighlight'), ('selected', '!focus', light_grey), ], foreground=[('selected', 'SystemHighlightText')], )
def __init__(self, master): ConfigurationPage.__init__(self, master) self.add_checkbox("general.single_instance", tr("Allow only single Thonny instance"), row=1, columnspan=2) self.add_checkbox("general.event_logging", tr("Log program usage events"), row=4, columnspan=2) self.add_checkbox( "file.reopen_all_files", tr("Reopen all files from previous session"), row=5, columnspan=2, ) if running_on_linux(): self.add_checkbox( "file.avoid_zenity", tr("Use Tk file dialogs instead of Zenity"), tooltip=tr( "Select if the file dialogs end up behind the main window" ), row=6, columnspan=2, ) self.add_checkbox( "general.disable_notification_sound", tr("Disable notification sound"), row=7, columnspan=2, ) self.add_checkbox( "general.debug_mode", tr("Debug mode (provides more detailed diagnostic logs)"), row=8, columnspan=2, ) # language self._language_name_var = tk.StringVar( value=languages.LANGUAGES_DICT.get( get_workbench().get_option("general.language"), "")) self._language_label = ttk.Label(self, text=tr("Language")) self._language_label.grid(row=10, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) self._language_combo = ttk.Combobox( self, width=20, exportselection=False, textvariable=self._language_name_var, state="readonly", height=15, values=list(languages.LANGUAGES_DICT.values()), ) self._language_combo.grid(row=10, column=1, sticky=tk.W, pady=(10, 0)) # Mode ttk.Label(self, text=tr("UI mode")).grid(row=20, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) self.add_combobox( "general.ui_mode", ["simple", "regular", "expert"], row=20, column=1, pady=(10, 0), width=10, ) # scaling self._scaling_label = ttk.Label(self, text=tr("UI scaling factor")) self._scaling_label.grid(row=30, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) scalings = ["default"] + sorted( {0.5, 0.75, 1.0, 1.25, 1.33, 1.5, 2.0, 2.5, 3.0, 4.0}) self.add_combobox("general.scaling", scalings, row=30, column=1, pady=(10, 0), width=10) self._font_scaling_var = get_workbench().get_variable( "general.font_scaling_mode") self._font_scaling_label = ttk.Label(self, text=tr("Font scaling mode")) self._font_scaling_label.grid(row=40, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) self.add_combobox( "general.font_scaling_mode", ["default", "extra", "automatic"], row=40, column=1, pady=(10, 0), width=10, ) env_label = ttk.Label( self, text=tr("Environment variables (one KEY=VALUE per line)")) env_label.grid(row=90, column=0, sticky=tk.W, pady=(20, 0), columnspan=2) self.env_box = tktextext.TextFrame(self, horizontal_scrollbar=False, height=4, borderwidth=1, undo=True, wrap="none") self.env_box.grid(row=100, column=0, sticky="nsew", pady=(0, 10), columnspan=2) for entry in get_workbench().get_option("general.environment"): self.env_box.text.insert("end", entry + "\n") reopen_label = ttk.Label( self, text=tr("NB! Restart Thonny after changing these options!"), font="BoldTkDefaultFont", ) reopen_label.grid(row=110, column=0, sticky="sw", pady=(20, 0), columnspan=2) self.columnconfigure(1, weight=1) self.rowconfigure(100, weight=1)