當前位置: 首頁>>代碼示例>>Python>>正文


Python GLib.Error方法代碼示例

本文整理匯總了Python中gi.repository.GLib.Error方法的典型用法代碼示例。如果您正苦於以下問題:Python GLib.Error方法的具體用法?Python GLib.Error怎麽用?Python GLib.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gi.repository.GLib的用法示例。


在下文中一共展示了GLib.Error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _connect

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def _connect(self, device):
        def cb_connect():
            try:
                bus = pydbus.SystemBus()
                proxy = bus.get(SERVICE_NAME, device.path)
                proxy.Connect()
            except KeyError:
                self._log.debug("The device has likely disappeared.", exc_info=True)
            except GLib.Error:
                self._log.debug("Connect() failed:", exc_info=True)
            else:
                self._log.info("Connection successful.")

            self.queued_connections -= 1

        if self.queued_connections == 0:
            print_device(device, "Connecting")
            GLib.idle_add(cb_connect)
            device.connected = True
            self.queued_connections += 1 
開發者ID:scipag,項目名稱:btle-sniffer,代碼行數:22,代碼來源:sniffer.py

示例2: load_pixbuf

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def load_pixbuf(icon_name, size):
    pixbuf = None
    theme = Gtk.IconTheme.get_default()
    if icon_name:
        try:
            icon_info = theme.lookup_icon(icon_name, size, 0)
            if icon_info:
                pixbuf = icon_info.load_icon()
        except GLib.Error:
            pass
    if not pixbuf:
        pixbuf = theme.load_icon("com.github.bilelmoussaoui.Authenticator",
                                 size, 0)

    if pixbuf and (pixbuf.props.width != size or pixbuf.props.height != size):
        pixbuf = pixbuf.scale_simple(size, size,
                                     GdkPixbuf.InterpType.BILINEAR)
    return pixbuf 
開發者ID:bilelmoussaoui,項目名稱:Authenticator,代碼行數:20,代碼來源:utils.py

示例3: load_style_css

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def load_style_css(self, css_file):
		self.logger.debug('loading style from css file: ' + css_file)
		css_file = Gio.File.new_for_path(css_file)
		style_provider = Gtk.CssProvider()
		style_provider.connect('parsing-error', self.signal_css_provider_parsing_error)
		try:
			style_provider.load_from_file(css_file)
		except GLib.Error:  # pylint: disable=catching-non-exception
			self.logger.error('there was an error parsing the css file, it will not be applied as a style provider')
			return None
		Gtk.StyleContext.add_provider_for_screen(
			Gdk.Screen.get_default(),
			style_provider,
			Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
		)
		return style_provider 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:18,代碼來源:application.py

示例4: show

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def show(self):
        """Create, update, or re-create the notification, and show it."""
        if self.notification is None:
            self.notification = self.new_notification(
                self.summary, self.to_string(), self.icon)
        elif not self.notification.update(
                self.summary, self.to_string(), self.icon):
            self.notification = self.new_notification(
                self.summary, self.to_string(), self.icon)
        try:
            self.notification.show()
        # pylint: disable=catching-non-exception
        except GLib.Error as exc:
            # If a notification daemon isn't running, show an error once
            if not self.shown_error:
                self.shown_error = True
                LOG.e("Error while showing notification, is a daemon running?",
                      "\n", str(exc)) 
開發者ID:epoptes,項目名稱:epoptes,代碼行數:20,代碼來源:notifications.py

示例5: main

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def main():
    loop = asyncio.get_event_loop()
    glib_loop = GLib.MainLoop()

    try:
        panctl = PanCtl()
    except GLib.Error as e:
        print(f"Error, {e}")
        sys.exit(-1)

    fut = loop.run_in_executor(None, glib_loop.run)

    try:
        loop.run_until_complete(panctl.loop())
    except KeyboardInterrupt:
        pass

    GLib.idle_add(glib_loop.quit)
    loop.run_until_complete(fut) 
開發者ID:matrix-org,項目名稱:pantalaimon,代碼行數:21,代碼來源:panctl.py

示例6: cb_syncthing_qr

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def cb_syncthing_qr(self, io, results, *a):
		"""
		Called when QR code is loaded or operation fails. Image is then
		displayed in dialog, failure is silently ignored.
		"""
		try:
			ok, contents, etag = io.load_contents_finish(results)
			if ok:
				# QR is loaded, save it to temp file and let GTK to handle
				# rest
				tf = tempfile.NamedTemporaryFile("wb", suffix=".png", delete=False)
				tf.write(contents)
				tf.close()
				self["vQR"].set_from_file(tf.name)
				os.unlink(tf.name)
		except GLib.Error as e:
			if e.code in [14, 15]:
				# Unauthorized. Grab CSRF token from daemon and try again
				log.warning("Failed to load image using glib. Retrying with urllib2.")
				self.load_data_urllib()
		except Exception as e:
			log.exception(e)
			return
		finally:
			del io 
開發者ID:kozec,項目名稱:syncthing-gtk,代碼行數:27,代碼來源:iddialog.py

示例7: get_theme_css_provider

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def get_theme_css_provider(self, theme_plugin):
        css_dir = theme_plugin.gtk_preview_dir

        css_name = "theme{}.css".format(
            '20' if Gtk.get_minor_version() >= 20 else ''
        )
        css_path = os.path.join(css_dir, css_name)
        if not os.path.exists(css_path):
            css_path = os.path.join(css_dir, "theme.css")

        css_provider = self.css_providers.theme.get(css_path)
        if css_provider:
            return css_provider
        css_provider = Gtk.CssProvider()
        try:
            css_provider.load_from_path(css_path)
        except GLib.Error as exc:  # pylint: disable=catching-non-exception
            print(exc)
        self.css_providers.theme[css_path] = css_provider
        return css_provider 
開發者ID:themix-project,項目名稱:oomox,代碼行數:22,代碼來源:preview.py

示例8: bytes2pixbuf

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def bytes2pixbuf(data,
                 width=icon_size['width'],
                 height=icon_size['height'],
                 display_name=None):  # type: (bytes, int, int, Optional[str]) -> GdkPixbuf.Pixbuf
    """
    converts raw bytes into a GTK PixBug

    args:
        data (bytes): raw bytes
        width (int): width of image
        height (int): height of images

    returns:
        GtkPixbuf: a GTK Pixbuf

    """
    loader = GdkPixbuf.PixbufLoader()
    loader.set_size(width, height)
    try:
        loader.write(data)
        loader.close()
    except (GLib.Error, TypeError) as e:
        logger.error(u"can't process icon for {}: {}".format(display_name, str(e)))
    else:
        return loader.get_pixbuf() 
開發者ID:eduvpn,項目名稱:python-eduvpn-client,代碼行數:27,代碼來源:util.py

示例9: __enter__

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def __enter__(self):
        self._log.debug("Choosing the first available Bluetooth adapter and "
                        "starting device discovery.")
        self._log.debug("The discovery filter is set to Bluetooth LE only.")
        try:
            self.adapter = find_adapter()
            self.adapter.SetDiscoveryFilter({"Transport": pydbus.Variant("s", "le")})
            self.adapter.StartDiscovery()
        except GLib.Error as ex:
            self._log.exception("Is the bluetooth controller powered on? "
                                "Use `bluetoothctl`, `power on` otherwise.")
            raise ex
        return self 
開發者ID:scipag,項目名稱:btle-sniffer,代碼行數:15,代碼來源:sniffer.py

示例10: image_from_path

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def image_from_path(path, size=48, image=None):
  gimage = Gtk.Image() if image is None else image

  try:
    pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, size, size, True)
    gimage.set_from_pixbuf(pixbuf)
  except GLib.Error:
    pass

  return gimage 
開發者ID:jonian,項目名稱:kickoff-player,代碼行數:12,代碼來源:gtk.py

示例11: error

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def error(self, message):
        message = f"Error: {message} " f"(see help)"
        print(message)
        raise ParseError 
開發者ID:matrix-org,項目名稱:pantalaimon,代碼行數:6,代碼來源:panctl.py

示例12: unverified_devices

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def unverified_devices(self, pan_user, room_id, display_name):
        self.completer.rooms[pan_user].add(room_id)
        print(
            f"Error sending message for user {pan_user}, "
            f"there are unverified devices in the room {display_name} "
            f"({room_id}).\nUse the send-anyways or cancel-sending commands "
            f"to ignore the devices or cancel the sending."
        ) 
開發者ID:matrix-org,項目名稱:pantalaimon,代碼行數:10,代碼來源:panctl.py

示例13: load_pixbuf

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def load_pixbuf(theme, icon_name):
    pixbuf = None
    try:
        icon_info = theme.lookup_icon(icon_name, 64, 0)
        if not icon_info.is_symbolic():
            icon_path = icon_info.get_filename()
            if not path.islink(icon_path) and icon_name.startswith("folder"):
                pixbuf = icon_info.load_icon()
    except GLib.Error:
        pixbuf = theme.load_icon("image-missing", 64, 0)
    if pixbuf and (pixbuf.props.width != 64 or pixbuf.props.height != 64):
        pixbuf = pixbuf.scale_simple(64, 64,
                                     GdkPixbuf.InterpType.BILINEAR)
    return pixbuf 
開發者ID:bilelmoussaoui,項目名稱:nautilus-folder-icons,代碼行數:16,代碼來源:utils.py

示例14: load_icons

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def load_icons(self):
        """ Set the icon list for both windows.
        """
        try:
            icon_list = [GdkPixbuf.Pixbuf.new_from_file(i) for i in util.list_icons()]
        except Exception:
            logger.exception('Error loading icons')
            return

        self.c_win.set_icon_list(icon_list)
        self.p_win.set_icon_list(icon_list) 
開發者ID:Cimbali,項目名稱:pympress,代碼行數:13,代碼來源:ui.py

示例15: menu_about

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import Error [as 別名]
def menu_about(self, *args):
        """ Display the "About pympress" dialog.

        Handles clicks on the "about" menu.
        """
        about = Gtk.AboutDialog(transient_for = self.p_win)
        pympress = util.get_pympress_meta()
        about.set_program_name('pympress')
        about.set_version(pympress['version'])
        about.set_copyright(_('Contributors:') + '\n' + pympress['contributors'])
        about.set_comments(_('pympress is a little PDF reader written in Python ' +
                             'using Poppler for PDF rendering and GTK for the GUI.\n') +
                           _('Some preferences are saved in ') + self.config.path_to_config() + '\n' +
                           _('Resources are loaded from ') + os.path.dirname(util.get_locale_dir()) + '\n' +
                           _('The log is written to ') + util.get_log_path() + '\n\n' +
                           _('Media support uses {}.').format(self.medias.backend_version()) + '\n' +
                           _('Python version {}').format(sys.version))
        about.set_website('https://github.com/Cimbali/pympress')
        try:
            about.set_logo(GdkPixbuf.Pixbuf.new_from_file(util.get_icon_path('pympress-128.png')))
        except Exception:
            logger.exception(_('Error loading icon for about window'))
        about.run()
        about.destroy()


    ##############################################################################
    ############################ Document manangement ############################
    ############################################################################## 
開發者ID:Cimbali,項目名稱:pympress,代碼行數:31,代碼來源:ui.py


注:本文中的gi.repository.GLib.Error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。