本文整理汇总了Python中gi.repository.Gtk方法的典型用法代码示例。如果您正苦于以下问题:Python repository.Gtk方法的具体用法?Python repository.Gtk怎么用?Python repository.Gtk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository
的用法示例。
在下文中一共展示了repository.Gtk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_pixbuf
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [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
示例2: get_icon_by_name
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [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_gi_clipboard
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [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
示例4: async_call
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def async_call(func, *args, callback=None):
'''Call `func` in background thread, and then call `callback` in Gtk main thread.
If error occurs in `func`, error will keep the traceback and passed to
`callback` as second parameter. Always check `error` is not None.
'''
def do_call():
result = None
error = None
try:
result = func(*args)
except Exception:
error = traceback.format_exc()
logger.error(error)
if callback:
GLib.idle_add(callback, result, error)
thread = threading.Thread(target=do_call)
thread.daemon = True
thread.start()
示例5: __init__
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [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()
示例6: popup_menu
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def popup_menu(self, icon, button, time):
"""Method to display a popup menu whenever user clicked to the system tray icon.
Args:
icon: Icon instance.
button: Button instance.
time: Timestamp.
"""
self.menu = self.Gtk.Menu()
menuitemDragonfire = self.Gtk.MenuItem(label="Dragonfire")
self.menu.append(menuitemDragonfire)
menuitemDragonfire.set_sensitive(False)
menuitemSeperator = self.Gtk.SeparatorMenuItem()
self.menu.append(menuitemSeperator)
menuitemExit = self.Gtk.MenuItem(label="Exit")
menuitemExit.connect_object("activate", self.exit, "Exit")
self.menu.append(menuitemExit)
self.menu.show_all()
self.menu.popup(None, None, None, None, button, time)
示例7: clear
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def clear():
"""Clear the clipboard."""
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.clear()
示例8: set
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def set(string):
"""
Copy a string to the clipboard.
:param string: the string to copy.
:type string: str
"""
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.set_text(string, -1)
示例9: __init__
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def __init__(self):
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
示例10: __init__
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def __init__(self):
builder = Gtk.Builder.new_from_resource(UI_PATH + 'headerbar.ui')
self.header_bar = builder.get_object('header_bar')
self.menu_button = builder.get_object('menu_button')
self.select_button = builder.get_object('select_button')
self.pencil_button = builder.get_object('pencil_button')
builder.add_from_resource(UI_PATH + 'menu.ui')
self.window_menu = builder.get_object('window-menu')
self.menu_button.set_menu_model(self.window_menu)
示例11: __init__
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def __init__(self, useGtk=False):
_gtk = None
if useGtk is True:
from gi.repository import Gtk as _gtk
_glibbase.GlibReactorBase.__init__(self, GLib, _gtk, useGtk=useGtk)
示例12: configure_gtk
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def configure_gtk(self):
theme_path = self.get_theme_path()
if not theme_path:
raise ValueError("GTK theme 'RAFCON' does not exist")
theme_name = "RAFCON"
dark_theme = self.get_config_value('THEME_DARK_VARIANT', True)
# GTK_DATA_PREFIX must point to a path that contains share/themes/THEME_NAME
gtk_data_prefix = os.path.dirname(os.path.dirname(os.path.dirname(theme_path)))
os.environ['GTK_DATA_PREFIX'] = gtk_data_prefix
os.environ['GTK_THEME'] = "{}{}".format(theme_name, ":dark" if dark_theme else "")
# The env vars GTK_DATA_PREFIX and GTK_THEME must be set before Gtk is imported first to prevent GTK warnings
# from other themes
try:
from gi.repository import Gtk
settings = Gtk.Settings.get_default()
if settings:
settings.set_property("gtk-enable-animations", True)
settings.set_property("gtk-theme-name", theme_name)
settings.set_property("gtk-application-prefer-dark-theme", dark_theme)
Gtk.Window.set_default_icon_name("rafcon" if dark_theme else "rafcon-light")
except ImportError:
pass
示例13: test_clipboard
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def test_clipboard(self):
"""Copy image name to clipboard."""
def compare_text(clipboard, text, expected_text):
self.compare_result = False
self.compare_result = text == expected_text
name = self.vimiv.get_pos(True)
basename = os.path.basename(name)
abspath = os.path.abspath(name)
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
primary = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
# Copy basename and abspath to clipboard
self.vimiv["clipboard"].copy_name(False)
# Check if the info message is displayed correctly
self.check_statusbar("INFO: Copied " + basename + " to clipboard")
clipboard.request_text(compare_text, basename)
self.assertTrue(self.compare_result)
self.vimiv["clipboard"].copy_name(True)
clipboard.request_text(compare_text, abspath)
self.assertTrue(self.compare_result)
# Toggle to primary and copy basename
self.run_command("set copy_to_primary!")
self.vimiv["clipboard"].copy_name(False)
primary.request_text(compare_text, basename)
self.assertTrue(self.compare_result)
# Toggle back to clipboard and copy basename
self.run_command("set copy_to_primary!")
self.vimiv["clipboard"].copy_name(False)
clipboard.request_text(compare_text, basename)
self.assertTrue(self.compare_result)
示例14: get
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def get(icon: str) -> str:
"""
:param icon:
:return: icon name and path
"""
if icon is None:
icon = not_found(icon)
EXTENSIONS = (".png", ".svg")
if icon.endswith(EXTENSIONS):
# if image has full icon path return icon.
if icon.startswith("/"):
return icon
# if image has icon name and extension, but no path.
else:
for ext in EXTENSIONS:
if icon.endswith(ext):
icon = icon.replace(ext, '')
icon_theme = Gtk.IconTheme.get_default()
if not icon_theme.has_icon(icon):
# check for icon in pixmaps directory.
pixmaps = f"/usr/share/pixmaps/{icon}"
for ext in EXTENSIONS:
if os.path.isfile(f"{pixmaps}{ext}"):
return f"{pixmaps}{ext}"
SIZES = (64, 48, 32, 24)
for size in SIZES:
icon_name = icon_theme.lookup_icon(icon, size, 0)
if icon_name:
return icon_name.get_filename()
icon = not_found(icon)
return icon
示例15: __init__
# 需要导入模块: from gi import repository [as 别名]
# 或者: from gi.repository import Gtk [as 别名]
def __init__(self):
self._clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self._selection = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)