当前位置: 首页>>代码示例>>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;未经允许,请勿转载。