当前位置: 首页>>代码示例>>Python>>正文


Python GLib.GError方法代码示例

本文整理汇总了Python中gi.repository.GLib.GError方法的典型用法代码示例。如果您正苦于以下问题:Python GLib.GError方法的具体用法?Python GLib.GError怎么用?Python GLib.GError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gi.repository.GLib的用法示例。


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

示例1: _load_thread

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def _load_thread(self, loader, path):
        # The try ... except wrapper and the _faulty_image attribute are used to
        # catch weird images that break GdkPixbufLoader but work otherwise
        # See https://github.com/karlch/vimiv/issues/49 for more information
        try:
            self._faulty_image = True
            with open(path, "rb") as f:
                image_bytes = f.read()
                loader.write(image_bytes)
            self._faulty_image = False
            loader.close()
        except GLib.GError:
            self._pixbuf_original = GdkPixbuf.Pixbuf.new_from_file(path)
            self._faulty_image = False
            self._set_image_pixbuf()
            GLib.idle_add(self._update) 
开发者ID:karlch,项目名称:vimiv,代码行数:18,代码来源:image.py

示例2: write_stdin

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def write_stdin(self, writer, line):
        if self.terminated:
            return
        try:
            log.debug(line, extra={"task": self.defname})
            writer.write(line.encode())
            await writer.drain()
        except BrokenPipeError:
            log.debug('SubProcess.write_stdin(): BrokenPipeError', extra={"task": self.defname})
            self.emit("died")
            self.terminate()
        except ConnectionResetError:
            log.debug('SubProcess.write_stdin(): ConnectionResetError', extra={"task": self.defname})
            self.emit("died")
            self.terminate()
        except GLib.GError:
            log.debug("SubProcess.write_stdin(): GLib.GError", extra={"task": self.defname})
            self.emit("died")
            self.terminate() 
开发者ID:pychess,项目名称:pychess,代码行数:21,代码来源:SubProcess.py

示例3: t1_func

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def t1_func():
		for obj in [remote, remote_iface]:
			assert(obj.Foo == "foo")
			assert(obj.Foobar == "foobar")
			obj.Foobar = "barfoo"
			assert(obj.Foobar == "barfoo")
			obj.Foobar = "foobar"
			assert(obj.Foobar == "foobar")
			obj.Bar = "rab"

		remote.Foobar = "barfoo"

		try:
			remote.Get("net.lew21.pydbus.tests.publish_properties", "Bar")
			assert(False)
		except GLib.GError:
			pass
		try:
			remote.Set("net.lew21.pydbus.tests.publish_properties", "Foo", Variant("s", "haxor"))
			assert(False)
		except GLib.GError:
			pass
		assert(remote.GetAll("net.lew21.pydbus.tests.publish_properties") == {'Foobar': 'barfoo', 'Foo': 'foo'})
		remote.Quit() 
开发者ID:LEW21,项目名称:pydbus,代码行数:26,代码来源:publish_properties.py

示例4: _cb_finished

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def _cb_finished(self, proc, results):
		"""
		Callback for wait_check_async.
		With Gio < 3.12, timer and _cb_check_alive is used.
		"""
		try:
			proc.wait_check_finish(results)
			log.info("Subprocess finished with code %s", proc.get_exit_status())
		except GLib.GError:
			# Exited with exit code
			log.info("Subprocess exited with code %s", proc.get_exit_status())
		if proc.get_exit_status() == 127:
			# Command not found
			self.emit("failed", Exception("Command not found"))
		else:
			self.emit('exit', proc.get_exit_status())
		if IS_WINDOWS: self._stdout.close()
		self._cancel.cancel() 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:20,代码来源:daemonprocess.py

示例5: __init__

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def __init__(self, type: str) -> None:
        # initiating notification
        Notify.init("Battery Monitor")
        message = MESSAGES[type]
        head = message[0]
        body = message[1]
        icon = ICONS[type]
        self.last_percentage = 0
        self.last_notification = ''
        self.notifier = Notify.Notification.new(head, body, icon)
        self.notifier.set_urgency(Notify.Urgency.CRITICAL)
        try:
            self.notifier.show()
        except GLib.GError as e:
            # fixing GLib.GError: g-dbus-error-quark blindly
            pass
        self.config = configparser.ConfigParser()
        self.load_config() 
开发者ID:maateen,项目名称:battery-monitor,代码行数:20,代码来源:Notification.py

示例6: show_notification

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def show_notification(self, type: str, battery_percentage: int,
                          remaining_time: str = None, _time: int = 5) -> None:

        message = MESSAGES[type]
        head = message[0]
        body = message[1].format(battery_percentage=battery_percentage,
                                 remaining_time=remaining_time)
        icon = ICONS[type]
        self.notifier.update(head, body, icon)
        try:
            self.notifier.show()
        except GLib.GError as e:
            # fixing GLib.GError: g-dbus-error-quark blindly
            # To Do: investigate the main reason and make a fix
            pass
        time.sleep(self.notification_stability)
        self.notifier.close() 
开发者ID:maateen,项目名称:battery-monitor,代码行数:19,代码来源:Notification.py

示例7: rm_rf

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def rm_rf(self, url):
        try:
            logger.info("Deleting %s ...", url)
            f = Gio.File.new_for_uri(url)
            deleted = False
            try:
                deleted = f.trash()
            except Exception as exc:
                logger.warning("Failed to trash %s. Will try to delete it"
                               " instead", f.get_uri(), exc_info=exc)
            if not deleted:
                self._rm_rf(f)
            logger.info("%s deleted", url)
        except GLib.GError as exc:
            logger.warning("Gio.Gerror", exc_info=exc)
            raise IOError(str(exc)) 
开发者ID:openpaperwork,项目名称:paperwork-backend,代码行数:18,代码来源:fs.py

示例8: can_import

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def can_import(self, file_uris, current_doc=None):
        """
        Check that the specified file looks like a directory containing many
        pdf files
        """
        if len(file_uris) <= 0:
            return False
        try:
            for file_uri in file_uris:
                file_uri = self.fs.safe(file_uri)
                for child in self.fs.recurse(file_uri):
                    if self.check_file_type(child):
                        return True
        except GLib.GError:
            pass
        return False 
开发者ID:openpaperwork,项目名称:paperwork-backend,代码行数:18,代码来源:docimport.py

示例9: notify

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def notify(message, title='AutomaThemely'):
    import gi
    gi.require_version('Notify', '0.7')
    from gi.repository import Notify, GLib

    if not Notify.is_initted():
        Notify.init('AutomaThemely')

    n = Notify.Notification.new(title, message, get_resource('automathemely.svg'))
    try:  # I don't even know... https://bugzilla.redhat.com/show_bug.cgi?id=1582833
        n.show()
    except GLib.GError as e:
        if str(e) != 'g-dbus-error-quark: Unexpected reply type (16)' \
                and str(e) != 'g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient ' \
                              'disconnected from message bus without replying (4)':
            raise e 
开发者ID:C2N14,项目名称:AutomaThemely,代码行数:18,代码来源:utils.py

示例10: create_pipeline_from_string

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def create_pipeline_from_string(self, pipeline_string):
        try:
            self.logger.debug('Creating with pipeline: ' + pipeline_string)
            self.pipeline = Gst.parse_launch(pipeline_string)
            setup_messaging(pipe=self.pipeline, parent_object=self)
        except GLib.GError as e:
            self.error_message = str(e)
            self.logger.error('Failed to create pipeline [%s]: %s' % (pipeline_string, self.error_message))
            raise brave.exceptions.PipelineFailure(self.error_message) 
开发者ID:bbc,项目名称:brave,代码行数:11,代码来源:inputoutputoverlay.py

示例11: add_library_root_path_to_shortcut_folders_of_dialog

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def add_library_root_path_to_shortcut_folders_of_dialog(dialog):
    from gi.repository import GLib
    from rafcon.gui.singleton import library_manager
    library_paths = library_manager.library_root_paths
    library_keys = sorted(library_paths)
    for library_key in library_keys:
        try:
            dialog.add_shortcut_folder(library_paths[library_key])
        except GLib.GError:
            # this occurs if the shortcut file already exists
            # unfortunately dialog.list_shortcut_folders() does not work
            # that's why the error is caught
            pass 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:15,代码来源:interface.py

示例12: start

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def start(self):
        log.debug("SubProcess.start(): create_subprocess_exec...", extra={"task": self.defname})
        if sys.platform == "win32":
            # To prevent engines opening console window
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        else:
            startupinfo = None

        create = asyncio.create_subprocess_exec(* self.argv,
                                                stdin=asyncio.subprocess.PIPE,
                                                stdout=asyncio.subprocess.PIPE,
                                                startupinfo=startupinfo,
                                                env=self.env,
                                                cwd=self.cwd)
        try:
            self.proc = await asyncio.wait_for(create, TIME_OUT_SECOND)
            self.pid = self.proc.pid
            # print(self.pid, self.path)
            if self.lowPriority:
                proc = psutil.Process(self.pid)
                if sys.platform == "win32":
                    niceness = psutil.BELOW_NORMAL_PRIORITY_CLASS
                else:
                    niceness = 15  # The higher, the lower the priority
                if psutil.__version__ >= "2.0.0":
                    proc.nice(niceness)
                else:
                    proc.set_nice(niceness)
            self.read_stdout_task = create_task(self.read_stdout(self.proc.stdout))
            self.write_task = None
        except asyncio.TimeoutError:
            log.warning("TimeoutError", extra={"task": self.defname})
            raise
        except GLib.GError:
            log.warning("GLib.GError", extra={"task": self.defname})
            raise
        except Exception:
            e = sys.exc_info()[0]
            log.warning("%s" % e, extra={"task": self.defname})
            raise 
开发者ID:pychess,项目名称:pychess,代码行数:43,代码来源:SubProcess.py

示例13: _syncthing_cb_config_error

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def _syncthing_cb_config_error(self, exception, command):
		self.cancel_all()
		if isinstance(exception, GLib.GError):
			if exception.code in (0, 39, 34, 45):	# Connection Refused / Cannot connect to destination
				# It usually means that daemon is not yet fully started or not running at all.
				epoch = self._epoch
				self.emit("connection-error", Daemon.REFUSED, exception.message, exception)
				if epoch == self._epoch:
					r = RESTRequest(self, "system/config", self._syncthing_cb_config, self._syncthing_cb_config_error)
					self.timer("config", self._refresh_interval, r.start)
				return
		elif isinstance(exception, HTTPAuthException):
			self.emit("connection-error", Daemon.NOT_AUTHORIZED, exception.message, exception)
			return
		elif isinstance(exception, HTTPCode):
			# HTTP 404 may acually mean old daemon version
			version = get_header(exception.headers, "X-Syncthing-Version")
			if version != None and not compare_version(version, MIN_VERSION):
				self._epoch += 1
				msg = "daemon is too old"
				self.emit("connection-error", Daemon.OLD_VERSION, msg, Exception(msg))
			else:
				self.emit("connection-error", Daemon.UNKNOWN, exception.message, exception)
			return
		elif isinstance(exception, TLSUnsupportedException):
			self.emit("connection-error", Daemon.TLS_UNSUPPORTED, exception.message, exception)
			return
		elif isinstance(exception, ConnectionRestarted):
			# Happens on Windows. Just try again.
			GLib.idle_add(self._request_config)
			return
		elif isinstance(exception, TLSUnsupportedException):
			self.emit("connection-error", Daemon.TLS_UNSUPPORTED, exception.message, exception)
			return
		self.emit("connection-error", Daemon.UNKNOWN, exception.message, exception) 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:37,代码来源:daemon.py

示例14: _error

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def _error(self, exception):
		if self._connection:
			self._connection.close(None)
		if self._epoch == self._parent._epoch:
			if isinstance(exception, GLib.GError):
				if exception.code in (0, 39, 34):	# Connection terminated unexpectedly, Connection Refused
					self._parent._disconnected(message=str(exception))
					return
			self._parent.timer(None, 1, self.start) 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:11,代码来源:daemon.py

示例15: set_image_from_file

# 需要导入模块: from gi.repository import GLib [as 别名]
# 或者: from gi.repository.GLib import GError [as 别名]
def set_image_from_file(self, iconpath):
		try:
			pixbuf = GdkPixbuf.Pixbuf.new_from_file(iconpath)
			icon = Gtk.Image.new_from_pixbuf(pixbuf)
		except GLib.GError:
			icon = Gtk.Image.new_from_stock(Gtk.STOCK_MISSING_IMAGE, 22)
		return icon 
开发者ID:Jessewb786,项目名称:Silaty,代码行数:9,代码来源:sidebar.py


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