Skip to main content

Create rofi menus via python

Project description

Package version

rofi-menu

Rofi allows defining custom modes (see the spec).

This lib is a reference implementation with some extra "sugar".

Simple demo:

custom menu

Installation

Using pip

$ pip install rofi-menu

Example

Create a python script which will be used for rofi mode e.g. example.py (don't forget to mark it as executable -- chmod +x ./example.py)

Assuming you installed rofi-menu into a virtual environment (let's say it's ~/.pyenv/versions/rofi/bin/python). Make sure shebang points to the right python executable, e.g. #!/home/user/pyenv/versions/rofi/bin/python.

#!/home/user/pyenv/versions/rofi/bin/python
import rofi_menu


class ProjectsMenu(rofi_menu.Menu):
    prompt = "Projects"
    items = [
        rofi_menu.BackItem(),
        rofi_menu.ShellItem("Project 1", "code-insiders ~/Develop/project1"),
        rofi_menu.ShellItem("Project 2", "code-insiders ~/Develop/project2"),
        rofi_menu.ShellItem("Project X", "code-insiders ~/Develop/projectx"),
    ]


class LogoutMenu(rofi_menu.Menu):
    prompt = "Logout"
    items = [
        rofi_menu.ShellItem("Yes", "i3-msg exit", flags={rofi_menu.FLAG_STYLE_URGENT}),
        rofi_menu.ExitItem("No", flags={rofi_menu.FLAG_STYLE_ACTIVE}),
    ]


class MainMenu(rofi_menu.Menu):
    prompt = "menu"
    items = [
        rofi_menu.TouchpadItem(),
        rofi_menu.NestedMenu("Projects >", ProjectsMenu()),
        rofi_menu.ShellItem(
            "Downloads (show size)", "du -csh ~/Downloads", show_output=True
        ),
        rofi_menu.NestedMenu("Second monitor", rofi_menu.SecondMonitorMenu()),
        rofi_menu.ShellItem("Lock screen", "i3lock -i ~/.config/i3/bg.png"),
        rofi_menu.ShellItem("Sleep", "systemctl suspend"),
        rofi_menu.NestedMenu("Logout", LogoutMenu()),
    ]


if __name__ == "__main__":
    rofi_menu.run(MainMenu())

Run it as:

$ rofi -modi mymenu:/path/to/example.py -show mymenu

It'll result in

rofi menu

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rofi-menu-0.2.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rofi_menu-0.2.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file rofi-menu-0.2.2.tar.gz.

File metadata

  • Download URL: rofi-menu-0.2.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.3.0-53-generic

File hashes

Hashes for rofi-menu-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ab717e965104373ab5794db8e7a77c32c1ab55058b165c13051b473b245d5180
MD5 e2cf0822ed5fda0a27220a24e45b99cc
BLAKE2b-256 ef1b801633721df3a1213ea044dbf7b1026a9294d18fa7abc76c3b098bcb090a

See more details on using hashes here.

File details

Details for the file rofi_menu-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: rofi_menu-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.3.0-53-generic

File hashes

Hashes for rofi_menu-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30959408a8e7a143d80685a6c2bc1b449e89e2a217fc77225ee4733e44d64379
MD5 da09dbb95a39f029bd08e2c4dc772116
BLAKE2b-256 0631d6a6b93b09c495c78f0ce286d929c2658ce323446e2a74458e1e3f17b7f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page