示例#1
0
 def getInt(self):
     idf = InputFormDescr(title='Choose a value')
     idf.append({'widgetType':IntThumbWheel,
                 'name':'tw',
                 'wcfg':{'width':125, 'height':30, 'nblines':30}})
     form  = InputForm(master=self.widget.master, root = None, descr=idf)
     values = form.go()
     return values['tw']
示例#2
0
 def getInt(self):
     idf = InputFormDescr(title='Choose a value')
     idf.append({
         'widgetType': IntThumbWheel,
         'name': 'tw',
         'wcfg': {
             'width': 125,
             'height': 30,
             'nblines': 30
         }
     })
     form = InputForm(master=self.widget.master, root=None, descr=idf)
     values = form.go()
     return values['tw']
 def buildText(self,parent,textwcfg, buttonwcfg):
     # Build the LoadOrSaveText widget or ScrolledText
     self.idf = InputFormDescr()
     textwcfg['name']='UserFunction'
     self.text = buttonwcfg['text']
     self.idf.append(textwcfg)
     #windows = InputForm(parent, self.idf)
     master = parent
     root = None
     windows = InputForm(master,root,  self.idf)
     self.vals = windows.go()
     # Uncheck the checkbutton if needed
     if isinstance(self.button,Tkinter.Checkbutton) and \
        buttonwcfg.has_key('variable'):
         if isinstance(buttonwcfg['variable'], Tkinter.StringVar):
             buttonwcfg['variable'].set('0')
         elif isinstance(buttonwcfg['variable'], Tkinter.IntVar):
             buttonwcfg['variable'].set(0)
示例#4
0
 def buildText(self,parent,textwcfg, buttonwcfg):
     # Build the LoadOrSaveText widget or ScrolledText
     self.idf = InputFormDescr()
     textwcfg['name']='UserFunction'
     self.text = buttonwcfg['text']
     self.idf.append(textwcfg)
     #windows = InputForm(parent, self.idf)
     master = parent
     root = None
     windows = InputForm(master,root,  self.idf)
     self.vals = windows.go()
     # Uncheck the checkbutton if needed
     if isinstance(self.button,Tkinter.Checkbutton) and \
        buttonwcfg.has_key('variable'):
         if isinstance(buttonwcfg['variable'], Tkinter.StringVar):
             buttonwcfg['variable'].set('0')
         elif isinstance(buttonwcfg['variable'], Tkinter.IntVar):
             buttonwcfg['variable'].set(0)
示例#5
0
class AnimPlayer(Player, geomsChooser):
    """ provide a player to display/undisplay DejaVu object
    in a cylce making a animation.

    viewer: DejaVu viewer
    height,width are the property of the player gui
    startFrame: frame to begin
    endFrame: last frame to display
    stepSize: step between new frame
    playMode:                  #playMode options:
                               #   0   play once and stop
                               #   1   play continuously in 1 direction
                               #   2   play once in 2 directions
                               #   3   play continuously in 2 directions
    titleStr: title of the gui windows
    counter: gui with a counter on or not
    gui: #1 show the player gui
         #0 player gui not display
    framerate =15.             # number of frame per second to be display
    """
    def __init__(self,
                 viewer,
                 master=None,
                 root=None,
                 height=80,
                 width=200,
                 currentFrameIndex=0,
                 startFrame=0,
                 endFrame=0,
                 maxFrame=0,
                 stepSize=1,
                 playMode=1,
                 titleStr='AnimPlayer',
                 counter=1,
                 gui=1,
                 framerate=15.):

        if master is None:
            master = Tkinter.Toplevel()

        # viewer from which we get the geom to animate
        self.viewer = viewer
        # frame list, is a list of geom .
        # each frame is made of n DejaVu object to be display
        # it a list of tuple, each tuple is a {} and []
        # {} is: {'objname':['geom1','geom2'],'objname':['geom1','geom2']}
        # [] is list of DejaVu object per frame
        self.framelist = []

        Player.__init__(self,
                        master=master,
                        root=root,
                        height=height,
                        width=width,
                        currentFrameIndex=currentFrameIndex,
                        startFrame=startFrame,
                        endFrame=endFrame,
                        maxFrame=maxFrame,
                        stepSize=stepSize,
                        playMode=playMode,
                        titleStr=titleStr,
                        counter=counter,
                        gui=gui,
                        framerate=framerate)

    def nextFrame(self, id):
        """ id: index number of the frame to display.
        undisplay object from previous frame, display object
        of new frame.
        """
        if not self.framelist: return
        id = int(id)
        if id >= len(self.framelist): return

        i = self.currentFrameIndex
        ## undisplay previous object
        frame = self.framelist[i]
        for obj in frame[1]:
            obj.Set(visible=0, redo=0)

        if self.hasCounter and self.gui:
            self.form.ent2.delete(0, 'end')
            self.form.ent2.insert(0, str(id))

        ## display new frame
        currentframe = self.framelist[id]
        for obj in currentframe[1]:
            obj.Set(visible=1, redo=0)

        self.viewer.deleteOpenglList()
        self.viewer.Redraw()
        self.currentFrameIndex = id

#####################################################################
#### Animation Setting the frame

    def SetAnim_cb(self):
        self.showForm()

    def showForm(self):
        """create formdescr for setAnim
        form to set the animation:
        each frame is a list of geom to display
        """

        entryFrame = []
        for i in range(len(self.framelist)):
            val = 'frame_' + str(i)
            entryFrame.append((val, ))

        if not hasattr(self, 'form_Setanim'):
            ifd = InputFormDescr(title="SetAnimation")
            ifd.append({
                'widgetType': ListChooser,
                'name': 'availableGeom',
                'tooltip': 'geom available in viewer',
                'wcfg': {
                    'mode': 'extended',
                    'lbwcfg': {
                        'exportselection': 1
                    },
                    'command': [(self.toggleExpansion, '<Double-Button-1>')],
                    'commandEvent': None,
                    'title': 'availableGeom'
                },
                'gridcfg': {
                    'row': 0,
                    'column': 0,
                    'sticky': 'wens',
                    'rowspan': 3
                }
            })
            ifd.append({
                'name': 'newframe',
                'widgetType': Tkinter.Button,
                'tooltip': """ Add an empty frame to the animation""",
                'wcfg': {
                    'text': 'NewFrame',
                    'command': self.addframe_cb
                },
                'gridcfg': {
                    'row': 0,
                    'column': 1,
                    'rowspan': 1
                }
            })

            ifd.append({
                'name': 'add',
                'widgetType': Tkinter.Button,
                'tooltip': """ Add the selected geom to selected frame""",
                'wcfg': {
                    'text': 'AddGeom',
                    'command': self.add_cb
                },
                'gridcfg': {
                    'row': 1,
                    'column': 1,
                    'rowspan': 1
                }
            })

            ifd.append({
                'name': 'geomtoload',
                'widgetType': ListChooser,
                'tooltip': """list of frame  the user chose to
                        apply to the pattern""",
                'wcfg': {
                    'entries': entryFrame,
                    'mode': 'extended',
                    'lbwcfg': {
                        'exportselection': 0
                    },
                    'title': 'Frame(geom) to be display'
                },
                'gridcfg': {
                    'sticky': 'we',
                    'row': 0,
                    'column': 2,
                    'rowspan': 3
                }
            })
            ifd.append({
                'name': 'remove',
                'widgetType': Tkinter.Button,
                'tooltip': """ Remove the selected entry from the
                        commands to be applied to the object when loaded in the application""",
                'wcfg': {
                    'text': 'REMOVE',
                    'width': 10,
                    'command': self.remove_cb
                },
                'gridcfg': {
                    'sticky': 'we',
                    'row': 0,
                    'column': 3
                }
            })

            ifd.append({
                'name': 'oneup',
                'widgetType': Tkinter.Button,
                'tooltip': """Move the selected entry up one entry""",
                'wcfg': {
                    'text': 'Move up',
                    'width': 10,
                    'command': self.moveup_cb
                },
                'gridcfg': {
                    'sticky': 'we',
                    'row': 1,
                    'column': 3
                }
            })

            ifd.append({
                'name': 'onedown',
                'widgetType': Tkinter.Button,
                'tooltip': """Move the selected entry down one entry""",
                'wcfg': {
                    'text': 'Move down',
                    'width': 10,
                    'command': self.movedown_cb
                },
                'gridcfg': {
                    'sticky': 'we',
                    'row': 2,
                    'column': 3
                }
            })

            self.form_Setanim = InputForm(self.master,
                                          None,
                                          descr=ifd,
                                          scrolledFrame=0)

            self.lc = self.form_Setanim.descr.entryByName['availableGeom'][
                'widget']
            self.lc2 = self.form_Setanim.descr.entryByName['geomtoload'][
                'widget']
            self.addObject(self.viewer.rootObject, None)
            val = self.form_Setanim.go()
            if val:
                self.assign()
                self.form_Setanim.withdraw()
        else:
            self.form_Setanim.deiconify()
            val = self.form_Setanim.go()
            if val:
                self.assign()
                self.form_Setanim.withdraw()

    def deleteAnim(self):
        """ Delete all frame from the player list."""

        self.Stop_cb()
        self.startFrame = 0
        self.endFrame = -1
        self.maxFrame = 0
        self.targetFrame = self.endFrame
        self.target = self.endFrame
        self.currentFrameIndex = 0

    def assign(self, list=None):
        """ assign the animation.
        framelist ; list of {}
        return a list of obj for each frame
        """
        self.deleteAnim()
        AllObjects = self.viewer.rootObject.AllObjects()
        if list:
            self.framelist = []
            for f in list:
                self.framelist.append((f, []))
        print "assign"
        print "self.framelist", self.framelist
        for frame in self.framelist:
            geomDic = frame[0]
            Namelist = []
            for parents in geomDic.keys():
                parentlist = filter(lambda x, name=parents: x.name == name,
                                    AllObjects)
                obj = parentlist[0]
                childrens = geomDic[obj.name]
                if len(childrens) > 0:
                    for namegeom in childrens:
                        child = filter(lambda x, name=namegeom: x.name == name,
                                       obj.children)[0]
                        if child.children != []:
                            for c in child.children:
                                frame[1].append(c)
                        else:
                            frame[1].append(child)
                else:
                    frame[1].append(obj)

            self.endFrame = self.endFrame + 1
            self.maxFrame = self.maxFrame + 1
            self.targetFrame = self.endFrame
            self.target = self.endFrame

    def movedown_cb(self):
        """ move entry one down """
        sel = self.lc2.get()
        index = self.lc2.getInd()
        if not sel: return
        sel = sel[0]
        if string.find(sel, "frame") < 0: return
        # get frame Index
        frameInd = int(string.split(sel, '_')[1])
        currentframe = self.framelist[frameInd]
        if (frameInd + 1) >= len(self.framelist): return
        # select next Frame.
        nextframe = self.framelist[frameInd + 1]
        # move current frame one down in list
        self.framelist[frameInd] = nextframe
        self.framelist[frameInd + 1] = currentframe
        self.updatelistchooser(self.framelist)

    def moveup_cb(self):
        """ move entry one up """
        sel = self.lc2.get()
        index = self.lc2.getInd()
        if not sel: return
        sel = sel[0]
        if string.find(sel, "frame") < 0: return
        # get frame Index
        frameInd = int(string.split(sel, '_')[1])
        currentframe = self.framelist[frameInd]
        if (frameInd - 1) < 0: return
        # select previous Frame
        prevframe = self.framelist[frameInd - 1]
        # move current frame one up in list
        self.framelist[frameInd] = prevframe
        self.framelist[frameInd - 1] = currentframe
        self.updatelistchooser(self.framelist)

    def addframe_cb(self):
        """ add a new frame entry"""
        frame = ({}, [])
        nb = len(self.framelist)
        #frame.number = nbframe
        value = 'frame_' + str(nb)
        self.framelist.append(frame)
        self.lc2.deselect(0, last='end')
        self.lc2.insert('end', value)
        self.lc2.select('end')

    def add_cb(self):
        listgeom = []
        # get the frame index to add new geom
        if len(self.lc2.entries) > 0:
            ind = self.lc2.getInd()
            if len(ind) == 0: return  # no entry selected so create a new frame
            # get geom name to load
            o = map(int, self.lc.lb.curselection())
            for Ind in o:
                fullName = self.getFullName(Ind)
                listgeom.append(fullName)
            # get frame instance
            for index in ind:
                value = self.lc2.entries[index][0]
                if string.find(value, "frame") < 0: return
                frameInd = int(string.split(value, '_')[1])
                frameGeom = self.framelist[frameInd][0]
                for geom in listgeom:
                    # strip the root
                    l = string.split(geom, '|')
                    if not frameGeom.has_key(l[1]):
                        frameGeom[l[1]] = []
                    for i in l[2:]:
                        if not (i in frameGeom[l[1]]):
                            frameGeom[l[1]].append(i)

            self.updatelistchooser(self.framelist)
        else:
            return

    def updatelistchooser(self, entry):
        """ update what is display in the list chooser """
        # save current selection
        sel = self.lc2.get()
        # remove current entry
        self.lc2.clear()
        prefix = '~'
        prefix2 = '~~'
        nb = 0
        for e in entry:
            v = 'frame_' + str(nb)
            nb = nb + 1
            # listchooser entry has to be a tuple(value,comment)
            self.lc2.add((v, ))
            for mol in e[0].keys():
                self.lc2.add((prefix + mol, ))
                for geom in e[0][mol]:
                    self.lc2.add((prefix2 + geom, ))
        # select the entry save as sel
        # keep the entry selected after the update
        for i in sel:
            self.lc2.select((i, ))

    def findFramefromGeomInd(self, index):
        """ return the frame number from  which the geom was selected """
        for i in range(index + 1):
            value = self.lc2.entries[index - i][0]
            if string.find(value, "frame") >= 0:
                frameInd = int(string.split(value, '_')[1])
                lcInd = index - i
                return (frameInd, lcInd)
        return 0

    def findParentGeom(self, index):
        """ find the parent value name from a geom ~~
        go up to find first value with onley ~ """
        parent = None
        for i in range(index + 1):
            parent = self.lc2.entries[index - i][0]
            if parent[0] == '~' and parent[1] != '~':
                parent = parent[1:]
                return parent
        return None

    def removeEntryGeom(self, value, index):
        """ the geom entry in the listchooser"""
        # first find from which frame we need to remove geom
        val = self.findFramefromGeomInd(index)
        if val:
            frameInd = val[0]
            lcInd = val[1]
            if value[1] == '~':
                parent = self.findParentGeom(index)
                if parent:
                    listgeom = self.framelist[frameInd][0][parent]
                    rindex = listgeom.index(value[2:])
                    del listgeom[rindex]

            elif self.framelist[frameInd][0].has_key(value[1:]):
                del self.framelist[frameInd][0][value[1:]]

            self.updatelistchooser(self.framelist)

    def removeEntryFrame(self, value, index):
        """ remove the frame entry in the listchooser"""
        # delete frame from framelist
        frameInd = int(string.split(value, '_')[1])
        del self.framelist[frameInd]
        # Update list chooser
        self.updatelistchooser(self.framelist)

    def remove_cb(self):
        """ remove entry in litschooser (geomtoload)"""
        selindex = self.lc2.getInd()
        for index in selindex:
            value = self.lc2.entries[index][0]
            if string.find(value, "frame") >= 0:
                self.removeEntryFrame(value, index)
            elif value[0] == '~':
                self.removeEntryGeom(value, index)
示例#6
0
class geomsChooser:
    def __init__(self, viewer):

        #ViewerGUI(viewer,8,2)
        # the viewe where the geoms are display (for us: pmv or DejaVu)
        if viewer is None:
            return
        self.viewer = viewer
        geomDic = {}
        dpyList = None
        self.assignGeom = [geomDic, dpyList]

    def toggleExpansion(self, event):
        # get a 0-based index into list of names
        o = self.lc.lb.nearest(event.y)
        fullName = self.getFullName(o)
        #obj = self.objectByName(self.olist.get(o))
        obj = self.viewer.FindObjectByName(fullName)
        if obj:
            childGeoms = obj.AllObjects()
            if len(childGeoms) == 1:  # this geoemtry has no children
                return
            else:  # this geometry has children
                if obj.isExpandedInObjectList: self.collapse(obj)
                else: self.expand(obj)

    def expand(self, object):
        # object is a geometry
        if object.isExpandedInObjectList: return
        object.isExpandedInObjectList = 1
        geoms = object.children
        ind = self.objectIndex(object) + 1
        c = self.countParents(object) + 1
        prefix = '~' * c
        for i in range(len(geoms)):
            g = geoms[i]
            if g == object: continue
            if not g.listed: continue
            if len(g.vertexSet) == 0 and len(g.children) == 0: continue
            self.lc.insert(ind, prefix + g.name)
            ind = ind + 1

    def collapse(self, object):
        # object is a geometry, we recursively collapse the sub-tree
        object.isExpandedInObjectList = 0

        # delete the names from the bject list widget
        nbChildren = self.countDecendentsInWidget(object)
        ind = self.objectIndex(object) + 1
        for i in range(ind, ind + nbChildren):
            self.lc.lb.delete(ind)
        # toggle isExpandedInObjectList for all descendents
        for child in object.AllObjects():
            if child.listed:
                child.isExpandedInObjectList = 0

    def countDecendentsInWidget(self, object):
        # object is a geometry, we count and return the number of
        # decendents shown in widget
        ind = self.objectIndex(object)
        allNames = self.lc.lb.get(0, 'end')
        nbTild = string.count(allNames[ind], '~') + 1
        # count children in widget
        nbChildren = 0
        for i in range(ind + 1, len(allNames)):
            nbt = string.count(allNames[i], '~')
            if nbt >= nbTild:
                nbChildren = nbChildren + 1
            else:
                break
        return nbChildren

    def getFullName(self, ind):
        # strip the leading ~
        allNames = self.lc.lb.get(0, 'end')
        nbTild = string.count(allNames[ind], '~')
        fullName = allNames[ind][nbTild:]
        for i in range(ind - 1, -1, -1):
            nbt, name = self.lstripChar(allNames[i], '~')
            if nbt >= nbTild: continue
            nbTild = nbt
            fullName = name + '|' + fullName
        return fullName

    def objectIndex(self, object):
        # object is a geometry and we find this object's index in the list of
        # names displayed in te widget. If the ibecjt is not shown we
        # return -1
        l = self.lc.lb.get(0, 'end')
        for i in range(len(l)):
            indent, n = self.lstripChar(l[i], '~')
            if n == object.name: break
        if i == len(l): return -1
        else: return i

    def lstripChar(self, name, char):
        n = string.count(name, '~')
        return n, name[n:]

    def countParents(self, object):
        c = 0
        while object.parent:
            c = c + 1
            object = object.parent
        return c

    def addObject(self, obj, parent):
        if not obj.listed: return
        if not parent:
            self.lc.insert(0, obj.name)
            self.lc.select(obj.name)
        else:
            if not parent.isExpandedInObjectList: return

            i = self.objectIndex(parent)
            if i == -1: return
            c = self.countParents(obj)
            prefix = '~' * c
            name = prefix + obj.name
            # now we need to skip all children already there
            l = self.lc.lb.get(0, 'end')
            while 1:
                i = i + 1
                if i == len(l): break
                if self.lc.get(i)[:c] != prefix: break

            self.lc.insert(i, name)

    def getFullNameList(self, name, list, dic):
        """ get the list of fullName from geomDic """

        for p in dic.keys():
            name1 = name + '|' + p
            if dic[p] != {}:
                list = self.getFullNameList(name1, list, dic[p])
            else:
                list.append(name1)

        return list

    def getDpyList(self, objects):
        """function to obtain a display list for any object in DejaVu"""
        from opengltk.OpenGL import GL
        # Draw build a display function that contains global coloring,
        # transformation nd all global GL properties of this objects.
        # we cannot use the object's display list that does not contains this
        # info
        #if len(objects) == 1 and objects[0].dpyList:
        #    return objects[0].dpyList
        # transparent object need to be drawn last

        # reorder object so transparent object drawn last
        transparent = []
        opaque = []
        for obj in objects:
            if obj.transparent:  #obj.isTransparent():
                transparent.append(obj)
            else:
                opaque.append(obj)
        objlist = opaque + transparent

        lNewList = GL.glGenLists(1)
        #print "lNewList geomsChooser.getDpyList", lNewList, self.name
        dpyList = (lNewList,
                   self.viewer.currentCamera.tk.call(
                       self.viewer.currentCamera._w, 'contexttag'))

        camera = self.mv.GUI.VIEWER.currentCamera
        camera.Activate()

        GL.glNewList(dpyList, GL.GL_COMPILE)
        #print "geomChooser 208", GL.glGetIntegerv(GL.GL_LIST_INDEX)
        for obj in objlist:
            if obj.immediateRendering:  # or obj.hasChildWithImmediateRendering:
                camera.drawMode = 5
                camera.Draw(obj)
            else:
                camera.drawMode = 2
                camera.drawTransparentObjects = 0
                camera.hasTransparentObjects = 0
                # draw opaque object
                for m in obj.instanceMatricesFortran:
                    GL.glPushMatrix()
                    GL.glMultMatrixf(m)
                    if len(obj.children):
                        map(camera.Draw, obj.children)
                    else:
                        camera.Draw(obj)
                    GL.glPopMatrix()

                # draw transparent children of object
                if camera.hasTransparentObjects:
                    camera.drawTransparentObjects = 1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        map(camera.Draw, obj.children)
                        GL.glPopMatrix()
                # draw transparent object that do not have children
                if obj.isTransparent() and not len(obj.children):
                    camera.drawTransparentObjects = 1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        camera.Draw(obj)
                        GL.glPopMatrix()

        GL.glEndList()
        return dpyList

    def buildForm(self):
        ifd = InputFormDescr(title=self.ftitle)
        ifd.append({
            'widgetType': ListChooser,
            'name': 'availableGeom',
            'tooltip': 'geom available in viewer',
            'wcfg': {
                'mode': 'extended',
                'lbwcfg': {
                    'exportselection': 1
                },
                'command': [(self.toggleExpansion, '<Double-Button-1>')],
                'commandEvent': None,
                'title': 'availableGeom'
            },
            'gridcfg': {
                'row': 0,
                'column': 0,
                'sticky': 'wens',
                'rowspan': 3
            }
        })

        ifd.append({
            'name': 'add',
            'widgetType': Tkinter.Button,
            'tooltip': """ Add the selected geom to selected frame""",
            'wcfg': {
                'text': '>>',
                'command': self.add_cb
            },
            'gridcfg': {
                'row': 1,
                'column': 1,
                'rowspan': 1
            }
        })

        ifd.append({
            'name': 'remove',
            'widgetType': Tkinter.Button,
            'tooltip': """ remove the selected geom to selected """,
            'wcfg': {
                'text': '<<',
                'command': self.remove_cb
            },
            'gridcfg': {
                'row': 2,
                'column': 1,
                'rowspan': 1
            }
        })

        ifd.append({
            'name': 'toload',
            'widgetType': ListChooser,
            'tooltip': """list of geom  the user chose to
                    apply to the pattern""",
            'wcfg': {
                'mode': 'extended',
                'lbwcfg': {
                    'exportselection': 0
                },
                'title': self.lc2title
            },
            'gridcfg': {
                'sticky': 'we',
                'row': 0,
                'column': 2,
                'rowspan': 3
            }
        })
        ifd.append({
            'name': 'clear',
            'widgetType': Tkinter.Button,
            'tooltip': """ Clear entry """,
            'wcfg': {
                'text': 'Clear',
                'width': 10,
                'command': self.clear_cb
            },
            'gridcfg': {
                'sticky': 'we',
                'row': 0,
                'column': 3
            }
        })
        ifd.append({
            'name': 'remove',
            'widgetType': Tkinter.Button,
            'tooltip': """ remove the selected geom to selected """,
            'wcfg': {
                'text': '<<',
                'command': self.remove_cb
            },
            'gridcfg': {
                'row': 2,
                'column': 1,
                'rowspan': 1
            }
        })
        return ifd

    def showForm(self, master, geomDic=None, func=None):
        """create formdescr for setGeoms
        geomDic = a dict of Geom 
        """
        # assign a func so we can log it in Pmv
        # func is a Pmv command
        if func:
            self.assign_func = func

        if geomDic:
            self.assignGeom[0] = geomDic

        if hasattr(self, 'form'):
            if self.guiOn:
                return
            else:
                self.update_lc2()
                self.form.deiconify()
                val = self.form.go()

                if val:
                    geomDic = self.assignGeom[0]
                    self.assign_func(geomDic)
                    self.form.withdraw()
        else:
            if not master:
                master = Tkinter.Toplevel()
                master.title('GeomChooser')
            else:
                master = master

            ifd = self.buildForm()
            self.form = InputForm(master,
                                  None,
                                  descr=ifd,
                                  scrolledFrame=0,
                                  cancelCfg={'command': self.cancel_cb})

            self.lc = self.form.descr.entryByName['availableGeom']['widget']
            self.lc2 = self.form.descr.entryByName['toload']['widget']
            self.addObject(self.viewer.rootObject, None)
            self.update_lc2()
            val = self.form.go()
            if val:
                geomDic = self.assignGeom[0]
                self.assign_func(geomDic)
                self.form.withdraw()

    def cancel_cb(self, event=None, func=None):
        """ close setup animation form without setting anything"""
        if hasattr(self, 'geomDicCopy'):
            self.patDic = self.patDicCopy.copy()

    def add_cb(self):
        lgeom = []
        geomDic = self.assignGeom[0]
        # get geom name to load
        o = map(int, self.lc.lb.curselection())
        for Ind in o:
            fullName = self.getFullName(Ind)
            obj = self.viewer.FindObjectByName(fullName)
            # strip the root
            l = string.split(fullName, '|')[1:]
            for i in range(len(l)):
                if i == 0:
                    if not geomDic.has_key(l[i]):
                        dic = geomDic[l[i]] = {}
                    else:
                        dic = geomDic[l[i]]
                else:
                    if not dic.has_key(l[i]):
                        dic[l[i]] = {}

                    dic = dic[l[i]]

        self.update_lc2()

    def insertValue(self, ind, prefix, dic):
        """ insert Value of a dictionnary in the listchooser2"""
        for key in dic.keys():
            if dic[key] == {}:
                ind = ind + 1
                self.lc2.insert(ind, prefix + key)
            else:
                ind = ind + 1
                self.lc2.insert(ind, prefix + key)
                p = prefix + '~'
                ind = self.insertValue(ind, p, dic[key])
        return ind

    def update_lc2(self):
        """ update listchooser entries display"""

        # save current entry selected
        sel = self.lc2.get()
        prefix = '~'
        self.lc2.clear()
        ind = 0
        geomDic = self.assignGeom[0]
        ind = self.insertValue(ind, prefix, geomDic)

        # select the entry save as sel
        # keep the entry selected after the update
        for i in sel:
            self.lc2.select((i, ))

    def findParentMol(self, index):
        """ find the parent value name from a geom ~~
        go up to find first value with onley ~ """
        parent = None
        for i in range(index + 1):
            parent = self.lc2.entries[index - i][0]
            if parent[0] == '~' and parent[1] != '~':
                parent = parent[1:]
                return parent
        return None

    def remove_cb(self):
        """ remove entry in litschooser (geomtoload)"""
        geomDic = self.assignGeom[0]
        selindex = self.lc2.getInd()
        for index in selindex:
            value = self.lc2.entries[index][0]

            if value[1] == '~':
                mol = self.findParentMol(index)
                rindex = geomDic[mol].index(value[2:])
                del geomDic[mol][rindex]
            else:
                mol = value[1:]
                del geomDic[mol]
        self.update_lc2()

    def clear_cb(self):
        """ clear all entry """
        self.lc2.clear()
        if self.assignGeom:
            self.assignGeom[0] = {}  # geomDic
            self.assignGeom[1] = None  # dpyList
class AnimPlayer(Player,geomsChooser):
    """ provide a player to display/undisplay DejaVu object
    in a cylce making a animation.

    viewer: DejaVu viewer
    height,width are the property of the player gui
    startFrame: frame to begin
    endFrame: last frame to display
    stepSize: step between new frame
    playMode:                  #playMode options:
                               #   0   play once and stop
                               #   1   play continuously in 1 direction
                               #   2   play once in 2 directions
                               #   3   play continuously in 2 directions
    titleStr: title of the gui windows
    counter: gui with a counter on or not
    gui: #1 show the player gui
         #0 player gui not display
    framerate =15.             # number of frame per second to be display
    """


    def __init__(self,viewer, master=None, root=None,
                 height=80,width=200,
                 currentFrameIndex=0,
                 startFrame=0, 
                 endFrame=0,
                 maxFrame=0,
                 stepSize=1, 
                 playMode=1,
                 titleStr='AnimPlayer',
                 counter = 1,
                 gui=1,framerate=15.):

        if master is None:
            master = Tkinter.Toplevel()

        # viewer from which we get the geom to animate
        self.viewer = viewer
        # frame list, is a list of geom .
        # each frame is made of n DejaVu object to be display
        # it a list of tuple, each tuple is a {} and []
        # {} is: {'objname':['geom1','geom2'],'objname':['geom1','geom2']}
        # [] is list of DejaVu object per frame
        self.framelist=[]

        Player.__init__(self, master=master,root=root,height=height,
                        width=width,currentFrameIndex=currentFrameIndex,
                        startFrame=startFrame,endFrame=endFrame,
                        maxFrame=maxFrame,stepSize=stepSize,
                        playMode=playMode,titleStr=titleStr,counter=counter,
                        gui=gui,framerate=framerate)

    def nextFrame(self, id):
        """ id: index number of the frame to display.
        undisplay object from previous frame, display object
        of new frame.
        """
        if not self.framelist:return
        id = int(id)
        if id >=len(self.framelist):return

        i = self.currentFrameIndex
        ## undisplay previous object
        frame = self.framelist[i]
        for obj in frame[1]:
            obj.Set(visible=0,redo=0)
            
        if self.hasCounter and self.gui:
            self.form.ent2.delete(0,'end')
            self.form.ent2.insert(0, str(id))

        ## display new frame
        currentframe = self.framelist[id]
        for obj in currentframe[1]:
            obj.Set(visible=1,redo=0)
        
        self.viewer.deleteOpenglList()
	self.viewer.Redraw()
        self.currentFrameIndex = id

#####################################################################
#### Animation Setting the frame

    def SetAnim_cb(self):
        self.showForm()
        
    def showForm(self):
        """create formdescr for setAnim
        form to set the animation:
        each frame is a list of geom to display
        """

        entryFrame = []
        for i in range(len(self.framelist)):
            val = 'frame_'+str(i)
            entryFrame.append((val,))
        
        if not hasattr(self,'form_Setanim'):
            ifd = InputFormDescr(title="SetAnimation")
            ifd.append({'widgetType':ListChooser,
                        'name':'availableGeom',
                        'tooltip':'geom available in viewer',
                        'wcfg':{'mode':'extended',
                                'lbwcfg':{'exportselection':1},
                                'command':[(self.toggleExpansion,'<Double-Button-1>')],
                                'commandEvent':None,
                                'title':'availableGeom'},
                        
                        'gridcfg':{'row':0,'column':0,
                                   'sticky':'wens','rowspan':3}})
            ifd.append({'name':'newframe',
                        'widgetType':Tkinter.Button,
                        'tooltip':""" Add an empty frame to the animation""",
                        'wcfg':{'text':'NewFrame','command':self.addframe_cb},
                        'gridcfg':{'row':0,'column':1,'rowspan':1 }})
            
            ifd.append({'name':'add',
                        'widgetType':Tkinter.Button,
                        'tooltip':""" Add the selected geom to selected frame""",
                        'wcfg':{'text':'AddGeom','command':self.add_cb},
                        'gridcfg':{'row':1,'column':1,'rowspan':1 }})
            
            ifd.append({'name':'geomtoload',
                        'widgetType':ListChooser,
                        'tooltip':"""list of frame  the user chose to
                        apply to the pattern""",
                        'wcfg':{'entries':entryFrame,
                                'mode':'extended',
                                'lbwcfg':{'exportselection':0},
                                'title':'Frame(geom) to be display'},
                        'gridcfg':{'sticky':'we', 
                                   'row':0, 'column':2,'rowspan':3}})
            ifd.append({'name':'remove',
                        'widgetType':Tkinter.Button,
                        'tooltip':""" Remove the selected entry from the
                        commands to be applied to the object when loaded in the application""",
                        'wcfg':{'text':'REMOVE','width':10,
                                'command':self.remove_cb},
                        'gridcfg':{'sticky':'we','row':0, 'column':3}})
            
            ifd.append({'name':'oneup',
                        'widgetType':Tkinter.Button,
                        'tooltip':"""Move the selected entry up one entry""",
                        'wcfg':{'text':'Move up','width':10,
                                'command':self.moveup_cb},
                        'gridcfg':{'sticky':'we','row':1,'column':3}})
            
            ifd.append({'name':'onedown',
                        'widgetType':Tkinter.Button,
                        'tooltip':"""Move the selected entry down one entry""",
                        'wcfg':{'text':'Move down','width':10,
                                'command':self.movedown_cb},
                        'gridcfg':{'sticky':'we','row':2,'column':3}})

            self.form_Setanim = InputForm(self.master,None,descr=ifd,
                                  scrolledFrame=0)
            
            
            self.lc = self.form_Setanim.descr.entryByName['availableGeom']['widget']
            self.lc2 = self.form_Setanim.descr.entryByName['geomtoload']['widget']
            self.addObject(self.viewer.rootObject,None)
            val = self.form_Setanim.go()
            if val:
                self.assign()
                self.form_Setanim.withdraw()
        else:
            self.form_Setanim.deiconify()
            val = self.form_Setanim.go()
            if val:
                self.assign()
                self.form_Setanim.withdraw()
                
    def deleteAnim(self):
        """ Delete all frame from the player list."""

        self.Stop_cb()
        self.startFrame=0
        self.endFrame = -1
        self.maxFrame = 0
        self.targetFrame = self.endFrame
        self.target = self.endFrame
        self.currentFrameIndex =0


    def assign(self,list=None):
        """ assign the animation.
        framelist ; list of {}
        return a list of obj for each frame
        """
        self.deleteAnim()
        AllObjects = self.viewer.rootObject.AllObjects()
        if list :
            self.framelist=[]
            for f in list:
                self.framelist.append((f,[]))
        print "assign"
        print "self.framelist",self.framelist
        for frame in self.framelist:
            geomDic = frame[0]
            Namelist=[]
            for parents in geomDic.keys():
                parentlist = filter(lambda x, name=parents:x.name == name,AllObjects)
                obj = parentlist[0]
                childrens = geomDic[obj.name]
                if len(childrens) > 0:
                    for namegeom in childrens:
                        child = filter(lambda x,
                                       name=namegeom:x.name == name,
                                       obj.children)[0]
                        if child.children != []:
                            for c in child.children:
                                frame[1].append(c)
                        else:
                            frame[1].append(child)
                else:
                    frame[1].append(obj)

            self.endFrame = self.endFrame +1
            self.maxFrame = self.maxFrame +1
            self.targetFrame = self.endFrame
            self.target = self.endFrame


    def movedown_cb(self):
        """ move entry one down """
        sel = self.lc2.get()
        index = self.lc2.getInd()
        if not sel: return
        sel = sel[0]
        if string.find(sel,"frame") < 0: return
        # get frame Index
        frameInd = int(string.split(sel,'_')[1])
        currentframe = self.framelist[frameInd]
        if (frameInd + 1) >= len(self.framelist):return
        # select next Frame.
        nextframe = self.framelist[frameInd+1]
        # move current frame one down in list
        self.framelist[frameInd] =nextframe
        self.framelist[frameInd+1] =currentframe
        self.updatelistchooser(self.framelist)

    def moveup_cb(self):
        """ move entry one up """
        sel = self.lc2.get()
        index = self.lc2.getInd()
        if not sel: return
        sel = sel[0]
        if string.find(sel,"frame") < 0: return
        # get frame Index
        frameInd = int(string.split(sel,'_')[1])
        currentframe=self.framelist[frameInd]
        if (frameInd - 1) <  0 :return
        # select previous Frame
        prevframe = self.framelist[frameInd-1]
        # move current frame one up in list
        self.framelist[frameInd] =prevframe
        self.framelist[frameInd-1] =currentframe
        self.updatelistchooser(self.framelist)
        
    def addframe_cb(self):
        """ add a new frame entry"""
        frame = ({},[])
        nb = len(self.framelist)
        #frame.number = nbframe 
        value = 'frame_'+ str(nb)
        self.framelist.append(frame)
        self.lc2.deselect(0,last='end')
        self.lc2.insert('end',value)
        self.lc2.select('end')

    def add_cb(self):
        listgeom=[]
        # get the frame index to add new geom
        if len(self.lc2.entries)>0:
            ind = self.lc2.getInd()
            if len(ind) ==0:return # no entry selected so create a new frame
            # get geom name to load
            o = map(int,self.lc.lb.curselection())
            for Ind in o:
                    fullName = self.getFullName(Ind)
                    listgeom.append(fullName)
            # get frame instance
            for index in ind:
                value = self.lc2.entries[index][0]
                if string.find(value,"frame") < 0: return
                frameInd = int(string.split(value,'_')[1])
                frameGeom = self.framelist[frameInd][0]
                for geom in listgeom:
                    # strip the root
                    l = string.split(geom,'|')
                    if not frameGeom.has_key(l[1]):
                        frameGeom[l[1]]=[]
                    for i in l[2:]:
                        if not( i in frameGeom[l[1]]):
                            frameGeom[l[1]].append(i)

            self.updatelistchooser(self.framelist)
        else:
            return
        
    def updatelistchooser(self,entry):
        """ update what is display in the list chooser """
        # save current selection
        sel  = self.lc2.get()
        # remove current entry
        self.lc2.clear()
        prefix = '~'
        prefix2 = '~~'
        nb= 0
        for e in entry:
            v = 'frame_'+str(nb)
            nb = nb+1
            # listchooser entry has to be a tuple(value,comment)
            self.lc2.add((v,))
            for mol in e[0].keys():
                self.lc2.add((prefix+mol,))
                for geom in e[0][mol]:
                    self.lc2.add((prefix2+geom,))
        # select the entry save as sel
        # keep the entry selected after the update
        for i in sel:
            self.lc2.select((i,))


    def findFramefromGeomInd(self,index):
        """ return the frame number from  which the geom was selected """
        for i in range(index+1):
            value = self.lc2.entries[index-i][0]
            if string.find(value,"frame") >= 0:
                frameInd =  int(string.split(value,'_')[1])
                lcInd = index -i
                return (frameInd,lcInd)
        return 0
    
    def findParentGeom(self,index):
        """ find the parent value name from a geom ~~
        go up to find first value with onley ~ """
        parent = None
        for i in range(index+1):
            parent = self.lc2.entries[index -i][0]
            if parent[0] == '~' and parent[1] !='~':
                parent = parent[1:]
                return parent
        return  None
    
    def removeEntryGeom(self,value,index):
        """ the geom entry in the listchooser"""
        # first find from which frame we need to remove geom
        val = self.findFramefromGeomInd(index)
        if val:
            frameInd =val[0]
            lcInd = val[1]
            if value[1] == '~':
                parent = self.findParentGeom(index)
                if parent:
                    listgeom = self.framelist[frameInd][0][parent]
                    rindex = listgeom.index(value[2:])
                    del listgeom[rindex]
                
            elif self.framelist[frameInd][0].has_key(value[1:]):
                del self.framelist[frameInd][0][value[1:]]
            
            self.updatelistchooser(self.framelist)
            
    def removeEntryFrame(self,value,index):
        """ remove the frame entry in the listchooser"""
        # delete frame from framelist
        frameInd = int(string.split(value,'_')[1])
        del self.framelist[frameInd]
        # Update list chooser
        self.updatelistchooser(self.framelist)
        
    def remove_cb(self):
        """ remove entry in litschooser (geomtoload)"""
        selindex = self.lc2.getInd()
        for index in selindex:
            value = self.lc2.entries[index][0]
            if string.find(value,"frame") >= 0:
                self.removeEntryFrame(value,index)
            elif value[0] == '~':
                self.removeEntryGeom(value,index)
class geomsChooser:

    def __init__(self,viewer):

        #ViewerGUI(viewer,8,2)
        # the viewe where the geoms are display (for us: pmv or DejaVu)
        if viewer is None:
            return
        self.viewer = viewer
        geomDic = {}
        dpyList = None
        self.assignGeom =[geomDic,dpyList]

 
    def toggleExpansion(self, event):
        # get a 0-based index into list of names
	o = self.lc.lb.nearest(event.y)
        fullName = self.getFullName(o)
	#obj = self.objectByName(self.olist.get(o))
        obj = self.viewer.FindObjectByName(fullName)
	if obj:
            childGeoms = obj.AllObjects()
            if len(childGeoms)==1:  # this geoemtry has no children
                return
            else: # this geometry has children
                if obj.isExpandedInObjectList: self.collapse(obj)
                else: self.expand(obj)

    def expand(self, object):
        # object is a geometry
        if object.isExpandedInObjectList: return
        object.isExpandedInObjectList = 1
        geoms = object.children
        ind = self.objectIndex(object) + 1
        c = self.countParents(object) + 1
        prefix = '~'*c
        for i in range(len(geoms)):
            g = geoms[i]
            if g==object: continue
            if not g.listed: continue
            if len(g.vertexSet) == 0 and len(g.children)==0:continue
            self.lc.insert(ind, prefix + g.name)
            ind = ind + 1

            
    def collapse(self, object):
        # object is a geometry, we recursively collapse the sub-tree
        object.isExpandedInObjectList = 0

        # delete the names from the bject list widget
        nbChildren = self.countDecendentsInWidget(object)
        ind = self.objectIndex(object) + 1
        for i in range(ind, ind+nbChildren):
            self.lc.lb.delete(ind)
        # toggle isExpandedInObjectList for all descendents
        for child in object.AllObjects():
            if child.listed:
                child.isExpandedInObjectList = 0

    def countDecendentsInWidget(self, object):
        # object is a geometry, we count and return the number of 
        # decendents shown in widget
        ind = self.objectIndex(object)
        allNames = self.lc.lb.get(0,'end')
        nbTild = string.count(allNames[ind],'~')+1
        # count children in widget
        nbChildren = 0
        for i in range(ind+1, len(allNames)):
            nbt = string.count(allNames[i],'~')
            if nbt >= nbTild:
                nbChildren = nbChildren + 1
            else:
                break
        return nbChildren

        
    def getFullName(self, ind):
        # strip the leading ~
        allNames = self.lc.lb.get(0,'end')
        nbTild = string.count(allNames[ind],'~')
        fullName = allNames[ind][nbTild:]
        for i in range(ind-1, -1, -1):
            nbt, name = self.lstripChar(allNames[i], '~')
            if nbt >= nbTild: continue
            nbTild = nbt
            fullName = name + '|' + fullName
        return fullName

    def objectIndex(self, object):
        # object is a geometry and we find this object's index in the list of
        # names displayed in te widget. If the ibecjt is not shown we
        # return -1
        l = self.lc.lb.get(0,'end')
        for i in range(len(l)):
            indent, n = self.lstripChar(l[i], '~')
            if n==object.name: break
        if i==len(l): return -1
        else: return i

    def lstripChar(self, name, char):
	n = string.count(name,'~')
	return n, name[ n : ]

    def countParents(self, object):
	c = 0
	while object.parent:
	    c = c+1
	    object = object.parent
	return c

    def addObject(self, obj, parent):
        if not obj.listed: return
	if not parent:
	    self.lc.insert(0,obj.name)
	    self.lc.select(obj.name)
	else:
            if not parent.isExpandedInObjectList: return
                
            i = self.objectIndex(parent)
	    if i==-1: return
	    c = self.countParents(obj)
            prefix = '~'*c
	    name = prefix + obj.name
            # now we need to skip all children already there
            l = self.lc.lb.get(0,'end')
            while 1:
                i = i + 1
                if i==len(l): break
                if self.lc.get(i)[:c]!=prefix: break

	    self.lc.insert(i, name)

    def getFullNameList(self,name,list,dic):
        """ get the list of fullName from geomDic """

        for p in dic.keys():
            name1 = name +'|'+p
            if dic[p] != {}:
                list = self.getFullNameList(name1,list,dic[p])
            else:
                list.append(name1)
                
        return list
    

    def getDpyList(self,objects):
        """function to obtain a display list for any object in DejaVu"""
        from opengltk.OpenGL import GL
        # Draw build a display function that contains global coloring,
        # transformation nd all global GL properties of this objects.
        # we cannot use the object's display list that does not contains this
        # info
        #if len(objects) == 1 and objects[0].dpyList:
        #    return objects[0].dpyList
        # transparent object need to be drawn last

        # reorder object so transparent object drawn last
        transparent =[]
        opaque = []
        for obj in objects:
            if obj.transparent: #obj.isTransparent():
                transparent.append(obj)
            else:
                opaque.append(obj)
        objlist = opaque + transparent
        
        lNewList = GL.glGenLists(1)
        #print "lNewList geomsChooser.getDpyList", lNewList, self.name
        dpyList = ( lNewList,
                   self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
                  )

        camera = self.mv.GUI.VIEWER.currentCamera
        camera.Activate()

        GL.glNewList(dpyList, GL.GL_COMPILE)
        #print "geomChooser 208", GL.glGetIntegerv(GL.GL_LIST_INDEX)
        for obj in objlist:
            if obj.immediateRendering: # or obj.hasChildWithImmediateRendering:
                camera.drawMode=5
                camera.Draw(obj)
            else:
                camera.drawMode=2
                camera.drawTransparentObjects = 0
                camera.hasTransparentObjects = 0
                # draw opaque object
                for m in obj.instanceMatricesFortran:
                    GL.glPushMatrix()
                    GL.glMultMatrixf(m)
                    if len(obj.children):
                        map( camera.Draw, obj.children)
                    else:
                        camera.Draw(obj)
                    GL.glPopMatrix()
                
                # draw transparent children of object
                if camera.hasTransparentObjects:
                    camera.drawTransparentObjects = 1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        map( camera.Draw, obj.children)
                        GL.glPopMatrix()
                # draw transparent object that do not have children
                if obj.isTransparent() and not len(obj.children):
                    camera.drawTransparentObjects =1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        camera.Draw(obj)
                        GL.glPopMatrix()
                    

        GL.glEndList()    
        return dpyList

    def buildForm(self):
        ifd = InputFormDescr(title=self.ftitle)
        ifd.append({'widgetType':ListChooser,
                    'name':'availableGeom',
                    'tooltip':'geom available in viewer',
                    'wcfg':{'mode':'extended',
                            'lbwcfg':{'exportselection':1},
                            'command':[(self.toggleExpansion,'<Double-Button-1>')],
                            'commandEvent':None,
                            'title':'availableGeom'},
                    
                    'gridcfg':{'row':0,'column':0,
                               'sticky':'wens','rowspan':3}})
        
        ifd.append({'name':'add',
                    'widgetType':Tkinter.Button,
                    'tooltip':""" Add the selected geom to selected frame""",
                    'wcfg':{'text':'>>','command':self.add_cb},
                    'gridcfg':{'row':1,'column':1,'rowspan':1 }})
        
        ifd.append({'name':'remove',
                    'widgetType':Tkinter.Button,
                    'tooltip':""" remove the selected geom to selected """,
                    'wcfg':{'text':'<<','command':self.remove_cb},
                    'gridcfg':{'row':2,'column':1,'rowspan':1 }})
            
        ifd.append({'name':'toload',
                    'widgetType':ListChooser,
                    'tooltip':"""list of geom  the user chose to
                    apply to the pattern""",
                    'wcfg':{
            'mode':'extended',
            'lbwcfg':{'exportselection':0},
            'title':self.lc2title},
                    'gridcfg':{'sticky':'we', 
                               'row':0, 'column':2,'rowspan':3}})
        ifd.append({'name':'clear',
                    'widgetType':Tkinter.Button,
                    'tooltip':""" Clear entry """,
                    'wcfg':{'text':'Clear','width':10,
                            'command':self.clear_cb},
                    'gridcfg':{'sticky':'we','row':0, 'column':3}})
        ifd.append({'name':'remove',
                    'widgetType':Tkinter.Button,
                    'tooltip':""" remove the selected geom to selected """,
                    'wcfg':{'text':'<<','command':self.remove_cb},
                    'gridcfg':{'row':2,'column':1,'rowspan':1 }})
        return ifd
        
    def showForm(self,master,geomDic=None,func=None):
        """create formdescr for setGeoms
        geomDic = a dict of Geom 
        """
        # assign a func so we can log it in Pmv
        # func is a Pmv command
        if func:
            self.assign_func = func
            
        if geomDic:
            self.assignGeom[0]=geomDic
            
        if hasattr(self,'form'):
            if self.guiOn:
                return
            else:
                self.update_lc2()
                self.form.deiconify()
                val = self.form.go()
               
                if val:
                    geomDic =self.assignGeom[0] 
                    self.assign_func(geomDic)
                    self.form.withdraw()
        else:
            if not master:
                master = Tkinter.Toplevel()
                master.title('GeomChooser')
            else:
                master = master

            ifd = self.buildForm()
            self.form = InputForm(master,None,descr=ifd,
                                  scrolledFrame=0,
                                  cancelCfg={'command':self.cancel_cb})
                
            self.lc = self.form.descr.entryByName['availableGeom']['widget']
            self.lc2 = self.form.descr.entryByName['toload']['widget']
            self.addObject(self.viewer.rootObject,None)
            self.update_lc2()
            val = self.form.go()
            if val:
                geomDic =self.assignGeom[0] 
                self.assign_func(geomDic)
                self.form.withdraw()
                
    def cancel_cb(self,event = None, func=None):
        """ close setup animation form without setting anything"""
        if hasattr(self,'geomDicCopy'):
            self.patDic = self.patDicCopy.copy()
        
    def add_cb(self):
        lgeom=[]
        geomDic = self.assignGeom[0]
        # get geom name to load
        o = map(int,self.lc.lb.curselection())
        for Ind in o:
            fullName = self.getFullName(Ind)
            obj = self.viewer.FindObjectByName(fullName)
            # strip the root
            l = string.split(fullName,'|')[1:]
            for i in range(len(l)):
                if i==0:
                    if not geomDic.has_key(l[i]):
                        dic = geomDic[l[i]]={}
                    else:
                        dic = geomDic[l[i]]
                else:
                    if not dic.has_key(l[i]):
                        dic[l[i]]={}
                        
                    dic = dic[l[i]]
            
        self.update_lc2()

    def insertValue(self,ind,prefix,dic):
        """ insert Value of a dictionnary in the listchooser2"""
        for key in dic.keys():
            if dic[key] == {}:
                ind = ind+1
                self.lc2.insert(ind, prefix+key)
            else:
                ind =ind +1
                self.lc2.insert(ind, prefix+key)
                p = prefix + '~'
                ind=self.insertValue(ind,p,dic[key])
        return ind
        
    def update_lc2(self):
        """ update listchooser entries display"""

        # save current entry selected
        sel  = self.lc2.get()
        prefix = '~'
        self.lc2.clear()
        ind = 0
        geomDic = self.assignGeom[0]
        ind = self.insertValue(ind,prefix,geomDic)

        # select the entry save as sel
        # keep the entry selected after the update
        for i in sel:
            self.lc2.select((i,))

    def findParentMol(self,index):
        """ find the parent value name from a geom ~~
        go up to find first value with onley ~ """
        parent = None
        for i in range(index+1):
            parent = self.lc2.entries[index -i][0]
            if parent[0] == '~' and parent[1] !='~':
                parent = parent[1:]
                return parent
        return  None
         
    def remove_cb(self):
        """ remove entry in litschooser (geomtoload)"""
        geomDic = self.assignGeom[0]
        selindex = self.lc2.getInd()
        for index in selindex:
            value = self.lc2.entries[index][0]
           
            if value[1] == '~':
                mol = self.findParentMol(index)
                rindex = geomDic[mol].index(value[2:])
                del geomDic[mol][rindex]
            else:
                mol = value[1:]
                del geomDic[mol]
        self.update_lc2()

    def clear_cb(self):
        """ clear all entry """
        self.lc2.clear()
        if  self.assignGeom:
            self.assignGeom[0] = {} # geomDic
            self.assignGeom[1] = None # dpyList