Exemplo n.º 1
0
    def on_motion(self, event):
        text = cast(SyntaxText, event.widget)
        if self.proper_modifier_is_pressed(event):
            self.remove_underline(event)
            start_index = text.index(f"@{event.x},{event.y} wordstart")
            end_index = text.index(f"@{event.x},{event.y} wordend")
            # sometimes, start_index will contain wrong line number
            start_line, start_col = start_index.split(".")
            end_line, end_col = end_index.split(".")
            if start_line != end_line:
                start_index = end_line + "." + start_col

            word = text.get(start_index, end_index)
            if (
                word
                and (word[0].isalpha() or word[0] == "_")
                # and not iskeyword(word)
                and self._index_doesnt_have_tags(
                    text,
                    start_index,
                    {"string", "string3", "open_string", "open_string3", "comment"},
                )
            ):
                text.tag_add("name_link", start_index, end_index)
                text["cursor"] = get_hyperlink_cursor()
                text.underlined = True
        else:
            if getattr(text, "underlined", False):
                self.remove_underline(event)
Exemplo n.º 2
0
    def __init__(self, master):
        import webbrowser

        super().__init__(master)

        main_frame = ttk.Frame(self)
        main_frame.grid(sticky=tk.NSEW, ipadx=15, ipady=15)
        main_frame.rowconfigure(0, weight=1)
        main_frame.columnconfigure(0, weight=1)

        self.title(tr("About Thonny"))
        self.resizable(height=tk.FALSE, width=tk.FALSE)
        self.protocol("WM_DELETE_WINDOW", self._ok)

        # bg_frame = ttk.Frame(self) # gives proper color in aqua
        # bg_frame.grid()

        heading_font = tkinter.font.nametofont("TkHeadingFont").copy()
        heading_font.configure(size=19, weight="bold")
        heading_label = ttk.Label(
            main_frame, text="Thonny " + thonny.get_version(), font=heading_font
        )
        heading_label.grid()

        url = "https://thonny.org"
        url_font = tkinter.font.nametofont("TkDefaultFont").copy()
        url_font.configure(underline=1)
        url_label = ttk.Label(
            main_frame, text=url, style="Url.TLabel", cursor=get_hyperlink_cursor(), font=url_font
        )
        url_label.grid()
        url_label.bind("<Button-1>", lambda _: webbrowser.open(url))

        if sys.platform == "linux":
            try:
                import distro  # distro don't need to be installed

                system_desc = distro.name(True)
            except ImportError:
                system_desc = "Linux"

            if "32" not in system_desc and "64" not in system_desc:
                system_desc += " " + self.get_os_word_size_guess()
        else:
            system_desc = (
                platform.system() + " " + platform.release() + " " + self.get_os_word_size_guess()
            )

        platform_label = ttk.Label(
            main_frame,
            justify=tk.CENTER,
            text=system_desc
            + "\n"
            + "Python "
            + get_python_version_string(maxsize=sys.maxsize)
            + "\n"
            + "Tk "
            + ui_utils.get_tk_version_str(),
        )
        platform_label.grid(pady=20)

        credits_label = ttk.Label(
            main_frame,
            text=tr(
                "Made in\n"
                + "University of Tartu, Estonia,\n"
                + "with the help from\n"
                + "open-source community,\n"
                + "Raspberry Pi Foundation\n"
                + "and Cybernetica AS"
            ),
            style="Url.TLabel",
            cursor=get_hyperlink_cursor(),
            font=url_font,
            justify="center",
        )
        credits_label.grid()
        credits_label.bind(
            "<Button-1>",
            lambda _: webbrowser.open("https://github.com/thonny/thonny/blob/master/CREDITS.rst"),
        )

        license_font = tkinter.font.nametofont("TkDefaultFont").copy()
        license_font.configure(size=7)
        license_label = ttk.Label(
            main_frame,
            text="Copyright (©) "
            + str(datetime.datetime.now().year)
            + " Aivar Annamaa\n"
            + tr(
                "This program comes with\n"
                + "ABSOLUTELY NO WARRANTY!\n"
                + "It is free software, and you are welcome to\n"
                + "redistribute it under certain conditions, see\n"
                + "https://opensource.org/licenses/MIT\n"
                + "for details"
            ),
            justify=tk.CENTER,
            font=license_font,
        )
        license_label.grid(pady=20)

        ok_button = ttk.Button(main_frame, text=tr("OK"), command=self._ok, default="active")
        ok_button.grid(pady=(0, 15))
        ok_button.focus_set()

        self.bind("<Return>", self._ok, True)
        self.bind("<Escape>", self._ok, True)
Exemplo n.º 3
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=35, anchor=tk.CENTER, stretch=False)
        self.tree.column("confusing",
                         width=35,
                         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=get_hyperlink_cursor(),
            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()
Exemplo n.º 4
0
 def _hyperlink_enter(self, event):
     self.config(cursor=get_hyperlink_cursor())