def get_file_icon(path, icon_size): """ :param ~ulauncher.util.Path.Path path: :param int icon_size: """ try: if path.is_dir(): special_dir = SPECIAL_DIRS.get(str(path)) if special_dir: return get_themed_icon_by_name(special_dir, icon_size) return get_themed_icon_by_name('folder', icon_size) ext = path.get_ext() if ext in ULAUNCHER_FILE_ICON_DB: return load_image(get_data_file('media', 'fileicons', '%s.png' % ext), icon_size) freedesktop = FREEDESKTOP_STANDARD.get(ext) if freedesktop: return get_themed_icon_by_name(freedesktop, icon_size) if path.is_exe(): return load_image(get_data_file('media', 'executable-icon.png'), icon_size) except Exception as e: logger.warning('Icon not found %s. %s: %s' % (path, type(e).__name__, e.message)) return load_image(get_data_file('media', 'unknown-file-icon.png'), icon_size)
def get_file_icon(path, icon_size): """ :param Path path: :param int icon_size: """ # TODO add fallbacks for folders # handle symbolic links /usr/share/icons/Humanity/emblems/48/emblem-symbolic-link.svg try: if path.is_dir(): special_dir = SPECIAL_DIRS.get(str(path)) if special_dir: return get_themed_icon_by_name(special_dir, icon_size) return get_themed_icon_by_name('folder', icon_size) ext = path.get_ext() if ext in ULAUNCHER_FILE_ICON_DB: return load_image( get_data_file('media', 'fileicons', '%s.png' % ext), icon_size) freedesktop = FREEDESKTOP_STANDARD.get(ext) if freedesktop: return get_themed_icon_by_name(freedesktop, icon_size) if path.is_exe(): return load_image(get_data_file('media', 'executable-icon.png'), icon_size) except Exception as e: logger.warning('Icon not found %s. %s: %s' % (path, type(e).__name__, e.message)) return load_image(get_data_file('media', 'unknown-file-icon.png'), icon_size)
def get_file_icon(path, icon_size): """ :param ~ulauncher.utils.Path.Path path: :param int icon_size: """ # pylint: disable=broad-except try: if path.is_dir(): special_dir = SPECIAL_DIRS.get(str(path)) if special_dir: return get_themed_icon_by_name(special_dir, icon_size) return get_themed_icon_by_name('folder', icon_size) ext = path.get_ext() if ext in ULAUNCHER_FILE_ICON_DB: return load_image( get_data_file('media', 'fileicons', '%s.png' % ext), icon_size) freedesktop = FREEDESKTOP_STANDARD.get(ext) if freedesktop: return get_themed_icon_by_name(freedesktop, icon_size) if path.is_exe(): return load_image(get_data_file('media', 'executable-icon.png'), icon_size) except Exception as e: logger.warning('Icon not found %s. %s: %s', path, type(e).__name__, e) return load_image(get_data_file('media', 'unknown-file-icon.png'), icon_size)
def finish_initializing(self, builder): """Called while initializing this instance in __new__ finish_initalizing should be called after parsing the ui definition and creating a PreferencesDialog object with it in order to finish initializing the start of the new PerferencesUlauncherDialog instance. Put your initialization code in here and leave __init__ undefined. """ # Get a reference to the builder and set up the signals. self.builder = builder self.ui = builder.get_ui(self, True) # unnecessary action area can be removed only manually, like this self.ui['dialog_action_area'].destroy() self.settings = Settings.get_instance() self._init_webview() self.init_styles(get_data_file('styles', 'preferences.css')) self.autostart_pref = AutostartPreference() self.hotkey_dialog = HotkeyDialog() self.hotkey_dialog.connect('hotkey-set', self.on_hotkey_set) self.show_all()
def get_app_icon_pixbuf(icon, icon_size, icon_name): """ :param Gio.Icon icon: :param int icon_size: :param str icon_name: :rtype: :class:`GtkPixbuf` """ pixbuf_icon = None # pylint: disable=broad-except if isinstance(icon, Gio.ThemedIcon): try: icon_name = icon.get_names()[0] if not icon_name: return None pixbuf_icon = get_themed_icon_by_name(icon_name, icon_size) except Exception as e: logger.info('Could not load icon for %s. E: %s', icon_name, e) elif isinstance(icon, Gio.FileIcon): pixbuf_icon = load_image(icon.get_file().get_path(), icon_size) elif isinstance(icon, str): pixbuf_icon = load_image(icon, icon_size) if not pixbuf_icon: pixbuf_icon = load_image(get_data_file('media', 'executable-icon.png'), icon_size) return pixbuf_icon
def get_app_icon_pixbuf(app, icon_size): """ :param Gio.DesktopAppInfo app: :param int icon_size: :rtype: :class:`GtkPixbuf` """ icon = app.get_icon() pixbuf_icon = None if isinstance(icon, Gio.ThemedIcon): try: icon_name = icon.get_names()[0] if not icon_name: return None pixbuf_icon = get_themed_icon_by_name(icon_name, icon_size) except Exception as e: logger.info('Could not load icon for %s. E: %s' % (app.get_string('Icon'), e)) elif isinstance(icon, Gio.FileIcon): pixbuf_icon = load_image(icon.get_file().get_path(), icon_size) elif isinstance(icon, str): pixbuf_icon = load_image(icon, icon_size) if not pixbuf_icon: pixbuf_icon = load_image(get_data_file('media', 'executable-icon.png'), icon_size) return pixbuf_icon
def finish_initializing(self, builder): """Called while initializing this instance in __new__ finish_initalizing should be called after parsing the ui definition and creating a PreferencesDialog object with it in order to finish initializing the start of the new PerferencesUlauncherDialog instance. Put your initialization code in here and leave __init__ undefined. """ # Get a reference to the builder and set up the signals. self.builder = builder self.ui = builder.get_ui(self, True) # unnecessary action area can be removed only manually, like this self.ui['dialog_action_area'].destroy() self.settings = Settings.get_instance() self._init_webview() self.init_styles(get_data_file('styles', 'preferences.css')) self._handle_no_window_shadow_option(self.ui['window_wrapper']) self.autostart_pref = AutostartPreference() self.hotkey_dialog = HotkeyDialog() self.hotkey_dialog.connect('hotkey-set', self.on_hotkey_set) self.show_all()
def get_app_icon_pixbuf(app, icon_size): """ :param Gio.DesktopAppInfo app: :param int icon_size: return PixBuf """ icon = app.get_icon() pixbuf_icon = None if isinstance(icon, Gio.ThemedIcon): try: icon_name = icon.get_names()[0] pixbuf_icon = get_themed_icon_by_name(icon_name, icon_size) except Exception as e: logger.warn('Could not load icon for %s. E: %s' % (app.get_string('Icon'), e)) elif isinstance(icon, Gio.FileIcon): pixbuf_icon = load_image(icon.get_file().get_path(), icon_size) elif isinstance(icon, str): pixbuf_icon = load_image(icon, icon_size) if not pixbuf_icon: pixbuf_icon = load_image(get_data_file('media', 'executable-icon.png'), icon_size) return pixbuf_icon
def init_styles(self): self.provider = Gtk.CssProvider() self.provider.load_from_path(get_data_file('ui', 'ulauncher.css')) self.apply_css(self, self.provider) self.screen = self.get_screen() self.visual = self.screen.get_rgba_visual() if self.visual is not None and self.screen.is_composited(): self.set_visual(self.visual)
def _render_prefs_icon(self): scale_factor = get_monitor_scale_factor() prefs_pixbuf = load_image(get_data_file('media', 'gear.svg'), 16 * scale_factor) surface = Gdk.cairo_surface_create_from_pixbuf(prefs_pixbuf, scale_factor, self.get_window()) prefs_image = Gtk.Image.new_from_surface(surface) self.prefs_btn.set_image(prefs_image)
def create_item(result_item, index, query): glade_filename = get_data_file('ui', '%s.ui' % result_item.UI_FILE) if not os.path.exists(glade_filename): glade_filename = None builder = Gtk.Builder() builder.set_translation_domain('ulauncher') builder.add_from_file(glade_filename) item_frame = builder.get_object('item-frame') item_frame.initialize(builder, result_item, index, query) return item_frame
def new_from_file(cls, builder_file_name): """Return a fully-instantiated Gtk.Builder instance from specified ui file :param builder_file_name: The name of the builder file, without extension. Assumed to be in the 'ui' directory under the data path. """ # Look for the ui file that describes the user interface. ui_filename = get_data_file('ui', '%s.ui' % (builder_file_name,)) if not os.path.exists(ui_filename): ui_filename = None builder = cls() builder.set_translation_domain('ulauncher') builder.add_from_file(ui_filename) return builder
def new_from_file(cls, builder_file_name): """Return a fully-instantiated Gtk.Builder instance from specified ui file :param builder_file_name: The name of the builder file, without extension. Assumed to be in the 'ui' directory under the data path. """ # Look for the ui file that describes the user interface. ui_filename = get_data_file('ui', '%s.ui' % (builder_file_name,)) if not os.path.exists(ui_filename): ui_filename = None builder = cls() builder.set_translation_domain('ulauncher') builder.add_from_file(ui_filename) return builder
def create_item_widgets(items, query): results = [] for index, result_item in enumerate(items): glade_filename = get_data_file('ui', '%s.ui' % result_item.UI_FILE) if not os.path.exists(glade_filename): glade_filename = None builder = Gtk.Builder() builder.set_translation_domain('ulauncher') builder.add_from_file(glade_filename) item_frame = builder.get_object('item-frame') item_frame.initialize(builder, result_item, index, query) results.append(item_frame) return results
def get_icon(self): return load_image(get_data_file('media/calculator-icon.png'), self.ICON_SIZE)
def _load_prefs_html(self, page=''): uri = "file://%s#/%s" % (get_data_file('preferences', 'dist', 'index.html'), page) self.webview.load_uri(uri)
def __init__(self): super(StackoverflowResultItem, self).__init__('so', 'Stack Overflow', "Search Stack Overflow for '{query}'", 'http://stackoverflow.com/search?q=%s', get_data_file('media/stackoverflow-icon.svg'))
def __init__(self): super(GoogleResultItem, self).__init__('g', 'Google', "Search Google for '{query}'", 'https://google.com/search?q=%s', get_data_file('media/google-search-icon.png'))
def _read_theme(name): """Returns dict from data/ui/css/themes/<name>/theme.json""" filename = get_data_file('styles', 'themes', name, 'theme.json') with open(filename, 'r') as f: return json.load(f)
def get_icon(self): return load_image(get_data_file('media/calculator-icon.png'), self.ICON_SIZE)
def get_icon(self): if self.icon: return load_image(self.icon, self.get_icon_size()) return load_image(get_data_file('media', 'executable-icon.png'), self.get_icon_size())
def _load_prefs_html(self, page=''): uri = "file://%s#/%s" % (get_data_file('preferences', 'dist', 'index.html'), page) self.webview.load_uri(uri)
def __init__(self): super(WikipediaResultItem, self).__init__( 'wiki', 'Wikipedia', "Search Wikipedia for '{query}'", 'http://en.wikipedia.org/wiki/Special:Search?search=%s', get_data_file('media/wikipedia-icon.png'))
def get_icon(self): if self.icon: return load_image(self.icon, self.ICON_SIZE) return load_image(get_data_file('media', 'executable-icon.png'), self.ICON_SIZE)
def get_icon(self): return load_image(get_data_file('media/calculator-icon.png'), self.get_icon_size())