def _get_webrepl_frame(self): if self._webrepl_frame is not None: return self._webrepl_frame self._webrepl_frame = ttk.Frame(self) self._webrepl_url_var = create_string_var( get_workbench().get_option(self.backend_name + ".webrepl_url")) url_label = ttk.Label(self._webrepl_frame, text="URL (eg. %s)" % DEFAULT_WEBREPL_URL) url_label.grid(row=0, column=0, sticky="nw", pady=(10, 0)) url_entry = ttk.Entry(self._webrepl_frame, textvariable=self._webrepl_url_var, width=30) url_entry.grid(row=1, column=0, sticky="nw") self._webrepl_password_var = create_string_var( get_workbench().get_option(self.backend_name + ".webrepl_password")) pw_label = ttk.Label(self._webrepl_frame, text=tr("Password")) pw_label.grid(row=0, column=1, sticky="nw", pady=(10, 0), padx=(10, 0)) pw_entry = ttk.Entry(self._webrepl_frame, textvariable=self._webrepl_password_var, width=15) pw_entry.grid(row=1, column=1, sticky="nw", padx=(10, 0)) return self._webrepl_frame
def _get_webrepl_frame(self): if self._webrepl_frame is not None: return self._webrepl_frame self._webrepl_frame = ttk.Frame(self) self._webrepl_url_var = create_string_var(DEFAULT_WEBREPL_URL) url_label = ttk.Label(self._webrepl_frame, text="URL (eg. %s)" % DEFAULT_WEBREPL_URL) url_label.grid(row=0, column=0, sticky="nw", pady=(10, 0)) url_entry = ttk.Entry(self._webrepl_frame, textvariable=self._webrepl_url_var, width=24) url_entry.grid(row=1, column=0, sticky="nw") self._webrepl_password_var = create_string_var( get_workbench().get_option(self.backend_name + ".webrepl_password")) pw_label = ttk.Label( self._webrepl_frame, text="Password (the one specified with `import webrepl_setup`)") pw_label.grid(row=2, column=0, sticky="nw", pady=(10, 0)) pw_entry = ttk.Entry(self._webrepl_frame, textvariable=self._webrepl_password_var, width=9) pw_entry.grid(row=3, column=0, sticky="nw") return self._webrepl_frame
def __init__(self, master): ConfigurationPage.__init__(self, master) self._family_variable = create_string_var( get_workbench().get_option("view.editor_font_family"), modification_listener=self._update_preview_font) self._size_variable = create_string_var( get_workbench().get_option("view.editor_font_size"), modification_listener=self._update_preview_font) ttk.Label(self, text="Editor font").grid(row=0, column=0, sticky="w") self._family_combo = ttk.Combobox(self, exportselection=False, state='readonly', textvariable=self._family_variable, values=self._get_families_to_show()) self._family_combo.grid(row=1, column=0, sticky=tk.NSEW, padx=(0,10)) ttk.Label(self, text="Size").grid(row=0, column=1, sticky="w") self._size_combo = ttk.Combobox(self, width=4, exportselection=False, textvariable=self._size_variable, state='readonly', values=[str(x) for x in range(3,73)]) self._size_combo.grid(row=1, column=1) ttk.Label(self, text="Preview").grid(row=2, column=0, sticky="w", pady=(10,0)) self._preview_font = tk_font.Font() self._preview_text = tk.Text(self, height=10, borderwidth=1, font=self._preview_font, wrap=tk.WORD) self._preview_text.insert("1.0", textwrap.dedent(""" The quick brown fox jumps over the lazy dog ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890 @$%()[]{}/\_-+ "Hello " + 'world!'""").strip()) self._preview_text.grid(row=3, column=0, columnspan=2, sticky=tk.NSEW, pady=(0,5)) self.columnconfigure(0, weight=1) self.rowconfigure(3, weight=1) self._update_preview_font()
def __init__(self, master): ConfigurationPage.__init__(self, master) self._configuration_variable = create_string_var( get_workbench().get_option("run.backend_configuration")) entry_label = ttk.Label( self, text="Which interpreter to use for running programs?") entry_label.grid(row=0, column=0, columnspan=2, sticky=tk.W) self._entry = ttk.Combobox(self, exportselection=False, textvariable=self._configuration_variable, values=self._get_configurations()) self._entry.grid(row=1, column=0, columnspan=2, sticky=tk.NSEW) self._entry.state(['!disabled', 'readonly']) another_label = ttk.Label(self, text="Your interpreter isn't in the list?") another_label.grid(row=2, column=0, columnspan=2, sticky=tk.W, pady=(10, 0)) self._select_button = ttk.Button( self, text="Locate another executable " + ("(pythonw.exe) ..." if running_on_windows() else "(python3) ..."), command=self._select_executable) self._select_button.grid(row=3, column=0, columnspan=2, sticky=tk.NSEW) self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=1)
def _add_text_field(self, label_text, variable_name, row, show=None): entry_label = ttk.Label(self, text=label_text) entry_label.grid(row=row, column=0, sticky="w") variable = create_string_var(get_workbench().get_option(variable_name), self._on_change) entry = ttk.Entry(self, textvariable=variable, show=show) entry.grid(row=row + 1, column=0, sticky="we") return variable
def _init_themes(self): self._original_ui_theme = get_workbench().get_option("view.ui_theme") self._original_syntax_theme = get_workbench().get_option( "view.syntax_theme") self._ui_theme_variable = create_string_var( self._original_ui_theme, modification_listener=self._update_appearance) self._syntax_theme_variable = create_string_var( self._original_syntax_theme, modification_listener=self._update_appearance) ttk.Label(self, text=tr("UI theme")).grid(row=1, column=1, sticky="w", pady=(0, 10), padx=(0, 5)) self._ui_theme_combo = ttk.Combobox( self, exportselection=False, textvariable=self._ui_theme_variable, state="readonly", height=15, values=get_workbench().get_usable_ui_theme_names(), ) self._ui_theme_combo.grid(row=1, column=2, sticky="nwe", pady=(0, 5)) ttk.Label(self, text=tr("Syntax theme")).grid(row=2, column=1, sticky="w", pady=(0, 10), padx=(0, 5)) self._syntax_theme_combo = ttk.Combobox( self, exportselection=False, textvariable=self._syntax_theme_variable, state="readonly", height=15, values=get_workbench().get_syntax_theme_names(), ) self._syntax_theme_combo.grid(row=2, column=2, sticky="nwe", pady=(0, 5))
def __init__(self, master): super().__init__(master) self._configuration_variable = create_string_var( get_workbench().get_option("CustomInterpreter.path")) entry_label = ttk.Label(self, text=tr("Known interpreters")) entry_label.grid(row=0, column=0, columnspan=2, sticky=tk.W) self._entry = ttk.Combobox( self, exportselection=False, textvariable=self._configuration_variable, values=self._get_interpreters(), ) self._entry.grid(row=1, column=0, columnspan=2, sticky=tk.NSEW) self._entry.state(["!disabled", "readonly"]) another_label = ttk.Label( self, text=tr("Your interpreter isn't in the list?")) another_label.grid(row=2, column=0, columnspan=2, sticky=tk.W, pady=(10, 0)) ttk.Style().configure("Centered.TButton", justify="center") self._select_button = ttk.Button( self, style="Centered.TButton", text=tr("Locate another") + " " + ("python.exe ..." if running_on_windows() else tr("python executable") + " ...") + "\n" + tr("NB! Thonny only supports Python 3.5 and later"), command=self._select_executable, ) self._select_button.grid(row=3, column=0, columnspan=2, sticky=tk.NSEW) self._venv_button = ttk.Button( self, style="Centered.TButton", text=tr("Create new virtual environment") + " ...\n" + "(" + tr("Select existing or create a new empty directory") + ")", command=self._create_venv, ) self._venv_button.grid(row=4, column=0, columnspan=2, sticky=tk.NSEW, pady=(5, 0)) self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=1)
def __init__(self, master): ConfigurationPage.__init__(self, master) self._backend_specs_by_desc = { spec.description: spec for spec in get_workbench().get_backends().values() } self._conf_pages = {} self._current_page = None current_backend_name = get_workbench().get_option("run.backend_name") try: current_backend_desc = get_workbench().get_backends( )[current_backend_name].description except KeyError: current_backend_desc = "" self._combo_variable = create_string_var(current_backend_desc) label = ttk.Label( self, text=tr( "Which interpreter or device should Thonny use for running your code?" )) label.grid(row=0, column=0, columnspan=2, sticky=tk.W) sorted_backend_specs = sorted(self._backend_specs_by_desc.values(), key=lambda x: x.sort_key) self._combo = ttk.Combobox( self, exportselection=False, textvariable=self._combo_variable, values=[spec.description for spec in sorted_backend_specs], height=25, ) self._combo.grid(row=1, column=0, columnspan=2, sticky=tk.NSEW, pady=(0, 10)) self._combo.state(["!disabled", "readonly"]) self.labelframe = ttk.LabelFrame(self, text=" " + tr("Details") + " ") self.labelframe.grid(row=2, column=0, sticky="nsew") self.labelframe.columnconfigure(0, weight=1) self.labelframe.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.rowconfigure(2, weight=1) self._combo_variable.trace("w", self._backend_changed) self._backend_changed()
def __init__(self, master): ConfigurationPage.__init__(self, master) ttk.Label(self, text="EV3 connection settings").pack(side=tk.TOP, padx=5, pady=(5,30)) workbench=get_workbench() for name in ('ip','username','password'): self.__dict__[name]=create_string_var(workbench.get_option("ev3."+name)) self.makeentry( "IP address:", self.ip, width=10) self.makeentry( "User name:", self.username, width=10) self.makeentry( "Password:"******"*")
def __init__(self, master, kind, initial_dir): super().__init__(master=master) self.result = None self.updating_selection = False self.kind = kind if kind == "open": self.title(tr("Open from %s") % get_runner().get_node_label()) else: assert kind == "save" self.title(tr("Save to %s") % get_runner().get_node_label()) background = ttk.Frame(self) background.grid(row=0, column=0, sticky="nsew") self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.browser = DialogRemoteFileBrowser(background, self) self.browser.grid(row=0, column=0, columnspan=4, sticky="nsew", pady=20, padx=20) self.browser.configure(borderwidth=1, relief="groove") self.browser.tree.configure(selectmode="browse") self.name_label = ttk.Label(background, text=tr("File name:")) self.name_label.grid(row=1, column=0, pady=(0, 20), padx=20, sticky="w") self.name_var = create_string_var("") self.name_entry = ttk.Entry( background, textvariable=self.name_var, state="normal" if kind == "save" else "disabled" ) self.name_entry.grid(row=1, column=1, pady=(0, 20), padx=(0, 20), sticky="we") self.name_entry.bind("<KeyRelease>", self.on_name_edit, True) self.ok_button = ttk.Button(background, text=tr("OK"), command=self.on_ok) self.ok_button.grid(row=1, column=2, pady=(0, 20), padx=(0, 20), sticky="e") self.cancel_button = ttk.Button(background, text=tr("Cancel"), command=self.on_cancel) self.cancel_button.grid(row=1, column=3, pady=(0, 20), padx=(0, 20), sticky="e") background.rowconfigure(0, weight=1) background.columnconfigure(1, weight=1) self.bind("<Escape>", self.on_cancel, True) self.bind("<Return>", self.on_ok, True) self.protocol("WM_DELETE_WINDOW", self.on_cancel) self.tree_select_handler_id = self.browser.tree.bind( "<<TreeviewSelect>>", self.on_tree_select, True ) self.browser.request_focus_into(initial_dir) self.name_entry.focus_set()
def __init__(self, master): super().__init__(master) self._configuration_variable = create_string_var( get_workbench().get_option("CustomInterpreter.path")) entry_label = ttk.Label(self, text=tr("Python executable")) entry_label.grid(row=0, column=1, columnspan=2, sticky=tk.W) self._entry = ttk.Combobox( self, exportselection=False, textvariable=self._configuration_variable, values=_get_interpreters(), ) self._entry.grid(row=1, column=1, sticky=tk.NSEW) self._select_button = ttk.Button( self, text="...", width=3, command=self._select_executable, ) self._select_button.grid(row=1, column=2, sticky="e", padx=(10, 0)) self.columnconfigure(1, weight=1) extra_text = tr("NB! Thonny only supports Python 3.5 and later") if running_on_mac_os(): extra_text += "\n\n" + tr( "NB! File selection button may not work properly when selecting executables\n" + "from a virtual environment. In this case choose the 'activate' script instead\n" + "of the interpreter (or enter the path directly to the box)!") extra_label = ttk.Label(self, text=extra_text) extra_label.grid(row=2, column=1, columnspan=2, pady=10, sticky="w") last_row = ttk.Frame(self) last_row.grid(row=100, sticky="swe", column=1, columnspan=2) self.rowconfigure(100, weight=1) last_row.columnconfigure(1, weight=1) new_venv_link = ui_utils.create_action_label( last_row, "New virtual environment", self._create_venv, ) new_venv_link.grid(row=0, column=1, sticky="e", pady=10)
def __init__(self, configuration_manager): super().__init__(className="Thonny") ttk.Style().theme_use(ui_utils.get_default_theme()) self.title("Welcome to Thonny!" + " [portable]" if is_portable() else "") self.protocol("WM_DELETE_WINDOW", self.destroy) self.ok = False self.conf = configuration_manager self.main_frame = ttk.Frame(self) self.main_frame.grid(row=1, column=1, sticky="nsew") self.columnconfigure(1, weight=1) self.rowconfigure(1, weight=1) self.main_frame.rowconfigure(1, weight=1) logo_file = os.path.join(os.path.dirname(__file__), "res", "thonny.png") self.logo = tk.PhotoImage(file=logo_file) logo_label = ttk.Label(self.main_frame, image=self.logo) logo_label.grid(row=1, rowspan=3, column=1, sticky="nsew") self.padx = 50 self.pady = 50 self.language_variable = ui_utils.create_string_var( languages.BASE_LANGUAGE_NAME, self.on_change_language) self.add_combo(1, "Language:", self.language_variable, list(languages.LANGUAGES_DICT.values())) self.mode_variable = tk.StringVar(value=STD_MODE_TEXT) self.add_combo(2, "Initial settings:", self.mode_variable, [STD_MODE_TEXT, RPI_MODE_TEXT]) ok_button = ttk.Button(self.main_frame, text="Let's go!", command=self.on_ok) ok_button.grid(row=3, column=3, padx=(0, self.padx), pady=(self.pady * 0.7, self.pady), sticky="se") self.center()
def _add_combobox_field(self, label_text, variable_name, row, options, pady: Union[int, tuple] = 0, width=None): if isinstance(pady, int): pady = (pady, pady) label = ttk.Label(self, text=label_text) label.grid(row=row, column=0, sticky="w", pady=pady) variable = create_string_var(get_workbench().get_option(variable_name), self._on_change) return self.add_combobox(variable, options, row=row, column=1, pady=pady, padx=ems_to_pixels(1), width=width)
def _add_text_field(self, label_text, variable_name, row, show=None, pady: Union[int, tuple] = 0, width=None): if isinstance(pady, int): pady = (pady, pady) entry_label = ttk.Label(self, text=label_text) entry_label.grid(row=row, column=0, sticky="w", pady=pady) variable = create_string_var(get_workbench().get_option(variable_name), self._on_change) entry = ttk.Entry(self, textvariable=variable, show=show, width=width) entry.grid(row=row, column=1, sticky="we", pady=pady, padx=ems_to_pixels(1)) return variable
def __init__(self, master): super().__init__(master) self._has_opened_firmware_flasher = False intro_label = ttk.Label(self, text=self._get_intro_text()) intro_label.grid(row=0, column=0, sticky="nw") driver_url = self._get_usb_driver_url() if driver_url: driver_url_label = create_url_label(self, driver_url) driver_url_label.grid(row=1, column=0, sticky="nw") port_label = ttk.Label( self, text="Port or WebREPL" if self.allow_webrepl else tr("Port")) port_label.grid(row=3, column=0, sticky="nw", pady=(10, 0)) self._ports_by_desc = { p.description if p.device in p.description else p.description + " (" + p.device + ")": p.device for p in list_serial_ports() } self._ports_by_desc["< " + tr("Try to detect port automatically") + " >"] = "auto" self._WEBREPL_OPTION_DESC = "< WebREPL >" if self.allow_webrepl: self._ports_by_desc[self._WEBREPL_OPTION_DESC] = "webrepl" def port_order(p): _, name = p if name is None: return "" elif name.startswith("COM") and len(name) == 4: # Make one-digit COM ports go before COM10 return name.replace("COM", "COM0") else: return name # order by port, auto first port_descriptions = [ key for key, _ in sorted(self._ports_by_desc.items(), key=port_order) ] self._port_desc_variable = create_string_var( self.get_stored_port_desc(), self._on_change_port) self._port_combo = ttk.Combobox( self, exportselection=False, textvariable=self._port_desc_variable, values=port_descriptions, ) self._port_combo.state(["!disabled", "readonly"]) self._port_combo.grid(row=4, column=0, sticky="new") self.columnconfigure(0, weight=1) self._webrepl_frame = None self._flashing_frame = None last_row = ttk.Frame(self) last_row.grid(row=100, sticky="swe") self.rowconfigure(100, weight=1) last_row.columnconfigure(1, weight=1) advanced_link = ui_utils.create_action_label( last_row, tr("Advanced options"), lambda event: self._show_advanced_options()) # advanced_link.grid(row=0, column=1, sticky="e") if self._has_flashing_dialog(): firmware_link = ui_utils.create_action_label( last_row, tr("Install or update firmware"), self._on_click_firmware_installer_link, ) firmware_link.grid(row=1, column=1, sticky="e") self._on_change_port()
def __init__(self, master): super().__init__(master) intro_text = (_( "Connect your device to the computer and select corresponding port below" ) + "\n" + "(" + _( 'look for your device name, "USB Serial" or "UART"' ) + ").\n" + _( "If you can't find it, you may need to install proper USB driver first." )) if self.allow_webrepl: intro_text = ( ("Connecting via USB cable:") + "\n" + intro_text + "\n\n" + ("Connecting via WebREPL protocol:") + "\n" + ("If your device supports WebREPL, first connect via serial, make sure WebREPL is enabled\n" + "(import webrepl_setup), connect your computer and device to same network and select < WebREPL > below" )) intro_label = ttk.Label(self, text=intro_text) intro_label.grid(row=0, column=0, sticky="nw") driver_url = self._get_usb_driver_url() if driver_url: driver_url_label = create_url_label(self, driver_url) driver_url_label.grid(row=1, column=0, sticky="nw") port_label = ttk.Label( self, text="Port or WebREPL" if self.allow_webrepl else _("Port")) port_label.grid(row=3, column=0, sticky="nw", pady=(10, 0)) self._ports_by_desc = { p.description if p.device in p.description else p.description + " (" + p.device + ")": p.device for p in list_serial_ports() } self._ports_by_desc["< " + _("Try to detect port automatically") + " >"] = "auto" self._WEBREPL_OPTION_DESC = "< WebREPL >" if self.allow_webrepl: self._ports_by_desc[self._WEBREPL_OPTION_DESC] = "webrepl" def port_order(p): _, name = p if name is None: return "" elif name.startswith("COM") and len(name) == 4: # Make one-digit COM ports go before COM10 return name.replace("COM", "COM0") else: return name # order by port, auto first port_descriptions = [ key for key, _ in sorted(self._ports_by_desc.items(), key=port_order) ] self._port_desc_variable = create_string_var( self.get_current_port_desc(), self._on_change_port) self._port_combo = ttk.Combobox( self, exportselection=False, textvariable=self._port_desc_variable, values=port_descriptions, ) self._port_combo.state(["!disabled", "readonly"]) self._port_combo.grid(row=4, column=0, sticky="new") self.columnconfigure(0, weight=1) self._webrepl_frame = None self._flashing_frame = None self._on_change_port()
def __init__(self, master, package_metadata, selected_version): tk.Toplevel.__init__(self, master) self.result = None self._closed = False self._version_data = None self._package_name = package_metadata["info"]["name"] self.title("Advanced install / upgrade / downgrade") self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) main_frame = ttk.Frame(self) # To get styled background main_frame.grid(sticky="nsew") main_frame.rowconfigure(0, weight=1) main_frame.columnconfigure(0, weight=1) version_label = ttk.Label(main_frame, text="Desired version") version_label.grid(row=0, column=0, columnspan=2, padx=20, pady=(15, 0), sticky="w") def version_sort_key(s): # Trying to massage understandable versions into valid StrictVersions if s.replace(".", "").isnumeric(): # stable release s2 = s + "b999" # make it latest beta version elif "rc" in s: s2 = s.replace("rc", "b8") else: s2 = s try: return StrictVersion(s2) except Exception: # use only numbers nums = re.findall(r"\d+", s) while len(nums) < 2: nums.append("0") return StrictVersion(".".join(nums[:3])) version_strings = list(package_metadata["releases"].keys()) version_strings.sort(key=version_sort_key, reverse=True) self.version_var = ui_utils.create_string_var( selected_version, self._start_fetching_version_info) self.version_combo = ttk.Combobox( main_frame, textvariable=self.version_var, values=version_strings, exportselection=False, ) self.version_combo.state(["!disabled", "readonly"]) self.version_combo.grid(row=1, column=0, columnspan=2, pady=(0, 15), padx=20, sticky="ew") self.requires_label = ttk.Label(main_frame, text="") self.requires_label.grid(row=2, column=0, columnspan=2, pady=(0, 15), padx=20, sticky="ew") self.update_deps_var = tk.IntVar() self.update_deps_var.set(0) self.update_deps_cb = ttk.Checkbutton(main_frame, text="Upgrade dependencies", variable=self.update_deps_var) self.update_deps_cb.grid(row=3, column=0, columnspan=2, padx=20, sticky="w") self.ok_button = ttk.Button(main_frame, text="Install", command=self._ok) self.ok_button.grid(row=4, column=0, pady=15, padx=(20, 0), sticky="se") self.cancel_button = ttk.Button(main_frame, text="Cancel", command=self._cancel) self.cancel_button.grid(row=4, column=1, pady=15, padx=(5, 20), sticky="se") # self.resizable(height=tk.FALSE, width=tk.FALSE) self.version_combo.focus_set() self.bind("<Escape>", self._cancel, True) self.protocol("WM_DELETE_WINDOW", self._cancel) if self.version_var.get().strip(): self._start_fetching_version_info()
def _init_fonts(self): self._original_editor_family = get_workbench().get_option( "view.editor_font_family") self._original_editor_size = get_workbench().get_option( "view.editor_font_size") self._original_io_family = get_workbench().get_option( "view.io_font_family") self._original_io_size = get_workbench().get_option( "view.io_font_size") self._editor_family_variable = create_string_var( self._original_editor_family, modification_listener=self._update_appearance) self._editor_size_variable = create_string_var( self._original_editor_size, modification_listener=self._update_appearance) self._io_family_variable = create_string_var( self._original_io_family, modification_listener=self._update_appearance) self._io_size_variable = create_string_var( self._original_io_size, modification_listener=self._update_appearance) ttk.Label(self, text=tr("Editor font")).grid(row=1, column=3, sticky="w", pady=(0, 5), padx=(25, 5)) editor_family_combo = ttk.Combobox( self, exportselection=False, state="readonly", height=15, textvariable=self._editor_family_variable, values=self._get_families_to_show(), ) editor_family_combo.grid(row=1, column=4, sticky="nwe", pady=(0, 5)) editor_size_combo = ttk.Combobox( self, width=4, exportselection=False, textvariable=self._editor_size_variable, state="readonly", height=15, values=[str(x) for x in range(3, 73)], ) editor_size_combo.grid(row=1, column=5, sticky="nwe", pady=(0, 5), padx=(5, 0)) ttk.Label(self, text=tr("IO font")).grid(row=2, column=3, sticky="w", pady=(0, 5), padx=(25, 5)) io_family_combo = ttk.Combobox( self, exportselection=False, state="readonly", height=15, textvariable=self._io_family_variable, values=self._get_families_to_show(), ) io_family_combo.grid(row=2, column=4, sticky="nwe", pady=(0, 5)) io_size_combo = ttk.Combobox( self, width=4, exportselection=False, textvariable=self._io_size_variable, state="readonly", height=15, values=[str(x) for x in range(3, 73)], ) io_size_combo.grid(row=2, column=5, sticky="nwe", pady=(0, 5), padx=(5, 0))
def __init__(self, master): self._original_family = get_workbench().get_option( "view.editor_font_family") self._original_size = get_workbench().get_option( "view.editor_font_size") self._original_ui_theme = get_workbench().get_option("view.ui_theme") self._original_syntax_theme = get_workbench().get_option( "view.syntax_theme") self._original_io_family = get_workbench().get_option( "view.io_font_family") self._original_io_size = get_workbench().get_option( "view.io_font_size") ConfigurationPage.__init__(self, master) self._family_variable = create_string_var( self._original_family, modification_listener=self._update_appearance) self._size_variable = create_string_var( self._original_size, modification_listener=self._update_appearance) self._ui_theme_variable = create_string_var( self._original_ui_theme, modification_listener=self._update_appearance) self._syntax_theme_variable = create_string_var( self._original_syntax_theme, modification_listener=self._update_appearance) self._io_family_variable = create_string_var( self._original_io_family, modification_listener=self._update_appearance) self._io_size_variable = create_string_var( self._original_io_size, modification_listener=self._update_appearance) ttk.Label(self, text="UI theme").grid(row=1, column=0, sticky="w", pady=(10, 0)) self._ui_theme_combo = ttk.Combobox( self, exportselection=False, textvariable=self._ui_theme_variable, state="readonly", height=15, values=get_workbench().get_usable_ui_theme_names(), ) self._ui_theme_combo.grid(row=2, column=0, sticky="nsew", padx=(0, 10)) ttk.Label(self, text="Syntax theme").grid(row=1, column=1, sticky="w", pady=(10, 0)) self._syntax_theme_combo = ttk.Combobox( self, exportselection=False, textvariable=self._syntax_theme_variable, state="readonly", height=15, values=get_workbench().get_syntax_theme_names(), ) self._syntax_theme_combo.grid(row=2, column=1, sticky="nsew", padx=(0, 10)) ttk.Label(self, text="Editor font").grid(row=1, column=2, sticky="w", pady=(10, 0)) self._family_combo = ttk.Combobox( self, exportselection=False, state="readonly", height=15, textvariable=self._family_variable, values=self._get_families_to_show(), ) self._family_combo.grid(row=2, column=2, sticky=tk.NSEW, padx=(0, 10)) ttk.Label(self, text="Size").grid(row=1, column=3, sticky="w", pady=(10, 0)) self._size_combo = ttk.Combobox( self, width=4, exportselection=False, textvariable=self._size_variable, state="readonly", height=15, values=[str(x) for x in range(3, 73)], ) self._size_combo.grid(row=2, column=3, sticky="nsew") ttk.Label(self, text="Editor preview").grid(row=3, column=0, sticky="w", pady=(10, 0), columnspan=4) self._preview_codeview = CodeView( self, height=6, font="EditorFont", # relief="sunken", # borderwidth=1, ) self._preview_codeview.set_content( textwrap.dedent(""" def foo(bar): if bar is None: # This is a comment print("The answer is", 33) unclosed_string = "blah, blah """).strip()) self._preview_codeview.grid(row=4, column=0, columnspan=4, sticky=tk.NSEW, pady=(0, 5)) ttk.Label(self, text="Shell font").grid(row=5, column=2, sticky="w", pady=(10, 0)) self._family_combo = ttk.Combobox( self, exportselection=False, state="readonly", height=15, textvariable=self._io_family_variable, values=self._get_families_to_show(), ) self._family_combo.grid(row=6, column=2, sticky=tk.NSEW, padx=(0, 10)) ttk.Label(self, text="Size").grid(row=5, column=3, sticky="w", pady=(10, 0)) self._size_combo = ttk.Combobox( self, width=4, exportselection=False, textvariable=self._io_size_variable, state="readonly", height=15, values=[str(x) for x in range(3, 73)], ) self._size_combo.grid(row=6, column=3, sticky="nsew") ttk.Label(self, text="Shell preview").grid(row=7, column=0, sticky="w", pady=(10, 0), columnspan=4) self._shell_preview = tk.Text(self, height=3) self._shell_preview.grid(row=8, column=0, columnspan=4, sticky=tk.NSEW, pady=(0, 5)) self._insert_shell_text() ttk.Label( self, text="NB! Some style elements change only after restarting Thonny" ).grid(row=9, column=0, columnspan=4, sticky="w", pady=(0, 5)) self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=1) self.columnconfigure(2, weight=1) self.columnconfigure(3, weight=1)
def __init__(self, master): ConfigurationPage.__init__(self, master) # HACK: take geometry from options window and increase its width with 5 em for extra ev3 tab # and 10 em for extra heigt for ev3 tab optionsWindow = self.master.master optionsWindow.update() # to update geometry in optionsWindow geometry = optionsWindow.winfo_geometry() # print("geometry:",geometry) # needs above update call otherwise geometry: 1x1+0+0 width = optionsWindow.winfo_width() height = optionsWindow.winfo_height() # print("width:",width) # print("height:",height) from thonny.ui_utils import ems_to_pixels width = width + ems_to_pixels(5) height = height + ems_to_pixels(14) optionsWindow.geometry("%dx%d" % (width, height)) # get options from workbench workbench = get_workbench() for name in ('ip', 'username', 'password', 'rpyc_timeout', "playfield"): self.__dict__[name] = create_string_var( workbench.get_option("ev3." + name)) for name in ('show_start_stop_buttons', 'show_fullscreen', 'show_maximized', 'show_on_second_monitor'): self.__dict__[name] = create_string_var( workbench.get_option("ev3." + name)) ttk.Label(self, text="EV3 connection settings").pack(side=tk.TOP, padx=5, pady=(5, 30)) self.makeentry("IP address:", self.ip, width=10) self.makeentry("User name:", self.username, width=10) self.makeentry("Password:"******"EV3 Simulator options").pack(side=tk.TOP, padx=5, pady=(20, 20)) self.makeselect("Playfield", self.playfield, ["small", "large"]) #self.makecheckbox( "Show simulator maximized", self.show_maximized) import platform if platform.system().lower() == "windows": self.makecheckbox("Show simulator fullscreen on second monitor", self.show_on_second_monitor) else: self.makecheckbox("Show simulator fullscreen", self.show_fullscreen) self.makecheckbox("Show simulator window on second monitor", self.show_on_second_monitor) ttk.Label( self, text= "Warning: to use simulated bluetooth in simulator make sure you have PyBluez uninstalled!", font="BoldTkDefaultFont").pack(side=tk.TOP, padx=0, pady=(0, 0)) ttk.Label(self, text="EV3 Advanced options").pack(side=tk.TOP, padx=5, pady=(20, 20)) self.makecheckbox( "Show start/stop on the EV3 buttons on toolbar. (needs restart)", self.show_start_stop_buttons) self.makeentry("Rpyc Timeout(secs)^:", self.rpyc_timeout, width=10) default_font = tk.font.nametofont("TkDefaultFont") label = ttk.Label( self, text= ('^ The "Stop all programs/motors/sound on EV3" command is faster when using the rpyc protocol but it needs\n' ' the rpyc server installed on the EV3. First the rpyc protocol is tried, but if that fails the slower \n' ' ssh protocol is tried. Because by default no rpyc server is installed we keep the rpyc timeout low,\n' ' however sometimes a bigger rpyc timeout is needed which can be increased here.' )) label.config(font=(default_font.cget("family"), int(default_font.cget("size") * 0.9))) label.pack(side=tk.TOP, padx=5, pady=(20, 20))