Giter Site home page Giter Site logo

pyrofi's Introduction

About

PyPI - License PyPI - Implementation PyPI - Python Version GitHub tag (latest SemVer) PyPI wemake-python-styleguide

PyRofi wraps Rofi and helps you to build the hierarchical menus with neat navigation. You can also use Wofi as the "backend".

Installation

Make sure that you have Rofi or the Wofi installed. Then just python3 -m pip install --update --user pyrofi (requires Python ^3.6).

Menu structure

Every menu is just a dictionary: the keys are menu item captions, values are actions or submenus.

run_menu({
    'command': ['man', 'ls'],
    'submenu': {
        'command': [...],
        ...
    },
})

Submenus are just dictionaries with the same structure.

Action can be:

  • the "command" โ€” a list with command plus arguments
    'google': ['firefox', 'https://google.com']`
  • some Callable[List[str], ] that receives a path to the item and returns
    • None if all the work is done and you need to stop the interaction
    • a command (see above)
      def show_path(path):
          return ['echo'] + path
      
      ...
      'where am I': show_path
    • a submenu to "dive" into (you can build the submenus dynamically)
      def games_menu(path):
          return {
              ...
          }
      
      'games': games_menu

Also, the run_menu function can receive a callback: Callable[List[Any], bool] argument: that's how you can override the command execution. Any callback function should take a path as a sole argument and return either True if no more interactions are needed or False if you want to keep the menu active.

Example

#!/usr/bin/env python3

from pyrofi import run_menu

def hello_world(_):
    print('Hello World!')

def dice():
    import random
    return ['echo', random.choice('123456')]

run_menu({
    'Calculator': ['xcalc'],
    'Games': {
        'Rogue': ['rogue'],
        'Angband': ['angband']
    },
    'Calendar': ['ncal', '2019'],
    'Hello World': hello_world,
    'Dice': dice,
})

If you want to use Wofi, you will need to add menu_cmd=pyrofi.WOFI_CMD (or just menu_cmd='wofi) to the run_menu call.

More complex example you can see here and run it with python3 -m pyrofi.

pyrofi's People

Contributors

astynax avatar

Watchers

James Cloos avatar

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.