GithubHelp home page GithubHelp logo

context-menu-maker's Introduction

context-menu-maker

A program that makes Windows context menus from YAML files. It's extremely customizable, and easy to use.

Demo Image

Install

Just download the contents of this repository and place them in a location that shouldn't change much. I used C:\Python36\Scripts\context-menu-maker.

Usage

Example

Consider the following snippet:

name: 'settings'
title: 'Settings'
exists: [^folder]
tree:
	control-panel:
    	title: 'Control Panel'
        icon:
        	handler: 'exefile'
            executable: 'control.exe'
        action: 'control.exe'
    other-options:
    	title: 'Other...'
        icon: 'C:\insert_icon_file_here.ico'
        tree:
        	reg:
            	title: 'Registry Editor'
                icon:
                	handler: 'exefile'
                    executable: 'regedit.exe'
                action: 'regedit.exe'

When installed, right clicking on a folder and then clicking on a button entitled "Settings" would produce a context menu that looks like this:

Example Image

Syntax

Header

Each menu descriptor file always includes a 'name', 'title', and 'exists' field at the top.

Name

The 'name' field describes the internal name that the menu shall assume in Windows. It's used for placing the correct registry keys. Give it a simple name (preferably without spaces)

Title

This field describes the external name (or, rather, 'verb' as given by MSDN) that your context menu will use. It's the name that shows up in Explorer's context menu.

Exists

This field is a bit more complicated. It describes if your context menu will show up depending on what you click on/where you click. For example: exists: [^allfiles] would tell Explorer that your context menu can be triggered off of any file (the context menu produced by right clicking a file will have your menu on it). This does not include directories.

There are multiple things that you can put in your exists section; here they are:

Name Location
^allfiles Every file type
^desktop Files on the desktop
^directory Not sure, but it's in the registry. Will have to figure out what this does.
^directoryba Same as above, but the background.
^folder Any folder
^folderba The background of an open folder window
^drive Any drive
^driveba The background of an open drive window
^everything All of the above

Additionally, you can specify single file types that you wish to include: exists: [doc, pdf, jpg]

Icon

This field provides an icon that will be shown in the context menu; note that it cannot use a handler (mentioned later); it must be a pointer to a file containing the icon that you wish to use.

Handlers

Handlers is a term I've used to describe a piece of code that modifies the menu in a specific way. Vague, I know. Here's an example:

icon:
	handler: exefile
    executable: 'C:\Windows\System32\regedit.exe'

It uses a handler called "exefile", which pulls an icon from an executable file. It has different functionality than the default icon field behavior, which normally loads an icon from a given file.

Handlers are useful when an action is more efficiently completed by using a method other than the default behavior.

Tree

Creating nested context menus is done by traversing the tree field in the .yml file. Items in the tree can have actions (an action object), or another tree (a submenu). You can name them whatever you want; the program doesn't use the name.

Objects

Objects in the tree have properties that must be fulfulled in order for the object to display correctly. These properties can use certain handlers that provide resources in certain ways. For example, an icon handler might take an icon from a provided .exe file. Using handlers helps create better customizability and gives the user a lot of power to create their own options easily.

In the tree, objects are defined as sub-fields:

tree:
	object-action:
    	...
    object-submenu:
    	tree:
        	object-action-nested:
            	...
            object-submenu-nested:
            	...
Action objects

These objects are displayed as buttons in the context menu; pressing them launches an action, as opposed to displaying a submenu. To make an action, one must add an object with a field entitled action:

tree:
	object-action:
    	action: 'C:\Windows\System32\regedit.exe'
        ...

An action can have a handler associated with it. For more information on handlers, jump to the "handlers" section above.

Submenu objects

Submenu objects are simpler. They must contain a tree field, which, in turn, includes other objects, be they actions or more submenus:

tree:
	object-submenu:
    	tree:
        	object-action:
            	...
            object-submenu:
            	tree:
                	...

Shared properties

The title field and the icon (optional) field can be used on both submenu and action objects. The title field gives an external name to the object (the name that the end user will see in the context menu), and the icon field obviously gives the icon to be used for that particular object.

Installation

Context menus are installed once, and can always be uninstalled.

To install a context menu from a .yml file, run at an administrative command prompt:

C:\path_to_python\python.exe C:\path_to_main.py C:\path_to_yml_file install

To install the example .yml, the command would be something like this (at least, for me):

C:\Python36\python.exe C:\Python36\Scripts\context-menu-maker\main.py C:\Users\me\context-menus\example.yml install

To uninstall a context menu, simply run the install command and substitute "install" with "remove".

C:\path_to_python\python.exe C:\path_to_main.py C:\path_to_yml_file remove

To test a context menu:

C:\path_to_python\python.exe C:\path_to_main.py C:\path_to_yml_file run

context-menu-maker's People

Contributors

mnurzia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

context-menu-maker's Issues

Error when installing menu. TypeError: load() missing 1 required positional argument: 'Loader'

Getting the following error when installing a menu:

Traceback (most recent call last): File "C:\Tools\Context Menu Maker\main.py", line 12, in <module> condocp = ContextDocParser(open(sys.argv[1],'r'),os.path.realpath(__file__)) File "C:\Tools\Context Menu Maker\contextdocparser.py", line 13, in __init__ self.documentObject = yaml.load(document) TypeError: load() missing 1 required positional argument: 'Loader'

Had to install pyyaml and win32api as well beforehand.

Not sure how to proceed here.

YAML depreciated warning, and a WNDPROC error. Is it possible to pass %1?

so if I run

name: 'random-settings'
title: 'Settings'
exists: [^allfiles]
tree:
    defrag:
        title: 'BLK Unpacker'
        icon: 
            handler: 'exefile'
            executable: 'I:\WarThunder\icon.ico'
        action: '"C:\Program Files (PE)\wt-tools\blk_unpack.exe" --format strict_blk %1'

i get

PS C:\WINDOWS\system32> python.exe C:\Users\diVine\Downloads\context-menu-maker-master\main.py C:\Users\diVine\Downloads\context-menu-maker-master\examples\simple.yml run
C:\Users\diVine\Downloads\context-menu-maker-master\contextdocparser.py:13: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  self.documentObject = yaml.load(document)
Python WNDPROC handler failed

YAML depreciated warning, and a WNDPROC error. Is it possible to pass %1?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.