Python gi.repository.GObject 模块,GError() 实例源码

我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用gi.repository.GObject.GError()

项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def __get_gconf_string(key):
    """
    Attempt to retrieve a value from the GNOME gconf database based of the
    passed key.

    :param key: GCONF key
    :type key: unicode
    :returns: Value associated with the GCONF key
    :rtype: unicode
    """
    try:
        val =  CLIENT.get_string(key)
    except GObject.GError:
        val = None
    return str(val)

#-------------------------------------------------------------------------
#
# __get_gconf_bool
#
#-------------------------------------------------------------------------
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def __get_gconf_bool(key):
    """
    Attempt to retrieve a value from the GNOME gconf database based of the
    passed key.

    :param key: GCONF key
    :type key: unicode
    :returns: Value associated with the GCONF key
    :rtype: bool
    """
    try:
        val = CLIENT.get_bool(key)
    except GObject.GError:
        val = None
    return val

#-------------------------------------------------------------------------
#
# __build_thumb_path
#
#-------------------------------------------------------------------------
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def image_size(source):
    """
    Return the width and size of the specified image.

    :param source: source image file, in any format that gtk recongizes
    :type source: unicode
    :rtype: tuple(int, int)
    :returns: a tuple consisting of the width and height
    """
    from gi.repository import GdkPixbuf
    from gi.repository import GObject
    try:
        img = GdkPixbuf.Pixbuf.new_from_file(source)
        width = img.get_width()
        height = img.get_height()
    except GObject.GError:
        width = 0
        height = 0
    return (width, height)

#-------------------------------------------------------------------------
#
# image_actual_size
#
#-------------------------------------------------------------------------
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def start_app(datadir):
    global splash_win
    if not options.no_splash:
        solfege.splash_win = splash_win = SplashWin()
        time.sleep(0.1)
        Gdk.flush()
        while Gtk.events_pending():
            Gtk.main_iteration()

    else:
        solfege.splash_win = splash_win = None
    style_provider = Gtk.CssProvider()
    with open("solfege.css", "r") as f:
        css = f.read()
    try:
        style_provider.load_from_data(css)
    except GObject.GError, e:
        print e
        pass
    Gtk.StyleContext.add_provider_for_screen(
        Gdk.Screen.get_default(), style_provider,
        Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    GObject.timeout_add(1, start_gui, datadir)
    Gtk.main()
项目:pycam    作者:SebKuzminsky    | 项目源码 | 文件源码
def add_to_recent_file_list(self, filename):
        # Add the item to the recent files list - if it already exists.
        # Otherwise it will be added later after writing the file.
        uri = pycam.Utils.URIHandler(filename)
        if uri.exists():
            # skip this, if the recent manager is not available (e.g. GTK 2.12.1 on Windows)
            if self.recent_manager:
                if self.recent_manager.has_item(uri.get_url()):
                    try:
                        self.recent_manager.remove_item(uri.get_url())
                    except GObject.GError:
                        pass
                self.recent_manager.add_item(uri.get_url())
            # store the directory of the last loaded file
            if uri.is_local():
                self.last_dirname = os.path.dirname(uri.get_local_path())
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _gio_screenshots_json_download_complete_cb(self, source, result, path):
        try:
            res, content, etag = source.load_contents_finish(result)
        except GObject.GError:
            # ignore read errors, most likely transient
            return
        if content is not None:
            try:
                content = json.loads(content)
            except ValueError as e:
                LOG.error("can not decode: '%s' (%s)" % (content, e))
                content = None

        if isinstance(content, dict):
            # a list of screenshots as listsed online
            screenshot_list = content['screenshots']
        else:
            # fallback to a list of screenshots as supplied by the axi
            screenshot_list = []

        # save for later and emit
        self._screenshot_list = self._sort_screenshots_by_best_version(
            screenshot_list)
        self.emit("screenshots-available", self._screenshot_list)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _check_url_reachable_and_then_download_cb(self, f, result,
                                                  user_data=None):
        self.LOG.debug("_check_url_reachable_and_then_download_cb: %s" % f)
        try:
            info = f.query_info_finish(result)
            etag = info.get_etag()
            self.emit('file-url-reachable', True)
            self.LOG.debug("file reachable %s %s %s" % (self.url,
                                                        info,
                                                        etag))
            # url is reachable, now download the file
            f.load_contents_async(
                self._cancellable, self._file_download_complete_cb, None)
        except GObject.GError as e:
            self.LOG.debug("file *not* reachable %s" % self.url)
            self.emit('file-url-reachable', False)
            self.emit('error', GObject.GError, e)
        del f
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _gio_screenshots_json_download_complete_cb(self, source, result, path):
        try:
            res, content, etag = source.load_contents_finish(result)
        except GObject.GError:
            # ignore read errors, most likely transient
            return
        if content is not None:
            try:
                content = json.loads(content)
            except ValueError as e:
                LOG.error("can not decode: '%s' (%s)" % (content, e))
                content = None

        if isinstance(content, dict):
            # a list of screenshots as listsed online
            screenshot_list = content['screenshots']
        else:
            # fallback to a list of screenshots as supplied by the axi
            screenshot_list = []

        # save for later and emit
        self._screenshot_list = self._sort_screenshots_by_best_version(
            screenshot_list)
        self.emit("screenshots-available", self._screenshot_list)
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def get_thumbnail_image(src_file, mtype=None, rectangle=None, size=SIZE_NORMAL):
    """
    Return the thumbnail image (in GTK Pixbuf format) associated with the
    source file passed to the function. If no thumbnail could be found,
    the associated icon for the mime type is returned, or if that cannot be
    found, a generic document icon is returned.

    The image is not generated every time, but only if the thumbnail does not
    exist, or if the source file is newer than the thumbnail.

    :param src_file: Source media file
    :type src_file: unicode
    :param mime_type: mime type of the source file
    :type mime_type: unicode
    :param rectangle: subsection rectangle
    :type rectangle: tuple
    :returns: thumbnail representing the source file
    :rtype: GdkPixbuf.Pixbuf
    """
    try:
        filename = get_thumbnail_path(src_file, mtype, rectangle, size)
        return GdkPixbuf.Pixbuf.new_from_file(filename)
    except (GObject.GError, OSError):
        if mtype:
            return find_mime_type_pixbuf(mtype)
        else:
            default = os.path.join(IMAGE_DIR, "document.png")
            return GdkPixbuf.Pixbuf.new_from_file(default)

#-------------------------------------------------------------------------
#
# get_thumbnail_path
#
#-------------------------------------------------------------------------
项目:pipeline    作者:liorbenhorin    | 项目源码 | 文件源码
def send2trash(path):
    try:
        f = Gio.File.new_for_path(path)
        f.trash(cancellable=None)
    except GObject.GError as e:
        raise OSError(e.message)
项目:pycam    作者:SebKuzminsky    | 项目源码 | 文件源码
def get_icons_pixbuffers():
    result = []
    for icon_filename in WINDOW_ICON_FILENAMES:
        abs_filename = get_ui_file_location(icon_filename, silent=True)
        if abs_filename:
            try:
                result.append(Gdk.pixbuf_new_from_file(abs_filename))
            except GObject.GError as err_msg:
                # ignore icons that are not found
                log.debug("Failed to process window icon (%s): %s", abs_filename, err_msg)
        else:
            log.debug("Failed to locate window icon: %s", icon_filename)
    return result
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_icon(self, doc):
        try:
            full_icon_file_name = self.db.get_iconname(doc)
            icon_file_name = split_icon_ext(full_icon_file_name)
            if icon_file_name:
                icon_name = icon_file_name
                if icon_name in self.icon_cache:
                    return self.icon_cache[icon_name]
                # icons.load_icon takes between 0.001 to 0.01s on my
                # machine, this is a significant burden because get_value
                # is called *a lot*. caching is the only option

                # look for the icon on the iconpath
                if self.icons.has_icon(icon_name):
                    icon = self.icons.load_icon(icon_name, self.icon_size, 0)
                    if icon:
                        self.icon_cache[icon_name] = icon
                        return icon
                elif self.db.get_icon_download_url(doc):
                    url = self.db.get_icon_download_url(doc)
                    self._download_icon_and_show_when_ready(
                        url,
                        self.get_pkgname(doc),
                        full_icon_file_name)
                    # display the missing icon while the real one downloads
                    self.icon_cache[icon_name] = self.missing_icon
        except GObject.GError as e:
            LOG.debug("get_icon returned '%s'" % e)
        return self.missing_icon
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_main_menu_path(self, desktop_file, menu_files_list=None):
        if not desktop_file:
            return
        from gi.repository import GMenu
        from gi.repository import GObject
        # use the system ones by default, but allow override for
        # easier testing
        if menu_files_list is None:
            menu_files_list = ["applications.menu", "settings.menu"]
        for n in menu_files_list:
            if n.startswith("/"):
                tree = GMenu.Tree.new_for_path(n, 0)
            else:
                tree = GMenu.Tree.new(n, 0)
            try:
                tree.load_sync()
            except GObject.GError as e:
                LOG.warning("could not load GMenu path: %s" % e)
                return

            root = tree.get_root_directory()
            self._search_gmenu_dir([root],
                                   os.path.basename(desktop_file))
            # retry search for app-install-data desktop files
            if not self._found and ":" in os.path.basename(desktop_file):
                # the desktop files in app-install-data have a layout
                # like "pkg:file.desktop" so we need to take that into
                # account when searching
                desktop_file = os.path.basename(desktop_file).split(":")[1]
                self._search_gmenu_dir([root], desktop_file)
            return self._found


# these are the old static bindinds that are no longer required
# (this is just kept here in case of problems with the dynamic
#  GIR and the old gtk2 gtk ui)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _get_icon_as_pixbuf(self, app_details):
        if app_details.icon:
            if self.icons.has_icon(app_details.icon):
                try:
                    return self.icons.load_icon(app_details.icon,
                                                self.APP_ICON_SIZE, 0)
                except GObject.GError as e:
                    logging.warn("failed to load '%s': %s" % (
                            app_details.icon, e))
                    return self.icons.load_icon(Icons.MISSING_APP,
                                                self.APP_ICON_SIZE, 0)
            elif app_details.icon_url:
                LOG.debug("did not find the icon locally, must download it")

                def on_image_download_complete(downloader, image_file_path):
                    # when the download is complete, replace the icon in the
                    # view with the downloaded one
                    logging.debug("_get_icon_as_pixbuf:image_downloaded() %s" %
                        image_file_path)
                    try:
                        pb = GdkPixbuf.Pixbuf.new_from_file(image_file_path)
                        # fixes crash in testsuite if window is destroyed
                        # and after that this callback is called (wouldn't
                        # it be nice if gtk would do that automatically?)
                        if self.icon.get_property("visible"):
                            self.icon.set_from_pixbuf(pb)
                    except Exception as e:
                        LOG.warning(
                            "couldn't load downloadable icon file '%s': %s" %
                            (image_file_path, e))

                image_downloader = SimpleFileDownloader()
                image_downloader.connect(
                    'file-download-complete', on_image_download_complete)
                image_downloader.download_file(
                    app_details.icon_url, app_details.cached_icon_file_path)
        return self.icons.load_icon(Icons.MISSING_APP, self.APP_ICON_SIZE, 0)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, icons, layout, show_ratings, overlay_icon_name):
        Gtk.CellRendererText.__init__(self)

        # the icon pixbuf to be displayed in the row
        self.icon = None

        # geometry-state values
        self.pixbuf_width = 0
        self.apptitle_width = 0
        self.apptitle_height = 0
        self.normal_height = 0
        self.selected_height = 0
        self.show_ratings = show_ratings

        # button packing
        self.button_spacing = 0
        self._buttons = {
            Gtk.PackType.START: [],
            Gtk.PackType.END: []
        }
        self._all_buttons = {}

        # cache a layout
        self._layout = layout
        # star painter, paints stars
        self._stars = StarRenderer()
        self._stars.size = StarSize.SMALL

        # icon/overlay jazz
        try:
            self._installed = icons.load_icon(overlay_icon_name,
                                              self.OVERLAY_SIZE, 0)
        except GObject.GError:
            # icon not present in theme, probably because running uninstalled
            self._installed = icons.load_icon('emblem-system',
                                              self.OVERLAY_SIZE, 0)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _on_screenshot_download_complete(self, loader, screenshot_path):
        try:
            self.screenshot_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
                screenshot_path)
        except Exception, e:
            LOG.exception("Pixbuf.new_from_file() failed")
            self.loader.emit('error', GObject.GError, e)
            return False

        #context = self.button.get_style_context()
        tw, th = self.MAX_SIZE_CONSTRAINTS
        pb = self._downsize_pixbuf(self.screenshot_pixbuf, tw, th)
        self.button.image.set_from_pixbuf(pb)
        self.ready = True
        self.display_image()
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def render_cell_icon(self, column, cell, store, iter, user_data):
        pkg = store.get_value(iter, self.COL_PKG)
        if pkg is None:
            cell.set_visible(False)
            return

        cell.set_visible(True)

        when = store.get_value(iter, self.COL_WHEN)
        if isinstance(when, datetime.datetime):
            action = store.get_value(iter, self.COL_ACTION)
            cell.set_property('pixbuf', self._emblems[action])

            #~ icon_name = Icons.MISSING_APP
            #~ for m in self.db.xapiandb.postlist("AP" + pkg):
                #~ doc = self.db.xapiandb.get_document(m.docid)
                #~ icon_value = doc.get_value(XapianValues.ICON)
                #~ if icon_value:
                    #~ icon_name = os.path.splitext(icon_value)[0]
                #~ break
            #~ if icon_name in self._app_icon_cache:
                #~ icon = self._app_icon_cache[icon_name]
            #~ else:
                #~ try:
                    #~ icon = self.icons.load_icon(icon_name, self.ICON_SIZE,
                        #~ 0)
                #~ except GObject.GError:
                    #~ icon = self._app_icon_cache[Icons.MISSING_APP]
                #~ self._app_icon_cache[icon_name] = icon
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_icon(self, doc):
        try:
            full_icon_file_name = self.db.get_iconname(doc)
            icon_file_name = split_icon_ext(full_icon_file_name)
            if icon_file_name:
                icon_name = icon_file_name
                if icon_name in self.icon_cache:
                    return self.icon_cache[icon_name]
                # icons.load_icon takes between 0.001 to 0.01s on my
                # machine, this is a significant burden because get_value
                # is called *a lot*. caching is the only option

                # look for the icon on the iconpath
                if self.icons.has_icon(icon_name):
                    icon = self.icons.load_icon(icon_name, self.icon_size, 0)
                    if icon:
                        self.icon_cache[icon_name] = icon
                        return icon
                elif self.db.get_icon_download_url(doc):
                    url = self.db.get_icon_download_url(doc)
                    self._download_icon_and_show_when_ready(
                        url,
                        self.get_pkgname(doc),
                        full_icon_file_name)
                    # display the missing icon while the real one downloads
                    self.icon_cache[icon_name] = self.missing_icon
        except GObject.GError as e:
            LOG.debug("get_icon returned '%s'" % e)
        return self.missing_icon
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_main_menu_path(self, desktop_file, menu_files_list=None):
        if not desktop_file:
            return
        from gi.repository import GMenu
        from gi.repository import GObject
        # use the system ones by default, but allow override for
        # easier testing
        if menu_files_list is None:
            menu_files_list = ["applications.menu", "settings.menu"]
        for n in menu_files_list:
            if n.startswith("/"):
                tree = GMenu.Tree.new_for_path(n, 0)
            else:
                tree = GMenu.Tree.new(n, 0)
            try:
                tree.load_sync()
            except GObject.GError as e:
                LOG.warning("could not load GMenu path: %s" % e)
                return

            root = tree.get_root_directory()
            self._search_gmenu_dir([root],
                                   os.path.basename(desktop_file))
            # retry search for app-install-data desktop files
            if not self._found and ":" in os.path.basename(desktop_file):
                # the desktop files in app-install-data have a layout
                # like "pkg:file.desktop" so we need to take that into
                # account when searching
                desktop_file = os.path.basename(desktop_file).split(":")[1]
                self._search_gmenu_dir([root], desktop_file)
            return self._found


# these are the old static bindinds that are no longer required
# (this is just kept here in case of problems with the dynamic
#  GIR and the old gtk2 gtk ui)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, icons, layout, show_ratings, overlay_icon_name):
        Gtk.CellRendererText.__init__(self)

        # the icon pixbuf to be displayed in the row
        self.icon = None

        # geometry-state values
        self.pixbuf_width = 0
        self.apptitle_width = 0
        self.apptitle_height = 0
        self.normal_height = 0
        self.selected_height = 0
        self.show_ratings = show_ratings

        # button packing
        self.button_spacing = 0
        self._buttons = {
            Gtk.PackType.START: [],
            Gtk.PackType.END: []
        }
        self._all_buttons = {}

        # cache a layout
        self._layout = layout
        # star painter, paints stars
        self._stars = StarRenderer()
        self._stars.size = StarSize.SMALL

        # icon/overlay jazz
        try:
            self._installed = icons.load_icon(overlay_icon_name,
                                              self.OVERLAY_SIZE, 0)
        except GObject.GError:
            # icon not present in theme, probably because running uninstalled
            self._installed = icons.load_icon('emblem-system',
                                              self.OVERLAY_SIZE, 0)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _on_screenshot_download_complete(self, loader, screenshot_path):
        try:
            self.screenshot_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
                screenshot_path)
        except Exception, e:
            LOG.exception("Pixbuf.new_from_file() failed")
            self.loader.emit('error', GObject.GError, e)
            return False

        #context = self.button.get_style_context()
        tw, th = self.MAX_SIZE_CONSTRAINTS
        pb = self._downsize_pixbuf(self.screenshot_pixbuf, tw, th)
        self.button.image.set_from_pixbuf(pb)
        self.ready = True
        self.display_image()
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _reset_icon_cache(self, theme=None):
        self._app_icon_cache.clear()
        try:
            missing = self.icons.load_icon(Icons.MISSING_APP, self.ICON_SIZE,
                0)
        except GObject.GError:
            missing = None
        self._app_icon_cache[Icons.MISSING_APP] = missing
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def render_cell_icon(self, column, cell, store, iter, user_data):
        pkg = store.get_value(iter, self.COL_PKG)
        if pkg is None:
            cell.set_visible(False)
            return

        cell.set_visible(True)

        when = store.get_value(iter, self.COL_WHEN)
        if isinstance(when, datetime.datetime):
            action = store.get_value(iter, self.COL_ACTION)
            cell.set_property('pixbuf', self._emblems[action])

            #~ icon_name = Icons.MISSING_APP
            #~ for m in self.db.xapiandb.postlist("AP" + pkg):
                #~ doc = self.db.xapiandb.get_document(m.docid)
                #~ icon_value = doc.get_value(XapianValues.ICON)
                #~ if icon_value:
                    #~ icon_name = os.path.splitext(icon_value)[0]
                #~ break
            #~ if icon_name in self._app_icon_cache:
                #~ icon = self._app_icon_cache[icon_name]
            #~ else:
                #~ try:
                    #~ icon = self.icons.load_icon(icon_name, self.ICON_SIZE,
                        #~ 0)
                #~ except GObject.GError:
                    #~ icon = self._app_icon_cache[Icons.MISSING_APP]
                #~ self._app_icon_cache[icon_name] = icon