def _load_game(self, button): chooser = ObjectChooser(_('Choose memorize game'), parent=self.activity, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) jobject = '' try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug('ObjectChooser: %r', chooser.get_selected_object()) jobject = chooser.get_selected_object() if not jobject or not jobject.file_path: return finally: chooser.destroy() del chooser if jobject and jobject.file_path: title = jobject.metadata['title'] if jobject.metadata.has_key('icon-color'): color = jobject.metadata['icon-color'] else: color = profile.get_color().to_string() self.emit('game_changed', jobject.file_path, 4, 'file', title, color) if self.jobject != None: self.jobject.destroy() self.jobject = jobject
def __do_clicked_image(self, control, event, obj, property): if hasattr(mime, 'GENERIC_TYPE_IMAGE'): filter = {'what_filter': mime.GENERIC_TYPE_IMAGE} else: filter = {} # Courtesy of Write.activity - toolbar.py chooser = ObjectChooser( title=_('Choose image'), parent=Globals.JokeMachineActivity, #._parent, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, **filter) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug('ObjectChooser: %r' % chooser.get_selected_object()) journal_object = chooser.get_selected_object() if hasattr(obj, 'image_blob' ) and journal_object and journal_object.file_path: logging.debug('Getting journal object: %r, %s', journal_object, journal_object.file_path) # Set the image now raw = _load_image(journal_object.file_path) obj.image = str(journal_object.metadata['title']) obj.image_blob = raw # refresh the image image_file = StringIO.StringIO(obj.image_blob) surface = cairo.ImageSurface.create_from_png(image_file) control.props.image = surface finally: #chooser.hide() chooser.destroy() del chooser
def add_image (self, *args):#widget=None, response=None, *args): """ Use to trigger and process the My Own Image selector. """ if hasattr(mime, 'GENERIC_TYPE_IMAGE'): chooser = ObjectChooser(_('Choose image'), self._parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, what_filter=mime.GENERIC_TYPE_IMAGE) else: chooser = ObjectChooser(_('Choose image'), self._parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: if self.load_image(str(jobject.file_path), True): pass else: err = gtk.MessageDialog(self._parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Not a valid image file")) err.run() err.destroy() return finally: chooser.destroy() del chooser
def _set_img(self, widget, win): win.destroy() chooser = ObjectChooser() res = chooser.run() if res == gtk.RESPONSE_CANCEL: chooser.destroy() else: chooser.destroy() image = gtk.Image() ch = chooser.get_selected_object() self.user.disconnect(self.conectado) path = ch.file_path self.conectado = self.user.connect('clicked', self.open, path) pix = gtk.gdk.pixbuf_new_from_file_at_size(path, 200, 200) image.set_from_pixbuf(pix) for x in list(self.user): self.user.remove(x) self.user.add(image) ### d = utils.model.get_value(utils.iter_sel, 0) echo = False a = 0 while not echo: if d == NAMES[a]: utils.current = a echo = True a += 1 AVATARS.__setitem__(utils.current, path) ## self.show_all()
def __do_clicked_image(self, control, event, obj, property): if hasattr(mime, "GENERIC_TYPE_IMAGE"): filter = {"what_filter": mime.GENERIC_TYPE_IMAGE} else: filter = {} # Courtesy of Write.activity - toolbar.py chooser = ObjectChooser( title=_("Choose image"), parent=Globals.JokeMachineActivity, # ._parent, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, **filter ) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug("ObjectChooser: %r" % chooser.get_selected_object()) journal_object = chooser.get_selected_object() if hasattr(obj, "image_blob") and journal_object and journal_object.file_path: logging.debug("Getting journal object: %r, %s", journal_object, journal_object.file_path) # Set the image now raw = _load_image(journal_object.file_path) obj.image = str(journal_object.metadata["title"]) obj.image_blob = raw # refresh the image image_file = StringIO.StringIO(obj.image_blob) surface = cairo.ImageSurface.create_from_png(image_file) control.props.image = surface finally: # chooser.hide() chooser.destroy() del chooser
def add_image(self, *args): #widget=None, response=None, *args): """ Use to trigger and process the My Own Image selector. """ if hasattr(mime, 'GENERIC_TYPE_IMAGE'): filter = {'what_filter': mime.GENERIC_TYPE_IMAGE} else: filter = {} chooser = ObjectChooser( _('Choose image'), self.parentp, #self._parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, **filter) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: if self.load_image(str(jobject.file_path), True): pass else: err = gtk.MessageDialog(self._parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Not a valid image file")) err.run() err.destroy() return finally: chooser.destroy() del chooser
def __do_clicked_choose_sound(self, control, event, obj, property): if hasattr(mime, 'GENERIC_TYPE_AUDIO'): filter = {'what_filter': mime.GENERIC_TYPE_AUDIO} else: filter = {} logging.debug('choosing sound file') chooser = ObjectChooser( title=_('Choose Sound'), parent=Globals.JokeMachineActivity, #._parent, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, **filter) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug('ObjectChooser: %r' % chooser.get_selected_object()) journal_object = chooser.get_selected_object() if hasattr(obj, 'sound_blob' ) and journal_object and journal_object.file_path: logging.debug('Getting journal object: %r, %s, %s', journal_object, journal_object.file_path, journal_object.metadata['title']) # Set the sound now f = open(journal_object.file_path, 'r') raw = f.read() f.close() obj.sound = str(journal_object.metadata['title']) obj.sound_blob = raw control.props.text = obj.sound finally: #chooser.hide() chooser.destroy() del chooser
def show(self): chooser = ObjectChooser(parent=self._parent) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug('FilePicker.show: %r' % chooser.get_selected_object()) jobject = chooser.get_selected_object() if jobject and jobject.file_path: ext = os.path.splitext(jobject.file_path)[1] f, new_temp = tempfile.mkstemp(ext) del f global _temp_files_to_clean _temp_files_to_clean.append(new_temp) shutil.copy(jobject.file_path, new_temp) self._file = new_temp finally: chooser.destroy() del chooser if self._file: return interfaces.nsIFilePicker.returnOK else: return interfaces.nsIFilePicker.returnCancel
def __send_cb(self, button): chooser = ObjectChooser() try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: logging.debug('##### %s' % jobject.file_path) finally: chooser.destroy() del chooser
def insertImage(self, widget, activity): self._activity = activity chooser = ObjectChooser('Choose image', self._activity, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: self._activity.toUploadChosen(jobject.file_path) finally: chooser.destroy() del chooser
def _image_cb(self, button): chooser = ObjectChooser( _('Choose image'), self._parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug('ObjectChooser: %r' % chooser.get_selected_object()) jobject = chooser.get_selected_object() if jobject and jobject.file_path: self._abiword_canvas.insert_image(jobject.file_path, True) finally: chooser.destroy() del chooser
def _show_picker_cb(self, duumy1): chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: #print jobject.file_path self.obj = jobject.file_path subprocess.call(['/usr/bin/killall', 'mpg123']) self.read_file(str(jobject.file_path)) finally: chooser.destroy() del chooser
def chooser(parent_window, filter, action): """ Choose an object from the datastore and take some action """ chooser = None try: chooser = ObjectChooser(parent=parent_window, what_filter=filter) except TypeError: chooser = ObjectChooser(None, parent_window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) if chooser is not None: try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: dsobject = chooser.get_selected_object() action(dsobject) dsobject.destroy() finally: chooser.destroy() del chooser
def open_from_journal(button, filechooser, activity=None): if filechooser: chooser = ObjectChooser(parent=filechooser, what_filter=mime.GENERIC_TYPE_TEXT) else: chooser = ObjectChooser(parent=activity, what_filter=mime.GENERIC_TYPE_TEXT) result = chooser.run() chooser.destroy() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() path = str(jobject.get_file_path()) else: path = None if filechooser: filechooser.path = path filechooser.response(OPEN_FROM_JOURNAL) else: activity.open_file(None, from_journal=path)
def requestAddFile(self, widget, data=None): _logger.info('Requesting to add file') chooser = ObjectChooser() if chooser.run() == gtk.RESPONSE_ACCEPT: # get object and build file jobject = chooser.get_selected_object() self.show_throbber(True, _("Packaging Object")) try: file_obj = self.activity.build_file(jobject) except InShareException: self._alert(_("Object Not Added"), _("Object already shared")) self.show_throbber(False) return # No problems continue self.show_throbber(False) # Add To UI self._addFileToUIList(file_obj.id, file_obj) # Register File with activity share list self.activity._registerShareFile(file_obj.id, file_obj) # Upload to server? if data and data.has_key('upload'): self.show_throbber(True, _("Uploading Object to server")) def send(): try: self.activity.send_file_to_server( file_obj.id, file_obj) except FileUploadFailure: self._alert(_("Failed to upload object")) self._remFileFromUIList(file_obj.id) self.activity.delete_file(file_obj.id) self.show_throbber(False) threading.Thread(target=send).start() chooser.destroy() del chooser
def chooser(parent_window, filter, action): """ Choose an object from the datastore and take some action """ from sugar.graphics.objectchooser import ObjectChooser _chooser = None try: _chooser = ObjectChooser(parent=parent_window, what_filter=filter) except TypeError: _chooser = ObjectChooser(None, parent_window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) if _chooser is not None: try: result = _chooser.run() if result == gtk.RESPONSE_ACCEPT: dsobject = _chooser.get_selected_object() action(dsobject) dsobject.destroy() finally: _chooser.destroy() del _chooser
def _load_game(self, button): chooser = ObjectChooser(_('Choose memorize game'), parent=self.activity, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) jobject = '' try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug('ObjectChooser: %r' % chooser.get_selected_object()) jobject = chooser.get_selected_object() if not jobject or not jobject.file_path: return finally: chooser.destroy() del chooser if jobject and jobject.file_path: self.emit('create_load_game', jobject.file_path) self._save_button.set_sensitive(False)
def loadButtonClicked(self, button): chooser = ObjectChooser( 'Pick a level', self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: event = olpcgames.eventwrap.Event( type=pygame.USEREVENT, code=olpcgames.FILE_READ_REQUEST, filename=jobject.file_path, metadata=jobject.metadata, ) olpcgames.eventwrap.post(event) event.block() finally: chooser.destroy() del chooser
def pick(cb=None, default=None, parent=None, what=None): """ Opens object chooser. Method returns: * cb(jobject), if object was choosen and cb is not None * jobject, if object was choosen and cb is None * default, otherwise NOTE: 'what' makes sense only for sugar >= 0.84 """ what = what and {'what_filter': what} or {} chooser = ObjectChooser(parent=parent, **what) logging.error(chooser) jobject = None out = None try: if chooser.run() == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() logging.debug('ObjectChooser: %r' % jobject) if jobject and jobject.file_path: if cb: out = cb(jobject) else: out = jobject finally: if jobject and id(jobject) != id(out): jobject.destroy() chooser.destroy() del chooser if out: return out else: return default
def requestAddFile(self, widget, data=None): _logger.info('Requesting to add file') chooser = ObjectChooser(parent=self.activity) if chooser.run() == gtk.RESPONSE_ACCEPT: # get object and build file jobject = chooser.get_selected_object() self.show_throbber(True, _("Packaging Object") ) try: file_obj = self.activity.build_file( jobject ) except InShareException: self._alert(_("Object Not Added"), _("Object already shared")) self.show_throbber( False ) return # No problems continue self.show_throbber( False ) # Add To UI self._addFileToUIList( file_obj.id, file_obj ) # Register File with activity share list self.activity._registerShareFile( file_obj.id, file_obj ) # Upload to server? if data and data.has_key('upload'): self.show_throbber(True, _("Uploading Object to server")) def send(): try: self.activity.send_file_to_server( file_obj.id, file_obj ) except FileUploadFailure: self._alert( _("Failed to upload object") ) self._remFileFromUIList( file_obj.id ) self.activity.delete_file( file_obj.id ) self.show_throbber( False ) threading.Thread(target=send).start() chooser.destroy() del chooser
def pick(cb=None, default=None, parent=None, what=None): """ Opens object chooser. Method returns: * cb(jobject), if object was choosen and cb is not None * jobject, if object was choosen and cb is None * default, otherwise NOTE: 'what' makes sense only for sugar >= 0.84 """ what = what and {'what_filter': what} or {} chooser = ObjectChooser(parent=parent, **what) jobject = None out = None try: if chooser.run() == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() logging.debug('ObjectChooser: %r' % jobject) if jobject and jobject.file_path: if cb: out = cb(jobject) else: out = jobject finally: if jobject and id(jobject) != id(out): jobject.destroy() chooser.destroy() del chooser if out: return out else: return default
def load_image_from_journal(self): chooser = None name = None jobject = None try: chooser = ObjectChooser(parent=self, what_filter=None) except TypeError: chooser = ObjectChooser( None, self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) if chooser is not None: try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: name = jobject.metadata['title'] #mime_type = jobject.metadata['mime_type'] #_logger.debug('result of choose: %s (%s)' % \(name, str(mime_type))) finally: chooser.destroy() del chooser return jobject
def chooser_dialog(parent_window, filter, action): ''' Choose an object from the datastore and take some action ''' from sugar.graphics.objectchooser import ObjectChooser chooser = None dsobject = None cleanup_needed = False try: chooser = ObjectChooser(parent=parent_window, what_filter=filter) except TypeError: # Old-syle Sugar chooser chooser = ObjectChooser( None, parent_window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) cleanup_needed = True if chooser is not None: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: dsobject = chooser.get_selected_object() if cleanup_needed: chooser.destroy() del chooser gobject.idle_add(action, dsobject)
def __do_clicked_choose_sound(self, control, event, obj, property): if hasattr(mime, "GENERIC_TYPE_AUDIO"): filter = {"what_filter": mime.GENERIC_TYPE_AUDIO} else: filter = {} logging.debug("choosing sound file") chooser = ObjectChooser( title=_("Choose Sound"), parent=Globals.JokeMachineActivity, # ._parent, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, **filter ) try: result = chooser.run() if result == gtk.RESPONSE_ACCEPT: logging.debug("ObjectChooser: %r" % chooser.get_selected_object()) journal_object = chooser.get_selected_object() if hasattr(obj, "sound_blob") and journal_object and journal_object.file_path: logging.debug( "Getting journal object: %r, %s, %s", journal_object, journal_object.file_path, journal_object.metadata["title"], ) # Set the sound now f = open(journal_object.file_path, "r") raw = f.read() f.close() obj.sound = str(journal_object.metadata["title"]) obj.sound_blob = raw control.props.text = obj.sound finally: # chooser.hide() chooser.destroy() del chooser