當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。