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")
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())
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()
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)
def _insert_text_drctly(self, txt, tags): if txt != "": TextWrapper._user_text_insert(self, "output_insert", txt, tags)