Take screenshot and save it to the journal (<alt>1).
This commit is contained in:
parent
283a3f4c97
commit
a9600516fb
@ -14,15 +14,22 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
from gettext import gettext as _
|
||||||
from sets import Set
|
from sets import Set
|
||||||
import logging
|
import logging
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
import gtk
|
||||||
import wnck
|
import wnck
|
||||||
|
|
||||||
from sugar.activity.activityhandle import ActivityHandle
|
from sugar.activity.activityhandle import ActivityHandle
|
||||||
from sugar.graphics.popupcontext import PopupContext
|
from sugar.graphics.popupcontext import PopupContext
|
||||||
from sugar.activity import activityfactory
|
from sugar.activity import activityfactory
|
||||||
|
from sugar.datastore import datastore
|
||||||
|
from sugar import profile
|
||||||
import sugar
|
import sugar
|
||||||
|
|
||||||
from view.ActivityHost import ActivityHost
|
from view.ActivityHost import ActivityHost
|
||||||
@ -196,3 +203,27 @@ class Shell(gobject.GObject):
|
|||||||
if not is_visible:
|
if not is_visible:
|
||||||
self._frame.do_slide_in()
|
self._frame.do_slide_in()
|
||||||
act.chat_show(is_visible)
|
act.chat_show(is_visible)
|
||||||
|
|
||||||
|
def take_screenshot(self):
|
||||||
|
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")
|
||||||
|
|
||||||
|
jobject = datastore.create()
|
||||||
|
jobject.metadata['title'] = _('Screenshot')
|
||||||
|
jobject.metadata['keep'] = '0'
|
||||||
|
jobject.metadata['buddies'] = ''
|
||||||
|
jobject.metadata['preview'] = ''
|
||||||
|
jobject.metadata['icon-color'] = profile.get_color().to_string()
|
||||||
|
jobject.metadata['mime-type'] = 'image/png'
|
||||||
|
jobject.file_path = file_path
|
||||||
|
datastore.write(jobject)
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ _actions_table = {
|
|||||||
'F10' : 'volume_2',
|
'F10' : 'volume_2',
|
||||||
'F11' : 'volume_3',
|
'F11' : 'volume_3',
|
||||||
'F12' : 'volume_4',
|
'F12' : 'volume_4',
|
||||||
|
'<alt>1' : 'screenshot',
|
||||||
'<alt>F8' : 'color_mode',
|
'<alt>F8' : 'color_mode',
|
||||||
'<alt>F5' : 'b_and_w_mode',
|
'<alt>F5' : 'b_and_w_mode',
|
||||||
'<alt>equal' : 'console',
|
'<alt>equal' : 'console',
|
||||||
@ -114,6 +115,9 @@ class KeyHandler(object):
|
|||||||
def handle_color_mode(self):
|
def handle_color_mode(self):
|
||||||
self._set_display_mode(hardwaremanager.COLOR_MODE)
|
self._set_display_mode(hardwaremanager.COLOR_MODE)
|
||||||
|
|
||||||
|
def handle_screenshot(self):
|
||||||
|
self._shell.take_screenshot()
|
||||||
|
|
||||||
def handle_b_and_w_mode(self):
|
def handle_b_and_w_mode(self):
|
||||||
self._set_display_mode(hardwaremanager.B_AND_W_MODE)
|
self._set_display_mode(hardwaremanager.B_AND_W_MODE)
|
||||||
|
|
||||||
|
@ -20,9 +20,11 @@ activity must do to participate in the Sugar desktop.
|
|||||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
# Boston, MA 02111-1307, USA.
|
# Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
from gettext import gettext as _
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import tempfile
|
||||||
|
|
||||||
import gtk, gobject
|
import gtk, gobject
|
||||||
|
|
||||||
@ -208,7 +210,7 @@ class Activity(Window, gtk.Container):
|
|||||||
elif create_jobject:
|
elif create_jobject:
|
||||||
logging.debug('Creating a jobject.')
|
logging.debug('Creating a jobject.')
|
||||||
self._jobject = datastore.create()
|
self._jobject = datastore.create()
|
||||||
self._jobject.metadata['title'] = '%s %s' % (get_bundle_name(), 'Activity')
|
self._jobject.metadata['title'] = _('%s Activity') % get_bundle_name()
|
||||||
self._jobject.metadata['activity'] = self.get_service_name()
|
self._jobject.metadata['activity'] = self.get_service_name()
|
||||||
self._jobject.metadata['keep'] = '0'
|
self._jobject.metadata['keep'] = '0'
|
||||||
self._jobject.metadata['buddies'] = ''
|
self._jobject.metadata['buddies'] = ''
|
||||||
@ -275,7 +277,7 @@ class Activity(Window, gtk.Container):
|
|||||||
def save(self):
|
def save(self):
|
||||||
"""Request that the activity is saved to the Journal."""
|
"""Request that the activity is saved to the Journal."""
|
||||||
try:
|
try:
|
||||||
file_path = os.path.join('/tmp', '%i' % time.time())
|
file_path = os.path.join(tempfile.gettempdir(), '%i' % time.time())
|
||||||
self.write_file(file_path)
|
self.write_file(file_path)
|
||||||
self._jobject.file_path = file_path
|
self._jobject.file_path = file_path
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
|
Loading…
Reference in New Issue
Block a user