Exemple #1
0
    def demo(self):
        TextWrapper._user_text_insert(self, "end", """Python 3.2.3
>>> %run "c:/my documents/kool/prog/katsetus.py"
Sisesta esimene arv: 4
Sisesta teine arv: 6
Nende arvude summa on 10
>>> " kalanaba ".trim()
"kalanaba"
>>>>>> 3 + 4
7
>>> 
""")
        promptfont = font.Font(family='Courier New', size=10, weight="bold")
        self.text.tag_add("prompt", "2.0", "2.4")
        self.text.tag_add("outprompt", "2.0", "2.4")
        self.text.tag_add("prompt", "6.0", "6.4")
        self.text.tag_add("prompt", "8.0", "8.7")
        self.text.tag_add("prompt", "10.0", "10.4")
        self.text.tag_configure("prompt", foreground="purple", 
                                spacing1=12, font=promptfont)
        self.text.tag_configure("outprompt", spacing3=12)
        
        self.text.tag_bind("prompt", "<Enter>", lambda _: self.text.configure(cursor="hand2"))
        self.text.tag_bind("prompt", "<Leave>", lambda _: self.text.configure(cursor="arrow"))
        
        self.text.tag_add("console", "3.0", "6.0")
        #self.text.tag_configure("console", foreground="white", background="#555555", relief=tk.RAISED, lmargin1=20)
        consolefont = font.Font(family='Consolas', size=8, weight="normal", slant="italic")
        self.text.tag_configure("console", lmargin1=16, font=consolefont, foreground="blue")
Exemple #2
0
 def _user_text_insert(self, index, txt, tags=(), **kw):
     #print("insert", index, text, kw)
     if (self._editing_allowed()
         and self._in_current_input_range(index)):
         #self._print_marks("before insert")
         # I want all marks to stay in place
         self.text.mark_gravity("input_start", tk.LEFT)
         self.text.mark_gravity("output_insert", tk.LEFT)
         
         if self._get_state() == "input":
             tags = tags + ("io", "stdin")
         else:
             tags = tags + ("toplevel", "command")
         
         # when going back and fixing in the middle of command and pressing ENTER there
         if txt == "\n":
             self.text.mark_set("insert", "insert lineend")
             index = "insert"
             
         TextWrapper._user_text_insert(self, index, txt, tags, **kw)
         
         # tag first char of io separately
         if self._get_state() == "input" and self._before_io:
             self.text.tag_add("vertically_spaced", index)
             self._before_io = False
         
         self._try_submit_input()
     else:
         self.bell()
         print("Shell: can't insert", self._get_state())
Exemple #3
0
 def _user_text_delete(self, index1, index2=None, **kw):
     if (self._editing_allowed() 
         and self._in_current_input_range(index1)
         and (index2 is None or self._in_current_input_range(index2))):
         TextWrapper._user_text_delete(self, index1, index2, **kw)
     else:
         self.bell()
         print("Shell: can't delete", self._get_state())
Exemple #4
0
    def set_content(self, content):
        TextWrapper._user_text_delete(self, "1.0", tk.END)
        TextWrapper._user_text_insert(self, "1.0", content)
        self._update_line_numbers()
        self.text.edit_reset()

        if self.colorer:
            self.colorer.notify_range("1.0", "end")
        self.update_level_boxes()
Exemple #5
0
    def _user_text_delete(self, index1, index2=None):
        # cursor_pos = self.text.index(tk.INSERT)

        if self.read_only:
            self.bell()
            print("CodeView._user_text_insert, read only")
            # self._show_read_only_warning()
        else:
            TextWrapper._user_text_delete(self, index1, index2)
            if self.colorer:
                self.colorer.on_delete(index1, index2)
            self._update_line_numbers()
            self.update_level_boxes()
Exemple #6
0
    def _user_text_insert(self, index, chars, tags=None):
        # cursor_pos = self.text.index(tk.INSERT)

        if self.read_only:
            self.bell()
            # print("CodeView._user_text_insert, read only") # TODO: log this?
            # self._show_read_only_warning()
        else:
            TextWrapper._user_text_insert(self, index, chars, tags)
            if self.colorer:
                self.colorer.on_insert(index, chars, tags)

            if self.paren_matcher:
                try:
                    if chars in (")", "]", "}"):
                        self.paren_matcher.paren_closed_event(None)
                    else:
                        self.remove_paren_highlight()
                except:
                    pass

            self._update_line_numbers()
            self.update_level_boxes()
            self.text.see(index)
Exemple #7
0
 def _insert_text_drctly(self, txt, tags):
     if txt != "":
         TextWrapper._user_text_insert(self, "output_insert", txt, tags)
Exemple #8
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))
Exemple #9
0
 def on_text_mouse_click(self, event):
     TextWrapper.on_text_mouse_click(self, event)
     self.remove_paren_highlight()
Exemple #10
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)