示例#1
0
def test_method_info():
    def example_func():
        pass

    cc = menus.ContextCommand('Test Command', python=example_func)
    func_name, func_file_name, func_dir_path = cc.get_method_info()
    assert func_name == 'example_func' and func_file_name == 'test_menus' and get_last_path_item(
        func_dir_path) == 'tests'
def install_menus(arguments: argparse.Namespace) -> int:
    """
    Installs Beancounttant context menus.
    """
    beancounttant_menu = menus.ContextMenu(MENU_TITLE, type=MENU_TYPE)
    beancounttant_menu.add_items([
        menus.ContextCommand('Generate Transaction',
                             params=Path(arguments.config_file).as_posix(),
                             python=generate_transaction)])
    beancounttant_menu.compile()
    return 0
示例#3
0
def test_command_func():
    nm = linux_menus.NautilusMenu(
        fc.name,
        [menus.ContextCommand(fc.name, command=fc.command, python=fc.python)],
        fc.type)
    lm = nm.generate_command_func(fc.command)
    valid_func = '''
\tdef method_handler0(self, menu, files):
\t\tos.system('echo hello > example.txt')\n
'''
    assert valid_func == lm.code
示例#4
0
def test_build_script_body():
    nm = linux_menus.NautilusMenu(
        fc.name,
        [menus.ContextCommand(fc.name, command=fc.command, python=fc.python)],
        fc.type)
    nm.build_script()
    valid_commands = [
        'menuitem0 = Nautilus.MenuItem(name = "ExampleMenuProvider::TestCommand", label="TestCommand", tip = "", icon = "")',
        'submenu1 = Nautilus.Menu()', 'menuitem0.set_submenu(submenu1)',
        'menuitem2 = Nautilus.MenuItem(name = "ExampleMenuProvider::TestCommand", label="TestCommand", tip = "", icon = "")',
        'menuitem2.connect("activate", self.method_handler3, files)',
        'submenu1.append_item(menuitem2)', 'return menuitem0,'
    ]

    print(nm.commands)
    print()
    print(valid_commands)
    assert nm.commands == valid_commands
示例#5
0
def foo2(filenames):
    print('foo2')
    print(filenames)
    input()


def foo3(filenames):
    print('foo3')
    print(filenames)
    input()


if __name__ == '__main__':
    from context_menu import menus

    cm = menus.ContextMenu('Foo menu', type='FILES')
    cm2 = menus.ContextMenu('Foo Menu 2')
    cm3 = menus.ContextMenu('Foo Menu 3')
    cm3.add_items([
        menus.ContextCommand('Foo One', command='echo hello > example.txt'),
    ])
    cm2.add_items([
        menus.ContextCommand('Foo Two', python=foo2),
        cm3,
    ])
    cm.add_items([cm2, menus.ContextCommand('Foo Three', python=foo3)])
    cm.compile()