def __init__(self, master):
        ConfigurationPage.__init__(self, master)

        group_spacing = ems_to_pixels(2)

        try:
            self.add_checkbox("view.name_highlighting",
                              tr("Highlight matching names"))
        except Exception:
            # name matcher may have been disabled
            logger.warning("Couldn't create name matcher checkbox")

        try:
            self.add_checkbox("view.locals_highlighting",
                              tr("Highlight local variables"))
        except Exception:
            # locals highlighter may have been disabled
            logger.warning("Couldn't create name locals highlighter checkbox")

        self.add_checkbox("view.paren_highlighting",
                          tr("Highlight parentheses"))
        self.add_checkbox("view.syntax_coloring",
                          tr("Highlight syntax elements"))
        self.add_checkbox("view.highlight_tabs",
                          tr("Highlight tab characters"))
        self.add_checkbox(
            "view.highlight_current_line",
            tr("Highlight current line (requires reopening the editor)"),
        )

        get_workbench().set_default("view.remember_line", False)
        self.add_checkbox(
            "view.remember_line",
            tr("Remember cursor position after reloading on external modification"
               ),
        )

        self.add_checkbox(
            "edit.automatic_calltips",
            tr("Automatically show parameter info after typing '('"),
            columnspan=2,
            pady=(group_spacing, 0),
        )
        self.add_checkbox(
            "edit.automatic_completions",
            tr("Automatically propose completions while typing"),
            columnspan=2,
        )
        self.add_checkbox(
            "edit.automatic_completion_details",
            tr("Automatically show documentation for completions"),
            columnspan=2,
        )
        self.add_checkbox(
            "edit.tab_request_completions_in_editors",
            tr("Request completions with Tab-key in editors"),
            columnspan=2,
        )
        self.add_checkbox(
            "edit.tab_request_completions_in_shell",
            tr("Request completions with Tab-key in Shell"),
            columnspan=2,
        )

        self.add_checkbox(
            "edit.indent_with_tabs",
            tr("Indent with tab characters (not recommended for Python)"),
            columnspan=2,
            pady=(group_spacing, 0),
        )

        self.add_checkbox("view.show_line_numbers",
                          tr("Show line numbers"),
                          pady=(20, 0))
        self._line_length_var = get_workbench().get_variable(
            "view.recommended_line_length")
        label = ttk.Label(
            self,
            text=tr(
                "Recommended maximum line length\n(Set to 0 to turn off margin line)"
            ))
        label.grid(row=20, column=0, sticky=tk.W)
        self._line_length_combo = ttk.Combobox(
            self,
            width=4,
            exportselection=False,
            textvariable=self._line_length_var,
            state="readonly",
            values=[0, 60, 70, 80, 90, 100, 110, 120],
        )
        self._line_length_combo.grid(row=20, column=1, sticky=tk.W, padx=10)

        self.columnconfigure(1, weight=1)
Esempio n. 2
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)
Esempio n. 3
0
    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))
Esempio n. 4
0
    def __init__(self, master):
        ConfigurationPage.__init__(self, master)

        self.add_checkbox(
            "general.single_instance", _("Allow only single Thonny instance"), row=1, columnspan=2
        )
        self.add_checkbox(
            "general.event_logging", _("Log program usage events"), row=4, columnspan=2
        )
        self.add_checkbox(
            "file.reopen_all_files",
            _("Reopen all files from previous session"),
            row=5,
            columnspan=2,
        )
        self.add_checkbox(
            "general.disable_notification_sound",
            _("Disable notification sound"),
            row=6,
            columnspan=2,
        )
        self.add_checkbox(
            "general.debug_mode",
            _("Debug mode (provides more detailed diagnostic logs)"),
            row=7,
            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=_("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=_("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=_("UI scaling factor"))
        self._scaling_label.grid(row=30, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0))
        scalings = 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=_("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,
        )

        reopen_label = ttk.Label(
            self,
            text=_("NB! Restart Thonny after changing these options!"),
            font="BoldTkDefaultFont",
        )
        reopen_label.grid(row=100, column=0, sticky=tk.W, pady=20, columnspan=2)

        self.columnconfigure(1, weight=1)
Esempio n. 5
0
    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)