我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用gtk.CheckMenuItem()。
def on_populate_popup(self, treeview, menu): '''Add popup menu options.''' menu.prepend(gtk.SeparatorMenuItem()) # Add menu with view options. view_menu = gtk.Menu() # Add options to show tags and tagged pages. items = ( (_('Show only Pages with Tags'), self._show_tagged, lambda o: self.toggle_show_tagged()), (_('Show Tags'), self.uistate['show tags'], lambda o: self.toggle_show_tags()) ) for name, active, func in items: item = gtk.CheckMenuItem(name) item.set_active(active) item.connect('activate', func) view_menu.append(item) view_menu.append(gtk.SeparatorMenuItem()) # Add options to switch between views. def _change_view(item, event): self.uistate['Open pages'] = item.zim_view self.treeview.change_view(self.uistate['Open pages']) items = ( (_('Default'), 'default'), (_('Collapse other Pages'), 'collapse'), (_('Disable'), 'disable') ) item = None for name, view in items: item = gtk.RadioMenuItem(group = item, label = name) if view == self.uistate['Open pages']: item.set_active(True) item.zim_view = view item.connect('button-release-event', _change_view) view_menu.append(item) item = gtk.MenuItem('View') item.set_submenu(view_menu) menu.prepend(item) menu.show_all()
def on_gremlin_clicked(self, widget, event, data=None): if event.type == gtk.gdk._2BUTTON_PRESS: self.clear_live_plotter() # Settings if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: menu = gtk.Menu() program_alpha = gtk.CheckMenuItem("Program alpha") program_alpha.set_active(self.program_alpha) program_alpha.connect("activate", self.toggle_program_alpha) menu.append(program_alpha) show_limits = gtk.CheckMenuItem("Show limits") show_limits.set_active(self.show_limits) show_limits.connect("activate", self.toggle_show_limits) menu.append(show_limits) show_extents = gtk.CheckMenuItem("Show extents") show_extents.set_active(self.show_extents_option) show_extents.connect("activate", self.toggle_show_extents_option) menu.append(show_extents) live_plot = gtk.CheckMenuItem("Show live plot") live_plot.set_active(self.show_live_plot) live_plot.connect("activate", self.toggle_show_live_plot) menu.append(live_plot) # lathe = gtk.CheckMenuItem("Lathe mode") # lathe.set_active(self.lathe_option ) # lathe.connect("activate", self.toggle_lathe_option) # menu.append(lathe) menu.popup(None, None, None, event.button, event.time) menu.show_all()
def create_menu(self): menu = gtk.Menu() self.add_menu_item("_Pause f.lux", self._toggle_pause, menu, MenuItem=gtk.CheckMenuItem) self.add_menu_item("Prefere_nces", self._open_preferences, menu) self.add_menu_separator(menu) self.add_menu_item("Quit", self._quit, menu) return menu