本文整理汇总了Python中gi.repository方法的典型用法代码示例。如果您正苦于以下问题:Python gi.repository方法的具体用法?Python gi.repository怎么用?Python gi.repository使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi
的用法示例。
在下文中一共展示了gi.repository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_quartz
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def is_quartz():
"""
Tests to see if Python is currently running with gtk and
windowing system is Mac OS-X's "quartz".
"""
if mac():
try:
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
except ImportError:
return False
return Gdk.Display.get_default().__class__.__name__.endswith("QuartzDisplay")
return False
示例2: get_icon_by_name
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def get_icon_by_name(name, size=256):
try:
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
except:
raise MissingDependencies(
'Unable to lookup system icons!',
['gir1.2-gtk-3.0']
)
icon_theme = Gtk.IconTheme.get_default()
icon = icon_theme.lookup_icon(name, size, 0)
if icon:
file_path = icon.get_filename()
_type = get_type_by_filepath(file_path)
return _type(file_path)
else:
raise IconNotFound(name)
示例3: __init__
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def __init__(self, *args, **kwargs):
StatusIcon.__init__(self, *args, **kwargs)
try:
import gi
gi.require_version('AppIndicator3', '0.1')
from gi.repository import AppIndicator3 as appindicator
self._status_active = appindicator.IndicatorStatus.ACTIVE
self._status_passive = appindicator.IndicatorStatus.PASSIVE
except (ImportError, ValueError):
raise NotImplementedError
category = appindicator.IndicatorCategory.APPLICATION_STATUS
# Whatever icon is set here will be used as a tooltip icon during the entire time to icon is shown
self._tray = appindicator.Indicator.new("syncthing-gtk", self._get_icon(), category)
self._tray.set_menu(self._get_popupmenu())
self._tray.set_title(self.TRAY_TITLE)
示例4: __init__
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def __init__(self, autokeyApp):
Notify.init("AutoKey")
# Used to rate-limit error notifications to 1 per second. Without this, two notifications per second cause the
# following exception, which in turn completely locks up the GUI:
# gi.repository.GLib.GError: g-io-error-quark:
# GDBus.Error:org.freedesktop.Notifications.Error.ExcessNotificationGeneration:
# Created too many similar notifications in quick succession (36)
self.last_notification_timestamp = datetime.datetime.now()
self.app = autokeyApp
self.configManager = autokeyApp.service.configManager
self.indicator = AppIndicator3.Indicator.new("AutoKey", cm.ConfigManager.SETTINGS[cm.NOTIFICATION_ICON],
AppIndicator3.IndicatorCategory.APPLICATION_STATUS)
self.indicator.set_attention_icon(common.ICON_FILE_NOTIFICATION_ERROR)
self.update_visible_status()
self.rebuild_menu()
示例5: init_gi_clipboard
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def init_gi_clipboard():
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
cb = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
def copy_gi(text):
cb.set_text(text, -1)
cb.store()
def paste_gi():
clipboardContents = cb.wait_for_text()
# for python 2, returns None if the clipboard is blank.
if clipboardContents is None:
return ''
else:
return clipboardContents
return copy_gi, paste_gi
示例6: __init__
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def __init__(self):
"""Initialization method of :class:`dragonfire.stray.SystemTrayIcon` class.
"""
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
self.Gtk = Gtk
self.icon = self.Gtk.StatusIcon()
self.icon.set_title("Dragonfire")
if os.path.isfile(TRAY_ICON):
self.icon.set_from_file(TRAY_ICON)
else:
self.icon.set_from_file(DEVELOPMENT_DIR + TRAY_ICON_ALT)
self.icon.connect('popup-menu', self.popup_menu)
self.Gtk.main()
示例7: notify
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [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
示例8: __init__
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def __init__(self, path, cached=True, size=256):
try:
gi.require_version('Rsvg', '2.0')
from gi.repository import Rsvg
except:
raise MissingDependencies(
'Unable to convert SVG image to PNG!', ['gir1.2-rsvg-2.0']
)
try:
import cairo
except:
raise MissingDependencies(
'Unable to convert SVG image to PNG!', ['cairo']
)
tmp_file = tempfile.NamedTemporaryFile()
image_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, size, size)
rsvg_handle = Rsvg.Handle.new_from_file(path)
context = cairo.Context(image_surface)
context.scale(
float(size) / rsvg_handle.props.height,
float(size) / rsvg_handle.props.width
)
rsvg_handle.render_cairo(context)
image_surface.write_to_png(tmp_file.name)
BaseImage.__init__(self, tmp_file.name, cached=True)
示例9: has_display
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def has_display():
"""
Tests to see if Python is currently running with gtk
"""
# FIXME: currently, Gtk.init_check() requires all strings
# in argv, and we might have unicode.
temp, sys.argv = sys.argv, sys.argv[:1]
try:
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
except ImportError:
return False
try:
test = Gtk.init_check(temp) and \
Gdk.Display.get_default()
sys.argv = temp
return bool(test)
except:
sys.argv = temp
return False
# A couple of places add menu accelerators using <alt>, which doesn't
# work with Gtk-quartz. <Meta> is the usually correct replacement, but
# in one case the key is a number, and <meta>number is used by Spaces
# (a mac feature), so we'll use control instead.
示例10: create_about_tab
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def create_about_tab(self):
from gi.repository import Pango
page = Gtk.VBox()
page.show()
tv = Gtk.TextView()
tv.set_editable(False)
tv.set_cursor_visible(False)
tv.modify_font(Pango.FontDescription(MONOSPACE_FONT))
scroll = Gtk.ScrolledWindow()
scroll.add(tv)
page.pack_start(scroll, True, True, 0)
self.info = tv.get_buffer()
self.add_tab(page, 'Wall')
示例11: assert_valid_output_file
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def assert_valid_output_file(output_video_location):
'''
Given a file, validates it is a video (mp4) file
'''
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib
Gst.init(None)
mainloop = GLib.MainLoop()
# We create a pipeline so that we can read the file and check it:
pipeline = Gst.ElementFactory.make("playbin")
pipeline.set_property('uri','file://'+output_video_location)
playsink = pipeline.get_by_name('playsink')
playsink.set_property('video-sink', Gst.ElementFactory.make('fakesink'))
pipeline.set_state(Gst.State.PAUSED)
def after_a_second():
assert pipeline.get_state(0).state == Gst.State.PAUSED
element = pipeline.get_by_name('inputselector1')
caps = element.get_static_pad('src').get_current_caps()
assert caps.to_string() == 'audio/x-raw, format=(string)F32LE, layout=(string)interleaved, rate=(int)48000, channels=(int)2, channel-mask=(bitmask)0x0000000000000003'
element = pipeline.get_by_name('inputselector0')
caps = element.get_static_pad('src').get_current_caps()
assert caps.to_string() == 'video/x-raw, format=(string)NV12, width=(int)640, height=(int)360, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)jpeg, colorimetry=(string)bt601, framerate=(fraction)30/1'
pipeline.set_state(Gst.State.NULL)
mainloop.quit()
GLib.timeout_add(1000, after_a_second)
mainloop.run()
示例12: check11_osmgpsmap
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def check11_osmgpsmap(self):
'''osmgpsmap'''
# Start check
OSMGPSMAP_MIN_VERSION = (1, 0)
OSMGPSMAP_FOUND = False
try:
from gi import Repository
repository = Repository.get_default()
if repository.enumerate_versions("OsmGpsMap"):
gi.require_version('OsmGpsMap', '1.0')
from gi.repository import OsmGpsMap as osmgpsmap
try:
osmgpsmap_str = osmgpsmap._version
OSMGPSMAP_FOUND = True
except Exception: # any failure to 'get' the version
osmgpsmap_str = 'unknown version'
else:
osmgpsmap_str = 'not found'
except ImportError:
osmgpsmap_str = 'not found'
if OSMGPSMAP_FOUND:
result = ("* osmgpsmap " + osmgpsmap_str + " (Success version " +
verstr(OSMGPSMAP_MIN_VERSION) +
" or greater installed.)")
else:
result = ("* osmgpsmap " + osmgpsmap_str + " (Requires version " +
verstr(OSMGPSMAP_MIN_VERSION) + " or greater)")
# End check
self.append_text(result)
示例13: check19_geocodeglib
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def check19_geocodeglib(self):
'''geocodeglib
# added to gramps master v5.1.0
#TODO: add to gramps-v check
https://github.com/gramps-project/gramps/blob/maintenance/gramps50/gramps/plugins/lib/maps/placeselection.py
'''
self.append_text("\n")
# Start check
geocodeglib_min_ver = "1.0"
try:
gi.require_version('GeocodeGlib', '1.0')
from gi.repository import GeocodeGlib
geocodeglib_ver = str(GeocodeGlib._version)
GEOCODEGLIB = True
except Exception:
geocodeglib_ver = "Not found"
GEOCODEGLIB = False
if GEOCODEGLIB:
result = ("* geocodeglib " + geocodeglib_ver +
" (Success version " + geocodeglib_min_ver +
" or greater installed.)")
else:
result = ("* geocodeglib " + geocodeglib_ver +
" (Requires version " + geocodeglib_min_ver +
" or greater installed.)")
# End check
self.append_text(result)
示例14: check22_graphview
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def check22_graphview(self):
'''
Graph View - Requires: PyGoocanvas and Goocanvas and
graphviz (python-pygoocanvas, gir1.2-goocanvas-2.0)
'''
self.append_text("\n")
self.render_text("""<b>02. <a href="https://gramps-project.org/wiki"""
"""/index.php?title=Graph_View">"""
"""Addon:Graph View</a> :</b> """)
# Start check
# check for GooCanvas
try:
try:
gi.require_version('GooCanvas', '2.0')
except Exception:
print("Why, when same code works in Graphview")
from gi.repository import GooCanvas
goocanvas_ver = str(GooCanvas._version)
#print("GooCanvas version:" + goocanvas_ver)
except ImportError:
goocanvas_ver = "Not installed"
result = "(GooCanvas:" + goocanvas_ver + ")(PyGoocanvas: TBD?)"
# End check
self.append_text(result)
self.append_text("(")
self.check12_graphviz()
self.append_text(")")
示例15: main
# 需要导入模块: import gi [as 别名]
# 或者: from gi import repository [as 别名]
def main():
"""Start volctl."""
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from volctl.app import VolctlApp
VolctlApp()
Gtk.main()