From 86ce7d4c14b458dce4edca81af8ae9fff0a770f7 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Sun, 18 Jan 2009 23:01:58 +0000 Subject: ... --- diff --git a/Bundle.py b/Bundle.py new file mode 100644 index 0000000..c2f2a35 --- /dev/null +++ b/Bundle.py @@ -0,0 +1,123 @@ +# 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 + +def load(filepath): + pass + +def save(filepath): + pass + +""" + pics = self.getpics(self.imgdir) + pixbuf = gtk.gdk.pixbuf_new_from_file(pics[self.imgstartindex]) + scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.ccismall.set_from_pixbuf(scaled_buf) + self.charlabel.set_label(os.path.split(self.imgdir)[1]) + + + def restore(self, sdata): + # THE BELOW SHOULD WORK BUT DOESN'T + #zf = StringIO.StringIO(sdata) + #self.loadfromzip(zf) + # END OF STUFF THAT DOESN'T WORK + sdd = pickle.loads(sdata) + tmpbgpath = os.path.join(TMPDIR,'back.png') + f = file(tmpbgpath,'w') + f.write(sdd['pngdata']) + f.close() + self.setback(tmpbgpath) + os.remove(tmpbgpath) + transimgpath = os.path.join(self.iconsdir,TRANSIMG) + for i in range(len(sdd['fgpixbufpaths'])): + filepath = sdd['fgpixbufpaths'][i] + if filepath == transimgpath: + continue + pixbuf = gtk.gdk.pixbuf_new_from_file(filepath) + fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.fgpixbufs[i] = fgpixbuf + if i == 0: + self.fgpixbuf = fgpixbuf + self.drawmain() + scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.frameimgs[i].set_from_pixbuf(scaled_buf) + + + def loadfromzip(self, f): + # print filepath + #zf = zipfile.ZipFile(filepath,'r') + zf = zipfile.ZipFile(f) + fnames = zf.namelist() + framenames = [] + for fname in fnames: + if fname[-8:] == 'back.png': + backname = fname + else: + framenames.append(fname) + framenames.sort() + # set the background + tmpbgpath = os.path.join(TMPDIR,'back.png') + f = file(tmpbgpath,'w') + f.write(zf.read(backname)) + f.close() + self.setback(tmpbgpath) + os.remove(tmpbgpath) + self.imgdir = TMPDIR + for filepath in framenames: + fname = os.path.split(filepath)[1] + tmpfilepath = os.path.join(TMPDIR,fname) + f = file(tmpfilepath,'w') + f.write(zf.read(filepath)) + f.close() + zf.close() + self.loadimages() + # setup the filmstrip frames + pics = self.getpics(self.imgdir) + count = 0 + for imgpath in pics: + pixbuf = gtk.gdk.pixbuf_new_from_file(imgpath) + fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.fgpixbufs[count] = fgpixbuf + if count == 0: + self.fgpixbuf = fgpixbuf + self.drawmain() + scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.frameimgs[count].set_from_pixbuf(scaled_buf) + count += 1 + entries = os.listdir(TMPDIR) + for entry in entries: + entrypath = os.path.join(TMPDIR,entry) + os.remove(entrypath) + + def savetozip(self, f): + # print filepath + #zf = zipfile.ZipFile(filepath,'w') + zf = zipfile.ZipFile(f,'w') + # add the background file + tmpbgpath = os.path.join(TMPDIR,'back.png') + self.bgpixbuf.save(tmpbgpath,'png') + zf.write(tmpbgpath) + os.remove(tmpbgpath) + # add the frames + count = 1 + for pixbuf in self.fgpixbufs: + filename = '%02d.png' % count + filepath = os.path.join(TMPDIR,filename) + pixbuf.save(filepath,'png') + zf.write(filepath) + os.remove(filepath) + count += 1 + zf.close() + + +""" diff --git a/Char.py b/Char.py new file mode 100644 index 0000000..a6efb6f --- /dev/null +++ b/Char.py @@ -0,0 +1,109 @@ +# 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 gtk + +Size = (100, 100) + +class Char: + id = 0 + pixbuf = None #gtk.gdk.Pixbuf() + +def list(): + return [Char()] + + +""" + pics = self.getpics(self.imgdir) + pixbuf = gtk.gdk.pixbuf_new_from_file(pics[self.imgstartindex]) + scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.ccismall.set_from_pixbuf(scaled_buf) + self.charlabel.set_label(os.path.split(self.imgdir)[1]) + + + def restore(self, sdata): + # THE BELOW SHOULD WORK BUT DOESN'T + #zf = StringIO.StringIO(sdata) + #self.loadfromzip(zf) + # END OF STUFF THAT DOESN'T WORK + sdd = pickle.loads(sdata) + tmpbgpath = os.path.join(TMPDIR,'back.png') + f = file(tmpbgpath,'w') + f.write(sdd['pngdata']) + f.close() + self.setback(tmpbgpath) + os.remove(tmpbgpath) + transimgpath = os.path.join(self.iconsdir,TRANSIMG) + for i in range(len(sdd['fgpixbufpaths'])): + filepath = sdd['fgpixbufpaths'][i] + if filepath == transimgpath: + continue + pixbuf = gtk.gdk.pixbuf_new_from_file(filepath) + fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.fgpixbufs[i] = fgpixbuf + if i == 0: + self.fgpixbuf = fgpixbuf + self.drawmain() + scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.frameimgs[i].set_from_pixbuf(scaled_buf) + + + def loadfromzip(self, f): + # print filepath + #zf = zipfile.ZipFile(filepath,'r') + zf = zipfile.ZipFile(f) + fnames = zf.namelist() + framenames = [] + for fname in fnames: + if fname[-8:] == 'back.png': + backname = fname + else: + framenames.append(fname) + framenames.sort() + # set the background + tmpbgpath = os.path.join(TMPDIR,'back.png') + f = file(tmpbgpath,'w') + f.write(zf.read(backname)) + f.close() + self.setback(tmpbgpath) + os.remove(tmpbgpath) + self.imgdir = TMPDIR + for filepath in framenames: + fname = os.path.split(filepath)[1] + tmpfilepath = os.path.join(TMPDIR,fname) + f = file(tmpfilepath,'w') + f.write(zf.read(filepath)) + f.close() + zf.close() + self.loadimages() + # setup the filmstrip frames + pics = self.getpics(self.imgdir) + count = 0 + for imgpath in pics: + pixbuf = gtk.gdk.pixbuf_new_from_file(imgpath) + fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.fgpixbufs[count] = fgpixbuf + if count == 0: + self.fgpixbuf = fgpixbuf + self.drawmain() + scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) + self.frameimgs[count].set_from_pixbuf(scaled_buf) + count += 1 + entries = os.listdir(TMPDIR) + for entry in entries: + entrypath = os.path.join(TMPDIR,entry) + os.remove(entrypath) + + +""" diff --git a/ComboBox.py b/ComboBox.py new file mode 100644 index 0000000..d5a6c64 --- /dev/null +++ b/ComboBox.py @@ -0,0 +1,39 @@ +import pygtk +import gtk + +from sugar.graphics.combobox import ComboBox + +class BigComboBox(ComboBox): + def __init__(self): + ComboBox.__init__(self) + + def append_item(self, action_id, text = None, icon_name = None, size = None, + pixbuf = None): + + if not self._icon_renderer and (icon_name or pixbuf): + self._icon_renderer = gtk.CellRendererPixbuf() + + settings = self.get_settings() + w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) + self._icon_renderer.props.stock_size = w + + self.pack_start(self._icon_renderer, False) + self.add_attribute(self._icon_renderer, 'pixbuf', 2) + + if not self._text_renderer and text: + self._text_renderer = gtk.CellRendererText() + self.pack_end(self._text_renderer, True) + self.add_attribute(self._text_renderer, 'text', 1) + + if not pixbuf: + if icon_name: + if not size: + size = gtk.ICON_SIZE_LARGE_TOOLBAR + width, height = gtk.icon_size_lookup(size) + else: + width, height = size + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name, width, height) + else: + pixbuf = None + + self._model.append([action_id, text, pixbuf, False]) diff --git a/Shared.py b/Shared.py new file mode 100644 index 0000000..d786ad3 --- /dev/null +++ b/Shared.py @@ -0,0 +1,204 @@ +from sugar.activity import activity +from sugar.presence import presenceservice +from sugar.presence.tubeconn import TubeConnection +import telepathy +import telepathy.client +from dbus import Interface +from dbus.service import method, signal +from dbus.gobject_service import ExportedGObject + +SERVICE = 'org.freedesktop.Telepathy.Tube.Connect' +IFACE = SERVICE +PATH = '/org/freedesktop/Telepathy/Tube/Connect' + +class Shared(activity.Activity): + def __init__(self, handle): + activity.Activity.__init__(self,handle) + + # mesh stuff + self.pservice = presenceservice.get_instance() + owner = self.pservice.get_owner() + self.owner = owner + try: + name, path = self.pservice.get_preferred_connection() + self.tp_conn_name = name + self.tp_conn_path = path + self.conn = telepathy.client.Connection(name, path) + except TypeError: + pass + self.initiating = None + + #sharing stuff + self.game = None + self.connect('shared', self._shared_cb) + if self._shared_activity: + # we are joining the activity + self.connect('joined', self._joined_cb) + if self.get_shared(): + # oh, OK, we've already joined + self._joined_cb() + else: + # we are creating the activity + pass + + + def _shared_cb(self,activity): + self.initiating = True + self._setup() + id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube( + SERVICE, {}) + #self.app.export.set_label('Shared Me') + + def _joined_cb(self,activity): + if self.game is not None: + return + + if not self._shared_activity: + return + + #for buddy in self._shared_activity.get_joined_buddies(): + # self.buddies_panel.add_watcher(buddy) + + #logger.debug('Joined an existing Connect game') + #self.app.export.set_label('Joined You') + self.initiating = False + self._setup() + + #logger.debug('This is not my activity: waiting for a tube...') + self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].ListTubes( + reply_handler=self._list_tubes_reply_cb, + error_handler=self._list_tubes_error_cb) + + def _setup(self): + if self._shared_activity is None: + return + + bus_name, conn_path, channel_paths = self._shared_activity.get_channels() + + # Work out what our room is called and whether we have Tubes already + room = None + tubes_chan = None + text_chan = None + for channel_path in channel_paths: + channel = telepathy.client.Channel(bus_name, channel_path) + htype, handle = channel.GetHandle() + if htype == telepathy.HANDLE_TYPE_ROOM: + #logger.debug('Found our room: it has handle#%d "%s"', + # handle, self.conn.InspectHandles(htype, [handle])[0]) + room = handle + ctype = channel.GetChannelType() + if ctype == telepathy.CHANNEL_TYPE_TUBES: + #logger.debug('Found our Tubes channel at %s', channel_path) + tubes_chan = channel + elif ctype == telepathy.CHANNEL_TYPE_TEXT: + #logger.debug('Found our Text channel at %s', channel_path) + text_chan = channel + + if room is None: + #logger.error("Presence service didn't create a room") + return + if text_chan is None: + #logger.error("Presence service didn't create a text channel") + return + + # Make sure we have a Tubes channel - PS doesn't yet provide one + if tubes_chan is None: + #logger.debug("Didn't find our Tubes channel, requesting one...") + tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES, + telepathy.HANDLE_TYPE_ROOM, room, True) + + self.tubes_chan = tubes_chan + self.text_chan = text_chan + + tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube', + self._new_tube_cb) + + def _list_tubes_reply_cb(self, tubes): + for tube_info in tubes: + self._new_tube_cb(*tube_info) + + def _list_tubes_error_cb(self, e): + #logger.error('ListTubes() failed: %s', e) + pass + + def _new_tube_cb(self, id, initiator, type, service, params, state): + #logger.debug('New tube: ID=%d initator=%d type=%d service=%s ' + # 'params=%r state=%d', id, initiator, type, service, + # params, state) + + if (self.game is None and type == telepathy.TUBE_TYPE_DBUS and + service == SERVICE): + if state == telepathy.TUBE_STATE_LOCAL_PENDING: + self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id) + + tube_conn = TubeConnection(self.conn, + self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES], + id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]) + self.game = ConnectGame(tube_conn, self.initiating, self) + +class ConnectGame(ExportedGObject): + def __init__(self,tube, is_initiator, activity): + super(ConnectGame,self).__init__(tube,PATH) + self.tube = tube + self.is_initiator = is_initiator + self.entered = False + self.activity = activity + + self.ordered_bus_names=[] + self.tube.watch_participants(self.participant_change_cb) + + def participant_change_cb(self, added, removed): + if not self.entered: + if self.is_initiator: + self.add_hello_handler() + else: + self.Hello() + self.entered = True + + @signal(dbus_interface=IFACE,signature='') + def Hello(self): + """Request that this player's Welcome method is called to bring it + up to date with the game state. + """ + + @method(dbus_interface=IFACE, in_signature='s', out_signature='') + def Welcome(self, sdata): + #sdata is the zip file contents + #self.activity.app.lessonplans.set_label('got data to restore') + self.activity.app.restore(str(sdata)) + + def add_hello_handler(self): + self.tube.add_signal_receiver(self.hello_cb, 'Hello', IFACE, + path=PATH, sender_keyword='sender') + + def hello_cb(self, sender=None): + self.tube.get_object(sender, PATH).Welcome(self.activity.app.getsdata(),dbus_interface=IFACE) + + +""" + def getsdata(self): + #self.lessonplans.set_label('getting sdata') + # THE BELOW SHOULD WORK BUT DOESN'T + #zf = StringIO.StringIO() + #self.savetozip(zf) + #zf.seek(0) + #sdata = zf.read() + #zf.close() + # END OF STUFF THAT DOESN'T WORK + sdd = {} + tmpbgpath = os.path.join(TMPDIR,'back.png') + self.bgpixbuf.save(tmpbgpath,'png') + sdd['pngdata'] = file(tmpbgpath).read() + os.remove(tmpbgpath) + sdd['fgpixbufpaths'] = self.fgpixbufpaths + #sdd['fgpixbufs'] = [] + #count = 1 + #for pixbuf in self.fgpixbufs: + # filename = '%02d.png' % count + # filepath = os.path.join(TMPDIR,filename) + # pixbuf.save(filepath,'png') + # sdd['fgpixbufs'].append(file(filepath).read()) + # os.remove(filepath) + # count += 1 + return pickle.dumps(sdd) +""" diff --git a/cartoonbuilder.py b/cartoonbuilder.py index edafcfd..06903da 100755 --- a/cartoonbuilder.py +++ b/cartoonbuilder.py @@ -37,11 +37,11 @@ import pickle import gst from sugar.activity.activity import get_activity_root -_ = gettext.lgettext +from ComboBox import * +from Shared import * +import Char -SERVICE = 'org.freedesktop.Telepathy.Tube.Connect' -IFACE = SERVICE -PATH = '/org/freedesktop/Telepathy/Tube/Connect' +_ = gettext.lgettext TRANSIMG = '50x50blank-trans.png' BGHEIGHT = gtk.gdk.screen_height() - 450 # 425 @@ -246,33 +246,15 @@ class cartoonbuilder: self.bgsmall.set_from_pixbuf(scaled_buf) self.drawmain() - def setcharacter(self): - pics = self.getpics(self.imgdir) - pixbuf = gtk.gdk.pixbuf_new_from_file(pics[self.imgstartindex]) - scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.ccismall.set_from_pixbuf(scaled_buf) - self.charlabel.set_label(os.path.split(self.imgdir)[1]) - - def lastcharacter(self, widget, data=None): + def _char_cb(self, widget): if self.imgdirindex == 0: self.imgdirindex = (len(self.imgdirs)-1) else: self.imgdirindex -= 1 - self.imgstartindex = 0 - self.imgdir = self.imgdirs[self.imgdirindex] - self.loadimages() - self.setcharacter() - self.drawmain() - def nextcharacter(self, widget, data=None): - if self.imgdirindex == (len(self.imgdirs)-1): - self.imgdirindex = 0 - else: - self.imgdirindex += 1 self.imgstartindex = 0 self.imgdir = self.imgdirs[self.imgdirindex] self.loadimages() - self.setcharacter() self.drawmain() def changesound(self): @@ -381,271 +363,6 @@ class cartoonbuilder: self.mfdraw.bgpixbuf = self.bgpixbuf self.mfdraw.queue_draw() - def getbackgroundfile(self, widget, data=None): - dialog = gtk.FileChooserDialog(title="Open..", - action=gtk.FILE_CHOOSER_ACTION_OPEN, - buttons=(gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL, - gtk.STOCK_OPEN, gtk.RESPONSE_OK)) - if self.insugar: - dialog.set_current_folder('/home/olpc') - dialog.set_default_response(gtk.RESPONSE_OK) - - #filter = gtk.FileFilter() - #filter.set_name("All files") - #filter.add_pattern("*") - #dialog.add_filter(filter) - - filter = gtk.FileFilter() - filter.set_name("Images") - filter.add_mime_type("image/png") - filter.add_mime_type("image/jpeg") - filter.add_mime_type("image/gif") - filter.add_pattern("*.png") - filter.add_pattern("*.jpg") - filter.add_pattern("*.gif") - dialog.add_filter(filter) - - response = dialog.run() - if response == gtk.RESPONSE_OK: - #print dialog.get_filename(), 'selected' - bgimgpath = dialog.get_filename() - self.backpicpaths.append(bgimgpath) - self.backnum = self.backpicpaths.index(bgimgpath) - self.setback(bgimgpath) - f = file(os.path.join(self.mdirpath,'config.backpics'),'a') - f.write('%s\n' % bgimgpath) - f.close() - elif response == gtk.RESPONSE_CANCEL: - # print 'Closed, no files selected' - pass - dialog.destroy() - - def getimgdir(self, widget, data=None): - daction = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER - dialog = gtk.FileChooserDialog(title='Select Folder', - action=daction, - buttons=(gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, - gtk.RESPONSE_OK)) - if self.insugar: - dialog.set_current_folder('/home/olpc') - dialog.set_default_response(gtk.RESPONSE_OK) - response = dialog.run() - if response == gtk.RESPONSE_OK: - #print dialog.get_filename(), 'selected' - imgdir = dialog.get_filename() - pics = self.getpics(imgdir) - if pics: - self.imgdir = imgdir - self.imgdirs.append(imgdir) - self.imgdirindex = self.imgdirs.index(imgdir) - self.loadimages() - self.setcharacter() - self.drawmain() - f = file(os.path.join(self.mdirpath,'config.imgdirs'),'a') - f.write('%s\n' % imgdir) - f.close() - elif response == gtk.RESPONSE_CANCEL: - pass - dialog.destroy() - - def getsoundfile(self, widget, data=None): - dialog = gtk.FileChooserDialog(title="Open..", - action=gtk.FILE_CHOOSER_ACTION_OPEN, - buttons=(gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL, - gtk.STOCK_OPEN, gtk.RESPONSE_OK)) - if self.insugar: - dialog.set_current_folder('/home/olpc') - dialog.set_default_response(gtk.RESPONSE_OK) - - filter = gtk.FileFilter() - filter.set_name("Sounds") - #filter.add_mime_type("image/png") - filter.add_pattern('*.wav') - filter.add_pattern('*.mp3') - filter.add_pattern('*.ogg') - dialog.add_filter(filter) - - response = dialog.run() - if response == gtk.RESPONSE_OK: - soundfilepath = dialog.get_filename() - self.sounds.append(soundfilepath) - self.soundfile = soundfilepath - self.soundindex = self.sounds.index(soundfilepath) - self.changesound() - f = file(os.path.join(self.mdirpath,'config.sounds'),'a') - f.write('%s\n' % soundfilepath) - f.close() - elif response == gtk.RESPONSE_CANCEL: - # print 'Closed, no files selected' - pass - dialog.destroy() - - def getsdata(self): - #self.lessonplans.set_label('getting sdata') - # THE BELOW SHOULD WORK BUT DOESN'T - #zf = StringIO.StringIO() - #self.savetozip(zf) - #zf.seek(0) - #sdata = zf.read() - #zf.close() - # END OF STUFF THAT DOESN'T WORK - sdd = {} - tmpbgpath = os.path.join(TMPDIR,'back.png') - self.bgpixbuf.save(tmpbgpath,'png') - sdd['pngdata'] = file(tmpbgpath).read() - os.remove(tmpbgpath) - sdd['fgpixbufpaths'] = self.fgpixbufpaths - #sdd['fgpixbufs'] = [] - #count = 1 - #for pixbuf in self.fgpixbufs: - # filename = '%02d.png' % count - # filepath = os.path.join(TMPDIR,filename) - # pixbuf.save(filepath,'png') - # sdd['fgpixbufs'].append(file(filepath).read()) - # os.remove(filepath) - # count += 1 - return pickle.dumps(sdd) - - def restore(self, sdata): - # THE BELOW SHOULD WORK BUT DOESN'T - #zf = StringIO.StringIO(sdata) - #self.loadfromzip(zf) - # END OF STUFF THAT DOESN'T WORK - sdd = pickle.loads(sdata) - tmpbgpath = os.path.join(TMPDIR,'back.png') - f = file(tmpbgpath,'w') - f.write(sdd['pngdata']) - f.close() - self.setback(tmpbgpath) - os.remove(tmpbgpath) - transimgpath = os.path.join(self.iconsdir,TRANSIMG) - for i in range(len(sdd['fgpixbufpaths'])): - filepath = sdd['fgpixbufpaths'][i] - if filepath == transimgpath: - continue - pixbuf = gtk.gdk.pixbuf_new_from_file(filepath) - fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.fgpixbufs[i] = fgpixbuf - if i == 0: - self.fgpixbuf = fgpixbuf - self.drawmain() - scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.frameimgs[i].set_from_pixbuf(scaled_buf) - - def savefile(self, widget, data=None): - daction = gtk.FILE_CHOOSER_ACTION_SAVE - dialog = gtk.FileChooserDialog(title='Save Animation', - action=daction, - buttons=(gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, - gtk.RESPONSE_OK)) - if self.insugar: - dialog.set_current_folder('/home/olpc') - dialog.set_current_name('cartoon.zip') - dialog.set_default_response(gtk.RESPONSE_OK) - response = dialog.run() - if response == gtk.RESPONSE_OK: - filepath = dialog.get_filename() - zf = file(filepath,'w') - self.savetozip(zf) - elif response == gtk.RESPONSE_CANCEL: - pass - dialog.destroy() - - def savetozip(self, f): - # print filepath - #zf = zipfile.ZipFile(filepath,'w') - zf = zipfile.ZipFile(f,'w') - # add the background file - tmpbgpath = os.path.join(TMPDIR,'back.png') - self.bgpixbuf.save(tmpbgpath,'png') - zf.write(tmpbgpath) - os.remove(tmpbgpath) - # add the frames - count = 1 - for pixbuf in self.fgpixbufs: - filename = '%02d.png' % count - filepath = os.path.join(TMPDIR,filename) - pixbuf.save(filepath,'png') - zf.write(filepath) - os.remove(filepath) - count += 1 - zf.close() - - def loadfile(self, widget, data=None): - daction = gtk.FILE_CHOOSER_ACTION_OPEN - dialog = gtk.FileChooserDialog(title='Select File', - action=daction, - buttons=(gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, - gtk.RESPONSE_OK)) - if self.insugar: - dialog.set_current_folder('/home/olpc') - dialog.set_default_response(gtk.RESPONSE_OK) - filter = gtk.FileFilter() - filter.set_name("Zipfiles") - #filter.add_mime_type("image/gif") - filter.add_pattern("*.zip") - dialog.add_filter(filter) - response = dialog.run() - if response == gtk.RESPONSE_OK: - filepath = dialog.get_filename() - zf = file(filepath,'r') - self.loadfromzip(zf) - elif response == gtk.RESPONSE_CANCEL: - pass - dialog.destroy() - - def loadfromzip(self, f): - # print filepath - #zf = zipfile.ZipFile(filepath,'r') - zf = zipfile.ZipFile(f) - fnames = zf.namelist() - framenames = [] - for fname in fnames: - if fname[-8:] == 'back.png': - backname = fname - else: - framenames.append(fname) - framenames.sort() - # set the background - tmpbgpath = os.path.join(TMPDIR,'back.png') - f = file(tmpbgpath,'w') - f.write(zf.read(backname)) - f.close() - self.setback(tmpbgpath) - os.remove(tmpbgpath) - self.imgdir = TMPDIR - for filepath in framenames: - fname = os.path.split(filepath)[1] - tmpfilepath = os.path.join(TMPDIR,fname) - f = file(tmpfilepath,'w') - f.write(zf.read(filepath)) - f.close() - zf.close() - self.loadimages() - #self.setcharacter() - # setup the filmstrip frames - pics = self.getpics(self.imgdir) - count = 0 - for imgpath in pics: - pixbuf = gtk.gdk.pixbuf_new_from_file(imgpath) - fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.fgpixbufs[count] = fgpixbuf - if count == 0: - self.fgpixbuf = fgpixbuf - self.drawmain() - scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.frameimgs[count].set_from_pixbuf(scaled_buf) - count += 1 - entries = os.listdir(TMPDIR) - for entry in entries: - entrypath = os.path.join(TMPDIR,entry) - os.remove(entrypath) - def setplayspeed(self,adj): self.waittime = int((6-adj.value)*150) if self.playing: @@ -690,7 +407,6 @@ class cartoonbuilder: if self.imgstartindex > 0: self.imgstartindex -= 2 self.loadimages() - self.setcharacter() self.drawmain() def imgdown(self, widget, data=None): @@ -698,7 +414,6 @@ class cartoonbuilder: if len(pics[self.imgstartindex:]) > FRAME_COUNT: self.imgstartindex += 2 self.loadimages() - self.setcharacter() self.drawmain() def gettranspixbuf(self, width=50, height=50): @@ -709,6 +424,7 @@ class cartoonbuilder: scaled_buf = pixbuf.scale_simple(width,height,gtk.gdk.INTERP_BILINEAR) return scaled_buf + """ def showlessonplans(self, widget, data=None): dia = gtk.Dialog(title='Lesson Plans', parent=None, @@ -755,58 +471,7 @@ class cartoonbuilder: dia.vbox.pack_start(notebook, True, True, 0) result = dia.run() dia.destroy() - - def changed_cb(self, combobox): - model = combobox.get_model() - index = combobox.get_active() - if index: - lang = model[index][0] - if lang == 'Espa\xc3\xb1ol': - lang = SPANISH - if lang in LANG: - self.lessonplans.set_label(LANG[lang]['lessonplan']) - prepare_btn(self.lessonplans) - if not self.insugar: - self.character.set_label(LANG[lang]['character']) - prepare_btn(self.character) - self.bgbutton.set_label(LANG[lang]['background']) - prepare_btn(self.bgbutton) - self.soundbutton.set_label(LANG[lang]['sound']) - prepare_btn(self.soundbutton) - else: - print repr(lang) - return - - def changebuttonlang(self): - self.lessonplans.set_label(LANG[self.language]['lessonplan']) - prepare_btn(self.lessonplans) - self.lang.set_label(self.language) - prepare_btn(self.lang) - self.character.set_label(LANG[self.language]['character']) - prepare_btn(self.character) - self.bgbutton.set_label(LANG[self.language]['background']) - prepare_btn(self.bgbutton) - self.soundbutton.set_label(LANG[self.language]['sound']) - prepare_btn(self.soundbutton) - - def setlastlanguage(self, widget, data=None): - li = LANGLIST.index(self.language) - if li == 0: - self.language = LANGLIST[len(LANGLIST)-1] - else: - self.language = LANGLIST[li-1] - self.changebuttonlang() - - def setnextlanguage(self, widget, data=None): - li = LANGLIST.index(self.language) - if li == (len(LANGLIST)-1): - self.language = LANGLIST[0] - else: - self.language = LANGLIST[li+1] - self.changebuttonlang() - - def getdefaultlang(self): - return 'English' + """ def __init__(self,insugar,toplevel_window,mdirpath): self.mdirpath = mdirpath @@ -825,8 +490,6 @@ class cartoonbuilder: self.backpicpaths.append(bpfilepath) bpfile.close() self.waittime = 3*150 - self.insugar = insugar - self.language = self.getdefaultlang() self.imgdirs = [] imgdirfile = file(os.path.join(self.mdirpath,'config.imgdirs')) for line in imgdirfile: @@ -859,86 +522,12 @@ class cartoonbuilder: # END GSTREAMER STUFF self.fgpixbuf = self.gettranspixbuf(BGWIDTH,BGHEIGHT) - self.mpbox = gtk.VBox() - - self.main = gtk.EventBox() - self.main.show() - self.main.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BUTTON_BACKGROUND)) - self.mainbox = gtk.EventBox() - self.mainbox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND)) - self.mainbox.set_border_width(5) - self.mainbox.show() - self.main.add(self.mainbox) - self.mpbox.show() - self.logobox = gtk.HBox(False,0) - self.logobox.show() - self.logo = gtk.Image() - self.logo.show() - self.logo.set_from_file(os.path.join(self.iconsdir,'logo.png')) - self.logobox.pack_start(self.logo,False,False,0) - self.lessonplans = gtk.Button('Lesson Plans') - self.lessonplans.connect('clicked',self.showlessonplans, None) - prepare_btn(self.lessonplans) - self.lessonplans.show() - self.lpvbox = gtk.VBox() - self.lpvbox.show() - self.lpvbox.pack_start(self.lessonplans,True,False,0) - self.lpoframe = gtk.EventBox() - self.lpoframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) - self.lpoframe.show() - self.lpframe = gtk.EventBox() - self.lpframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND)) - self.lpframe.show() - self.lpalign = gtk.Alignment(1.0,1.0,1.0,1.0) - self.lpalign.add(self.lpframe) - self.lpalign.set_padding(5,0,5,0) - self.lpalign.show() - self.lpoframe.add(self.lpalign) - self.lphbox = gtk.HBox() - self.lphbox.show() - self.lphbox.pack_start(self.lpvbox,True,False,0) - self.lpframe.add(self.lphbox) - self.logobox.pack_start(self.lpoframe,True,True,0) - self.langdd = gtk.combo_box_new_text() - self.langdd.append_text('Language') - self.langdd.append_text('English') - self.langdd.append_text(SPANISH) - self.langdd.connect('changed', self.changed_cb) - self.langdd.set_active(0) - self.langdd.show() - self.langddvbox = gtk.VBox() - self.langddvbox.show() - self.langddvbox.pack_start(self.langdd,True,False,0) - #vvvv LANGUAGE BUTTONS vvvv - #self.lastlang = gtk.Button() - #self.lastlang.connect('clicked', self.setlastlanguage, None) - #llla = gtk.Image() - #llla.set_from_file(os.path.join(self.iconsdir,'left_arrow.png')) - #llla.show() - #self.lastlang.add(llla) - #prepare_btn(self.lastlang) - #self.lastlang.show() - #self.llvbox = gtk.VBox() - #self.llvbox.show() - #self.llvbox.pack_start(self.lastlang,True,False,0) - #self.lang = gtk.Button(self.language) - #prepare_btn(self.lang) - #self.lang.show() - #self.nextlang = gtk.Button() - #self.nextlang.connect('clicked', self.setnextlanguage, None) - #nlra = gtk.Image() - #nlra.set_from_file(os.path.join(self.iconsdir,'right_arrow.png')) - #nlra.show() - #self.nextlang.add(nlra) - #prepare_btn(self.nextlang) - #self.nextlang.show() - #self.nlvbox = gtk.VBox() - #self.nlvbox.show() - #self.nlvbox.pack_start(self.nextlang,True,False,0) - #self.langvbox = gtk.VBox() - #self.langvbox.show() - #self.langvbox.pack_start(self.lang,True,False,0) - #^^^^ LANGUAGE BUTTONS^^^^ + + + + + + self.langoframe = gtk.EventBox() self.langoframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) self.langoframe.show() @@ -947,10 +536,7 @@ class cartoonbuilder: self.langframe.show() self.langalign = gtk.Alignment(1.0,1.0,1.0,1.0) self.langalign.add(self.langframe) - if not self.insugar: - self.langalign.set_padding(5,0,5,0) - else: - self.langalign.set_padding(5,0,5,5) + self.langalign.set_padding(5,0,5,5) self.langalign.show() self.langoframe.add(self.langalign) self.langhbox = gtk.HBox() @@ -958,73 +544,9 @@ class cartoonbuilder: #self.langhbox.pack_start(self.llvbox,True,False,0) #self.langhbox.pack_start(self.langvbox,True,False,0) #self.langhbox.pack_start(self.nlvbox,True,False,0) - self.langhbox.pack_start(self.langddvbox,True,False,0) self.langframe.add(self.langhbox) - self.logobox.pack_start(self.langoframe,True,True,0) - - if not self.insugar: - self.sooframe = gtk.EventBox() - self.sooframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) - self.sooframe.show() - self.soframe = gtk.EventBox() - self.soframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND)) - self.soframe.show() - self.soalign = gtk.Alignment(1.0,1.0,1.0,1.0) - self.soalign.add(self.soframe) - self.soalign.set_padding(5,0,5,5) - self.soalign.show() - self.sooframe.add(self.soalign) - self.fsvbox = gtk.VBox() - self.fsvbox.show() - self.fileopen = gtk.Button() - openimg = gtk.Image() - openimg.set_from_stock(gtk.STOCK_OPEN,gtk.ICON_SIZE_BUTTON) - openimg.show() - prepare_btn(self.fileopen) - self.fileopen.set_label('') - self.fileopen.set_image(openimg) - self.fileopen.connect('clicked',self.loadfile, None) - self.fileopen.show() - self.fovbox = gtk.VBox() - self.fovbox.show() - self.fovbox.pack_start(self.fileopen,True,False,0) - self.fohbox = gtk.HBox() - self.fohbox.show() - self.fohbox.pack_start(self.fovbox,True,False,0) - self.filesave = gtk.Button() - saveimg = gtk.Image() - saveimg.set_from_stock(gtk.STOCK_SAVE,gtk.ICON_SIZE_BUTTON) - saveimg.show() - prepare_btn(self.filesave) - self.filesave.set_label('') - self.filesave.set_image(saveimg) - self.filesave.connect('clicked',self.savefile, None) - self.filesave.show() - self.fsvbox.pack_start(self.filesave,True,False,0) - self.fohbox.pack_start(self.fsvbox,True,False,0) - self.soframe.add(self.fohbox) - self.logobox.pack_start(self.sooframe,True,True,0) - - self.mpbox.pack_start(self.logobox,False,False,0) - - self.centerframeborder = gtk.EventBox() - self.centerframeborder.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) - self.centerframeborder.show() - self.ocenterframe = gtk.EventBox() - self.ocenterframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND)) - self.ocenterframe.set_border_width(5) - self.ocenterframe.show() - self.centerframeborder.add(self.ocenterframe) - self.centerframe = gtk.EventBox() - self.centerframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND)) - self.centerframe.set_border_width(5) - self.centerframe.show() - self.ocenterframe.add(self.centerframe) - self.hbox = gtk.HBox() - self.hbox.show() - self.mainbox.add(self.mpbox) - self.centerframe.add(self.hbox) - self.mpbox.pack_start(self.centerframeborder,True,True,0) + #self.logobox.pack_start(self.langoframe,True,True,0) + self.tvbox = gtk.VBox() @@ -1120,14 +642,10 @@ class cartoonbuilder: self.idbhbox.show() self.idbhbox.pack_start(self.imgdownbutton,True,False,0) self.tvbox.pack_start(self.idbhbox,False,False,5) - self.hbox.pack_start(self.tvbox,False,True,0) self.imgdir = self.imgdirs[self.imgdirindex] self.loadimages() - self.rightbox = gtk.VBox() - self.rightbox.show() - # ANIMATION FRAMES / FILMSTRIP self.tophbox = gtk.HBox() self.tophbox.show() @@ -1220,26 +738,11 @@ class cartoonbuilder: self.cfvbox.pack_start(self.clrframe,True,False,0) self.tophbox.pack_start(self.cfvbox,False,False,5) - pink_arrow = gtk.Image() - pink_arrow.set_from_file(os.path.join(self.iconsdir, 'pink_arrow.png')) - pink_arrow.show() - self.pahbox = gtk.HBox() - self.pahbox.show() - self.pahbox.pack_start(pink_arrow,False,False,150) - self.topvbox = gtk.VBox() - self.topvbox.show() - self.topvbox.pack_start(self.tophbox,False,False,0) - self.topvbox.pack_start(self.pahbox,False,False,0) - - self.rightbox.pack_start(self.topvbox,False,False,5) self.frame_selected = 0 self.fbstyle = self.framebuttons[0].get_style() self.framebuttons[0].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) self.framebuttons[0].modify_bg(gtk.STATE_PRELIGHT,gtk.gdk.color_parse(YELLOW)) - self.bottomhbox = gtk.HBox() - self.bottomhbox.show() - self.centervbox = gtk.VBox() self.centervbox.show() # MAIN IMAGE @@ -1254,7 +757,7 @@ class cartoonbuilder: self.mfdrawbox.show() self.mfdrawbox.add(self.mfdraw) self.mfdrawborder.add(self.mfdrawbox) - self.centervbox.pack_start(self.mfdrawborder,True,False,0) + self.centervbox.pack_end(self.mfdrawborder,True,False,0) self.bcontrolbox = gtk.HBox() self.bcontrolbox.set_border_width(5) @@ -1288,74 +791,23 @@ class cartoonbuilder: #self.sbox.pack_start(self.pslabel,True,True,0) self.bcontrolbox.pack_start(self.sbox,True,True,5) self.centervbox.pack_start(self.bcontrolbox,False,False,0) - self.bottomhbox.pack_start(self.centervbox,True,False,0) self.controlbox = gtk.VBox() self.controlbox.show() + # CHARACTER CONTROLS - self.ccbox = gtk.VBox() - self.ccbox.show() - self.cchbox = gtk.HBox() - self.cchbox.show() - self.cclbutton = gtk.Button() - self.cclbutton.connect('clicked',self.lastcharacter,None) - self.cclbutton.show() - ccla = gtk.Image() - ccla.set_from_file(os.path.join(self.iconsdir,'big_left_arrow.png')) - ccla.show() - prepare_btn(self.cclbutton) - self.cclbutton.add(ccla) - self.cclbvbox = gtk.VBox() - self.cclbvbox.show() - self.cclbvbox.pack_start(self.cclbutton,True,False,0) - self.cchbox.pack_start(self.cclbvbox,True,True,5) - self.ccibutton = gtk.Button() - self.ccibutton.show() - self.ccismall = gtk.Image() - self.ccismall.show() - self.cciebox = gtk.EventBox() - self.cciebox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BLACK)) - self.cciebox.show() - self.cciebox.add(self.ccismall) - self.ccibvbox = gtk.VBox() - self.ccibvbox.show() - self.ccibvbox.pack_start(self.cciebox,True,False,0) - self.cchbox.pack_start(self.ccibvbox,False,False,0) - self.ccrbutton = gtk.Button() - self.ccrbutton.connect('clicked',self.nextcharacter,None) - self.ccrbutton.show() - ccra = gtk.Image() - ccra.set_from_file(os.path.join(self.iconsdir,'big_right_arrow.png')) - ccra.show() - self.ccrbutton.add(ccra) - prepare_btn(self.ccrbutton) - self.ccrbvbox = gtk.VBox() - self.ccrbvbox.show() - self.ccrbvbox.pack_start(self.ccrbutton,True,False,0) - self.cchbox.pack_start(self.ccrbvbox,True,True,5) - self.ccbox.pack_start(self.cchbox,True,True,0) - self.charlabel = gtk.Label('') - self.charlabel.show() - self.charlabelhbox = gtk.HBox() - self.charlabelhbox.show() - self.charlabelhbox.pack_start(self.charlabel,True,False,0) - self.ccbox.pack_start(self.charlabelhbox,False,False,0) - if not self.insugar: - self.character = gtk.Button('My Character') - self.character.connect('clicked',self.getimgdir,None) - prepare_btn(self.character) - self.character.show() - self.characterhbox = gtk.HBox() - self.characterhbox.show() - self.characterhbox.pack_start(self.character,True,False,0) - self.ccbox.pack_start(self.characterhbox,False,False,5) - self.setcharacter() - - - self.controlbox.pack_start(self.ccbox,False,False,5) + char_box = BigComboBox() + char_box.show() + for i in Char.list(): + char_box.append_item(i.id, size = Char.Size, + pixbuf = i.pixbuf) + char_box.connect('changed', self._char_cb) + self.controlbox.pack_start(char_box, False, False, 5) # BACKGROUND CONTROLS + + self.bgbox = gtk.VBox() self.bgbox.show() self.bghbox = gtk.HBox() @@ -1390,15 +842,6 @@ class cartoonbuilder: self.brbvbox.pack_start(self.brbutton,True,False,0) self.bghbox.pack_start(self.brbvbox,True,True,5) self.bgbox.pack_start(self.bghbox,True,True,0) - if not self.insugar: - self.bgbutton = gtk.Button('My Background') - self.bgbutton.connect('clicked',self.getbackgroundfile,None) - prepare_btn(self.bgbutton) - self.bgbutton.show() - self.bgbuttonhbox = gtk.HBox() - self.bgbuttonhbox.show() - self.bgbuttonhbox.pack_start(self.bgbutton,True,False,0) - self.bgbox.pack_start(self.bgbuttonhbox,False,False,5) self.controlbox.pack_start(self.bgbox,False,False,5) # SOUND CONTROLS @@ -1445,36 +888,91 @@ class cartoonbuilder: self.soundlabelhbox.show() self.soundlabelhbox.pack_start(self.soundlabel,True,False,0) self.soundbox.pack_start(self.soundlabelhbox,False,False,0) - if not self.insugar: - self.soundbutton = gtk.Button('My Sound') - self.soundbutton.connect('clicked',self.getsoundfile,None) - prepare_btn(self.soundbutton) - self.soundbutton.show() - self.soundbuttonhbox = gtk.HBox() - self.soundbuttonhbox.show() - self.soundbuttonhbox.pack_start(self.soundbutton,True,False,0) - self.soundbox.pack_start(self.soundbuttonhbox,False,False,5) self.controlbox.pack_start(self.soundbox,False,False,5) - # FINISHING DETAILS + + + + + + self.centerframe = gtk.EventBox() + self.centerframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND)) + self.centerframe.set_border_width(5) + self.centerframe.show() + #self.ocenterframe.add(self.centerframe) + + + + + + + leftbox = gtk.VBox() + leftbox.show() + + self.logo = gtk.Image() + self.logo.show() + self.logo.set_from_file(os.path.join(self.iconsdir,'logo.png')) + leftbox.pack_start(self.logo,False,False,0) + + self.bottomhbox = gtk.HBox() + self.bottomhbox.show() + leftbox.pack_start(self.bottomhbox,True,True,10) self.bottomhbox.pack_start(self.controlbox,False,False,10) - self.rightbox.pack_start(self.bottomhbox,True,True,10) - self.hbox.pack_start(self.rightbox,True,True,0) + + + + + cetralbox = gtk.HBox() + cetralbox.show() + cetralbox.pack_start(self.centervbox,True,False,0) + cetralbox.pack_start(self.tvbox,False,True,0) + + + + + hdesktop = gtk.HBox() + hdesktop.show() + hdesktop.pack_start(leftbox,False,True,0) + hdesktop.pack_start(cetralbox,True,True,0) + + pink_arrow = gtk.Image() + pink_arrow.set_from_file(os.path.join(self.iconsdir, 'pink_arrow.png')) + pink_arrow.show() + self.pahbox = gtk.HBox() + self.pahbox.show() + self.pahbox.pack_start(pink_arrow,False,False,150) + + self.topvbox = gtk.VBox() + self.topvbox.show() + self.topvbox.pack_start(self.tophbox,False,False,0) + self.topvbox.pack_start(self.pahbox,False,False,0) + + desktop = gtk.VBox() + desktop.show() + #desktop.pack_start(self.logobox,False,False,0) + desktop.pack_start(hdesktop,True,True,0) + desktop.pack_end(self.topvbox, False, False, 0) + + greenbox = gtk.EventBox() + greenbox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND)) + greenbox.set_border_width(5) + greenbox.show() + greenbox.add(desktop) + + yellowbox = gtk.EventBox() + yellowbox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) + yellowbox.show() + yellowbox.add(greenbox) + + self.main = yellowbox + self.main.show_all() def main(self): gtk.main() try: - from sugar.activity import activity from sugar.graphics.toolbutton import ToolButton from sugar.graphics.objectchooser import ObjectChooser - from sugar.presence import presenceservice - from sugar.presence.tubeconn import TubeConnection - import telepathy - import telepathy.client - from dbus import Interface - from dbus.service import method, signal - from dbus.gobject_service import ExportedGObject class BGToolbar(gtk.Toolbar): def __init__(self,sactivity,app): @@ -1500,9 +998,9 @@ try: chooser.destroy() del chooser - class cartoonbuilderActivity(activity.Activity): + class cartoonbuilderActivity(Shared): def __init__(self, handle): - activity.Activity.__init__(self,handle) + Shared.__init__(self,handle) self.connect("destroy",self.destroy_cb) #app = cartoonbuilder(self,'/home/olpc/Activities/CartoonBuilder.activity') bundle_path = activity.get_bundle_path() @@ -1519,189 +1017,17 @@ try: self._jobject.metadata['title'] = 'CartoonBuilder' title_widget = toolbox._activity_toolbar.title title_widget.set_size_request(title_widget.get_layout().get_pixel_size()[0] + 20, -1) - outerframe = gtk.EventBox() - outerframe.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BUTTON_BACKGROUND)) - outerframe.show() - innerframe = gtk.EventBox() - innerframe.show() - ifalign = gtk.Alignment(1.0,1.0,1.0,1.0) - ifalign.add(innerframe) - ifalign.set_padding(10,10,30,30) # top,bottom,left,right - ifalign.show() - #innerframe.set_border_width(150) - outerframe.add(ifalign) - innerframe.add(self.app.main) - self.set_canvas(outerframe) - - # mesh stuff - self.pservice = presenceservice.get_instance() - owner = self.pservice.get_owner() - self.owner = owner - try: - name, path = self.pservice.get_preferred_connection() - self.tp_conn_name = name - self.tp_conn_path = path - self.conn = telepathy.client.Connection(name, path) - except TypeError: - pass - self.initiating = None - - #sharing stuff - self.game = None - self.connect('shared', self._shared_cb) - if self._shared_activity: - # we are joining the activity - self.connect('joined', self._joined_cb) - if self.get_shared(): - # oh, OK, we've already joined - self._joined_cb() - else: - # we are creating the activity - pass - + self.set_canvas(self.app.main) def destroy_cb(self, data=None): return True def read_file(self, filepath): - zf = file(filepath,'r') - self.app.loadfromzip(zf) + Bundle.load(filepath) def write_file(self, filepath): - zf = file(filepath,'w') - self.app.savetozip(zf) - - def _shared_cb(self,activity): - self.initiating = True - self._setup() - id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube( - SERVICE, {}) - #self.app.export.set_label('Shared Me') - - def _joined_cb(self,activity): - if self.game is not None: - return - - if not self._shared_activity: - return - - #for buddy in self._shared_activity.get_joined_buddies(): - # self.buddies_panel.add_watcher(buddy) - - #logger.debug('Joined an existing Connect game') - #self.app.export.set_label('Joined You') - self.initiating = False - self._setup() - - #logger.debug('This is not my activity: waiting for a tube...') - self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].ListTubes( - reply_handler=self._list_tubes_reply_cb, - error_handler=self._list_tubes_error_cb) - - def _setup(self): - if self._shared_activity is None: - return - - bus_name, conn_path, channel_paths = self._shared_activity.get_channels() - - # Work out what our room is called and whether we have Tubes already - room = None - tubes_chan = None - text_chan = None - for channel_path in channel_paths: - channel = telepathy.client.Channel(bus_name, channel_path) - htype, handle = channel.GetHandle() - if htype == telepathy.HANDLE_TYPE_ROOM: - #logger.debug('Found our room: it has handle#%d "%s"', - # handle, self.conn.InspectHandles(htype, [handle])[0]) - room = handle - ctype = channel.GetChannelType() - if ctype == telepathy.CHANNEL_TYPE_TUBES: - #logger.debug('Found our Tubes channel at %s', channel_path) - tubes_chan = channel - elif ctype == telepathy.CHANNEL_TYPE_TEXT: - #logger.debug('Found our Text channel at %s', channel_path) - text_chan = channel - - if room is None: - #logger.error("Presence service didn't create a room") - return - if text_chan is None: - #logger.error("Presence service didn't create a text channel") - return - - # Make sure we have a Tubes channel - PS doesn't yet provide one - if tubes_chan is None: - #logger.debug("Didn't find our Tubes channel, requesting one...") - tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES, - telepathy.HANDLE_TYPE_ROOM, room, True) - - self.tubes_chan = tubes_chan - self.text_chan = text_chan - - tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube', - self._new_tube_cb) - - def _list_tubes_reply_cb(self, tubes): - for tube_info in tubes: - self._new_tube_cb(*tube_info) - - def _list_tubes_error_cb(self, e): - #logger.error('ListTubes() failed: %s', e) - pass - - def _new_tube_cb(self, id, initiator, type, service, params, state): - #logger.debug('New tube: ID=%d initator=%d type=%d service=%s ' - # 'params=%r state=%d', id, initiator, type, service, - # params, state) - - if (self.game is None and type == telepathy.TUBE_TYPE_DBUS and - service == SERVICE): - if state == telepathy.TUBE_STATE_LOCAL_PENDING: - self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id) - - tube_conn = TubeConnection(self.conn, - self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES], - id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]) - self.game = ConnectGame(tube_conn, self.initiating, self) - - class ConnectGame(ExportedGObject): - def __init__(self,tube, is_initiator, activity): - super(ConnectGame,self).__init__(tube,PATH) - self.tube = tube - self.is_initiator = is_initiator - self.entered = False - self.activity = activity - - self.ordered_bus_names=[] - self.tube.watch_participants(self.participant_change_cb) - - def participant_change_cb(self, added, removed): - if not self.entered: - if self.is_initiator: - self.add_hello_handler() - else: - self.Hello() - self.entered = True - - @signal(dbus_interface=IFACE,signature='') - def Hello(self): - """Request that this player's Welcome method is called to bring it - up to date with the game state. - """ - - @method(dbus_interface=IFACE, in_signature='s', out_signature='') - def Welcome(self, sdata): - #sdata is the zip file contents - #self.activity.app.lessonplans.set_label('got data to restore') - self.activity.app.restore(str(sdata)) - - def add_hello_handler(self): - self.tube.add_signal_receiver(self.hello_cb, 'Hello', IFACE, - path=PATH, sender_keyword='sender') - - def hello_cb(self, sender=None): - self.tube.get_object(sender, PATH).Welcome(self.activity.app.getsdata(),dbus_interface=IFACE) + Bundle.save(filepath) + except ImportError: pass -- cgit v0.9.1