本文整理汇总了Python中gi.repository.Gtk.ImageMenuItem方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.ImageMenuItem方法的具体用法?Python Gtk.ImageMenuItem怎么用?Python Gtk.ImageMenuItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.ImageMenuItem方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def __init__(self, image_path):
Gtk.ImageMenuItem.__init__(self)
self.get_style_context().add_class("KanoComboBox")
self.set_use_underline(False)
self.set_always_show_image(True)
# set the given image
pixbuf = GdkPixbuf.Pixbuf.new_from_file(image_path)
image = Gtk.Image.new_from_pixbuf(pixbuf)
# put the image inside an alignment container for centering
self.box = Gtk.Alignment()
self.box.set_padding(0, 0, 0, pixbuf.get_width())
self.box.add(image)
# by default, a MenuItem has an AccelLabel widget as it's one and only child
self.remove(self.get_child())
self.add(self.box)
# By overriding this signal we can stop the Menu
# containing this item from being popped down
self.connect("button-release-event", self.do_not_popdown_menu)
示例2: build_menu_item
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def build_menu_item(self, obj_type, handle):
if obj_type == 'Person':
person = self.dbstate.db.get_person_from_handle(handle)
name = name_displayer.display(person)
elif obj_type == 'Event':
event = self.dbstate.db.get_event_from_handle(handle)
name = str(event.get_type())
item = Gtk.ImageMenuItem(None)
image = Gtk.Image.new_from_icon_name('gtk-edit', Gtk.IconSize.MENU)
image.show()
label = Gtk.Label(label=_("Edit %s") % name)
label.show()
label.set_halign(Gtk.Align.START)
item.set_image(image)
item.add(label)
item.connect('activate', self.edit_menu, handle, obj_type)
item.show()
return item
示例3: show_change_task
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def show_change_task(self):
self.showChangeTask(Gtk.ImageMenuItem())
# to be called from the daemon
示例4: wifiListMenu
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def wifiListMenu(self, wificard, cbssid, passes, cards):
wiconncmenu = Gtk.Menu()
avconnmenu = Gtk.MenuItem("Available Connections")
avconnmenu.set_submenu(wiconncmenu)
for bssid in cards[wificard]['info']:
ssid = cards[wificard]['info'][bssid][0]
sn = cards[wificard]['info'][bssid][4]
caps = cards[wificard]['info'][bssid][6]
if passes is True:
if cbssid != bssid:
menu_item = Gtk.ImageMenuItem(ssid)
if caps == 'E' or caps == 'ES':
menu_item.set_image(self.openwifi(sn))
menu_item.connect("activate", self.menu_click_open,
ssid, bssid, wificard)
else:
menu_item.set_image(self.securewifi(sn))
menu_item.connect("activate", self.menu_click_lock,
ssid, bssid, wificard)
menu_item.show()
wiconncmenu.append(menu_item)
else:
menu_item = Gtk.ImageMenuItem(ssid)
if caps == 'E' or caps == 'ES':
menu_item.set_image(self.openwifi(sn))
menu_item.connect("activate", self.menu_click_open, ssid,
bssid, wificard)
else:
menu_item.set_image(self.securewifi(sn))
menu_item.connect("activate", self.menu_click_lock, ssid,
bssid, wificard)
menu_item.show()
wiconncmenu.append(menu_item)
self.menu.append(avconnmenu)
示例5: _setup_menu
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def _setup_menu(self):
mute_menu_item = Gtk.ImageMenuItem("Mute")
img = Gtk.Image.new_from_icon_name(
"audio-volume-muted", Gtk.IconSize.SMALL_TOOLBAR
)
mute_menu_item.set_image(img)
mute_menu_item.connect("activate", self._cb_menu_mute)
mixer_menu_item = Gtk.ImageMenuItem("Mixer")
img = Gtk.Image.new_from_icon_name(
"multimedia-volume-control", Gtk.IconSize.SMALL_TOOLBAR
)
mixer_menu_item.set_image(img)
mixer_menu_item.connect("activate", self._cb_menu_mixer)
preferences_menu_item = Gtk.ImageMenuItem("Preferences")
img = Gtk.Image.new_from_icon_name(
"preferences-desktop", Gtk.IconSize.SMALL_TOOLBAR
)
preferences_menu_item.set_image(img)
preferences_menu_item.connect("activate", self._cb_menu_preferences)
about_menu_item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_ABOUT)
about_menu_item.connect("activate", self._cb_menu_about)
exit_menu_item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_QUIT)
exit_menu_item.connect("activate", self._cb_menu_quit)
self._menu.append(mute_menu_item)
self._menu.append(mixer_menu_item)
self._menu.append(preferences_menu_item)
self._menu.append(Gtk.SeparatorMenuItem())
self._menu.append(about_menu_item)
self._menu.append(exit_menu_item)
self._menu.show_all()
# gui callbacks
示例6: _populate_menu
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def _populate_menu(self, textview, menu):
opc = Gtk.ImageMenuItem((Gtk.STOCK_CLEAR))
opc.get_children()[0].set_label('Clear text')
menu.prepend(Gtk.SeparatorMenuItem())
menu.prepend(opc)
opc.connect("activate", self._clear, iter)
menu.show_all()
示例7: _populate_popup
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def _populate_popup(self, textview, menu):
'''Populates the menu with the Find item.'''
menu.append(Gtk.SeparatorMenuItem())
opc = Gtk.ImageMenuItem((Gtk.STOCK_FIND))
opc.get_children()[0].set_label('Find...')
menu.append(opc)
opc.connect("activate", self.show_search)
menu.show_all()
示例8: right_click_event
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def right_click_event(self, icon, button, time):
def toggle_continuous(ImageMenuItem):
threading.Thread(target=self._toggle_continuous,args=[]).start()
def _quit_daemon():
#don't try to close the systray
self.interface.do_quit(False)
def quit_daemon():
threading.Thread(target=_quit_daemon,args=[]).start()
def quit(ImageMenuItem):
quit_daemon()
Gtk.main_quit()
#the funcs must be declared before menu.append use
def do_reset(ImageMenuItem):
threading.Thread(target=self._fsm,args=['reset']).start()
def do_stop(ImageMenuItem):
threading.Thread(target=self._fsm,args=['stop']).start()
def take_a_break(ImageMenuItem):
threading.Thread(target=self._fsm,args=['take_break']).start()
def create_menu_item(label, icon_name):
image = Gtk.Image()
image.set_from_icon_name(icon_name, 24)
item = Gtk.ImageMenuItem()
item.set_label(label)
item.set_image(image)
return item
def connect_menu_item(label, icon_name, event):
item = create_menu_item(label, icon_name)
item.connect("activate", event)
return item
self.menu = Gtk.Menu()
self.menu.append(connect_menu_item("Change task", "edit-paste", self.showChangeTask))
self.menu.append(connect_menu_item("Toggle continuous", "gtk-goto-last", toggle_continuous))
self.menu.append(connect_menu_item("Reset", "edit-redo", do_reset))
self.menu.append(connect_menu_item("Stop", "process-stop", do_stop))
self.menu.append(connect_menu_item("Take a break", "alarm-symbolic", take_a_break))
self.menu.append(connect_menu_item("Close app", "application-exit",quit))
self.menu.show_all()
self.menu.popup(None, None, None, self.status_icon, button, time)
示例9: create_menu
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def create_menu(self):
menu = Gtk.Menu()
self.current = Gtk.ImageMenuItem.new_with_label(_('Paused'))
self.current.connect('activate', self.play_or_pause)
self.current.set_always_show_image(True)
self.current.show()
menu.append(self.current)
separator1 = Gtk.SeparatorMenuItem()
separator1.show()
menu.append(separator1)
self.next = Gtk.ImageMenuItem(label=_('Previous'))
self.next.show()
self.next.connect('activate', self.on_activate_previous)
menu.append(self.next)
self.previous = Gtk.ImageMenuItem(label=_('Next'))
self.previous.show()
self.previous.connect('activate', self.on_activate_next)
menu.append(self.previous)
separator2 = Gtk.SeparatorMenuItem()
separator2.show()
menu.append(separator2)
self.show_main_window = Gtk.MenuItem.new_with_label(_('Hide main window'))
self.show_main_window.show()
self.show_main_window.connect('activate', self.on_show_main_window)
menu.append(self.show_main_window)
ayuda_menu = Gtk.MenuItem(label=_('Help'))
ayuda_menu.set_submenu(self.get_help_menu())
ayuda_menu.show()
menu.append(ayuda_menu)
separator3 = Gtk.SeparatorMenuItem()
separator3.show()
menu.append(separator3)
exit_option = Gtk.MenuItem.new_with_label(_('Quit'))
exit_option.show()
exit_option.connect('activate', self.on_exit_option)
menu.append(exit_option)
return menu
示例10: rebuild_menu
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def rebuild_menu(self):
# Main Menu items
self.errorItem = Gtk.MenuItem(_("View script error"))
enableMenuItem = Gtk.CheckMenuItem(_("Enable Expansions"))
enableMenuItem.set_active(self.app.service.is_running())
enableMenuItem.set_sensitive(not self.app.serviceDisabled)
configureMenuItem = Gtk.ImageMenuItem(_("Show Main Window"))
configureMenuItem.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.MENU))
removeMenuItem = Gtk.ImageMenuItem(_("Remove icon"))
removeMenuItem.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU))
quitMenuItem = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_QUIT, None)
# Menu signals
enableMenuItem.connect("toggled", self.on_enable_toggled)
configureMenuItem.connect("activate", self.on_show_configure)
removeMenuItem.connect("activate", self.on_remove_icon)
quitMenuItem.connect("activate", self.on_destroy_and_exit)
self.errorItem.connect("activate", self.on_show_error)
# Get phrase folders to add to main menu
folders = []
items = []
for folder in self.configManager.allFolders:
if folder.show_in_tray_menu:
folders.append(folder)
for item in self.configManager.allItems:
if item.show_in_tray_menu:
items.append(item)
# Construct main menu
self.menu = popupmenu.PopupMenu(self.app.service, folders, items, False)
if len(items) > 0:
self.menu.append(Gtk.SeparatorMenuItem())
self.menu.append(self.errorItem)
self.menu.append(enableMenuItem)
self.menu.append(configureMenuItem)
self.menu.append(removeMenuItem)
self.menu.append(quitMenuItem)
self.menu.show_all()
self.errorItem.hide()
self.indicator.set_menu(self.menu)
示例11: on_button_press_event
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ImageMenuItem [as 别名]
def on_button_press_event(self, treeview, event):
'''
Displays a context-menu on right button click
Opens the link of a tablecell on CTRL pressed and left button click
'''
if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 1 and event.get_state() & Gdk.ModifierType.CONTROL_MASK:
# With CTRL + LEFT-Mouse-Click link of cell is opened
cellvalue = self.fetch_cell_by_event(event, treeview)
linkvalue = self.get_linkurl(cellvalue)
if linkvalue:
self.emit('link-clicked', {'href': str(linkvalue)})
return
if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3:
# Right button opens context menu
self._keep_toolbar_open = True
cellvalue = self.fetch_cell_by_event(event, treeview)
linkvalue = self.get_linkurl(cellvalue)
linkitem_is_activated = (linkvalue is not None)
menu = Gtk.Menu()
for stock, handler, data, tooltip in (
(Gtk.STOCK_ADD, self.on_add_row, None, _('Add row')), # T: menu item
(Gtk.STOCK_DELETE, self.on_delete_row, None, _('Delete row')), # T: menu item
(Gtk.STOCK_COPY, self.on_clone_row, None, _('Clone row')), # T: menu item
(None, None, None, None), # T: menu item
(Gtk.STOCK_JUMP_TO, self.on_open_link, linkvalue, _('Open cell content link')), # T: menu item
(None, None, None, None),
(Gtk.STOCK_GO_UP, self.on_move_row, -1, _('Row up')), # T: menu item
(Gtk.STOCK_GO_DOWN, self.on_move_row, 1, _('Row down')), # T: menu item
(None, None, None, None),
(Gtk.STOCK_PREFERENCES, self.on_change_columns, None, _('Change columns')) # T: menu item
):
if stock is None:
menu.append(Gtk.SeparatorMenuItem())
else:
item = Gtk.ImageMenuItem(stock)
item.set_always_show_image(True)
item.set_label(_(tooltip))
if data:
item.connect_after('activate', handler, data)
else:
item.connect_after('activate', handler)
if handler == self.on_open_link:
item.set_sensitive(linkitem_is_activated)
menu.append(item)
menu.show_all()
gtk_popup_at_pointer(menu, event)