<s> """<STR_LIT>""" <EOL> __all__ = [ '<STR_LIT>' ] <EOL> import os <EOL> import sys <EOL> import pyclbr <EOL> from . import PyShell <EOL> from . WindowList import ListedToplevel <EOL> from . TreeWidget import TreeNode , TreeItem , ScrolledCanvas <EOL> from . configHandler import idleConf <EOL> def collect_objects ( d , name = None ) : <EOL> items = [ ] <EOL> objects = { } <EOL> for key , cl in list ( d . items ( ) ) : <EOL> if name is None or cl . module == name : <EOL> s = key <EOL> if hasattr ( cl , '<STR_LIT>' ) and cl . super : <EOL> supers = [ ] <EOL> for sup in cl . super : <EOL> if type ( sup ) is type ( '<STR_LIT>' ) : <EOL> sname = sup <EOL> else : <EOL> sname = sup . name <EOL> if sup . module != cl . module : <EOL> sname = "<STR_LIT>" % ( sup . module , sname ) <EOL> supers . append ( sname ) <EOL> s = s + "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( supers ) <EOL> items . append ( ( cl . lineno , s ) ) <EOL> objects [ s ] = cl <EOL> return objects , items <EOL> class ClassBrowser : <EOL> def __init__ ( self , flist , name , path ) : <EOL> self . name = name <EOL> self . file = os . path . join ( path [ <NUM_LIT:0> ] , self . name + "<STR_LIT>" ) <EOL> self . init ( flist ) <EOL> def close ( self , event = None ) : <EOL> self . top . destroy ( ) <EOL> self . node . destroy ( ) <EOL> def init ( self , flist ) : <EOL> self . flist = flist <EOL> pyclbr . _modules . clear ( ) <EOL> self . top = top = ListedToplevel ( flist . root ) <EOL> top . protocol ( "<STR_LIT>" , self . close ) <EOL> top . bind ( "<STR_LIT>" , self . close ) <EOL> self . settitle ( ) <EOL> top . focus_set ( ) <EOL> theme = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ) <EOL> background = idleConf . GetHighlight ( theme , '<STR_LIT>' ) [ '<STR_LIT>' ] <EOL> sc = ScrolledCanvas ( top , bg = background , highlightthickness = <NUM_LIT:0> , takefocus = <NUM_LIT:1> ) <EOL> sc . frame . pack ( expand = <NUM_LIT:1> , fill = "<STR_LIT>" ) <EOL> item = self . rootnode ( ) <EOL> self . node = node = TreeNode ( sc . canvas , None , item ) <EOL> node . update ( ) <EOL> node . expand ( ) <EOL> def settitle ( self ) : <EOL> self . top . wm_title ( "<STR_LIT>" + self . name ) <EOL> self . top . wm_iconname ( "<STR_LIT>" ) <EOL> def rootnode ( self ) : <EOL> return ModuleBrowserTreeItem ( self . file ) <EOL> class ModuleBrowserTreeItem ( TreeItem ) : <EOL> def __init__ ( self , file ) : <EOL> self . file = file <EOL> def GetText ( self ) : <EOL> return os . path . basename ( self . file ) <EOL> def GetIconName ( self ) : <EOL> return "<STR_LIT>" <EOL> def GetSubList ( self ) : <EOL> sublist = [ ] <EOL> for name in self . listobjects ( ) : <EOL> item = ObjectBrowserTreeItem ( name , self . classes , self . file ) <EOL> sublist . append ( item ) <EOL> return sublist <EOL> def OnDoubleClick ( self ) : <EOL> if os . path . normcase ( self . file [ - <NUM_LIT:3> : ] ) != "<STR_LIT>" : <EOL> return <EOL> if not os . path . exists ( self . file ) : <EOL> return <EOL> PyShell . flist . open ( self . file ) <EOL> def IsExpandable ( self ) : <EOL> return os . path . normcase ( self . file [ - <NUM_LIT:3> : ] ) == "<STR_LIT>" <EOL> def listobjects ( self ) : <EOL> dir , file = os . path . split ( self . file ) <EOL> name , ext = os . path . splitext ( file ) <EOL> if os . path . normcase ( ext ) != "<STR_LIT>" : <EOL> return [ ] <EOL> try : <EOL> dict = pyclbr . readmodule_ex ( name , [ dir ] + sys . path ) <EOL> except ImportError as msg : <EOL> return [ ] <EOL> self . classes , items = collect_objects ( dict , name ) <EOL> items . sort ( ) <EOL> return [ s for item , s in items ] <EOL> class ObjectBrowserTreeItem ( TreeItem ) : <EOL> def __init__ ( self , name , classes , file ) : <EOL> self . name = name <EOL> self . classes = classes <EOL> self . file = file <EOL> try : <EOL> self . cl = self . classes [ self . name ] <EOL> except ( IndexError , KeyError ) : <EOL> self . cl = None <EOL> self . isfunction = isinstance ( self . cl , pyclbr . Function ) <EOL> def GetText ( self ) : <EOL> if self . isfunction : <EOL> return "<STR_LIT>" + self . name + "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" + self . name <EOL> def GetIconName ( self ) : <EOL> if self . isfunction : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def IsExpandable ( self ) : <EOL> if self . cl : <EOL> try : <EOL> return not not self . cl . objects <EOL> except AttributeError : <EOL> return False <EOL> def GetSubList ( self ) : <EOL> if not self . cl : <EOL> return [ ] <EOL> sublist = [ ] <EOL> for obj in self . listobjects ( ) : <EOL> classes , item_name = obj <EOL> item = ObjectBrowserTreeItem ( item_name , classes , self . file ) <EOL> sublist . append ( item ) <EOL> return sublist <EOL> def OnDoubleClick ( self ) : <EOL> if not os . path . exists ( self . file ) : <EOL> return <EOL> edit = PyShell . flist . open ( self . file ) <EOL> if hasattr ( self . cl , '<STR_LIT>' ) : <EOL> lineno = self . cl . lineno <EOL> edit . gotoline ( lineno ) <EOL> def listobjects ( self ) : <EOL> if not self . cl : <EOL> return [ ] <EOL> result = [ ] <EOL> for name , ob in list ( self . cl . objects . items ( ) ) : <EOL> classes , items = collect_objects ( { name : ob } ) <EOL> result . append ( ( ob . lineno , classes , items [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) ) <EOL> result . sort ( ) <EOL> return [ item [ <NUM_LIT:1> : ] for item in result ] <EOL> def main ( ) : <EOL> try : <EOL> file = __file__ <EOL> except NameError : <EOL> file = sys . argv [ <NUM_LIT:0> ] <EOL> if sys . argv [ <NUM_LIT:1> : ] : <EOL> file = sys . argv [ <NUM_LIT:1> ] <EOL> else : <EOL> file = sys . argv [ <NUM_LIT:0> ] <EOL> dir , file = os . path . split ( file ) <EOL> name = os . path . splitext ( file ) [ <NUM_LIT:0> ] <EOL> ClassBrowser ( PyShell . flist , name , [ dir ] ) <EOL> if sys . stdin is sys . __stdin__ : <EOL> mainloop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
