Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/smile.py
diff options
context:
space:
mode:
authorTony Anderson <tony_anderson@usa.net>2009-08-11 06:39:32 (GMT)
committer Tony Anderson <tony_anderson@usa.net>2009-08-11 06:39:32 (GMT)
commita9c66189f458d883bb940f11d744d00d0aa89683 (patch)
tree4968d84f8888208503a4fcb64e1d438afd87eb84 /smile.py
Initial commit
Diffstat (limited to 'smile.py')
-rwxr-xr-xsmile.py213
1 files changed, 213 insertions, 0 deletions
diff --git a/smile.py b/smile.py
new file mode 100755
index 0000000..1c2bad0
--- /dev/null
+++ b/smile.py
@@ -0,0 +1,213 @@
+# -*- 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
+
+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
+import zipfile
+import subprocess
+
+from path import path
+
+DATASTORE = '/home/olpc/.sugar/default/datastore/store'
+DATAPATH = path(activity.get_activity_root()) / "data"
+BUNDLEPATH = DATAPATH / 'bundle'
+SELECTTOOLBAR = 1
+
+
+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):
+ activity.Activity.__init__(self, handle)
+ self.set_title("Smile")
+ self.exit = False
+ self.connect("destroy", self.destroy)
+ self.connect("delete_event", self.destroy)
+ self.chooser = Smxoview(self)
+ # 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
+ # 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.show_all()
+
+ #set up bundle folder
+ subprocess.call("mkdir -p " + BUNDLEPATH, shell=True)
+ subprocess.call("rm -rf " + BUNDLEPATH + '/*', shell=True)
+
+ while self.exit == False:
+ self.flush_events()
+
+ def read_file(self, file_path):
+ print 'read_file:', file_path
+ z = zipfile.ZipFile(file_path, "r")
+ for i in z.infolist():
+ f = open(os.path.join(BUNDLEPATH, i.filename), "wb")
+ f.write(z.read(i.filename))
+ if path(i.filename).ext == ".smil":
+ self.doc = i.filename
+ f.close()
+ z.close()
+ print 'bundle unzipped'
+ #convert src to absolute path
+ f = open(BUNDLEPATH / self.doc, 'r')
+ t = f.read()
+ f.close()
+ tc = t.replace('src = "', 'src = "' + BUNDLEPATH + '/')
+ tcc = tc.replace('src="', 'src = "' + BUNDLEPATH + '/')
+ f = open(BUNDLEPATH / self.doc, 'w')
+ f.write(tcc)
+ f.close()
+ print 'smil=', tcc
+ #play smil document
+ self.player = ambulantglue.Glue(self.doc, self.ambulant_widget)
+ print 'player ready'
+ self.playbutton.show()
+
+class SelectToolBar(gtk.Toolbar):
+
+ def __init__(self, chooser):
+ gtk.Toolbar.__init__(self)
+ self.chooser = chooser
+
+ #get mount points
+ ds_mounts = datastore.mounts()
+ pendrive = -1
+ for i in range(0, len(ds_mounts), 1):
+ print 'mount', i, ds_mounts[i]['uri'], ds_mounts[i]['title'], ds_mounts[i]['id']
+ if ds_mounts[i]['uri'].find('datastore') > 0:
+ journal = i
+ else:
+ pendrive = i
+
+ self.journalbtn = ToolButton('activity-journal')
+ self.journalbtn.set_tooltip("Choose bundle")
+ self.journalbtn.connect('clicked', self.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.insert(self.pendrivebutton, -1)
+ self.pendrivebutton.show()
+ self.show()
+
+ self.playbutton = ToolButton('gtk-media-play')
+ self.playbutton.connect('clicked', self.play)
+ self.playbutton.show()
+ self.insert(self.playbutton, -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):
+ print 'smxoview init'
+ gtk.VBox.__init__(self)
+ self.activity = activity
+ 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.set_rules_hint(True)
+ sw.add(self.treeView)
+ self.create_columns(self.treeView)
+ self.pack_start(sw, True, True, 0)
+
+ def create_columns(self, treeView):
+
+ rendererText = gtk.CellRendererText()
+ column = gtk.TreeViewColumn("Title", rendererText, text=1)
+ column.set_sort_column_id(1)
+ treeView.append_column(column)
+ rendererText = gtk.CellRendererText()
+ column = gtk.TreeViewColumn("Date", rendererText, text=2)
+ column.set_sort_order(gtk.SORT_DESCENDING)
+ column.set_sort_column_id(2)
+ treeView.append_column(column)
+
+ def get_treeView(self):
+ return self.treeView
+
+ def set_store(self, mountpoint, pth):
+ print 'set_store', mountpoint, pth
+ store = gtk.ListStore(str, str, str)
+ #get objects from the local datastore
+ ds_objects, num_objects = datastore.find({'mountpoints':[mountpoint], 'mime_type':['application/x-smile', 'application/zip']})
+ for f in ds_objects:
+ object = f.object_id
+ title = f.metadata['title']
+ try:
+ t = f.metadata['timestamp']
+ except:
+ t = 0
+ #timestamp = datetime.fromtimestamp(t)
+ timestamp = t
+ store.append([object, title, timestamp])
+ 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()