diff options
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/bigtext.py | 26 | ||||
-rwxr-xr-x | examples/browse.py | 52 | ||||
-rwxr-xr-x | examples/calc.py | 244 | ||||
-rwxr-xr-x | examples/dialog.py | 76 | ||||
-rwxr-xr-x | examples/edit.py | 58 | ||||
-rwxr-xr-x | examples/fib.py | 22 | ||||
-rwxr-xr-x | examples/graph.py | 58 | ||||
-rwxr-xr-x | examples/input_test.py | 10 | ||||
-rwxr-xr-x | examples/lcd_cf635.py | 38 | ||||
-rwxr-xr-x | examples/palette_test.py | 42 | ||||
-rwxr-xr-x | examples/treesample.py | 16 |
11 files changed, 321 insertions, 321 deletions
diff --git a/examples/bigtext.py b/examples/bigtext.py index aa5c3a1..8fc448c 100755 --- a/examples/bigtext.py +++ b/examples/bigtext.py @@ -50,7 +50,7 @@ class BigTextDisplay: ('chars', 'light gray', 'black'), ('exit', 'white', 'dark cyan'), ] - + def create_radio_button(self, g, name, font, fn): w = urwid.RadioButton(g, name, False, on_state_change=fn) w.font = font @@ -61,7 +61,7 @@ class BigTextDisplay: w = urwid.Text(" " + name + " (UTF-8 mode required)") w = urwid.AttrWrap(w, 'button disabled') return w - + def create_edit(self, label, text, fn): w = urwid.Edit(label, text) urwid.connect_signal(w, 'change', fn) @@ -94,35 +94,35 @@ class BigTextDisplay: chosen_font_rb = rb exit_font = font self.font_buttons.append( rb ) - + # Create BigText self.bigtext = urwid.BigText("", None) bt = SwitchingPadding(self.bigtext, 'left', None) bt = urwid.AttrWrap(bt, 'bigtext') bt = urwid.Filler(bt, 'bottom', None, 7) bt = urwid.BoxAdapter(bt, 7) - + # Create chars_avail cah = urwid.Text("Characters Available:") self.chars_avail = urwid.Text("", wrap='any') ca = urwid.AttrWrap(self.chars_avail, 'chars') - + chosen_font_rb.set_state(True) # causes set_font_event call - + # Create Edit widget edit = self.create_edit("", "Urwid "+urwid.__version__, self.edit_change_event) - + # ListBox chars = urwid.Pile([cah, ca]) fonts = urwid.Pile([urwid.Text("Fonts:")] + self.font_buttons, focus_item=1) - col = urwid.Columns([('fixed',16,chars), fonts], 3, + col = urwid.Columns([('fixed',16,chars), fonts], 3, focus_column=1) bt = urwid.Pile([bt, edit], focus_item=1) l = [bt, urwid.Divider(), col] w = urwid.ListBox(urwid.SimpleListWalker(l)) - + # Frame w = urwid.AttrWrap(w, 'body') hdr = urwid.Text("Urwid BigText example program - F8 exits.") @@ -137,10 +137,10 @@ class BigTextDisplay: def main(self): self.view, self.exit_view = self.setup_view() - self.loop = urwid.MainLoop(self.view, self.palette, + self.loop = urwid.MainLoop(self.view, self.palette, unhandled_input=self.unhandled_input) self.loop.run() - + def unhandled_input(self, key): if key == 'f8': self.loop.widget = self.exit_view @@ -152,10 +152,10 @@ class BigTextDisplay: if key in ('n', 'N'): self.loop.widget = self.view return True - + def main(): BigTextDisplay().main() - + if '__main__'==__name__: main() diff --git a/examples/browse.py b/examples/browse.py index e182cde..d5a5f16 100755 --- a/examples/browse.py +++ b/examples/browse.py @@ -93,7 +93,7 @@ class FileTreeWidget(FlagFileWidget): def get_display_text(self): return self.get_node().get_key() - + class EmptyWidget(urwid.TreeWidget): @@ -164,7 +164,7 @@ class DirectoryNode(urwid.ParentNode): else: depth = path.count(dir_sep()) key = os.path.basename(path) - urwid.ParentNode.__init__(self, path, key=key, parent=parent, + urwid.ParentNode.__init__(self, path, key=key, parent=parent, depth=depth) def load_parent(self): @@ -186,7 +186,7 @@ class DirectoryNode(urwid.ParentNode): files.append(a) except OSError, e: depth = self.get_depth() + 1 - self._children[None] = ErrorNode(self, parent=self, key=None, + self._children[None] = ErrorNode(self, parent=self, key=None, depth=depth) return [None] @@ -199,7 +199,7 @@ class DirectoryNode(urwid.ParentNode): keys = dirs + files if len(keys) == 0: depth=self.get_depth() + 1 - self._children[None] = EmptyNode(self, parent=self, key=None, + self._children[None] = EmptyNode(self, parent=self, key=None, depth=depth) keys = [None] return keys @@ -226,7 +226,7 @@ class DirectoryBrowser: ('body', 'black', 'light gray'), ('flagged', 'black', 'dark green', ('bold','underline')), ('focus', 'light gray', 'dark blue', 'standout'), - ('flagged focus', 'yellow', 'dark cyan', + ('flagged focus', 'yellow', 'dark cyan', ('bold','standout','underline')), ('head', 'yellow', 'black', 'standout'), ('foot', 'light gray', 'black'), @@ -236,7 +236,7 @@ class DirectoryBrowser: ('flag', 'dark gray', 'light gray'), ('error', 'dark red', 'light gray'), ] - + footer_text = [ ('title', "Directory Browser"), " ", ('key', "UP"), ",", ('key', "DOWN"), ",", @@ -246,12 +246,12 @@ class DirectoryBrowser: ('key', "+"), ",", ('key', "-"), " ", ('key', "LEFT"), " ", - ('key', "HOME"), " ", + ('key', "HOME"), " ", ('key', "END"), " ", ('key', "Q"), ] - - + + def __init__(self): cwd = os.getcwd() store_initial_cwd(cwd) @@ -261,17 +261,17 @@ class DirectoryBrowser: self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), 'foot') self.view = urwid.Frame( - urwid.AttrWrap(self.listbox, 'body'), - header=urwid.AttrWrap(self.header, 'head'), + urwid.AttrWrap(self.listbox, 'body'), + header=urwid.AttrWrap(self.header, 'head'), footer=self.footer) def main(self): """Run the program.""" - + self.loop = urwid.MainLoop(self.view, self.palette, unhandled_input=self.unhandled_input) self.loop.run() - + # on exit, write the flagged filenames to the console names = [escape_filename_sh(x) for x in get_flagged_names()] print " ".join(names) @@ -299,13 +299,13 @@ def add_widget(path, widget): def get_flagged_names(): """Return a list of all filenames marked as flagged.""" - + l = [] for w in _widget_cache.values(): if w.flagged: l.append(w.get_node().get_value()) return l - + ###### @@ -314,7 +314,7 @@ _initial_cwd = [] def store_initial_cwd(name): """Store the initial current working directory path components.""" - + global _initial_cwd _initial_cwd = name.split(dir_sep()) @@ -323,14 +323,14 @@ def starts_expanded(name): if name is '/': return True - + l = name.split(dir_sep()) if len(l) > len(_initial_cwd): return False - + if l != _initial_cwd[:len(l)]: return False - + return True @@ -338,11 +338,11 @@ def escape_filename_sh(name): """Return a hopefully safe shell-escaped version of a filename.""" # check whether we have unprintable characters - for ch in name: - if ord(ch) < 32: + for ch in name: + if ord(ch) < 32: # found one so use the ansi-c escaping return escape_filename_sh_ansic(name) - + # all printable characters, so return a double-quoted version name.replace('\\','\\\\') name.replace('"','\\"') @@ -353,7 +353,7 @@ def escape_filename_sh(name): def escape_filename_sh_ansic(name): """Return an ansi-c shell-escaped version of a filename.""" - + out =[] # gather the escaped characters into a list for ch in name: @@ -363,7 +363,7 @@ def escape_filename_sh_ansic(name): out.append('\\\\') else: out.append(ch) - + # slap them back together in an ansi-c quote $'...' return "$'" + "".join(out) + "'" @@ -383,6 +383,6 @@ def dir_sep(): return getattr(os.path,'sep','/') -if __name__=="__main__": +if __name__=="__main__": main() - + diff --git a/examples/calc.py b/examples/calc.py index f132172..ec1f039 100755 --- a/examples/calc.py +++ b/examples/calc.py @@ -44,7 +44,7 @@ else: def div_or_none(a,b): """Divide a by b. Return result or None on divide by zero.""" - if b == 0: + if b == 0: return None return a/b @@ -72,8 +72,8 @@ E_no_parent_column = "There is no parent column to return to." E_cant_combine = "Cannot combine cells with sub-expressions." E_invalid_in_parent_cell = "Cannot enter numbers into parent cell." E_invalid_in_help_col = [ - "Help Column is in focus. Press ", - ('key',COLUMN_KEYS[1]),"-",('key',COLUMN_KEYS[-1]), + "Help Column is in focus. Press ", + ('key',COLUMN_KEYS[1]),"-",('key',COLUMN_KEYS[-1]), " to select another column."] # Shared layout object @@ -82,12 +82,12 @@ CALC_LAYOUT = None class CalcEvent(Exception): """Events triggered by user input.""" - + attr = 'event' - + def __init__(self, message): self.message = message - + def widget(self): """Return a widget containing event information""" text = urwid.Text( self.message, 'center' ) @@ -115,24 +115,24 @@ class Cell: self.child = None self.setup_edit() self.result = urwid.Text("", layout=CALC_LAYOUT) - + def show_result(self, next_cell): """Return whether this widget should display its result. next_cell -- the cell following self or None""" - - if self.is_top: + + if self.is_top: return False if next_cell is None: return True if self.op == "+" and next_cell.op == "+": return False return True - - + + def setup_edit(self): """Create the standard edit widget for this cell.""" - + self.edit = urwid.IntEdit() if not self.is_top: self.edit.set_caption( self.op + " " ) @@ -140,38 +140,38 @@ class Cell: def get_value(self): """Return the numeric value of the cell.""" - + if self.child is not None: return self.child.get_result() else: return long("0"+self.edit.edit_text) - + def get_result(self): """Return the numeric result of this cell's operation.""" - + if self.is_top: return self.get_value() - if self.result.text == "": + if self.result.text == "": return None return long(self.result.text) def set_result(self, result): """Set the numeric result for this cell.""" - + if result == None: self.result.set_text("") else: self.result.set_text( "%d" %result ) - + def become_parent(self, column, letter): """Change the edit widget to a parent cell widget.""" - + self.child = column self.edit = ParentEdit( self.op, letter ) - + def remove_child(self): """Change the edit widget back to a standard edit widget.""" - + self.child = None self.setup_edit() @@ -183,39 +183,39 @@ class Cell: class ParentEdit(urwid.Edit): """Edit widget modified to link to a child column""" - + def __init__(self, op, letter): """Use the operator and letter of the child column as caption - + op -- operator or None letter -- letter of child column remove_fn -- function to call when user wants to remove child function takes no parameters """ - + urwid.Edit.__init__(self, layout=CALC_LAYOUT) self.op = op self.set_letter( letter ) - + def set_letter(self, letter): """Set the letter of the child column for display.""" - + self.letter = letter caption = "("+letter+")" if self.op is not None: caption = self.op+" "+caption self.set_caption(caption) - + def keypress(self, size, key): - """Disable usual editing, allow only removing of child""" - + """Disable usual editing, allow only removing of child""" + if key == "backspace": raise ColumnDeleteEvent(self.letter, from_parent=True) elif key in list("0123456789"): raise CalcEvent, E_invalid_in_parent_cell else: return key - + class CellWalker(urwid.ListWalker): def __init__(self, content): @@ -243,13 +243,13 @@ class CellWalker(urwid.ListWalker): return self.div, pos else: return self.content[i].result, pos - + def get_focus(self): return self._get_at_pos(self.focus) - + def set_focus(self, focus): self.focus = focus - + def get_next(self, start_from): i, sub = start_from assert sub in (0,1,2) @@ -264,7 +264,7 @@ class CellWalker(urwid.ListWalker): return self._get_at_pos( (i, 2) ) else: return self._get_at_pos( (i+1, 0) ) - + def get_prev(self, start_from): i, sub = start_from assert sub in (0,1,2) @@ -280,8 +280,8 @@ class CellWalker(urwid.ListWalker): return self._get_at_pos( (i, 0) ) else: return self._get_at_pos( (i, 1) ) - - + + class CellColumn( urwid.WidgetWrap ): def __init__(self, letter): self.walker = CellWalker([Cell(None)]) @@ -289,26 +289,26 @@ class CellColumn( urwid.WidgetWrap ): self.listbox = urwid.ListBox( self.walker ) self.set_letter( letter ) urwid.WidgetWrap.__init__(self, self.frame) - + def set_letter(self, letter): """Set the column header with letter.""" - + self.letter = letter header = urwid.AttrWrap( urwid.Text( ["Column ",('key',letter)], layout = CALC_LAYOUT), 'colhead' ) self.frame = urwid.Frame( self.listbox, header ) - + def keypress(self, size, key): key = self.frame.keypress( size, key) - if key is None: + if key is None: changed = self.update_results() if changed: raise UpdateParentEvent() return - + f, (i, sub) = self.walker.get_focus() - if sub != 0: + if sub != 0: # f is not an edit widget return key if OPERATORS.has_key(key): @@ -317,27 +317,27 @@ class CellColumn( urwid.WidgetWrap ): cursor_pos = edit.edit_pos tail = edit.edit_text[cursor_pos:] edit.set_edit_text( edit.edit_text[:cursor_pos] ) - + new_cell = Cell( key ) new_cell.edit.set_edit_text( tail ) self.content[i+1:i+1] = [new_cell] - + changed = self.update_results() self.move_focus_next( size ) self.content[i+1].edit.set_edit_pos(0) if changed: raise UpdateParentEvent() return - + elif key == 'backspace': # unhandled backspace, we're at beginning of number # append current number to cell above, removing operator above = self.walker.get_cell(i-1) if above is None: # we're the first cell - raise ColumnDeleteEvent( self.letter, + raise ColumnDeleteEvent( self.letter, from_parent=False ) - + edit = self.walker.get_cell(i).edit # check that we can combine if above.child is not None: @@ -346,7 +346,7 @@ class CellColumn( urwid.WidgetWrap ): # ..and current not empty, no good raise CalcEvent, E_cant_combine above_pos = 0 - else: + else: # above is normal number cell above_pos = len(above.edit.edit_text) above.edit.set_edit_text( above.edit.edit_text + @@ -359,7 +359,7 @@ class CellColumn( urwid.WidgetWrap ): if changed: raise UpdateParentEvent() return - + elif key == 'delete': # pull text from next cell into current cell = self.walker.get_cell(i) @@ -373,7 +373,7 @@ class CellColumn( urwid.WidgetWrap ): if below.child is not None: # cell below is a parent raise CalcEvent, E_cant_combine - + edit = self.walker.get_cell(i).edit edit.set_edit_text( edit.edit_text + below.edit.edit_text ) @@ -385,53 +385,53 @@ class CellColumn( urwid.WidgetWrap ): return return key - + def move_focus_next(self, size): f, (i, sub) = self.walker.get_focus() assert i<len(self.content)-1 - + ni = i while ni == i: self.frame.keypress(size, 'down') nf, (ni, nsub) = self.walker.get_focus() - + def move_focus_prev(self, size): f, (i, sub) = self.walker.get_focus() assert i>0 - + ni = i while ni == i: self.frame.keypress(size, 'up') nf, (ni, nsub) = self.walker.get_focus() - - + + def update_results( self, start_from=None ): """Update column. Return True if final result changed. - + start_from -- Cell to start updating from or None to start from the current focus (default None) """ - + if start_from is None: f, (i, sub) = self.walker.get_focus() else: i = self.content.index(start_from) if i == None: return False - + focus_cell = self.walker.get_cell(i) - + if focus_cell.is_top: x = focus_cell.get_value() last_op = None - else: + else: last_cell = self.walker.get_cell(i-1) x = last_cell.get_result() - + if x is not None and focus_cell.op is not None: - x = OPERATORS[focus_cell.op]( x, + x = OPERATORS[focus_cell.op]( x, focus_cell.get_value() ) focus_cell.set_result(x) - + for cell in self.content[i+1:]: if cell.op is None: x = None @@ -443,11 +443,11 @@ class CellColumn( urwid.WidgetWrap ): return True - + def create_child( self, letter ): """Return (parent cell,child column) or None,None on failure.""" f, (i, sub) = self.walker.get_focus() - if sub != 0: + if sub != 0: # f is not an edit widget return None, None @@ -467,10 +467,10 @@ class CellColumn( urwid.WidgetWrap ): return len(self.content)==1 and self.content[0].is_empty() - + def get_expression(self): """Return the expression as a printable string.""" - + l = [] for c in self.content: if c.op is not None: # only applies to first cell @@ -479,16 +479,16 @@ class CellColumn( urwid.WidgetWrap ): l.append("("+c.child.get_expression()+")") else: l.append("%d"%c.get_value()) - + return "".join(l) def get_result(self): """Return the result of the last cell in the column.""" - + return self.content[-1].get_result() - - + + class HelpColumn(urwid.BoxWidget): help_text = [ @@ -507,8 +507,8 @@ class HelpColumn(urwid.BoxWidget): "", [ "Sub-expressions: ", ('key', "("), " and ", ('key', ")") ], "", - [ "Columns: ", ('key', COLUMN_KEYS[0]), " and ", - ('key',COLUMN_KEYS[1]), "-", + [ "Columns: ", ('key', COLUMN_KEYS[0]), " and ", + ('key',COLUMN_KEYS[1]), "-", ('key',COLUMN_KEYS[-1]) ], "", [ "Exit: ", ('key', "Q") ], @@ -516,39 +516,39 @@ class HelpColumn(urwid.BoxWidget): "", ["Column Calculator does operations in the order they are ", "typed, not by following usual precedence rules. ", - "If you want to calculate ", ('key', "12 - 2 * 3"), + "If you want to calculate ", ('key', "12 - 2 * 3"), " with the multiplication happening before the ", - "subtraction you must type ", + "subtraction you must type ", ('key', "12 - (2 * 3)"), " instead."], ] - + def __init__(self): self.head = urwid.AttrWrap( urwid.Text(["Help Column ", ('key',"?")], layout = CALC_LAYOUT), 'help') - self.foot = urwid.AttrWrap( + self.foot = urwid.AttrWrap( urwid.Text(["[text continues.. press ", ('key',"?"), " then scroll]"]), 'helpnote' ) self.items = [urwid.Text(x) for x in self.help_text] self.listbox = urwid.ListBox(urwid.SimpleListWalker(self.items)) self.body = urwid.AttrWrap( self.listbox, 'help' ) self.frame = urwid.Frame( self.body, header=self.head) - + def render(self, size, focus=False): maxcol, maxrow = size head_rows = self.head.rows((maxcol,)) - if "bottom" in self.listbox.ends_visible( + if "bottom" in self.listbox.ends_visible( (maxcol, maxrow-head_rows) ): self.frame.footer = None else: self.frame.footer = self.foot return self.frame.render( (maxcol, maxrow), focus) - + def keypress( self, size, key ): return self.frame.keypress( size, key ) - + class CalcDisplay: palette = [ @@ -563,7 +563,7 @@ class CalcDisplay: ('event', 'light red', 'black', 'standout'), ('confirm', 'yellow', 'black', 'bold'), ] - + def __init__(self): self.columns = urwid.Columns([HelpColumn(), CellColumn("A")], 1) self.col_list = self.columns.widget_list @@ -586,7 +586,7 @@ class CalcDisplay: def input_filter(self, input, raw_input): if 'q' in input or 'Q' in input: raise urwid.ExitMainLoop() - + # handle other keystrokes for k in input: try: @@ -597,51 +597,51 @@ class CalcDisplay: # display any message self.event = e self.view.footer = e.widget() - + # remove all input from further processing by MainLoop return [] - + def wrap_keypress(self, key): """Handle confirmation and throw event on bad input.""" - + try: key = self.keypress(key) - + except ColumnDeleteEvent, e: if e.letter == COLUMN_KEYS[1]: # cannot delete the first column, ignore key return - + if not self.column_empty( e.letter ): # need to get two in a row, so check last event if not isinstance(self.event,ColumnDeleteEvent): # ask for confirmation raise e self.delete_column(e.letter) - + except UpdateParentEvent, e: self.update_parent_columns() return - + if key is None: return if self.columns.get_focus_column() == 0: if key not in ('up','down','page up','page down'): raise CalcEvent, E_invalid_in_help_col - + if key not in EDIT_KEYS and key not in MOVEMENT_KEYS: raise CalcEvent, E_invalid_key % key.upper() - + def keypress(self, key): """Handle a keystroke.""" self.loop.process_input([key]) - + if key.upper() in COLUMN_KEYS: # column switch i = COLUMN_KEYS.index(key.upper()) - if i >= len( self.col_list ): + if i >= len( self.col_list ): raise CalcEvent, E_no_such_column % key.upper() self.columns.set_focus_column( i ) return @@ -650,7 +650,7 @@ class CalcDisplay: if len( self.col_list ) >= len(COLUMN_KEYS): raise CalcEvent, E_no_more_columns i = self.columns.get_focus_column() - if i == 0: + if i == 0: # makes no sense in help column return key col = self.col_list[i] @@ -662,7 +662,7 @@ class CalcDisplay: self.col_list.append(child) self.set_link( parent, col, child ) self.columns.set_focus_column(len(self.col_list)-1) - + elif key == ")": i = self.columns.get_focus_column() if i == 0: @@ -670,43 +670,43 @@ class CalcDisplay: return key col = self.col_list[i] parent, pcol = self.get_parent( col ) - if parent is None: + if parent is None: # column has no parent raise CalcEvent, E_no_parent_column - + new_i = self.col_list.index( pcol ) self.columns.set_focus_column( new_i ) else: return key - + def set_link( self, parent, pcol, child ): """Store the link between a parent cell and child column. - + parent -- parent Cell object pcol -- CellColumn where parent resides child -- child CellColumn object""" self.col_link[ child ] = parent, pcol - + def get_parent( self, child ): """Return the parent and parent column for a given column.""" return self.col_link.get( child, (None,None) ) - + def column_empty(self, letter): """Return True if the column passed is empty.""" - + i = COLUMN_KEYS.index(letter) col = self.col_list[i] return col.is_empty() - - + + def delete_column(self, letter): """Delete the column with the given letter.""" - + i = COLUMN_KEYS.index(letter) col = self.col_list[i] - + parent, pcol = self.get_parent( col ) f = self.columns.get_focus_column() @@ -714,11 +714,11 @@ class CalcDisplay: # move focus to the parent column f = self.col_list.index(pcol) self.columns.set_focus_column(f) - + parent.remove_child() pcol.update_results(parent) del self.col_list[i] - + # delete children of this column keep_right_cols = [] remove_cols = [col] @@ -732,7 +732,7 @@ class CalcDisplay: # remove the links del self.col_link[rc] # keep only the non-children - self.col_list[i:] = keep_right_cols + self.col_list[i:] = keep_right_cols # fix the letter assignments for j in range(i, len(self.col_list)): @@ -750,21 +750,21 @@ class CalcDisplay: col = self.col_list[f] while 1: parent, pcol = self.get_parent(col) - if pcol is None: + if pcol is None: return changed = pcol.update_results( start_from = parent ) - if not changed: + if not changed: return col = pcol - - + + def get_expression_result(self): """Return (expression, result) as strings.""" - + col = self.col_list[1] return col.get_expression(), "%d"%col.get_result() - + class CalcNumLayout(urwid.TextLayout): @@ -800,19 +800,19 @@ class CalcNumLayout(urwid.TextLayout): return l - - - + + + def main(): """Launch Column Calculator.""" global CALC_LAYOUT CALC_LAYOUT = CalcNumLayout() - + urwid.web_display.set_preferences("Column Calculator") # try to handle short web requests quickly if urwid.web_display.handle_short_request(): return - + CalcDisplay().main() if '__main__'==__name__ or urwid.web_display.is_web_request(): diff --git a/examples/dialog.py b/examples/dialog.py index 2de61c0..dbdeb28 100755 --- a/examples/dialog.py +++ b/examples/dialog.py @@ -42,7 +42,7 @@ class DialogDisplay: ('focus','white','dark blue','bold'), ('focustext','light gray','dark blue'), ] - + def __init__(self, text, height, width, body=None): width = int(width) if width <= 0: @@ -50,7 +50,7 @@ class DialogDisplay: height = int(height) if height <= 0: height = ('relative', 80) - + self.body = body if body is None: # fill space with nothing @@ -61,24 +61,24 @@ class DialogDisplay: self.frame.header = urwid.Pile( [urwid.Text(text), urwid.Divider()] ) w = self.frame - + # pad area around listbox w = urwid.Padding(w, ('fixed left',2), ('fixed right',2)) w = urwid.Filler(w, ('fixed top',1), ('fixed bottom',1)) w = urwid.AttrWrap(w, 'body') - + # "shadow" effect w = urwid.Columns( [w,('fixed', 2, urwid.AttrWrap( urwid.Filler(urwid.Text(('border',' ')), "top") ,'shadow'))]) - w = urwid.Frame( w, footer = + w = urwid.Frame( w, footer = urwid.AttrWrap(urwid.Text(('border',' ')),'shadow')) # outermost border area w = urwid.Padding(w, 'center', width ) w = urwid.Filler(w, 'middle', height ) w = urwid.AttrWrap( w, 'border' ) - + self.view = w @@ -102,10 +102,10 @@ class DialogDisplay: self.loop.run() except DialogExit, e: return self.on_exit( e.args[0] ) - + def on_exit(self, exitcode): return exitcode, "" - + class InputDialogDisplay(DialogDisplay): @@ -113,11 +113,11 @@ class InputDialogDisplay(DialogDisplay): self.edit = urwid.Edit() body = urwid.ListBox([self.edit]) body = urwid.AttrWrap(body, 'selectable','focustext') - + DialogDisplay.__init__(self, text, height, width, body) - + self.frame.set_focus('body') - + def unhandled_key(self, size, k): if k in ('up','page up'): self.frame.set_focus('body') @@ -127,11 +127,11 @@ class InputDialogDisplay(DialogDisplay): # pass enter to the "ok" button self.frame.set_focus('footer') self.view.keypress( size, k ) - + def on_exit(self, exitcode): return exitcode, self.edit.get_edit_text() - + class TextDialogDisplay(DialogDisplay): def __init__(self, file, height, width): l = [] @@ -154,20 +154,20 @@ class TextDialogDisplay(DialogDisplay): class ListDialogDisplay(DialogDisplay): def __init__(self, text, height, width, constr, items, has_default): j = [] - if has_default: + if has_default: k, tail = 3, () - else: + else: k, tail = 2, ("no",) while items: j.append( items[:k] + tail ) items = items[k:] - + l = [] self.items = [] for tag, item, default in j: w = constr( tag, default=="on" ) self.items.append(w) - w = urwid.Columns( [('fixed', 12, w), + w = urwid.Columns( [('fixed', 12, w), urwid.Text(item)], 2 ) w = urwid.AttrWrap(w, 'selectable','focus') l.append(w) @@ -175,9 +175,9 @@ class ListDialogDisplay(DialogDisplay): lb = urwid.ListBox(l) lb = urwid.AttrWrap( lb, "selectable" ) DialogDisplay.__init__(self, text, height, width, lb ) - + self.frame.set_focus('body') - + def unhandled_key(self, size, k): if k in ('up','page up'): self.frame.set_focus('body') @@ -199,14 +199,14 @@ class ListDialogDisplay(DialogDisplay): s = i.get_label() break return exitcode, s - - - + + + class CheckListDialogDisplay(ListDialogDisplay): def on_exit(self, exitcode): """ - Mimic dialog(1)'s --checklist exit. + Mimic dialog(1)'s --checklist exit. Put each checked item in double quotes with a trailing space. """ if exitcode != 0: @@ -250,7 +250,7 @@ def do_checklist(text, height, width, list_height, *items): d = CheckListDialogDisplay( text, height, width, constr, items, True) d.add_buttons([ ("OK", 0), ("Cancel", 1) ]) return d - + def do_inputbox(text, height, width): d = InputDialogDisplay( text, height, width ) d.add_buttons([ ("Exit", 0) ]) @@ -286,22 +286,22 @@ def do_yesno(text, height, width): d.add_buttons([ ("Yes", 0), ("No", 1) ]) return d -MODES={ '--checklist': (do_checklist, +MODES={ '--checklist': (do_checklist, "text height width list-height [ tag item status ] ..."), - '--inputbox': (do_inputbox, + '--inputbox': (do_inputbox, "text height width"), - '--menu': (do_menu, + '--menu': (do_menu, "text height width menu-height [ tag item ] ..."), - '--msgbox': (do_msgbox, + '--msgbox': (do_msgbox, "text height width"), - '--radiolist': (do_radiolist, + '--radiolist': (do_radiolist, "text height width list-height [ tag item status ] ..."), '--textbox': (do_textbox, "file height width"), - '--yesno': (do_yesno, + '--yesno': (do_yesno, "text height width"), } - + def show_usage(): """ @@ -310,7 +310,7 @@ def show_usage(): modelist = [(mode, help) for (mode, (fn, help)) in MODES.items()] modelist.sort() sys.stdout.write( - __doc__ + + __doc__ + "\n".join(["%-15s %s"%(mode,help) for (mode,help) in modelist]) + """ @@ -324,20 +324,20 @@ def main(): if len(sys.argv) < 2 or not MODES.has_key(sys.argv[1]): show_usage() return - + # Create a DialogDisplay instance fn, help = MODES[sys.argv[1]] d = fn( * sys.argv[2:] ) - + # Run it exitcode, exitstring = d.main() - + # Exit if exitstring: sys.stderr.write(exitstring+"\n") - + sys.exit(exitcode) - -if __name__=="__main__": + +if __name__=="__main__": main() diff --git a/examples/edit.py b/examples/edit.py index eed7970..e4fb4b0 100755 --- a/examples/edit.py +++ b/examples/edit.py @@ -37,30 +37,30 @@ import urwid class LineWalker(urwid.ListWalker): """ListWalker-compatible class for lazily reading file contents.""" - + def __init__(self, name): self.file = open(name) self.lines = [] self.focus = 0 - - def get_focus(self): + + 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, start_from): return self._get_at_pos(start_from + 1) - + def get_prev(self, start_from): return self._get_at_pos(start_from - 1) def read_next_line(self): """Read another line from the file.""" - + next_line = self.file.readline() - + if not next_line or next_line[-1:] != '\n': # no newline on last line of file self.file = None @@ -69,22 +69,22 @@ class LineWalker(urwid.ListWalker): next_line = next_line[:-1] expanded = next_line.expandtabs() - + edit = urwid.Edit("", expanded, allow_tab=True) edit.set_edit_pos(0) edit.original_text = next_line self.lines.append(edit) return next_line - - + + def _get_at_pos(self, pos): """Return a widget for the line number passed.""" - + if pos < 0: # line 0 is the start of the file, no more above return None, None - + if len(self.lines) > pos: # we have that line so return it return self.lines[pos], pos @@ -96,12 +96,12 @@ class LineWalker(urwid.ListWalker): assert pos == len(self.lines), "out of order request?" self.read_next_line() - + return self.lines[-1], pos - + def split_focus(self): """Divide the focus edit widget at the cursor location.""" - + focus = self.lines[self.focus] pos = focus.edit_pos edit = urwid.Edit("",focus.edit_text[pos:], allow_tab=True) @@ -117,7 +117,7 @@ class LineWalker(urwid.ListWalker): if above is None: # already at the top return - + focus = self.lines[self.focus] above.set_edit_pos(len(above.edit_text)) above.set_edit_text(above.edit_text + focus.edit_text) @@ -131,7 +131,7 @@ class LineWalker(urwid.ListWalker): if below is None: # already at bottom return - + focus = self.lines[self.focus] focus.set_edit_text(focus.edit_text + below.edit_text) del self.lines[self.focus+1] @@ -143,16 +143,16 @@ class EditDisplay: ('foot','dark cyan', 'dark blue', 'bold'), ('key','light cyan', 'dark blue', 'underline'), ] - + footer_text = ('foot', [ "Text Editor ", ('key', "F5"), " save ", ('key', "F8"), " quit", ]) - + def __init__(self, name): self.save_name = name - self.walker = LineWalker(name) + self.walker = LineWalker(name) self.listbox = urwid.ListBox(self.walker) self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), "foot") @@ -163,7 +163,7 @@ class EditDisplay: self.loop = urwid.MainLoop(self.view, self.palette, unhandled_input=self.unhandled_keypress) self.loop.run() - + def unhandled_keypress(self, k): """Last resort for keypresses.""" @@ -197,11 +197,11 @@ class EditDisplay: else: return return True - + def save_file(self): """Write the file out to disk.""" - + l = [] walk = self.walker for edit in walk.lines: @@ -210,14 +210,14 @@ class EditDisplay: l.append(edit.original_text) else: l.append(re_tab(edit.edit_text)) - + # then the rest while walk.file is not None: l.append(walk.read_next_line()) - + # write back to disk outfile = open(self.save_name, "w") - + prefix = "" for line in l: outfile.write(prefix + line) @@ -249,7 +249,7 @@ def main(): sys.stderr.write(__doc__) return EditDisplay(name).main() - -if __name__=="__main__": + +if __name__=="__main__": main() diff --git a/examples/fib.py b/examples/fib.py index 7f8d4b7..e3262b4 100755 --- a/examples/fib.py +++ b/examples/fib.py @@ -28,32 +28,32 @@ Features: """ import urwid - + class FibonacciWalker(urwid.ListWalker): """ListWalker-compatible class for browsing fibonacci set. - + positions returned are (value at position-1, value at position) tuples. """ def __init__(self): self.focus = (0L,1L) self.numeric_layout = NumericLayout() - + def _get_at_pos(self, pos): """Return a widget and the position passed.""" return urwid.Text("%d"%pos[1], layout=self.numeric_layout), pos - - def get_focus(self): + + 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, start_from): a, b = start_from focus = b, a+b return self._get_at_pos(focus) - + def get_prev(self, start_from): a, b = start_from focus = b-a, a @@ -66,7 +66,7 @@ def main(): ('key','light cyan', 'black', 'underline'), ('title', 'white', 'black',), ] - + footer_text = [ ('title', "Fibonacci Set Viewer"), " ", ('key', "UP"), ", ", ('key', "DOWN"), ", ", @@ -74,7 +74,7 @@ def main(): " move view ", ('key', "Q"), " exits", ] - + def exit_on_q(input): if input in ('q', 'Q'): raise urwid.ExitMainLoop() @@ -108,5 +108,5 @@ class NumericLayout(urwid.TextLayout): return [[(width, x, x+width)] for x in linestarts] -if __name__=="__main__": +if __name__=="__main__": main() diff --git a/examples/graph.py b/examples/graph.py index a882599..c21c9a9 100755 --- a/examples/graph.py +++ b/examples/graph.py @@ -20,7 +20,7 @@ # Urwid web site: http://excess.org/urwid/ """ -Urwid example demonstrating use of the BarGraph widget and creating a +Urwid example demonstrating use of the BarGraph widget and creating a floating-window appearance. Also shows use of alarms to create timed animation. """ @@ -33,12 +33,12 @@ import time UPDATE_INTERVAL = 0.2 def sin100( x ): - """ + """ A sin function that returns values between 0 and 100 and repeats after x == 100. """ return 50 + 50 * math.sin( x * math.pi / 50 ) - + class GraphModel: """ A class responsible for storing the data that will be displayed @@ -46,14 +46,14 @@ class GraphModel: """ data_max_value = 100 - + def __init__(self): data = [ ('Saw', range(0,100,2)*2), ('Square', [0]*30 + [100]*30), ('Sine 1', [sin100(x) for x in range(100)] ), - ('Sine 2', [(sin100(x) + sin100(x*2))/2 + ('Sine 2', [(sin100(x) + sin100(x*2))/2 for x in range(100)] ), - ('Sine 3', [(sin100(x) + sin100(x*3))/2 + ('Sine 3', [(sin100(x) + sin100(x*3))/2 for x in range(100)] ), ] self.modes = [] @@ -61,13 +61,13 @@ class GraphModel: for m, d in data: self.modes.append(m) self.data[m] = d - + def get_modes(self): return self.modes - + def set_mode(self, m): self.current_mode = m - + def get_data(self, offset, r): """ Return the data in [offset:offset+r], the maximum value @@ -108,11 +108,11 @@ class GraphView(urwid.WidgetWrap): ('pg complete', 'white', 'dark magenta'), ('pg smooth', 'dark magenta','black') ] - + graph_samples_per_bar = 10 graph_num_bars = 5 graph_offset_per_second = 5 - + def __init__(self, controller): self.controller = controller self.started = True @@ -146,7 +146,7 @@ class GraphView(urwid.WidgetWrap): else: l.append([value,0]) self.graph.set_data(l,max_value) - + # also update progress if (o//repeat)&1: # show 100% for first half, 0 for second half @@ -171,8 +171,8 @@ class GraphView(urwid.WidgetWrap): self.started = True self.start_time = time.time() self.controller.animate_graph() - - + + def on_reset_button(self, w): self.offset = 0 self.start_time = time.time() @@ -199,13 +199,13 @@ class GraphView(urwid.WidgetWrap): self.animate_progress = self.progress_bar( state ) self.animate_progress_wrap._w = self.animate_progress self.update_graph( True ) - + def main_shadow(self, w): """Wrap a shadow and background around widget w.""" bg = urwid.AttrWrap(urwid.SolidFill(u"\u2592"), 'screen edge') shadow = urwid.AttrWrap(urwid.SolidFill(u" "), 'main shadow') - + bg = urwid.Overlay( shadow, bg, ('fixed left', 3), ('fixed right', 1), ('fixed top', 2), ('fixed bottom', 1)) @@ -213,7 +213,7 @@ class GraphView(urwid.WidgetWrap): ('fixed left', 2), ('fixed right', 3), ('fixed top', 1), ('fixed bottom', 2)) return w - + def bar_graph(self, smooth=False): satt = None if smooth: @@ -233,7 +233,7 @@ class GraphView(urwid.WidgetWrap): def progress_bar(self, smooth=False): if smooth: - return urwid.ProgressBar('pg normal', 'pg complete', + return urwid.ProgressBar('pg normal', 'pg complete', 0, 1, 'pg smooth') else: return urwid.ProgressBar('pg normal', 'pg complete', @@ -255,11 +255,11 @@ class GraphView(urwid.WidgetWrap): self.on_animate_button( self.animate_button ) self.offset = 0 self.animate_progress = self.progress_bar() - animate_controls = urwid.GridFlow( [ + animate_controls = urwid.GridFlow( [ self.animate_button, self.button("Reset", self.on_reset_button), ], 9, 2, 0, 'center') - + if urwid.get_encoding_mode() == "utf8": unicode_checkbox = urwid.CheckBox( "Enable Unicode Graphics", @@ -267,10 +267,10 @@ class GraphView(urwid.WidgetWrap): else: unicode_checkbox = urwid.Text( "UTF-8 encoding not detected") - + self.animate_progress_wrap = urwid.WidgetWrap( self.animate_progress) - + l = [ urwid.Text("Mode",align="center"), ] + self.mode_buttons + [ urwid.Divider(), @@ -285,7 +285,7 @@ class GraphView(urwid.WidgetWrap): w = urwid.ListBox(urwid.SimpleListWalker(l)) return w - def main_window(self): + def main_window(self): self.graph = self.bar_graph() self.graph_wrap = urwid.WidgetWrap( self.graph ) vline = urwid.AttrWrap( urwid.SolidFill(u'\u2502'), 'line') @@ -299,7 +299,7 @@ class GraphView(urwid.WidgetWrap): w = urwid.AttrWrap(w,'line') w = self.main_shadow(w) return w - + class GraphController: """ @@ -320,17 +320,17 @@ class GraphController: def get_modes(self): """Allow our view access to the list of modes.""" return self.model.get_modes() - + def set_mode(self, m): """Allow our view to set the mode.""" rval = self.model.set_mode( m ) self.view.update_graph(True) return rval - + def get_data(self, offset, range): """Provide data to our view for the graph.""" return self.model.get_data( offset, range ) - + def main(self): self.loop = urwid.MainLoop(self.view, self.view.palette) @@ -347,10 +347,10 @@ class GraphController: if self.animate_alarm: self.loop.remove_alarm(self.animate_alarm) self.animate_alarm = None - + def main(): GraphController().main() - + if '__main__'==__name__: main() diff --git a/examples/input_test.py b/examples/input_test.py index e202162..2c154bc 100755 --- a/examples/input_test.py +++ b/examples/input_test.py @@ -63,9 +63,9 @@ def key_test(): t += ["("] + out + [")"] else: t += ["'",('key',k),"' "] - + rawt = urwid.Text(", ".join(["%d"%r for r in raw])) - + if t: lw.append( urwid.Columns([ @@ -87,8 +87,8 @@ def key_test(): loop.run() finally: screen.tty_signal_keys(*old) - - + + def main(): @@ -96,7 +96,7 @@ def main(): if urwid.web_display.handle_short_request(): return key_test() - + if '__main__'==__name__ or urwid.web_display.is_web_request(): main() diff --git a/examples/lcd_cf635.py b/examples/lcd_cf635.py index 77e8f17..09f66ef 100755 --- a/examples/lcd_cf635.py +++ b/examples/lcd_cf635.py @@ -13,7 +13,7 @@ The crystalfontz 635 has these characters in ROM: ...... ...... ...... 0x11 0xd0 0xbb -By adding the characters in CGRAM below we can use them as part of a +By adding the characters in CGRAM below we can use them as part of a horizontal slider control, selected check box and selected radio button respectively. """ @@ -22,14 +22,14 @@ import sys import urwid.lcd_display CGRAM = """ -...... ...... ...... ...... ..X... ...... ...... ...... -XXXXXX XXXXXX XXXXXX XXXXXX X.XX.. .XXXXX ..XXX. .....X -...... XX.... XXXX.. XXXXXX X.XXX. .X...X .X...X ....XX -...... XX.... XXXX.. XXXXXX X.XXXX .X...X .X...X .X.XX. -...... XX.... XXXX.. XXXXXX X.XXX. .X...X .X...X .XXX.. -XXXXXX XXXXXX XXXXXX XXXXXX X.XX.. .XXXXX ..XXX. ..X... -...... ...... ...... ...... ..X... ...... ...... ...... -...... ...... ...... ...... ...... ...... ...... ...... +...... ...... ...... ...... ..X... ...... ...... ...... +XXXXXX XXXXXX XXXXXX XXXXXX X.XX.. .XXXXX ..XXX. .....X +...... XX.... XXXX.. XXXXXX X.XXX. .X...X .X...X ....XX +...... XX.... XXXX.. XXXXXX X.XXXX .X...X .X...X .X.XX. +...... XX.... XXXX.. XXXXXX X.XXX. .X...X .X...X .XXX.. +XXXXXX XXXXXX XXXXXX XXXXXX X.XX.. .XXXXX ..XXX. ..X... +...... ...... ...... ...... ..X... ...... ...... ...... +...... ...... ...... ...... ...... ...... ...... ...... """ def program_cgram(screen): @@ -94,11 +94,11 @@ class LCDProgressBar(urwid.FlowWidget): filled = urwid.int_scale(self.value, self.range, steps) full_segments = int(filled / (len(self.segments) - 1)) last_char = filled % (len(self.segments) - 1) + 1 - s = (self.segments[-1] * full_segments + + s = (self.segments[-1] * full_segments + self.segments[last_char] + self.segments[0] * (maxcol -full_segments - 1)) return urwid.Text(s).render(size) - + def move_position(self, size, direction): """ Update and return the value one step +ve or -ve, based on @@ -166,7 +166,7 @@ class MenuOption(urwid.Button): ('fixed', 1, urwid.SelectableIcon('\xdf', cursor_position=0)), self._label]) - urwid.connect_signal(self, 'click', + urwid.connect_signal(self, 'click', lambda option: show_menu(submenu)) def keypress(self, size, key): @@ -214,10 +214,10 @@ def build_menus(): apply an exponential transformation to values sent so that apparent brightness increases in a natural way. """ - return lambda value: screen.set_led_pin(index, rg, - [0, 1, 2, 3, 4, 5, 6, 8, 11, 14, 18, + return lambda value: screen.set_led_pin(index, rg, + [0, 1, 2, 3, 4, 5, 6, 8, 11, 14, 18, 23, 29, 38, 48, 61, 79, 100][value]) - + return urwid.Columns([ ('fixed', 2, urwid.Text('%dR' % index)), LCDHorizontalSlider(18, 0, exp_scale_led(0)), @@ -228,15 +228,15 @@ def build_menus(): menu_structure = [ ('Display Settings', [ display_setting('Brightness', 101, screen.set_backlight), - display_setting('Contrast', 76, + display_setting('Contrast', 76, lambda x: screen.set_lcd_contrast(x + 75)), ]), ('Cursor Settings', [ cursor_option('Block', screen.CURSOR_BLINKING_BLOCK), cursor_option('Underscore', screen.CURSOR_UNDERSCORE), - cursor_option('Block + Underscore', + cursor_option('Block + Underscore', screen.CURSOR_BLINKING_BLOCK_UNDERSCORE), - cursor_option('Inverting Block', + cursor_option('Inverting Block', screen.CURSOR_INVERTING_BLINKING_BLOCK), ]), ('LEDs', [ @@ -279,7 +279,7 @@ screen = urwid.lcd_display.CF635Screen(sys.argv[1]) # set up our font program_cgram(screen) loop = urwid.MainLoop(build_menus(), screen=screen) -# FIXME: want screen to know it is in narrow mode, or better yet, +# FIXME: want screen to know it is in narrow mode, or better yet, # do the unicode conversion for us urwid.set_encoding('narrow') diff --git a/examples/palette_test.py b/examples/palette_test.py index 271dd51..820feb5 100755 --- a/examples/palette_test.py +++ b/examples/palette_test.py @@ -34,10 +34,10 @@ CHART_256 = """ brown__ dark_red_ dark_magenta_ dark_blue_ dark_cyan_ dark_green_ yellow_ light_red light_magenta light_blue light_cyan light_green - #00f#06f#08f#0af#0df#0ff black_______ dark_gray___ + #00f#06f#08f#0af#0df#0ff black_______ dark_gray___ #60f#00d#06d#08d#0ad#0dd#0fd light_gray__ white_______ - #80f#60d#00a#06a#08a#0aa#0da#0fa - #a0f#80d#60a#008#068#088#0a8#0d8#0f8 + #80f#60d#00a#06a#08a#0aa#0da#0fa + #a0f#80d#60a#008#068#088#0a8#0d8#0f8 #d0f#a0d#80d#608#006#066#086#0a6#0d6#0f6 #f0f#d0d#a0a#808#606#000#060#080#0a0#0d0#0f0#0f6#0f8#0fa#0fd#0ff #f0d#d0a#a08#806#600#660#680#6a0#6d0#6f0#6f6#6f8#6fa#6fd#6ff#0df @@ -50,29 +50,29 @@ yellow_ light_red light_magenta light_blue light_cyan light_green #86d#66a#68a#6aa#6da #f80#f86#f88#f8a#f8d#f8f#d6f#a0f #a6d#86a#668#688#6a8#6d8 #f60#f66#f68#f6a#f6d#f6f#d0f #d6d#a6a#868#666#686#6a6#6d6#6d8#6da#6dd #f00#f06#f08#f0a#f0d#f0f - #d6a#a68#866#886#8a6#8d6#8d8#8da#8dd#6ad - #d68#a66#a86#aa6#ad6#ad8#ada#add#8ad#68d - #d66#d86#da6#dd6#dd8#dda#ddd#aad#88d#66d g78_g82_g85_g89_g93_g100 + #d6a#a68#866#886#8a6#8d6#8d8#8da#8dd#6ad + #d68#a66#a86#aa6#ad6#ad8#ada#add#8ad#68d + #d66#d86#da6#dd6#dd8#dda#ddd#aad#88d#66d g78_g82_g85_g89_g93_g100 #da6#da8#daa#dad#a8d#86d g52_g58_g62_g66_g70_g74_ #88a#8aa #d86#d88#d8a#d8d#a6d g27_g31_g35_g38_g42_g46_g50_ #a8a#888#8a8#8aa #d66#d68#d6a#d6d g0__g3__g7__g11_g15_g19_g23_ - #a88#aa8#aaa#88a + #a88#aa8#aaa#88a #a88#a8a -""" +""" CHART_88 = """ brown__ dark_red_ dark_magenta_ dark_blue_ dark_cyan_ dark_green_ yellow_ light_red light_magenta light_blue light_cyan light_green - #00f#08f#0cf#0ff black_______ dark_gray___ - #80f#00c#08c#0cc#0fc light_gray__ white_______ + #00f#08f#0cf#0ff black_______ dark_gray___ + #80f#00c#08c#0cc#0fc light_gray__ white_______ #c0f#80c#008#088#0c8#0f8 -#f0f#c0c#808#000#080#0c0#0f0#0f8#0fc#0ff #88c#8cc - #f0c#c08#800#880#8c0#8f0#8f8#8fc#8ff#0cf #c8c#888#8c8#8cc +#f0f#c0c#808#000#080#0c0#0f0#0f8#0fc#0ff #88c#8cc + #f0c#c08#800#880#8c0#8f0#8f8#8fc#8ff#0cf #c8c#888#8c8#8cc #f08#c00#c80#cc0#cf0#cf8#cfc#cff#8cf#08f #c88#cc8#ccc#88c - #f00#f80#fc0#ff0#ff8#ffc#fff#ccf#88f#00f #c88#c8c - #fc0#fc8#fcc#fcf#c8f#80f - #f80#f88#f8c#f8f#c0f g62_g74_g82_g89_g100 + #f00#f80#fc0#ff0#ff8#ffc#fff#ccf#88f#00f #c88#c8c + #fc0#fc8#fcc#fcf#c8f#80f + #f80#f88#f8c#f8f#c0f g62_g74_g82_g89_g100 #f00#f08#f0c#f0f g0__g19_g35_g46_g52 """ @@ -80,7 +80,7 @@ CHART_16 = """ brown__ dark_red_ dark_magenta_ dark_blue_ dark_cyan_ dark_green_ yellow_ light_red light_magenta light_blue light_cyan light_green -black_______ dark_gray___ light_gray__ white_______ +black_______ dark_gray___ light_gray__ white_______ """ ATTR_RE = re.compile("(?P<whitespace>[ \n]*)(?P<entry>[^ \n]+)") @@ -115,7 +115,7 @@ def parse_chart(chart, convert): attr, text = attrtext out.append((attr, text.ljust(elen))) return out - + def foreground_chart(chart, background, colors): """ Create text markup for a foreground colour chart @@ -199,7 +199,7 @@ def main(): if state: is_foreground_chart = chart_radio_buttons[0].state set_mode(colors, is_foreground_chart) - + def mode_rb(text, colors, state=False): # mode radio buttons rb = urwid.RadioButton(mode_radio_buttons, text, state) @@ -209,10 +209,10 @@ def main(): def on_chart_change(rb, state): # handle foreground check box state change set_mode(screen.colors, state) - + def click_exit(button): raise urwid.ExitMainLoop() - + lb.extend([ urwid.AttrMap(urwid.Text("Urwid Palette Test"), 'header'), urwid.AttrMap(urwid.Columns([ @@ -238,7 +238,7 @@ def main(): ]) set_mode(16, True) # displays the chart - + def unhandled_input(key): if key in ('Q','q','esc'): raise urwid.ExitMainLoop() diff --git a/examples/treesample.py b/examples/treesample.py index 5d492c4..f6f771d 100755 --- a/examples/treesample.py +++ b/examples/treesample.py @@ -78,7 +78,7 @@ class ExampleTreeBrowser: ('flag', 'dark gray', 'light gray'), ('error', 'dark red', 'light gray'), ] - + footer_text = [ ('title', "Example Data Browser"), " ", ('key', "UP"), ",", ('key', "DOWN"), ",", @@ -87,7 +87,7 @@ class ExampleTreeBrowser: ('key', "+"), ",", ('key', "-"), " ", ('key', "LEFT"), " ", - ('key', "HOME"), " ", + ('key', "HOME"), " ", ('key', "END"), " ", ('key', "Q"), ] @@ -99,14 +99,14 @@ class ExampleTreeBrowser: self.header = urwid.Text( "" ) self.footer = urwid.AttrWrap( urwid.Text( self.footer_text ), 'foot') - self.view = urwid.Frame( - urwid.AttrWrap( self.listbox, 'body' ), - header=urwid.AttrWrap(self.header, 'head' ), + self.view = urwid.Frame( + urwid.AttrWrap( self.listbox, 'body' ), + header=urwid.AttrWrap(self.header, 'head' ), footer=self.footer ) def main(self): """Run the program.""" - + self.loop = urwid.MainLoop(self.view, self.palette, unhandled_input=self.unhandled_input) self.loop.run() @@ -123,7 +123,7 @@ def get_example_tree(): retval['children'].append({"name":"child " + str(i)}) retval['children'][i]['children']=[] for j in range(10): - retval['children'][i]['children'].append({"name":"grandchild " + + retval['children'][i]['children'].append({"name":"grandchild " + str(i) + "." + str(j)}) return retval @@ -133,6 +133,6 @@ def main(): ExampleTreeBrowser(sample).main() -if __name__=="__main__": +if __name__=="__main__": main() |