indicator-keyboard-led.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:indicator-keyboard-led 作者: adrianiainlam 项目源码 文件源码
def create_menu(self, xdotool, order):
        menu = Gtk.Menu()
        xdotool = xdotool or shutil.which('xdotool')
        if xdotool and os.access(xdotool, os.X_OK) and os.path.isfile(xdotool):
            def send_keypress(menuitem, keystroke):
                subprocess.call([xdotool, 'key', keystroke])
            def new_menu_item(itemtype):
                if itemtype == 'N':
                    item = Gtk.MenuItem.new_with_label(_('Num Lock'))
                    item.connect('activate', send_keypress, 'Num_Lock')
                elif itemtype == 'C':
                    item = Gtk.MenuItem.new_with_label(_('Caps Lock'))
                    item.connect('activate', send_keypress, 'Caps_Lock')
                elif itemtype == 'S':
                    item = Gtk.MenuItem.new_with_label(_('Scroll Lock'))
                    item.connect('activate', send_keypress, 'Scroll_Lock')
                else:
                    raise ValueError('Invalid itemtype')
                return item

            for i in order:
                menu.append(new_menu_item(i))
            menu.append(Gtk.SeparatorMenuItem())

        quit_item = Gtk.MenuItem.new_with_label(_('Quit'))
        menu.append(quit_item)
        quit_item.connect('activate', Gtk.main_quit)

        self.indicator.set_menu(menu)
        menu.show_all()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号