예제 #1
0
 def __init__(self, master, workbench):
     ttk.Frame.__init__(self, master)
     
     self._workbench = workbench
     self._before_io = True
     self._command_count = 0
     self._command_history = [] # actually not really history, because each command occurs only once
     self._command_history_current_index = None 
     self.text_mode = "toplevel"
     
     """
     self.margin = tk.Text(self,
             width = 4,
             padx = 4,
             highlightthickness = 0,
             takefocus = 0,
             bd = 0,
             #font = self.font,
             cursor = "dotbox",
             background = '#e0e0e0',
             foreground = '#999999',
             #state='disabled'
             )
     self.margin.grid(row=0, column=0)
     """
     
     self.vert_scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL)
     self.vert_scrollbar.grid(row=0, column=2, sticky=tk.NSEW)
     editor_font = font.nametofont(name='TkFixedFont')
     self.text = tk.Text(self,
                         font=editor_font,
                         #foreground="white",
                         #background="#666666",
                         highlightthickness=0,
                         #highlightcolor="LightBlue",
                         borderwidth=0,
                         yscrollcommand=self.vert_scrollbar.set,
                         padx=4,
                         insertwidth=2,
                         height=10,
                         undo=True,
                         autoseparators=False)
     
     #log_user_event(ShellCreateEvent(self)) TODO:
     
     self.text.grid(row=0, column=1, sticky=tk.NSEW)
     self.text.bind("<Up>", self._arrow_up, "+")
     self.text.bind("<Down>", self._arrow_down, "+")
     self.text.bind("<KeyPress>", self._text_key_press, "+")
     self.text.bind("<KeyRelease>", self._text_key_release, "+")
     self.text.bind("<Home>", self.home_callback)
     self.vert_scrollbar['command'] = self.text.yview
     self.columnconfigure(1, weight=1)
     self.rowconfigure(0, weight=1)
     
     TextWrapper.__init__(self)
     
     self.text["font"] = workbench.get_font("EditorFont")
     vert_spacing = 10
     io_indent = 16
     
     self.text.tag_configure("toplevel", font=workbench.get_font("EditorFont"))
     self.text.tag_configure("prompt", foreground="purple", font=workbench.get_font("BoldEditorFont"))
     self.text.tag_configure("command", foreground="black")
     self.text.tag_configure("automagic", foreground="DarkGray")
     #self.text.tag_configure("value", foreground="DarkGreen")
     #self.text.tag_configure("value", foreground="#B25300")
     self.text.tag_configure("value", foreground="DarkBlue") # TODO: see also _text_key_press and _text_key_release
     self.text.tag_configure("error", foreground="Red")
     
     self.text.tag_configure("io", lmargin1=io_indent, lmargin2=io_indent, rmargin=io_indent,
                             font=workbench.get_font("IOFont"))
     self.text.tag_configure("stdin", foreground="Blue")
     self.text.tag_configure("stdout", foreground="Black")
     self.text.tag_configure("stderr", foreground="Red")
     self.text.tag_configure("hyperlink", foreground="#3A66DD", underline=True)
     self.text.tag_bind("hyperlink", "<ButtonRelease-1>", self._handle_hyperlink)
     self.text.tag_bind("hyperlink", "<Enter>", self._hyperlink_enter)
     self.text.tag_bind("hyperlink", "<Leave>", self._hyperlink_leave)
     
     self.text.tag_configure("vertically_spaced", spacing1=vert_spacing)
     self.text.tag_configure("inactive", foreground="#aaaaaa")
     
     # 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.text.mark_set("input_start", "end-1c")
     self.text.mark_gravity("input_start", tk.LEFT)
     
     self.text.mark_set("output_end", "end-1c")
     self.text.mark_gravity("output_end", tk.LEFT)
     
     self.text.mark_set("output_insert", "end-1c")
     self.text.mark_gravity("output_insert", tk.RIGHT)
     
     
     self.active_object_tags = set()
 
     self._workbench.bind("BackendMessage", 
         lambda e: self._handle_vm_message(e.message))
예제 #2
0
    def __init__(
        self,
        master,
        workbench,
        first_line_no=1,
        font_size=11,
        auto_vert_scroll=False,
        height=None,
        propose_remove_line_numbers=False,
    ):
        ttk.Frame.__init__(self, master)
        self._workbench = workbench

        # attributes
        self.first_line_no = first_line_no
        self.filename = None
        self.file_encoding = "UTF-8"

        self.tabwidth = 8  # See comments in idlelib.EditorWindow
        self.indentwidth = 4
        self.usetabs = False

        # child widgets
        if auto_vert_scroll:
            self.vbar = AutoScrollbar(self, orient=tk.VERTICAL)
        else:
            self.vbar = ttk.Scrollbar(self, orient=tk.VERTICAL)
        self.vbar.grid(row=0, column=2, sticky=tk.NSEW)
        self.hbar = AutoScrollbar(self, orient=tk.HORIZONTAL)
        self.hbar.grid(row=1, column=0, sticky=tk.NSEW, columnspan=2)

        self.margin = tk.Text(
            self,
            width=4,
            padx=5,
            pady=5,
            highlightthickness=0,
            takefocus=0,
            bd=0,
            font=workbench.get_font("EditorFont"),
            # cursor = "dotbox",
            background="#e0e0e0",
            foreground="#999999",
            # state='disabled'
        )

        # self.margin.grid(row=0, column=0, sticky=tk.NSEW)

        def _vertical_scrollbar_update(*args):
            self.vbar.set(*args)
            self.margin.yview(tk.MOVETO, args[0])

        self.text = tk.Text(
            self,
            # background="#ffffff",
            # background="#FEE5BF",
            # background="gray",
            height=height,
            spacing1=0,
            spacing3=0,
            highlightthickness=0,
            # highlightcolor="LightBlue",
            yscrollcommand=_vertical_scrollbar_update,
            xscrollcommand=self.hbar.set,
            borderwidth=0,
            font=self._workbench.get_font("EditorFont"),
            wrap=tk.NONE,
            insertwidth=2,
            # selectborderwidth=2,
            inactiveselectbackground="gray",
            # highlightthickness=0, # TODO: try different in Mac and Linux
            # highlightcolor="gray",
            padx=5,
            pady=5,
            undo=True,
            autoseparators=False,
        )

        TextWrapper.__init__(self, propose_remove_line_numbers)

        self.read_only = False

        self.text.grid(row=0, column=1, sticky=tk.NSEW)

        def _vertical_scroll(*args):
            self.text.yview(*args)
            self.margin.yview(*args)

        self.vbar["command"] = _vertical_scroll  # TODO: keep line count same in margin
        self.hbar["command"] = self.text.xview

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

        self.colorer = None
        self.set_coloring(True)
        self.set_up_paren_matching()

        # TODO: use general event system
        self._resetting_modified_flag = (
            False
        )  # used internally, indicates when modified flag reset is currently in progress

        # self.prepare_level_boxes()

        """
        self.text.tag_configure('statement', borderwidth=1, relief=tk.SOLID)
        self.text.tag_configure('statement_odd', borderwidth=1, relief=tk.SOLID, background="#FFFFFF")
        self.text.tag_configure('statement_even', borderwidth=1, relief=tk.SOLID, background="#FFFFFE")
        """
        self.text.tag_configure("before", background="#F8FC9A")
        self.text.tag_configure("after", background="#D7EDD3")
        self.text.tag_configure("exception", background="#FFBFD6")

        # self.current_statement_range = None
        self.active_statement_ranges = []
        # self.statement_tags = set()

        self.num_context_lines = 50, 500, 5000000  # See idlelib.EditorWindow
        self.context_use_ps1 = False
        self.modified_since_last_save = False

        # TODO: Check Mac bindings
        self.text.bind("<Control-BackSpace>", self.del_word_left)
        self.text.bind("<Control-Delete>", self.del_word_right)
        self.text.bind("<Home>", self.home_callback)
        self.text.bind("<Left>", self.move_at_edge_if_selection(0))
        self.text.bind("<Right>", self.move_at_edge_if_selection(1))
        self.text.bind("<Tab>", self.indent_or_dedent_event)
        self.text.bind("<Return>", self.newline_and_indent_event)
        self.text.bind("<BackSpace>", self.smart_backspace_event)
        self.text.bind("<<Modified>>", self.on_text_modified)

        fixwordbreaks(tk._default_root)