-
-
Save colinjroberts/a6825eab34a17efb3c5ae4435d93949a to your computer and use it in GitHub Desktop.
Part 2 of development of a Python urwid app for tracking information during a job search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urwid | |
def build_tab_menu(choices): | |
"""Defines and builds tab_menu using list of choices""" | |
cells = [] | |
for item in choices: | |
button = urwid.Button(item) | |
urwid.connect_signal(button, 'click', None, item) | |
cells.append(urwid.AttrMap(button, None, focus_map='reversed')) | |
return urwid.GridFlow(cells, 20, 2, 1, "left") | |
def exit_program(): | |
"""Exit the main loop and return to the terminal""" | |
raise urwid.ExitMainLoop() | |
def q_for_exit(key): | |
"""Check for key presses for q and quits""" | |
if key in ('q', 'Q'): | |
exit_program() | |
if __name__ == "__main__": | |
"""Main process that splits the main window into tabs and a main body | |
using a Pile""" | |
# Builds primary two subdivisions: tab_menu and body_container | |
tab_menu = build_tab_menu(['Todo', 'Jobs', 'Companies', 'Contacts']) | |
body_container = urwid.Filler(urwid.Text("This is where " | |
"the body will go."), "top") | |
# Arrange primary items into a Pile | |
main_pile = urwid.Pile([('pack', tab_menu), urwid.LineBox(body_container)]) | |
mainloop = urwid.MainLoop(main_pile, | |
palette=[('reversed', 'standout', '')], | |
unhandled_input=q_for_exit) | |
mainloop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment