Exemplo n.º 1
0
    def get(self):
        if not hasattr(self, 'vals'):
            return
        # Apply if Cancel button was checked self.result = None
        elif not self.vals:
            #self.result =(self.text,None,None)
            self.result = {}

        # No function defined is the text field.
        elif self.vals['UserFunction'] in ['\012','']:
            #self.result = (self.text,None,None)
            self.result = {}

        else:
            # Text lets remove comments
            # Function defined
            funcString = self.vals['UserFunction']
            function = evalString(funcString)

            textwcfg = self.idf[0]
            if self.callback:
##                 self.result = (self.text,
##                                self.callback(function), funcString)
                self.result = (self.text,
                               self.callback(function),function)
                               
            else:
##                 self.result = (self.text,None,funcString)
                self.result = (self.text,None,function)
        # Have to send back a tuple (name of the widget, result, function)

        return self.result
Exemplo n.º 2
0
    def get(self):
        if not hasattr(self, 'vals'):
            return
        # Apply if Cancel button was checked self.result = None
        elif not self.vals:
            #self.result =(self.text,None,None)
            self.result = {}

        # No function defined is the text field.
        elif self.vals['UserFunction'] in ['\012','']:
            #self.result = (self.text,None,None)
            self.result = {}

        else:
            # Text lets remove comments
            # Function defined
            funcString = self.vals['UserFunction']
            function = evalString(funcString)

            textwcfg = self.idf[0]
            if self.callback:
##                 self.result = (self.text,
##                                self.callback(function), funcString)
                self.result = (self.text,
                               self.callback(function),function)
                               
            else:
##                 self.result = (self.text,None,funcString)
                self.result = (self.text,None,function)
        # Have to send back a tuple (name of the widget, result, function)

        return self.result
        def drawLabels(mol, nodes, materials, function, lambdaFunc,
                       font, location, only, negate, format):
            #font = 'glut'+ font
            geomName = nodes[0].__class__.__name__+'Labels'
            labelGeom = mol.geomContainer.geoms[geomName]
            set = mol.geomContainer.atoms[geomName]
            if negate:
                if len(set):
                    set = set - nodes
            ##if only or there were no labels, label current atms 
            elif only or not len(set):
                set = nodes
            ##not negate, not only and some previous labels, 
            ##  label union of old + new
            else:
                set = nodes.union(set)

            ##now, update the geometries:
            # draw atoms with bonds and without bonds
            if len(set)==0:
                labelGeom.Set(vertices=[], labels=[], tagModified=False)
                mol.geomContainer.atoms[geomName] = set
                return

            # 1st lines need to store the wole set in the
            # mol.geomContainer.atoms['lines'] because of the picking.
            mol.geomContainer.atoms[geomName] = set
            propLabels = [""]*len(set)
            try:
                func = evalString(function)
            except:
                self.warningMsg("Error occured while evaluating the expression")
                return
            if lambdaFunc == 1:
                try:
                    newPropLabels = map(func, set)
                except KeyError:
                    msg= "all nodes do not have such a property"
                    self.warningMsg(msg)
                    newPropLabels =list("?"*len(nodes))

            else:
                try:
                    newPropLabels = func(nodes)
                except KeyError:
                    msg= "all nodes do not have such a property"
                    self.warningMsg(msg)
                    newPropLabels =list("?"*len(nodes))

            assert len(newPropLabels) == len(propLabels)
            for i in range(len(newPropLabels)):
                item = newPropLabels[i]
                if format:
                    try:
                        item = format%newPropLabels[i]
                    except:
                        item = str(newPropLabels[i])
                else:
                    item = str(newPropLabels[i])
                if propLabels[i] =="" :
                    propLabels[i] = propLabels[i]+item
                else:
                    propLabels[i] = propLabels[i]+";"+item
            propLabels=tuple(propLabels)

            propCenters=[]    
            for item in set:
                z = item.findType(Atom)
                if location=='First':
                    z=z[0]
                    zcoords = Numeric.array(z.coords)
                    zcoords = zcoords+0.2
                    zcoords = zcoords.tolist()
                    propCenters.append(zcoords)
                elif location=='Center':
                    zcoords = Numeric.array(z.coords)
                    zcoords = Numeric.sum(zcoords)/(len(zcoords)*1.0)
                    zcoords = zcoords.tolist()
                    propCenters.append(zcoords)
                if location=='Last':
                    z=z[-1]
                    zcoords = Numeric.array(z.coords)
                    zcoords = zcoords+0.2
                    zcoords = zcoords.tolist()
                    propCenters.append(zcoords)
            propCenters = tuple(propCenters)
            colors = (materials,)
            labelGeom.Set(labels = propLabels,
                          vertices = propCenters,
                          materials = colors, font = font, visible = 1,
                          tagModified=False)
Exemplo n.º 4
0
        def drawLabels(mol, nodes, materials, function, lambdaFunc,
                       font, location, only, negate, format):
            #font = 'glut'+ font
            geomName = nodes[0].__class__.__name__+'Labels'
            labelGeom = mol.geomContainer.geoms[geomName]
            set = mol.geomContainer.atoms[geomName]
            if negate:
                if len(set):
                    set = set - nodes
            ##if only or there were no labels, label current atms 
            elif only or not len(set):
                set = nodes
            ##not negate, not only and some previous labels, 
            ##  label union of old + new
            else:
                set = nodes.union(set)

            ##now, update the geometries:
            # draw atoms with bonds and without bonds
            if len(set)==0:
                labelGeom.Set(vertices=[], labels=[], tagModified=False)
                mol.geomContainer.atoms[geomName] = set
                return

            # 1st lines need to store the wole set in the
            # mol.geomContainer.atoms['lines'] because of the picking.
            mol.geomContainer.atoms[geomName] = set
            propLabels = [""]*len(set)
            try:
                func = evalString(function)
            except:
                self.warningMsg("Error occured while evaluating the expression")
                return
            if lambdaFunc == 1:
                try:
                    newPropLabels = map(func, set)
                except KeyError:
                    msg= "all nodes do not have such a property"
                    self.warningMsg(msg)
                    newPropLabels =list("?"*len(nodes))

            else:
                try:
                    newPropLabels = func(nodes)
                except KeyError:
                    msg= "all nodes do not have such a property"
                    self.warningMsg(msg)
                    newPropLabels =list("?"*len(nodes))

            assert len(newPropLabels) == len(propLabels)
            for i in range(len(newPropLabels)):
                item = newPropLabels[i]
                if format:
                    try:
                        item = format%newPropLabels[i]
                    except:
                        item = str(newPropLabels[i])
                else:
                    item = str(newPropLabels[i])
                if propLabels[i] =="" :
                    propLabels[i] = propLabels[i]+item
                else:
                    propLabels[i] = propLabels[i]+";"+item
            propLabels=tuple(propLabels)

            propCenters=[]    
            for item in set:
                z = item.findType(Atom)
                if location=='First':
                    z=z[0]
                    zcoords = Numeric.array(z.coords)
                    zcoords = zcoords+0.2
                    zcoords = zcoords.tolist()
                    propCenters.append(zcoords)
                elif location=='Center':
                    n = int(len(z)/2.)
                    z=z[n]
                    zcoords = Numeric.array(z.coords)
                    zcoords = zcoords+0.2
                    #zcoords = Numeric.sum(zcoords)/(len(zcoords)*1.0)
                    zcoords = zcoords.tolist()
                    propCenters.append(zcoords)
                if location=='Last':
                    z=z[-1]
                    zcoords = Numeric.array(z.coords)
                    zcoords = zcoords+0.2
                    zcoords = zcoords.tolist()
                    propCenters.append(zcoords)
            propCenters = tuple(propCenters)
            colors = (materials,)
            labelGeom.Set(labels = propLabels,
                          vertices = propCenters,
                          materials = colors, font = font, visible = 1,
                          tagModified=False)