本文整理汇总了Python中gi.repository.GObject.GError方法的典型用法代码示例。如果您正苦于以下问题:Python GObject.GError方法的具体用法?Python GObject.GError怎么用?Python GObject.GError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GObject
的用法示例。
在下文中一共展示了GObject.GError方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: image_size
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
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
#
#-------------------------------------------------------------------------
示例2: __get_gconf_string
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
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
#
#-------------------------------------------------------------------------
示例3: __get_gconf_bool
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
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
#
#-------------------------------------------------------------------------
示例4: __load_icon
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def __load_icon(self):
"""
Loads emblem icons from the current icon theme
Sometimes an icon can't be loaded because of a bug in system
libraries, e.g. bug #1079587. Gracefuly degradate and skip
the loading of a corrupted icon.
"""
self.symbol_model = Gtk.ListStore(GdkPixbuf.Pixbuf, str)
for icon in Gtk.IconTheme.get_default().list_icons(context="Emblems"):
try:
img = Gtk.IconTheme.get_default().load_icon(icon, 16, 0)
self.symbol_model.append([img, icon])
except GObject.GError:
log.error(f"Failed to load icon '{icon}'")
self.symbol_iv.set_model(self.symbol_model)
self.loaded = True
# PUBLIC IF #####
示例5: send2trash
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def send2trash(path):
try:
f = Gio.File.new_for_path(path)
f.trash(cancellable=None)
except GObject.GError as e:
raise OSError(e.message)
示例6: get_thumbnail_image
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
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
#
#-------------------------------------------------------------------------
示例7: send2trash
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def send2trash(path):
try:
f = Gio.File.new_for_path(path)
f.trash(cancellable=None)
except GObject.GError as e:
if e.code == Gio.IOErrorEnum.NOT_SUPPORTED:
# We get here if we can't create a trash directory on the same
# device. I don't know if other errors can result in NOT_SUPPORTED.
raise TrashPermissionError('')
raise OSError(e.message)
示例8: trash
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def trash(self, file):
'''Trash a file or folder by moving it to the system trashcan
if supported. Depends on the C{gio} library.
@param file: a C{LocalFile} object
@returns: C{True} when successful
@raises TrashNotSupportedError: if trashing is not supported
or failed.
@raises TrashCancelledError: if trashing was cancelled by the
user
'''
if not Gio:
raise TrashNotSupportedError('Gio not imported')
elif not isinstance(file, LocalFSObjectBase):
raise TrashNotSupportedError('cannot trash a non-local file or folder')
if file.exists():
logger.info('Move %s to trash' % file)
f = Gio.File.new_for_uri(file.uri)
try:
ok = f.trash()
except GObject.GError as error:
if error.code == Gio.IOErrorEnum.CANCELLED \
or (os.name == 'nt' and error.code == 0):
# code 0 observed on windows for cancel
logger.info('Trash operation cancelled')
raise TrashCancelledError('Trashing cancelled')
elif error.code == Gio.IOErrorEnum.NOT_SUPPORTED:
raise TrashNotSupportedError('Trashing failed')
else:
raise error
else:
if not ok:
raise TrashNotSupportedError('Trashing failed')
file._cleanup()
return True
else:
return False
示例9: get_mime_icon
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def get_mime_icon(file, size):
if not Gio:
return None
try:
f = Gio.File.new_for_uri(file.uri)
info = f.query_info('standard::*', Gio.FileQueryInfoFlags.NONE, None)
icon = info.get_icon()
except:
logger.exception('Failed to query info for file: %s', file)
return None
global _last_warning_missing_icon
if isinstance(icon, Gio.ThemedIcon):
names = icon.get_names()
icon_theme = Gtk.IconTheme.get_default()
try:
icon_info = icon_theme.choose_icon(names, size, 0)
if icon_info:
return icon_info.load_icon()
else:
if _last_warning_missing_icon != names:
logger.debug('Missing icons in icon theme: %s', names)
_last_warning_missing_icon = names
return None
except GObject.GError:
logger.exception('Could not load icon for file: %s', file)
return None
else:
return None
示例10: on_notebook_properties_changed
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def on_notebook_properties_changed(self, properties):
self.set_title(self.notebook.name + ' - Zim')
if self.notebook.icon:
try:
self.set_icon_from_file(self.notebook.icon)
except GObject.GError:
logger.exception('Could not load icon %s', self.notebook.icon)
示例11: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def __init__(self, notebook, page, navigation):
Window.__init__(self)
self.navigation = navigation
self.notebook = notebook
self.set_title(page.name + ' - Zim')
#if ui.notebook.icon:
# try:
# self.set_icon_from_file(ui.notebook.icon)
# except GObject.GError:
# logger.exception('Could not load icon %s', ui.notebook.icon)
page = notebook.get_page(page)
self.uistate = notebook.state['PageWindow']
self.uistate.setdefault('windowsize', (500, 400), check=value_is_coord)
w, h = self.uistate['windowsize']
self.set_default_size(w, h)
self.pageview = PageView(notebook, navigation, secondary=True)
self.pageview.set_page(page)
self.add(self.pageview)
def do_delete_event(*a):
logger.debug('Close PageWindow for %s', page)
self.uistate['windowsize'] = tuple(self.get_size())
self.connect('delete-event', do_delete_event)
示例12: spawn
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import GError [as 别名]
def spawn(self, args=None, callback=None, data=None, cwd=None):
'''Start the application in the background and return immediately.
This is used to start an external in parallel with zim that is
not expected to exit immediatly, so we do not want to wait for
it - e.g. a webbrowser to show an URL that was clicked.
@param args: additional arguments to give to the command as tuple or list
@param callback: optional callback can be used to trigger when
the application exits. The signature is::
callback(status, data)
where 'C{status}' is the exit status of the process. The
application object provides a constant 'C{STATUS_OK}' which can
be used to test if the application was successful or not.
@param data: additional data for the callback
@param cwd: the folder to set as working directory for the command
@returns: the PID for the new process
'''
cwd, argv = self._checkargs(cwd, args)
flags = GObject.SPAWN_SEARCH_PATH
if callback:
flags |= GObject.SPAWN_DO_NOT_REAP_CHILD
# without this flag child is reaped automatically -> no zombies
if cwd is None:
cwd = os.getcwd()
logger.info('Spawning: %s (cwd: %s)', argv, cwd)
if TEST_MODE:
TEST_MODE_RUN_CB(argv)
return None
try:
try:
pid, stdin, stdout, stderr = \
GObject.spawn_async(argv, flags=flags, working_directory=cwd)
except GObject.GError:
if _CAN_CALL_FLATPAK_HOST_COMMAND:
pid, stdin, stdout, stderr = \
GObject.spawn_async(_FLATPAK_HOSTCOMMAND_PREFIX + argv, flags=flags, working_directory=cwd)
else:
raise
except GObject.GError:
from zim.gui.widgets import ErrorDialog
ErrorDialog(None, _('Failed running: %s') % argv[0]).run()
#~ # T: error when application failed to start
return None
else:
logger.debug('Process started with PID: %i', pid)
if callback:
# child watch does implicit reaping -> no zombies
if data is None:
GObject.child_watch_add(pid,
lambda pid, status: callback(status))
else:
GObject.child_watch_add(pid,
lambda pid, status, data: callback(status, data), data)
return pid