Beispiel #1
0
    def __init__(self):
        self._main_dir = os.path.dirname(sys.modules["thonny"].__file__)
        self._heap = {
        }  # WeakValueDictionary would be better, but can't store reference to None
        site.sethelper()  # otherwise help function is not available
        pydoc.pager = pydoc.plainpager  # otherwise help command plays tricks
        self._install_fake_streams()
        self._current_executor = None
        self._io_level = 0

        original_argv = sys.argv.copy()
        original_path = sys.path.copy()

        # clean up path
        sys.path = [d for d in sys.path if d != ""]

        # script mode
        if len(sys.argv) > 1:
            special_names_to_remove = set()
            sys.argv[:] = sys.argv[
                1:]  # shift argv[1] to position of script name
            sys.path.insert(0, os.path.abspath(os.path.dirname(
                sys.argv[0])))  # add program's dir
            __main__.__dict__["__file__"] = sys.argv[0]
            # TODO: inspect.getdoc

        # shell mode
        else:
            special_names_to_remove = {"__file__", "__cached__"}
            sys.argv[:] = [""]  # empty "script name"
            sys.path.insert(0, "")  # current dir

        # clean __main__ global scope
        for key in list(__main__.__dict__.keys()):
            if not key.startswith("__") or key in special_names_to_remove:
                del __main__.__dict__[key]

        # unset __doc__, then exec dares to write doc of the script there
        __main__.__doc__ = None

        self.send_message("Ready",
                          main_dir=self._main_dir,
                          original_argv=original_argv,
                          original_path=original_path,
                          argv=sys.argv,
                          path=sys.path,
                          python_version=get_python_version_string(),
                          python_executable=sys.executable,
                          cwd=os.getcwd())
Beispiel #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(_("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="hand2",
                              font=url_font)
        url_label.grid()
        url_label.bind("<Button-1>", lambda _: webbrowser.open(url))

        if platform.system() == "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() +
            "Tk " + ui_utils.get_tk_version_str(),
        )
        platform_label.grid(pady=20)

        credits_label = ttk.Label(
            main_frame,
            text=_("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="hand2",
            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" +
            _("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="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)
Beispiel #3
0
    def __init__(self, master):
        tk.Toplevel.__init__(self, 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("About Thonny")
        if misc_utils.running_on_mac_os():
            self.configure(background="systemSheetBackground")
        self.resizable(height=tk.FALSE, width=tk.FALSE)
        self.transient(master)
        self.grab_set()
        self.protocol("WM_DELETE_WINDOW", self._ok)

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

        heading_font = 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 = "http://thonny.org"
        url_font = font.nametofont("TkDefaultFont").copy()
        url_font.configure(underline=1)
        url_label = ttk.Label(
            main_frame,
            text=url,
            cursor="hand2",
            foreground="blue",
            font=url_font,
        )
        url_label.grid()
        url_label.bind("<Button-1>", lambda _: webbrowser.open(url))

        if platform.system() == "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() + "Tk " +
                                   ui_utils.get_tk_version_str())
        platform_label.grid(pady=20)

        credits_label = ttk.Label(
            main_frame,
            text="Made in\nUniversity of Tartu, Estonia\n" +
            "with the help from\nopen-source community",
            cursor="hand2",
            foreground="blue",
            font=url_font,
            justify=tk.CENTER)
        credits_label.grid()
        credits_label.bind(
            "<Button-1>", lambda _: webbrowser.open(
                "https://bitbucket.org/plas/thonny/src/master/CREDITS.rst"))

        license_font = 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" + "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="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)

        ui_utils.center_window(self, master)
        self.wait_window()
Beispiel #4
0
    def __init__(self, master, version):
        tk.Toplevel.__init__(self, master)

        #self.geometry("200x200")
        # TODO: position in the center of master
        self.geometry(
            "+%d+%d" %
            (master.winfo_rootx() + master.winfo_width() // 2 - 50,
             master.winfo_rooty() + master.winfo_height() // 2 - 150))

        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("About Thonny")
        if misc_utils.running_on_mac_os():
            self.configure(background="systemSheetBackground")
        self.resizable(height=tk.FALSE, width=tk.FALSE)
        self.transient(master)
        self.grab_set()
        self.protocol("WM_DELETE_WINDOW", self._ok)

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

        version_str = "%d.%d.%d" % version.version
        if version.prerelease:
            version_str += "".join(map(str, version.prerelease))

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

        url = "http://thonny.org"
        url_font = font.nametofont("TkDefaultFont").copy()
        url_font.configure(underline=1)
        url_label = ttk.Label(
            main_frame,
            text=url,
            cursor="hand2",
            foreground="blue",
            font=url_font,
        )
        url_label.grid()
        url_label.bind("<Button-1>", lambda _: webbrowser.open(url))

        if platform.system() == "Linux":
            import distro
            system_desc = distro.name(True)
            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() + "Tk " +
                                   self.tk.call('info', 'patchlevel'))
        platform_label.grid(pady=20)

        license_font = font.nametofont("TkDefaultFont").copy()
        license_font.configure(size=7)
        license_label = ttk.Label(
            main_frame,
            text="Coppyright (©) " + str(datetime.datetime.now().year) +
            " Aivar Annamaa\n" + "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\n",
            justify=tk.CENTER,
            font=license_font)
        license_label.grid()

        ok_button = ttk.Button(main_frame,
                               text="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)
        self.wait_window()