diff --git a/mach5 b/mach5 index 8c5994c..c5657ea 100755 --- a/mach5 +++ b/mach5 @@ -48,4 +48,5 @@ if not os.path.exists(menu_file): os.strerror(errno.ENOENT), menu_file) -Menu(get_data_from(menu_file)).get_command().execute() +# Menu(get_data_from(menu_file)).get_command().execute() +Menu(get_data_from(menu_file)).get_option() diff --git a/machlib/menu.py b/machlib/menu.py index ca55dbf..549b998 100644 --- a/machlib/menu.py +++ b/machlib/menu.py @@ -8,6 +8,9 @@ from collections import OrderedDict from getkey import getkey, keys import subprocess +import tkinter as tk + + def get_data_from(menu_file): """Get menu data from a yaml menu file.""" @@ -24,6 +27,8 @@ def get_data_from(menu_file): return(menu_data) + + class Command: """A Mach5 command.""" @@ -42,6 +47,7 @@ class Command: def execute(self): """Execute command.""" + print(f"Execute command {self._name}") subprocess.Popen(os.path.expanduser(self._cmd)) @@ -73,6 +79,13 @@ class Menu: my_str += f"{v.show()}\n" return my_str + def show_entries(self): + """Show Menu entries.""" + my_str = '' + for i, v in self._entries.items(): + my_str += f"{v.show()}\n" + return my_str + def get_command(self): """Get command from menu.""" print(self.show(True)) @@ -85,3 +98,29 @@ class Menu: return self._entries[opt] elif opt == keys.ESC: exit(0) + + def get_option(self): + """Get option with Tkinter.""" + + def key_pressed(event): + """Return char for key_pressed event.""" + opt = event.char + if opt in self._entries: + if isinstance(self._entries[opt], Menu): + return self._entries[opt].get_option() + else: + root.destroy() + self._entries[opt].execute() + exit(0) + elif opt == keys.ESC: + exit(0) + + root = tk.Tk() + root.geometry('300x100') + root.title("Mach5") + text_box = tk.Text(root) + text_box.insert(tk.END, self.show(True)) + text_box.grid(row=0, column=0) + root.bind("", key_pressed) + + root.mainloop()