Created
November 28, 2018 18:43
-
-
Save raek/49ec23435d3edca74b65c37505848434 to your computer and use it in GitHub Desktop.
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 as u | |
with open('text.txt', 'rt') as f: | |
text_lines = f.read().split('\n') | |
def unhandled_input(key): | |
pass #body.keypress(key) | |
def send_line(line): | |
pass | |
class ChatEdit(u.Edit): | |
def keypress(self, size, key): | |
if key == 'enter': | |
send_line(edit.get_edit_text()) | |
edit.set_edit_text('') | |
return None | |
else: | |
return super().keypress(size, key) | |
class FallbackFocusFrame(u.Frame): | |
def keypress(self, size, key): | |
key = self._body_keypress(size, key) | |
if not key: | |
return None | |
else: | |
return self._footer_keypress(size, key) | |
def _body_keypress(self, size, key): | |
maxcol, maxrow = size | |
remaining = maxrow | |
if self.header is not None: | |
remaining -= self.header.rows((maxcol,)) | |
if self.footer is not None: | |
remaining -= self.footer.rows((maxcol,)) | |
if remaining <= 0: | |
return key | |
if not self.body.selectable(): | |
return key | |
return self.body.keypress((maxcol, remaining), key) | |
def _footer_keypress(self, size, key): | |
maxcol, maxrow = size | |
return self.footer.keypress((maxcol,), key) | |
palette = [ | |
('bar', 'white', 'dark blue'), | |
] | |
header = u.AttrMap(u.Text(' Rocketty'), 'bar') | |
list_walker = u.SimpleFocusListWalker([u.Text(t) for t in text_lines]) | |
body = u.ListBox(list_walker) | |
list_walker.set_focus(list_walker.positions()[-1]) | |
status = u.AttrMap(u.Text(' [18:13] [raek(+Ri) (zZzZ)] [1:freenode (change with ^X)] '), 'bar') | |
edit = ChatEdit(wrap='clip') | |
edit_line = u.Columns([('pack', u.Text('[#d1d] ')), edit]) | |
footer = u.Pile([status, edit_line]) | |
frame = FallbackFocusFrame(body, header, footer, focus_part='footer') | |
loop = u.MainLoop(frame, palette=palette, unhandled_input=unhandled_input, handle_mouse=False) | |
loop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment