Example #1
0
 def edit_comment(self, *args):
     text = self.master.current_text
     file = self.master.current_file
     selection = text_get_selected(text)
     if selection:
         file.insert_comment(text.index(tk.SEL_FIRST), text.index(tk.SEL_LAST))
     else:
         file.insert_comment(text.index("current linestart"), text.index("current lineend"))
Example #2
0
 def edit_duplicate(self, *args):
     text = self.master.current_text
     selection = text_get_selected(text)
     if selection:
         text.insert(tk.SEL_LAST, f"\n{selection}")
     else:
         selection = text.get(tk.CURRENT + " linestart",
                              tk.CURRENT + " lineend")
         text.insert(tk.CURRENT + " lineend", f"\n{selection}")
     pass  # TODO
Example #3
0
 def edit_formatting_capitalized(self, *args):
     text = self.master.current_text
     selection = text_get_selected(text)
     if selection:
         text.insert(tk.SEL_LAST, selection.capitalize())
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
     else:
         selection = text.get(tk.CURRENT + " linestart",
                              tk.CURRENT + " lineend")
         text.insert(tk.CURRENT + " lineend", selection.capitalize())
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
     pass
Example #4
0
 def insert(self, text):
     sel = text_get_selected(text)
     if sel and self.replace_selection:
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
     current = text.index(tk.CURRENT)
     line, column = current.split(".")
     rv = self.before_cursor + sel + self.after_cursor
     text.insert(tk.CURRENT, rv)
     if self.replace_selection:
         column = int(column)
     else:
         column = int(column) + len(self.before_cursor)
     text.mark_set("current", f"{line}.{column}")
Example #5
0
 def edit_formatting_random(self, *args):
     def rand(s):
         rv = ""
         for char in s:
             rv += [char.upper(), char.lower()][random.randint(0, 1)]
         return rv
     text = self.master.current_text
     selection = text_get_selected(text)
     if selection:
         text.insert(tk.SEL_LAST, rand(selection))
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
     else:
         selection = text.get(tk.CURRENT + " linestart",
                              tk.CURRENT + " lineend")
         text.insert(tk.CURRENT + " lineend", rand(selection))
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
Example #6
0
 def edit_formatting_spongebob(self, *args):
     def sponge(s):
         rv = ""
         i = 0
         for char in s:
             if char == " ":
                 rv += " "
                 continue
             rv += [char.upper(), char.lower()][i % 2]
             i += 1
         return rv
     text = self.master.current_text
     selection = text_get_selected(text)
     if selection:
         text.insert(tk.SEL_LAST, sponge(selection))
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
     else:
         selection = text.get(tk.CURRENT + " linestart",
                              tk.CURRENT + " lineend")
         text.insert(tk.CURRENT + " lineend", sponge(selection))
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
Example #7
0
 def edit_formatting_invert(self, *args):
     def invert(s):
         rv = ""
         for char in s:
             if char in string.ascii_lowercase:
                 rv += char.upper()
             elif char in string.ascii_uppercase:
                 rv += char.lower()
             else:
                 rv += char
         return rv
     text = self.master.current_text
     selection = text_get_selected(text)
     if selection:
         text.insert(tk.SEL_LAST, invert(selection))
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
     else:
         selection = text.get(tk.CURRENT + " linestart",
                              tk.CURRENT + " lineend")
         text.insert(tk.CURRENT + " lineend", invert(selection))
         text.delete(tk.SEL_FIRST, tk.SEL_LAST)
     pass