dynmen - a python interface to dynamic menus
Introduction
dynmen is a python library for controlling dynamic menus like
Usage
All of the menu instances take an iterable like a list or a dict as input, and return a tuple containing the selected key and its associated value. Please see the examples folder for more examples. I've used dynmen in a number of programs:
- dynmen_scripts is a collection of small programs using dynmen
- python-vpnmenu uses networkmanager to control vpn connections
Using the dynmen.Menu class
The dynmen.Menu
class is the foundational menu class in the package. The application specific menu classes
DMenu
and Rofi
are built on top of it. If you want to use some dynamic menu which doesn't have a dynmen
specific class, you can launch the menu through dynmen.Menu
.
from dynmen import Menu
rofi = Menu(['rofi', '-dmenu'])
result = rofi({'first': 1, 'second': 2, 'third': 3})
print(result)
Using a menu in non-blocking mode
from dynmen import Menu
rofi = Menu(['rofi', '-dmenu'], process_mode='futures')
future = rofi(list('abcdefghijklmnopqrstuvwxyz'))
print(future.result())
Using an application-specific class
This example uses the Rofi()
class which is generated from
the rofi man page, and whose attributes correspond to rofi
command-line flags. For example, rofi ... -font 'monospace 20'
is
equivalent to menu = Rofi(); menu.font = 'monospace 20'
. You can
also set attributes through the constructor Rofi(font='monospace 20')
.
exdict = {
'Alyssa Boyd': ('Brownmouth', '09044'),
'Amy Martin': ('Mikechester', '33477'),
'Angela Mcdonald': ('North Gwendolynberg', '29053'),
'Bradley Santos': ('Andrewsmouth', '72513'),
'Brittany Manning': ('South Danielmouth', '44482'),
'Candice Huber': ('New Kimberly', '11698'),
'Cheyenne Thornton': ('New Anthony', '88618'),
'Dr. Kelli Sharp MD': ('North Rhondashire', '71761'),
'Evan Osborne': ('Andrewsside', '14378'),
'Gary Hernandez': ('Burnshaven', '62267'),
'George Elliott': ('Calebton', '55053'),
'Hannah Williams': ('North Stacy', '50983'),
'James Taylor': ('Gallegoshaven', '95677'),
'John White': ('Hansenhaven', '44559'),
'Monique Mccoy': ('Katherinemouth', '42023'),
'Randy Campos': ('South Scotthaven', '47692'),
'Rebecca Wolfe': ('Torresburgh', '37979'),
'Ronald Parks': ('Turnerland', '96367'),
'Russell Schroeder': ('Smithfurt', '39696'),
'Trevor Kelly': ('South Jenniferport', '73366'),
}
from dynmen.rofi import Rofi
menu = Rofi(lines=10, hide_scrollbar=True)
menu.prompt = "Name of person: "
menu.font = 'DejaVu Sans 30'
menu.case_insensitive = True
out = menu(exdict)
print(out)
Installation
Installing from pypi
pip install --user dynmen
Installing development version from github
git clone https://github.com/frostidaho/dynmen.git
cd dynmen
make install-user