context_menu package

Submodules

context_menu.example module

context_menu.linux_menus module

class context_menu.linux_menus.CodeBuilder(body_commands: list, script_dirs: list, funcs: list, imports: list, type: str)

Bases: object

The CodeBuilder class is used for generating the final python file for the Linux menus.

build_imports()

Creates the header of necessary imports.

Handled automatically by compile.

build_script_dirs()

Creates the header of necessary path configurations.

Adds all the ‘sys.path.appends’ in order to immport the classes and functions.

Handled automatically by compile.

compile()

Creates the code file.

class context_menu.linux_menus.ExistingCode

Bases: enum.Enum

Preset values important for metaprogramming.

BACKGROUND_ITEMS = '\tdef get_background_items(self, window, files):'
CLASS_TEMPLATE = '\nclass ExampleMenuProvider(GObject.GObject, Nautilus.MenuProvider):\n\tdef __init__(self):\n\t\tpass\n'
CODE_HEAD = "\nimport gi\nimport sys\nimport os\n\ngi.require_version('Nautilus', '3.0')\n\nfrom gi.repository import Nautilus, GObject\n\n# -------------------------------------------- #\n\ntry:\n\tfrom urllib import unquote\nexcept ImportError:\n\tfrom urllib.parse import unquote\n "
COMMAND_HANDLER_TEMPLATE = "\n\tdef {}(self, menu, files):\n\t\tfilepath = [unquote(subFile.get_uri()[7:]) for subFile in files][0]\n\t\tos.system('{}'{})\n\n"
FILE_ITEMS = '\tdef get_file_items(self, window, files):'
MENU_ITEM = 'menuitem{} = Nautilus.MenuItem(name = "ExampleMenuProvider::{}", label="{}", tip = "{}", icon = "{}")'
METHOD_HANDLER_TEMPLATE = '\n\tdef {}(self, menu, files):\n\t\tfilenames = [unquote(subFile.get_uri()[7:]) for subFile in files]\n\t\t{}.{}({}, "{}")\n\n'
SUB_MENU = 'submenu{} = Nautilus.Menu()'
class context_menu.linux_menus.NautilusMenu(name: str, sub_items: list, type: str)

Bases: object

append_item(menu: str, item: str)

Creates a necssary body_command.

build_script()

Finishes and returns the full code.

build_script_body(name: str, items: list)

Builds the body commands of the script.

compile()

Creates the code, creates a file, and moves it to the correct location.

connect(item: str, func: str)

Creates a necssary body_command.

create_path(path: str, dir: str)

Creates a path to directory. Creates all sub-directories

generate_command_func(command: str)

Generates a command attached to a python function

generate_item(name: str)

Generates a nautilus command variable.

generate_menu()

Generates a nautilus menu variable.

generate_mod_command_func(command: str, command_vars: list)

Generates a command attached to a python function that allows special variables.

generate_python_func(class_origin: str, class_func: str, params: str)

Generates a command attached to a python function

get_next_item()

Very niche, required in other methods.

set_submenu(item: str, menu: str)

Creates a necssary body_command.

class context_menu.linux_menus.Variable(name: str, code: str)

Bases: object

Very simple class with no methods to help simplify the code.

context_menu.linux_menus.command_var_format(item: str)

Converts a python string to a value for a command

context_menu.linux_menus.remove_linux_menu(name)

context_menu.menus module

class context_menu.menus.ContextCommand(name: str, command: str = None, python: function = None, params: str = '', command_vars: list = None)

Bases: object

The general command class.

A command is an executable entry in a context-menu, where menus hold other commands.

Name = Name of the command Command = command to be ran from the shell python = function to be ran params = any other parameters to be passed command_vars = to help with the command

get_method_info() -> ('function name', 'function file name', 'path to function directory')

Extremely important for making shell commands to run python code.

Returns a tuple.

get_platform_command()

Will be used in future changes.

class context_menu.menus.ContextMenu(name: str, type: str = None)

Bases: object

The general menu class. This class generalizes the menus and eventually passes the correct values to the platform-specifically menus.

add_items(items: list)

Adds a list of items to the current menu.

compile()

Recognizes the current platform and passes information to the respective menu. Creates the actual menu.

class context_menu.menus.FastCommand(name: str, type: str, command: str = None, python: function = None, params: str = '', command_vars: list = None)

Bases: object

Used for fast creation of a command. Good if you don’t want to get too involved and just jump start a program.

Extremely similar methods to other classes, only slightly modified. View the documentation of the above classes for info on these methods.

compile()
get_method_info()
context_menu.menus.removeMenu(name: str, type: str)

Removes a menu/command entry from a context menu.

Requires the name of the menu and type of the menu

context_menu.windows_menus module

class context_menu.windows_menus.FastRegistryCommand(name: str, type: str, command: str, python: function, params: str, command_vars: list)

Bases: object

Fast command class.

Everything is identical to either the RegistryMenu class or code in the menus file

compile()
get_method_info()
class context_menu.windows_menus.RegistryMenu(name: str, sub_items: list, type: str)

Bases: object

Class to convert the general menu from menus.py to a Windows-specific menu.

compile(items: list = None, path: str = None)

Used to create the menu. Recursively iterates through each element in the top level menu.

create_command(name: str, path: str, command: str)

Creates a key with a command subkey with the ‘name’ and ‘command’, at path ‘path’.

create_menu(name: str, path: str) → Path to shell key of new menu

Creates a menu with the given name and path.

Used in the compile method.

context_menu.windows_menus.command_preset_format(item: str) → Path to desired python type

Converts a python string to an executable location.

For example, ‘python’ -> sys.executable

context_menu.windows_menus.command_var_format(item: str)

Converts a python string to a value for a command

context_menu.windows_menus.context_registry_format(item: str) → registry path to the desired type

Converts a verbose type into a registry path.

For example, ‘FILES’ -> ‘SoftwareClasses*shell’

context_menu.windows_menus.create_directory_background_command(func_name: str, func_file_name: str, func_dir_path: str, params: str) → Registry valid string to call python function

Creates a registry valid command to link a context menu entry to a funtion, specifically for backgrounds(DIRECTORY_BACKGROUND, DESKTOP_BACKGROUND).

Requires the name of the function, the name of the file, and the path to the directory of the file.

context_menu.windows_menus.create_file_select_command(func_name: str, func_file_name: str, func_dir_path: str, params: str) → Registry valid string to call python function

Creates a registry valid command to link a context menu entry to a funtion, specifically for file selection(FILES, DIRECTORY, DRIVE).

Requires the name of the function, the name of the file, and the path to the directory of the file.

context_menu.windows_menus.create_shell_command(command: str, command_vars: list) → Shell command

Creates a shell command and replaces ‘?’ with the command_vars list

context_menu.windows_menus.remove_windows_menu(name: str, type: str)

Removes a context menu from the windows registry.

Module contents