示例#1
0
    def __init__(self, master, propose_remove_line_numbers=False, **text_frame_args):
        frame_args = text_frame_args.copy()
        if "text_class" not in frame_args:
            frame_args["text_class"] = CodeViewText

        super().__init__(
            master,
            undo=True,
            wrap=tk.NONE,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            **frame_args,
        )

        # TODO: propose_remove_line_numbers on paste??

        assert self._first_line_number is not None

        get_workbench().bind("SyntaxThemeChanged", self._reload_theme_options, True)
        self._original_newlines = os.linesep
        self._reload_theme_options()
        self._gutter.bind("<Double-Button-1>", self._toggle_breakpoint, True)
        # self.text.tag_configure("breakpoint_line", background="pink")
        self._gutter.tag_configure("breakpoint", foreground="crimson")

        editor_font = tk.font.nametofont("EditorFont")
        spacer_font = editor_font.copy()
        spacer_font.configure(size=editor_font.cget("size") // 4)
        self._gutter.tag_configure("spacer", font=spacer_font)
        self._gutter.tag_configure("active", font="BoldEditorFont")
        self._gutter.tag_raise("spacer")
示例#2
0
    def __init__(self, master, propose_remove_line_numbers=False, **text_frame_args):

        tktextext.TextFrame.__init__(
            self,
            master,
            text_class=CodeViewText,
            undo=True,
            wrap=tk.NONE,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            **text_frame_args
        )

        # TODO: propose_remove_line_numbers on paste??

        assert self._first_line_number is not None

        self._syntax_theme_change_binding = tk._default_root.bind(
            "<<SyntaxThemeChanged>>", self._reload_theme_options, True
        )

        self._reload_theme_options()
        self._gutter.bind("<Double-Button-1>", self._toggle_breakpoint, True)
        # self.text.tag_configure("breakpoint_line", background="pink")
        self._gutter.tag_configure("breakpoint", foreground="crimson")

        editor_font = tk.font.nametofont("EditorFont")
        spacer_font = editor_font.copy()
        spacer_font.configure(size=editor_font.cget("size") // 4)
        self._gutter.tag_configure("spacer", font=spacer_font)
        self._gutter.tag_configure("active", font="BoldEditorFont")
        self._gutter.tag_raise("spacer")
示例#3
0
    def __init__(self, master):
        tktextext.TextFrame.__init__(
            self,
            master,
            text_class=AssistantRstText,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            read_only=True,
            wrap="word",
            font="TkDefaultFont",
            # cursor="arrow",
            padx=10,
            pady=0,
            insertwidth=0,
        )

        self._analyzer_instances = []

        self._snapshots_per_main_file = {}
        self._current_snapshot = None

        self._accepted_warning_sets = []

        self.text.tag_configure(
            "section_title",
            spacing3=5,
            font="BoldTkDefaultFont",
            # foreground=get_syntax_options_for_tag("stderr")["foreground"]
        )
        self.text.tag_configure(
            "intro",
            # font="ItalicTkDefaultFont",
            spacing3=10,
        )
        self.text.tag_configure("relevant_suggestion_title", font="BoldTkDefaultFont")
        self.text.tag_configure("suggestion_title", lmargin2=16, spacing1=5, spacing3=5)
        self.text.tag_configure("suggestion_body", lmargin1=16, lmargin2=16)
        self.text.tag_configure("body", font="ItalicTkDefaultFont")

        main_font = tk.font.nametofont("TkDefaultFont")

        # Underline on font looks better than underline on tag
        italic_underline_font = main_font.copy()
        italic_underline_font.configure(slant="italic", size=main_font.cget("size"), underline=True)

        self.text.tag_configure("feedback_link", justify="right", font=italic_underline_font)
        self.text.tag_bind("feedback_link", "<ButtonRelease-1>", self._ask_feedback, True)
        self.text.tag_configure("python_errors_link", justify="right", font=italic_underline_font)
        self.text.tag_bind(
            "python_errors_link",
            "<ButtonRelease-1>",
            lambda e: get_workbench().open_url("errors.rst"),
            True,
        )

        get_workbench().bind("ToplevelResponse", self.handle_toplevel_response, True)

        add_error_helper("*", GenericErrorHelper)
示例#4
0
    def __init__(self, master):
        super().__init__(master)

        self.add_checkbox(
            "assistance.open_assistant_on_errors",
            _("Open Assistant automatically when program crashes with an exception"
              ),
            row=1,
        )

        self.add_checkbox(
            "assistance.open_assistant_on_warnings",
            _("Open Assistant automatically when it has warnings for your code"
              ),
            row=2,
        )

        if get_workbench().get_option("assistance.use_pylint",
                                      "missing") != "missing":
            self.add_checkbox(
                "assistance.use_pylint",
                _("Perform selected Pylint checks"),
                row=3,
            )

        if get_workbench().get_option("assistance.use_mypy",
                                      "missing") != "missing":
            self.add_checkbox(
                "assistance.use_mypy",
                _("Perform MyPy checks"),
                row=4,
            )

        disabled_checks_label = ttk.Label(
            self, text=_("Disabled checks (one id per line)"))
        disabled_checks_label.grid(row=8, sticky="nw", pady=(10, 0))

        self.disabled_checks_box = TextFrame(
            self,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            wrap="word",
            font="TkDefaultFont",
            # cursor="arrow",
            padx=5,
            pady=5,
            height=4,
            borderwidth=1,
            relief="groove",
        )
        self.disabled_checks_box.grid(row=9, sticky="nsew", pady=(0, 10))
        self.disabled_checks_box.text.insert(
            "1.0", "\n".join(
                get_workbench().get_option("assistance.disabled_checks")))

        self.columnconfigure(0, weight=1)
        self.rowconfigure(9, weight=1)
示例#5
0
文件: ui.py 项目: kspar/thonny-easy
    def __init__(self, master, exercise_provider_class):
        self._destroyed = False
        self._poll_scheduler = None
        super().__init__(master, borderwidth=0, relief="flat")

        self._provider = exercise_provider_class(self)
        self._executor = concurrent.futures.ThreadPoolExecutor(
            max_workers=self._provider.get_max_threads())
        self._page_future = None  # type: Optional[concurrent.futures.Future]
        self._image_futures = {}

        self.columnconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)

        self.vert_scrollbar = ttk.Scrollbar(self,
                                            orient=tk.VERTICAL,
                                            style=scrollbar_style("Vertical"))
        self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=2)

        self.hor_scrollbar = ttk.Scrollbar(self,
                                           orient=tk.HORIZONTAL,
                                           style=scrollbar_style("Horizontal"))
        self.hor_scrollbar.grid(row=2, column=0, sticky=tk.NSEW)

        tktextext.fixwordbreaks(tk._default_root)
        self.init_header(row=0, column=0)

        spacer = ttk.Frame(self, height=1)
        spacer.grid(row=1, sticky="nsew")

        self._html_widget = HtmlText(
            master=self,
            renderer_class=ExerciseHtmlRenderer,
            link_and_form_handler=self._on_request_new_page,
            image_requester=self._on_request_image,
            read_only=True,
            wrap="word",
            font="TkDefaultFont",
            padx=0,
            pady=0,
            insertwidth=0,
            borderwidth=0,
            highlightthickness=0,
            yscrollcommand=self.vert_scrollbar.set,
            xscrollcommand=self.hor_scrollbar.set,
        )

        self._html_widget.grid(row=1, column=0, sticky="nsew")

        self.vert_scrollbar["command"] = self._html_widget.yview
        self.hor_scrollbar["command"] = self._html_widget.xview

        self._poll_scheduler = None

        # TODO: go to last page from previous session?
        self.go_to("/")
        self._poll_provider_responses()
示例#6
0
    def _init_previews(self):
        ttk.Label(self, text=tr("Preview")).grid(row=20,
                                                 column=1,
                                                 sticky="w",
                                                 pady=(5, 2),
                                                 columnspan=5)
        self._preview_codeview = CodeView(self,
                                          height=6,
                                          font="EditorFont",
                                          relief="groove",
                                          borderwidth=1,
                                          line_numbers=True)

        self._preview_codeview.set_content(
            textwrap.dedent("""
            def foo(bar):
                if bar is None: # """ + tr("This is a comment") + """
                    print('""" + tr("The answer is") + """', 33)

            """ + tr("unclosed_string") + ''' = "''' + tr("blah, blah") +
                            "\n").strip())
        self._preview_codeview.grid(row=21,
                                    column=1,
                                    columnspan=5,
                                    sticky=tk.NSEW)

        self._shell_preview = tktextext.TextFrame(
            self,
            text_class=BaseShellText,
            height=4,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            relief="groove",
            borderwidth=1,
            font="EditorFont",
        )
        self._shell_preview.grid(row=31,
                                 column=1,
                                 columnspan=5,
                                 sticky=tk.NSEW,
                                 pady=(5, 5))
        self._shell_preview.text.set_read_only(True)
        self._insert_shell_text()

        ttk.Label(
            self,
            text=tr(
                "NB! Some style elements change only after restarting Thonny!"
            ),
            font="BoldTkDefaultFont",
        ).grid(row=40, column=1, columnspan=5, sticky="w", pady=(5, 0))
示例#7
0
    def __init__(self, master):
        TextFrame.__init__(
            self,
            master,
            text_class=rst_utils.RstText,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            borderwidth=0,
            wrap="word",
            relief="flat",
            padx=20,
            pady=0,
            read_only=True,
        )

        self.load_rst_file("index.rst")
示例#8
0
    def __init__(self,
                 master,
                 show_hidden_files=False,
                 last_folder_setting_name=None,
                 breadcrumbs_pady=(5, 7)):
        self._cached_dir_data = {}
        ttk.Frame.__init__(self, master, borderwidth=0, relief="flat")
        self.vert_scrollbar = ttk.Scrollbar(self,
                                            orient=tk.VERTICAL,
                                            style=scrollbar_style("Vertical"))
        self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=3)

        tktextext.fixwordbreaks(tk._default_root)
        self.building_breadcrumbs = False
        self.init_header(row=0, column=0)

        spacer = ttk.Frame(self, height=1)
        spacer.grid(row=1, sticky="nsew")

        self.tree = ttk.Treeview(
            self,
            columns=["#0", "kind", "path"],
            displaycolumns=(0, ),
            yscrollcommand=self.vert_scrollbar.set,
        )
        self.tree["show"] = "headings"
        self.tree.grid(row=2, column=0, sticky=tk.NSEW)
        self.vert_scrollbar["command"] = self.tree.yview
        self.columnconfigure(0, weight=1)
        self.rowconfigure(2, weight=1)

        self.show_hidden_files = show_hidden_files
        self.tree["show"] = ("tree", )

        self.tree.bind("<3>", self.on_secondary_click, True)
        if misc_utils.running_on_mac_os():
            self.tree.bind("<2>", self.on_secondary_click, True)
            self.tree.bind("<Control-1>", self.on_secondary_click, True)
        self.tree.bind('<Double-Button-1>', self.on_double_click, True)
        self.tree.bind("<<TreeviewOpen>>", self.on_open_node)

        wb = get_workbench()
        self.folder_icon = wb.get_image("folder")
        self.python_file_icon = wb.get_image("python-file")
        self.text_file_icon = wb.get_image("text-file")
        self.generic_file_icon = wb.get_image("generic-file")
        self.hard_drive_icon = wb.get_image("hard-drive")

        self.tree.column("#0", width=500, anchor=tk.W)

        # set-up root node
        self.tree.set("", "kind", "root")
        self.menu = tk.Menu(self.tree, tearoff=False)

        self._last_folder_setting_name = last_folder_setting_name
        self.focus_into_saved_folder()
示例#9
0
 def __init__(self, master):
     TextFrame.__init__(
         self,
         master,
         text_class=rst_utils.RstText,
         vertical_scrollbar_style=scrollbar_style("Vertical"),
         horizontal_scrollbar_style=scrollbar_style("Horizontal"),
         horizontal_scrollbar_class=ui_utils.AutoScrollbar,
         borderwidth=0,
         wrap="word",
         relief="flat",
         padx=20,
         pady=0,
         read_only=True,
     )
     self.language_dir = os.path.join(
         os.path.dirname(thonny.__file__),
         "locale",
         get_workbench().get_option("general.language"),
         "HELP_CONTENT",
     )
     self.load_rst_file("index.rst")
示例#10
0
 def __init__(self, master):
     TextFrame.__init__(
         self,
         master,
         text_class=rst_utils.RstText,
         vertical_scrollbar_style=scrollbar_style("Vertical"),
         horizontal_scrollbar_style=scrollbar_style("Horizontal"),
         horizontal_scrollbar_class=ui_utils.AutoScrollbar,
         borderwidth=0,
         wrap="word",
         relief="flat",
         padx=20,
         pady=0,
         read_only=True,
     )
     # retrieve the directory of the preferred language
     # for help's .rst files ; this directory is ./ by default
     self.languageDir = "."
     self._configuration_manager = try_load_configuration(
         CONFIGURATION_FILE_NAME)
     self.languageDir = self._configuration_manager.get_option(
         "general.language", ".")
     self.load_rst_file("index.rst")
示例#11
0
    def __init__(self, master):
        super().__init__(master, borderwidth=0, relief="flat")

        self._provider_name = None
        self._provider_records_by_name = {
            p["name"]: p for p in get_workbench().get_exercise_providers()
        }

        self.columnconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)

        self.vert_scrollbar = ttk.Scrollbar(
            self, orient=tk.VERTICAL, style=scrollbar_style("Vertical")
        )
        self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=3)

        tktextext.fixwordbreaks(tk._default_root)
        self.init_header(row=0, column=0)

        self.breadcrumbs_bar.set_links(
            [
                ("_home", tr("Home")),
                ("/", "lahendus.ut.ee"),
                ("/c1", "Programmeerimise algkursus"),
                ("/c1/ch1", "1. Funktsioonid"),
                ("/c1/ch1", "14. Küpsisetort vol. 2"),
            ]
        )

        spacer = ttk.Frame(self, height=1)
        spacer.grid(row=1, sticky="nsew")

        self._html_widget = HtmlText(
            master=self,
            link_and_form_handler=self._on_request_new_page,
            read_only=True,
            wrap="word",
            font="TkDefaultFont",
            padx=10,
            pady=0,
            insertwidth=0,
            borderwidth=0,
            highlightthickness=0,
        )

        self._html_widget.grid(row=1, column=0, sticky="nsew")

        self.go_to_provider_selection_page()
示例#12
0
文件: shell.py 项目: neilk17/thonny
    def __init__(self, master, **kw):
        ttk.Frame.__init__(self, master, **kw)

        self.vert_scrollbar = ttk.Scrollbar(self,
                                            orient=tk.VERTICAL,
                                            style=scrollbar_style("Vertical"))
        self.vert_scrollbar.grid(row=1, column=2, sticky=tk.NSEW)
        get_workbench().add_command(
            "clear_shell",
            "edit",
            "Clear shell",
            self.clear_shell,
            default_sequence=_CLEAR_SHELL_DEFAULT_SEQ,
            group=200,
        )

        get_workbench().set_default("shell.max_lines", 1000)
        get_workbench().set_default("shell.squeeze_threshold", 1000)

        self.text = ShellText(
            self,
            font="EditorFont",
            # foreground="white",
            # background="#666666",
            highlightthickness=0,
            # highlightcolor="LightBlue",
            borderwidth=0,
            yscrollcommand=self.vert_scrollbar.set,
            padx=4,
            insertwidth=2,
            height=10,
            undo=True,
        )

        get_workbench().event_generate("ShellTextCreated",
                                       text_widget=self.text)

        self.text.grid(row=1, column=1, sticky=tk.NSEW)
        self.vert_scrollbar["command"] = self.text.yview
        self.columnconfigure(1, weight=1)
        self.rowconfigure(1, weight=1)

        self.notice = ttk.Label(self, text="", background="#ffff99", padding=3)
示例#13
0
    def __init__(self,
                 master,
                 show_hidden_files=False,
                 show_expand_buttons=True):
        global LOCAL_FILES_ROOT_TEXT
        LOCAL_FILES_ROOT_TEXT = _("This computer")

        self.show_expand_buttons = show_expand_buttons
        self._cached_child_data = {}
        self.path_to_highlight = None

        ttk.Frame.__init__(self, master, borderwidth=0, relief="flat")
        self.vert_scrollbar = ttk.Scrollbar(self,
                                            orient=tk.VERTICAL,
                                            style=scrollbar_style("Vertical"))
        self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=3)

        tktextext.fixwordbreaks(tk._default_root)
        self.building_breadcrumbs = False
        self.init_header(row=0, column=0)

        spacer = ttk.Frame(self, height=1)
        spacer.grid(row=1, sticky="nsew")

        self.tree = ttk.Treeview(
            self,
            columns=["#0", "kind", "path", "name", "time", "size"],
            displaycolumns=(
                # 4,
                # 5
            ),
            yscrollcommand=self.vert_scrollbar.set,
            selectmode="extended",
        )
        self.tree.grid(row=2, column=0, sticky=tk.NSEW)
        self.vert_scrollbar["command"] = self.tree.yview
        self.columnconfigure(0, weight=1)
        self.rowconfigure(2, weight=1)

        self.show_hidden_files = show_hidden_files
        self.tree["show"] = "tree"

        self.tree.bind("<3>", self.on_secondary_click, True)
        if misc_utils.running_on_mac_os():
            self.tree.bind("<2>", self.on_secondary_click, True)
            self.tree.bind("<Control-1>", self.on_secondary_click, True)
        self.tree.bind("<Double-Button-1>", self.on_double_click, True)
        self.tree.bind("<<TreeviewOpen>>", self.on_open_node)

        wb = get_workbench()
        self.folder_icon = wb.get_image("folder")
        self.python_file_icon = wb.get_image("python-file")
        self.text_file_icon = wb.get_image("text-file")
        self.generic_file_icon = wb.get_image("generic-file")
        self.hard_drive_icon = wb.get_image("hard-drive")

        self.tree.column("#0", width=200, anchor=tk.W)
        self.tree.heading("#0", text="Name", anchor=tk.W)
        self.tree.column("time", width=60, anchor=tk.W)
        self.tree.heading("time", text="Time", anchor=tk.W)
        self.tree.column("size", width=40, anchor=tk.E)
        self.tree.heading("size", text="Size (bytes)", anchor=tk.E)
        self.tree.column("kind", width=30, anchor=tk.W)
        #         self.tree.heading("kind", text="Kind")
        #         self.tree.column("path", width=300, anchor=tk.W)
        #         self.tree.heading("path", text="path")
        #         self.tree.column("name", width=60, anchor=tk.W)
        #         self.tree.heading("name", text="name")

        # set-up root node
        self.tree.set(ROOT_NODE_ID, "kind", "root")
        self.menu = tk.Menu(self.tree, tearoff=False)
        self.current_focus = None
示例#14
0
    def _create_widgets(self, parent):

        header_frame = ttk.Frame(parent)
        header_frame.grid(row=1,
                          column=0,
                          sticky="nsew",
                          padx=15,
                          pady=(15, 0))
        header_frame.columnconfigure(0, weight=1)
        header_frame.rowconfigure(1, weight=1)

        name_font = tk.font.nametofont("TkDefaultFont").copy()
        name_font.configure(size=16)
        self.search_box = ttk.Entry(header_frame)
        self.search_box.grid(row=1, column=0, sticky="nsew")
        self.search_box.bind("<Return>", self._on_search, False)

        self.search_button = ttk.Button(
            header_frame,
            text=_("Find package from PyPI"),
            command=self._on_search,
            width=25,
        )
        self.search_button.grid(row=1, column=1, sticky="nse", padx=(10, 0))

        main_pw = tk.PanedWindow(
            parent,
            orient=tk.HORIZONTAL,
            background=lookup_style_option("TPanedWindow", "background"),
            sashwidth=15,
        )
        main_pw.grid(row=2, column=0, sticky="nsew", padx=15, pady=15)
        parent.rowconfigure(2, weight=1)
        parent.columnconfigure(0, weight=1)

        listframe = ttk.Frame(main_pw, relief="flat", borderwidth=1)
        listframe.rowconfigure(0, weight=1)
        listframe.columnconfigure(0, weight=1)

        self.listbox = ui_utils.ThemedListbox(
            listframe,
            activestyle="dotbox",
            width=20,
            height=18,
            selectborderwidth=0,
            relief="flat",
            # highlightthickness=4,
            # highlightbackground="red",
            # highlightcolor="green",
            borderwidth=0,
        )
        self.listbox.insert("end", " <INSTALL>")
        self.listbox.bind("<<ListboxSelect>>", self._on_listbox_select, True)
        self.listbox.grid(row=0, column=0, sticky="nsew")
        list_scrollbar = AutoScrollbar(listframe,
                                       orient=tk.VERTICAL,
                                       style=scrollbar_style("Vertical"))
        list_scrollbar.grid(row=0, column=1, sticky="ns")
        list_scrollbar["command"] = self.listbox.yview
        self.listbox["yscrollcommand"] = list_scrollbar.set

        info_frame = ttk.Frame(main_pw)
        info_frame.columnconfigure(0, weight=1)
        info_frame.rowconfigure(1, weight=1)

        main_pw.add(listframe)
        main_pw.add(info_frame)

        self.name_label = ttk.Label(info_frame, text="", font=name_font)
        self.name_label.grid(row=0, column=0, sticky="w", padx=5)

        info_text_frame = tktextext.TextFrame(
            info_frame,
            read_only=True,
            horizontal_scrollbar=False,
            background=lookup_style_option("TFrame", "background"),
            vertical_scrollbar_class=AutoScrollbar,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            width=60,
            height=10,
        )
        info_text_frame.configure(borderwidth=0)
        info_text_frame.grid(row=1,
                             column=0,
                             columnspan=4,
                             sticky="nsew",
                             pady=(0, 10))
        self.info_text = info_text_frame.text
        link_color = lookup_style_option("Url.TLabel", "foreground", "red")
        self.info_text.tag_configure("url",
                                     foreground=link_color,
                                     underline=True)
        self.info_text.tag_bind("url", "<ButtonRelease-1>",
                                self._handle_url_click)
        self.info_text.tag_bind(
            "url", "<Enter>", lambda e: self.info_text.config(cursor="hand2"))
        self.info_text.tag_bind("url", "<Leave>",
                                lambda e: self.info_text.config(cursor=""))
        self.info_text.tag_configure("install_file",
                                     foreground=link_color,
                                     underline=True)
        self.info_text.tag_bind("install_file", "<ButtonRelease-1>",
                                self._handle_install_file_click)
        self.info_text.tag_bind(
            "install_file", "<Enter>",
            lambda e: self.info_text.config(cursor="hand2"))
        self.info_text.tag_bind("install_file", "<Leave>",
                                lambda e: self.info_text.config(cursor=""))

        default_font = tk.font.nametofont("TkDefaultFont")
        self.info_text.configure(font=default_font, wrap="word")

        bold_font = default_font.copy()
        # need to explicitly copy size, because Tk 8.6 on certain Ubuntus use bigger font in copies
        bold_font.configure(weight="bold", size=default_font.cget("size"))
        self.info_text.tag_configure("caption", font=bold_font)
        self.info_text.tag_configure("bold", font=bold_font)

        self.command_frame = ttk.Frame(info_frame)
        self.command_frame.grid(row=2, column=0, sticky="w")

        self.install_button = ttk.Button(self.command_frame,
                                         text=_(" Upgrade "),
                                         command=self._on_click_install)

        self.install_button.grid(row=0, column=0, sticky="w", padx=0)

        self.uninstall_button = ttk.Button(
            self.command_frame,
            text=_("Uninstall"),
            command=lambda: self._perform_action("uninstall"),
        )

        self.uninstall_button.grid(row=0, column=1, sticky="w", padx=(5, 0))

        self.advanced_button = ttk.Button(
            self.command_frame,
            text="...",
            width=3,
            command=lambda: self._perform_action("advanced"),
        )

        self.advanced_button.grid(row=0, column=2, sticky="w", padx=(5, 0))

        self.close_button = ttk.Button(info_frame,
                                       text=_("Close"),
                                       command=self._on_close)
        self.close_button.grid(row=2, column=3, sticky="e")
    def __init__(self, master):
        super().__init__(master)

        ui_utils.create_url_label(
            self,
            "https://github.com/thonny/thonny/wiki/Friendly-traceback",
            text=_("Friendly traceback level"),
        ).grid(row=1, column=0, sticky="w")

        self.add_combobox(
            "assistance.friendly_traceback_level",
            values=[0, 1, 2, 3, 4, 5, 6, 7, 9],
            row=1,
            column=1,
            width=3,
            padx=5,
        )

        self.add_checkbox(
            "assistance.open_assistant_on_errors",
            _("Open Assistant automatically when program crashes with an exception"
              ),
            row=2,
            columnspan=2,
        )

        self.add_checkbox(
            "assistance.open_assistant_on_warnings",
            _("Open Assistant automatically when it has warnings for your code"
              ),
            row=3,
            columnspan=2,
        )

        if get_workbench().get_option("assistance.use_pylint",
                                      "missing") != "missing":
            self.add_checkbox("assistance.use_pylint",
                              _("Perform selected Pylint checks"),
                              row=4,
                              columnspan=2)

        if get_workbench().get_option("assistance.use_mypy",
                                      "missing") != "missing":
            self.add_checkbox("assistance.use_mypy",
                              _("Perform MyPy checks"),
                              row=5,
                              columnspan=2)

        disabled_checks_label = ttk.Label(
            self, text=_("Disabled checks (one id per line)"))
        disabled_checks_label.grid(row=8,
                                   sticky="nw",
                                   pady=(10, 0),
                                   columnspan=2)

        self.disabled_checks_box = TextFrame(
            self,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            wrap="word",
            font="TkDefaultFont",
            # cursor="arrow",
            padx=5,
            pady=5,
            height=4,
            borderwidth=1,
            relief="groove",
        )
        self.disabled_checks_box.grid(row=9,
                                      sticky="nsew",
                                      pady=(0, 10),
                                      columnspan=2)
        self.disabled_checks_box.text.insert(
            "1.0", "\n".join(
                get_workbench().get_option("assistance.disabled_checks")))

        self.columnconfigure(1, weight=1)
        self.rowconfigure(9, weight=1)
示例#16
0
    def __init__(self,
                 master,
                 show_hidden_files=False,
                 last_folder_setting_name=None):
        ttk.Frame.__init__(self, master, borderwidth=0, relief="flat")
        self.vert_scrollbar = ttk.Scrollbar(self,
                                            orient=tk.VERTICAL,
                                            style=scrollbar_style("Vertical"))
        self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=4)

        self.toolbar = ttk.Frame(self, style="ViewToolbar.TFrame")
        self.toolbar.grid(row=0, sticky="nsew")
        self.toolbar.grid(row=1, sticky="nsew")
        self.init_toolbar()

        tktextext.fixwordbreaks(tk._default_root)
        self.building_breadcrumbs = False
        self.path_bar = tktextext.TweakableText(self,
                                                borderwidth=0,
                                                relief="flat",
                                                height=1,
                                                font="TkDefaultFont",
                                                wrap="word",
                                                padx=6)
        self.init_path_bar()

        self.set_breadcrumbs(
            "This computer\\C:\\Users\\Aivar\\Documents\\Python\\PyGame\\NikaNaka"
        )

        self.path_bar.grid(row=2, sticky="nsew")

        self.tree = ttk.Treeview(
            self,
            columns=["#0", "kind", "path"],
            displaycolumns=(0, ),
            yscrollcommand=self.vert_scrollbar.set,
        )
        self.tree["show"] = "headings"
        self.tree.grid(row=3, column=0, sticky=tk.NSEW)
        self.vert_scrollbar["command"] = self.tree.yview
        self.columnconfigure(0, weight=1)
        self.rowconfigure(3, weight=1)

        self.show_hidden_files = show_hidden_files
        self.tree["show"] = ("tree", )

        wb = get_workbench()
        self.folder_icon = wb.get_image("folder")
        self.python_file_icon = wb.get_image("python-file")
        self.text_file_icon = wb.get_image("text-file")
        self.generic_file_icon = wb.get_image("generic-file")
        self.hard_drive_icon = wb.get_image("hard-drive")

        self.tree.column("#0", width=500, anchor=tk.W)

        # set-up root node
        self.tree.set("", "kind", "root")
        self.tree.set("", "path", "")
        self.refresh_tree()

        self.tree.bind("<<TreeviewOpen>>", self.on_open_node)

        self._last_folder_setting_name = last_folder_setting_name
        self.open_initial_folder()
示例#17
0
    def __init__(self, master, main_file_path, all_snapshots):
        super().__init__(master=master)
        main_frame = ttk.Frame(self)
        main_frame.grid(row=0, column=0, sticky="nsew")
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        self.main_file_path = main_file_path
        self.snapshots = self._select_unsent_snapshots(all_snapshots)

        self.title("Send feedback for Assistant")

        padx = 15

        intro_label = ttk.Label(
            main_frame,
            text="Below are the messages Assistant gave you in response to " +
            ("using the shell" if self._happened_in_shell() else "testing '" +
             os.path.basename(main_file_path) + "'") + " since " +
            self._get_since_str() + ".\n\n" +
            "In order to improve this feature, Thonny developers would love to know how "
            +
            "useful or confusing these messages were. We will only collect version "
            + "information and the data you enter or approve on this form.",
            wraplength=550,
        )
        intro_label.grid(row=1,
                         column=0,
                         columnspan=3,
                         sticky="nw",
                         padx=padx,
                         pady=(15, 15))

        tree_label = ttk.Label(
            main_frame,
            text=
            "Which messages were helpful (H) or confusing (C)?       Click on  [  ]  to mark!",
        )
        tree_label.grid(row=2,
                        column=0,
                        columnspan=3,
                        sticky="nw",
                        padx=padx,
                        pady=(15, 0))
        tree_frame = ui_utils.TreeFrame(
            main_frame,
            columns=["helpful", "confusing", "title", "group", "symbol"],
            displaycolumns=["helpful", "confusing", "title"],
            height=10,
            borderwidth=1,
            relief="groove",
        )
        tree_frame.grid(row=3,
                        column=0,
                        columnspan=3,
                        sticky="nsew",
                        padx=padx)
        self.tree = tree_frame.tree
        self.tree.column("helpful", width=30, anchor=tk.CENTER, stretch=False)
        self.tree.column("confusing",
                         width=30,
                         anchor=tk.CENTER,
                         stretch=False)
        self.tree.column("title", width=350, anchor=tk.W, stretch=True)

        self.tree.heading("helpful", text="H", anchor=tk.CENTER)
        self.tree.heading("confusing", text="C", anchor=tk.CENTER)
        self.tree.heading("title", text="Group / Message", anchor=tk.W)
        self.tree["show"] = ("headings", )
        self.tree.bind("<1>", self._on_tree_click, True)
        main_font = tk.font.nametofont("TkDefaultFont")
        bold_font = main_font.copy()
        bold_font.configure(weight="bold", size=main_font.cget("size"))
        self.tree.tag_configure("group", font=bold_font)

        self.include_thonny_id_var = tk.IntVar(value=1)
        include_thonny_id_check = ttk.Checkbutton(
            main_frame,
            variable=self.include_thonny_id_var,
            onvalue=1,
            offvalue=0,
            text=
            "Include Thonny's installation time (allows us to group your submissions)",
        )
        include_thonny_id_check.grid(row=4,
                                     column=0,
                                     columnspan=3,
                                     sticky="nw",
                                     padx=padx,
                                     pady=(5, 0))

        self.include_snapshots_var = tk.IntVar(value=1)
        include_snapshots_check = ttk.Checkbutton(
            main_frame,
            variable=self.include_snapshots_var,
            onvalue=1,
            offvalue=0,
            text=
            "Include snapshots of the code and Assistant responses at each run",
        )
        include_snapshots_check.grid(row=5,
                                     column=0,
                                     columnspan=3,
                                     sticky="nw",
                                     padx=padx,
                                     pady=(0, 0))

        comments_label = ttk.Label(main_frame,
                                   text="Any comments? Enhancement ideas?")
        comments_label.grid(row=6,
                            column=0,
                            columnspan=3,
                            sticky="nw",
                            padx=padx,
                            pady=(15, 0))
        self.comments_text_frame = tktextext.TextFrame(
            main_frame,
            vertical_scrollbar_style=scrollbar_style("Vertical"),
            horizontal_scrollbar_style=scrollbar_style("Horizontal"),
            horizontal_scrollbar_class=ui_utils.AutoScrollbar,
            wrap="word",
            font="TkDefaultFont",
            # cursor="arrow",
            padx=5,
            pady=5,
            height=4,
            borderwidth=1,
            relief="groove",
        )
        self.comments_text_frame.grid(row=7,
                                      column=0,
                                      columnspan=3,
                                      sticky="nsew",
                                      padx=padx)

        url_font = tk.font.nametofont("TkDefaultFont").copy()
        url_font.configure(underline=1, size=url_font.cget("size"))
        preview_link = ttk.Label(
            main_frame,
            text="(Preview the data to be sent)",
            style="Url.TLabel",
            cursor="hand2",
            font=url_font,
        )
        preview_link.bind("<1>", self._preview_submission_data, True)
        preview_link.grid(row=8, column=0, sticky="nw", padx=15, pady=15)

        submit_button = ttk.Button(main_frame,
                                   text="Submit",
                                   width=10,
                                   command=self._submit_data)
        submit_button.grid(row=8, column=0, sticky="ne", padx=0, pady=15)

        cancel_button = ttk.Button(main_frame,
                                   text="Cancel",
                                   width=7,
                                   command=self._close)
        cancel_button.grid(row=8,
                           column=1,
                           sticky="ne",
                           padx=(10, 15),
                           pady=15)

        self.protocol("WM_DELETE_WINDOW", self._close)
        self.bind("<Escape>", self._close, True)

        main_frame.columnconfigure(0, weight=1)
        main_frame.rowconfigure(3, weight=3)
        main_frame.rowconfigure(6, weight=2)

        self._empty_box = "[  ]"
        self._checked_box = "[X]"
        self._populate_tree()