Python gi.repository.Gtk() Examples
The following are 21
code examples of gi.repository.Gtk().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gi.repository
, or try the search function
.
Example #1
Source File: stray.py From Dragonfire with MIT License | 6 votes |
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)
Example #2
Source File: stray.py From Dragonfire with MIT License | 6 votes |
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()
Example #3
Source File: images.py From pulseaudio-dlna with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: gutil.py From bcloud with GNU General Public License v3.0 | 6 votes |
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()
Example #5
Source File: Pyperclip.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: utils.py From Authenticator with GNU General Public License v2.0 | 6 votes |
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
Example #7
Source File: gireactor.py From learn_python3_spider with MIT License | 5 votes |
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)
Example #8
Source File: stray.py From Dragonfire with MIT License | 5 votes |
def exit(self, data=None): """Method to exit the system tray icon. Keyword Args: data : *Unknown* """ self.Gtk.main_quit() global global_event_holder global_event_holder.set()
Example #9
Source File: DesktopManage.py From kano-apps with GNU General Public License v2.0 | 5 votes |
def _create_kdesk_icon(app): icon_theme = Gtk.IconTheme.get_default() icon_info = icon_theme.lookup_icon(app["icon"], 66, 0) icon = app["icon"] if icon_info is not None: icon = icon_info.get_filename() cmd = app["launch_command"] if type(app["launch_command"]) is dict: args = map(lambda s: "\"{}\"".format(s) if s.find(" ") >= 0 else s, app["launch_command"]["args"]) cmd = app["launch_command"]["cmd"] if len(args) > 0: cmd += " " + " ".join(args) kdesk_entry = 'table Icon\n' kdesk_entry += ' Caption:\n' kdesk_entry += ' AppID:\n' kdesk_entry += ' Command: {}\n'.format(cmd) kdesk_entry += ' Singleton: true\n' kdesk_entry += ' Icon: {}\n'.format(icon) kdesk_entry += ' IconHover: {}\n'.format(media_dir() + "icons/generic-hover.png") kdesk_entry += ' HoverXOffset: 0\n' kdesk_entry += ' Relative-To: grid\n' kdesk_entry += ' X: 0\n' kdesk_entry += ' Y: 0\n' kdesk_entry += 'end\n' kdesk_dir = os.path.expanduser(KDESK_DIR) if not os.path.exists(kdesk_dir): os.makedirs(kdesk_dir) icon_f = open(_get_kdesk_icon_path(app), 'w') icon_f.write(kdesk_entry) icon_f.close()
Example #10
Source File: Media.py From kano-apps with GNU General Public License v2.0 | 5 votes |
def get_app_icon(loc, size=APP_ICON_SIZE): try: pb = GdkPixbuf.Pixbuf.new_from_file_at_size(loc, size, size) icon = Gtk.Image.new_from_pixbuf(pb) except: icon = Gtk.Image.new_from_icon_name(loc, -1) icon.set_pixel_size(size) return icon
Example #11
Source File: interface.py From autokey with GNU General Public License v3.0 | 5 votes |
def __init__(self): self._clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) self._selection = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
Example #12
Source File: Icons.py From Jadesktop with GNU General Public License v3.0 | 5 votes |
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
Example #13
Source File: gireactor.py From learn_python3_spider with MIT License | 5 votes |
def __init__(self, useGtk=False): _gtk = None if useGtk is True: from gi.repository import Gtk as _gtk _glibbase.PortableGlibReactorBase.__init__(self, GLib, _gtk, useGtk=useGtk)
Example #14
Source File: fileactions_test.py From vimiv with MIT License | 5 votes |
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)
Example #15
Source File: config.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
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
Example #16
Source File: gireactor.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def __init__(self, useGtk=False): _gtk = None if useGtk is True: from gi.repository import Gtk as _gtk _glibbase.PortableGlibReactorBase.__init__(self, GLib, _gtk, useGtk=useGtk)
Example #17
Source File: gireactor.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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)
Example #18
Source File: headerbar.py From ImEditor with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: nautilus_copy_path.py From nautilus-copy-path with MIT License | 5 votes |
def __init__(self): self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
Example #20
Source File: clipboard.py From Authenticator with GNU General Public License v2.0 | 5 votes |
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)
Example #21
Source File: clipboard.py From Authenticator with GNU General Public License v2.0 | 5 votes |
def clear(): """Clear the clipboard.""" clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.clear()