Cut and copy
This commit is contained in:
parent
d72e35add3
commit
6ba81591c5
|
|
@ -89,6 +89,7 @@ class CodeEditor(ScrollableView):
|
||||||
self.lexer = ActionScriptLexer()
|
self.lexer = ActionScriptLexer()
|
||||||
self.cursorpos = 0
|
self.cursorpos = 0
|
||||||
self.scursorpos = 0
|
self.scursorpos = 0
|
||||||
|
self.selection = (0,0)
|
||||||
self.formatter = PyGUIFormatter()
|
self.formatter = PyGUIFormatter()
|
||||||
# self.filter = NameHighlightFilter(
|
# self.filter = NameHighlightFilter(
|
||||||
self.filter = EverythingHighlightFilter(
|
self.filter = EverythingHighlightFilter(
|
||||||
|
|
@ -169,6 +170,7 @@ class CodeEditor(ScrollableView):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.scursorpos = self.cursorpos
|
self.scursorpos = self.cursorpos
|
||||||
|
self.selection = (self.cursorpos, self.cursorpos)
|
||||||
if int(y/self.font.height):
|
if int(y/self.font.height):
|
||||||
self.cursorpos+=1
|
self.cursorpos+=1
|
||||||
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
|
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
|
||||||
|
|
@ -183,6 +185,7 @@ class CodeEditor(ScrollableView):
|
||||||
pass
|
pass
|
||||||
if int(y/self.font.height):
|
if int(y/self.font.height):
|
||||||
self.cursorpos+=1
|
self.cursorpos+=1
|
||||||
|
self.selection = (min(self.cursorpos, self.scursorpos), max(self.cursorpos, self.scursorpos))
|
||||||
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
|
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
|
||||||
def key_down(self, event):
|
def key_down(self, event):
|
||||||
keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow",
|
keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow",
|
||||||
|
|
@ -242,6 +245,7 @@ class CodeEditor(ScrollableView):
|
||||||
self.text=self.text[:self.cursorpos]+str(key)+self.text[self.cursorpos:]
|
self.text=self.text[:self.cursorpos]+str(key)+self.text[self.cursorpos:]
|
||||||
self.cursorpos += 1
|
self.cursorpos += 1
|
||||||
self.scursorpos = self.cursorpos
|
self.scursorpos = self.cursorpos
|
||||||
|
self.selection = (self.cursorpos, self.cursorpos)
|
||||||
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
|
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
|
||||||
class test(Application):
|
class test(Application):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
||||||
|
|
@ -821,10 +821,16 @@ def redo(widget=None):
|
||||||
undo_stack.append(e)
|
undo_stack.append(e)
|
||||||
MainWindow.stage.draw()
|
MainWindow.stage.draw()
|
||||||
|
|
||||||
|
def cut(widget=None):
|
||||||
|
if MainWindow.scriptwindow.is_focused():
|
||||||
|
clip = MainWindow.scriptwindow.text[MainWindow.scriptwindow.selection[0]:MainWindow.scriptwindow.selection[1]]
|
||||||
|
MainWindow.scriptwindow.insert("")
|
||||||
|
svlgui.app.set_clipboard(clip)
|
||||||
|
|
||||||
def copy(widget=None):
|
def copy(widget=None):
|
||||||
clip = svlgui.app.get_clipboard() if svlgui.app.query_clipboard() else None
|
if MainWindow.scriptwindow.is_focused():
|
||||||
print clip
|
clip = MainWindow.scriptwindow.text[MainWindow.scriptwindow.selection[0]:MainWindow.scriptwindow.selection[1]]
|
||||||
raise blearrghh
|
svlgui.app.set_clipboard(clip)
|
||||||
def paste(widget=None):
|
def paste(widget=None):
|
||||||
clip = svlgui.app.get_clipboard() if svlgui.app.query_clipboard() else None
|
clip = svlgui.app.get_clipboard() if svlgui.app.query_clipboard() else None
|
||||||
if clip:
|
if clip:
|
||||||
|
|
@ -947,7 +953,7 @@ svlgui.menufuncs([["File",
|
||||||
["Edit",
|
["Edit",
|
||||||
("Undo", undo, "/z"),
|
("Undo", undo, "/z"),
|
||||||
("Redo", redo, "/^z"),
|
("Redo", redo, "/^z"),
|
||||||
"Cut",
|
("Cut", cut, "/x"),
|
||||||
("Copy", copy, "/c"),
|
("Copy", copy, "/c"),
|
||||||
("Paste", paste, "/v"),
|
("Paste", paste, "/v"),
|
||||||
"Delete",
|
"Delete",
|
||||||
|
|
|
||||||
14
svlgui.py
14
svlgui.py
|
|
@ -341,6 +341,7 @@ if SYSTEM=="osx":
|
||||||
m.undo_cmd.enabled = 1
|
m.undo_cmd.enabled = 1
|
||||||
m.redo_cmd.enabled = 1
|
m.redo_cmd.enabled = 1
|
||||||
m.copy_cmd.enabled = 1
|
m.copy_cmd.enabled = 1
|
||||||
|
m.cut_cmd.enabled = 1
|
||||||
m.paste_cmd.enabled = 1
|
m.paste_cmd.enabled = 1
|
||||||
m.run_file.enabled = 1
|
m.run_file.enabled = 1
|
||||||
m.run_html.enabled = 1
|
m.run_html.enabled = 1
|
||||||
|
|
@ -573,7 +574,7 @@ def menufuncs(j):
|
||||||
menus.append(menu)
|
menus.append(menu)
|
||||||
else:
|
else:
|
||||||
cmds={"New...":"new_cmd", "Save":"save_cmd", "Save As":"save_as_cmd", "Open":"open_cmd","About Lightningbeam...":"about_cmd",\
|
cmds={"New...":"new_cmd", "Save":"save_cmd", "Save As":"save_as_cmd", "Open":"open_cmd","About Lightningbeam...":"about_cmd",\
|
||||||
"Preferences":"preferences_cmd", "Undo":"undo_cmd", "Redo":"redo_cmd", "Copy":"copy_cmd", "Paste":"paste_cmd"}
|
"Preferences":"preferences_cmd", "Undo":"undo_cmd", "Redo":"redo_cmd", "Cut":"cut_cmd", "Copy":"copy_cmd", "Paste":"paste_cmd"}
|
||||||
[setattr(app,cmds[k[0]],k[1]) for k in i if (k[0] in cmds)]
|
[setattr(app,cmds[k[0]],k[1]) for k in i if (k[0] in cmds)]
|
||||||
|
|
||||||
class VBox(Widget):
|
class VBox(Widget):
|
||||||
|
|
@ -1215,7 +1216,14 @@ class TextView(Widget):
|
||||||
def _settext(self, text):
|
def _settext(self, text):
|
||||||
if SYSTEM=="osx":
|
if SYSTEM=="osx":
|
||||||
self.box.text = text
|
self.box.text = text
|
||||||
|
def _getselection(self):
|
||||||
|
if SYSTEM=="osx":
|
||||||
|
return self.box.selection
|
||||||
|
def _setselection(self, tup):
|
||||||
|
if SYSTEM=="osx":
|
||||||
|
self.box.selection = tup
|
||||||
text = property(_gettext, _settext)
|
text = property(_gettext, _settext)
|
||||||
|
selection = property(_getselection, _setselection)
|
||||||
def __init__(self,editable=True,width=False,height=False,code=False):
|
def __init__(self,editable=True,width=False,height=False,code=False):
|
||||||
if SYSTEM=="gtk":
|
if SYSTEM=="gtk":
|
||||||
self.sw=ScrolledWindow()
|
self.sw=ScrolledWindow()
|
||||||
|
|
@ -1256,7 +1264,9 @@ class TextView(Widget):
|
||||||
def insert(self, text):
|
def insert(self, text):
|
||||||
if SYSTEM=="osx":
|
if SYSTEM=="osx":
|
||||||
if isinstance(self.box, CodeEditor):
|
if isinstance(self.box, CodeEditor):
|
||||||
self.box.text = self.box.text[:self.box.scursorpos]+text+self.box.text[self.box.cursorpos:]
|
self.box.text = self.box.text[:self.box.selection[0]]+text+self.box.text[self.box.selection[1]:]
|
||||||
|
self.box.scursorpos = self.box.cursorpos = self.box.selection[0]+len(text)
|
||||||
|
self.box.selection = (self.box.selection[0]+len(text), self.box.selection[0]+len(text))
|
||||||
self.box.invalidate_rect([0,0,self.box.extent[0],self.box.extent[1]])
|
self.box.invalidate_rect([0,0,self.box.extent[0],self.box.extent[1]])
|
||||||
def scroll_bottom(self):
|
def scroll_bottom(self):
|
||||||
if SYSTEM=="osx":
|
if SYSTEM=="osx":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue