def on_tag_update(self, e, track, tag): if track.get_tag_raw('fav')[0] == "1": self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON)) else: self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON))
def __init__(self): self.executor = DBusExecutor() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_border_width(16) self.window.set_resizable(False) self.window.connect("destroy", self.executor.cancel) vbox = gtk.VBox(False, 16) self.window.add(vbox) icon_size = gtk.ICON_SIZE_DND logout_btn = BiggerButton('_Logout') image = gtk.image_new_from_icon_name('gnome-session-logout', icon_size) logout_btn.set_property('image', image) logout_btn.connect('clicked', self.executor.logout) vbox.pack_start(logout_btn, True, True, 0) restart_btn = BiggerButton('_Restart') image = gtk.image_new_from_icon_name('gnome-session-reboot', icon_size) restart_btn.set_property('image', image) restart_btn.connect('clicked', self.executor.restart) vbox.pack_start(restart_btn, True, True, 0) shutdown_btn = BiggerButton('Shut_down') image = gtk.image_new_from_icon_name('gnome-session-halt', icon_size) shutdown_btn.set_property('image', image) shutdown_btn.connect('clicked', self.executor.shutdown) vbox.pack_start(shutdown_btn, True, True, 0) suspend_btn = BiggerButton('_Suspend') image = gtk.image_new_from_icon_name('gnome-session-suspend', icon_size) suspend_btn.set_property('image', image) suspend_btn.connect('clicked', self.executor.suspend) vbox.pack_start(suspend_btn, True, True, 0) hibernate_btn = BiggerButton('_Hibernate') image = gtk.image_new_from_icon_name('gnome-session-hibernate', icon_size) hibernate_btn.set_property('image', image) hibernate_btn.connect('clicked', self.executor.hibernate) vbox.pack_start(hibernate_btn, True, True, 0) sep = gtk.HSeparator() vbox.pack_start(sep, True, True, 0) cancel_btn = BiggerButton('_Abort') image = gtk.image_new_from_stock(gtk.STOCK_CANCEL, icon_size) cancel_btn.set_property('image', image) cancel_btn.connect('clicked', self.executor.cancel) vbox.pack_start(cancel_btn, True, True, 0) self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.set_skip_taskbar_hint(True) self.window.stick() self.window.set_decorated(False) self.window.show_all()
def __init__(self, plugin, parent, expander=True, onlyclear=False): # Alias. self.plugin = plugin # Force to make dir if not exists. main.presets.get_plugin_path(plugin.name) # Interface display. self.box = gtk.HBox() if expander: self.expander = gtk.Expander(_('Presets')) self.expander.add(self.box) gutils.separator(parent) parent.pack_start(self.expander, False) else: gutils.separator(parent) parent.pack_start(self.box, False) # Restore defaults button. default = gtk.Button() default.set_image(gtk.image_new_from_icon_name('gtk-clear', 1)) default.set_relief(gtk.RELIEF_NONE) default.set_tooltip_text(_('Restore default values')) default.connect('clicked', lambda x: self.load_default()) self.box.pack_end(default, False) if onlyclear: return # Manage presets button. manage = gtk.Button() manage.set_image(gtk.image_new_from_icon_name('gtk-edit', 1)) manage.set_relief(gtk.RELIEF_NONE) manage.set_tooltip_text(_('Manage presets')) manager = main.plugins.childs['preset-manager'] manage.connect('clicked',lambda x: manager.callback(plugin.name)) self.box.pack_end(manage, False) # Save preset button. save = gtk.Button() save.set_image(gtk.image_new_from_icon_name('gtk-save', 1)) save.set_relief(gtk.RELIEF_NONE) save.set_tooltip_text(_('Save the current values as a new preset')) save.connect('clicked', lambda x: self.save()) self.box.pack_end(save, False) # Available presets menu-button. load = gtk.Button() load.set_image(gtk.image_new_from_icon_name('gtk-index', 1)) load.set_relief(gtk.RELIEF_NONE) load.set_tooltip_text(_('Show available presets')) self.box.pack_end(load, False) load.connect( 'clicked', lambda x: self.popup())
def on_bookmark_button_clicked(self, *e): track = self.dbfm_plugin.get_current_track() if track.get_tag_raw("fav")[0] == "1": self.dbfm_plugin.mark_as_dislike(track) self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON)) else : self.dbfm_plugin.mark_as_like(track) self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON))
def on_tag_update(self, e, track, tag): if track != self.dbfm_plugin.get_current_track(): return if track.get_tag_raw('fav')[0] == "1": self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON)) else: self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON))
def on_bookmark_button_clicked(self, *e): track = self.dbfm_plugin.get_current_track() if not self.dbfm_plugin.is_douban_track(track): return if track.get_rating() == 5: self.dbfm_plugin.mark_as_dislike(track) self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON)) else : self.dbfm_plugin.mark_as_like(track) self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON))
def on_fullscreen_toggled(self, sender): #switches between showing the conflicts in a standalone window. #uses fullscreenButton.get_active() as a state variable if self.fullscreenButton.get_active(): self.expander.set_expanded(False) self.fullscreenButton.set_image(gtk.image_new_from_icon_name("gtk-leave-fullscreen", gtk.ICON_SIZE_MENU)) self.conflictScrolledWindow.reparent(self.standalone) self.standalone.show() self.expander.set_sensitive(False) else: self.fullscreenButton.set_image(gtk.image_new_from_icon_name("gtk-fullscreen", gtk.ICON_SIZE_MENU)) self.conflictScrolledWindow.reparent(self.expander) self.standalone.hide() self.expander.set_sensitive(True)
def on_bookmark_button_clicked(self, *e): track = self.dbfm_plugin.get_current_track() if not self.dbfm_plugin.is_douban_track(track): return if track.get_rating() == 5: self.dbfm_plugin.mark_as_dislike(track) self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON)) else: self.dbfm_plugin.mark_as_like(track) self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON))
def ask(title, question, pre_fill = False):#{{{ """ Ask for something and return it """ done_ok = [ False ] def hide(x): done_ok[0] = True my_window.hide() gtk.main_quit() my_window = gtk.Window() my_window.connect("hide", hide) my_window.set_title("passwrd: " + title) my_window.set_default_size(300, 120) my_window.set_border_width(10) my_window.set_position(gtk.WIN_POS_MOUSE) my_vbox = gtk.VBox() my_window.add(my_vbox) my_hbox = gtk.HBox() my_vbox.add(my_hbox) my_image = gtk.image_new_from_icon_name("gtk-dialog-question", 3) my_hbox.add(my_image) my_label = gtk.Label(question) my_label.set_padding(3, 3) my_hbox.add(my_label) my_entry = gtk.Entry() if pre_fill: my_entry.set_text(pre_fill) my_entry.set_activates_default(True) my_vbox.add(my_entry) my_button = gtk.Button() my_button.set_label("Ok") my_button.connect("clicked", hide) my_button.set_flags(gtk.CAN_DEFAULT) my_button.set_image(gtk.image_new_from_icon_name("gtk-ok", -1)) my_window.set_default(my_button) my_hbox2 = gtk.HBox() my_hbox2.add(gtk.Label()) my_hbox2.add_with_properties(my_button, "expand", False, "fill", False) my_hbox2.add(gtk.Label()) my_vbox.add(my_hbox2) my_window.show_all() gtk.main() search = my_entry.get_text() my_window.destroy() handle_pending_events() if not done_ok[0]: sys.exit(1) return search
def factory(self, menu, parent, context): """ Sets up the menu item """ global LASTFMLOVER item = gtk.ImageMenuItem(_("Love This Track")) item.set_image(gtk.image_new_from_icon_name("love", gtk.ICON_SIZE_MENU)) if self.get_tracks_function is not None: tracks = self.get_tracks_function() empty = len(tracks) == 0 else: empty = context.get("selection-empty", True) if not empty: tracks = context.get("selected-tracks", []) if not empty and LASTFMLOVER.network is not None: # We only care about the first track track = tracks[0] lastfm_track = pylast.Track( track.get_tag_display("artist"), track.get_tag_display("title"), LASTFMLOVER.network ) if lastfm_track in LASTFMLOVER.loved_tracks: item.set_label(_("Unlove This Track")) item.connect("activate", self.on_activate, track) else: item.set_sensitive(False) return item
def clone_image(self, image): storage = image.get_storage_type() if storage == gtk.IMAGE_PIXMAP: img, mask = image.get_pixmap() return gtk.image_new_from_pixmap(img, mask) if storage == gtk.IMAGE_IMAGE: img, mask = image.get_image() return gtk.image_new_from_image(img, mask) if storage == gtk.IMAGE_PIXBUF: return gtk.image_new_from_pixbuf(image.get_pixbuf()) if storage == gtk.IMAGE_STOCK: img, size = image.get_stock() return gtk.image_new_from_stock(img, size) if storage == gtk.IMAGE_ICON_SET: img, size = image.get_icon_set() return gtk.image_new_from_icon_set(img, size) if storage == gtk.IMAGE_ANIMATION: return gtk.image_new_from_animation(image.get_animation()) if storage == gtk.IMAGE_ICON_NAME: img, size = image.get_icon_name() return gtk.image_new_from_icon_name(img, size) # if storage == gtk.IMAGE_EMPTY: img = gtk.Image() img.set_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU) return img
def get_image(self): if self._icon_name: return gtk.image_new_from_icon_name(self._icon_name, gtk.ICON_SIZE_MENU) elif self._stock_id: return gtk.image_new_from_stock(self._stock_id, gtk.ICON_SIZE_MENU) else: return gtk.Image()
def __init__(self, exaile): EggTrayIcon.__init__(self, 'Exaile Trayicon') self.image = gtk.image_new_from_icon_name('exaile', gtk.ICON_SIZE_MENU) self.eventbox = gtk.EventBox() self.eventbox.add(self.image) self.add(self.eventbox) builder = gtk.Builder() basedir = os.path.dirname(os.path.abspath(__file__)) builder.add_from_file(os.path.join(basedir, 'drop_target_window.ui')) self.exaile = exaile self.drop_target_window = builder.get_object('drop_target_window') self.play_target = builder.get_object('play_target') self.append_target = builder.get_object('append_target') self.new_playlist_target = builder.get_object('new_playlist_target') self.description_label = builder.get_object('description_label') self._drag_motion_id = None self._drag_leave_id = None BaseTrayIcon.__init__(self, self.exaile.gui.main) self.setup_drag_destinations() self.show_all()
def load_icon_image(icon_name, size): icontheme = gtk.icon_theme_get_default() if not icontheme.has_icon(icon_name): icon_name = 'gtk-missing-image' return gtk.image_new_from_icon_name(icon_name, size)
def __init__(self, parent, on_cancel=None): self.parent = parent self.on_cancel = on_cancel self.state = FancyProgressBar.HIDE self.offset = float(1) self.progress_bar = gtk.ProgressBar() image = gtk.image_new_from_icon_name('general_stop', \ gtk.ICON_SIZE_LARGE_TOOLBAR) self.cancel_button = gtk.ToolButton(image) self.hbox_animation_actor = gtk.HBox() self.hbox_inner = gtk.HBox() self.hbox_animation_actor.pack_start(self.hbox_inner) self.hbox_animation_actor.child_set(self.hbox_inner, 'padding', 12) self.hbox_inner.pack_start(self.progress_bar) self.hbox_inner.pack_start(self.cancel_button, False) self.animation_actor = hildon.AnimationActor() self.animation_actor.set_parent(self.parent) self.animation_actor.add(self.hbox_animation_actor) self.animation_actor.show_all() self.height, self.width = self.cancel_button.size_request() self.event_box = gtk.EventBox() self.event_box.connect('button-release-event', self.on_button_release) self.event_box.set_size_request(-1, self.height) self.offset = float(self.height) self.relayout()
def add_scrolled_parent(self, view, text, show_close=False, show_icon=None, make_active=False, save=None): scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll.add(view) scroll.saved_query = save img = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) btn = gtk.Button() btn.set_image(img) btn.set_relief(gtk.RELIEF_NONE) btn.set_name("tab-close-button") hb = gtk.HBox(spacing=2) if show_icon: hb.pack_start( gtk.image_new_from_icon_name(show_icon, gtk.ICON_SIZE_MENU)) hb.pack_start(gtk.Label(text)) if show_close: hb.pack_end(btn, False, False) hb.show_all() self.tabs.append_page(scroll, hb) self.tabs.set_tab_reorderable(scroll, True) self.tabs.show_all() if make_active: self.tabs.set_current_page(self.tabs.page_num(scroll)) btn.connect("clicked", self.on_tab_close, scroll)
def set_layout(self): """ Gui layout """ vbox = gtk.VBox(False, 8) self.add(vbox) hbox = gtk.HBox(False, 5) label = gtk.Label() label.set_markup('<b>%s</b>' % _( 'Select which controls should be visible')) image = gtk.image_new_from_icon_name( 'preferences-desktop', gtk.ICON_SIZE_DIALOG) hbox.pack_start(image, False, False) hbox.pack_start(label, False, False) vbox.pack_start(hbox, False, False) sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) vbox.pack_start(sw) bbox = gtk.HButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) button = gtk.Button(stock=gtk.STOCK_CLOSE) button.connect('clicked', self.close) bbox.add(button) vbox.pack_start(bbox, False, False) model = self._create_model() treeview = gtk.TreeView(model) treeview.set_headers_visible(False) sw.add(treeview) self._add_columns(treeview) self.show_all()
def item(self, plugin): """Create a new item into menu. @plugin: The plugin instance associated.""" # Create the menuitem. if plugin.type == 'launcher' or plugin.type == 'dialog': item = gtk.ImageMenuItem(plugin.label, True) if plugin.type == 'toggle': item = gtk.CheckMenuItem(plugin.label, True) item.set_active(plugin.state) item.connect('activate', lambda x: plugin.callback()) item.set_sensitive(plugin.sensitive) self.submenu.append(item) self.menubar.items[plugin] = item # Add image. if plugin.icon: isstock = plugin.icon.startswith('gtk-') if isstock: image = gtk.image_new_from_stock(plugin.icon, 1) else: image = gtk.image_new_from_icon_name(plugin.icon, 1) item.set_image(image) # Add shortcut. cfgname = 'plugin.%s' % plugin.name shortcuts = main.shortcuts.childs if shortcuts.has_key(cfgname): shortcut = shortcuts[cfgname] item.add_accelerator( 'activate', self.accelgroup, int(shortcut.key, 16), shortcut.mask, gtk.ACCEL_VISIBLE)
def right_click_event(self, icon, button, time): menu = gtk.Menu() about = gtk.ImageMenuItem(gtk.STOCK_ABOUT) logview = gtk.ImageMenuItem() logview.set_image(gtk.image_new_from_icon_name('emblem-photos', gtk.ICON_SIZE_MENU)) logview.set_label("Account Albums") logview.connect("activate", self.show_albums) quit = gtk.ImageMenuItem(gtk.STOCK_QUIT) about.connect("activate", self.about_click) quit.connect("activate", self.exit) apimenu = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES) apimenu.set_label("Preferences") apimenu.connect("activate", self.open_preferences) shotmenu = gtk.ImageMenuItem(gtk.STOCK_FULLSCREEN) shotmenu.set_label("Take Screenshot") shotmenu.connect("activate", self.take_screenshot) menu.append(about) menu.append(logview) menu.append(gtk.SeparatorMenuItem()) menu.append(shotmenu) menu.append(gtk.SeparatorMenuItem()) menu.append(apimenu) menu.append(gtk.SeparatorMenuItem()) menu.append(quit) menu.show_all() menu.popup(None, None, gtk.status_icon_position_menu, button, time, self.statusicon)
def docklet_icon_menu(self, icon, event, place): menu = self.create_default_menu() if place is not None: #If the place is ejectable if place[2]: eject = awn.image_menu_item_new_with_label(_("Eject")) image = gtk.image_new_from_icon_name('media-eject', gtk.ICON_SIZE_MENU) eject.set_image(image) menu.append(eject) eject.connect('activate', self.docklet_menu_eject, place[4]) elif place[3] == 'trash:///': empty = gtk.MenuItem(_("Empty Trash")) menu.append(empty) if self.trash.props.file_count == 0: empty.set_sensitive(False) empty.connect('activate', self.docklet_empty_trash) prefs = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES) prefs.connect('activate', self.open_prefs) menu.append(prefs) about = gtk.ImageMenuItem(gtk.STOCK_ABOUT) about.connect("activate", self.open_about) menu.append(about) menu.show_all() icon.popup_gtk_menu (menu, event.button, event.time)
def __init__( self, icon_name, icon_size ): self._gtk = gtk.Button() self._gtk.set_image( gtk.image_new_from_icon_name( icon_name, icon_size ) ) #icon = gtk.icon_theme_get_default().load_icon( "stock_up", 5, () ) self._gtk.set_relief( gtk.RELIEF_NONE ) self._gtk.set_focus_on_click( False ) self._gtk.show_all()
def show_folder_view_menu_popup( self, list, button, time ): iter = list.get_selection().get_selected()[1] if iter is None: return #print "popup-menu" self.popup_menu = gtk.Menu() menu_item = gtk.ImageMenuItem( 'backintime.open' ) menu_item.set_image( gtk.image_new_from_icon_name( self.store_folder_view.get_value( iter, 2 ), gtk.ICON_SIZE_MENU ) ) menu_item.connect( 'activate', self.on_list_folder_view_open_item ) self.popup_menu.append( menu_item ) self.popup_menu.append( gtk.SeparatorMenuItem() ) menu_item = gtk.ImageMenuItem( 'backintime.copy' ) menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_COPY, gtk.ICON_SIZE_MENU ) ) menu_item.connect( 'activate', self.on_list_folder_view_copy_item ) self.popup_menu.append( menu_item ) menu_item = gtk.ImageMenuItem( 'backintime.snapshots' ) menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_INDEX, gtk.ICON_SIZE_MENU ) ) menu_item.connect( 'activate', self.on_list_folder_view_snapshots_item ) self.popup_menu.append( menu_item ) if len( self.snapshot_id ) > 1: menu_item = gtk.ImageMenuItem( 'backintime.restore' ) menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_UNDELETE, gtk.ICON_SIZE_MENU ) ) menu_item.connect( 'activate', self.on_list_folder_view_restore_item ) self.popup_menu.append( menu_item ) self.popup_menu.show_all() self.popup_menu.popup( None, None, None, button, time )
def image_icon_menuitem(label, icon_name, space=10): import gtk image = gtk.image_new_from_icon_name(icon_name, gtk.ICON_SIZE_MENU) item = gtk.ImageMenuItem(stock_id=gtk.STOCK_ABOUT) item.set_image(image) item.get_child().set_text(label) return item
def __init__(self, item): gtk.VBox.__init__(self) self.show_button = WidgetFactory.create("GconfCheckButton", label = item["label"], key = item["visible"]) self.show_button.connect('toggled', self.colleague_changed) self.pack_start(self.show_button, False, False, 0) self.show_hbox = gtk.HBox(False, 10) self.pack_start(self.show_hbox, False, False, 0) if not self.show_button.get_active(): self.show_hbox.set_sensitive(False) icon = gtk.image_new_from_icon_name(item["icon"], gtk.ICON_SIZE_DIALOG) self.show_hbox.pack_start(icon, False, False, 0) self.rename_button = WidgetFactory.create("StrGconfCheckButton", label = item["rename"], key = item["name"]) self.rename_button.connect('toggled', self.colleague_changed) vbox = gtk.VBox(False, 5) self.show_hbox.pack_start(vbox, False, False, 0) vbox.pack_start(self.rename_button, False, False, 0) self.entry = WidgetFactory.create("GconfEntry", key = item["name"]) self.entry.connect('focus-out-event', self.entry_focus_out) self.entry.connect_activate_signal() if not self.rename_button.get_active(): self.entry.set_sensitive(False) vbox.pack_start(self.entry, False, False, 0)
def connect_to_activate(self, w): try: hosts = self._gcc.get_list(GCONF_APP_HOSTS, gconf.VALUE_STRING) except: hosts = [] submenu = w.get_submenu() for child in submenu.get_children(): submenu.remove(child) # populate devices menu for host in hosts: item = gtk.ImageMenuItem() item.set_label(host) try: image = gtk.image_new_from_icon_name('network-server', gtk.ICON_SIZE_MENU) item.set_image(image) item.set_always_show_image(True) except: pass submenu.append(item) item.connect('activate', self.connect_to_host_activate, host) item.show() w.set_submenu(submenu)
def factory(menu, parent, context): item = None if condition_fn is not None and not condition_fn(name, parent, context): return None if display_name is not None: if icon_name is not None: item = gtk.ImageMenuItem(display_name) image = gtk.image_new_from_icon_name(icon_name, size=gtk.ICON_SIZE_MENU) item.set_image(image) else: item = gtk.MenuItem(display_name) else: item = gtk.ImageMenuItem(icon_name) if submenu is not None: item.set_submenu(submenu) if accelerator is not None: key, mods = gtk.accelerator_parse(accelerator) item.add_accelerator('activate', FAKEACCELGROUP, key, mods, gtk.ACCEL_VISIBLE) if callback is not None: item.connect('activate', callback, name, parent, context, *callback_args) return item
def __init__(self): gtk.Menu.__init__(self) #CCSM if 'ccsm' in apps: item = ApplicationItem('ccsm') item.set_image(gtk.image_new_from_stock('gtk-preferences', gtk.ICON_SIZE_MENU)) self.append(item) #Emerald Theme Manager if 'emerald theme manager' in apps: item = ApplicationItem('emerald theme manager') item.set_image(gtk.image_new_from_icon_name('emerald-theme-manager-icon', gtk.ICON_SIZE_MENU)) self.append(item) if 'ccsm' in apps or 'emerald theme manager' in apps: item = gtk.SeparatorMenuItem() self.append(item) #Reload item = gtk.ImageMenuItem('Reload Window Manager') item.connect('activate', self.reload_activate) item.set_image(gtk.image_new_from_stock('gtk-refresh', gtk.ICON_SIZE_MENU)) if not wms: item.set_sensitive(False) self.append(item) #Window Manager item = gtk.ImageMenuItem('Select Window Manager') item.set_image(gtk.image_new_from_stock('gtk-index', gtk.ICON_SIZE_MENU)) submenu = WindowManagerMenu() item.set_submenu(submenu) if not wms: item.set_sensitive(False) self.append(item) #Compiz Options item = gtk.ImageMenuItem('Compiz Options') item.set_image(gtk.image_new_from_stock('gtk-properties', gtk.ICON_SIZE_MENU)) submenu = CompizOptionMenu() item.set_submenu(submenu) if not options: item.set_sensitive(False) self.append(item) #Window Decorator item = gtk.ImageMenuItem('Select Window Decorator') item.set_image(gtk.image_new_from_stock('gtk-select-color', gtk.ICON_SIZE_MENU)) submenu = CompizDecoratorMenu() item.set_submenu(submenu) if not decorators: item.set_sensitive(False) self.append(item) item = gtk.SeparatorMenuItem() self.append(item) item = gtk.ImageMenuItem(stock_id=gtk.STOCK_QUIT) item.connect('activate', self.quit_activate) self.append(item)
def get_image_from_name(name, size, fit_size = "both"): assert isinstance(name, str), "Image name must be a string" icon = None if gtk.stock_lookup(name): icon = gtk.image_new_from_stock(name, size) elif gtk.icon_theme_get_default().has_icon(name): icon = gtk.image_new_from_icon_name(name, size) else: path = os.path.join('..', os.path.dirname(os.path.dirname(__file__)), 'data', 'gfx', name+'.png') if os.path.exists(path): try: _size = gtk.icon_size_lookup(size) pixbuf = gtk.gdk.pixbuf_new_from_file(path) heightS = max(float(_size[1])/float(pixbuf.get_height()), 1.0) widthS = max(float(_size[0])/float(pixbuf.get_width()), 1.0) if fit_size == 'both': if heightS < widthS: pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(path, _size[1]*pixbuf.get_width()/pixbuf.get_height(), _size[1]) else: pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(path, _size[0], _size[0]*pixbuf.get_height()/pixbuf.get_width()) elif fit_size == 'width': pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(path, _size[0], _size[0]*pixbuf.get_height()/pixbuf.get_widtht()) else: pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(path, _size[1]*pixbuf.get_width()/pixbuf.get_height(), _size[1]) icon = gtk.image_new_from_pixbuf(pixbuf) except Exception as e: print e icon = gtk.image_new_from_stock(gtk.STOCK_MISSING_IMAGE, size) else: icon = gtk.image_new_from_stock(gtk.STOCK_MISSING_IMAGE, size) return icon
def cb(weather, sky, srss, image): print "tooltip update cb" if image is not None: self.__weather_image.set_from_icon_name(image, gtk.ICON_SIZE_BUTTON) tooltip_hbox = gtk.HBox(spacing=6) tooltip_hbox.set_border_width(2) tooltip_hbox.add(gtk.image_new_from_icon_name(image, gtk.ICON_SIZE_DIALOG)) description_vbox = gtk.VBox() tooltip_hbox.add(description_vbox) tooltip_title = [] if weather is not None: tooltip_title.append(weather[0].upper() + weather[1:]) if sky is not None: tooltip_title.append(sky[0].upper() + sky[1:]) if len(tooltip_title) > 0: sky_label = gtk.Label("<b>%s</b>" % ", ".join(tooltip_title)) sky_label.set_use_markup(True) sky_label.set_alignment(0.0, 0.5) description_vbox.pack_start(sky_label, expand=False) sunriseset_label = gtk.Label("Sunrise: %s:%s / Sunset: %s:%s" % (srss[0] + srss[1])) sunriseset_label.set_alignment(0.0, 0.5) description_vbox.pack_start(sunriseset_label, expand=False) print "constructed tooltip hbox:", tooltip_hbox self.__tooltip_hbox = tooltip_hbox
def factory(menu_, parent, context): item = None dt = (datetime.now() - close_time) if dt.seconds > 60: display_name = _( '{playlist_name} ({track_count} tracks, closed {minutes} min ago)' ).format(playlist_name=playlist.name, track_count=len(playlist), minutes=dt.seconds // 60) else: display_name = _( '{playlist_name} ({track_count} tracks, closed {seconds} sec ago)' ).format(playlist_name=playlist.name, track_count=len(playlist), seconds=dt.seconds) item = gtk.ImageMenuItem(display_name) item.set_image( gtk.image_new_from_icon_name('music-library', gtk.ICON_SIZE_MENU)) # Add accelerator to top item if self.tab_history[0][1].name == item_name: key, mods = gtk.accelerator_parse(self.accelerator.keys) item.add_accelerator('activate', menu.FAKEACCELGROUP, key, mods, gtk.ACCEL_VISIBLE) item.connect( 'activate', lambda w: self.restore_closed_tab(item_name=item_name)) return item
def on_tray_icon_popup(self, icon, event_button, event_time): menu = gtk.Menu() if self.props.visible: # Hide ----------------------------------------------------------------- m_hide = gtk.ImageMenuItem(_("Hide")) img = gtk.image_new_from_file(image_path('hide.png')) img.show() m_hide.set_image(img) menu.append(m_hide) m_hide.connect('activate', lambda w: self.hide()) else: # Show ----------------------------------------------------------------- m_show = gtk.ImageMenuItem(_("Show")) img = gtk.image_new_from_file(image_path('show.png')) img.show() m_show.set_image(img) menu.append(m_show) m_show.connect('activate', lambda w: self.show()) # Separator ------------------------------------------------------------ menu.append(gtk.SeparatorMenuItem()) # Quit ----------------------------------------------------------------- m_quit = gtk.ImageMenuItem(_("Quit")) img = gtk.image_new_from_icon_name('application-exit', gtk.ICON_SIZE_MENU) img.show() m_quit.set_image(img) menu.append(m_quit) m_quit.connect('activate', self.on_quit) menu.show_all() menu.popup(None, None, None, event_button, event_time)
def __init__(self): abstract.Plugin.__init__(self) box = gtk.HBox(False, 0) self.add(box) btn = gtk.Button() img = gtk.image_new_from_icon_name("stock_volume", gtk.ICON_SIZE_BUTTON) btn.add(img) btn.set_name("EdgeButton") btn.set_relief(gtk.RELIEF_NONE) box.add(btn) globals.tooltips.set_tip(btn, _("Open the volume control")) self._eb = gtk.EventBox() self.bar = gtk.ProgressBar() self.bar.set_orientation(gtk.PROGRESS_BOTTOM_TO_TOP) self.bar.set_size_request(11, 55) box.add(self._eb) self._eb.add(self.bar) btn.connect("clicked", self.__cb_mixer) btn.connect("scroll-event", self.__cb_scroll) self._eb.connect("scroll-event", self.__cb_scroll) self.mixer = ossaudiodev.openmixer() self.update() gobject.timeout_add(1000, self.update) self.show_all()
def factory(self, menu, parent, context): """ Sets up the menu item """ global LASTFMLOVER item = gtk.ImageMenuItem(_('Love This Track')) item.set_image(gtk.image_new_from_icon_name('love', gtk.ICON_SIZE_MENU)) if self.get_tracks_function is not None: tracks = self.get_tracks_function() empty = len(tracks) == 0 else: empty = context.get('selection-empty', True) if not empty: tracks = context.get('selected-tracks', []) if not empty and LASTFMLOVER.network is not None: # We only care about the first track track = tracks[0] lastfm_track = pylast.Track(track.get_tag_display('artist'), track.get_tag_display('title'), LASTFMLOVER.network) if lastfm_track in LASTFMLOVER.loved_tracks: item.set_label(_('Unlove This Track')) item.connect('activate', self.on_activate, track) else: item.set_sensitive(False) return item
def _build_widget(self): self.widget = gtk.Alignment(1.0, 0.5, 0.0, 1.0) button_widget = gtk.Button(self.title) if self.image: button_widget.set_image(gtk.image_new_from_icon_name(self.image, gtk.ICON_SIZE_BUTTON)) button_widget.connect("clicked", self._button_clicked) self.widget.add(button_widget)
def set_layout(self): """ Gui layout """ vbox = gtk.VBox(False, 8) self.add(vbox) hbox = gtk.HBox(False, 5) label = gtk.Label() label.set_markup('<b>%s</b>' % _('Select which controls should be visible')) image = gtk.image_new_from_icon_name('preferences-desktop', gtk.ICON_SIZE_DIALOG) hbox.pack_start(image, False, False) hbox.pack_start(label, False, False) vbox.pack_start(hbox, False, False) sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) vbox.pack_start(sw) bbox = gtk.HButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) button = gtk.Button(stock=gtk.STOCK_CLOSE) button.connect('clicked', self.close) bbox.add(button) vbox.pack_start(bbox, False, False) model = self._create_model() treeview = gtk.TreeView(model) treeview.set_headers_visible(False) sw.add(treeview) self._add_columns(treeview) self.show_all()
def __init__(self, parent, label, buttons): """Create and put on parent. @parent: Parent widget to put in. @label: Text to display. @buttons: """ # Create main widget and add into parent. self.box = gtk.HBox(False, 0) parent.pack_start(self.box, False, False, 0) # Label. if label: label = gtk.Label('%s:' % label) label.set_alignment(0, 0.5) self.box.pack_start(label, True, True, 0) # Margin between label and buttons. gutils.margin(self.box, 20, 1) # Buttons. for properties in reversed(buttons): icon, tooltip, callback = properties button = gtk.Button() button.set_image(gtk.image_new_from_icon_name(icon, 1)) button.set_relief(gtk.RELIEF_NONE) button.set_tooltip_text(tooltip) button.connect('clicked', lambda x,y=callback: y()) self.box.pack_end(button, False)
def __init__(self, panel_notebook): """ Adds the button to the main window and moves the main menu items """ gtk.Button.__init__(self) notebook.NotebookAction.__init__(self, panel_notebook) self.set_image( gtk.image_new_from_icon_name('exaile', gtk.ICON_SIZE_BUTTON)) self.set_tooltip_text(_('Main Menu')) self.set_focus_on_click(True) self.set_relief(gtk.RELIEF_NONE) accessible = self.get_accessible() accessible.set_role(atk.ROLE_MENU) accessible.set_name(_('Main Menu')) builder = main.mainwindow().builder # Move menu items of the main menu to the internal menu self.mainmenu = builder.get_object('mainmenu') self.menu = gtk.Menu() self.menu.attach_to_widget(self, lambda *args: False) self.menu.connect('deactivate', self.on_menu_deactivate) for menuitem in self.mainmenu: menuitem.reparent(self.menu) self.menu.show_all() self.show_all() self.connect('toggled', self.on_toggled)
def factory(menu_, parent, context): item = None dt = (datetime.now() - close_time) if dt.seconds > 60: display_name = _('{playlist_name} ({track_count} tracks, closed {minutes} min ago)').format( playlist_name=playlist.name, track_count=len(playlist), minutes=dt.seconds // 60 ) else: display_name = _('{playlist_name} ({track_count} tracks, closed {seconds} sec ago)').format( playlist_name=playlist.name, track_count=len(playlist), seconds=dt.seconds ) item = gtk.ImageMenuItem(display_name) item.set_image(gtk.image_new_from_icon_name('music-library', gtk.ICON_SIZE_MENU)) # Add accelerator to top item if self.tab_history[0][1].name == item_name: key, mods = gtk.accelerator_parse(self.accelerator.keys) item.add_accelerator('activate', menu.FAKEACCELGROUP, key, mods, gtk.ACCEL_VISIBLE) item.connect('activate', lambda w: self.restore_closed_tab(item_name=item_name)) return item
def __init__(self, vm, engine): vmmGObjectUI.__init__(self, "vmm-migrate.ui", "vmm-migrate") self.vm = vm self.conn = vm.conn self.engine = engine self.destconn_rows = [] self.window.connect_signals({ "on_vmm_migrate_delete_event" : self.close, "on_migrate_cancel_clicked" : self.close, "on_migrate_finish_clicked" : self.finish, "on_migrate_dest_changed" : self.destconn_changed, "on_migrate_set_rate_toggled" : self.toggle_set_rate, "on_migrate_set_interface_toggled" : self.toggle_set_interface, "on_migrate_set_port_toggled" : self.toggle_set_port, "on_migrate_set_maxdowntime_toggled" : self.toggle_set_maxdowntime, }) self.bind_escape_key_close() blue = gtk.gdk.color_parse("#0072A8") self.widget("migrate-header").modify_bg(gtk.STATE_NORMAL, blue) image = gtk.image_new_from_icon_name("vm_clone_wizard", gtk.ICON_SIZE_DIALOG) image.show() self.widget("migrate-vm-icon-box").pack_end(image, False) self.init_state()
def __init__(self, item): gtk.VBox.__init__(self) self.show_button = WidgetFactory.create("GconfCheckButton", label=item["label"], key=item["visible"]) self.show_button.connect('toggled', self.colleague_changed) self.pack_start(self.show_button, False, False, 0) self.show_hbox = gtk.HBox(False, 10) self.pack_start(self.show_hbox, False, False, 0) if not self.show_button.get_active(): self.show_hbox.set_sensitive(False) icon = gtk.image_new_from_icon_name(item["icon"], gtk.ICON_SIZE_DIALOG) self.show_hbox.pack_start(icon, False, False, 0) self.rename_button = WidgetFactory.create("StrGconfCheckButton", label=item["rename"], key=item["name"]) self.rename_button.connect('toggled', self.colleague_changed) vbox = gtk.VBox(False, 5) self.show_hbox.pack_start(vbox, False, False, 0) vbox.pack_start(self.rename_button, False, False, 0) self.entry = WidgetFactory.create("GconfEntry", key=item["name"]) self.entry.connect('focus-out-event', self.entry_focus_out) self.entry.connect_activate_signal() if not self.rename_button.get_active(): self.entry.set_sensitive(False) vbox.pack_start(self.entry, False, False, 0)
def on_playback_start(self, type, player, data): track = player.current artist = track.get_tag_raw('artist')[0] album = track.get_tag_raw('album')[0] title = track.get_tag_raw('title')[0] self.window.set_title("%s - %s Exaile" % (title, artist)) self.track_title_label.set_label("<big><b>%s - %s</b></big>" %(title, artist)) self.track_info_label.set_label(album) if track.get_rating() == 5: self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON)) else: self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON))
def __get_left_click_menu(self): if self.__lmenu is None: self.__lmenu = gtk.Menu() if self.__backend.can_suspend(): suspend_item = gtk.ImageMenuItem(_('Suspend')) suspend_icon = gtk.image_new_from_icon_name('batti-suspend', gtk.ICON_SIZE_MENU) suspend_item.set_image(suspend_icon) suspend_item.connect('activate', self.__suspend) self.__lmenu.append(suspend_item) if self.__backend.can_hibernate(): hibernate_item = gtk.ImageMenuItem(_('Hibernate')) hibernate_icon = gtk.image_new_from_icon_name('batti-hibernate', gtk.ICON_SIZE_MENU) hibernate_item.set_image(hibernate_icon) hibernate_item.connect('activate', self.__hibernate) self.__lmenu.append(hibernate_item) self.__lmenu.show_all() return self.__lmenu
def _build_widget(self): self.widget = gtk.Alignment(1.0, 0.5, 0.0, 1.0) button_widget = gtk.Button(self.title) if self.image: button_widget.set_image( gtk.image_new_from_icon_name(self.image, gtk.ICON_SIZE_BUTTON)) button_widget.connect("clicked", self._button_clicked) self.widget.add(button_widget)
def new_toggle_button(self, label, filter): togglebutton = gtk.ToggleToolButton() togglebutton.set_label(label) togglebutton.set_tooltip(self.tooltips, label) icon = 'gnome-mime-' + filter icon_widget = gtk.image_new_from_icon_name(icon, gtk.ICON_SIZE_MENU) togglebutton.set_icon_widget(icon_widget) togglebutton.filter_value = filter return togglebutton
def on_fullscreen_toggled(self, sender): #switches between showing the conflicts in a standalone window. #uses fullscreenButton.get_active() as a state variable if self.fullscreenButton.get_active(): self.expander.set_expanded(False) self.fullscreenButton.set_image( gtk.image_new_from_icon_name("gtk-leave-fullscreen", gtk.ICON_SIZE_MENU)) self.conflictScrolledWindow.reparent(self.standalone) self.standalone.show() self.expander.set_sensitive(False) else: self.fullscreenButton.set_image( gtk.image_new_from_icon_name("gtk-fullscreen", gtk.ICON_SIZE_MENU)) self.conflictScrolledWindow.reparent(self.expander) self.standalone.hide() self.expander.set_sensitive(True)
def set_initial_state(self): blue = gtk.gdk.color_parse("#0072A8") self.widget("clone-header").modify_bg(gtk.STATE_NORMAL, blue) box = self.widget("clone-vm-icon-box") image = gtk.image_new_from_icon_name("vm_clone_wizard", gtk.ICON_SIZE_DIALOG) image.show() box.pack_end(image, False)
def on_playback_start(self, type, player, data): track = player.current artist = track.get_tag_raw('artist')[0] album = track.get_tag_raw('album')[0] title = track.get_tag_raw('title')[0] self.window.set_title("%s - %s Exaile" % (title, artist)) self.track_title_label.set_label("<big><b>%s - %s</b></big>" % (title, artist)) self.track_info_label.set_label(album) if track.get_rating() == 5: self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON)) else: self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON))
def _get_icon(self, name): """ Load menu icons dynamically. :param str name: name of the menu item :returns: the loaded icon :rtype: gtk.Image """ return gtk.image_new_from_icon_name(self._menu_icons[name], gtk.ICON_SIZE_MENU)
def new_small_button(iconname, click_callback, tooltip=None, relief=gtk.RELIEF_NONE): btn = gtk.Button() btn.set_image(gtk.image_new_from_icon_name(iconname, gtk.ICON_SIZE_BUTTON)) if tooltip: btn.set_tooltip_text(tooltip) btn.set_focus_on_click(False) btn.set_relief(relief) btn.connect('clicked', click_callback) return btn
def getIconOrLabel(icon_name, label_text, icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR): icon = gtk.Image() theme = gtk.icon_theme_get_default() if theme.lookup_icon(icon_name, icon_size, gtk.ICON_LOOKUP_USE_BUILTIN): icon = gtk.image_new_from_icon_name(icon_name, icon_size) else: icon.set_from_stock(gtk.STOCK_EXECUTE, icon_size) label = label_text if icon != None: label = None return icon, label
def build_shutdown_button_menu(widget, shutdown_cb, reboot_cb, destroy_cb, save_cb): icon_name = util.running_config.get_shutdown_icon_name() widget.set_icon_name(icon_name) menu = gtk.Menu() widget.set_menu(menu) rebootimg = gtk.image_new_from_icon_name(icon_name, gtk.ICON_SIZE_MENU) shutdownimg = gtk.image_new_from_icon_name(icon_name, gtk.ICON_SIZE_MENU) destroyimg = gtk.image_new_from_icon_name(icon_name, gtk.ICON_SIZE_MENU) saveimg = gtk.image_new_from_icon_name(gtk.STOCK_SAVE, gtk.ICON_SIZE_MENU) reboot = gtk.ImageMenuItem(_("_Reboot")) reboot.set_image(rebootimg) reboot.show() reboot.connect("activate", reboot_cb) menu.add(reboot) shutdown = gtk.ImageMenuItem(_("_Shut Down")) shutdown.set_image(shutdownimg) shutdown.show() shutdown.connect("activate", shutdown_cb) menu.add(shutdown) destroy = gtk.ImageMenuItem(_("_Force Off")) destroy.set_image(destroyimg) destroy.show() destroy.connect("activate", destroy_cb) menu.add(destroy) sep = gtk.SeparatorMenuItem() sep.show() menu.add(sep) save = gtk.ImageMenuItem(_("Sa_ve")) save.set_image(saveimg) save.show() save.connect("activate", save_cb) menu.add(save)
def setup_main_dialog(self): if self.dialog is None: self.dialog = self.applet.dialog.new("main") self.vbox = gtk.VBox() self.dialog.add(self.vbox) else: self.vbox.foreach(gtk.Widget.destroy) if self.backend.supports_scaling(): group = None self.radio_buttons = {} governors = self.backend.get_governors() if "userspace" in governors: governors.remove("userspace") for i in self.backend.get_frequencies(): group = gtk.RadioButton(group, self.human_readable_freqency(i)) group.props.can_focus = False self.vbox.add(group) self.radio_buttons[i] = group group.connect("toggled", self.frequency_changed_cb, i) self.vbox.add(gtk.SeparatorMenuItem()) for i in governors: group = gtk.RadioButton(group, i) group.props.can_focus = False self.vbox.add(group) self.radio_buttons[i] = group group.connect("toggled", self.governor_changed_cb, i) else: hbox = gtk.HBox(spacing=6) hbox.set_border_width(6) self.vbox.add(hbox) hbox.add( gtk.image_new_from_icon_name("dialog-information", gtk.ICON_SIZE_DIALOG)) label = gtk.Label( _("<span size=\"large\"><b>Scaling unavailable</b></span>\n\nFrequency scaling is not\navailable for the selected CPU." )) label.set_use_markup(True) hbox.add(label) if self.__button_press_event_id is not None: self.applet.disconnect(self.__button_press_event_id) self.__button_press_event_id = self.applet.connect( "button-press-event", self.button_press_event_cb)
def __set_icon(self, icon): """Set the icon in the related button widget. Restore the label when when no icon is selected.""" if icon is not None: for i in self.ti_bt: self.ti_bt.remove(i) ti_bt_img = gtk.image_new_from_icon_name(icon, gtk.ICON_SIZE_BUTTON) ti_bt_img.show() self.ti_bt.add(ti_bt_img) else: for i in self.ti_bt: self.ti_bt.remove(i) self.ti_bt.add(self.ti_bt_label)
def on_playback_start(self, etype, player, *data): track = player.current artist = track.get_tag_raw('artist')[0] album = track.get_tag_raw('album')[0] title = track.get_tag_raw('title')[0] self.window.set_title(u"Exaile \u8c46\u74e3FM %s - %s" % (title, artist)) self.track_title_label.set_label("%s - %s" % (title, artist)) self.track_info_label.set_label(album) if track.get_tag_raw('fav')[0] == "1": self.bookmark_button.set_image( gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON)) else: self.bookmark_button.set_image( gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON)) self.sensitive(True) self.pause_button.set_image( gtk.image_new_from_stock('gtk-media-pause', gtk.ICON_SIZE_BUTTON))