コード例 #1
0
ファイル: workbench.py プロジェクト: byache/thonny
    def _init_window(self):

        self.set_default("layout.zoomed", False)
        self.set_default("layout.top", 15)
        self.set_default("layout.left", 150)
        self.set_default("layout.width", 700)
        self.set_default("layout.height", 650)
        self.set_default("layout.w_width", 200)
        self.set_default("layout.e_width", 200)
        self.set_default("layout.s_height", 200)

        # I don't actually need saved options for Full screen/maximize view,
        # but it's easier to create menu items, if I use configuration manager's variables
        self.set_default("view.full_screen", False)
        self.set_default("view.maximize_view", False)

        # In order to avoid confusion set these settings to False
        # even if they were True when Thonny was last run
        self.set_option("view.full_screen", False)
        self.set_option("view.maximize_view", False)

        self.geometry("{0}x{1}+{2}+{3}".format(
            self.get_option("layout.width"), self.get_option("layout.height"),
            self.get_option("layout.left"), self.get_option("layout.top")))

        if self.get_option("layout.zoomed"):
            ui_utils.set_zoomed(self, True)

        self.protocol("WM_DELETE_WINDOW", self._on_close)

        # Window icons
        window_icons = self.get_option("theme.window_icons")
        if window_icons:
            imgs = [self.get_image(filename) for filename in window_icons]
            self.iconphoto(True, *imgs)
        elif running_on_linux() and ui_utils.get_tk_version_info() >= (8, 6):
            self.iconphoto(True, self.get_image("thonny.png"))
        else:
            icon_file = os.path.join(self.get_package_dir(), "res",
                                     "thonny.ico")
            try:
                self.iconbitmap(icon_file, default=icon_file)
            except:
                try:
                    # seems to work in mac
                    self.iconbitmap(icon_file)
                except:
                    pass  # TODO: try to get working in Ubuntu

        self.bind("<Configure>", self._on_configure, True)
コード例 #2
0
ファイル: editor_helpers.py プロジェクト: ZCG-coder/thonny
    def _set_window_attributes(self):
        if running_on_mac_os():
            try:
                # Must be the first thing to do after creating window
                # https://wiki.tcl-lang.org/page/MacWindowStyle
                self.tk.call("::tk::unsupported::MacWindowStyle", "style",
                             self._w, "help", "noActivates")
                if get_tk_version_info() >= (8, 6, 10) and running_on_mac_os():
                    self.wm_overrideredirect(1)
            except tk.TclError:
                pass
        else:
            self.wm_overrideredirect(1)
        self.wm_transient(get_workbench())

        # From IDLE
        # TODO: self.update_idletasks()  # Need for tk8.6.8 on macOS: #40128.
        self.lift()
コード例 #3
0
    def __init__(self, codeview):
        tk.Toplevel.__init__(self, codeview.winfo_toplevel())
        text = tk.Text(self, **self.get_text_options())
        BaseExpressionBox.__init__(self, codeview, text)
        self.text.grid()

        if running_on_mac_os():
            try:
                # NB! Must be the first thing to do after creation
                # https://wiki.tcl-lang.org/page/MacWindowStyle
                self.tk.call("::tk::unsupported::MacWindowStyle", "style",
                             self._w, "help", "noActivates")
            except TclError:
                pass
        else:
            raise RuntimeError("Should be used only on Mac")

        self.resizable(False, False)
        if get_tk_version_info() >= (8, 6, 10) and running_on_mac_os():
            self.wm_overrideredirect(1)
        self.wm_transient(codeview.winfo_toplevel())
        self.lift()
コード例 #4
0
ファイル: rst_utils.py プロジェクト: Pydiderot/pydiderotIDE
    def configure_tags(self):
        main_font = tk.font.nametofont("TkDefaultFont")

        bold_font = main_font.copy()
        bold_font.configure(weight="bold", size=main_font.cget("size"))

        italic_font = main_font.copy()
        italic_font.configure(slant="italic", size=main_font.cget("size"))

        h1_font = main_font.copy()
        h1_font.configure(size=main_font.cget("size") * 2, weight="bold")

        h2_font = main_font.copy()
        h2_font.configure(size=round(main_font.cget("size") * 1.5),
                          weight="bold")

        h3_font = main_font.copy()
        h3_font.configure(size=main_font.cget("size"), weight="bold")

        small_font = main_font.copy()
        small_font.configure(size=round(main_font.cget("size") * 0.8))
        small_italic_font = italic_font.copy()
        small_italic_font.configure(size=round(main_font.cget("size") * 0.8))

        # Underline on font looks better than underline on tag
        underline_font = main_font.copy()
        underline_font.configure(underline=True)

        self.tag_configure("h1", font=h1_font, spacing3=5)
        self.tag_configure("h2", font=h2_font, spacing3=5)
        self.tag_configure("h3", font=h3_font, spacing3=5)
        self.tag_configure("p", spacing1=0, spacing3=10, spacing2=0)
        self.tag_configure("line_block", spacing1=0, spacing3=10, spacing2=0)
        self.tag_configure("em", font=italic_font)
        self.tag_configure("strong", font=bold_font)

        # TODO: hyperlink syntax options may require different background as well
        self.tag_configure(
            "a",
            **{
                **get_syntax_options_for_tag("hyperlink"), "underline": False
            },
            font=underline_font)
        self.tag_configure("small", font=small_font)
        self.tag_configure("light", foreground="gray")
        self.tag_configure("remark", font=small_italic_font)
        self.tag_bind("a", "<Enter>", self._hyperlink_enter)
        self.tag_bind("a", "<Leave>", self._hyperlink_leave)

        self.tag_configure("topic_title", lmargin2=16, font=bold_font)
        self.tag_configure("topic_body", lmargin1=16, lmargin2=16)
        self.tag_configure(
            "code",
            font="TkFixedFont",
            # wrap="none", # TODO: needs automatic hor-scrollbar and better padding mgmt
            # background="#eeeeee"
        )
        # if ui_utils.get_tk_version_info() >= (8,6,6):
        #    self.tag_configure("code", lmargincolor=self["background"])

        for i in range(1, 6):
            self.tag_configure("list%d" % i,
                               lmargin1=i * 10,
                               lmargin2=i * 10 + 10)

        toti_code_font = bold_font.copy()
        toti_code_font.configure(
            family=tk.font.nametofont("TkFixedFont").cget("family"),
            size=bold_font.cget("size"))
        self.tag_configure("topic_title_code", font=toti_code_font)
        self.tag_raise("topic_title_code", "code")
        self.tag_raise("topic_title_code", "topic_title")
        self.tag_raise("a", "topic_title")

        # TODO: topic_title + em
        self.tag_raise("em", "topic_title")
        self.tag_raise("a", "em")
        self.tag_raise("a", "topic_body")
        self.tag_raise("a", "topic_title")

        if ui_utils.get_tk_version_info() >= (8, 6, 6):
            self.tag_configure("sel", lmargincolor=self["background"])
        self.tag_raise("sel")
コード例 #5
0
    def __init__(self, master, cnf={}, **kw):

        super().__init__(master, cnf, **kw)
        self.bindtags(self.bindtags() + ("ShellText", ))

        self._before_io = True
        self._command_history = (
            []
        )  # actually not really history, because each command occurs only once
        self._command_history_current_index = None

        self.bind("<Up>", self._arrow_up, True)
        self.bind("<Down>", self._arrow_down, True)
        self.bind("<KeyPress>", self._text_key_press, True)
        self.bind("<KeyRelease>", self._text_key_release, True)

        prompt_font = tk.font.nametofont("BoldEditorFont")
        vert_spacing = 10
        io_indent = 16
        code_indent = prompt_font.measure(">>> ")

        self.tag_configure("command",
                           lmargin1=code_indent,
                           lmargin2=code_indent)
        self.tag_configure(
            "io",
            lmargin1=io_indent,
            lmargin2=io_indent,
            rmargin=io_indent,
            font="IOFont",
        )
        if ui_utils.get_tk_version_info() >= (8, 6, 6):
            self.tag_configure(
                "io",
                lmargincolor=get_syntax_options_for_tag("TEXT")["background"])

        self.tag_bind("hyperlink", "<ButtonRelease-1>", self._handle_hyperlink)
        self.tag_bind("hyperlink", "<Enter>", self._hyperlink_enter)
        self.tag_bind("hyperlink", "<Leave>", self._hyperlink_leave)
        self.tag_raise("hyperlink")

        self.tag_configure("vertically_spaced", spacing1=vert_spacing)

        # Underline on font looks better than underline on tag
        io_hyperlink_font = tk.font.nametofont("IOFont").copy()
        io_hyperlink_font.configure(underline=get_syntax_options_for_tag(
            "hyperlink").get("underline", True))
        self.tag_configure("io_hyperlink",
                           underline=False,
                           font=io_hyperlink_font)
        self.tag_raise("io_hyperlink", "hyperlink")

        self.tag_configure("suppressed_io", elide=True)

        # create 3 marks: input_start shows the place where user entered but not-yet-submitted
        # input starts, output_end shows the end of last output,
        # output_insert shows where next incoming program output should be inserted
        self.mark_set("input_start", "end-1c")
        self.mark_gravity("input_start", tk.LEFT)

        self.mark_set("output_end", "end-1c")
        self.mark_gravity("output_end", tk.LEFT)

        self.mark_set("output_insert", "end-1c")
        self.mark_gravity("output_insert", tk.RIGHT)

        self.active_object_tags = set()

        self._last_welcome_text = None

        get_workbench().bind("InputRequest", self._handle_input_request, True)
        get_workbench().bind("ProgramOutput", self._handle_program_output,
                             True)
        get_workbench().bind("ToplevelResponse",
                             self._handle_toplevel_response, True)
        get_workbench().bind("DebuggerResponse",
                             self._handle_fancy_debugger_progress, True)

        self._menu = ShellMenu(self)
コード例 #6
0
ファイル: htmltext.py プロジェクト: kspar/thonny-easy
    def _configure_tags(self):
        main_font = tkfont.nametofont("TkDefaultFont")
        x_padding = main_font.measure("m")

        bold_font = main_font.copy()
        bold_font.configure(weight="bold", size=main_font.cget("size"))

        italic_font = main_font.copy()
        italic_font.configure(slant="italic", size=main_font.cget("size"))

        h1_font = main_font.copy()
        h1_font.configure(size=round(main_font.cget("size") * 1.4),
                          weight="bold")

        h2_font = main_font.copy()
        h2_font.configure(size=round(main_font.cget("size") * 1.3),
                          weight="bold")

        h3_font = main_font.copy()
        h3_font.configure(size=main_font.cget("size"), weight="bold")

        small_font = main_font.copy()
        small_font.configure(size=round(main_font.cget("size") * 0.8))
        small_italic_font = italic_font.copy()
        small_italic_font.configure(size=round(main_font.cget("size") * 0.8))

        # Underline on font looks better than underline on tag
        underline_font = main_font.copy()
        underline_font.configure(underline=True)

        fixed_font = tkfont.nametofont("TkFixedFont")
        fixed_bold_font = fixed_font.copy()
        fixed_bold_font.configure(weight="bold", size=fixed_font.cget("size"))

        self.tag_configure("_base_",
                           lmargin1=x_padding,
                           lmargin2=x_padding,
                           rmargin=x_padding)
        self.tag_configure("h1", font=h1_font, spacing3=5)
        self.tag_configure("h2", font=h2_font, spacing3=5)
        self.tag_configure("h3", font=h3_font, spacing3=5)
        # self.tag_configure("p", spacing1=0, spacing3=10, spacing2=0)
        self.tag_configure("line_block", spacing1=0, spacing3=10, spacing2=0)
        self.tag_configure("em", font=italic_font)
        self.tag_configure("strong", font=bold_font)
        self.tag_configure("hr", wrap="none")
        self.tag_configure(
            "table", wrap="none", font=fixed_font
        )  # Fixed font as otherwise centering later won't work.

        self.tag_configure(
            "a",
            **{
                **get_syntax_options_for_tag("hyperlink"), "underline": False
            },
            font=underline_font)
        self.tag_configure("small", font=small_font)
        self.tag_configure("light", foreground="gray")
        self.tag_configure("remark", font=small_italic_font)
        self.tag_bind("a", "<ButtonRelease-1>", self._hyperlink_click)
        self.tag_bind("a", "<Enter>", self._hyperlink_enter)
        self.tag_bind("a", "<Leave>", self._hyperlink_leave)

        gutter_options = get_syntax_options_for_tag("GUTTER")
        self.tag_configure(
            "code",
            font=fixed_font,
            background=gutter_options["background"],
            lmargincolor=self["background"],
            rmargincolor=self["background"],
        )
        self.tag_configure(
            "pre",
            font=fixed_font,
            wrap=
            "none",  # TODO: needs automatic hor-scrollbar and better padding mgmt
            background=gutter_options["background"],
            rmargincolor=self["background"],
            lmargincolor=self["background"])
        # if ui_utils.get_tk_version_info() >= (8,6,6):
        #    self.tag_configure("code", lmargincolor=self["background"])

        li_indent = main_font.measure("m")
        li_bullet_width = main_font.measure(get_ul_li_marker(0))
        for i in range(1, 6):
            indent = x_padding + i * li_indent
            self.tag_configure("list%d" % i,
                               lmargin1=indent,
                               lmargin2=indent + li_bullet_width)

        self.tag_raise("a", "em")

        if ui_utils.get_tk_version_info() >= (8, 6, 6):
            self.tag_configure("sel", lmargincolor=self["background"])
        self.tag_raise("sel")