All Projects → saleguas → Context_menu

saleguas / Context_menu

Licence: mit
💻 A Python library to create and deploy cross-platform native context menus. 💻

Programming Languages

python
139335 projects - #7 most used programming language
metaprogramming
66 projects

Projects that are alternatives of or similar to Context menu

rctx-contextmenu
✨ Context menu for React
Stars: ✭ 23 (-91.25%)
Mutual labels:  contextmenu
Registry Monitor
A Windows script to monitor registry hives for modifications & notify you when modifications have occured.
Stars: ✭ 19 (-92.78%)
Mutual labels:  registry
crm
Cargo registry manager (Cargo 注册表管理器),用于方便的管理和更换 Rust 国内镜像源
Stars: ✭ 103 (-60.84%)
Mutual labels:  registry
unit-converter
Convert standard units from one to another with this easy to use, lightweight package
Stars: ✭ 104 (-60.46%)
Mutual labels:  registry
Vutils
Vutils or Vic Utilities is an utility library written in Modern C++ and for Modern C++. It helps your programming go easier, faster, and simpler.
Stars: ✭ 16 (-93.92%)
Mutual labels:  registry
registry-js
A simple and opinionated library for working with the Windows registry
Stars: ✭ 105 (-60.08%)
Mutual labels:  registry
justContext.js
Styleable context menu in pure JS (no jQuery).
Stars: ✭ 78 (-70.34%)
Mutual labels:  contextmenu
Blazorcontextmenu
A context menu component for Blazor !
Stars: ✭ 257 (-2.28%)
Mutual labels:  contextmenu
charts
This repository is home to the original helm charts for products throughout the open data platform ecosystem.
Stars: ✭ 39 (-85.17%)
Mutual labels:  registry
roadmap
Public roadmap for npm
Stars: ✭ 215 (-18.25%)
Mutual labels:  registry
nnrm
🔧 New nrm (NPM registry manager). Use smaller dependencies.
Stars: ✭ 55 (-79.09%)
Mutual labels:  registry
feedback
Public feedback discussions for npm
Stars: ✭ 91 (-65.4%)
Mutual labels:  registry
available-versions
Returns a promise with new versions higher than given for a npm module
Stars: ✭ 18 (-93.16%)
Mutual labels:  registry
WindowsRegistry
Windows Registry Tweaks & Hacks
Stars: ✭ 31 (-88.21%)
Mutual labels:  registry
jsPanel3
A jQuery Plugin to create highly configurable floating panels, modals, tooltips, hints/notifiers or contextmenus for use in a backend solution and other web applications.
Stars: ✭ 89 (-66.16%)
Mutual labels:  contextmenu
singularityhub.github.io
Container tools for scientific computing! Docs at https://singularityhub.github.io/singularityhub-docs
Stars: ✭ 68 (-74.14%)
Mutual labels:  registry
dashboard
Interactive UI for analyzing Jina logs, designing Flows and viewing Hub images
Stars: ✭ 105 (-60.08%)
Mutual labels:  registry
Open Registry
Community Owned JavaScript Registry
Stars: ✭ 259 (-1.52%)
Mutual labels:  registry
Dubbo3
Dubbo3: distributed RPC framework from Alibaba Dubbo2
Stars: ✭ 257 (-2.28%)
Mutual labels:  registry
elm-contextmenu
Flexible context menu for Elm
Stars: ✭ 16 (-93.92%)
Mutual labels:  contextmenu

💻 context_menu 💻

A Python library to create and deploy cross-platform native context menus.

build passing readthedocs pip python version


example usage

Quickstart

  1. Install the library via pip:

    python -m pip install context_menu

  2. Create and compile the menu:

  • You can create menus in as little as 3 lines:
    from context_menu import menus
    fc = menus.FastCommand('Example Fast Command 1', type='FILES', command='echo Hello')
    fc.compile()
    
  • Or you can create much more complicated nested menus:
        def foo2(filenames, params):
            print('foo2')
            print(filenames)
            input()

        def foo3(filenames, params):
            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()
  1. See the output!
  • First example

    first Example

  • Second example

    second Example

Detailed Usage

ContextMenu Class

The ContextMenu object holds other context objects. It expects a name, and the activation type if it is the root menu(the first menu). Only compile the root menu.

ContextMenu(name: str, type: str = None)

Menus can be added to menus, creating cascading context menus. You can use the {MENU}.add_items{ITEMS} function to add context elements together, for example:

cm = menus.ContextMenu('Foo menu', type='DIRECTORY_BACKGROUND')
cm.add_items([
    menus.ContextMenu(...),
    menus.ContextCommand(...),
    menus.ContextCommand(...)
])
cm.compile()

You have to call {MENU}.compile() in order to create the menu.

ContextCommand Class

The ContextCommand class creates the selectable part of the menu (you can click it). It requires a name, and either a Python function or a command (but NOT both) and has various other options

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

Python functions can be passed to this method, regardless of their location. However, the function must accept only two parameters filenames, which is a list of paths*, and params, the parameters passed to the function. and if the function is in the same file as the menu, you have to surround it with if __name__ == '__main__':

Any command passed (as a string) will be directly ran from the shell.

FastCommand Class

The FastCommand class is an extension of the ContextMenu class and allows you to quickly create a single entry menu. It expects a name, type, and command/function.

FastCommand(name: str, type: str, command: str = None, python: 'function' = None, params: str = '', command_vars: list = None)
def foo1(filenames, params):
    print(filenames)
    input()

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

    fc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1)
    fc.compile()

Admin privileges are required on windows, as it modifies the Registry. The code will automatically prompt for Admin rights if it is not sufficiently elevated.

Advanced Usage

removeMenu method

You can remove a menu easily as well. Simply call the 'menus.removeMenu()' method.

removeMenu(name: str, type: str)

For example, if I wanted to remove the menu 'Foo Menu' that activated on type 'FILES':

from context_menu import menus

menus.removeMenu('Foo Menu', 'FILES')

params Command Parameter

In both the ContextCommand class and FastCommand class you can pass in a parameter, defined by the parameter=None variable. This value MUST be a string! This means instead of passing a list or numbers, pass it as a string separated by spaces or whatever to delimitate it.

fc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1, params='a b c d e')
fc.compile()

For more information, see this.

Works on the FastCommand and ContextCommand class.

command_vars Command Parameter

If you decide to pass a shell command, you can access a list of special variables. For example, if I wanted to run a custom command with the file selected, I could use the following:

fc = menus.FastCommand('Weird Copy', type='FILES', command='touch ?x', command_vars=['FILENAME'])
fc.compile()

which would create a new file with the name of whatever I selected with an 'x' on the end. The ? variable is interpreted from left to right and replaced with the selected values (see this).

All of the preset values are as follows:

Name Function
FILENAME The path to the file selected
DIR/DIRECTORY The directory the script was ran in.
PYTHONLOC The location of the python interpreter.

Works on the FastCommand and ContextCommand class.

Opening on Files

Simply pass the extension of the file you want to open onto when creating the menu.

fc = menus.FastCommand('Weird Copy', type='.txt', command='touch ?x', command_vars=['FILENAME']) # opens on .txt files
fc.compile()

Check out the examples folder for more complicated examples.

Types

There are different locations where a context menu can fire (if you right click on a folder you'll get different options then if you right click on a file). The type variable controls this behavior in the library, and you can reference this table to determine the type:

Name Location Action
FILES HKEY_CURRENT_USER\Software\Classes\*\shell\ Opens on a file
DIRECTORY HKEY_CURRENT_USER\Software\Classes\Directory\shell Opens on a directory
DIRECTORY_BACKGROUND HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell Opens on the background of the Directory
DRIVE HKEY_CURRENT_USER\Software\Classes\Drive\shell Opens on the drives(think USBs)

Important notes

  • The code can sometimes be really weird when it comes to admin rights on Windows. The compile() method will automatically prompt for admin rights if required, but this can cause issues sometimes. Admin rights no longer required as of version 1.2.0.

  • Almost all of the errors I've encountered in testing were when the code and the functions were in the same file. You should make a separate file for the code or surround it with if __name__ == '__main__':.

Feel free to check out a file sorter I made that implements very complex usage of this library.

You can check out the official documentation here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].