當前位置: 首頁>>代碼示例>>Python>>正文


Python ObjectChooser.destroy方法代碼示例

本文整理匯總了Python中sugar3.graphics.objectchooser.ObjectChooser.destroy方法的典型用法代碼示例。如果您正苦於以下問題:Python ObjectChooser.destroy方法的具體用法?Python ObjectChooser.destroy怎麽用?Python ObjectChooser.destroy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sugar3.graphics.objectchooser.ObjectChooser的用法示例。


在下文中一共展示了ObjectChooser.destroy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _load_image_cb

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
 def _load_image_cb(self, button):
     chooser = None
     name = None
     self._custom_food_jobject = None
     if hasattr(mime, 'GENERIC_TYPE_IMAGE'):
         # See SL bug #2398
         if 'image/svg+xml' not in \
                 mime.get_generic_type(mime.GENERIC_TYPE_IMAGE).mime_types:
             mime.get_generic_type(
                 mime.GENERIC_TYPE_IMAGE).mime_types.append('image/svg+xml')
         chooser = ObjectChooser(parent=self,
                                 what_filter=mime.GENERIC_TYPE_IMAGE)
     else:
         try:
             chooser = ObjectChooser(parent=self, what_filter=None)
         except TypeError:
             chooser = ObjectChooser(
                 None, self,
                 Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
     if chooser is not None:
         try:
             result = chooser.run()
             if result == Gtk.ResponseType.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
         if name is not None:
             self._custom_food_jobject = jobject
     return
開發者ID:leonardcj,項目名稱:nutrition,代碼行數:37,代碼來源:NutritionActivity.py

示例2: _load_project

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def _load_project(self, button):
        chooser = ObjectChooser(parent=self)
        result = chooser.run()
        if result == Gtk.ResponseType.ACCEPT:
            dsobject = chooser.get_selected_object()
            file_path = dsobject.get_file_path()
            try:
                f = open(file_path, 'r')
                # Test if the file is valid project.
                json.loads(f.read())
                f.close()

                self.read_file(file_path)
                self.game.run(True)
            except:
                title = _('Load project from journal')
                msg = _(
                    'Error: Cannot open Physics project from this file.')
                alert = NotifyAlert(5)
                alert.props.title = title
                alert.props.msg = msg
                alert.connect(
                    'response',
                    lambda alert,
                    response: self.remove_alert(alert))
                self.add_alert(alert)

            chooser.destroy()
開發者ID:i5o,項目名稱:physics,代碼行數:30,代碼來源:activity.py

示例3: __add_cover_response_cb

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def __add_cover_response_cb(self, alert, response_id, operation_function):
        if response_id == Gtk.ResponseType.YES:
            try:
                chooser = ObjectChooser(self, what_filter='Image',
                                        filter_type=FILTER_TYPE_GENERIC_MIME,
                                        show_preview=True)
            except:
                # for compatibility with older versions
                chooser = ObjectChooser(self, what_filter='Image')

            try:
                result = chooser.run()
                if result == Gtk.ResponseType.ACCEPT:
                    logging.error('ObjectChooser: %r' %
                                  chooser.get_selected_object())
                    jobject = chooser.get_selected_object()
                    if jobject and jobject.file_path:
                        logging.error("imagen seleccionada: %s",
                                      jobject.file_path)
                        mime_type = mime.get_for_file(jobject.file_path)
                        extension = mime.get_primary_extension(mime_type)
                        tempfile_name = \
                            os.path.join(
                                self.get_activity_root(), 'instance',
                                'tmp%i.%s' % (time.time(), extension))
                        os.link(jobject.file_path, tempfile_name)
                        operation_function(tempfile_name)
            finally:
                chooser.destroy()
                del chooser

        elif response_id == Gtk.ResponseType.NO:
            self._save_epub()
        self.remove_alert(alert)
開發者ID:leonardcj,項目名稱:write-books-activity,代碼行數:36,代碼來源:activity.py

示例4: add_image

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def add_image(self):
        try:
            chooser = ObjectChooser(self._activity, what_filter='Image',
                                    filter_type=FILTER_TYPE_GENERIC_MIME,
                                    show_preview=True)
        except:
            # for compatibility with older versions
            chooser = ObjectChooser(self._activity, what_filter='Image')

        try:
            result = chooser.run()
            if result == Gtk.ResponseType.ACCEPT:
                logging.error('ObjectChooser: %r' %
                              chooser.get_selected_object())
                jobject = chooser.get_selected_object()
                if jobject and jobject.file_path:
                    logging.error("imagen seleccionada: %s",
                                  jobject.file_path)
                    tempfile_name = \
                        os.path.join(self._activity.get_activity_root(),
                                     'instance', 'tmp%i' % time.time())
                    os.link(jobject.file_path, tempfile_name)
                    logging.error("tempfile_name: %s", tempfile_name)
                    self._page.add_box_from_journal_image(tempfile_name)
        finally:
            chooser.destroy()
            del chooser
開發者ID:godiard,項目名稱:fototoon-activity,代碼行數:29,代碼來源:toolbar.py

示例5: _show_picker_cb

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def _show_picker_cb(self, button):
        if not self._want_document:
            return

        try:
            chooser = ObjectChooser(self, what_filter='Image',
                                    filter_type=FILTER_TYPE_GENERIC_MIME,
                                    show_preview=True)
        except:
            # for compatibility with older versions
            chooser = ObjectChooser(self._activity, what_filter='Image')

        try:
            result = chooser.run()
            if result == Gtk.ResponseType.ACCEPT:
                jobject = chooser.get_selected_object()
                if jobject and jobject.file_path:
                    self._object_id = jobject.object_id
                    self.read_file(jobject.file_path)
                    self.set_canvas(self.scrolled_window)
                    self.scrolled_window.show()
        finally:
            self.get_current_image_index()
            self.make_button_sensitive()
            chooser.destroy()
            del chooser
開發者ID:leonardcj,項目名稱:imageviewer-activity,代碼行數:28,代碼來源:ImageViewerActivity.py

示例6: _choose_image

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def _choose_image(self):
        from sugar3.graphics.objectchooser import ObjectChooser
        try:
            from sugar3.graphics.objectchooser import FILTER_TYPE_GENERIC_MIME
        except:
            FILTER_TYPE_GENERIC_MIME = 'generic_mime'
        from sugar3 import mime

        chooser = None
        name = None

        if hasattr(mime, 'GENERIC_TYPE_IMAGE'):
            # See #2398
            if 'image/svg+xml' not in \
                    mime.get_generic_type(mime.GENERIC_TYPE_IMAGE).mime_types:
                mime.get_generic_type(
                    mime.GENERIC_TYPE_IMAGE).mime_types.append('image/svg+xml')
            try:
                chooser = ObjectChooser(parent=self._reflection.activity,
                                        what_filter=mime.GENERIC_TYPE_IMAGE,
                                        filter_type=FILTER_TYPE_GENERIC_MIME,
                                        show_preview=True)
            except:
                chooser = ObjectChooser(parent=self._reflection.activity,
                                        what_filter=mime.GENERIC_TYPE_IMAGE)
        else:
            try:
                chooser = ObjectChooser(parent=self, what_filter=None)
            except TypeError:
                chooser = ObjectChooser(
                    None, self._reflection.activity,
                    Gtk.DialogFlags.MODAL |
                    Gtk.DialogFlags.DESTROY_WITH_PARENT)

        if chooser is not None:
            try:
                result = chooser.run()
                if result == Gtk.ResponseType.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

            if name is not None:
                pixbuf = self.add_new_picture(jobject.file_path)
                self._reflection.set_modification_time()
                if self._reflection.activity.sharing and pixbuf is not None:
                    self._reflection.activity.send_event(PICTURE_CMD,
                        {"basename": os.path.basename(jobject.file_path),
                         "data": utils.pixbuf_to_base64(pixbuf)})
                    self._reflection.activity.send_event(IMAGE_REFLECTION_CMD,
                        {"obj_id": self._reflection.data["obj_id"],
                         "basename": os.path.basename(jobject.file_path)})

        self._reflection.activity.reset_cursor()
開發者ID:AbrahmAB,項目名稱:reflect,代碼行數:62,代碼來源:reflectwindow.py

示例7: add_image

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    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(self.parentp, **filter)
        try:
            result = chooser.run()
            if result == Gtk.ResponseType.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.DialogFlags.MODAL, Gtk.MESSAGE_ERROR, Gtk.BUTTONS_OK,
                                                _("Not a valid image file"))
                        err.run()
                        err.destroy()
                        return
        finally:
            chooser.destroy()
            del chooser
開發者ID:zeecoder606,項目名稱:Gtk3slider,代碼行數:27,代碼來源:image_category.py

示例8: _load_project

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
 def _load_project(self, button):
     chooser = ObjectChooser(parent=self)
     result = chooser.run()
     if result == Gtk.ResponseType.ACCEPT:
         dsobject = chooser.get_selected_object()
         file_path = dsobject.get_file_path()
         self.__load_game(file_path, True)
         chooser.destroy()
開發者ID:godiard,項目名稱:physics,代碼行數:10,代碼來源:activity.py

示例9: load

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def load(self, file_path=None):
        """
        If the filePath is None this function opens the Object Chooser Dialog
        for choosing a .zip type file
        If the file contains a *.ufo folder than that
        UFO Font file will be loaded using defcon
        and the current page will be set to Font Summary Page
        if the filepath is specified than the ufo from that filepath is opened
        """
        if file_path is None:

            # FIXME: Add compatibility for earlier versions # noqa
            try:
                chooser = ObjectChooser(
                    parent=self,
                    what_filter=self.get_bundle_id(),
                    filter_type=FILTER_TYPE_MIME_BY_ACTIVITY)
            except:
                self._show_alert("Error",
                                 "This feature is not Implemented")
                logging.error("This feature is not Implemented")
                return
            try:
                result = chooser.run()
                if result == Gtk.ResponseType.ACCEPT:
                    jobject = chooser.get_selected_object()

                    if jobject and jobject.file_path:

                        # Now we know the file exists
                        # Check if the file is of the valid format

                        if not self._load_from_file(jobject.file_path):
                            self._show_alert("Error",
                                             "Invalid File type chosen")
                            logging.error("File type is invalid")
                            return
                        else:
                            self.set_page("SUMMARY")
            finally:
                chooser.destroy()
                del chooser

        else:
            if not self._load_from_file(file_path):
                self._show_alert("Error",
                                 "Invalid File type chosen")
                logging.error("File type is invalid")
                return
            else:
                self.set_page("SUMMARY")

        # print success message
        self._show_alert("Success",
                         "Imported Font: " + str(globals.FONT.info.familyName))
開發者ID:sugarlabs,項目名稱:edit-fonts-activity,代碼行數:57,代碼來源:EditFonts.py

示例10: import_font

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def import_font(self, file_path=None):
        """Import the font from a .otf or .ttf file."""
        if file_path is None:

            # FIXME: Add compatibility for earlier versions
            # FIXME: Fix the filter type to include either
            # all the objects or only the .otf and .ttf font files
            try:
                chooser = ObjectChooser(
                    parent=self,
                    what_filter=self.get_bundle_id(),
                    filter_type=None)
            except:
                self._show_alert("Error",
                                 "This feature is not Implemented")
                logging.error("This feature is not Implemented")
                return
            else:
                try:
                    result = chooser.run()
                    if result == Gtk.ResponseType.ACCEPT:
                        jobject = chooser.get_selected_object()

                        if jobject and jobject.file_path:
                            file_path = jobject.file_path
                finally:
                    chooser.destroy()
                    del chooser

        font = BaseFont.import_from_binary(file_path)
        if font is None:
            self._show_alert("Error",
                             "Invalid file chosen")
            return
        else:
            # save the ufo in the instance folder
            # so that we have a font path which can be
            # needed to perform other actions on the font
            path = self._create_font_instance()
            globals.FONT = font
            if path is not None:
                self.set_page("SUMMARY")

            # print success message
            self._show_alert("Success",
                             "Imported Font: %s" %
                             globals.FONT.info.familyName)
開發者ID:sugarlabs,項目名稱:edit-fonts-activity,代碼行數:49,代碼來源:EditFonts.py

示例11: __button_choose_image_cb

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def __button_choose_image_cb(self, button):

        try:
            chooser = ObjectChooser(self.get_toplevel(), what_filter='Image',
                                    filter_type=FILTER_TYPE_GENERIC_MIME,
                                    show_preview=True)
        except:
            # for compatibility with older versions
            chooser = ObjectChooser(self.get_toplevel(), what_filter='Image')

        try:
            result = chooser.run()

            if result == Gtk.ResponseType.ACCEPT:

                jobject = chooser.get_selected_object()

                images_mime_types = mime.get_generic_type(
                    mime.GENERIC_TYPE_IMAGE).mime_types

                if jobject and jobject.file_path and \
                   jobject.metadata.get('mime_type') in images_mime_types:

                    pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                        jobject.file_path,
                        self._poll.activity._image_size['height'],
                        self._poll.activity._image_size['width'])

                    self._poll.images[self.field] = pixbuf

                    self._poll.images_ds_objects[self.field]['id'] = \
                        jobject.object_id

                    self._poll.images_ds_objects[self.field]['file_path'] = \
                        jobject.file_path

                    self.__show_image_thumbnail()

                else:
                    self._poll.activity.get_alert(
                        _('Poll Activity'),
                        _('Your selection is not an image'))

        finally:
            chooser.destroy()
            del chooser
開發者ID:godiard,項目名稱:poll-activity,代碼行數:48,代碼來源:Widgets.py

示例12: __button_choose_image_cb

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
    def __button_choose_image_cb(self, button, data=None, data2=None):

        if hasattr(mime, 'GENERIC_TYPE_IMAGE'):
            chooser = ObjectChooser(parent=self,
                                    what_filter=mime.GENERIC_TYPE_IMAGE)
        else:
            chooser = ObjectChooser(parent=self)

        try:
            result = chooser.run()

            if result == Gtk.ResponseType.ACCEPT:

                jobject = chooser.get_selected_object()

                images_mime_types = mime.get_generic_type(
                    mime.GENERIC_TYPE_IMAGE).mime_types

                if jobject and jobject.file_path and \
                   jobject.metadata.get('mime_type') in images_mime_types:

                    pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                        jobject.file_path,
                        self._poll.activity._image_size['height'],
                        self._poll.activity._image_size['width'])

                    self._poll.images[int(data)] = pixbuf

                    self._poll.images_ds_objects[int(data)]['id'] = \
                        jobject.object_id

                    self._poll.images_ds_objects[int(data)]['file_path'] = \
                        jobject.file_path

                    self.__show_image_thumbnail(data2, data)
                    button.set_label(_('Change Image'))

                else:
                    self._poll.activity.get_alert(
                        _('Poll Activity'),
                        _('Your selection is not an image'))

        finally:
            chooser.destroy()
            del chooser
開發者ID:Daksh,項目名稱:poll,代碼行數:47,代碼來源:Widgets.py

示例13: _upload_cb

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
 def _upload_cb(self, widget, i):
     chooser = None
     dsobject = None
     name = None
     chooser = ObjectChooser(parent=self._task_master.activity)
     if chooser is not None:
         result = chooser.run()
         if result == Gtk.ResponseType.ACCEPT:
             dsobject = chooser.get_selected_object()
             if dsobject and dsobject.file_path:
                 name = dsobject.metadata['title']
         chooser.destroy()
         del chooser
     if name is not None:
         span = 'size="large"'
         self._labels[i].set_markup('<span %s>%s</span>' % (span, name))
         self._files[i] = dsobject.file_path
         self._mimetypes[i] = dsobject.metadata['mime_type']
開發者ID:cottonpaul,項目名稱:OneSupport,代碼行數:20,代碼來源:tasks.py

示例14: chooser

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
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,
                                filter_type=FILTER_TYPE_GENERIC_MIME,
                                show_preview=True)
    except:
        chooser = ObjectChooser(parent=parent_window, what_filter=filter)
    if chooser is not None:
        try:
            result = chooser.run()
            if result == Gtk.ResponseType.ACCEPT:
                dsobject = chooser.get_selected_object()
                action(dsobject)
                dsobject.destroy()
        finally:
            chooser.destroy()
            del chooser
開發者ID:erilyth,項目名稱:fractionbounce,代碼行數:21,代碼來源:utils.py

示例15: _chooser

# 需要導入模塊: from sugar3.graphics.objectchooser import ObjectChooser [as 別名]
# 或者: from sugar3.graphics.objectchooser.ObjectChooser import destroy [as 別名]
 def _chooser(self, filter, action):
     ''' Choose an object from the datastore and take some action '''
     chooser = None
     try:
         chooser = ObjectChooser(parent=self, what_filter=filter)
     except TypeError:
         chooser = ObjectChooser(
             None, self,
             Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
     if chooser is not None:
         try:
             result = chooser.run()
             if result == Gtk.ResponseType.ACCEPT:
                 dsobject = chooser.get_selected_object()
                 action(dsobject)
                 dsobject.destroy()
         finally:
             chooser.destroy()
             del chooser
開發者ID:leonardcj,項目名稱:turtlepond,代碼行數:21,代碼來源:TurtlePondActivity.py


注:本文中的sugar3.graphics.objectchooser.ObjectChooser.destroy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。