Skip to content

Instantly share code, notes, and snippets.

@ulidtko
Created December 15, 2019 20:28
Show Gist options
  • Save ulidtko/c24684f39be860af09f22c5b1a43f947 to your computer and use it in GitHub Desktop.
Save ulidtko/c24684f39be860af09f22c5b1a43f947 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import urwid
from urwid import MainLoop, ExitMainLoop
from urwid import Text, Edit, Button
from urwid import Frame, Pile, Padding, Filler, LineBox, Columns, Divider
from urwid import SolidFill, BoxAdapter
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
def on_keypress(key):
if key == 'q':
raise ExitMainLoop()
def lorem_toggle(button):
lorem_holder.edit_text = '' if lorem_holder.edit_text else LOREM_IPSUM
leftpane = Frame(
body=Filler(Pile([
Text("Steps to reproduce:"),
Divider(" "),
Text("1. Size down the terminal window so that Top Label in the right pane scrolls over the top."),
Divider(" "),
Text("2. Hit → (the right arrow key), then ↑↑↑↑ until Top Label is visible again. The Hmmm button is hidden now."),
Divider(" "),
Text("3. Hit ← and press Toggle Lorem Ipsum"),
Divider(" "),
Text("4. Hit → and ↓↓↓↓. Boom!"),
Divider(" "),
Padding(Button("Toggle Lorem Ipsum", on_press=lorem_toggle), width=22),
])),
header=Text("ListBox #386 crash demo -- no Terminal used!"),
footer=Text("Hit Q to exit")
)
lorem_holder = Edit()
lorem_holder._selectable = False
rightpane = urwid.ListBox(urwid.SimpleListWalker([
Padding(LineBox(Text("Top Label")), left=5, right=5),
Padding(BoxAdapter(SolidFill('.'), height=20), left=5, right=5),
Padding(lorem_holder, left=5, right=5),
Padding(urwid.Button("Hmmm..."), width=11),
]))
mainframe = Columns([
LineBox(leftpane),
LineBox(rightpane),
], dividechars=1)
urwid.set_encoding('utf-8')
MainLoop(mainframe, unhandled_input=on_keypress) \
.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment