<s> """<STR_LIT>""" <EOL> from Tkinter import ( <EOL> ACTIVE , Button , Canvas , E , END , Entry , Frame , Label , LEFT , Listbox , <EOL> mainloop , N , S , StringVar , Toplevel , Tk , W ) <EOL> from tkSimpleDialog import _QueryString <EOL> from tkFileDialog import _Dialog <EOL> from twisted . spread import pb <EOL> from twisted import copyright <EOL> import string <EOL> class _QueryPassword ( _QueryString ) : <EOL> def body ( self , master ) : <EOL> w = Label ( master , text = self . prompt , justify = LEFT ) <EOL> w . grid ( row = <NUM_LIT:0> , padx = <NUM_LIT:5> , sticky = W ) <EOL> self . entry = Entry ( master , name = "<STR_LIT>" , show = "<STR_LIT:*>" ) <EOL> self . entry . grid ( row = <NUM_LIT:1> , padx = <NUM_LIT:5> , sticky = W + E ) <EOL> if self . initialvalue : <EOL> self . entry . insert ( <NUM_LIT:0> , self . initialvalue ) <EOL> self . entry . select_range ( <NUM_LIT:0> , END ) <EOL> return self . entry <EOL> def askpassword ( title , prompt , ** kw ) : <EOL> '''<STR_LIT>''' <EOL> d = apply ( _QueryPassword , ( title , prompt ) , kw ) <EOL> return d . result <EOL> def grid_setexpand ( widget ) : <EOL> cols , rows = widget . grid_size ( ) <EOL> for i in range ( cols ) : <EOL> widget . columnconfigure ( i , weight = <NUM_LIT:1> ) <EOL> for i in range ( rows ) : <EOL> widget . rowconfigure ( i , weight = <NUM_LIT:1> ) <EOL> class CList ( Frame ) : <EOL> def __init__ ( self , parent , labels , disablesorting = <NUM_LIT:0> , ** kw ) : <EOL> Frame . __init__ ( self , parent ) <EOL> self . labels = labels <EOL> self . lists = [ ] <EOL> self . disablesorting = disablesorting <EOL> kw [ "<STR_LIT>" ] = <NUM_LIT:0> <EOL> for i in range ( len ( labels ) ) : <EOL> b = Button ( self , text = labels [ i ] , anchor = W , height = <NUM_LIT:1> , pady = <NUM_LIT:0> ) <EOL> b . config ( command = lambda s = self , i = i : s . setSort ( i ) ) <EOL> b . grid ( column = i , row = <NUM_LIT:0> , sticky = N + E + W ) <EOL> box = apply ( Listbox , ( self , ) , kw ) <EOL> box . grid ( column = i , row = <NUM_LIT:1> , sticky = N + E + S + W ) <EOL> self . lists . append ( box ) <EOL> grid_setexpand ( self ) <EOL> self . rowconfigure ( <NUM_LIT:0> , weight = <NUM_LIT:0> ) <EOL> self . _callall ( "<STR_LIT>" , '<STR_LIT>' , self . Button1 ) <EOL> self . _callall ( "<STR_LIT>" , '<STR_LIT>' , self . Button1 ) <EOL> self . bind ( '<STR_LIT>' , self . UpKey ) <EOL> self . bind ( '<STR_LIT>' , self . DownKey ) <EOL> self . sort = None <EOL> def _callall ( self , funcname , * args , ** kw ) : <EOL> rets = [ ] <EOL> for l in self . lists : <EOL> func = getattr ( l , funcname ) <EOL> ret = apply ( func , args , kw ) <EOL> if ret != None : rets . append ( ret ) <EOL> if rets : return rets <EOL> def Button1 ( self , e ) : <EOL> index = self . nearest ( e . y ) <EOL> self . select_clear ( <NUM_LIT:0> , END ) <EOL> self . select_set ( index ) <EOL> self . activate ( index ) <EOL> return "<STR_LIT>" <EOL> def UpKey ( self , e ) : <EOL> index = self . index ( ACTIVE ) <EOL> if index : <EOL> self . select_clear ( <NUM_LIT:0> , END ) <EOL> self . select_set ( index - <NUM_LIT:1> ) <EOL> return "<STR_LIT>" <EOL> def DownKey ( self , e ) : <EOL> index = self . index ( ACTIVE ) <EOL> if index != self . size ( ) - <NUM_LIT:1> : <EOL> self . select_clear ( <NUM_LIT:0> , END ) <EOL> self . select_set ( index + <NUM_LIT:1> ) <EOL> return "<STR_LIT>" <EOL> def setSort ( self , index ) : <EOL> if self . sort == None : <EOL> self . sort = [ index , <NUM_LIT:1> ] <EOL> elif self . sort [ <NUM_LIT:0> ] == index : <EOL> self . sort [ <NUM_LIT:1> ] = - self . sort [ <NUM_LIT:1> ] <EOL> else : <EOL> self . sort = [ index , <NUM_LIT:1> ] <EOL> self . _sort ( ) <EOL> def _sort ( self ) : <EOL> if self . disablesorting : <EOL> return <EOL> if self . sort == None : <EOL> return <EOL> ind , direc = self . sort <EOL> li = list ( self . get ( <NUM_LIT:0> , END ) ) <EOL> li . sort ( lambda x , y , i = ind , d = direc : d * cmp ( x [ i ] , y [ i ] ) ) <EOL> self . delete ( <NUM_LIT:0> , END ) <EOL> for l in li : <EOL> self . _insert ( END , l ) <EOL> def activate ( self , index ) : <EOL> self . _callall ( "<STR_LIT>" , index ) <EOL> def curselection ( self ) : <EOL> return self . lists [ <NUM_LIT:0> ] . curselection ( ) <EOL> def delete ( self , * args ) : <EOL> apply ( self . _callall , ( "<STR_LIT>" , ) + args ) <EOL> def get ( self , * args ) : <EOL> bad = apply ( self . _callall , ( "<STR_LIT>" , ) + args ) <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> return bad <EOL> ret = [ ] <EOL> for i in range ( len ( bad [ <NUM_LIT:0> ] ) ) : <EOL> r = [ ] <EOL> for j in range ( len ( bad ) ) : <EOL> r . append ( bad [ j ] [ i ] ) <EOL> ret . append ( r ) <EOL> return ret <EOL> def index ( self , index ) : <EOL> return self . lists [ <NUM_LIT:0> ] . index ( index ) <EOL> def insert ( self , index , items ) : <EOL> self . _insert ( index , items ) <EOL> self . _sort ( ) <EOL> def _insert ( self , index , items ) : <EOL> for i in range ( len ( items ) ) : <EOL> self . lists [ i ] . insert ( index , items [ i ] ) <EOL> def nearest ( self , y ) : <EOL> return self . lists [ <NUM_LIT:0> ] . nearest ( y ) <EOL> def see ( self , index ) : <EOL> self . _callall ( "<STR_LIT>" , index ) <EOL> def size ( self ) : <EOL> return self . lists [ <NUM_LIT:0> ] . size ( ) <EOL> def selection_anchor ( self , index ) : <EOL> self . _callall ( "<STR_LIT>" , index ) <EOL> select_anchor = selection_anchor <EOL> def selection_clear ( self , * args ) : <EOL> apply ( self . _callall , ( "<STR_LIT>" , ) + args ) <EOL> select_clear = selection_clear <EOL> def selection_includes ( self , index ) : <EOL> return self . lists [ <NUM_LIT:0> ] . select_includes ( index ) <EOL> select_includes = selection_includes <EOL> def selection_set ( self , * args ) : <EOL> apply ( self . _callall , ( "<STR_LIT>" , ) + args ) <EOL> select_set = selection_set <EOL> def xview ( self , * args ) : <EOL> if not args : return self . lists [ <NUM_LIT:0> ] . xview ( ) <EOL> apply ( self . _callall , ( "<STR_LIT>" , ) + args ) <EOL> def yview ( self , * args ) : <EOL> if not args : return self . lists [ <NUM_LIT:0> ] . yview ( ) <EOL> apply ( self . _callall , ( "<STR_LIT>" , ) + args ) <EOL> class ProgressBar : <EOL> def __init__ ( self , master = None , orientation = "<STR_LIT>" , <EOL> min = <NUM_LIT:0> , max = <NUM_LIT:100> , width = <NUM_LIT:100> , height = <NUM_LIT> , <EOL> doLabel = <NUM_LIT:1> , appearance = "<STR_LIT>" , <EOL> fillColor = "<STR_LIT>" , background = "<STR_LIT>" , <EOL> labelColor = "<STR_LIT>" , labelFont = "<STR_LIT>" , <EOL> labelText = "<STR_LIT>" , labelFormat = "<STR_LIT>" , <EOL> value = <NUM_LIT:0> , bd = <NUM_LIT:2> ) : <EOL> self . master = master <EOL> self . orientation = orientation <EOL> self . min = min <EOL> self . max = max <EOL> self . width = width <EOL> self . height = height <EOL> self . doLabel = doLabel <EOL> self . fillColor = fillColor <EOL> self . labelFont = labelFont <EOL> self . labelColor = labelColor <EOL> self . background = background <EOL> self . labelText = labelText <EOL> self . labelFormat = labelFormat <EOL> self . value = value <EOL> self . frame = Frame ( master , relief = appearance , bd = bd ) <EOL> self . canvas = Canvas ( self . frame , height = height , width = width , bd = <NUM_LIT:0> , <EOL> highlightthickness = <NUM_LIT:0> , background = background ) <EOL> self . scale = self . canvas . create_rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , width , height , <EOL> fill = fillColor ) <EOL> self . label = self . canvas . create_text ( self . canvas . winfo_reqwidth ( ) / <NUM_LIT:2> , <EOL> height / <NUM_LIT:2> , text = labelText , <EOL> anchor = "<STR_LIT:c>" , fill = labelColor , <EOL> font = self . labelFont ) <EOL> self . update ( ) <EOL> self . canvas . pack ( side = '<STR_LIT>' , fill = '<STR_LIT:x>' , expand = '<STR_LIT>' ) <EOL> def updateProgress ( self , newValue , newMax = None ) : <EOL> if newMax : <EOL> self . max = newMax <EOL> self . value = newValue <EOL> self . update ( ) <EOL> def update ( self ) : <EOL> value = self . value <EOL> if value > self . max : <EOL> value = self . max <EOL> if value < self . min : <EOL> value = self . min <EOL> if self . orientation == "<STR_LIT>" : <EOL> self . canvas . coords ( self . scale , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> float ( value ) / self . max * self . width , self . height ) <EOL> else : <EOL> self . canvas . coords ( self . scale , <NUM_LIT:0> , <EOL> self . height - ( float ( value ) / <EOL> self . max * self . height ) , <EOL> self . width , self . height ) <EOL> self . canvas . itemconfig ( self . scale , fill = self . fillColor ) <EOL> self . canvas . itemconfig ( self . label , fill = self . labelColor ) <EOL> if self . doLabel : <EOL> if value : <EOL> if value >= <NUM_LIT:0> : <EOL> pvalue = int ( ( float ( value ) / float ( self . max ) ) * <EOL> <NUM_LIT> ) <EOL> else : <EOL> pvalue = <NUM_LIT:0> <EOL> self . canvas . itemconfig ( self . label , text = self . labelFormat <EOL> % pvalue ) <EOL> else : <EOL> self . canvas . itemconfig ( self . label , text = '<STR_LIT>' ) <EOL> else : <EOL> self . canvas . itemconfig ( self . label , text = self . labelFormat % <EOL> self . labelText ) <EOL> self . canvas . update_idletasks ( ) <EOL> class DirectoryBrowser ( _Dialog ) : <EOL> command = "<STR_LIT>" <EOL> def askdirectory ( ** options ) : <EOL> "<STR_LIT>" <EOL> return apply ( DirectoryBrowser , ( ) , options ) . show ( ) <EOL> class GenericLogin ( Toplevel ) : <EOL> def __init__ ( self , callback , buttons ) : <EOL> Toplevel . __init__ ( self ) <EOL> self . callback = callback <EOL> Label ( self , text = "<STR_LIT>" % copyright . version ) . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:0> , columnspan = <NUM_LIT:2> ) <EOL> self . entries = { } <EOL> row = <NUM_LIT:1> <EOL> for stuff in buttons : <EOL> label , value = stuff [ : <NUM_LIT:2> ] <EOL> if len ( stuff ) == <NUM_LIT:3> : <EOL> dict = stuff [ <NUM_LIT:2> ] <EOL> else : dict = { } <EOL> Label ( self , text = label + "<STR_LIT>" ) . grid ( column = <NUM_LIT:0> , row = row ) <EOL> e = apply ( Entry , ( self , ) , dict ) <EOL> e . grid ( column = <NUM_LIT:1> , row = row ) <EOL> e . insert ( <NUM_LIT:0> , value ) <EOL> self . entries [ label ] = e <EOL> row = row + <NUM_LIT:1> <EOL> Button ( self , text = "<STR_LIT>" , command = self . doLogin ) . grid ( column = <NUM_LIT:0> , row = row ) <EOL> Button ( self , text = "<STR_LIT>" , command = self . close ) . grid ( column = <NUM_LIT:1> , row = row ) <EOL> self . protocol ( '<STR_LIT>' , self . close ) <EOL> def close ( self ) : <EOL> self . tk . quit ( ) <EOL> self . destroy ( ) <EOL> def doLogin ( self ) : <EOL> values = { } <EOL> for k in self . entries . keys ( ) : <EOL> values [ string . lower ( k ) ] = self . entries [ k ] . get ( ) <EOL> self . callback ( values ) <EOL> self . destroy ( ) <EOL> class Login ( Toplevel ) : <EOL> def __init__ ( self , <EOL> callback , <EOL> referenced = None , <EOL> initialUser = "<STR_LIT>" , <EOL> initialPassword = "<STR_LIT>" , <EOL> initialHostname = "<STR_LIT:localhost>" , <EOL> initialService = "<STR_LIT>" , <EOL> initialPortno = pb . portno ) : <EOL> Toplevel . __init__ ( self ) <EOL> version_label = Label ( self , text = "<STR_LIT>" % copyright . version ) <EOL> self . pbReferenceable = referenced <EOL> self . pbCallback = callback <EOL> self . username = Entry ( self ) <EOL> self . password = Entry ( self , show = '<STR_LIT:*>' ) <EOL> self . hostname = Entry ( self ) <EOL> self . service = Entry ( self ) <EOL> self . port = Entry ( self ) <EOL> self . username . insert ( <NUM_LIT:0> , initialUser ) <EOL> self . password . insert ( <NUM_LIT:0> , initialPassword ) <EOL> self . service . insert ( <NUM_LIT:0> , initialService ) <EOL> self . hostname . insert ( <NUM_LIT:0> , initialHostname ) <EOL> self . port . insert ( <NUM_LIT:0> , str ( initialPortno ) ) <EOL> userlbl = Label ( self , text = "<STR_LIT>" ) <EOL> passlbl = Label ( self , text = "<STR_LIT>" ) <EOL> servicelbl = Label ( self , text = "<STR_LIT>" ) <EOL> hostlbl = Label ( self , text = "<STR_LIT>" ) <EOL> portlbl = Label ( self , text = "<STR_LIT>" ) <EOL> self . logvar = StringVar ( ) <EOL> self . logvar . set ( "<STR_LIT>" % pb . Broker . version ) <EOL> self . logstat = Label ( self , textvariable = self . logvar ) <EOL> self . okbutton = Button ( self , text = "<STR_LIT>" , command = self . login ) <EOL> version_label . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:0> , columnspan = <NUM_LIT:2> ) <EOL> z = <NUM_LIT:0> <EOL> for i in [ [ userlbl , self . username ] , <EOL> [ passlbl , self . password ] , <EOL> [ hostlbl , self . hostname ] , <EOL> [ servicelbl , self . service ] , <EOL> [ portlbl , self . port ] ] : <EOL> i [ <NUM_LIT:0> ] . grid ( column = <NUM_LIT:0> , row = z + <NUM_LIT:1> ) <EOL> i [ <NUM_LIT:1> ] . grid ( column = <NUM_LIT:1> , row = z + <NUM_LIT:1> ) <EOL> z = z + <NUM_LIT:1> <EOL> self . logstat . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:6> , columnspan = <NUM_LIT:2> ) <EOL> self . okbutton . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:7> , columnspan = <NUM_LIT:2> ) <EOL> self . protocol ( '<STR_LIT>' , self . tk . quit ) <EOL> def loginReset ( self ) : <EOL> self . logvar . set ( "<STR_LIT>" ) <EOL> def loginReport ( self , txt ) : <EOL> self . logvar . set ( txt ) <EOL> self . after ( <NUM_LIT> , self . loginReset ) <EOL> def login ( self ) : <EOL> host = self . hostname . get ( ) <EOL> port = self . port . get ( ) <EOL> service = self . service . get ( ) <EOL> try : <EOL> port = int ( port ) <EOL> except : <EOL> pass <EOL> user = self . username . get ( ) <EOL> pswd = self . password . get ( ) <EOL> pb . connect ( host , port , user , pswd , service , <EOL> client = self . pbReferenceable ) . addCallback ( self . pbCallback ) . addErrback ( <EOL> self . couldNotConnect ) <EOL> def couldNotConnect ( self , f ) : <EOL> self . loginReport ( "<STR_LIT>" + f . getErrorMessage ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> root = Tk ( ) <EOL> o = CList ( root , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> o . pack ( ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:16> , <NUM_LIT:4> ) : <EOL> o . insert ( END , [ i , i + <NUM_LIT:1> , i + <NUM_LIT:2> , i + <NUM_LIT:3> ] ) <EOL> mainloop ( ) </s>
