;ò Úè@c@s¸dZdkZdkZdkZd„Zd„Zdeifd„ƒYZeZd„Z e djoLdei fd „ƒYZ d ei fd „ƒYZeeƒZeiƒndS( sg Hello, and welcome to this test of the wxTreeItemData class. The wxTreeItemData class can be used to associate a python object with a wxTreeCtrl item. In this sample, its use is demonstrated via a tree control that shows the contents of a python namespace according to the standard dir() command. Every item in the tree has its label taken from the dir() output, and 'behind it' a reference to the python object is stored in a wxTreeItemData object. As you may have guessed by now, this sample automatically displays '__doc__' strings if the selected python object happens to have one. Please expand the pyTree object to learn more about the implementation. Version 1.0, April 4 1999. Harm van der Heijden (H.v.d.Heijden@phys.tue.nl) P.S. Check out the string module. It's imported in this sample not because it's used, but because it's so beautifully documented... NcCsVd}xE|D]=}|djo|d}q |djo|d}q Pq W|SdS(s0Returns the indentation level of the given line.is is iN(sindentslinesc(slinesindentsc((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pys _getindent!s  cCs«yt|idƒ}Wnd|ifSnXx#t|iƒD]}|iƒ}q>Wt |ƒ}d}x:|o2||}|iƒ}t |ƒ|joPqiqiW|SdS(slGiven a func_code object, this function tries to find and return the python source code of the function.srs(could not open file %s)sN( sopensfuncs co_filenamesfsrangesco_firstlinenosisreadlineslines _getindentsindsmsg(sfuncsfsismsgsindsline((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pys _sourcefinder*s"    spyTreecBs;tZdZd„Zd„Zd„Zd„Zd„ZRS(s² This wx.TreeCtrl derivative displays a tree view of a Python namespace. Anything from which the dir() command returns a non-empty list is a branch in this tree. cCsçtii|||ƒ|it|ƒddti |ƒƒ|_t |ƒo|i |it ƒn|i ti|id|iƒƒ|i ti|id|iƒƒ|i ti|id|iƒƒt|_|i|iƒdS(s; Initialize function; because we insert branches into the tree as needed, we use the ITEM_EXPANDING event handler. The ITEM_COLLAPSED handler removes the stuff afterwards. The SEL_CHANGED handler attempts to display interesting information about the selected object. iÿÿÿÿsidN(swxsTreeCtrls__init__sselfsparentsidsAddRootsstrsroots TreeItemDatasdirsSetItemHasChildrensTruesBindsEVT_TREE_ITEM_EXPANDINGsOnItemExpandingsGetIdsEVT_TREE_ITEM_COLLAPSEDsOnItemCollapsedsEVT_TREE_SEL_CHANGEDs OnSelChangedsNonesoutputsExpand(sselfsparentsidsroot((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pys__init__Ks* """ cCs ||_dS(s” Set output function (accepts single string). Used to display string representation of the selected object by OnSelChanged. N(soutputsself(sselfsoutput((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pys SetOutputascCs¨|iƒ}|i|ƒodSn|i|ƒ}t|ƒ}xb|D]Z}t ||ƒ}|i ||ddt i|ƒƒ}t|ƒo|i|tƒqFqFWdS(sú The real workhorse of this class. First we retrieve the object (parent) belonging to the branch that is to be expanded. This is done by calling GetPyData(parent), which is a short-cut for GetPyItemData(parent).Get(). Then we get the dir() list of that object. For each item in this list, a tree item is created with associated wxTreeItemData referencing the child object. We get this object using child = getattr(parent, item). Finally, we check wether the child returns a non-empty dir() list. If so, it is labeled as 'having children', so that it may be expanded. When it actually is expanded, this function will again figure out what the offspring is. Niÿÿÿÿ(seventsGetItemsitemsselfs IsExpandeds GetPyDatasobjsdirslstskeysgetattrsnew_objs AppendItemswxs TreeItemDatasnew_itemsSetItemHasChildrensTrue(sselfseventsobjsnew_objsitemslstskeysnew_item((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pysOnItemExpandingis   cCs|iƒ}|i|ƒdS(s‡ We need to remove all children here, otherwise we'll see all that old rubbish again after the next expansion. N(seventsGetItemsitemsselfsDeleteChildren(sselfseventsitem((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pysOnItemCollapsedŠs cCsí|i odSn|i|iƒƒ}t|ƒ}t|dƒo|dt |dƒf}nt }t|dƒot |dƒ}n-t|dƒot t |dƒdƒ}n|o|dt |ƒ}nt |i|fƒdS(s If an output function is defined, we try to print some informative, interesting and thought-provoking stuff to it. If it has a __doc__ string, we print it. If it's a function or unbound class method, we attempt to find the python source. Ns__doc__s Documentation string: %ss func_codesim_funcs Function source: (sselfsoutputs GetPyDataseventsGetItemsobjsstrsmsgshasattrsgetattrsNonesfuncs _sourcefindersapply(sselfseventsobjsfuncsmsg((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pys OnSelChanged’s  (s__name__s __module__s__doc__s__init__s SetOutputsOnItemExpandingsOnItemCollapseds OnSelChanged(((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pyspyTreeDs    ! cCsÄtit}ti|ddƒ}ti|dƒ}t |d|ƒ}ti |dddti ƒ}|i||dƒ|i|iƒ|i|iƒ|iddfƒ||_|idƒd S( si This method is used by the wxPython Demo Framework for integrating this demo with the rest. iÿÿÿÿsPyTreeItemData TestssstyleiÈi iôiN(ssyssmoduless__name__s thisModuleswxsFramesframeswinsSplitterWindowssplitspyTreestreesTextCtrls TE_MULTILINEstextsSplitVerticallys SetOutputsSetValues SelectItemsrootsSetSizesotherWinsShow(sframesnbslogswinstreessplitstexts thisModule((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pysrunTest´s  s__main__sMyFramecBstZdZd„ZRS(s0Very standard Frame class. Nothing special here!cCs§dk}tii|tdddddfƒti|dƒ}t|d|ƒ}ti |dddti ƒ}|i ||d ƒ|i|iƒ|i|iƒdS( s;Make a splitter window; left a tree, right a textctrl. Wow.NiÿÿÿÿsPyTreeItemData Testssizei iôssstyleiÈ(s__main__swxsFrames__init__sselfsNonesSplitterWindowssplitspyTreestreesTextCtrls TE_MULTILINEstextsSplitVerticallys SetOutputsSetValues SelectItemsroot(sselfstextstreessplits__main__((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pys__init__Ís %(s__name__s __module__s__doc__s__init__(((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pysMyFrameÊs sMyAppcBstZdZd„ZRS(s1This class is even less interesting than MyFrame.cCs+tƒ}|itƒ|i|ƒtSdS(sOnInit. Boring, boring, boring!N(sMyFramesframesShowsTruesselfs SetTopWindow(sselfsframe((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pysOnInitÛs    (s__name__s __module__s__doc__sOnInit(((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pysMyAppØs (s__doc__sstringssysswxs _getindents _sourcefindersTreeCtrlspyTreesoverviewsrunTests__name__sFramesMyFramesAppsMyAppsFalsesappsMainLoop( srunTestsstringsoverviewsappspyTreessyss _sourcefindersMyApps _getindentsMyFrameswx((sf/mnt/gmirror/ports/x11-toolkits/py-wxPython26-common/work/wxPython-src-2.6.3.3/wxPython/demo/pyTree.pys?s    n