Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2008-10-22 08:34:01 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2008-10-22 08:34:01 (GMT)
commit39fcc1bc37bdde6e34e5bb3e2c8b5692851d8d58 (patch)
treeb54e336ea249703ae641d374ae762d4101027984 /extensions
parent17d797ea4e9b35f57b42c99eb197ad301dadbb01 (diff)
Modularize key handlers
Diffstat (limited to 'extensions')
-rw-r--r--extensions/Makefile.am2
-rw-r--r--extensions/globalkey/Makefile.am5
-rw-r--r--extensions/globalkey/__init__.py0
-rw-r--r--extensions/globalkey/screenshot.py59
4 files changed, 65 insertions, 1 deletions
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index d402374..d4ab534 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -1 +1 @@
-SUBDIRS = cpsection deviceicon
+SUBDIRS = cpsection deviceicon globalkey
diff --git a/extensions/globalkey/Makefile.am b/extensions/globalkey/Makefile.am
new file mode 100644
index 0000000..84a23ad
--- /dev/null
+++ b/extensions/globalkey/Makefile.am
@@ -0,0 +1,5 @@
+sugardir = $(pkgdatadir)/extensions/globalkey
+
+sugar_PYTHON = \
+ __init__.py \
+ screenshot.py
diff --git a/extensions/globalkey/__init__.py b/extensions/globalkey/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/extensions/globalkey/__init__.py
diff --git a/extensions/globalkey/screenshot.py b/extensions/globalkey/screenshot.py
new file mode 100644
index 0000000..ef4f5c9
--- /dev/null
+++ b/extensions/globalkey/screenshot.py
@@ -0,0 +1,59 @@
+# Copyright (C) 2008 One Laptop Per Child
+#
+# 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
+
+import os
+import tempfile
+import time
+from gettext import gettext as _
+
+import gtk
+import gconf
+
+from sugar.datastore import datastore
+
+BOUND_KEYS = ['<alt>1']
+
+def handle_key_press(key):
+ file_path = os.path.join(tempfile.gettempdir(), '%i' % time.time())
+
+ window = gtk.gdk.get_default_root_window()
+ width, height = window.get_size()
+ x_orig, y_orig = window.get_origin()
+
+ screenshot = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=False,
+ bits_per_sample=8, width=width,
+ height=height)
+ screenshot.get_from_drawable(window, window.get_colormap(), x_orig,
+ y_orig, 0, 0, width, height)
+ screenshot.save(file_path, "png")
+
+ client = gconf.client_get_default()
+ color = client.get_string('/desktop/sugar/user/color')
+
+ jobject = datastore.create()
+ try:
+ jobject.metadata['title'] = _('Screenshot')
+ jobject.metadata['keep'] = '0'
+ jobject.metadata['buddies'] = ''
+ jobject.metadata['preview'] = ''
+ jobject.metadata['icon-color'] = color
+ jobject.metadata['mime_type'] = 'image/png'
+ jobject.file_path = file_path
+ datastore.write(jobject, transfer_ownership=True)
+ finally:
+ jobject.destroy()
+ del jobject
+