ó «‡Uc@sŒdZddlZejdƒddlZddlZdejfd„ƒYZdejfd„ƒYZd„Z e d krˆe ƒndS( s›Tree View/Generic Tree Model This test is designed to demonstrate creating a new type of tree model in python for use with the new tree widget in gtk 2.0.iÿÿÿÿNs2.0t MyTreeModelcBseZdZdZdZd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„ZRS(s1This class represents the model of a tree. The iterators used to represent positions are converted to python objects when passed to the on_* methods. This means you can use any python object to represent a node in the tree. The None object represents a NULL iterator. In this tree, we use simple tuples to represent nodes, which also happen to be the tree paths for those nodes. This model is a tree of depth 3 with 5 nodes at each level of the tree. The values in the tree are just the string representations of the nodes.iicCstjj|ƒdS(sKconstructor for the model. Make sure you call PyTreeModel.__init__N(tgtktGenericTreeModelt__init__(tself((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyRscCsdS(s?returns the GtkTreeModelFlags for this particular type of modeli((R((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyt on_get_flags"scCsdS(s*returns the number of columns in the modeli((R((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyton_get_n_columns%scCstjS(s)returns the type of a column in the model(tgobjectt TYPE_STRING(Rtindex((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyton_get_column_type(scCs|S(s^returns the tree path(a tuple of indices at the various levels) for a particular node.((Rtnode((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyt on_get_path+scCs|S(s\returns the node corresponding to the given path. In our case, the node is the path((Rtpath((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyt on_get_iter/scCs|dkst‚| S(s<returns the value stored in a particular column for the nodei(tAssertionError(RR tcolumn((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyt on_get_value3scCsB|dkr>|d|jdkr'dS|d |ddfSdS(s/returns the next node at this level of the treeiÿÿÿÿiN(tNonet TREE_SIBLINGS(RR ((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyt on_iter_next7s cCs1|dkrdSt|ƒ|jkr)dS|dS(s$returns the first child of this nodeiN(i(i(Rtlent TREE_DEPTH(RR ((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyton_iter_children=s  cCs|dkpt|ƒ|jkS(s&returns true if this node has childrenN(RRR(RR ((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyton_iter_has_childDscCs0|dks!t|ƒ|jkr(|jSdSdS(s+returns the number of children of this nodeiN(RRRR(RR ((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyton_iter_n_childrenGs!cCsJ|dkr|fSt|ƒ|jkrB||jkrB||fSdSdS(s"returns the nth child of this nodeN(RRRR(RR tn((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyton_iter_nth_childMs  $ cCs4|dkst‚t|ƒdkr(dS|d SdS(sreturns the parent of this nodeiiÿÿÿÿN(RRR(RR ((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyton_iter_parentUs(t__name__t __module__t__doc__RRRRRR R RRRRRRRR(((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyRs              tGenericTreeModelDemocBseZdd„ZRS(cCstjj|ƒy|j|jƒƒWn$tk rM|jdd„ƒnX|j|jj ƒtj ƒ}|j tj tj ƒ|j |ƒtƒ}|jƒ}tj|ƒ}tjƒ}tjd|ddƒ}|j|ƒ|j |ƒ|jƒdS(NtdestroycWs tjƒS(N(Rt main_quit(tw((s'/usr/lib/pygtk27/2.0/demos/treemodel.pytcsttuplesttexti(RtWindowRt set_screent get_screentAttributeErrortconnectt set_titlet __class__RtScrolledWindowt set_policytPOLICY_AUTOMATICtaddRt filter_newtTreeViewtCellRendererTexttTreeViewColumnt append_columntshow_all(Rtparenttscrolled_windowtmodelt tree_viewtcellR((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyR^s"        N(RRRR(((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyR ]scCstƒtjƒdS(N(R Rtmain(((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyR=ust__main__( RtpygtktrequireRRRRR'R R=R(((s'/usr/lib/pygtk27/2.0/demos/treemodel.pyts    O