diff options
author | Aneesh Dogra <lionaneesh@gmail.com> | 2012-12-23 08:32:10 (GMT) |
---|---|---|
committer | Aneesh Dogra <lionaneesh@gmail.com> | 2012-12-23 08:35:10 (GMT) |
commit | dc33b4bf107a34c0e137e6d0c6da9b0ed937b214 (patch) | |
tree | fcd9569dfb46ace0eca283a69524fec35be00f7e | |
parent | 198a315d715c6fd60d9753c95c2c32a37a62133a (diff) |
Add the functionality to show webcam images to the person itself.
Need to add support for sending these images to other player.
-rw-r--r-- | GNUChessActivity.py | 21 | ||||
-rw-r--r-- | WebcamImages.py | 83 | ||||
-rwxr-xr-x[-rw-r--r--] | bin/x86_64/gnuchess | bin | 173376 -> 173376 bytes | |||
-rw-r--r-- | chess.py | 3 |
4 files changed, 101 insertions, 6 deletions
diff --git a/GNUChessActivity.py b/GNUChessActivity.py index 22e8171..e17fb5e 100644 --- a/GNUChessActivity.py +++ b/GNUChessActivity.py @@ -12,7 +12,6 @@ # Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA from gi.repository import Gtk, Gdk, GObject - from sugar3.activity import activity from sugar3 import profile from sugar3.graphics.toolbarbox import ToolbarBox @@ -25,7 +24,6 @@ from sugar3 import mime from sugar3.graphics.alert import ConfirmationAlert, NotifyAlert from sugar3.graphics.icon import Icon from sugar3.graphics.xocolor import XoColor - from toolbar_utils import button_factory, label_factory, separator_factory, \ radio_factory, entry_factory, combo_factory from utils import json_load, json_dump, get_hardware, \ @@ -39,6 +37,9 @@ from dbus.gobject_service import ExportedGObject from sugar3.presence import presenceservice from sugar3.presence.tubeconn import TubeConnection +from WebcamImages import WebcamImages +from WebcamImages import W_I_WIDTH + from gettext import gettext as _ from chess import Gnuchess @@ -46,7 +47,6 @@ from chess import Gnuchess import logging _logger = logging.getLogger('gnuchess-activity') - SERVICE = 'org.sugarlabs.GNUChessActivity' IFACE = SERVICE PATH = '/org/augarlabs/GNUChessActivity' @@ -82,11 +82,22 @@ class GNUChessActivity(activity.Activity): self._setup_toolbars() self._setup_dispatch_table() + self.main_hbox = Gtk.HBox() # contains webcam image viewer and the canvas + self.image_vbox = Gtk.VBox() # Create a canvas canvas = Gtk.DrawingArea() - canvas.set_size_request(Gdk.Screen.width(), \ + canvas.set_size_request(Gdk.Screen.width() - W_I_WIDTH, \ Gdk.Screen.height()) - self.set_canvas(canvas) + self.main_hbox.pack_start(canvas, False, True, 0) + # make sure that our Webcam images directory is empty + webcam_image = Gtk.Image() + w_obj = WebcamImages(webcam_image, 7) + self.image_vbox.pack_start(webcam_image, False, True, 0) + self.image_vbox.show() + self.main_hbox.pack_end(self.image_vbox, False, True, 0) + self.main_hbox.show_all() + self.set_canvas(self.main_hbox) + self.main_hbox.show() canvas.show() self.show_all() diff --git a/WebcamImages.py b/WebcamImages.py new file mode 100644 index 0000000..76a66b3 --- /dev/null +++ b/WebcamImages.py @@ -0,0 +1,83 @@ +# Copyright (c) 2012 Aneesh Dogra <lionaneesh@gmail.com> +# +# 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 3 of the License, or +# (at your option) any later version. +# +# You should have received a copy of the GNU General Public License +# along with this library; if not, write to the Free Software +# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA + +import time +import gst +import os +from sugar3.activity import activity +from gi.repository import GdkPixbuf, GObject + +WEBCAM_IMAGES_DIR = os.path.join(activity.get_bundle_path(), 'webcam_images') +W_I_WIDTH = 170 +W_I_HEIGHT = 120 + +class WebcamImages(): + """ + Created by Aneesh Dogra + + Generates Webcam images. + + @param image_widget + image_widget: GtkImage widget which you want to update. + @param fps + fps: No of frames generated per second. + """ + def __init__(self, image_widget, fps): + image_list = os.listdir(WEBCAM_IMAGES_DIR) + for image in image_list: + os.remove(os.path.join(WEBCAM_IMAGES_DIR, image)) + self.gen_webcam_images(fps) + # Let's give it some time to initialize itself and generate some images + time.sleep(2) + image_widget.set_size_request(W_I_WIDTH, W_I_HEIGHT) + self.update_image(fps, image_widget) + def gen_webcam_images(self, fps): + """ + Generates Webcam images, and saves them in WEBCAM_IMAGES_DIR + """ + player = gst.parse_launch ("v4l2src ! videorate ! " \ + "video/x-raw-rgb,framerate=%d/1 ! " \ + "pngenc snapshot=false ! " \ + "multifilesink location=%s" % \ + (fps, + os.path.join(WEBCAM_IMAGES_DIR, + '%09d.png'), )) + + player.set_state(gst.STATE_PLAYING) + + def update_image(self, fps, image_widget): + """ + Updates the images in image_widget. + Used for Webcam Images. + The function checks for files in WEBCAM_IMAGES_DIR + and updates the images in image_widget. + """ + image_list = os.listdir(WEBCAM_IMAGES_DIR) + image_list.sort() + image_list = [os.path.join(WEBCAM_IMAGES_DIR, image) \ + for image in image_list] + image = image_list[-1] + print image + + if os.path.splitext(image)[-1] == '.png': + pixbuf = GdkPixbuf.Pixbuf.new_from_file(image) + pixbuf = pixbuf.scale_simple(W_I_WIDTH, W_I_HEIGHT, + GdkPixbuf.InterpType.BILINEAR) + image_widget.set_from_pixbuf(pixbuf) + for a in image_list: + os.remove(a) + + self.image_updater_thread = GObject.timeout_add(1000 / fps, + self.update_image, + fps, + image_widget) + def cleanup(self): + GObject.source_remove(self.image_updater_thread) diff --git a/bin/x86_64/gnuchess b/bin/x86_64/gnuchess Binary files differindex a6240aa..a6240aa 100644..100755 --- a/bin/x86_64/gnuchess +++ b/bin/x86_64/gnuchess @@ -55,7 +55,8 @@ WK = 10 BK = 11 FILES = 'abcdefgh' RANKS = '12345678' -BIN = {'i686': 'i686', 'i586': 'i686', 'armv7l': 'armv7l'} +BIN = {'i686': 'i686', 'i586': 'i686', 'armv7l': 'armv7l', + 'x86_64': 'x86_64'} class Gnuchess(): |