curses-menu
curses-menu copied to clipboard
Allow for exiting multiple menu levels at once
For example I have similar menu structure:
- MenuItem:
- SubmenuItem
- CommandItem
- SubmenuItem
After descending to CommandItem and running it I would like to exit menu totally and see stdout of the executed command. How can I achieve this?
BTW, thanks for the nice piece of software!
I've started looking into this, at the moment I'm thinking creating a subclass of command item that gets its own menu, then exits its parent is the way to go, but I don't have it completely working yet, and I haven't started trying to get the stdout yet. It'll look into it more in the next week or two.
I'm guessing you've given up on this by now? I was hoping to create an ssh session launcher.
Yeah, I haven't really had much time for it lately. It's the kind of thing that I may mess around with eventually, but I have other priorities at the moment.
I’m sorry but I’m a bit new to github. I don’t know if this is what you are looking for. This is written in Python.
from scene import * import ui, sound
A = Action
class Button (ShapeNode): def init(self, btn_shape, title, *args, **kwargs): ShapeNode.init(self, btn_shape, 'white', 'black', *args, **kwargs) self.title = title self.shadow = ('black',0,5,10) lbl_font = ('Copperplate', 34) self.label = LabelNode(self.title, lbl_font, color='black', position=(0,4), parent=self) self.START_position = self.position
class Menu (Scene): def init(self, title, btn_titles): Scene.init(self) self.title = title self.btn_titles = btn_titles
def setup(self):
btn_total = len(self.btn_titles)
bg_shape = ui.Path.rect(0,0, self.size.w, self.size.h)
self.menu_bg = ShapeNode(bg_shape, 'white', parent=self)
self.settings_box = SpriteNode('iob:ios7_gear_256', size=(45,45), position=(-self.menu_bg.size.w/2+40,self.menu_bg.size.h/2-37), parent=self.menu_bg)
self.buttons = []
self.titles = []
self.titles.append(self.title)
for lbl in self.btn_titles:
self.titles.append(lbl)
title_total = len(self.titles)
btn_shape = ui.Path.rounded_rect(0, 0, self.size.w/1.4, self.size.h/(title_total+3), 8)
for n, title in enumerate(reversed(self.titles)):
y = n*(self.size.h/(title_total+1))+(self.size.h/(title_total+1))+(self.menu_bg.position.y-self.size.h/2)
if n != title_total-1:
btn = Button(btn_shape, title, position=(0,y), parent=self.menu_bg)
btn.line_width = 2
self.buttons.append(btn)
else:
lbl_font = ('Chalkduster',55)
lbl = LabelNode(str(title), lbl_font, color='black', position=(0,y), parent=self.menu_bg)
self.did_change_size()
def did_change_size(self):
self.menu_bg.position = self.size/2
def touch_began(self, t):
t_loc = self.menu_bg.point_from_scene(t.location)
if t_loc in self.settings_box.bbox:
if self.presenting_scene:
self.presenting_scene. show_settings_menu()
for btn in self.buttons:
if t_loc in btn.frame:
btn.position += (0,-4)
btn.stroke_color = '#d6b800'
sound.play_effect('8ve:8ve-tap-wooden')
def touch_ended(self, t):
t_loc = self.menu_bg.point_from_scene(t.location)
for btn in self.buttons:
btn.position = btn.START_position
btn.stroke_color = 'black'
if self.presenting_scene and t_loc in btn.frame:
new_title = self.presenting_scene.menu_button_selected(btn.title)
if name == 'main': run(Menu('Title',['Button1','Button2']))