我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用gi.repository.Gtk.CheckMenuItem()。
def setup_menu(self,indicator): def add_item(item): item.show() menu.append(item) return item menu = gtk.Menu() toggle_button = add_item(gtk.CheckMenuItem("Lock Orentation")) toggle_button.connect("toggled", self.toggle, indicator) indicator.set_secondary_activate_target(toggle_button) add_item(gtk.SeparatorMenuItem()) palm_toggle_button = add_item(gtk.CheckMenuItem("Palm Rejection")) palm_toggle_button.connect('toggled', self.palm_toggle, indicator) palm_toggle_button.set_active(True) add_item(gtk.MenuItem('About')).connect("activate", self.open_about_page) add_item(gtk.MenuItem("Exit")).connect("activate", self.quit) return menu
def __init__(self,note): Gtk.CheckMenuItem.__init__(self) self.note = note #self.get_children()[0].set_use_markup(True) if 'title' in note.keys() and note['title'] is not None: if len(note['title'])>28: title = note['title'][0:25]+'...' else: title = note['title'] else: title = '' if 'notes' in note.keys() and note['notes'] is not None: self.set_tooltip_text(note['notes']) if note['status'] == 'completed': self.set_label(title) self.set_active(True) else: self.set_label(title) self.set_active(False)
def create_view_menu(self): self.nb = self.main.tviews.right_notebook for x in self.nb.get_children(): box = self.nb.get_tab_label(x) element = box.get_children()[1].get_text().lower() item = Gtk.CheckMenuItem("Show " + element) if element != 'full info': item.set_active(True) item.connect("activate", self._on_status_view) self.vmenu.append(item) self.vmenu.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)
def menuPopup( self, widget, event ): if event.button == 3: mTree = Gtk.Menu() #i18n desktopMenuItem = Gtk.MenuItem(label=_("Add to desktop")) panelMenuItem = Gtk.MenuItem(label=_("Add to panel")) separator1 = Gtk.SeparatorMenuItem() favoriteMenuItem = Gtk.CheckMenuItem(label=_("Show in my favorites")) launchMenuItem = Gtk.MenuItem(label=_("Launch")) deleteMenuItem = Gtk.MenuItem(label=_("Delete from menu")) separator2 = Gtk.SeparatorMenuItem() propsMenuItem = Gtk.MenuItem(label=_("Edit properties")) mTree.append(desktopMenuItem) mTree.append(panelMenuItem) mTree.append(separator1) mTree.append(favoriteMenuItem) mTree.append(launchMenuItem) if os.environ["HOME"] in widget.desktopFile: mTree.append(deleteMenuItem) deleteMenuItem.connect("activate", self.delete_from_menu, widget) mTree.append(separator2) mTree.append(propsMenuItem) mTree.show_all() desktopMenuItem.connect("activate", self.add_to_desktop, widget) panelMenuItem.connect("activate", self.add_to_panel, widget) launchMenuItem.connect( "activate", self.onLaunchApp, widget ) propsMenuItem.connect( "activate", self.onPropsApp, widget) if self.isLocationInFavorites( widget.desktopFile ): favoriteMenuItem.set_active( True ) favoriteMenuItem.connect( "toggled", self.onRemoveFromFavorites, widget ) else: favoriteMenuItem.set_active( False ) favoriteMenuItem.connect( "toggled", self.onAddToFavorites, widget ) self.mateMenuWin.stopHiding() mTree.attach_to_widget(widget, None) if (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION) >= (3, 22): mTree.popup_at_pointer(event) else: mTree.popup(None, None, None, None, event.button, event.time)