From d72e35add3c3d49b01a51658a47a76785ff4cfd1 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Sun, 20 Jan 2013 15:46:01 -0500 Subject: [PATCH] Copy and paste --- codeeditor.py | 1 + lightningbeam.py | 24 +++++++++++++++++++++++- svlgui.py | 14 +++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/codeeditor.py b/codeeditor.py index ef7fe3c..f82e4e2 100644 --- a/codeeditor.py +++ b/codeeditor.py @@ -241,6 +241,7 @@ class CodeEditor(ScrollableView): else: self.text=self.text[:self.cursorpos]+str(key)+self.text[self.cursorpos:] self.cursorpos += 1 + self.scursorpos = self.cursorpos self.invalidate_rect([0,0,self.extent[0],self.extent[1]]) class test(Application): def __init__(self): diff --git a/lightningbeam.py b/lightningbeam.py index cb9feb0..ab49744 100755 --- a/lightningbeam.py +++ b/lightningbeam.py @@ -825,6 +825,28 @@ def copy(widget=None): clip = svlgui.app.get_clipboard() if svlgui.app.query_clipboard() else None print clip raise blearrghh +def paste(widget=None): + clip = svlgui.app.get_clipboard() if svlgui.app.query_clipboard() else None + if clip: + print clip + if MainWindow.stage.is_focused(): + ctext = svlgui.Text(clip,200,100) + ctext.editing = False + # svlgui.CURRENTTEXT = self.ctext + ctext.onMouseDown = onMouseDownText + ctext.onMouseDrag = onMouseDragText + ctext.onMouseUp = onMouseUpText + self = root.descendItem() + self.add(ctext) + # self.add(self.ctext) + # self.ctext = None + undo_stack.append(edit("add_object", self, {"frame":self.activelayer.currentframe, "layer":self.activelayer}, \ + {"frame":self.activelayer.currentframe, "layer":self.activelayer, \ + "obj":self.activelayer.frames[self.activelayer.currentframe].objs[-1]})) + self.activelayer.currentselect = self.activelayer.frames[self.activelayer.currentframe].objs[-1] + MainWindow.stage.draw() + elif MainWindow.scriptwindow.is_focused(): + MainWindow.scriptwindow.insert(clip) def add_keyframe(widget=None): print "af> ", root.descendItem().activeframe @@ -927,7 +949,7 @@ svlgui.menufuncs([["File", ("Redo", redo, "/^z"), "Cut", ("Copy", copy, "/c"), - "Paste", + ("Paste", paste, "/v"), "Delete", ("Preferences",preferences,"")], ["Timeline", diff --git a/svlgui.py b/svlgui.py index a3d5b1d..7411873 100644 --- a/svlgui.py +++ b/svlgui.py @@ -341,6 +341,7 @@ if SYSTEM=="osx": m.undo_cmd.enabled = 1 m.redo_cmd.enabled = 1 m.copy_cmd.enabled = 1 + m.paste_cmd.enabled = 1 m.run_file.enabled = 1 m.run_html.enabled = 1 m.create_sc.enabled = 1 @@ -572,7 +573,7 @@ def menufuncs(j): menus.append(menu) else: 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"} + "Preferences":"preferences_cmd", "Undo":"undo_cmd", "Redo":"redo_cmd", "Copy":"copy_cmd", "Paste":"paste_cmd"} [setattr(app,cmds[k[0]],k[1]) for k in i if (k[0] in cmds)] class VBox(Widget): @@ -1185,6 +1186,9 @@ class Canvas(Widget): self.canvas.invalidate_rect((0,0,self.canvas.extent[0],self.canvas.extent[1])) elif SYSTEM=="html": jscommunicate("drawcanvas("+self.tid+")") + def is_focused(self): + if SYSTEM=="osx": + return self.canvas.is_target() def add(self, obj, x, y): obj.x = x obj.y = y @@ -1246,6 +1250,14 @@ class TextView(Widget): return self.box elif SYSTEM=="html": return self.box + def is_focused(self): + if SYSTEM=="osx": + return self.box.is_target() + def insert(self, text): + if SYSTEM=="osx": + if isinstance(self.box, CodeEditor): + self.box.text = self.box.text[:self.box.scursorpos]+text+self.box.text[self.box.cursorpos:] + self.box.invalidate_rect([0,0,self.box.extent[0],self.box.extent[1]]) def scroll_bottom(self): if SYSTEM=="osx": self.scroll_page_down();