-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
meta.raw_input inaccessible inside NestedMenu #2
Comments
Hi @RafalSkolasinski, unfortunately, currently there're some limitations of handling user's input for nested menus. Because of the way rofi interacts with the script, it's not possible to track which submenu should handle user's input. let me describe the flow for handling selected items:
if user enters any input, there's no way to understand that this input should be handled by concrete submenu, because on any user input rofi just executes the script with that input as the first param (e.g. I see a couple solutions:
|
Some updates: pushed v0.4.0 @RafalSkolasinski, you might be interested in the examples here Handling user input in submenu should work. The example for i3 workspaces could look like #!/home/user/.pyenv/versions/rofi/bin/python
from i3ipc.aio import Connection
import rofi_menu
class WorkspaceItem(rofi_menu.Item):
def __init__(self, workspace, i3, **kwargs):
self.workspace = workspace
self.i3 = i3
flags = kwargs.get('flags', set())
if workspace.focused:
flags.add(rofi_menu.FLAG_STYLE_ACTIVE)
kwargs['flags'] = flags
super().__init__(workspace.name, **kwargs)
def clone(self):
return WorkspaceItem(self.workspace, self.i3)
async def on_select(self, meta):
await self.i3.command(f"workspace {self.workspace.name}")
return rofi_menu.Operation(rofi_menu.OP_EXIT)
class I3Workspaces(rofi_menu.Menu):
prompt = 'workspaces'
allow_user_input = True
async def generate_menu_items(self, meta):
self.i3 = await Connection(auto_reconnect=True).connect()
self.workspaces = await self.i3.get_workspaces()
return [WorkspaceItem(item_id=w.name, workspace=w, i3=self.i3) for w in self.workspaces]
async def on_user_input(self, meta):
await self.i3.command(f'workspace {meta.user_input}')
return rofi_menu.Operation(rofi_menu.OP_EXIT)
class MainMenu(rofi_menu.Menu):
prompt = "main menu"
items = [
rofi_menu.NestedMenu("Choose workspace", I3Workspaces()),
]
if __name__ == "__main__":
rofi_menu.run(MainMenu()) |
@miphreal Thanks for pinging me, I will give it a spin :) I am afraid it may not happen until the weekend though |
closing this issue, handling user input in nested menus was implemented |
Hi @miphreal,
It seems that making use of the raw input does not work fully inside NestedMenu (or I am doing something wrong ;)
Here's my approach:
Unfortunately when executing I am getting error
The text was updated successfully, but these errors were encountered: