本文整理汇总了Python中gi.repository.Gtk.MenuBar方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.MenuBar方法的具体用法?Python Gtk.MenuBar怎么用?Python Gtk.MenuBar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.MenuBar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gtk_menu_insert_by_path
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuBar [as 别名]
def gtk_menu_insert_by_path(menu, menu_path, menu_item):
"""
Add a new menu item into the existing menu at the path specified in
*menu_path*.
:param menu: The existing menu to add the new item to.
:type menu: :py:class:`Gtk.Menu` :py:class:`Gtk.MenuBar`
:param list menu_path: The labels of submenus to traverse to insert the new item.
:param menu_item: The new menu item to insert.
:type menu_item: :py:class:`Gtk.MenuItem`
"""
utilities.assert_arg_type(menu, (Gtk.Menu, Gtk.MenuBar), 1)
utilities.assert_arg_type(menu_path, list, 2)
utilities.assert_arg_type(menu_item, Gtk.MenuItem, 3)
while len(menu_path):
label = menu_path.pop(0)
menu_cursor = gtk_menu_get_item_by_label(menu, label)
if menu_cursor is None:
raise ValueError('missing node labeled: ' + label)
menu = menu_cursor.get_submenu()
menu.append(menu_item)
示例2: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuBar [as 别名]
def __init__(self):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
self.grid = Gtk.Grid(row_spacing=6, column_spacing=6)
self.grid.set_margin_top(WIDGET_SPACING // 2)
self.grid.set_halign(Gtk.Align.CENTER)
headerbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.headerbar = PreviewHeaderbar()
self.menubar = Gtk.MenuBar()
menuitem1 = Gtk.MenuItem(label=_('File'))
menuitem1.set_submenu(self.create_menu(3, True))
self.menubar.append(menuitem1)
menuitem2 = Gtk.MenuItem(label=_('Edit'))
menuitem2.set_submenu(self.create_menu(6, True))
self.menubar.append(menuitem2)
headerbox.pack_start(self.headerbar, True, True, 0)
headerbox.pack_start(self.menubar, True, True, 0)
self.label = Gtk.Label(label=_("This is a label"))
self.sel_label = Gtk.Label(label=_("Selected item"))
self.entry = Gtk.Entry(text=_("Text entry"))
self.button = Gtk.Button(label=_("Button"))
self.preview_imageboxes = {}
self.preview_imageboxes_templates = {}
self.preview_imageboxes['CHECKBOX'] = ScaledImage(width=16)
fake_checkbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
fake_checkbox.pack_start(self.preview_imageboxes['CHECKBOX'], False, False, 0)
fake_checkbox.pack_start(self.label, False, False, 0)
fake_checkbox.set_margin_left(WIDGET_SPACING // 2)
self.grid.set_margin_left(WIDGET_SPACING)
self.grid.set_margin_right(WIDGET_SPACING)
self.grid.attach(fake_checkbox, 3, 3, 1, 1)
self.grid.attach_next_to(
self.sel_label, fake_checkbox, Gtk.PositionType.BOTTOM, 1, 1
)
self.grid.attach_next_to(
self.entry, self.sel_label, Gtk.PositionType.BOTTOM, 1, 1
)
self.grid.attach_next_to(
self.button, self.entry, Gtk.PositionType.BOTTOM, 1, 1
)
self.pack_start(headerbox, True, True, 0)
self.pack_start(self.grid, True, True, 0)