Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/addons/screenclipper.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/screenclipper.py')
-rw-r--r--addons/screenclipper.py124
1 files changed, 124 insertions, 0 deletions
diff --git a/addons/screenclipper.py b/addons/screenclipper.py
new file mode 100644
index 0000000..7ad6808
--- /dev/null
+++ b/addons/screenclipper.py
@@ -0,0 +1,124 @@
+# Copyright (C) 2009, Tutorius.org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+from sugar.tutorius.actions import Action, DragWrapper
+from sugar.tutorius.properties import TScreenClipProperty, \
+ TArrayProperty
+import gtk
+
+class ScreenClip(Action):
+ # Create the position as an array of fixed-size 2
+ position = TArrayProperty((0,0), 2, 2)
+ # Do the same for the tail position
+ clip_image = TScreenClipProperty("")
+
+ def __init__(self, position=None,
+ clip_image=None,
+ **kwargs):
+ """
+ Shows a dialog with a given text, at the given position on the screen.
+
+ @param position A list of the form [x, y]
+ @param clip_image the screen clip image path
+ @param clip_rect rectangle of the clip image
+ """
+ Action.__init__(self, **kwargs)
+
+ if position:
+ self.position = position
+ if clip_image:
+ self.clip_image = clip_image
+
+ self.overlay = None
+ self._bubble = None
+
+ def do(self, overlayer=None, **kwargs):
+ """
+ Show the dialog
+ """
+ if overlayer is None:
+ raise TypeError("Missing overlayer argument")
+
+ self.overlay = overlayer
+
+ if not self._bubble:
+ # Normal gtk widgets use the parent window to draw themselves.
+ # For normal layouts, this is good, but as we are using the layout
+ # for stacking widgets, the rendering order is sometimes wrong.
+ # Thus, by adding the Image widget in a visible EventBox, we ensure
+ # the Image is drawn in its own window, and stacking is correct.
+ x, y = self.position
+ self._bubble = gtk.EventBox()
+ self._bubble.set_visible_window(True)
+ image = gtk.Image()
+ image.set_from_file(self.clip_image)
+ self._bubble.add(image)
+ self._bubble.show_all()
+ self.overlay.put(self._bubble, x, y)
+ self.overlay.queue_draw()
+
+ def undo(self):
+ """
+ Destroy the dialog
+ """
+ if self._bubble:
+ self.overlay.remove(self._bubble)
+ self._bubble.destroy()
+ self._bubble = None
+
+ def enter_editmode(self, overlayer=None, *args, **kwargs):
+ """
+ Enters edit mode. The action should display itself in some way,
+ without affecting the currently running application.
+ """
+ if overlayer is None:
+ raise TypeError("Missing overlayer argument")
+
+ self.overlay = overlayer
+ assert not self._drag, "bubble action set to editmode twice"
+ x, y = self.position
+ if self.clip_image:
+ self._bubble = gtk.EventBox()
+ self._bubble.set_visible_window(True)
+ image = gtk.Image()
+ image.set_from_file(self.clip_image)
+ self._bubble.add(image)
+ self._bubble.show_all()
+ self.overlay.put(self._bubble, x, y)
+
+ self._drag = DragWrapper(self._bubble, self.position,
+ update_action_cb=self.update_property,
+ draggable=True)
+
+ def exit_editmode(self, *args):
+ if self._drag:
+ x, y = self._drag.position
+ self.position = (int(x), int(y))
+
+ self._drag.draggable = False
+ self._drag = None
+ if self._bubble:
+ self.overlay.remove(self._bubble)
+ self._bubble = None
+ self.overlay = None
+
+__action__ = {
+ "name" : ScreenClip.__name__,
+ "display_name" : "Screen Capture Clip",
+ "icon" : "screenclip",
+ "class" : ScreenClip,
+ "mandatory_props" : []
+}
+