<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> __doc__ = """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import urwid <EOL> from pycopia . QA . tui import widgets <EOL> from pycopia . QA . tui import runner <EOL> from pycopia . db . tui import eventloop <EOL> class TopForm ( widgets . Form ) : <EOL> def __init__ ( self ) : <EOL> display_widget = self . build ( ) <EOL> self . __super . __init__ ( display_widget ) <EOL> def build ( self ) : <EOL> bt = urwid . BigText ( "<STR_LIT>" , urwid . HalfBlock5x4Font ( ) ) <EOL> bt = urwid . Padding ( bt , "<STR_LIT>" , None ) <EOL> menulist = [ <EOL> widgets . MenuItemWidget ( "<STR_LIT>" , self . do_run ) , <EOL> widgets . MenuItemWidget ( "<STR_LIT>" , self . do_job ) , <EOL> ] <EOL> pmenu = urwid . GridFlow ( menulist , <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:1> , "<STR_LIT:left>" ) <EOL> subhead = urwid . AttrMap ( urwid . Text ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> divider = urwid . Divider ( u"<STR_LIT:->" , top = <NUM_LIT:1> , bottom = <NUM_LIT:1> ) <EOL> formlist = [ bt , divider , subhead , pmenu ] <EOL> listbox = urwid . ListBox ( urwid . SimpleListWalker ( formlist ) ) <EOL> return urwid . Frame ( listbox ) <EOL> def do_run ( self , item ) : <EOL> frm = runner . RunnerForm ( ) <EOL> self . _emit ( "<STR_LIT>" , frm ) <EOL> def do_job ( self , item ) : <EOL> frm = runner . JobRunnerForm ( ) <EOL> self . _emit ( "<STR_LIT>" , frm ) <EOL> class TestRunnerShell ( object ) : <EOL> def __init__ ( self ) : <EOL> self . footer = urwid . AttrMap ( <EOL> urwid . Text ( [ <EOL> ( "<STR_LIT:key>" , "<STR_LIT>" ) , "<STR_LIT>" , <EOL> ( "<STR_LIT:key>" , "<STR_LIT>" ) , "<STR_LIT>" , <EOL> ( "<STR_LIT:key>" , "<STR_LIT>" ) , "<STR_LIT>" , <EOL> ] ) , <EOL> "<STR_LIT>" ) <EOL> self . reset ( ) <EOL> def unhandled_input ( self , k ) : <EOL> if k == "<STR_LIT>" : <EOL> self . _popform ( None ) <EOL> elif k == "<STR_LIT>" : <EOL> self . show_help ( ) <EOL> elif k == "<STR_LIT>" : <EOL> self . reset ( ) <EOL> elif k == "<STR_LIT>" : <EOL> pass <EOL> else : <EOL> widgets . DEBUG ( "<STR_LIT>" , k ) <EOL> def run ( self ) : <EOL> self . loop = urwid . MainLoop ( self . top , widgets . PALETTE , unhandled_input = self . unhandled_input , <EOL> event_loop = eventloop . PycopiaEventLoop ( ) ) <EOL> self . loop . run ( ) <EOL> self . loop = None <EOL> def reset ( self ) : <EOL> self . _formtrail = [ ] <EOL> self . loop = None <EOL> self . form = TopForm ( ) <EOL> urwid . connect_signal ( self . form , '<STR_LIT>' , self . _pushform ) <EOL> self . top = urwid . Frame ( self . form , footer = self . footer ) <EOL> def _pushform ( self , form , newform ) : <EOL> self . _formtrail . append ( form ) <EOL> urwid . connect_signal ( newform , '<STR_LIT>' , self . _pushform ) <EOL> urwid . connect_signal ( newform , '<STR_LIT>' , self . _popform ) <EOL> urwid . connect_signal ( newform , '<STR_LIT:message>' , self . _message ) <EOL> self . form = newform <EOL> self . top . body = self . form <EOL> def _popform ( self , form ) : <EOL> if form is not None : <EOL> urwid . disconnect_signal ( form , '<STR_LIT>' , self . _pushform ) <EOL> urwid . disconnect_signal ( form , '<STR_LIT>' , self . _popform ) <EOL> urwid . disconnect_signal ( form , '<STR_LIT:message>' , self . _message ) <EOL> if self . _formtrail : <EOL> self . form = self . _formtrail . pop ( ) <EOL> self . top . body = self . form <EOL> else : <EOL> raise urwid . ExitMainLoop ( ) <EOL> def _message ( self , form , msg ) : <EOL> self . message ( msg ) <EOL> def message ( self , msg ) : <EOL> self . top . set_footer ( urwid . AttrWrap ( urwid . Text ( msg ) , "<STR_LIT>" ) ) <EOL> self . loop . set_alarm_in ( <NUM_LIT> , self . _restore_footer ) <EOL> def _restore_footer ( self , loop , user_data ) : <EOL> self . top . set_footer ( self . footer ) <EOL> def show_help ( self ) : <EOL> hd = HelpDialog ( ) <EOL> urwid . connect_signal ( hd , '<STR_LIT>' , lambda hd : self . _restoreform ( ) ) <EOL> self . top . body = hd <EOL> def _restoreform ( self ) : <EOL> self . top . body = self . form <EOL> class HelpDialog ( urwid . WidgetWrap ) : <EOL> signals = [ '<STR_LIT>' ] <EOL> def __init__ ( self ) : <EOL> close_button = urwid . Button ( ( "<STR_LIT>" , "<STR_LIT:OK>" ) ) <EOL> urwid . connect_signal ( close_button , '<STR_LIT>' , lambda button : self . _emit ( "<STR_LIT>" ) ) <EOL> lb = urwid . LineBox ( urwid . Filler ( urwid . Pile ( [ urwid . Text ( __doc__ ) , close_button ] ) , valign = "<STR_LIT>" ) ) <EOL> self . __super . __init__ ( lb ) <EOL> def main ( argv ) : <EOL> """<STR_LIT>""" <EOL> from pycopia import getopt <EOL> debug = <NUM_LIT:0> <EOL> try : <EOL> optlist , longopts , args = getopt . getopt ( argv [ <NUM_LIT:1> : ] , "<STR_LIT>" ) <EOL> except getopt . GetoptError : <EOL> print ( main . __doc__ ) <EOL> return <EOL> for opt , val in optlist : <EOL> if opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> print ( main . __doc__ ) <EOL> return <EOL> elif opt == "<STR_LIT>" : <EOL> debug += <NUM_LIT:1> <EOL> elif opt == "<STR_LIT>" : <EOL> from pycopia import autodebug <EOL> if debug : <EOL> from pycopia import logwindow <EOL> widgets . DEBUG = logwindow . DebugLogWindow ( do_stderr = True ) <EOL> app = TestRunnerShell ( ) <EOL> try : <EOL> app . run ( ) <EOL> except : <EOL> if debug : <EOL> ex , val , tb = sys . exc_info ( ) <EOL> from pycopia import debugger <EOL> if debug > <NUM_LIT:1> : <EOL> from pycopia import IOurxvt <EOL> io = IOurxvt . UrxvtIO ( ) <EOL> else : <EOL> io = None <EOL> debugger . post_mortem ( tb , ex , val , io ) <EOL> widgets . DEBUG . close ( ) <EOL> if debug > <NUM_LIT:1> : <EOL> io . close ( ) <EOL> else : <EOL> raise <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( [ "<STR_LIT>" , "<STR_LIT>" ] ) </s>
