diff options
author | Tony Anderson <tony_anderson@usa.net> | 2009-08-14 15:12:23 (GMT) |
---|---|---|
committer | Tony Anderson <tony_anderson@usa.net> | 2009-08-14 15:12:23 (GMT) |
commit | a0b743e044fd6e535d7eeb0f6019d52c7323dd1c (patch) | |
tree | 28c7549f3d04c8aebd20f26d0f1b5b9c2c5cbcec /smile.py | |
parent | a9c66189f458d883bb940f11d744d00d0aa89683 (diff) |
more development
Diffstat (limited to 'smile.py')
-rw-r--r--[-rwxr-xr-x] | smile.py | 200 |
1 files changed, 117 insertions, 83 deletions
@@ -1,83 +1,102 @@ -# -*- mode:python; tab-width:4; indent-tabs-mode:t; -*- - -# smile.py -# -# activity implementation of ambulant -# -# 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 +#!/usr/bin/env python + +# test ambulantglue + +import os, sys, time + +import pygtk +pygtk.require('2.0') +import gtk from sugar.activity import activity from sugar.datastore import datastore from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.menuitem import MenuItem - import ambulantglue - -import sys, os, time, datetime -import subprocess -import gtk +from path import path import zipfile import subprocess -from path import path - +BASE = path("/media/0BF7-0F5D") / 'sandbox' DATASTORE = '/home/olpc/.sugar/default/datastore/store' DATAPATH = path(activity.get_activity_root()) / "data" BUNDLEPATH = DATAPATH / 'bundle' SELECTTOOLBAR = 1 +class SmileyActivity(activity.Activity): -class SmileActivity(activity.Activity): - - def destroy(self, widgets, params): - self.exit = True - - def flush_events(self): - while gtk.events_pending(): - gtk.main_iteration() - - def __init__(self, handle): + def __init__ (self, handle): activity.Activity.__init__(self, handle) - self.set_title("Smile") - self.exit = False + self.set_title("Smiley") self.connect("destroy", self.destroy) - self.connect("delete_event", self.destroy) - self.chooser = Smxoview(self) + self.exit = False + #setup chooser screen + box = gtk.VBox(homogeneous=False) + self.chooser = Smxoview(self.on_activated) + self.chooser.show() + lbl = gtk.Label("Chooserscreen") + lbl.show() + box.pack_start(lbl, False, False, 0) + box.pack_start(self.chooser, True, True, 0) + self.chooserscreen = box # Create the standard activity toolbox; add our toolbar - # Create our toolbar - selectTB = SelectToolBar(self.chooser) - toolbox = activity.ActivityToolbox(self) - toolbox.add_toolbar("Select", selectTB) - self.set_toolbox(toolbox) - toolbox.show() - self.toolbox = toolbox + self.entry = gtk.Entry() + self.entry.connect("activate", self.set_smil) + self.entry.show() + selectTB = SelectToolBar(self.chooser, self.play_cb, self.entry, self.choosebundle, self.destroy) + self.toolbox = activity.ActivityToolbox(self) + self.toolbox.add_toolbar("Select", selectTB) # Open with slideshow toolbar - toolbox.set_current_toolbar(SELECTTOOLBAR) - self.child.pack_start(self.chooser, True, True, 0) - # Set up ambulant drawing area - self.ambulant_widget = gtk.DrawingArea() - self.child.pack_start(self.ambulant_widget, True, True, 0) + self.toolbox.set_current_toolbar(SELECTTOOLBAR) + self.toolbox.show() + self.set_toolbox(self.toolbox) + # layout the player screen + box = gtk.VBox() + lbl = gtk.Label("Playerscreen") + lbl.show() + box.pack_start(lbl, False, False, 0) + self.scrn = gtk.DrawingArea() + box.pack_start(self.scrn, True, True, 0) + self.playerscreen = box + self.screenbox = gtk.VBox() + self.set_canvas(self.screenbox) self.show_all() - + self.current_screen = None #set up bundle folder subprocess.call("mkdir -p " + BUNDLEPATH, shell=True) subprocess.call("rm -rf " + BUNDLEPATH + '/*', shell=True) + def flush_events(self): + while gtk.events_pending(): + gtk.main_iteration() + + def destroy(self): + self.exit = True + + def start(self): while self.exit == False: self.flush_events() + def play_cb(self, widget): + self.player.play() + self.destroy() + + def choosebundle(self, widget, source, pth): + treeview = self.chooser.get_treeView() + treeview.set_model(self.chooser.set_store(source, pth)) + treeview.show() + if not self.current_screen == None: + self.screenbox.remove(self.current_screen) + self.current_screen = self.chooserscreen + self.current_screen.show() + self.screenbox.pack_start(self.current_screen, True, True) + print 'choosebundle done' + + def set_smil(self, widget): + print self.entry.get_text() + pth = BASE / self.entry.get_text() + print 'pth=', pth + self.start_smil(pth) + def read_file(self, file_path): print 'read_file:', file_path z = zipfile.ZipFile(file_path, "r") @@ -100,13 +119,32 @@ class SmileActivity(activity.Activity): f.close() print 'smil=', tcc #play smil document - self.player = ambulantglue.Glue(self.doc, self.ambulant_widget) - print 'player ready' - self.playbutton.show() + self.start_smil(BUNDLEPATH / self.doc) + + def start_smil(self, pth): + if not self.current_screen == None: + self.screenbox.remove(self.current_screen) + self.current_screen = self.playerscreen + self.playerscreen.show() + self.screenbox.pack_start(self.current_screen, True, True) + self.player = ambulantglue.Glue(pth , self.scrn) + self.start() + + def on_activated(self, widget, row, col): + print 'smxo on_activated' + model = widget.get_model() + print 'row', model[row][0], model[row][1], model[row][2] + title = model[row][1] + timestamp = model[row][2] + object = datastore.get(model[row][0]) + fn = object.file_path + print 'object filename', path(fn).exists(), fn + #open slideshow, set Navigation toolbar current + self.read_file(fn) class SelectToolBar(gtk.Toolbar): - def __init__(self, chooser): + def __init__(self, chooser, play_cb, entry, choosebundle, destroy): gtk.Toolbar.__init__(self) self.chooser = chooser @@ -122,46 +160,56 @@ class SelectToolBar(gtk.Toolbar): self.journalbtn = ToolButton('activity-journal') self.journalbtn.set_tooltip("Choose bundle") - self.journalbtn.connect('clicked', self.choosebundle, ds_mounts[journal]['id'], DATASTORE) + self.journalbtn.connect('clicked', choosebundle, ds_mounts[journal]['id'], DATASTORE) self.insert(self.journalbtn, -1) self.journalbtn.show() - + #show pendrive button only if pendrive is mounted if pendrive > -1: self.pendrivebutton = ToolButton('media-flash-usb') self.pendrivebutton.set_tooltip("Choose bundle") - self.pendrivebutton.connect('clicked', self.choosebundle, ds_mounts[pendrive]['id'], ds_mounts[pendrive]['title']) + self.pendrivebutton.connect('clicked', choosebundle, ds_mounts[pendrive]['id'], ds_mounts[pendrive]['title']) self.insert(self.pendrivebutton, -1) self.pendrivebutton.show() self.show() self.playbutton = ToolButton('gtk-media-play') - self.playbutton.connect('clicked', self.play) + self.playbutton.connect('clicked', play_cb) self.playbutton.show() self.insert(self.playbutton, -1) + self.toolitem = gtk.ToolItem() + self.toolitem.set_expand(True) + self.toolitem.show() + self.toolitem.add(entry) + self.insert(self.toolitem, -1) + + self.quitbutton = ToolButton('ooops') + self.quitbutton.connect('clicked', destroy) + self.quitbutton.show() + self.insert(self.quitbutton, -1) + def choosebundle(self, widget, source, pth): treeview = self.chooser.get_treeView() treeview.set_model(self.chooser.set_store(source, pth)) print 'choosebundle done' - def play(self): - print 'play' - self.player(play) - class Smxoview(gtk.VBox): - def __init__(self, activity): + def __init__(self, on_activated): print 'smxoview init' gtk.VBox.__init__(self) - self.activity = activity + lbl = gtk.Label("smxoview") + lbl.show() + self.pack_start(lbl, False, False, 0) sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.treeView = gtk.TreeView() - self.treeView.connect("row-activated", self.on_activated) + self.treeView.connect("row-activated", on_activated) self.treeView.set_rules_hint(True) sw.add(self.treeView) self.create_columns(self.treeView) + sw.show() self.pack_start(sw, True, True, 0) def create_columns(self, treeView): @@ -197,17 +245,3 @@ class Smxoview(gtk.VBox): f.destroy() print 'return smxo store', len(store) return store - - def on_activated(self, widget, row, col): - print 'smxo on_activated' - model = widget.get_model() - print 'row', model[row][0], model[row][1], model[row][2] - title = model[row][1] - timestamp = model[row][2] - object = datastore.get(model[row][0]) - fn = object.file_path - print 'object filename', path(fn).exists(), fn - #open slideshow, set Navigation toolbar current - self.activity.read_file(fn) - for object in ds_objects: - object.destroy() |