def _get_best_icon_size_for_panel(self): """ Returns the best icon size for the current panel size """ try: panel_width, panel_height = self.get_size() except: return gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)[0] orientation = self.applet.get_orient() if orientation in (mateapplet.ORIENT_DOWN, mateapplet.ORIENT_UP): panel_size = panel_height else: panel_size = panel_width # "snap" the icon size to the closest stock icon size for icon_size in range(1,7): icon_size_pixels = gtk.icon_size_lookup(icon_size)[0] if abs(icon_size_pixels - panel_size) <= 1: return icon_size_pixels # if no stock icon size if close enough, then use the panel size return panel_size
def changetitle(self, widget, title=None): "Change Title when file is temporary" pg = self.notebook.get_current_page() print self.file, pg, self.widget if self.change[pg] == 0: hbox = gtk.HBox(False, 0) print title if title is None: title = self.file[pg] label = gtk.Label('**' + title.split('/')[-1]) hbox.pack_start(label) # get a stock close button image close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) # make the close button btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) hbox.pack_start(btn, False, False) # this reduces the size of the button style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() self.notebook.set_tab_label(self.widget[pg], hbox) btn.connect('clicked', self.on_closetab_button_clicked, self.widget[pg]) self.change[pg] = 1 elif not title is None: hbox = gtk.HBox(False, 0) label = gtk.Label(title.split('/')[-1]) hbox.pack_start(label) # get a stock close button image close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) # make the close button btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) hbox.pack_start(btn, False, False) # this reduces the size of the button style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() self.notebook.set_tab_label(self.widget[pg], hbox) btn.connect('clicked', self.on_closetab_button_clicked, self.widget[pg]) self.change[pg] = 0
def get_icon_pixbuf(name=None, stock=None, size=gtk.ICON_SIZE_DIALOG): ok = True if name: #use png icons on windows if gs.IS_WINDOWS: name = os.path.splitext(name)[0] + ".png" filename = os.path.join(gs.ICON_DIR, name) try: pb = gtk.gdk.pixbuf_new_from_file_at_size( os.path.abspath(filename), *gtk.icon_size_lookup(size) ) except Exception: LOG.warn("Error loading icon: %s" % filename, exc_info=True) ok = False elif stock: try: pb = gtk.icon_theme_get_default().load_icon( stock, gtk.icon_size_lookup(size)[0], 0) except Exception: ok = False LOG.warn("Error loading stock icon: %s" % stock, exc_info=True) else: raise ValueError("Must pass and icon name or a stock name") if not ok: pb = gtk.icon_theme_get_default().load_icon( gtk.STOCK_MISSING_IMAGE, gtk.icon_size_lookup(size)[0], 0) return pb
def __set_item_icon(self, item, prop): item.set_property("always-show-image", True) if prop.icon: size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) item.set_image(icon.IconWidget(prop.icon, size[0])) elif prop.label and prop.label.get_text() != "": item.set_label("") item.connect_after("expose-event", self.__label_expose_cb) item.connect("select", self.__label_select_cb, None) item.connect("deselect", self.__label_deselect_cb, None) else: size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) item.set_image(icon.IconWidget("ibus", size[0]))
def __init__(self): self.icon_extension_types = re.compile('.*\.(png|xpm|svg)$') self.icon_theme = gtk.icon_theme_get_default() self.icon_size_app = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)[0] self.icon_size_category = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] self.icon_size_menu = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] uninstalled_icon_path = '/usr/share/app-install/icons/' if os.path.exists(uninstalled_icon_path): self.icon_theme.append_search_path(uninstalled_icon_path) self._listener = return_true self.icon_theme.connect('changed', self._on_icon_theme_changed)
def _item_new(self, action_id, text, icon_name, file_name): if not self._icon_renderer and (icon_name or file_name): self._icon_renderer = gtk.CellRendererPixbuf() settings = self.get_settings() w, h = gtk.icon_size_lookup_for_settings( settings, gtk.ICON_SIZE_MENU) self._icon_renderer.props.stock_size = max(w, h) self.pack_start(self._icon_renderer, False) self.add_attribute(self._icon_renderer, 'pixbuf', 2) if not self._text_renderer and text: self._text_renderer = gtk.CellRendererText() self.pack_end(self._text_renderer, True) self.add_attribute(self._text_renderer, 'text', 1) if icon_name or file_name: if text: size = gtk.ICON_SIZE_MENU else: size = gtk.ICON_SIZE_LARGE_TOOLBAR width, height = gtk.icon_size_lookup(size) if icon_name: file_name = self._get_real_name_from_theme(icon_name, size) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( file_name, width, height) else: pixbuf = None return (action_id, text, pixbuf, False)
def get_pixbuf(self, size): '''Get the application icon as a C{gtk.gdk.Pixbuf}. @param size: the icon size as gtk constant @returns: a pixbuf object or C{None} ''' icon = self['Desktop Entry'].get('Icon', None) if not icon: return None if isinstance(icon, File): icon = icon.path w, h = gtk.icon_size_lookup(size) if '/' in icon or '\\' in icon: if zim.fs.isfile(icon): return gtk.gdk.pixbuf_new_from_file_at_size(icon, w, h) else: return None else: theme = gtk.icon_theme_get_default() try: pixbuf = theme.load_icon(icon.encode('utf-8'), w, 0) except Exception as error: #~ logger.exception('Foo') return None return pixbuf
def _toolbar_reconf_cb(self, toolitem): toolbar = self.get_parent() lookup_ret = gtk.icon_size_lookup(self.get_icon_size()) lookup_succeeded, iw, ih = lookup_ret assert lookup_succeeded size = max(iw, ih) self._main_preview.set_size_request(size, size)
def insert_closable_page(self, widget, label, index_page=-1): #hbox will be used to store a label and button, as notebook tab title hbox = gtk.HBox(False, 0) #label = gtk.Label(title) hbox.pack_start(label, False, False) #get a stock close button image close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) #make the close button btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) hbox.pack_start(btn, False, False) btn.set_size_request(image_w + 4, image_h) #this reduces the size of the button style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() #the tab will have a single widget: a label #widget = gtk.Label(title) #remove #add the tab self.insert_page(widget, hbox, index_page) #hbox = label+close_button btn.connect('clicked', self.on_closetab_button_clicked, widget)
def __init__(self, label_text="Icon", mode="Normal", text=""): gtk.HBox.__init__(self) label=gtk.Label(label_text) self.text=text self.combobox=gtk.combo_box_new_text() self.combobox.append_text("Normal") self.combobox.append_text("File path") self.combobox.props.active = mode != "Normal" self.button=gtk.Button() self.image=gtk.Image() self.pack_start(label, expand=False) self.pack_start(self.button,expand=False) self.pack_end(self.combobox, expand=True) self.button.set_image(self.image) self.combobox.connect('changed', self._emit_mode_signal) self.button.connect('pressed', self._emit_text_signal) if mode == "File path": size=gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)[0] try: pixbuf=gtk.gdk.pixbuf_new_from_file_at_size(os.path.expanduser(self.text), size, size) self.image.set_from_pixbuf(pixbuf) except glib.GError: self.image.set_from_pixbuf(None) print "Couldn't set icon from file: %s" %(self.text) else: self.image.set_from_icon_name(self.text,gtk.ICON_SIZE_LARGE_TOOLBAR) self.button.set_tooltip_text(self.text) self.show_all()
def assemble_toolbar(self, bar): width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) bar.run = bar.add(text=_("Run Now"), tooltip=_("Perform installations and removals"), sensitive_fn=self.sensitize_run_button, stock=gtk.STOCK_EXECUTE, callback=lambda x:run_transaction_cb(self)) bar.append_space() bar.subs = bar.add(text=_("Catalogs"), tooltip=_("Change your catalog subscriptions"), pixbuf=red_pixbuf.get_pixbuf("channels-24"), callback=lambda x:self.open_or_raise_window(red_subscriptions.SubscriptionsWindow)) def verify_and_refresh_sensitive_cb(): comp=self.componentbook.get_visible_component() return comp.run_sensitized() bar.refresh = bar.add(text=_("Refresh"), tooltip=_("Refresh catalog data"), stock = gtk.STOCK_REFRESH, sensitive_fn=verify_and_refresh_sensitive_cb, callback=lambda x:rcd_util.refresh(self))
def createPrivateMessageWindow(self, username): frame = PrivateMessageFrame(self.client, self, username) self.messages[username] = frame box = gtk.HBox(False, 0) button = gtk.Button(label=None) button.connect("clicked", self.closePrivateMessageWindow, username) button.add( gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)) button.set_relief(gtk.RELIEF_NONE) focus_pad = button.style_get_property('focus-padding') focus_wid = button.style_get_property('focus-line-width') wid, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) wid += (focus_pad + focus_wid) * 2 height += (focus_pad + focus_wid) * 2 button.set_size_request(wid, height) s = _("Private Message") box.pack_start(gtk.Label("%s: %s " % (s, username)), False, False, 0) box.pack_start(button, False, False, 0) box.show_all() page_num = self.notebook.append_page(frame, box) self.notebook.set_current_page(page_num) frame.hasFocus()
def OnInstrumentAdded(self, project, instrument): """ Callback for when an instrument is added to the project. Parameters: project -- The project that the instrument was added to. instrument -- The instrument that was added. """ strip = MixerStrip(self.project, instrument, self, self.mainview) strip.connect("minimise", self.OnMinimiseTrack, instrument) self.mixerStripList.append(strip) #create the toolbar button that will be shown when the instrument is minimised imgsize = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] pixbuf = instrument.pixbuf.scale_simple(imgsize, imgsize, gtk.gdk.INTERP_BILINEAR) image = gtk.Image() image.set_from_pixbuf(pixbuf) toolButton = gtk.ToolButton() toolButton.set_label(instrument.name) toolButton.set_icon_widget(image) toolButton.set_is_important(True) toolButton.connect("clicked", self.OnMaximiseTrack, instrument) self.minimisedButtonList.append((instrument, toolButton)) instrument.connect("visible", self.OnInstrumentVisible) #check if the instrument is currently visible and show the widgets self.OnInstrumentVisible(instrument)
def __init__(self, stock): '''constructor''' gtk.Button.__init__(self) # name the button to link it to a style self.set_name("close-button") image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU) self.set_image(image) width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) self.set_size_request(width + 2, height + 2) self.set_focus_on_click(False) self.set_relief(gtk.RELIEF_NONE) gtk.rc_parse_string(''' style "close-button-style" { GtkWidget::focus-padding = 0 GtkWidget::focus-line-width = 0 xthickness = 0 ythickness = 0 } widget "*.close-button" style "close-button-style" ''')
def populate_model(self): m = self.model m.clear() for uri in self.app_list.get_apps(): itr = m.append() m[itr][AppListBox.URI] = uri try: iface = self.iface_cache.get_interface(uri) name = iface.get_name() summary = iface.summary or _('No information available') summary = summary[:1].capitalize() + summary[1:] # (GTK3 returns an extra boolean at the start) icon_width, icon_height = gtk.icon_size_lookup( gtk.ICON_SIZE_DIALOG)[-2:] pixbuf = icon.load_icon(self.iface_cache.get_icon_path(iface), icon_width, icon_height) except model.InvalidInterface as ex: name = uri summary = unicode(ex) pixbuf = None m[itr][AppListBox.NAME] = name if pixbuf is None: pixbuf = self.window.render_icon(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_DIALOG) m[itr][AppListBox.ICON] = pixbuf m[itr][AppListBox.MARKUP] = '<b>%s</b>\n<i>%s</i>' % ( _pango_escape(name), _pango_escape(summary))
def pixbuf_from_icon_name(self, icon_name, size=gtk.ICON_SIZE_BUTTON): """ Generates a pixbuf from an icon name :param stock_id: an icon name :type stock_id: string :param size: the size of the icon, will be tried to converted to a GTK icon size :type size: int or GtkIconSize :returns: the generated pixbuf :rtype: :class:`gtk.gdk.Pixbuf` or None """ if type(size) == gtk.IconSize: icon_size = gtk.icon_size_lookup(size) size = icon_size[0] try: pixbuf = self.icon_theme.load_icon(icon_name, size, gtk.ICON_LOOKUP_NO_SVG) except glib.GError as e: logger.warning( 'Failed to get pixbuf from "{icon_name}": {error}'.format( icon_name=icon_name, error=e.message)) pixbuf = None # TODO: Check if fallbacks are necessary return pixbuf
def _item_new(self, action_id, text, icon_name, file_name): if not self._icon_renderer and (icon_name or file_name): self._icon_renderer = gtk.CellRendererPixbuf() settings = self.get_settings() w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) self._icon_renderer.props.stock_size = max(w, h) self.pack_start(self._icon_renderer, False) self.add_attribute(self._icon_renderer, 'pixbuf', 2) if not self._text_renderer and text: self._text_renderer = gtk.CellRendererText() self.pack_end(self._text_renderer, True) self.add_attribute(self._text_renderer, 'text', 1) if icon_name or file_name: if text: size = gtk.ICON_SIZE_MENU else: size = gtk.ICON_SIZE_LARGE_TOOLBAR width, height = gtk.icon_size_lookup(size) if icon_name: file_name = self._get_real_name_from_theme(icon_name, size) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( file_name, width, height) else: pixbuf = None return (action_id, text, pixbuf, False)
def _toolbar_reconf_cb(self, toolitem): toolbar = self.get_parent() lookup_ret = gtk.icon_size_lookup(self.get_icon_size()) lookup_succeeded, iw, ih = lookup_ret assert lookup_succeeded self.image_size = max(iw, ih) self.main_image.set_size_request(iw, ih)
def createPrivateMessageWindow(self, username): frame = PrivateMessageFrame(self.client, self, username) self.messages[username] = frame box = gtk.HBox(False, 0) button = gtk.Button(label=None) button.connect("clicked", self.closePrivateMessageWindow, username) button.add( gtk.image_new_from_stock( gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU ) ) button.set_relief( gtk.RELIEF_NONE ) focus_pad = button.style_get_property('focus-padding') focus_wid = button.style_get_property('focus-line-width') wid, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) wid += (focus_pad + focus_wid) * 2 height += (focus_pad + focus_wid) * 2 button.set_size_request( wid, height ) s = _("Private Message") box.pack_start(gtk.Label("%s: %s " % (s,username)), False, False, 0) box.pack_start(button, False, False, 0) box.show_all() page_num = self.notebook.append_page( frame , box ) self.notebook.set_current_page(page_num) frame.hasFocus()
def __init__(self): self.icon_extension_types = re.compile('.*\.(png|xpm|svg)$') self.icon_theme = gtk.icon_theme_get_default() self.icon_size_app = gtk.icon_size_lookup( gtk.ICON_SIZE_LARGE_TOOLBAR)[0] self.icon_size_category = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] self.icon_size_menu = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] uninstalled_icon_path = '/usr/share/app-install/icons/' if os.path.exists(uninstalled_icon_path): self.icon_theme.append_search_path(uninstalled_icon_path) self._listener = return_true self.icon_theme.connect('changed', self._on_icon_theme_changed)
def activate(self, shell): try: entry_type = VkontakteEntryType() shell.props.db.register_entry_type(entry_type) except NotImplementedError: # backward compatibility with 0.12 version entry_type = shell.props.db.entry_register_type("VkontakteEntryType") # Set the source's icon width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) icon = gtk.gdk.pixbuf_new_from_file_at_size(DATA_DIR+"/vk_small.png", width, height) # rhythmbox api break up (0.13.2 - 0.13.3) if hasattr(rb, 'rb_source_group_get_by_name'): source_group = rb.rb_source_group_get_by_name("library") self.source = gobject.new(VkontakteSource, name=_("Vkontakte"), shell=shell, icon=icon, plugin=self, entry_type=entry_type, source_group=source_group) shell.register_entry_type_for_source(self.source, entry_type) shell.append_source(self.source, None) else: source_group = rb.rb_display_page_group_get_by_id ("library") self.source = gobject.new(VkontakteSource, name=_("Vkontakte"), shell=shell, plugin=self, pixbuf=icon, entry_type=entry_type) shell.register_entry_type_for_source(self.source, entry_type) shell.append_display_page(self.source, source_group) ui = shell.get_ui_manager() self.uid = ui.add_ui_from_string(popup_ui) ui.ensure_update() self.source.initialise()
def __init__(self, notebook): self.__model = gtk.TreeStore(gobject.TYPE_PYOBJECT) gtk.TreeView.__init__(self, self.__model) self.notebook = notebook self.__files_changed_handler = self.notebook.connect('files-changed', self.on_files_changed) column = gtk.TreeViewColumn() self.append_column(column) column.set_resizable(gtk.TREE_VIEW_COLUMN_AUTOSIZE) cell_renderer = _BgPixbufRenderer() cell_renderer.props.stock_size = gtk.ICON_SIZE_MENU width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) cell_renderer.props.width = width cell_renderer.props.height = height column.pack_start(cell_renderer, False) column.set_cell_data_func(cell_renderer, self.__state_cell_data_func) cell_renderer = gtk.CellRendererText() column.pack_start(cell_renderer, True) column.set_cell_data_func(cell_renderer, self.__filename_cell_data_func) self.set_headers_visible(False) self.get_selection().set_select_function(self.__select_function) self.__rescan()
def __init__(self, layer_exporter, initial_layer_tree=None, initial_previered_layer_id=None): super(ExportImagePreview, self).__init__() self._layer_exporter = layer_exporter self._initial_layer_tree = initial_layer_tree self._initial_previewed_layer_id = initial_previered_layer_id self._layer_elem = None self._preview_pixbuf = None self._previous_preview_pixbuf_width = None self._previous_preview_pixbuf_height = None self.draw_checkboard_alpha_background = True self._is_updating = False self._preview_width = None self._preview_height = None self._preview_scaling_factor = None self._init_gui() self._PREVIEW_ALPHA_CHECK_COLOR_FIRST, self._PREVIEW_ALPHA_CHECK_COLOR_SECOND = ( int(hex(shade)[2:] * 4, 16) for shade in gimp.checks_get_shades(gimp.check_type())) self._placeholder_image_size = gtk.icon_size_lookup(self._placeholder_image.get_property("icon-size")) self._vbox.connect("size-allocate", self._on_vbox_size_allocate) self._widget = self._vbox
def __init__(self, model=None): # TODO: add logic to flag open notebook italic - needs daemon if model is None: model = NotebookTreeModel() gtk.TreeView.__init__(self, model) self.get_selection().set_mode(gtk.SELECTION_BROWSE) self.set_rules_hint(True) self.set_reorderable(True) cell_renderer = gtk.CellRendererPixbuf() column = gtk.TreeViewColumn(None, cell_renderer, pixbuf=PIXBUF_COL) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) column.set_fixed_width(w * 2) self.append_column(column) cell_renderer = gtk.CellRendererText() cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) cell_renderer.set_fixed_height_from_font(2) column = gtk.TreeViewColumn(_('Notebook'), cell_renderer, markup=TEXT_COL) # T: Column heading in 'open notebook' dialog column.set_sort_column_id(NAME_COL) self.append_column(column)
def create_closeable_tab(notebook, title, widget): """ Create a notebook tab """ hbox = gtk.HBox(False, 0) label = gtk.Label(title) hbox.pack_start(label) close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) hbox.pack_start(btn, False, False) # Reduce the size of the button style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() create_tab(notebook, hbox, widget) btn.connect("clicked", on_close_tab_button_clicked, notebook, widget)
def __init__(self, win, editor=None): gtksourceview2.View.__init__(self) gtk.widget_push_composite_child() self.editor = editor self.buffer = gtksourceview2.Buffer() self.set_buffer(self.buffer) self.set_show_line_marks(True) width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height) pixbuf.fill(0) self.set_mark_category_pixbuf('sql-start', pixbuf) self.set_mark_category_pixbuf('sql-end', pixbuf) lang_manager = gtksourceview2.language_manager_get_default() self.buffer.set_language(lang_manager.get_language('sql')) self.app = win.app self._sig_app_config_changed = self.app.config.connect( 'changed', self.on_config_changed) self.update_textview_options() self._buffer_changed_cb = None self.buffer.connect('end-user-action', self.on_buffer_changed) self.buffer.connect('mark-set', self.on_mark_set) if self.editor is not None: self.editor.connect( 'connection-changed', lambda e, c: self.on_buffer_changed(self.buffer)) self.connect('expose-event', self.on_expose) self._sql_marks = set() self.connect('destroy', self.on_destroy)
def step(self, page, text, func): """ Adds a step of a multi-step operation. This will indicate when it's starting and when it's complete. """ def call_func(): self.bbox.set_sensitive(False) label.set_markup("<b>%s</b>" % text) while gtk.events_pending(): gtk.main_iteration() func() label.set_text(text) self.bbox.set_sensitive(True) icon.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_MENU) hbox = gtk.HBox(False, 12) hbox.show() page['widget'].pack_start(hbox, False, False, 0) icon = gtk.Image() icon.show() hbox.pack_start(icon, False, False, 0) icon.set_size_request(*gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)) label = gtk.Label(text) label.show() hbox.pack_start(label, False, False, 0) label.set_alignment(0, 0) page['on_show_funcs'].append(call_func)
def __init__(self): gtk.Window.__init__(self) self.set_decorated(False) self.set_resizable(False) self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.set_border_width(0) self.props.accept_focus = False #Setup estimate of width, height w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) self._width = w self._height = h self.connect('size-request', self._size_request_cb) screen = self.get_screen() screen.connect('size-changed', self._screen_size_changed_cb) self._button = gtk.Button() self._button.set_relief(gtk.RELIEF_NONE) self._icon = Icon(icon_name='view-return', icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) self._icon.show() self._button.add(self._icon) self._button.show() self.add(self._button)
def __create_im_menu(self): engines = self.__bus.list_active_engines() current_engine = \ (self.__focus_ic != None and self.__focus_ic.get_engine()) or \ (engines and engines[0]) or \ None size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) menu = gtk.Menu() for i, engine in enumerate(engines): lang = ibus.get_language_name(engine.language) item = gtk.ImageMenuItem("%s - %s" % (lang, engine.longname)) if current_engine and current_engine.name == engine.name: for widget in item.get_children(): if isinstance(widget, gtk.Label): widget.set_markup("<b>%s</b>" % widget.get_text()) if engine.icon: item.set_image(_icon.IconWidget(engine.icon, size[0])) else: item.set_image(_icon.IconWidget(ICON_ENGINE, size[0])) item.connect("activate", self.__im_menu_item_activate_cb, engine) menu.add(item) item = gtk.ImageMenuItem(_("Turn off input method")) item.set_image(_icon.IconWidget("gtk-close", size[0])) item.connect("activate", self.__im_menu_item_activate_cb, None) if self.__focus_ic == None or not self.__focus_ic.is_enabled(): item.set_sensitive(False) menu.add(item) menu.show_all() menu.set_take_focus(False) return menu
def get_pixbuf(self, size): '''Get the application icon as a C{gtk.gdk.Pixbuf}. @param size: the icon size as gtk constant @returns: a pixbuf object or C{None} ''' icon = self['Desktop Entry'].get('Icon', None) if not icon: return None if isinstance(icon, File): icon = icon.path w, h = gtk.icon_size_lookup(size) if '/' in icon or '\\' in icon: if zim.fs.isfile(icon): return gtk.gdk.pixbuf_new_from_file_at_size(icon, w, h) else: return None else: theme = gtk.icon_theme_get_default() try: pixbuf = theme.load_icon(icon.encode('utf-8'), w, 0) except Exception, error: #~ logger.exception('Foo') return None return pixbuf
def set_animation(self, name, size=None, fallback=None): """Show and start the animation of the given name and size""" if name == self.animation_name: return if size != None: self.icon_size = size self.stop_animation() animation = [] (width, height) = gtk.icon_size_lookup(self.icon_size) theme = gtk.icon_theme_get_default() theme.append_search_path("/usr/share/gnome-packagekit/icons") if theme.has_icon(name): pixbuf = theme.load_icon(name, width, 0) rows = pixbuf.get_height() / height cols = pixbuf.get_width() / width for r in range(rows): for c in range(cols): animation.append( pixbuf.subpixbuf(c * width, r * height, width, height)) if len(animation) > 0: self.animation = animation self.iter = 0 self.set_from_pixbuf(self.animation[0]) self.start_animation() else: self.set_from_pixbuf(pixbuf) self.icon_name = name else: self.set_from_icon_name(fallback, self.icon_size) self.icon_name = fallback
def create_tab(self, title): # hbox will be used to store a label and button, as notebook tab title hbox = gtk.HBox(False, 0) label = gtk.Label(title) hbox.pack_start(label) # get a stock close button image close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) # make the close button btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) hbox.pack_start(btn, False, False) # this reduces the size of the button style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() # the tab will have a single widget: a label widget = gtk.Label(title) # add the tab self.notebook.insert_page(widget, hbox) # connect the close button btn.connect("clicked", self.on_closetab_button_clicked, widget)
def _open_source_tab(self, menuitem, view): ''' Creacion del tab que contendra el codigo fuente. Es practicamente igual que la del tab para el view source ''' hbox = gtk.HBox(False, 0) close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) url, w = self._create_source_view() hostname = urlparse(url).hostname label = gtk.Label('source-view: '+hostname) hbox.pack_start(label, False, False) btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) btn.connect('clicked', self._close_current_tab) hbox.pack_end(btn, False, False) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() current_page = self.notebook.get_current_page() page_tuple = (w, hbox) self.tabs.insert(current_page+1, page_tuple) self.notebook.insert_page(page_tuple[0], page_tuple[1], current_page+1) self.show_all() self.notebook.set_current_page(current_page+1)
def __init__(self, title, message, pic): gtk.ImageMenuItem.__init__(self, stock_id=gtk.STOCK_DIALOG_INFO) self.set_tooltip_markup(message) if pic: pb = gtk.gdk.pixbuf_new_from_file_at_size( pic.replace("file://",""), *gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)) self.set_image(gtk.image_new_from_pixbuf(pb)) lbl = self.get_children()[0] lbl.set_text(title) #remove the label, and place it in a hbox self.remove(lbl) hb = gtk.HBox() hb.pack_start(lbl, True, True) #add another label beside it, that shows the time this item was added mtime = gtk.Label('<span style="italic" weight="light">%s</span>' % time.strftime("%I:%M %p")) mtime.props.xalign = 1.0 mtime.props.use_markup = True hb.pack_start(mtime, False, False) self.add(hb)
def _open_new_tab(self, widget, data=None): ''' Callback para abrir un nuevo tab ''' ''' hacemos una caja horizontal donde meteremos el titulo y el boton de cerrar tab ''' hbox = gtk.HBox(False, 0) ''' Titulo ''' label = gtk.Label("New Tab") hbox.pack_start(label, False, False) ''' Boton de cerrar ''' close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) btn.connect('clicked', self._close_current_tab) hbox.pack_end(btn, False, False) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() current_page = self.notebook.get_current_page() page_tuple = (self._create_tab(), hbox) self.tabs.insert(current_page+1, page_tuple) self.notebook.insert_page(page_tuple[0], page_tuple[1], current_page+1) self.notebook.set_current_page(current_page+1)
def pixbuf_from_icon_name(self, icon_name, size=48): """ Generates a pixbuf from an icon name :param stock_id: an icon name :type stock_id: string :param size: the size of the icon, will be tried to converted to a GTK icon size :type size: int or GtkIconSize :returns: the generated pixbuf :rtype: :class:`gtk.gdk.Pixbuf` or None """ if type(size) == gtk.IconSize: icon_size = gtk.icon_size_lookup(size) size = icon_size[0] try: pixbuf = self.icon_theme.load_icon( icon_name, size, gtk.ICON_LOOKUP_NO_SVG) except glib.GError as e: print e pixbuf = None # TODO: Check if fallbacks are necessary return pixbuf
def populate_model(self): m = self.model m.clear() for uri in self.app_list.get_apps(): itr = m.append() m[itr][AppListBox.URI] = uri try: iface = self.iface_cache.get_interface(uri) feed = self.iface_cache.get_feed(uri) if feed: name = feed.get_name() summary = feed.summary or _('No information available') summary = summary[:1].capitalize() + summary[1:] else: name = iface.get_name() summary = _('No information available') # (GTK3 returns an extra boolean at the start) icon_width, icon_height = gtk.icon_size_lookup(gtk.ICON_SIZE_DIALOG)[-2:] pixbuf = icon.load_icon(self.iface_cache.get_icon_path(iface), icon_width, icon_height) except model.InvalidInterface as ex: name = uri summary = unicode(ex) pixbuf = None m[itr][AppListBox.NAME] = name if pixbuf is None: pixbuf = self.window.render_icon(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_DIALOG) m[itr][AppListBox.ICON] = pixbuf m[itr][AppListBox.MARKUP] = '<b>%s</b>\n<i>%s</i>' % (_pango_escape(name), _pango_escape(summary))
def __init__(self, stock): '''constructor''' gtk.Button.__init__(self) # name the button to link it to a style self.set_name("close-button") self.image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU) self.set_image(self.image) width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) self.set_size_request(width + 2, height + 2) self.image.show() self.set_focus_on_click(False) self.set_relief(gtk.RELIEF_NONE) gtk.rc_parse_string(''' style "close-button-style" { GtkWidget::focus-padding = 0 GtkWidget::focus-line-width = 0 xthickness = 0 ythickness = 0 } widget "*.close-button" style "close-button-style" ''')
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 OnInstrumentAdded(self, project, instrument): """ Callback for when an instrument is added to the project. Parameters: project -- The project that the instrument was added to. instrument -- The instrument that was added. """ strip = MixerStrip(self.project, instrument, self, self.mainview) strip.connect("minimise", self.OnMinimiseTrack, instrument) self.mixerStripList.append(strip) #create the toolbar button that will be shown when the instrument is minimised imgsize = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] pixbuf = instrument.pixbuf.scale_simple(imgsize, imgsize, gtk.gdk.INTERP_BILINEAR) image = gtk.Image() image.set_from_pixbuf(pixbuf) toolButton = gtk.ToolButton() toolButton.set_label(instrument.name) toolButton.set_icon_widget(image) toolButton.set_is_important(True) toolButton.connect("clicked", self.OnMaximiseTrack, instrument) self.minimisedButtonList.append( (instrument, toolButton) ) instrument.connect("visible", self.OnInstrumentVisible) #check if the instrument is currently visible and show the widgets self.OnInstrumentVisible(instrument)
def __download_album(self, audio_dl_uri, sku): def download_progress(current, total): self.__downloads[str_uri] = (current, total) self.__notify_status_changed() def download_finished(uri, result): del self.__cancellables[str_uri] del self.__downloads[str_uri] try: success = uri.copy_finish(result) except Exception, e: success = False print "Download not completed: " + str(e) if success: threading.Thread(target=unzip_album).start() else: remove_download_files() if len(self.__downloads) == 0: # All downloads are complete shell = self.get_property('shell') manager = shell.get_player().get_property('ui-manager') manager.get_action("/MagnatuneSourceViewPopup/MagnatuneCancelDownload").set_sensitive(False) if success: width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) icon = rb.try_load_icon(gtk.icon_theme_get_default(), "magnatune", width, 0) shell.notify_custom(4000, _("Finished Downloading"), _("All Magnatune downloads have been completed."), icon, True) self.__notify_status_changed()
def create_close_button(self, title): """ Return a tab label widget with a close button """ #hbox will be used to store a label and button, as notebook tab title hbox = gtk.HBox(False, 0) label = gtk.Label(title) hbox.pack_start(label) #get a stock close button image close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) #make the close button btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) hbox.pack_start(btn, False, False) btn.connect('clicked', self.close_model) #this reduces the size of the button style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() return hbox
def activate(self, config): # Plugin activated self.limit = 100 self.offset = 0 self.url = '' self.auth = None self.cache_stream = None self.cache_dir = os.path.expanduser("~/.cache/rhythmbox/ampache") self.cache = AmpacheCache('%s/song-cache.xml' % self.cache_dir, True) self.db_dates = None self.update_date = None self.add_date = None self.clean_date = None self.config = config width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) icon = gtk.gdk.pixbuf_new_from_file_at_size(self.config.get("icon_filename"), width, height) #self.set_property( "icon", icon) shell = self.get_property("shell") self.db = shell.get_property("db") self.entry_type = self.get_property("entry-type") self.__activate = False
def __create_im_menu(self): engines = self.__bus.list_active_engines() current_engine = \ (self.__focus_ic != None and self.__focus_ic.get_engine()) or \ (engines and engines[0]) or \ None size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) menu = gtk.Menu() for i, engine in enumerate(engines): lang = ibus.get_language_name(engine.language) item = gtk.ImageMenuItem("%s - %s" % (lang, engine.longname)) if current_engine and current_engine.name == engine.name: for widget in item.get_children(): if isinstance(widget, gtk.Label): widget.set_markup("<b>%s</b>" % widget.get_text()) if engine.icon: item.set_image(_icon.IconWidget(engine.icon, size[0])) else: item.set_image(_icon.IconWidget(ICON_ENGINE, size[0])) item.connect("activate", self.__im_menu_item_activate_cb, engine) menu.add(item) item = gtk.ImageMenuItem(_("Turn off input method")) item.set_image(_icon.IconWidget("gtk-close", size[0])) item.connect("activate", self.__im_menu_item_activate_cb, None) menu.add(item) menu.show_all() menu.set_take_focus(False) return menu
def tab_label_style_set_cb (tab_label, style): context = tab_label.get_pango_context() metrics = context.get_metrics(tab_label.style.font_desc, context.get_language()) char_width = metrics.get_approximate_digit_width() (width, height) = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) tab_label.set_size_request(16 * pango.PIXELS(char_width) + 2 * width, pango.PIXELS(metrics.get_ascent() + metrics.get_descent()) +2)
def get_icon_pixbuf(self, name, icon_size=gtk.ICON_SIZE_MENU): try: return self.icon_cache[name] except KeyError: icon_size = gtk.icon_size_lookup(icon_size)[0] icon = self.icon_theme.load_icon(name, icon_size, 0) self.icon_cache[name] = icon return icon
def __init__(self, *args, **kwargs): dialog_kwargs = kwargs.copy() for arg in ('image', 'pixbuf', 'text', 'text_secondary'): try: del dialog_kwargs[arg] except: pass gtk.Dialog.__init__(self, *args, **dialog_kwargs) self.set_icon_name('vineyard') self.hbox = gtk.HBox() self.hbox.set_spacing(6) self.hbox.set_border_width(6) self.innervbox = gtk.VBox() self.innervbox.set_spacing(6) self.hbox.pack_end(self.innervbox) self.vbox.add(self.hbox) self.image = gtk.Image() if 'image' in kwargs: if kwargs['image'][0] == '/': pixbuf = vineyard.pixbuf_new_from_any_file( kwargs['image'], size=gtk.icon_size_lookup(gtk.ICON_SIZE_DIALOG)[1]) else: pixbuf = vineyard.pixbuf_new_from_string( kwargs['image'], icon_size=gtk.ICON_SIZE_DIALOG, return_first=True) elif 'pixbuf' in kwargs: pixbuf = kwargs['pixbuf'] else: pixbuf = vineyard.pixbuf_new_from_string( 'vineyard', icon_size=gtk.ICON_SIZE_DIALOG) self.image.set_from_pixbuf(pixbuf) self.image.set_alignment(0.5, 0.0) self.hbox.pack_start(self.image, expand=False, fill=False) self.label_first = gtk.Label() self.label_first.set_alignment(0.0, 0.5) self.innervbox.pack_start(self.label_first, expand=False, fill=True) if 'text' in kwargs: self.set_markup(kwargs['text']) self.label_second = gtk.Label() self.label_second.set_alignment(0.0, 0.5) self.innervbox.pack_start(self.label_second, expand=False, fill=True) if 'text_secondary' in kwargs: self.set_markup_second(kwargs['text_secondary'])
def _get_real_name_from_theme(self, name, size): icon_theme = gtk.icon_theme_get_default() width, height = gtk.icon_size_lookup(size) info = icon_theme.lookup_icon(name, max(width, height), 0) if not info: raise ValueError("Icon '" + name + "' not found.") fname = info.get_filename() del info return fname
def activate(self, shell): self.shell = shell # so the source can update the progress bar self.db = shell.get_property("db") self.entry_type = self.db.entry_register_type("MagnatuneEntryType") # allow changes which don't do anything self.entry_type.can_sync_metadata = True self.entry_type.sync_metadata = None theme = gtk.icon_theme_get_default() rb.append_plugin_source_path(theme, "/icons") width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) icon = rb.try_load_icon(theme, "magnatune", width, 0) group = rb.rb_source_group_get_by_name("stores") self.source = gobject.new(MagnatuneSource, shell=shell, entry_type=self.entry_type, source_group=group, icon=icon, plugin=self) shell.register_entry_type_for_source(self.source, self.entry_type) shell.append_source(self.source, None) # Add the source to the list manager = shell.get_player().get_property('ui-manager') # Add the popup menu actions self.action_group = gtk.ActionGroup('MagnatunePluginActions') action = gtk.Action('MagnatuneDownloadAlbum', _('Download Album'), _("Download this album from Magnatune"), 'gtk-save') action.connect( 'activate', lambda a: self.shell.get_property("selected-source"). download_album()) self.action_group.add_action(action) action = gtk.Action('MagnatuneArtistInfo', _('Artist Information'), _("Get information about this artist"), 'gtk-info') action.connect( 'activate', lambda a: self.shell.get_property("selected-source"). display_artist_info()) self.action_group.add_action(action) action = gtk.Action('MagnatuneCancelDownload', _('Cancel Downloads'), _("Stop downloading purchased albums"), 'gtk-stop') action.connect( 'activate', lambda a: self.shell.get_property("selected-source"). cancel_downloads()) action.set_sensitive(False) self.action_group.add_action(action) manager.insert_action_group(self.action_group, 0) self.ui_id = manager.add_ui_from_string(popup_ui) self.pec_id = shell.get_player().connect('playing-song-changed', self.playing_entry_changed) manager.ensure_update()
class IconMenuItem(gtk.ImageMenuItem): icon_size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] def __init__(self, icon, text): gtk.ImageMenuItem.__init__(self) self.set_image(iconfactory.get_image(icon, self.icon_size)) label = gtk.Label(text) label.set_alignment(0.0, 0.5) self.add(label) self.show_all()
def __init__(self, *args, **kwargs): super(Browser, self).__init__(*args, **kwargs) ''' Le decimos a gtk que use hilos ''' gobject.threads_init() ''' Definimos algunas propiedades de la ventana principal ''' self.set_title('Triana Browser') self.set_icon_from_file('./iconn.png') self.connect("destroy", gtk.main_quit) self.maximize() ''' Instanciamos un objeto notebook que es el que nos permite menejar varias tabs ''' self.notebook = gtk.Notebook() # self.notebook.set_property('show-tabs', False) self.notebook.set_scrollable(True) ''' Para mantener la lista de tab abiertas ''' self.tabs = [] self.set_size_request(400, 400) ''' HBox viene de Horizontal Box, y es el tipo de caja que hemos decido usar para meter la cabecera de cada tab del notebook ''' hbox = gtk.HBox(False, 0) ''' Boton de cerrar tab''' close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) label = gtk.Label("Nuevo Tab") hbox.pack_start(label, False, False) btn = gtk.Button() btn.set_relief(gtk.RELIEF_NONE) btn.set_focus_on_click(False) btn.add(close_image) btn.connect('clicked', self._close_current_tab) hbox.pack_end(btn, False, False) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 btn.modify_style(style) hbox.show_all() ''' Para empezar creamos una tab vacia ''' self.tabs.append((self._create_tab(), hbox)) self.notebook.append_page(*self.tabs[0]) ''' La caja principal donde lo metemos todo, de momento solo tenemos el notebook ''' box = gtk.VBox() box.pack_start(self.notebook) ''' Agragamos la caja a la ventana principal ''' self.add(box) ''' Eventos que queremos manejar Primero el evento producido por presionar alguna/s tecla/s ''' # self.connect("key-press-event", self._key_pressed) ''' El evento producido al cambiar de tab, le pasamos la funcion _tab_changed cada vez que se produzca''' self.notebook.connect("switch-page", self._tab_changed) ''' Lo mostramos todo ''' self.show_all()
def __init__(self, application, parent): self._container = gtk.EventBox() self._application = application self._parent = parent # initialize tab events self._container.add_events(gtk.gdk.BUTTON_RELEASE_MASK) self._container.connect('button-release-event', self._button_release_event) self._container.set_visible_window(False) # create interface self._hbox = gtk.HBox(False, 0) self._container.add(self._hbox) self._label = gtk.Label() self._label.set_max_width_chars(20) self._label.set_ellipsize(pango.ELLIPSIZE_END) self._lock_image = gtk.Image() self._lock_image.set_property('no-show-all', True) self._lock_image.set_from_icon_name('changes-prevent-symbolic', gtk.ICON_SIZE_MENU) image = gtk.Image() image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image_width, image_height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) image.show() style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 self._button = gtk.Button() self._button.set_focus_on_click(False) self._button.add(image) self._button.set_relief(gtk.RELIEF_NONE) self._button.modify_style(style) self._button.connect('clicked', self._close_tab) self._button.set_property('no-show-all', True) self._button.set_size_request(image_width + 2, image_height + 2) # pack interface self._hbox.pack_start(self._lock_image, False, False, 0) self._hbox.pack_start(self._label, True, True, 0) self._hbox.pack_start(self._button, False, False, 0) # show controls if self._application.options.get('tab_close_button'): self._button.show() self._hbox.set_spacing(3) self._container.show_all()
def win_add(self, page, hide_current=False, allow_similar=True): if not allow_similar: for other_page in self.pages: if page == other_page: current_page = self.notebook.get_current_page() page_num = self.notebook.page_num(other_page.widget) other_page.widget.props.visible = True self.notebook.set_current_page(page_num) # In order to focus the page if current_page == page_num: self._sig_page_changt(self.notebook, None, page_num) return previous_page_id = self.notebook.get_current_page() previous_widget = self.notebook.get_nth_page(previous_page_id) if previous_widget and hide_current: page_id = previous_page_id + 1 else: page_id = -1 self.previous_pages[page] = previous_widget self.pages.append(page) hbox = gtk.HBox(spacing=3) icon_w, icon_h = gtk.icon_size_lookup(gtk.ICON_SIZE_SMALL_TOOLBAR)[-2:] if page.icon is not None: common.ICONFACTORY.register_icon(page.icon) image = gtk.Image() image.set_from_stock(page.icon, gtk.ICON_SIZE_SMALL_TOOLBAR) hbox.pack_start(image, expand=False, fill=False) name = page.name label = gtk.Label(common.ellipsize(name, 20)) self.tooltips.set_tip(label, page.name) self.tooltips.enable() label.set_alignment(0.0, 0.5) hbox.pack_start(label, expand=True, fill=True) button = gtk.Button() img = gtk.Image() img.set_from_stock('tryton-close', gtk.ICON_SIZE_MENU) width, height = img.size_request() button.set_relief(gtk.RELIEF_NONE) button.set_can_focus(False) button.add(img) self.tooltips.set_tip(button, _('Close Tab')) button.connect('clicked', self._sig_remove_book, page.widget) hbox.pack_start(button, expand=False, fill=False) x, y = gtk.icon_size_lookup_for_settings(button.get_settings(), gtk.ICON_SIZE_MENU)[-2:] button.set_size_request(x, y) hbox.show_all() label_menu = gtk.Label(page.name) label_menu.set_alignment(0.0, 0.5) self.notebook.insert_page_menu(page.widget, hbox, label_menu, page_id) self.notebook.set_tab_reorderable(page.widget, True) self.notebook.set_current_page(page_id)
def OnInstrumentImage(self, instrument=None): """ Callback for when the instrument's image changes. Parameters: instrument -- the instrument instance that send the signal. """ imgsize = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0] pixbuf = self.instrument.pixbuf.scale_simple(imgsize, imgsize, gtk.gdk.INTERP_BILINEAR) self.instrImage.set_from_pixbuf(pixbuf)
def set_page(self, page): if page is None: self.page_widget = None return self.page_widget, alignment_ = _embed_page(_Box, page) w_, h = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) page.show() if self.props.palette is None: self.props.palette = _ToolbarPalette(invoker=ToolInvoker(self)) self._move_page_to_palette()
def __create_model(self): store = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING) ids = gtk.stock_list_ids() ids.sort() for data in ids: info = StockItemInfo(stock_id=data) stock_item = gtk.stock_lookup(data) if stock_item: info.stock_item = stock_item else: # stock_id, label, modifier, keyval, translation_domain info.stock_item = ('', '', 0, 0, '') # only show icons for stock IDs that have default icons icon_set = gtk.icon_factory_lookup_default(info.stock_id) if icon_set is None: info.small_icon = None else: # See what sizes this stock icon really exists at sizes = icon_set.get_sizes() n_sizes = len(sizes) # Use menu size if it exists, otherwise first size found size = sizes[0] i = 0 while (i < n_sizes): if (sizes[i] == gtk.ICON_SIZE_MENU): size = gtk.ICON_SIZE_MENU break i += 1 info.small_icon = self.render_icon(info.stock_id, size) if (size != gtk.ICON_SIZE_MENU): # Make the result the proper size for our thumbnail w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) scaled = info.small_icon.scale_simple(w, h, 'bilinear') info.small_icon = scaled if info.stock_item[3] == 0: info.accel_str = "" else: info.accel_str = \ gtk.accelerator_name(info.stock_item[3], info.stock_item[2]) iter = store.append() store.set(iter, 0, info, 1, info.stock_id) return store
def __init__(self, name, language_id, handler, document): GObject.GObject.__init__(self) self.name = name self.proposals = [] self.language_id = language_id self.handler = handler self.document = document self.info_widget = None self.mark = None theme = Gtk.icon_theme_get_default() w, h = Gtk.icon_size_lookup(Gtk.ICON_SIZE_MENU) self.icon = theme.load_icon(Gtk.STOCK_JUSTIFY_LEFT, w, 0)