Exemple #1
0
def _treeview_settings() -> BasicUiThemeSettings:
    light_blue = "#ADD8E6"
    light_grey = "#D3D3D3"

    if running_on_linux() or running_on_mac_os():
        bg_sel_focus = light_blue
        fg_sel_focus = "black"
        fg_sel_notfocus = "black"
    else:
        bg_sel_focus = "SystemHighlight"
        fg_sel_focus = "SystemHighlightText"
        fg_sel_notfocus = "SystemWindowText"

    return {
        "Treeview": {
            "configure": {"font": "TreeviewFont"},
            "map": {
                "background": [
                    ("selected", "focus", bg_sel_focus),
                    ("selected", "!focus", light_grey),
                ],
                "foreground": [
                    ("selected", "focus", fg_sel_focus),
                    ("selected", "!focus", fg_sel_notfocus),
                ],
            },
            "layout": [
                # get rid of borders
                ("Treeview.treearea", {"sticky": "nswe"})
            ],
        },
        "treearea": {"configure": {"borderwidth": 0}},
    }
    def __init__(self, master):
        super().__init__(master)
        runscript_label = ttk.Label(
            self, text=_("Running current script in terminal") + ":")
        runscript_label.grid(row=0, column=0, sticky="w")

        self.add_checkbox(
            "run.run_in_terminal_python_repl",
            _("Present Python REPL after program ends"),
            row=1,
            padx=(12, 0),
        )

        self.add_checkbox(
            "run.run_in_terminal_keep_open",
            _("Keep terminal window open after Python process ends"),
            row=2,
            padx=(12, 0),
        )

        exit_remark = " "
        if running_on_mac_os():
            exit_remark = _(
                "NB! Automatic closing needs to be enabled in Terminal's settings\n"
                + "(Profiles → Shell → When the shell exits)")
        remark_label = ttk.Label(self, text=exit_remark)
        remark_label.grid(row=3,
                          column=0,
                          sticky="w",
                          padx=(12, 0),
                          pady=(0, 10))
    def show_file(self,
                  filename,
                  text_range=None,
                  set_focus=True,
                  propose_dialog=True):
        # self.close_single_untitled_unmodified_editor()
        try:
            editor = self.get_editor(filename, True)
        except PermissionError:
            logging.getLogger("ynnoht").exception("Loading " + filename)
            msg = "Got permission error when trying to load\n" + filename
            if running_on_mac_os() and propose_dialog:
                msg += "\n\nTry opening it with File => Open."

            messagebox.showerror("Permission error", msg)
            return None

        assert editor is not None

        self.select(editor)
        if set_focus:
            editor.focus_set()

        if text_range is not None:
            editor.select_range(text_range)

        return editor
    def __init__(self, master):
        super().__init__(master)

        self.title("Configure shell macro")
        if misc_utils.running_on_mac_os():
            self.configure(background="systemSheetBackground")
        self.transient(master)
        self.grab_set()  # to make it active
        # self.grab_release() # to allow eg. copy something from the editor

        self._create_widgets()

        self.bind("<Escape>", self._on_close, True)
        self.protocol("WM_DELETE_WINDOW", self._on_close)
        self.main_command_text.focus_set()
    def _preview_submission_data(self, event=None):
        temp_path = os.path.join(
            tempfile.mkdtemp(),
            "ThonnyAssistantFeedback_" +
            datetime.datetime.now().isoformat().replace(":", ".")[:19] +
            ".txt",
        )
        data = self._collect_submission_data()
        with open(temp_path, "w", encoding="ascii") as fp:
            fp.write(data)

        if running_on_mac_os():
            subprocess.Popen(["open", "-e", temp_path])
        else:
            webbrowser.open(temp_path)
Exemple #6
0
    def __init__(self, text_frame, frame_info):
        self._text_frame = text_frame
        self._text = text_frame.text
        self._frame_info = frame_info
        self._frame_id = frame_info.id
        self._filename = frame_info.filename
        self._firstlineno = None
        if running_on_mac_os():
            self._expression_box = ToplevelExpressionBox(text_frame)
        else:
            self._expression_box = PlacedExpressionBox(text_frame)

        self._note_box = ui_utils.NoteBox(text_frame.winfo_toplevel())
        self._next_frame_visualizer = None
        self._prev_frame_visualizer = None
        self._text.set_read_only(True)
        self._line_debug = frame_info.current_statement is None

        self._reconfigure_tags()
Exemple #7
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)
        self.wm_transient(codeview.winfo_toplevel())
        self.lift()
    def indicate_modification(self):
        if not running_on_mac_os():
            return

        atts = self.winfo_toplevel().wm_attributes()
        if "-modified" in atts:
            i = atts.index("-modified")
            mod = atts[i:i + 2]
            rest = atts[:i] + atts[i + 2:]
        else:
            mod = ()
            rest = atts

        for editor in self.get_all_editors():
            if editor.is_modified():
                if mod != ("-modified", 1):
                    self.winfo_toplevel().wm_attributes(*(rest +
                                                          ("-modified", 1)))
                break
        else:
            if mod == ("-modified", 1):
                self.winfo_toplevel().wm_attributes(*(rest + ("-modified", 0)))
Exemple #9
0
    def _replace(self, focus, value):
        start_mark = self._get_mark_name(focus.lineno, focus.col_offset)
        end_mark = self._get_mark_name(focus.end_lineno, focus.end_col_offset)

        self.text.delete(start_mark, end_mark)

        id_str = memory.format_object_id(value.id)
        if get_workbench().in_heap_mode():
            value_str = id_str
        else:
            value_str = shorten_repr(value.repr, 100)

        object_tag = "object_" + str(value.id)
        self.text.insert(start_mark, value_str, ("value", object_tag))
        if misc_utils.running_on_mac_os():
            sequence = "<Command-Button-1>"
        else:
            sequence = "<Control-Button-1>"
        self.text.tag_bind(
            object_tag,
            sequence,
            lambda _: get_workbench().event_generate("ObjectSelect",
                                                     object_id=value.id),
        )
Exemple #10
0
    def _get_interpreters(self):
        result = set()

        if running_on_windows():
            # registry
            result.update(self._get_interpreters_from_windows_registry())

            for minor in [5, 6, 7, 8]:
                for dir_ in [
                        "C:\\Python3%d" % minor,
                        "C:\\Python3%d-32" % minor,
                        "C:\\Python3%d-64" % minor,
                        "C:\\Program Files\\Python 3.%d" % minor,
                        "C:\\Program Files\\Python 3.%d-64" % minor,
                        "C:\\Program Files (x86)\\Python 3.%d" % minor,
                        "C:\\Program Files (x86)\\Python 3.%d-32" % minor,
                ]:
                    path = os.path.join(dir_, WINDOWS_EXE)
                    if os.path.exists(path):
                        result.add(normpath_with_actual_case(path))

            # other locations
            for dir_ in ["C:\\Anaconda3", os.path.expanduser("~/Anaconda3")]:
                path = os.path.join(dir_, WINDOWS_EXE)
                if os.path.exists(path):
                    result.add(normpath_with_actual_case(path))

        else:
            # Common unix locations
            dirs = [
                "/bin", "/usr/bin", "/usr/local/bin",
                os.path.expanduser("~/.local/bin")
            ]
            for dir_ in dirs:
                # if the dir_ is just a link to another dir_, skip it
                # (not to show items twice)
                # for example on Fedora /bin -> usr/bin
                if not os.path.exists(dir_):
                    continue

                apath = normpath_with_actual_case(dir_)
                if apath != dir_ and apath in dirs:
                    continue
                for name in [
                        "python3", "python3.5", "python3.6", "python3.7",
                        "python3.8"
                ]:
                    path = os.path.join(dir_, name)
                    if os.path.exists(path):
                        result.add(path)

        if running_on_mac_os():
            for version in ["3.5", "3.6", "3.7", "3.8"]:
                dir_ = os.path.join(
                    "/Library/Frameworks/Python.framework/Versions", version,
                    "bin")
                path = os.path.join(dir_, "python3")

                if os.path.exists(path):
                    result.add(path)

        for command in [
                "python3", "python3.5", "python3.5", "python3.6", "python3.7",
                "python3.8"
        ]:
            path = which(command)
            if path is not None and os.path.isabs(path):
                result.add(path)

        for path in get_workbench().get_option("CustomInterpreter.used_paths"):
            if os.path.exists(path):
                result.add(normpath_with_actual_case(path))

        return sorted(result)
Exemple #11
0
 def _on_close(self):
     showinfo(
         _("Can't close yet"),
         _('Use "Stop" command if you want to cancel debugging'),
         parent=None if running_on_mac_os() else self,
     )
    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