Python gi.repository.Gtk 模块,MenuItem() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gi.repository.Gtk.MenuItem()

项目:surface-orientation    作者:virtualguywithabowtie    | 项目源码 | 文件源码
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
项目:YubiGuard    作者:pykong    | 项目源码 | 文件源码
def build_menu(self):
        menu = Gtk.Menu()

        item_unlock = Gtk.MenuItem('Unlock')
        item_unlock.connect('activate', self.unlock)
        menu.append(item_unlock)
        self.item_unlock = item_unlock
        self.item_unlock.set_sensitive(False)  # default state

        item_help = Gtk.MenuItem('Help')
        item_help.connect('activate', self.open_help)
        menu.append(item_help)

        separator = Gtk.SeparatorMenuItem()
        menu.append(separator)

        item_quit = Gtk.MenuItem('Quit')
        item_quit.connect('activate', self.quit)
        menu.append(item_quit)

        menu.show_all()
        return menu
项目:furi-kura    作者:benjamindean    | 项目源码 | 文件源码
def build_login_menu(self):

        def open_login(context):
            webbrowser.open(self.cfg_cls.LOGIN_URI, new=1, autoraise=True)

        login_menu = Gtk.Menu()
        item_login = Gtk.MenuItem('Login')
        item_separator = Gtk.SeparatorMenuItem()
        item_quit = Gtk.MenuItem('Quit')

        item_login.connect('activate', open_login)
        item_quit.connect('activate', self.quit)

        login_menu.append(item_login)
        login_menu.append(item_separator)
        login_menu.append(item_quit)
        login_menu.show_all()

        self.INDICATOR.set_menu(login_menu)
项目:btcwidget    作者:rafalh    | 项目源码 | 文件源码
def _create_menu(self):
        menu = Gtk.Menu()

        self._menu_item = Gtk.MenuItem("Bitcoin")
        self._menu_item.connect('activate', self._on_show_item_activate)
        menu.append(self._menu_item)

        options_menu_item = Gtk.MenuItem("Options...")
        options_menu_item.connect('activate', self._on_options_item_activate)
        menu.append(options_menu_item)

        alarm_menu_item = Gtk.MenuItem("Alarms...")
        alarm_menu_item.connect('activate', self._on_alarm_item_activate)
        menu.append(alarm_menu_item)

        quit_menu_item = Gtk.MenuItem("Quit")
        quit_menu_item.connect('activate', Gtk.main_quit)
        menu.append(quit_menu_item)

        menu.show_all()
        return menu
项目:scripts-systems    作者:nomad-fr    | 项目源码 | 文件源码
def build_menu(menu):
    item_status = gtk.MenuItem('Status')
    #item_status.connect('activate', status)
    menu.append(item_status)
    item_status.set_sensitive(False)

    item_backup = gtk.MenuItem('Backup')
    item_backup.connect('activate', backup)
    menu.append(item_backup)

    item_gotobackup = gtk.MenuItem('Open remote backup folder')
    item_gotobackup.connect('activate', gotobackup)
    menu.append(item_gotobackup)

    item_quit = gtk.MenuItem('Quit')
    item_quit.connect('activate', quit)
    menu.append(item_quit)
    menu.show_all()
    return menu
项目:vpn_widget    作者:deccico    | 项目源码 | 文件源码
def build_menu(self):
        menu = gtk.Menu()
        item_status = gtk.MenuItem('Connect')
        item_status.connect('activate', self.connect)
        menu.append(item_status)
        item_status = gtk.MenuItem('Disconnect')
        item_status.connect('activate', self.disconnect)
        menu.append(item_status)
        item_status = gtk.MenuItem('Display Connection Status')
        item_status.connect('activate', self.get_status)
        menu.append(item_status)
        item_quit = gtk.MenuItem('Quit')
        item_quit.connect('activate', self.quit)
        menu.append(item_quit)
        menu.show_all()
        return menu
项目:PyFlowChart    作者:steelcowboy    | 项目源码 | 文件源码
def create_quarter_menu(self):
        quarter_menu = Gtk.Menu()

        for key in self.quarters:
            quarter_item = Gtk.MenuItem()
            button = Gtk.CheckButton.new_with_label(self.quarters[key])
            if not self.hidden[key*2]:
                button.set_active(True)

            quarter_key = key*2
            quarter_item.connect('activate', self.toggle_quarter, quarter_key)
            quarter_item.add(button)
            quarter_menu.append(quarter_item)

        quarter_menu.show_all()
        return quarter_menu
项目:testindicator    作者:logileifs    | 项目源码 | 文件源码
def make_menu(self, event_button, event_time):
        menu = gtk.Menu()

        # show about dialog
        about = gtk.MenuItem("About")
        about.show()
        menu.append(about)
        about.connect('activate', self.show_about_dialog)

        # add quit item
        quit = gtk.MenuItem("Quit")
        quit.show()
        menu.append(quit)
        quit.connect('activate', gtk.main_quit)

        menu.popup(None, None, None, None, event_button, event_time)
项目:XFWM_theme_creator    作者:Sjc1000    | 项目源码 | 文件源码
def __init__(self):
        Gtk.ScrolledWindow.__init__(self)
        self.view = Gtk.IconView()
        self.list = Gtk.ListStore(Pixbuf, str)
        self.view.set_model(self.list)
        self.view.set_pixbuf_column(0)
        self.view.set_text_column(1)
        self.view.set_activate_on_single_click(True)
        self.view.set_item_width(100)

        self.menu = Gtk.Menu()
        copy = Gtk.MenuItem('Copy')
        copy.connect('activate', self.copy)
        paste = Gtk.MenuItem('Paste')
        paste.connect('activate', self.paste)
        self.menu.append(copy)
        self.menu.append(paste)

        self.view.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.view.connect('button-press-event', self.show_menu)

        self.view.set_vexpand(True)
        self.view.set_hexpand(True)
        self.add(self.view)
        self.view.connect('item-activated', self.row_activated)
项目:shadowsocks-eos    作者:Simpleyyt    | 项目源码 | 文件源码
def load_servers(self):
        for child in self.server_submenu.get_children():
            self.server_submenu.remove(child)
        servers = self.config.get('configs', '[]')
        index = self.config.get('index', 0)
        group = []
        i = 0
        for server in servers:
            name = server['remarks'] + '(' + server['server'] + ':' + str(server['port']) + ')'
            item = Gtk.RadioMenuItem.new_with_label(group, name)
            item.connect('activate', self.server_activate, server, i)
            self.server_submenu.append(item)
            group = item.get_group()
            if i == index:
                item.set_active(True)
                self.server_activate(item, server, i)
            i = i + 1

        self.server_submenu.append(Gtk.SeparatorMenuItem())

        self.open_server_item = Gtk.MenuItem('???????...')
        self.open_server_item.connect('activate', self.show_server_setting)
        self.server_submenu.append(self.open_server_item)
        self.server_submenu.show_all()
项目:gpt    作者:encarsia    | 项目源码 | 文件源码
def on_treeview_button_release_event(self,widget,event):
        try:
            #define context menu
            popup=Gtk.Menu()
            kd_item=Gtk.MenuItem(_("Open with Kdenlive"))
            #selected row is already caught by on_treeview_selection_changed function
            kd_item.connect("activate",self.on_open_with_kdenlive,self.sel_folder)

            #don't show menu item if there are no video files
            if self.sel_vid > 0 and cli.kd_supp is True:
                popup.append(kd_item)

            open_item=Gtk.MenuItem(_("Open folder"))
            open_item.connect("activate",self.on_open_folder,self.sel_folder)
            popup.append(open_item)
            popup.show_all()
            #only show on right click
            if event.button == 3:
                popup.popup(None,None,None,None,event.button,event.time)
                return True
        except AttributeError:
            # this error (missing variable self.sel_folder) is returned when clicking on title row
            # ignoring because there is nothing to happen on right click
            return
项目:handsup    作者:stuartlangridge    | 项目源码 | 文件源码
def main():
    global indicator, menu
    indicator = appindicator.Indicator.new(APPINDICATOR_ID, os.path.abspath('closed.svg'), appindicator.IndicatorCategory.SYSTEM_SERVICES)
    indicator.set_status(appindicator.IndicatorStatus.ACTIVE)

    pubnub = set_up_pubnub()

    menu = gtk.Menu()
    item = gtk.MenuItem('Quit')
    item.connect('activate', die, pubnub)
    menu.append(item)
    menu.show_all()

    indicator.set_menu(menu)
    indicator.set_icon(os.path.abspath("closed.svg"))

    notify.init(APPINDICATOR_ID)

    GObject.timeout_add_seconds(1, check_caps, pubnub)
    gtk.main()
项目:k380-function-keys-conf-applet    作者:cook1e-monster    | 项目源码 | 文件源码
def build_menu():
    menu = gtk.Menu()

    ### item ###
    item_on = gtk.MenuItem('On') # menu label
    item_on.connect('activate', keyboard_on) #actions
    menu.append(item_on) #add menu

    ### item ###
    item_off = gtk.MenuItem('Off') # menu label
    item_off.connect('activate', keyboard_off) #actions
    menu.append(item_off) #add menu

    ### item ###
    item_quit = gtk.MenuItem('Quit') # menu label
    item_quit.connect('activate', quit) #actions
    menu.append(item_quit) #add menu

    menu.show_all()
    return menu

### execute binary script ###
项目:dockyard    作者:maidstone-hackspace    | 项目源码 | 文件源码
def __init__(self, listbox, dialog):
        """ pass in list box to manage and connect event """
        self.logs = LogWindow()
        self.listbox = listbox
        self.listbox.connect('row-activated', self.listbox_row_activated)

        self.menu = Gtk.Menu()
        menu_item0 = Gtk.MenuItem("Terminal")
        menu_item0.connect('button_press_event', self.open_terminal)
        self.menu.append(menu_item0)

        menu_item1 = Gtk.MenuItem("Show Logs")
        self.menu.append(menu_item1)
        menu_item1.connect('button_press_event', self.show_loged)

        menu_item2 = Gtk.MenuItem("Test")
        self.menu.append(menu_item2)

        self.confirm_dialog = dialog
项目:batterym    作者:maks-a    | 项目源码 | 文件源码
def build_menu(self):
        menu = gtk.Menu()

        item = gtk.MenuItem('Battery monitor')
        item.connect('activate', self.battery_monitor)
        menu.append(item)

        item = gtk.MenuItem('Toggle theme')
        item.connect('activate', self.toggle_theme)
        menu.append(item)

        item = gtk.MenuItem('Quit')
        item.connect('activate', self.quit)
        menu.append(item)

        menu.show_all()
        return menu
项目:nba-appindicator    作者:AdeleD    | 项目源码 | 文件源码
def create_menu(self):
        menu = Gtk.Menu()

        # NBA results items
        for game in self.nba_games:
            item = Gtk.MenuItem(game['score'])
            item.connect('activate', self.on_click, game['gameinfo_url'])
            menu.append(item)

        # Quit item
        item_quit = Gtk.MenuItem('Quit')
        item_quit.connect('activate', self.on_quit)
        menu.append(item_quit)

        menu.show_all()

        self.indicator.set_menu(menu)
项目:pokemon-go-status    作者:sousatg    | 项目源码 | 文件源码
def __init__(self, indicator_id='myappindicator'):
        self.APPINDICATOR_ID = indicator_id

        self.indicator = appindicator.Indicator.new( self.APPINDICATOR_ID, 'whatever', appindicator.IndicatorCategory.SYSTEM_SERVICES)
        self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)

        # Set Menu
        menu = gtk.Menu()
        item_quit = gtk.MenuItem('Quit')
        item_quit.connect('activate', self.quit)
        menu.show_all()
        self.indicator.set_menu( menu )


        self.update_server_status_icon()

        signal.signal( signal.SIGINT, signal.SIG_DFL )

        gtk.main()
项目:pomodoro-indicator    作者:atareao    | 项目源码 | 文件源码
def get_menu(self):
        """Create and populate the menu."""
        menu = Gtk.Menu()

        self.pomodoro_start = Gtk.MenuItem.new_with_label(_('Start'))
        self.pomodoro_start.connect('activate', self.on_pomodoro_start)
        self.pomodoro_start.show()
        menu.append(self.pomodoro_start)

        self.pomodoro_restart = Gtk.MenuItem.new_with_label(_('Re-start'))
        self.pomodoro_restart.connect('activate', self.on_pomodoro_restart)
        self.pomodoro_restart.show()
        menu.append(self.pomodoro_restart)

        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)
项目:budgie-extras    作者:UbuntuBudgie    | 项目源码 | 文件源码
def create_menu(self):
        message = Gtk.MenuItem('Starting up...')
        self.menu.append(message)
        self.menu.show_all()
        self.popup = self.menu
        self.appbutton.connect('clicked', self.popup_menu)
项目:budgie-extras    作者:UbuntuBudgie    | 项目源码 | 文件源码
def edit_menu(self):
        for i in self.menu.get_children():
            self.menu.remove(i)
        for m in self.newmenu:
            add = Gtk.MenuItem(m)
            add.connect('activate', self.get_choice)
            self.menu.append(add)
        # fake separator
        self.menu.append(Gtk.MenuItem(''))
        newspace = Gtk.MenuItem('+')
        newspace.connect('activate', self.add_space)
        self.menu.append(newspace)
        self.change_onthefly()
        self.menu.show_all()
项目:budgie-extras    作者:UbuntuBudgie    | 项目源码 | 文件源码
def edit_menu2(self):
        for i in self.menu.get_children():
            self.menu.remove(i)
        for m in self.newmenu:
            ws = str(m[0] + 1)
            space = Gtk.MenuItem(ws)
            self.menu.append(space)
            if m[1]:
                # flattened submenu
                self.submenu = Gtk.Menu()
                for l in [d for d in m[1]]:
                    app = l[0]
                    wins = [[it[0], it[1]] for it in l[1]]
                    for w in wins:
                        name = self.shortname(w[0]) + "  -  " + app
                        winmention = Gtk.MenuItem(name)
                        self.submenu.append(winmention)
                        winmention.connect('activate', self.move_to, w[1])
                space.set_submenu(self.submenu)
            else:
                space.connect('activate', self.get_choice)
        # fake separator
        self.menu.append(Gtk.MenuItem(''))
        newspace = Gtk.MenuItem('+')
        newspace.connect('activate', self.add_space)
        self.menu.append(newspace)
        self.change_onthefly()
        self.menu.show_all()
项目:budgie-extras    作者:UbuntuBudgie    | 项目源码 | 文件源码
def change_onthefly(self):
        modesep = Gtk.SeparatorMenuItem()
        self.menu.add(modesep)
        mode_mention = Gtk.MenuItem("Mode")
        applet_modes = Gtk.Menu()
        active = modes.index(self.mode)
        self.mode_index = active
        self.menulist = ["      " + m for m in modes]
        self.menulist[active] = "? " + str(modes[active]) + ""
        for item in self.menulist:
            md = Gtk.MenuItem(item)
            md.connect('activate', self.set_mode, item)
            applet_modes.append(md)
        mode_mention.set_submenu(applet_modes)
        self.menu.add(mode_mention)
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def __init__(self, callback):
        Gtk.Menu.__init__(self)
        for idx, pname in enumerate(soundcard.percussion_names):
            menuitem = Gtk.MenuItem(pname)
            menuitem.connect('activate', callback, idx)
            self.append(menuitem)
            menuitem.show()
        self.show()
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def popup_alsa_connection_list(self, widget):
        connection_list = soundcard.alsa_sequencer.get_connection_list()
        if connection_list:
            menu = Gtk.Menu()
            for clientid, portid, clientname, portname, labeltext in connection_list:
                item = Gtk.MenuItem(labeltext)
                menu.append(item)

                def ff(widget, clientid, portid):
                    self.g_alsa_device.set_label(widget.get_child().get_text())
                    self.m_gui_client_port = (clientid, portid)
                    self.g_alsa_radio.set_active(True)
                item.connect('activate', ff, clientid, portid)
            menu.show_all()
            menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def _menu_hide_stuff(self, menu):
        """
        Hide the menu if it has no menu items, or all menu items are hidden.
        """
        for sub in menu.get_children():
            assert isinstance(sub, Gtk.MenuItem)
            if sub.get_submenu():
                self._menu_hide_stuff(sub.get_submenu())

                if not [c for c in sub.get_submenu().get_children() if c.get_property('visible')]:
                    sub.hide()
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def __init__(self, callback):
        Gtk.Menu.__init__(self)
        self.m_callback = callback
        for x in range(len(soundcard.instrument_names)):
            if x % 8 == 0:
                menuitem = Gtk.MenuItem(soundcard.instrument_sections[x/8])
                submenu = Gtk.Menu()
                self.append(menuitem)
                menuitem.set_submenu(submenu)
                menuitem.show()
            item = Gtk.MenuItem(soundcard.instrument_names[x])
            item.connect('activate', self.on_activate, x)
            submenu.append(item)
            item.show()
        self.show()
项目:ircalendar-indicator    作者:733amir    | 项目源码 | 文件源码
def menu():
    m = Gtk.Menu()
    item_quit = Gtk.MenuItem('Quit')
    item_quit.connect('activate', Gtk.main_quit)
    m.append(item_quit)
    m.show_all()
    return m
项目:MokaPlayer    作者:vedard    | 项目源码 | 文件源码
def __create_playlist_menus(self):
        for child in self.menuchild_gridview_playlist.get_children():
            self.menuchild_gridview_playlist.remove(child)

        for child in self.listbox_playlist.get_children():
            self.listbox_playlist.remove(child)

        self.listbox_playlist.add(self.__create_sidebar_header('Library'))
        self.listbox_playlist.add(self.__create_sidebar_row(SongsPlaylist()))
        self.listbox_playlist.add(self.__create_sidebar_row(AlbumsPlaylist()))
        self.listbox_playlist.add(self.__create_sidebar_row(ArtistsPlaylist()))
        self.listbox_playlist.add(self.__create_sidebar_row(UpNextPlaylist(self.player.queue)))
        self.listbox_playlist.add(self.__create_sidebar_row(MostPlayedPlaylist()))
        self.listbox_playlist.add(self.__create_sidebar_row(RarelyPlayedPlaylist()))
        self.listbox_playlist.add(self.__create_sidebar_row(RecentlyPlayedPlaylist()))
        self.listbox_playlist.add(self.__create_sidebar_row(RecentlyAddedPlaylist()))
        self.listbox_playlist.add(self.__create_sidebar_header('Playlists'))

        for playlist in self.player.library.get_playlists():
            menu_item = Gtk.MenuItem(label=playlist.name)
            menu_item.connect('activate', self.on_menu_gridview_add_to_playlist_activate,
                              playlist, self.menu_gridview)
            self.menuchild_gridview_playlist.append(menu_item)
            self.listbox_playlist.add(self.__create_sidebar_row(playlist))

        self.menuchild_gridview_playlist.show_all()
        self.listbox_playlist.show_all()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def hex_view_populate_popup(self, textview, popup):
        disassemble_item = Gtk.MenuItem('Disassemble')
        disassemble_item.connect('activate', self.disassemble_item_activate)
        separator = Gtk.SeparatorMenuItem()
        popup.prepend(separator)
        popup.prepend(disassemble_item)
        separator.show()
        disassemble_item.show()
项目:sony-av-indicator    作者:aschaeffer    | 项目源码 | 文件源码
def create_menu_item(self, menu, name, cmd):
        item = gtk.MenuItem(name)
        item.connect("activate", self.command_service.send_command_w, cmd)
        menu.append(item)
项目:nvidia-multiple-smi    作者:ClementPinard    | 项目源码 | 文件源码
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
项目:cryptobar    作者:akibabu    | 项目源码 | 文件源码
def submenu(submenu, title):
    submenu.show_all()
    menu = gtk.MenuItem(title)
    menu.set_submenu(submenu)
    return menu
项目:cryptobar    作者:akibabu    | 项目源码 | 文件源码
def menu_quit():
    menu = gtk.Menu()
    item_quit = gtk.MenuItem('Quit')
    item_quit.connect('activate', lambda x: gtk.main_quit())
    return item_quit
项目:CowNewsReader    作者:blediboss    | 项目源码 | 文件源码
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()
项目:ScreenRotator    作者:frecel    | 项目源码 | 文件源码
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
项目:ridinghood    作者:Aeva    | 项目源码 | 文件源码
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)
项目:ridinghood    作者:Aeva    | 项目源码 | 文件源码
def add_item(self, name, handler):
        """
        Add a new menu item.
        """
        item = Gtk.MenuItem(name)
        item.connect("activate", handler)
        self.menu.append(item)
项目:nepali-calendar-indicator    作者:techgaun    | 项目源码 | 文件源码
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
项目:ExpressGui    作者:mattbruning    | 项目源码 | 文件源码
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)
项目:hubangl    作者:soonum    | 项目源码 | 文件源码
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
项目:sleep-inhibit    作者:mssever    | 项目源码 | 文件源码
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)
项目:handsup    作者:stuartlangridge    | 项目源码 | 文件源码
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))
项目:gstation-edit    作者:fengalin    | 项目源码 | 文件源码
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')
项目:KeyCat    作者:KatreMetsvahi    | 项目源码 | 文件源码
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
项目:mate-menu    作者:ubuntu-mate    | 项目源码 | 文件源码
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)
项目:furi-kura    作者:benjamindean    | 项目源码 | 文件源码
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()
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
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
项目:backlight-indicator    作者:atareao    | 项目源码 | 文件源码
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)
项目:PyFlowChart    作者:steelcowboy    | 项目源码 | 文件源码
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()
项目:testindicator    作者:logileifs    | 项目源码 | 文件源码
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)