Mercurial > urwid-satext
comparison examples/menu.py @ 151:6689aa54b20c default tip
refactoring from camelCase -> snake_case:
This libraries was using camelCase due for historical reasons (related to the use of
Twisted in the initial project).
This patch fixes it by using PEP8 compliant snake_case
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 15:38:18 +0200 |
parents | 287ff3e1edd1 |
children |
comparison
equal
deleted
inserted
replaced
150:aa8f46b43a71 | 151:6689aa54b20c |
---|---|
16 | 16 |
17 class MenuDemo(object): | 17 class MenuDemo(object): |
18 | 18 |
19 def __init__(self): | 19 def __init__(self): |
20 _frame = urwid.Frame(urwid.Filler(urwid.Text('Menu demo', align='center'))) | 20 _frame = urwid.Frame(urwid.Filler(urwid.Text('Menu demo', align='center'))) |
21 self.loop = urwid.MainLoop(_frame, const_PALETTE, unhandled_input=self.keyHandler) | 21 self.loop = urwid.MainLoop(_frame, const_PALETTE, unhandled_input=self.key_handler) |
22 _frame.set_header(self.buildMenu()) | 22 _frame.set_header(self.buildMenu()) |
23 _frame.set_focus('header') | 23 _frame.set_focus('header') |
24 | 24 |
25 def run(self): | 25 def run(self): |
26 self.loop.run() | 26 self.loop.run() |
42 self._messageExit("Exiting throught 'Exit' menu item") | 42 self._messageExit("Exiting throught 'Exit' menu item") |
43 | 43 |
44 def buildMenu(self): | 44 def buildMenu(self): |
45 self.menu = Menu(self.loop) | 45 self.menu = Menu(self.loop) |
46 _menu1 = "Menu 1" | 46 _menu1 = "Menu 1" |
47 self.menu.addMenu(_menu1, "Item 1", self.menu_cb) #Adding a menu is quite easy | 47 self.menu.add_menu(_menu1, "Item 1", self.menu_cb) #Adding a menu is quite easy |
48 self.menu.addMenu(_menu1, "Item 2", self.menu_cb) #Here the callback is always the same, | 48 self.menu.add_menu(_menu1, "Item 2", self.menu_cb) #Here the callback is always the same, |
49 self.menu.addMenu(_menu1, "Item 3", self.menu_cb) #but you use different ones in real life :) | 49 self.menu.add_menu(_menu1, "Item 3", self.menu_cb) #but you use different ones in real life :) |
50 self.menu.addMenu(_menu1, "Exit (C-x)", self.exit_cb, 'ctrl x') #You can also add a shortcut | 50 self.menu.add_menu(_menu1, "Exit (C-x)", self.exit_cb, 'ctrl x') #You can also add a shortcut |
51 _menu2 = "Menu 2" | 51 _menu2 = "Menu 2" |
52 self.menu.addMenu(_menu2, "Item 1", self.menu_cb) | 52 self.menu.add_menu(_menu2, "Item 1", self.menu_cb) |
53 self.menu.addMenu(_menu2, "Item 2", self.menu_cb) | 53 self.menu.add_menu(_menu2, "Item 2", self.menu_cb) |
54 self.menu.addMenu(_menu2, "Item 3", self.menu_cb) | 54 self.menu.add_menu(_menu2, "Item 3", self.menu_cb) |
55 return self.menu | 55 return self.menu |
56 | 56 |
57 def keyHandler(self, input): | 57 def key_handler(self, input): |
58 """We leave if user press a quit char""" | 58 """We leave if user press a quit char""" |
59 if input in ('esc','q','Q'): | 59 if input in ('esc','q','Q'): |
60 raise urwid.ExitMainLoop() | 60 raise urwid.ExitMainLoop() |
61 else: | 61 else: |
62 return self.menu.checkShortcuts(input) #needed to manage shortcuts | 62 return self.menu.check_shortcuts(input) #needed to manage shortcuts |
63 | 63 |
64 demo = MenuDemo() | 64 demo = MenuDemo() |
65 demo.run() | 65 demo.run() |