Пример #1
0
def test_createTree():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')
    Tkinter._default_root.update()
    pause(0.2)
    tv.destroy()
Пример #2
0
def test_createTree():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')
    Tkinter._default_root.update()
    pause(0.2)
    tv.destroy()
Пример #3
0
def test_createWithMaster():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    import Tkinter
    master = Tkinter.Toplevel()
    tv = TreeView(master)
    tv.canvas.configure(bg='red')
    tv.canvas.update()
    pause(1)
    tv.destroy()
Пример #4
0
def test_createWithMaster():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    import Tkinter
    master = Tkinter.Toplevel()
    tv = TreeView(master)
    tv.canvas.configure(bg='red')
    tv.canvas.update()
    pause(1)
    tv.destroy()
Пример #5
0
    def createTree(self):
        """build a TreeView object, add it to the GUI"""
        self.tree = TreeView(master=self.frame, nohistory=True,
                             displayValue=True)
        # I want white background, so:
        self.tree.canvas.configure(bg='white')

        hasChildren = not self.isLeafNode(self.object)

        node = self.tree.addNode(parent=None, name=self.rootName,
                                 object=self.object, hasChildren=hasChildren,
                                 firstExpand_cb=self.expandTreeNode_cb)
Пример #6
0
def test_delete2TreesWithSameMaster():
    """ Test the function that if a tree does not own its master it does not destgroy it"""

    tv = TreeView()
    tv2 = TreeView()
    Tkinter._default_root.update()
    pause()
    tv.destroy()
    tv2.destroy()
Пример #7
0
    def __init__(self, parent=None):
        if not parent:
            parent = Tkinter.Tk()
            Pmw.initialise(parent)
            title = 'View the list of deployed Web services'
            parent.title(title)
            exitButton = Tkinter.Button(parent,
                                        text='Exit',
                                        command=parent.destroy)
            exitButton.pack(side='bottom')
        self.parent = parent
        # Create a group widget to contain the ComboBox for the Hosts.
        Hosts_Group = Pmw.Group(parent, tag_pyclass=None)
        Hosts_Group.pack(fill='x')
        self.Hosts_ComboBox = Pmw.ComboBox(
            Hosts_Group.interior(),
            label_text='Hosts:',
            labelpos='ws',
            entry_width=30,
            scrolledlist_items=('http://ws.nbcr.net:8080/opal', ),
            selectioncommand=self.update_services)
        self.Hosts_ComboBox.pack(padx=1, pady=1)

        # ScrolledListBox for listing Services
        from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
        frame = Tkinter.Frame(parent)
        frame.pack(side='left', fill='both')
        label = Tkinter.Label(frame, text='Services')
        label.pack()
        self.Services_Tree = TreeView(master=frame, treeWidth=230, width=230)
        self.Services_Tree.setAction(event='select',
                                     function=self.getDescription)

        # ScrolledText for providing information about Web Services
        self.Description_Text = Pmw.ScrolledText(parent,
                                                 labelpos='nsew',
                                                 label_text='Description',
                                                 text_state='disabled')

        #self.Services_Box.pack(side = 'left',fill='both')
        self.Description_Text.pack(side='right', expand=1, fill='both')
        self.Hosts_ComboBox.selectitem(0)
        self.Services_dict = {}
        self.update_services(None)
        parent.mainloop()
Пример #8
0
def test_hideShow():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')
    tv.hide()
    tv.canvas.update()
    pause(1)
    tv.show()
    tv.canvas.update()
    pause(1)
    tv.destroy()
Пример #9
0
def test_hideShow():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')
    tv.hide()
    tv.canvas.update()
    pause(1)
    tv.show()
    tv.canvas.update()
    pause(1)
    tv.destroy()
Пример #10
0
def test_delete2TreesWithSameMaster():
    """ Test the function that if a tree does not own its master it does not destgroy it"""

    tv = TreeView()
    tv2 = TreeView()
    Tkinter._default_root.update()
    pause()
    tv.destroy()
    tv2.destroy()
Пример #11
0
    def __init__(self, parent = None):
        if not parent:
            parent = Tkinter.Tk()
            Pmw.initialise(parent)
            title = 'View the list of deployed Web services'
            parent.title(title)
            exitButton = Tkinter.Button(parent, text = 'Exit', command = parent.destroy)
            exitButton.pack(side = 'bottom')
        self.parent = parent
        # Create a group widget to contain the ComboBox for the Hosts.
        Hosts_Group = Pmw.Group(parent, tag_pyclass = None)
        Hosts_Group.pack(fill='x')
        self.Hosts_ComboBox = Pmw.ComboBox(Hosts_Group.interior(),
                           label_text = 'Hosts:',
                           labelpos = 'ws',
                           entry_width = 30,
                           scrolledlist_items=('http://ws.nbcr.net:8080/opal',),
                           selectioncommand = self.update_services
                           )
        self.Hosts_ComboBox.pack(padx = 1, pady = 1)

        # ScrolledListBox for listing Services
        from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
        frame = Tkinter.Frame(parent)
        frame.pack(side = 'left',fill='both')
        label = Tkinter.Label(frame,text = 'Services')
        label.pack()
        self.Services_Tree = TreeView(master=frame,treeWidth=230,width=230)
        self.Services_Tree.setAction(event='select', 
                                      function=self.getDescription)

        # ScrolledText for providing information about Web Services
        self.Description_Text = Pmw.ScrolledText(parent,
        labelpos='nsew',
        label_text='Description',
        text_state = 'disabled'
        )
        
        #self.Services_Box.pack(side = 'left',fill='both')
        self.Description_Text.pack(side = 'right',expand = 1,fill='both')
        self.Hosts_ComboBox.selectitem(0)
        self.Services_dict = {}
        self.update_services(None)
        parent.mainloop()
Пример #12
0
def test_Add_to_History():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")
    
    selection = tv.GetSelected()
    if selection:
        print "Adding", selection.name, "to the history list"
    else:
        print "Nothing is selected"

    # add the current selected node to the list
    tv.AddToHistoryList()
    
    tv.destroy()
Пример #13
0
class ListWS:
    """
    This class tries to list the deployed Web services
    """
    def __init__(self, parent=None):
        if not parent:
            parent = Tkinter.Tk()
            Pmw.initialise(parent)
            title = 'View the list of deployed Web services'
            parent.title(title)
            exitButton = Tkinter.Button(parent,
                                        text='Exit',
                                        command=parent.destroy)
            exitButton.pack(side='bottom')
        self.parent = parent
        # Create a group widget to contain the ComboBox for the Hosts.
        Hosts_Group = Pmw.Group(parent, tag_pyclass=None)
        Hosts_Group.pack(fill='x')
        self.Hosts_ComboBox = Pmw.ComboBox(
            Hosts_Group.interior(),
            label_text='Hosts:',
            labelpos='ws',
            entry_width=30,
            scrolledlist_items=('http://ws.nbcr.net:8080/opal', ),
            selectioncommand=self.update_services)
        self.Hosts_ComboBox.pack(padx=1, pady=1)

        # ScrolledListBox for listing Services
        from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
        frame = Tkinter.Frame(parent)
        frame.pack(side='left', fill='both')
        label = Tkinter.Label(frame, text='Services')
        label.pack()
        self.Services_Tree = TreeView(master=frame, treeWidth=230, width=230)
        self.Services_Tree.setAction(event='select',
                                     function=self.getDescription)

        # ScrolledText for providing information about Web Services
        self.Description_Text = Pmw.ScrolledText(parent,
                                                 labelpos='nsew',
                                                 label_text='Description',
                                                 text_state='disabled')

        #self.Services_Box.pack(side = 'left',fill='both')
        self.Description_Text.pack(side='right', expand=1, fill='both')
        self.Hosts_ComboBox.selectitem(0)
        self.Services_dict = {}
        self.update_services(None)
        parent.mainloop()

    def update_services(self, event):
        self.parent.config(cursor='watch')
        self.Description_Text.configure(text_state='normal')
        self.Description_Text.clear()
        self.URL = self.Hosts_ComboBox.get()
        opener = urllib.FancyURLopener({})

        for key in self.Services_dict:
            self.Services_Tree.deleteNode(key)
        self.Services_dict = {}
        try:
            servlet = opener.open(self.URL + "/servlet/AxisServlet")
        except IOError:
            errorMsg = self.URL + "/servlet/AxisServlet could not be found"
            errorMsg += "\nPlease make sure that server is up and running"
            import tkMessageBox
            tkMessageBox.showerror("Error!", errorMsg)
            self.parent.config(cursor='')
            return

        text = servlet.read()
        text = text.split('<ul>')
        if text[0].find('<h2>And now... Some Services</h2>') == -1:
            errorMsg = self.URL + "/servlet/AxisServlet could not be found"
            errorMsg += "\nPlease make sure that server is up and running"
            import tkMessageBox
            tkMessageBox.showerror("Error!", errorMsg)
            self.parent.config(cursor='')
            return
        text = text[1:]
        last_service = ""
        for line in text[:-1]:
            methods = line.split('</ul>')
            if len(methods) > 1:
                methods = methods[0]
                methods = methods.split('<li>')
                methods = methods[1:]
                for method in methods:
                    self.Services_Tree.addNode(method.strip(),
                                               parent=last_service)
            tmp_text = line.split(self.URL + "/services/")
            port = tmp_text[-1].split('wsdl')
            self.Services_Tree.addNode(port[0][:-1])
            self.Services_dict[port[0][:-1]] = self.URL+"/services/" + \
                port[0][:-1] + "?wsdl"
            last_service = port[0][:-1]
        methods = line.split('</ul>')
        if len(methods) > 1:
            methods = methods[0]
            methods = methods.split('<li>')
            methods = methods[1:]
            for method in methods:
                self.Services_Tree.addNode(method.strip(), parent=last_service)
        self.parent.config(cursor='')
        #self.Services_Tree.deleteNode('AdminService')
        #self.Services_Tree.deleteNode('Version')
        #self.Services_Tree.deleteNode('APBSJobSubPort')

    def getDescription(self, tree_node):
        if tree_node.parent:
            service = tree_node.parent.GetFullName()
        else:
            service = tree_node.GetFullName()
        import ZSI
        self.Description_Text.configure(text_state='normal')
        self.Description_Text.clear()
        from ZSI.generate.wsdl2python import WriteServiceModule
        from ZSI.wstools import WSDLTools
        reader = WSDLTools.WSDLReader()
        wsdl = reader.loadFromURL(self.Services_dict[service])
        try:
            wsdl.services['AppService']
        except:
            self.Description_Text.insert(
                'end',
                'Sorry, only Opal based web services are supported http://nbcr.net/services/opal'
            )
            self.Description_Text.configure(text_state='disabled')
            return
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(\
                       self.URL + "/services/"+service)
        req = getAppMetadataRequest()
        resp = appServicePort.getAppMetadata(req)
        self.Description_Text.configure(text_state='normal')
        if resp._info:
            self.Description_Text.insert('end', resp._usage + "\n\n")
            self.Description_Text.insert('end', resp._info[0])
        else:
            self.Description_Text.insert('end', resp._usage)
        self.Description_Text.configure(text_state='disabled')
Пример #14
0
def test_moveNode():
    """ Test the function to move a tree node (including subtree) """

    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')
    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    tv.addNode('protein_333')
    tv.addNode('residue_21', parent='protein_2')
    tv.addNode('residue_Root', parent='protein_2')
    tv.addNode('basdfe', parent='protein_2|residue_21')
    tv.addNode('AminoAcidXXX', parent='protein_2|residue_21')
    tv.addNode('etc', parent='protein_1|residue_11')
    tv.addNode('color', parent='protein_1|residue_11|etc')
    tv.addNode('density', parent='protein_1|residue_11|etc')
    tv.addNode('residue_Moving', parent='protein_1')
    tv.addNode('2', parent='protein_2|residue_21')
    tv.addNode('3', parent='protein_2|residue_21')
    tv.addNode('4', parent='protein_2|residue_21')
    tv.addNode('L', parent='protein_2|residue_21|AminoAcidXXX')
    tv.addNode('protein_33xxxxxxx')

    node = tv.roots[0].children[1]
    dest = tv.roots[1].children[1]
    tv.moveNode(node, dest)

    assert node.parent == dest
    node.GetFullName() == 'protein_2|residue_Root|residue_Moving'
    assert dest.children[0] == node
    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()
Пример #15
0
def test_Lock_Unlock_History():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")
    tv.AddToHistoryList()
    tv.Select("protein_2")
    tv.AddToHistoryList()
    tv.Select("protein_1|residue_11")
    tv.AddToHistoryList()
    tv.Select("protein_1|residue_11|AminoAcid|H")
    tv.AddToHistoryList()
    
    # lock 
    tv.LockHistoryItem(2)
    tv.LockHistoryItem(3)
    # unlock        
    tv.UnLockHistoryItem(2)
    
    tv.destroy()
Пример #16
0
def test_NoHistory():
    """ Test the crateion of a TreeView with no history Pane """

    tv = TreeView(nohistory=True)
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')

    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")

    selection = tv.GetSelected()
    if selection:
        print "Adding", selection.name, "to the history list"
    else:
        print "Nothing is selected"

    # add the current selected node to the list
    tv.AddToHistoryList()

    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()
Пример #17
0
def test_copyTree():
    """ Test the function to copy a tree into another one"""

    tv = TreeView()
    tv2 = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')

    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    nodetest = tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.copy(tv2)
    node = tv2.findNodeFromName(nodetest.GetFullName())
    assert node.name == 'H'
    Tkinter._default_root.update()
    pause()
    tv.destroy()
    tv2.destroy()
Пример #18
0
def test_template():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.destroy()
Пример #19
0
def test_SetAction():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')

    #Set what to do after an action here.
    tv.setAction(event='select', function=foo)
    tv.Select("protein_1")

    tv.destroy()
Пример #20
0
def test_deleteNode():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    #Add some nodes 
    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    node = tv.addNode('H',      parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    
    # Now deleteing
    tv.deleteNode_byName('A', parent='protein_1|residue_11|AminoAcid')
    tv.deleteNode_byName('protein_2')
    
    tv.deleteNode(node)
    
    
    # the following returns error message, 
    # since AminoAcid is NOT the child of 'protein_1'
    tv.deleteNode_byName('AminoAcid',     parent='protein_1')
    
    # This should work
    tv.deleteNode_byName('AminoAcid',     parent='protein_1|residue_11')
    
    tv.destroy()
Пример #21
0
def test_addNode():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    # addNode(nodename, parentname = None)
    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    tv.addNode('protein_3')
    tv.addNode('residue_21',    parent='protein_2')
    tv.addNode('residue_25',    parent='protein_2')
    tv.addNode('basdfe',        parent='protein_2|residue_21')
    tv.addNode('AminoAcid',     parent='protein_2|residue_21')
    tv.addNode('etc',       parent='protein_1|residue_11')
    tv.addNode('color',     parent='protein_1|residue_11|etc')
    tv.addNode('density',   parent='protein_1|residue_11|etc')
    tv.addNode('residue_12',parent='protein_1')
    tv.addNode('2', parent='protein_2|residue_21')
    tv.addNode('3', parent='protein_2|residue_21')
    tv.addNode('4', parent='protein_2|residue_21')
    tv.addNode('L', parent='protein_2|residue_21|AminoAcid')
    for a in range(10):
        name = 'A' + str(a)
        tv.addNode(name,  parent='protein_2|residue_21|AminoAcid')
    tv.addNode('protein_4')
    tv.addNode('residue_22', parent='protein_2')

    # the addNode function check the node before adding to the parentname
    # if already in the child list, the new node will NOT be added.
    tv.addNode('residue_22', parent='protein_2')

    # addNode returns the handle of the noded added
    node = tv.addNode('S', parent='protein_2|residue_21|AminoAcid')
    print node.name, "was added to" , node.parentFullname

    tv.destroy()
Пример #22
0
def test_NoHistory():
    """ Test the crateion of a TreeView with no history Pane """


    tv = TreeView(nohistory=True)
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')

    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")
    
    selection = tv.GetSelected()
    if selection:
        print "Adding", selection.name, "to the history list"
    else:
        print "Nothing is selected"

    # add the current selected node to the list
    tv.AddToHistoryList()
    
    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()    
Пример #23
0
def test_obj2Node():
    """ Test the creation of a TreeView with obj2Node == false
    In that case there is not  1to 1 relation between object and node
    tv.objToNode should stay empty.
    """

    tv = TreeView(obj2Node=False)
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')

    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")
    
    assert tv.objToNode == {}
    
    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()    
Пример #24
0
def test_copyTree():
    """ Test the function to copy a tree into another one"""

    tv = TreeView()
    tv2 = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')

    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    nodetest = tv.addNode('H',parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.copy(tv2)
    node = tv2.findNodeFromName(nodetest.GetFullName())
    assert node.name == 'H'
    Tkinter._default_root.update()
    pause()
    tv.destroy()    
    tv2.destroy()    
Пример #25
0
def test_moveNodeUpOrDown():
    """ Test the function to move a tree node up and down in the node list """

    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed

    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    tv.addNode('protein_3')
    tv.addNode('residue_21',    parent='protein_2')
    tv.addNode('residue_25',    parent='protein_2')
    tv.addNode('basdfe',        parent='protein_2|residue_21')
    tv.addNode('AminoAcid',     parent='protein_2|residue_21')
    tv.addNode('etc',       parent='protein_1|residue_11')
    tv.addNode('color',     parent='protein_1|residue_11|etc')
    tv.addNode('density',   parent='protein_1|residue_11|etc')
    tv.addNode('residue_12',parent='protein_1')
    tv.addNode('2', parent='protein_2|residue_21')
    tv.addNode('3', parent='protein_2|residue_21')
    tv.addNode('4', parent='protein_2|residue_21')
    tv.addNode('L', parent='protein_2|residue_21|AminoAcid')
    tv.addNode('protein_33xxxxxxx')

    node=tv.roots[0].children[1]
    dest=tv.roots[1].children[1]

    ## NOTE: self.objToNode can also return node instance.

    n2=tv.findNodeFromName('protein_1|residue_12')
    n1=tv.findNodeFromName('protein_1|residue_11')
    p1=tv.findNodeFromName('protein_1')

    n2.moveUp()
    assert p1.children.index(n2)==0    
    n2.moveDown()
    assert p1.children.index(n1)==0
    

    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()
Пример #26
0
class ObjectBrowser:
    """Introspect an object with a tree-browser GUI.
Click on the [+] or double-click on the folder icons to expand 1 level.
At the top of this GUI 3 Radiobuttons are visible. Default is 'Attributes'
which means we do not include callable methods. 'Methods' will only display
callable methods. 'All' will display everything.

Required constructor argument: the objetc to be browsed.
Optional constructor arguments:
    rootName: a string used as the name for the root node. Default: 'root'
    title: a string used as window title. Default: 'Python Introspector'
    refresh: this has to be either None or a callable method that returns
             an object to be introspected. If refresh is not None a new
             button is added to the left of the Dismiss button. Clicking this
             button calls the callable method (which must return a new object)
             and rebuilds the tree. If refresh is None, we do not add the
             'Refresh' button. Default: None

API: show() displays the GUI
     hide() hides the GUI (this does not destroy the window)
     rebuild() destroys the current tree and rebuilds it

To get an idea of how this thing works, start Python, import this class, then
type:
browser = ObjectBrowser( __builtins__ )
"""


    def __init__(self, object, rootName='root', title='Python Introspector',
                 refresh=None):

        self.object = object       # the object to be introspeced
        self.rootName = rootName   # name the root node
        self.title = title         # title of the GUI

        assert refresh is None or callable(refresh)
        self.refresh = refresh # used to rebuild tree with new data
        self.busyRebuilding = False

        self.buildGUI()
        

    def buildGUI(self):
        self.root = tkinter.Toplevel()
        self.root.title(self.title)
        self.root.protocol('WM_DELETE_WINDOW', self.hide )
        self.topFrame = tkinter.Frame(self.root, relief='raised',
                           bd=4)
        self.topFrame.pack(fill="x", side='top', )

        choices = ['All', 'Attributes', 'Methods']
        self.choicesVarTk = tkinter.StringVar()
        self.choicesVarTk.set('Attributes')
        for c in choices:
            b = tkinter.Radiobutton(
                self.topFrame,
                variable = self.choicesVarTk,
                text=c, value=c, command=self.rebuild)
            b.pack(side='left', expand=1, fill='x')

        self.frame = tkinter.Frame(self.root)
        self.frame.pack(expand=1, fill="both")#, side='bottom')

        frame = tkinter.Frame(self.root, bd=3)
        frame.pack(fill="x", side='bottom')

        # add Refresh button if specified
        if self.refresh is not None:
            button1 = tkinter.Button(frame, text='Refresh',
                                     command=self.refresh_cb)
            button1.pack(expand=1, fill="x", side='left')

            button2 = tkinter.Button(frame, text='Dismiss', command=self.hide)
            button2.pack(expand=1, fill="x", side='left')

        else:
            button2 = tkinter.Button(frame, text='Dismiss', command=self.hide)
            button2.pack(expand=1, fill="x")
        
        # add root node        
        self.createTree()
        

    def show(self, event=None):
        """show GUI"""
        self.root.deiconify()
        if self.refresh is not None:
            data = self.refresh()
            if data != self.object:
                self.object = data
                self.rebuild()
                

    def hide(self, event=None):
        """hide GUI, note: this does not destroy the GUI"""
        self.root.withdraw()


    def createTree(self):
        """build a TreeView object, add it to the GUI"""
        self.tree = TreeView(master=self.frame, nohistory=True,
                             displayValue=True)
        # I want white background, so:
        self.tree.canvas.configure(bg='white')

        hasChildren = not self.isLeafNode(self.object)

        node = self.tree.addNode(parent=None, name=self.rootName,
                                 object=self.object, hasChildren=hasChildren,
                                 firstExpand_cb=self.expandTreeNode_cb)

    
    def expandTreeNode_cb(self, node=None, object=None):
        """expand the given object by 1 level (i.e. all its children)"""

        if type(object) in [list, tuple]:
            children = []
            i = 0
            for o in object:
                children.append( (str(i), o) )
                i = i + 1
                
        elif type(object) == dict:
            children = []
            for k, v in list(object.items()):
                children.append( (k, v) )

        elif type(object) in [ bool, float,
                               int, int, type(None),
                               bytes ]:
            children = []

        else:
            if self.choicesVarTk.get() == 'All':
                children = inspect.getmembers(object)
            elif self.choicesVarTk.get() == 'Attributes':
                children = inspect.getmembers(object,
                       lambda x: type(x) is not types.MethodType)
            elif self.choicesVarTk.get() == 'Methods':
                if node.parent is None: # only at the first level do we
                    # distinguish between methods, attributes, etc
                    children = inspect.getmembers(object, inspect.ismethod)
                else: #second and deeper levels: here we want to see everything
                    children = inspect.getmembers(object)

        from time import time
        t1 = time()
        nameList=[]
        objList=[]
        hasChildrenList=[]      
        for (name, data) in children:
            hasChildren = not self.isLeafNode(data)
            hasChildrenList.append(hasChildren)
            nameList.append(str(name))
            objList.append(data)
            
        n = self.tree.addNodeSet(parent=node, name=nameList, object=objList,
                                 hasChildren=hasChildrenList,
                                 firstExpand_cb=self.expandTreeNode_cb)
            
#            self.tree.canvas.update()
        #print "firstExpand_cb :", time()-t1


    def isLeafNode(self, x):
        """Helper method: returns True if this object does not have children
        (e.g., int, float, boolean, etc)"""
        
        if type(x) in [
            bool, float, int,
            int, type(None), bytes]:
            return True
        elif type(x) in [dict, list] and \
             len(x)==0:
            return True
        else:
            return False
                       

    def rebuild(self, event=None):
        """destroy old tree, delete frame, create new tree and add it to the
        GUI"""
        self.tree.destroy()
        self.tree = None
        self.createTree()
        self.busyRebuilding = False


    def refresh_cb(self, event=None):
        """rebuild tree with new data (calls rebuild)"""
        
        # Note: on slow machines, if one repeatetly clicks the 'Refresh'
        # button very, very fast, we can reach a state where the canvas has
        # been destroyed while we try to add an icon on it
        if self.busyRebuilding is True:
            return

        if self.refresh is not None:
            self.busyRebuilding = True
            # call the callback to get a new object to introspect
            self.object = self.refresh()
            # and rebuild tree
            self.rebuild()
Пример #27
0
def test_Lock_Unlock_History():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")
    tv.AddToHistoryList()
    tv.Select("protein_2")
    tv.AddToHistoryList()
    tv.Select("protein_1|residue_11")
    tv.AddToHistoryList()
    tv.Select("protein_1|residue_11|AminoAcid|H")
    tv.AddToHistoryList()

    # lock
    tv.LockHistoryItem(2)
    tv.LockHistoryItem(3)
    # unlock
    tv.UnLockHistoryItem(2)

    tv.destroy()
Пример #28
0
class ListWS:
    """
    This class tries to list the deployed Web services
    """
    def __init__(self, parent = None):
        if not parent:
            parent = Tkinter.Tk()
            Pmw.initialise(parent)
            title = 'View the list of deployed Web services'
            parent.title(title)
            exitButton = Tkinter.Button(parent, text = 'Exit', command = parent.destroy)
            exitButton.pack(side = 'bottom')
        self.parent = parent
        # Create a group widget to contain the ComboBox for the Hosts.
        Hosts_Group = Pmw.Group(parent, tag_pyclass = None)
        Hosts_Group.pack(fill='x')
        self.Hosts_ComboBox = Pmw.ComboBox(Hosts_Group.interior(),
                           label_text = 'Hosts:',
                           labelpos = 'ws',
                           entry_width = 30,
                           scrolledlist_items=('http://ws.nbcr.net:8080/opal',),
                           selectioncommand = self.update_services
                           )
        self.Hosts_ComboBox.pack(padx = 1, pady = 1)

        # ScrolledListBox for listing Services
        from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
        frame = Tkinter.Frame(parent)
        frame.pack(side = 'left',fill='both')
        label = Tkinter.Label(frame,text = 'Services')
        label.pack()
        self.Services_Tree = TreeView(master=frame,treeWidth=230,width=230)
        self.Services_Tree.setAction(event='select', 
                                      function=self.getDescription)

        # ScrolledText for providing information about Web Services
        self.Description_Text = Pmw.ScrolledText(parent,
        labelpos='nsew',
        label_text='Description',
        text_state = 'disabled'
        )
        
        #self.Services_Box.pack(side = 'left',fill='both')
        self.Description_Text.pack(side = 'right',expand = 1,fill='both')
        self.Hosts_ComboBox.selectitem(0)
        self.Services_dict = {}
        self.update_services(None)
        parent.mainloop()
        
    def update_services(self,event):
        self.parent.config(cursor='watch')
        self.Description_Text.configure(text_state = 'normal')
        self.Description_Text.clear()
        self.URL = self.Hosts_ComboBox.get()
        opener = urllib.FancyURLopener({}) 

        for key in self.Services_dict:
            self.Services_Tree.deleteNode(key)
        self.Services_dict = {}
        try:
            servlet = opener.open(self.URL+"/servlet/AxisServlet")
        except IOError:
            errorMsg = self.URL+"/servlet/AxisServlet could not be found"
            errorMsg += "\nPlease make sure that server is up and running"
            import tkMessageBox
            tkMessageBox.showerror("Error!",errorMsg)
            self.parent.config(cursor='')
            return

        text = servlet.read()
        text = text.split('<ul>')
        if text[0].find('<h2>And now... Some Services</h2>') == -1:
            errorMsg = self.URL+"/servlet/AxisServlet could not be found"
            errorMsg += "\nPlease make sure that server is up and running"
            import tkMessageBox
            tkMessageBox.showerror("Error!",errorMsg)
            self.parent.config(cursor='')
            return
        text = text[1:]
        last_service = ""
        for line in text[:-1]:
            methods = line.split('</ul>')
            if len(methods) > 1:
                methods = methods[0]
                methods = methods.split('<li>')
                methods = methods[1:]
                for method in methods:
                    self.Services_Tree.addNode(method.strip(),parent=last_service)
            tmp_text = line.split(self.URL+"/services/")
            port = tmp_text[-1].split('wsdl')
            self.Services_Tree.addNode(port[0][:-1])
            self.Services_dict[port[0][:-1]] = self.URL+"/services/" + \
                port[0][:-1] + "?wsdl"
            last_service = port[0][:-1]
        methods = line.split('</ul>')
        if len(methods) > 1:
            methods = methods[0]
            methods = methods.split('<li>')
            methods = methods[1:]
            for method in methods:
                self.Services_Tree.addNode(method.strip(),parent=last_service)
        self.parent.config(cursor='')        
        #self.Services_Tree.deleteNode('AdminService')
        #self.Services_Tree.deleteNode('Version')
        #self.Services_Tree.deleteNode('APBSJobSubPort')

    def getDescription(self, tree_node):
        if tree_node.parent:
            service = tree_node.parent.GetFullName()
        else:
            service = tree_node.GetFullName()
        import ZSI
        self.Description_Text.configure(text_state = 'normal')
        self.Description_Text.clear()
        from ZSI.generate.wsdl2python import WriteServiceModule
        from ZSI.wstools import WSDLTools
        reader = WSDLTools.WSDLReader()
        wsdl = reader.loadFromURL(self.Services_dict[service])
        try:  
            wsdl.services['AppService']
        except:
            self.Description_Text.insert('end', 'Sorry, only Opal based web services are supported http://nbcr.net/services/opal')
            self.Description_Text.configure(text_state = 'disabled')
            return
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(\
                       self.URL + "/services/"+service)
        req = getAppMetadataRequest()
        resp = appServicePort.getAppMetadata(req)
        self.Description_Text.configure(text_state = 'normal')
        if resp._info:
            self.Description_Text.insert('end',resp._usage+"\n\n")
            self.Description_Text.insert('end',resp._info[0])
        else:
            self.Description_Text.insert('end',resp._usage)
        self.Description_Text.configure(text_state = 'disabled')
Пример #29
0
def test_template():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.destroy()
Пример #30
0
def test_SelectNode_deSelectNode():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    #Add some nodes 
    tv.addNode('protein_1')
    node = tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    selection = tv.GetSelected()
    if selection:
        print "Now", selection.name, "is selected"
    else:
        print "Nothing is selected"

    # Now select a node 
    tv.Select("protein_1|residue_11|AminoAcid|A")
    
    selection = tv.GetSelected()
    if selection:
        print "***", selection.name, "is selected ***"
    else:
        print "Nothing is selected"
    
    tv.destroy()
Пример #31
0
def test_obj2Node():
    """ Test the creation of a TreeView with obj2Node == false
    In that case there is not  1to 1 relation between object and node
    tv.objToNode should stay empty.
    """

    tv = TreeView(obj2Node=False)
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')

    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")

    assert tv.objToNode == {}

    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()
Пример #32
0
def test_addNode():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    # addNode(nodename, parentname = None)
    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    tv.addNode('protein_3')
    tv.addNode('residue_21', parent='protein_2')
    tv.addNode('residue_25', parent='protein_2')
    tv.addNode('basdfe', parent='protein_2|residue_21')
    tv.addNode('AminoAcid', parent='protein_2|residue_21')
    tv.addNode('etc', parent='protein_1|residue_11')
    tv.addNode('color', parent='protein_1|residue_11|etc')
    tv.addNode('density', parent='protein_1|residue_11|etc')
    tv.addNode('residue_12', parent='protein_1')
    tv.addNode('2', parent='protein_2|residue_21')
    tv.addNode('3', parent='protein_2|residue_21')
    tv.addNode('4', parent='protein_2|residue_21')
    tv.addNode('L', parent='protein_2|residue_21|AminoAcid')
    for a in range(10):
        name = 'A' + str(a)
        tv.addNode(name, parent='protein_2|residue_21|AminoAcid')
    tv.addNode('protein_4')
    tv.addNode('residue_22', parent='protein_2')

    # the addNode function check the node before adding to the parentname
    # if already in the child list, the new node will NOT be added.
    tv.addNode('residue_22', parent='protein_2')

    # addNode returns the handle of the noded added
    node = tv.addNode('S', parent='protein_2|residue_21|AminoAcid')
    print node.name, "was added to", node.parentFullname

    tv.destroy()
Пример #33
0
def test_SetAction():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')

    #Set what to do after an action here.
    tv.setAction(event='select', function=foo)
    tv.Select("protein_1")
    
    tv.destroy()
Пример #34
0
def test_Expand_or_Collaps():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    #Add some nodes
    tv.addNode('protein_1')
    node = tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    # equivalent to
    print "Is node", node.name, "expanded?: ",
    print node.expanded

    tv.ExpandNode('protein_1|residue_11')
    print "After expanding, is node", node.name, "expanded?: ",
    print node.expanded

    tv.CollapseNode('protein_1|residue_11')
    print "After collapsing, is node", node.name, "expanded?: ",
    print node.expanded

    tv.destroy()
Пример #35
0
def test_moveNodeUpOrDown():
    """ Test the function to move a tree node up and down in the node list """

    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed

    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    tv.addNode('protein_3')
    tv.addNode('residue_21', parent='protein_2')
    tv.addNode('residue_25', parent='protein_2')
    tv.addNode('basdfe', parent='protein_2|residue_21')
    tv.addNode('AminoAcid', parent='protein_2|residue_21')
    tv.addNode('etc', parent='protein_1|residue_11')
    tv.addNode('color', parent='protein_1|residue_11|etc')
    tv.addNode('density', parent='protein_1|residue_11|etc')
    tv.addNode('residue_12', parent='protein_1')
    tv.addNode('2', parent='protein_2|residue_21')
    tv.addNode('3', parent='protein_2|residue_21')
    tv.addNode('4', parent='protein_2|residue_21')
    tv.addNode('L', parent='protein_2|residue_21|AminoAcid')
    tv.addNode('protein_33xxxxxxx')

    node = tv.roots[0].children[1]
    dest = tv.roots[1].children[1]

    ## NOTE: self.objToNode can also return node instance.

    n2 = tv.findNodeFromName('protein_1|residue_12')
    n1 = tv.findNodeFromName('protein_1|residue_11')
    p1 = tv.findNodeFromName('protein_1')

    n2.moveUp()
    assert p1.children.index(n2) == 0
    n2.moveDown()
    assert p1.children.index(n1) == 0

    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()
Пример #36
0
def test_SelectNode_deSelectNode():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    #Add some nodes
    tv.addNode('protein_1')
    node = tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    selection = tv.GetSelected()
    if selection:
        print "Now", selection.name, "is selected"
    else:
        print "Nothing is selected"

    # Now select a node
    tv.Select("protein_1|residue_11|AminoAcid|A")

    selection = tv.GetSelected()
    if selection:
        print "***", selection.name, "is selected ***"
    else:
        print "Nothing is selected"

    tv.destroy()
Пример #37
0
def test_Delete_from_History():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")
    tv.AddToHistoryList()
    
    tv.Select("protein_2")
    tv.AddToHistoryList()
    
    tv.Select("protein_1|residue_11")
    tv.AddToHistoryList()
    
    tv.Select("protein_1|residue_11|AminoAcid|H")
    tv.AddToHistoryList()
    
    # delete 
    tv.DeleteFromHistoryList(2)
    list=[0,2]
    tv.historyList.Delete_multi(list)
    tv.destroy()
Пример #38
0
def test_Add_to_History():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")

    selection = tv.GetSelected()
    if selection:
        print "Adding", selection.name, "to the history list"
    else:
        print "Nothing is selected"

    # add the current selected node to the list
    tv.AddToHistoryList()

    tv.destroy()
Пример #39
0
def test_deleteNode():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    #Add some nodes
    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    node = tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    # Now deleteing
    tv.deleteNode_byName('A', parent='protein_1|residue_11|AminoAcid')
    tv.deleteNode_byName('protein_2')

    tv.deleteNode(node)

    # the following returns error message,
    # since AminoAcid is NOT the child of 'protein_1'
    tv.deleteNode_byName('AminoAcid', parent='protein_1')

    # This should work
    tv.deleteNode_byName('AminoAcid', parent='protein_1|residue_11')

    tv.destroy()
Пример #40
0
def test_Delete_from_History():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    tv.addNode('protein_1')
    tv.addNode('residue_11', parent='protein_1')
    tv.addNode('AminoAcid', parent='protein_1|residue_11')
    tv.addNode('A', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H', parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')

    tv.Select("protein_1|residue_11|AminoAcid|A")
    tv.AddToHistoryList()

    tv.Select("protein_2")
    tv.AddToHistoryList()

    tv.Select("protein_1|residue_11")
    tv.AddToHistoryList()

    tv.Select("protein_1|residue_11|AminoAcid|H")
    tv.AddToHistoryList()

    # delete
    tv.DeleteFromHistoryList(2)
    list = [0, 2]
    tv.historyList.Delete_multi(list)
    tv.destroy()
Пример #41
0
def test_Expand_or_Collaps():
    from mglutil.gui.BasicWidgets.Tk.TreeWidget.tree import TreeView
    tv = TreeView()
    #Add some nodes 
    tv.addNode('protein_1')
    node = tv.addNode('residue_11',    parent='protein_1')
    tv.addNode('AminoAcid',     parent='protein_1|residue_11')
    tv.addNode('A',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',             parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    
    # equivalent to 
    print "Is node", node.name, "expanded?: ",
    print node.expanded
    
    tv.ExpandNode('protein_1|residue_11')
    print "After expanding, is node", node.name, "expanded?: ",
    print node.expanded
    
    tv.CollapseNode('protein_1|residue_11')
    print "After collapsing, is node", node.name, "expanded?: ",
    print node.expanded
    
    tv.destroy()
Пример #42
0
def test_moveNode():
    """ Test the function to move a tree node (including subtree) """

    tv = TreeView()
    # paint canvas red so we see it disappear when distroyed
    tv.canvas.configure(bg='red')
    tv.addNode('protein_1')
    tv.addNode('residue_11',parent='protein_1')
    tv.addNode('AminoAcid',parent='protein_1|residue_11')
    tv.addNode('A',parent='protein_1|residue_11|AminoAcid')
    tv.addNode('H',parent='protein_1|residue_11|AminoAcid')
    tv.addNode('protein_2')
    tv.addNode('protein_333')
    tv.addNode('residue_21',parent='protein_2')
    tv.addNode('residue_Root',parent='protein_2')
    tv.addNode('basdfe',parent='protein_2|residue_21')
    tv.addNode('AminoAcidXXX',parent='protein_2|residue_21')
    tv.addNode('etc',parent='protein_1|residue_11')
    tv.addNode('color',parent='protein_1|residue_11|etc')
    tv.addNode('density',parent='protein_1|residue_11|etc')
    tv.addNode('residue_Moving',parent='protein_1')
    tv.addNode('2',parent='protein_2|residue_21')
    tv.addNode('3',parent='protein_2|residue_21')
    tv.addNode('4',parent='protein_2|residue_21')
    tv.addNode('L',parent='protein_2|residue_21|AminoAcidXXX')
    tv.addNode('protein_33xxxxxxx')

    node=tv.roots[0].children[1]
    dest=tv.roots[1].children[1]
    tv.moveNode(node,dest)

    assert node.parent ==dest
    node.GetFullName()=='protein_2|residue_Root|residue_Moving'
    assert dest.children[0] == node
    #tv.topFrame.master.update()
    pause(0.2)
    tv.destroy()