pymenu.ext.pyxdg package

class pymenu.ext.pyxdg.Application(entry, parser=None, term_args=None)[source]

Bases: object

A launchable application defined by a XDG desktop entry.

Parameters:
  • entry (xdg.Menu.MenuEntry) – The desktop entry for this application.
  • parser (Callable) –

    A function that parses an Exec string of a desktop entry and returns an abstract syntax tree (AST) of it. The AST is expected to be made of lists and have the following structure (given the input app arg1 arg2):

    [
        ['a', 'p', 'p'],
        [
            ['a', 'r', 'g', '1'],
            ['a', 'r', 'g', '2']
        ]
    ]
    

    The default parser should work in most cases.

  • term_args (list) –

    Command line argument prefixes for terminal applications. In XDG compliant desktop environments, the default (['x-terminal-emulator', '-e']) should be enough since it work on any setup that implements the Debian Alternatives System which is common in many UNIX distributions and most popular desktop environments.

    If you do not use this from of a XDG compliant environment (in Qtile, for instance) you will need to set this manually.

arguments

Provide the command line arguments for this application.

Some (%i, %c, %k) fieldcode placeholders are replaced. Target-like fieldcodes placeholders like %f, %F, %u and %U are not replaced.

Returns:list
entry
executable

Provide the command line executables part for this application.

This may include terminal-specific executables and arguments, such as ['x-terminal-emulator', '-e'] in addition to the actual executable if this is a terminal application.

Returns:list
launch(*target_uris, **popen_kwargs)[source]

Launch this application with provided targets.

Parameters:
  • *target_uris – Positional arguments are used as URI targets for this application. If this application can handle multiple URIs at once, they are all parametrized in one subprocess. If this application can only handle one URI at a time, multiple processes are launched. If this application cannot handle target URIs, this argument is ignored.
  • **popen_kwargs – This application is launched as subprocesses using subprocess.Popen. These keyword arguments are simply passed along to this subprocess constructor.
Returns:

All subprocesses launched.

Return type:

list

class pymenu.ext.pyxdg.XdgMenuEntry(wrapped_entry, app_factory=None, parent=None)[source]

Bases: pymenu.MenuEntry

Wrap an XDG menu entry.

Parameters:

See also

xdg.Menu.Menu

classmethod from_xdg_menu_file(menu_def_file)[source]

Constructor for a .menu file.

pymenu.ext.pyxdg.exec_parser(exec_string)[source]

Make the AST for a XDG Exec string.

Parameters:exec_string (str) –
Returns:AST
Return type:list
pymenu.ext.pyxdg.launch_xdg_menu_entry(entry, *targets)[source]

A convenient launcher for desktop entries.

This uses the Application with default values.

Parameters:entry (xdg.Menu.MenuEntry) –
Returns:None
pymenu.ext.pyxdg.make_xdg_menu_entry(menu_def_file=None, cls=None)[source]

Make a pymenu.MenuEntry based on a XDG .menu file.

This is usually located in /etc/xdg/menus/applications.menu.

Parameters:
  • menu_def_file (str) –

    Path to a .menu file as defined in the Desktop Menu Specification. Defaults to /etc/xdg/menus/applications.menu

    This file can usually be found in the /etc/xdg/menus folder. The following command is a good start to list these .menu files:

    These .menu file may not include applications that installed their desktop entries in a user folder such as ~/.local/share/applications. In order to add additional directories to the desktop entries search path, you need to add a <AppDir> tag to the .menu file for the relevant directory.

  • cls (type) – The subclass of pymenu.MenuEntry to create. The default is XdgMenuEntry.

See also

pymenu.MenuEntry