• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python objectchooser.ObjectChooser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sugar3.graphics.objectchooser.ObjectChooser的典型用法代码示例。如果您正苦于以下问题:Python ObjectChooser类的具体用法?Python ObjectChooser怎么用?Python ObjectChooser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ObjectChooser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _load_project

    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,代码行数:28,代码来源:activity.py


示例2: _object_chooser

    def _object_chooser(self, mime_type, type_name):
        chooser = ObjectChooser()
        matches_mime_type = False

        response = chooser.run()
        if response == Gtk.ResponseType.ACCEPT:
            jobject = chooser.get_selected_object()
            metadata = jobject.metadata
            file_path = jobject.file_path

            if metadata['mime_type'] == mime_type:
                matches_mime_type = True

            else:
                alert = Alert()

                alert.props.title = _('Invalid object')
                alert.props.msg = \
                       _('The selected object must be a %s file' % (type_name))

                ok_icon = Icon(icon_name='dialog-ok')
                alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
                ok_icon.show()

                alert.connect('response', lambda a, r: self.remove_alert(a))

                self.add_alert(alert)

                alert.show()

        return matches_mime_type, file_path, metadata['title']
开发者ID:sugarlabs,项目名称:AnalyzeJournal,代码行数:31,代码来源:activity.py


示例3: add_image

    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,代码行数:25,代码来源:image_category.py


示例4: _load_project

 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,代码行数:8,代码来源:activity.py


示例5: load

    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,代码行数:55,代码来源:EditFonts.py


示例6: _choose_image

    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,代码行数:60,代码来源:reflectwindow.py


示例7: _new_picture

 def _new_picture(self, widget):
     try:
         chooser = ObjectChooser(parent=self)
     except:
         chooser = None
     f = None
     if chooser is not None:
         result = chooser.run()
         if result == Gtk.ResponseType.ACCEPT:
             dsobject = chooser.get_selected_object()
             f = dsobject.file_path
     if f is not None:
         self._image = pygame.image.load(f)
         self.actividad.set_background(self._image)
开发者ID:sugarlabs,项目名称:iknowEditor,代码行数:14,代码来源:activity.py


示例8: run

    def run(self):
        jobject = None
        _file = None
        try:
            result = ObjectChooser.run(self)
            if result == Gtk.ResponseType.ACCEPT:
                jobject = self.get_selected_object()
                logging.debug('FilePicker.show: %r', jobject)

                if jobject and jobject.file_path:
                    tmp_dir = tempfile.mkdtemp(prefix='', \
                            dir=os.path.join(get_activity_root(), 'tmp'))
                    _file = os.path.join(tmp_dir, _basename_strip(jobject))

                    os.rename(jobject.file_path, _file)

                    global _temp_dirs_to_clean
                    _temp_dirs_to_clean.append(tmp_dir)

                    logging.debug('FilePicker.show: file=%r', _file)
        finally:
            if jobject is not None:
                jobject.destroy()

        return _file
开发者ID:georgejhunt,项目名称:HaitiDictionary.activity,代码行数:25,代码来源:filepicker.py


示例9: import_font

    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,代码行数:47,代码来源:EditFonts.py


示例10: __add_cover_response_cb

    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,代码行数:34,代码来源:activity.py


示例11: add_image

    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,代码行数:27,代码来源:toolbar.py


示例12: _load_image_cb

 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,代码行数:35,代码来源:NutritionActivity.py


示例13: _upload_cb

 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,代码行数:18,代码来源:tasks.py


示例14: show

	def show(self):
		title = None
		parent = None
		file = None
		job = None
		chooser = ObjectChooser()

		try:
			result = chooser.run()
			if result == Gtk.ResponseType.ACCEPT:
				jobject = chooser.get_selected_object()

				if jobject and jobject.file_path:
					job = jobject

		finally:
			chooser.destroy()
			del chooser

		return job
开发者ID:sugarlabs,项目名称:maps-activity,代码行数:20,代码来源:filepicker.py


示例15: _show_picker_cb

    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,代码行数:26,代码来源:ImageViewerActivity.py


示例16: pick

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.ResponseType.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
开发者ID:leonardcj,项目名称:memorize-activity,代码行数:40,代码来源:chooser.py


示例17: show_picker_cb

    def show_picker_cb(self, button=None):
        # optional parameter button is used when called from activity.py
        # emptypanel big button
        jobject = None
        chooser = ObjectChooser(self.activity,
                                what_filter=mime.GENERIC_TYPE_AUDIO)

        try:
            result = chooser.run()
            if result == Gtk.ResponseType.ACCEPT:
                jobject = chooser.get_selected_object()
                if jobject and jobject.file_path:
                    logging.info('Adding %s', jobject.file_path)
                    self.activity.playlist_widget.load_file(jobject)
                    self.check_if_next_prev()

                    self.activity._switch_canvas(False)
                    self.activity._view_toolbar._show_playlist.set_active(
                        True)
        finally:
            if jobject is not None:
                jobject.destroy()
开发者ID:sugarlabs,项目名称:jukebox-activity,代码行数:22,代码来源:controls.py


示例18: import_clicked_cb

    def import_clicked_cb(self, btn):
        chooser = ObjectChooser(parent=self,
                                what_filter='text/x-typing-turtle-lessons')

        jobject = None
        if chooser.run() == Gtk.ResponseType.ACCEPT:
            jobject = chooser.get_selected_object()

        if jobject and jobject.file_path:
            fd = open(jobject.file_path, 'r')
            
            try:
                data = json.loads(fd.read())
                
                # Replace lessons without destroying the object.
                while len(self.lessons):
                    self.lessons.pop()
                for l in data['lessons']:
                    self.lessons.append(l)
                self.build()
            
            finally:
                fd.close()
开发者ID:godiard,项目名称:typing-turtle-activity,代码行数:23,代码来源:editlessonlistscreen.py


示例19: journal_open_image

    def journal_open_image (self):
        self.object_chooser_active = True
        if hasattr(mime, 'GENERIC_TYPE_IMAGE'):
            chooser = ObjectChooser(_('Choose image'),
                    what_filter=mime.GENERIC_TYPE_IMAGE)
        else:
            chooser = ObjectChooser(_('Choose image'))

        try:
            result = chooser.run()
            if result == Gtk.ResponseType.ACCEPT and chooser.get_selected_object():
                jobject = chooser.get_selected_object()
            else:
                return False

            if jobject and jobject.file_path:
                logging.debug("journal_open_image: fname=%s" % jobject.file_path)
                try:
                    self.orig_pic = GdkPixbuf.Pixbuf.new_from_file(jobject.file_path)
                    self.filename = os.path.join('images', os.path.basename(jobject.file_path))
                except Exception, e:
                    logging.error("journal_open_image: %s" % e)
                    return False
            else:
开发者ID:sugarlabs,项目名称:laybrinth-activity,代码行数:24,代码来源:ImageThought.py


示例20: run

    def run(self):
        jobject = None
        _file = None
        try:
            result = ObjectChooser.run(self)
            if result == Gtk.ResponseType.ACCEPT:
                jobject = self.get_selected_object()
                logging.debug('FilePicker.run: %r', jobject)

                if jobject and jobject.file_path:
                    _file = jobject.file_path
                    logging.debug('FilePicker.run: file=%r', _file)
        finally:
            if jobject is not None:
                jobject.destroy()

        return _file
开发者ID:luuik,项目名称:sugar-toolkit-gtk3,代码行数:17,代码来源:webkit1.py



注:本文中的sugar3.graphics.objectchooser.ObjectChooser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python palette.Palette类代码示例发布时间:2022-05-27
下一篇:
Python menuitem.MenuItem类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap