Skip to content

Instantly share code, notes, and snippets.

@Visgean
Created May 4, 2010 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Visgean/389121 to your computer and use it in GitHub Desktop.
Save Visgean/389121 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
# -*- coding: UTF-8 -*-
import urwid
from database import Pathject
class PathWalker(urwid.ListWalker):
""""""
def __init__(self):
paths = map(str, list(Pathject.select()))
self.paths = map(urwid.Text, paths)
self.focus = 0
def get_focus(self):
return self._get_at_pos(self.focus)
def set_focus(self, focus):
self.focus = focus
self._modified()
def get_next(self, actual_pos):
return self._get_at_pos(actual_pos + 1)
def get_prev(self, actual_pos):
return self._get_at_pos(actual_pos - 1)
def _get_at_pos(self, pos):
"""Return a path widget for the actual postition (*pos)"""
if pos < 0:
# there is no negative path object
return None, None
elif len(self.paths) < pos:
# out of range
return None, None
else:
return self.paths[pos]
def main():
palette = [
('body','black','dark cyan', 'standout'),
('foot','light gray', 'black'),
('key','light cyan', 'black', 'underline'),
('title', 'white', 'black',),
]
footer_text = [
('title', "Wooffy Daemon"), " ",
('key', "UP"), ", ", ('key', "DOWN"), ", ",
('key', "PAGE UP"), " and ", ('key', "PAGE DOWN"),
" move view ",
('key', "Q"), " exits",
]
def exit_on_q(input):
if input in ('q', 'Q'):
raise urwid.ExitMainLoop()
listbox = urwid.ListBox(PathWalker())
footer = urwid.AttrMap(urwid.Text(footer_text), 'foot')
view = urwid.Frame(urwid.AttrWrap(listbox, 'body'), footer=footer)
loop = urwid.MainLoop(view, palette, unhandled_input=exit_on_q)
loop.run()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment