def build_menu(machine):
menu = gtk.Menu()
host_item = gtk.MenuItem(machine['host'])
menu.append(host_item)
for gpu in machine['GPUs']:
gpu['title'] = gtk.MenuItem(gpu['name'] + ', ' + '%.2f' % (gpu['memory']) + ' GB')
gpu['title'].set_sensitive(False)
gpu['status'] = gtk.MenuItem(str(gpu['utilization']) + '% , ' + '%.2f' % (gpu['used_mem']) + ' GB')
menu.append(gpu['title'])
menu.append(gpu['status'])
menu.show_all()
machine['menu'] = menu
python类MenuItem()的实例源码
client_smi_appindicator.py 文件源码
项目:nvidia-multiple-smi
作者: ClementPinard
项目源码
文件源码
阅读 51
收藏 0
点赞 0
评论 0
def submenu(submenu, title):
submenu.show_all()
menu = gtk.MenuItem(title)
menu.set_submenu(submenu)
return menu
def menu_quit():
menu = gtk.Menu()
item_quit = gtk.MenuItem('Quit')
item_quit.connect('activate', lambda x: gtk.main_quit())
return item_quit
def build_menu(self):
self.menu = gtk.Menu()
self.item_main_window = gtk.MenuItem('Open Main Window')
self.item_main_window.connect('activate', self.main_window)
self.menu.append(self.item_main_window)
self.menu.append(gtk.SeparatorMenuItem().new())
self.item_quit = gtk.MenuItem('Quit')
self.item_quit.connect('activate', self.quit)
self.menu.append(self.item_quit)
self.menu.show_all()
def build_menu():
menu = Gtk.Menu()
#brightness
item_brightness_up = Gtk.MenuItem('Increase Brightness')
item_brightness_up.connect('activate', increase_brightness)
menu.append(item_brightness_up)
item_brightness_down = Gtk.MenuItem("Decrease Brightness")
item_brightness_down.connect('activate', decrease_brightness)
menu.append(item_brightness_down)
#rotate
item_rotate = Gtk.MenuItem('Rotate')
item_rotate.connect('activate', rotate_screen)
menu.append(item_rotate)
#flip
item_flip = Gtk.MenuItem('Flip')
item_flip.connect('activate', flip_screen)
menu.append(item_flip)
#seperator
seperator = Gtk.SeparatorMenuItem()
menu.append(seperator)
#quit
item_quit = Gtk.MenuItem('Quit')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def __init__(self, browser):
self.browser = browser
self.tab = None
self.menu = Gtk.Menu()
close_item = Gtk.MenuItem("Close Tab")
close_item.connect("activate", self.on_close)
self.menu.append(close_item)
def add_item(self, name, handler):
"""
Add a new menu item.
"""
item = Gtk.MenuItem(name)
item.connect("activate", handler)
self.menu.append(item)
def menu():
menu = gtk.Menu()
item_convert = gtk.MenuItem('Date Converter')
item_convert.connect('activate', open_convert_dialog)
menu.append(item_convert)
item_quit = gtk.MenuItem('Quit')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def __init__(self, express):
menu_names = ["Preferences", "About"]
Gtk.Menu.__init__(self)
self.set_title("bacon")
for name in menu_names:
menuitem = Gtk.MenuItem(label=name)
self.append(menuitem)
menuitem.show()
menuitem.connect("activate", globals()[name], express)
def _build_menu_item(self, name, menu,
image=None,
on_signal="activate",
callback=None):
"""
"""
menu_item = Gtk.MenuItem()
if image:
hbox = Gtk.Box(Gtk.Orientation.HORIZONTAL)
try:
icon = Gtk.Image.new_from_icon_name(image, 1)
except TypeError:
# ``image`` is a Gtk.Image already loaded.
icon = image
label = Gtk.Label(name)
# accelerator = ?
_pack_widgets(hbox, icon, label)
menu_item.add(hbox)
# use pack_end() to add an accelerator in a menu item with an image
else:
menu_item.set_label(name)
if callback:
menu_item.connect(on_signal, callback)
menu.append(menu_item)
return menu_item
def _build_indicator_menu(self, indicator):
'''Build the indicator menu'''
menu = Gtk.Menu()
self.inhibit_menu_item = Gtk.MenuItem("Inhibit Sleep")
menu.append(self.inhibit_menu_item)
self.inhibit_menu_item.connect("activate", self.on_toggle)
self.inhibit_menu_item.show()
menu_item = Gtk.SeparatorMenuItem()
menu.append(menu_item)
menu_item.show()
menu_item = Gtk.MenuItem('Preferences')
menu.append(menu_item)
menu_item.connect('activate', self.on_settings)
menu_item.show()
menu_item = Gtk.MenuItem('About')
menu.append(menu_item)
menu_item.connect('activate', self.on_about)
menu_item.show()
menu_item = Gtk.MenuItem("Quit")
menu.append(menu_item)
menu_item.connect("activate", self.on_quit)
menu_item.show()
indicator.set_menu(menu)
def update_people(person_uuid, handup):
if person_uuid not in PEOPLE:
mi = gtk.MenuItem(person_uuid)
n = notify.Notification.new("", "", "")
PEOPLE[person_uuid] = ["off", mi, n]
menu.append(mi)
PEOPLE[person_uuid][0] = handup
if handup == "on":
PEOPLE[person_uuid][1].show()
else:
PEOPLE[person_uuid][1].hide()
their = "their"
name = person_uuid
if handup == "on":
updown = "up"
icon = os.path.abspath("open-green.svg")
else:
updown = "down"
icon = os.path.abspath("closed.svg")
if unicode(person_uuid) == unicode(pnconfig.uuid):
their = "your"
name = "You"
if handup == "on":
icon = os.path.abspath("open-yellow.svg")
PEOPLE[person_uuid][2].update("%s put %s hand %s" % (name, their, updown), "", icon)
PEOPLE[person_uuid][2].show()
hand_state = "closed.svg"
print " Checking whether people have their hands up"
for p, hm in PEOPLE.items():
h, m, n = hm
if h == "on":
if unicode(p) == unicode(pnconfig.uuid):
print " I do, so let's go with a yellow hand, unless anyone else does too"
hand_state = "open-yellow.svg"
else:
print " ", p, "does, so it's a green hand icon"
hand_state = "open-green.svg"
break
print(" OK, finished checking; we're setting the hand to %s" % (hand_state,))
indicator.set_icon(os.path.abspath(hand_state))
def init_context_menu_widget(self):
self.context_menu_widget = self.gtk_builder.get_object('context-menu')
self.context_menu_widget.attach_to_widget(self.bank_list_widget)
if self.context_menu_widget:
self.menu_item_store = Gtk.MenuItem('Store changes')
self.menu_item_store.connect('activate', self.context_menu_store)
self.context_menu_widget.insert(self.menu_item_store, 0)
self.menu_item_store.set_sensitive(False)
self.menu_item_undo = Gtk.MenuItem('Undo changes')
self.menu_item_undo.connect('activate', self.context_menu_undo)
self.context_menu_widget.insert(self.menu_item_undo, 1)
self.menu_item_undo.set_sensitive(False)
self.menu_item_export = Gtk.MenuItem('Export program...')
self.menu_item_export.connect('activate',
self.context_menu_export_prg)
self.context_menu_widget.insert(self.menu_item_export, 2)
self.menu_item_export.set_sensitive(False)
self.menu_item_import = Gtk.MenuItem('Import...')
self.menu_item_import.connect('activate', self.import_prg_or_bank)
self.context_menu_widget.insert(self.menu_item_import, 3)
self.menu_item_import.set_sensitive(False)
self.copied_program = None
self.menu_item_copy = Gtk.MenuItem('Copy')
self.menu_item_copy.connect('activate', self.context_menu_copy)
self.context_menu_widget.insert(self.menu_item_copy, 4)
self.menu_item_copy.set_sensitive(False)
self.menu_item_paste = Gtk.MenuItem('Paste')
self.menu_item_paste.set_sensitive(False)
self.menu_item_paste.connect('activate', self.context_menu_paste)
self.context_menu_widget.insert(self.menu_item_paste, 5)
self.menu_item_paste.set_sensitive(False)
else:
print('Could not find widget for context menu')
def build_menu():
menu = gtk.Menu()
item_quit = gtk.MenuItem('Quit')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def trashPopup( self, widget, event ):
if event.button == 3:
trashMenu = Gtk.Menu()
emptyTrashMenuItem = Gtk.MenuItem(_("Empty trash"))
trashMenu.append(emptyTrashMenuItem)
trashMenu.show_all()
emptyTrashMenuItem.connect ( "activate", self.emptyTrash, widget )
self.mateMenuWin.stopHiding()
trashMenu.attach_to_widget(widget, None)
trashMenu.popup(None, None, None, None, 3, 0)
def update_indicator(self):
# Get subreddit name from config
subreddit = self.indicator.config.get('subreddit')
# Exit if not specified
if not subreddit:
return
posts_type = self.indicator.config.get('posts_type', 1)
posts_limit = self.indicator.config.get('posts_limit', '5')
types = {
1: 'new',
2: 'hot',
3: 'top',
4: 'random'
}
type_string = types[int(posts_type)]
# Get last posts
data = self.indicator.request.get_subreddit(subreddit, type_string, posts_limit)
# Exit if not specified
if not data:
return
# Where to append
menu = self.indicator.builder.get_object('furikura_menu')
for child in menu.get_children():
if child.get_name() == 'subreddit_post':
child.destroy()
# Show title
name = self.indicator.builder.get_object('subreddit')
name.set_label('/r/%s/%s' % (subreddit, type_string))
name.show()
# Show separator
self.indicator.builder.get_object('subreddit_separator_one').show()
self.indicator.builder.get_object('subreddit_separator_two').show()
# Iterate through last posts and append them to the menu
for post in data:
title = post['title'][:40] + (post['title'][40:] and '...')
item = Gtk.MenuItem('{upvotes}{gold} | {title}'.format(
upvotes=post['upvotes'],
gold=' \u2605' if post['gilded'] else '',
title=html.unescape(title)
))
url = 'https://www.reddit.com' + post['permalink'] \
if self.indicator.config.get('use_permalink') \
else post['link']
item.connect('activate', self.__open_url, url)
item.set_name('subreddit_post')
menu.add_child(self.indicator.builder, item)
item.show()
def create_learning_tree_menu(self):
"""
Create and return a Gtk.Menu object that has submenus that
let us select all lessons on the learning tree.
"""
def create_menu(page):
menu = Gtk.Menu()
for column in page:
for section in column:
item = Gtk.MenuItem(section.m_name)
for link in section:
if isinstance(link, frontpage.Page):
item = Gtk.MenuItem(link.m_name)
menu.append(item)
item.set_submenu(create_menu(link))
else:
assert isinstance(link, unicode)
# This will also alert us if the file is not
# found or not parsable:
try:
if lessonfile.infocache.get(link, 'module') not in ('melodicinterval', 'harmonicinterval', 'idbyname'):
continue
except lessonfile.infocache.InfoCacheException:
continue
# We don't want to add these lesson files because we know
# that they cannot be exported. It would be better
# to catch these with a more generic algorithm, but
# then we would have to parse all the files, and that
# would be too slow.
if link in (
# melodic-interval-self-config
"f62929dc-7122-4173-aad1-4d4eef8779af",
# harmonic-interval-self-config
"466409e7-9086-4623-aff0-7c27f7dfd13b",
# the csound-fifth-* files:
"b465c807-d7bf-4e3a-a6da-54c78d5b59a1",
"aa5c3b18-664b-4e3d-b42d-2f06582f4135",
"5098fb96-c362-45b9-bbb3-703db149a079",
"3b1f57e8-2983-4a74-96da-468aa5414e5e",
"a06b5531-7422-4ea3-8711-ec57e2a4ce22",
"e67c5bd2-a275-4d9a-96a8-52e43a1e8987",
"1cadef8c-859e-4482-a6c4-31bd715b4787",
):
continue
item = Gtk.MenuItem(_(lessonfile.infocache.get(link, 'title')))
item.connect('activate', self.on_select_exercise, link)
menu.append(item)
return menu
menu = create_menu(solfege.app.m_frontpage_data)
menu.show_all()
self._menu_hide_stuff(menu)
return menu
def get_menu(self):
"""Create and populate the menu."""
menu = Gtk.Menu()
self.working_menu_item = Gtk.MenuItem().new_with_label(_('Start'))
self.working_menu_item.connect('activate', self.on_working_menu_item)
self.working_menu_item.show()
menu.append(self.working_menu_item)
if self.wid > 0:
self.working_menu_item.set_label(_('Stop'))
else:
self.working_menu_item.set_label(_('Start'))
menu.append(self.working_menu_item)
#
capture_backlight_menu = Gtk.MenuItem().new_with_label(_('Capture \
backlight'))
capture_backlight_menu.connect('activate',
self.on_capture_backlight_menu)
capture_backlight_menu.show()
menu.append(capture_backlight_menu)
#
set_backlight_menu = Gtk.MenuItem().new_with_label(_('Set \
backlight manually'))
set_backlight_menu.connect('activate', self.on_set_backlight_menu)
set_backlight_menu.show()
menu.append(set_backlight_menu)
#
separator1 = Gtk.SeparatorMenuItem()
separator1.show()
menu.append(separator1)
#
menu_preferences = Gtk.MenuItem.new_with_label(_('Preferences'))
menu_preferences.connect('activate', self.on_preferences_item)
menu_preferences.show()
menu.append(menu_preferences)
menu_help = Gtk.MenuItem.new_with_label(_('Help'))
menu_help.set_submenu(self.get_help_menu())
menu_help.show()
menu.append(menu_help)
#
separator2 = Gtk.SeparatorMenuItem()
separator2.show()
menu.append(separator2)
#
menu_exit = Gtk.MenuItem.new_with_label(_('Exit'))
menu_exit.connect('activate', self.on_quit_item)
menu_exit.show()
menu.append(menu_exit)
#
menu.show()
return(menu)
def __init__(self, year):
Gtk.Grid.__init__(self)
self.year = year
self.selected_quarter = None
self.quarters = {
0: "Fall",
1: "Winter",
2: "Spring",
3: "Summer"
}
self.hidden = {x: False for x in [0,2,4,6]}
self.quarter_map = {}
self.set_vexpand(True)
self.set_hexpand(True)
self.set_valign(Gtk.Align.FILL)
self.set_halign(Gtk.Align.FILL)
horizontal_separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
horizontal_separator.set_margin_top(2)
horizontal_separator.set_margin_bottom(5)
self.attach(horizontal_separator, 0, 1, 2, 1)
for x in [0,2,4,6]:
if x < 6:
# Don't insert a column if it's at position 0
if x: self.insert_column(x)
# Insert column to expand horizontal separator
self.insert_column(x+1)
vertical_separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
vertical_separator.set_margin_start(5)
vertical_separator.set_margin_end(5)
self.attach(vertical_separator, x+1, 0, 1, 3)
quarter = quarterColumn(self.year, self.quarters[x/2])
label_box = Gtk.EventBox()
label = Gtk.Label(self.quarters[x/2])
label_box.add(label)
label_box.connect('button-press-event', self.quarter_clicked)
self.attach(label_box, x, 0, 1, 1)
self.quarter_map[x/2] = quarter
self.attach(quarter, x, 2, 1, 1)
self.hide_menu = Gtk.Menu()
hide_button = Gtk.MenuItem.new_with_label('Hide')
self.hide_menu.append(hide_button)
hide_button.show()
hide_button.connect('activate', self.toggle_quarter)
self.show_all()
def __init__(self, **kwargs):
super(Indicator, self).__init__()
self.indicator = appindicator.Indicator.new(
'testindicator',
YELLOW,
IndicatorCategory.APPLICATION_STATUS
)
self.status = None
self.on_quit = kwargs.get('quit')
self.on_run = kwargs.get('run', None)
self.on_stop = kwargs.get('stop', None)
self.indicator.set_status(IndicatorStatus.ACTIVE)
self.menu = gtk.Menu()
self.project_name = gtk.MenuItem(cfg.project_name)
self.project_name.set_sensitive(False)
self.project_name.show()
self.menu.append(self.project_name)
separator_item = gtk.SeparatorMenuItem()
separator_item.show()
self.menu.append(separator_item)
self.show_item = gtk.CheckMenuItem("Notifications")
self.show_item.set_active(cfg.notifications)
self.show_item.connect('toggled', self.on_notifications_toggle)
self.show_item.show()
self.menu.append(self.show_item)
self.run_now_item = gtk.MenuItem('Run tests (CTRL+SUPER+T)')
self.run_now_item.connect('activate', self.run_or_stop)
self.run_now_item.set_sensitive(True)
self.run_now_item.show()
self.menu.append(self.run_now_item)
separator_item = gtk.SeparatorMenuItem()
separator_item.show()
self.menu.append(separator_item)
self.item_quit = gtk.MenuItem('Exit (CTRL+SUPER+E)')
self.item_quit.connect('activate', self.on_quit)
self.menu.append(self.item_quit)
self.menu.show_all()
self.indicator.set_menu(self.menu)