Exemplo n.º 1
0
    def buildFormDescr(self, formName):
        if formName == "Vectfield":
            ifd = InputFormDescr(title="Choose Vect Field")
            vectList = []
            for key in self.vf.vectfield.keys():
                vectList.append((key, None))
            ifd.append({
                'widgetType': ListChooser,
                'name': 'vectObj',
                'wcfg': {
                    'title': 'Pick grid',
                    'entries': vectList,
                    'mode': 'single',
                    'lbwcfg': {
                        'height': 4
                    },
                },
                'gridcfg': {
                    'sticky': 'wens',
                    'column': 100,
                    'rowspan': 10
                }
            })

            return ifd
Exemplo n.º 2
0
def test_scrolledText():
    descr = InputFormDescr(title="Testing ScrolledText")
    descr.append({
        'widgetType': Pmw.ScrolledText,
        'name': 'sText',
        'defaultValue': """DEFAULT TEXT""",
        'wcfg': {
            'labelpos': 'n',
            'label_text': 'ScrolledText with headers',
            'usehullsize': 1,
            'hull_width': 400,
            'hull_height': 300,
            'text_wrap': 'none',
            'text_padx': 4,
            'text_pady': 4,
        },
        'gridcfg': {
            'sticky': 'wens'
        }
    })

    form = InputForm(master, root, descr, modal=0, blocking=0)
    values = form.testForm()
    if not values['sText'] == 'DEFAULT TEXT\n':
        raise RuntimeError
    form.destroy()
def test_thumbwheel():
    def tw_cb(event=None):
        pass
    from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel
    descr = InputFormDescr(title = 'Testing InputForm')
    descr.append({'name':'thumbwheel',
                  'widgetType':ThumbWheel,
                  'tooltip':"""Right click on the widget will display the control
                  panel and you can type a value manually""",
                  'defaultValue':100,
                  'wcfg':{'text':None,
                          'showLabel':1, 'width':100,
                          'min':0,
                          'lockBMin':1,
                          'lockBMax':1,
                          'lockBIncrement':1,
                          'value':40,
                          'oneTurn':1000,
                          'type':'int',
                          'increment':2,
                          'canvascfg':{'bg':'red'},
                          'wheelLabcfg1':{'font':(ensureFontCase('times'),14,'bold')},
                          'wheelLabcfg2':{'font':(ensureFontCase('times'),14,'bold')},
                          'callback':tw_cb,
                          'continuous':1, 'wheelPad':1, 'height':20},
                  'gridcfg':{'sticky':'e','row':-1}})
    
    form = InputForm(master, root, descr)
    value = form.testForm()
    assert value['thumbwheel']==100
    form.destroy() 
Exemplo n.º 4
0
    def guiCallback(self, event=None):
        """called each time the 'Delete Selected Atoms' button is pressed"""
        z = self.vf.getSelection()
        if z:
            ats = z.findType(Atom)


##             if self.vf.userpref['Expand Node Log String']['value'] == 0:
##                 self.vf.deleteAtomSet.nodeLogString = "self.getSelection()"
        else:
            self.vf.warningMsg('no atoms selected')
            return 'ERROR'
        if ats:
            if self.vf.undoCmdStack == []:
                self.doitWrapper(ats, redraw=0)
            else:
                text = """WARNING: This command cannot be undone.
                if you choose to continue the undo list will be reset.
                Do you want to continue?"""

                idf = self.idf = InputFormDescr(title="WARNING")
                idf.append({
                    'widgetType': Tkinter.Label,
                    'wcfg': {
                        'text': text
                    },
                    'gridcfg': {
                        'columnspan': 2,
                        'sticky': 'w'
                    }
                })

                idf.append({
                    'name': 'continueBut',
                    'widgetType': Tkinter.Button,
                    'wcfg': {
                        'text': 'CONTINUE',
                        'command': self.continue_cb
                    },
                    'gridcfg': {
                        'sticky': 'we'
                    }
                })

                idf.append({
                    'name': 'cancelBut',
                    'widgetType': Tkinter.Button,
                    'wcfg': {
                        'text': 'CANCEL',
                        'command': self.cancel_cb
                    },
                    'gridcfg': {
                        'row': -1,
                        'sticky': 'we'
                    }
                })

                self.form = self.vf.getUserInput(idf, modal=0, blocking=0)
                self.form.root.protocol('WM_DELETE_WINDOW', self.cancel_cb)
Exemplo n.º 5
0
    def buildFormDescr(self, formName):

        if not formName == 'showCmds': return
        idf = InputFormDescr(title='Show Commands and Documentation')
        from ViewerFramework.basicCommand import commandslist
        cname = commandslist
        cname.sort()

        idf.append({
            'name': 'cmdList',
            'widgetType': kbScrolledListBox,
            'wcfg': {
                'items': cname,
                'listbox_exportselection': 0,
                'labelpos': 'nw',
                'label_text': 'Loaded commands:',
                'selectioncommand': self.displayCmds_cb,
            },
            'gridcfg': {
                'sticky': 'wesn',
                'columnspan': 1,
                'weight': 20
            }
        })

        idf.append({
            'name': 'doclist',
            'widgetType': kbScrolledListBox,
            'wcfg': {
                'items': [],
                'listbox_exportselection': 0,
                #'listbox_selectmode':'extended',
                'labelpos': 'nw',
                'labelmargin': 0,
                'label_text': 'DOCUMENTATION',
                'listbox_width': 30
            },
            'gridcfg': {
                'sticky': 'wesn',
                'row': -1,
                'columnspan': 1,
                'weight': 20
            }
        })

        idf.append({
            'name': 'dismiss',
            'widgetType': Tkinter.Button,
            'wcfg': {
                'text': 'DISMISS',
                'command': self.dismiss_cb,
            },
            'gridcfg': {
                'sticky': 'ew',
                'columnspan': 3
            }
        })

        return idf
Exemplo n.º 6
0
    def guiCallback(self):
        ifd = InputFormDescr(title='Show/Hide VFGUI components ')
        for name in ['infoBar', 'MESSAGE_BOX']:
            w = self.getWidget(name)
            var = Tkinter.IntVar()
            self.tkvarDict[name] = var
            cb = CallBackFunction(self.callback, name, var)
            ifd.append({
                'widgetType': Tkinter.Checkbutton,
                'name': name,
                'wcfg': {
                    'text': name,
                    'command': cb,
                    'variable': var,
                },
                'defaultValue': w.winfo_ismapped(),
                'gridcfg': {
                    'sticky': Tkinter.W
                }
            })

        posy = 0
        for name in self.vf.GUI.menuBars.keys():
            w = self.getWidget(name)
            var = Tkinter.IntVar()
            self.tkvarDict[name] = var
            cb = CallBackFunction(self.callback, name, var)
            ifd.append({
                'widgetType': Tkinter.Checkbutton,
                'name': name,
                'wcfg': {
                    'text': name,
                    'command': cb,
                    'variable': var,
                },
                'defaultValue': w.winfo_ismapped(),
                'gridcfg': {
                    'sticky': Tkinter.W,
                    'column': 1,
                    'row': posy
                }
            })
            posy = posy + 1

        ifd.append({
            'widgetType': Tkinter.Button,
            'name': 'dismiss',
            'wcfg': {
                'text': 'dismiss',
                'command': self.dismiss_cb
            },
            'gridcfg': {
                'columnspan': 2
            },
        })
        self.ifd = ifd
        val = self.vf.getUserInput(ifd, modal=0)
Exemplo n.º 7
0
    def buildFormDescr(self, formName):

        if not formName == 'Show MailingLists':
            return
        idf = InputFormDescr(title='Show MailingLists')
        self.mailinglists_pages = ["Login Page", "Archive Page"]
        idf.append({
            'name': 'pmvlist',
            'widgetType': kbScrolledListBox,
            'wcfg': {
                'items': self.mailinglists_pages,
                'listbox_exportselection': 0,
                'labelpos': 'nw',
                'label_text': 'Pmv Mailing List',
                'selectioncommand': self.mailCmds_cb,
                'listbox_height': 3,
                #'hscrollmode':'dynamic',
            },
            'gridcfg': {
                'sticky': 'wesn',
                'columnspan': 1
            }
        })

        idf.append({
            'name': 'visionlist',
            'widgetType': kbScrolledListBox,
            'wcfg': {
                'items': self.mailinglists_pages,
                'listbox_exportselection': 0,
                'labelpos': 'nw',
                'label_text': 'Vision Mailing List',
                'selectioncommand': self.mailCmds_cb,
                'listbox_height': 3,
                #'hscrollmode':'dynamic',
            },
            'gridcfg': {
                'sticky': 'wesn',
                'columnspan': 1
            }
        })
        idf.append({
            'name': 'dismiss',
            'widgetType': Tkinter.Button,
            'wcfg': {
                'text': 'DISMISS',
                'command': self.dismiss_cb,
            },
            'gridcfg': {
                'sticky': 'ew',
                'columnspan': 3
            }
        })
        return idf
def test_inputform_groupwidgetsdefault():
    descr = InputFormDescr(title = 'Testing InputForm')
    descr.append({'name':'group',
                  'widgetType':Tkinter.Radiobutton,
                  'listtext':['rb1', 'rb2', 'rb3'],
                  'defaultValue':'rb3',
                  'gridcfg':{'sticky':'w'}})
    
    form = InputForm(master, root, descr)
    value = form.testForm()
    assert value['group']=='rb3'
    form.destroy() 
def test_inputForm_notebook():
    descr = InputFormDescr(title = 'Testing InputForm')
    descr.append({'widgetType':Pmw.NoteBook,
                  'name':'notebook',
                  'container':{'Page1':"w.page('Page1')",
                               'Page2':"w.page('Page2')",
                               'Page3':"w.page('Page3')"},
                  'wcfg':{'borderwidth':3},
                  'componentcfg':[{'name':'Page1', 'cfg':{}},
                                  {'name':'Page2', 'cfg':{}},
                                  {'name':'Page3', 'cfg':{}}],
                  'gridcfg':{'sticky':'wnse'}
                  })

    entries = [('Chocolate',None), ('Vanilla', None), ('Strawberry', None),
               ('Coffee',None), ('Pistachio', None), ('Rasberry',None),
               ]

    descr.append({'name':'listchooser',
                  'parent':'Page1',
                  'widgetType':ListChooser,
                  'defaultValue':'Chocolate',
                  'wcfg':{'entries':entries},
                  'gridcfg':{'sticky':'w'}
                  })
    
    descr.append({'name':'radioselect2',
                  'widgetType':Pmw.RadioSelect,
                  'parent':'Page2',
                  'listtext':['rb1', 'rb2', 'rb3','rb4', 'rb5', 'rb6',
                              'rb7', 'rb8', 'rb9','rb10', 'rb11', 'rb12'],
                  'wcfg':{'labelpos':'n',
                          'label_text':'Radiobuttons: ',
                          'orient':'horizontal',
                          'buttontype':'radiobutton'},
                  'gridcfg':{'sticky':'w'} })

    descr.append({'name':'radioselect',
                  'widgetType':Pmw.RadioSelect,
                  'parent':'Page3',
                  'defaultValue':'rb5',
                  'listtext':['rb1', 'rb2', 'rb3','rb4', 'rb5', 'rb6',
                              'rb7', 'rb8', 'rb9','rb10', 'rb11', 'rb12'],
                  'wcfg':{'labelpos':'n',
                          'label_text':'Radiobuttons: ',
                          'orient':'vertical',
                          'buttontype':'radiobutton'},
                  'gridcfg':{'sticky':'w'} })
    form = InputForm(master, root, descr, modal=0, blocking=0)
    values = form.testForm(container='Page3')
    assert values['radioselect']=='rb5'
    form.destroy() 
Exemplo n.º 10
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']
Exemplo n.º 11
0
    def buildFormDescr(self, formName):

        if formName == 'chooseCitation':
            idf = InputFormDescr(title="Choose Package")
            pname = self.citations.keys()
            #pname.sort()
            idf.append({
                'name': 'packList',
                'widgetType': Pmw.ScrolledListBox,
                'wcfg': {
                    'items': pname,
                    'listbox_exportselection': 0,
                    'labelpos': 'nw',
                    'usehullsize': 1,
                    'hull_width': 100,
                    'hull_height': 150,
                    'listbox_height': 5,
                    'listbox_width': 150,
                    'label_text': 'Select a package:',
                    'selectioncommand': self.displayCitation_cb,
                },
                'gridcfg': {
                    'sticky': 'wesn'
                }
            })

            idf.append({
                'name': 'citation',
                'widgetType': Pmw.ScrolledText,
                'wcfg': {
                    'labelpos': 'nw',
                    'text_width': 60,
                    'text_height': 10
                },
                'gridcfg': {
                    'sticky': 'wens'
                }
            })
            idf.append({
                'name': 'dismiss',
                'widgetType': Tkinter.Button,
                'wcfg': {
                    'text': 'DISMISS',
                    'command': self.dismiss_cb,
                },
                'gridcfg': {
                    'sticky': 'wens'
                }
            })
            return idf
Exemplo n.º 12
0
    def guiCallback(self):
        """called each time the 'Delete All Molecules' button is pressed"""
        if len(self.vf.Mols) == 0:
            self.warningMsg("No molecules present in the Viewer")
            return
        mols = self.vf.Mols
        if mols is not None and len(mols):
            text = """WARNING: This command cannot be undone.
            if you choose to continue the undo list will be reset.
            Do you want to continue?"""
            if not hasattr(self, 'idf'):
                self.idf = InputFormDescr(title="WARNING")
                self.idf.append({
                    'widgetType': Tkinter.Label,
                    'wcfg': {
                        'text': text
                    },
                    'gridcfg': {
                        'columnspan': 3,
                        'sticky': 'w'
                    }
                })

                self.idf.append({
                    'name': 'Continue Button',
                    'widgetType': Tkinter.Button,
                    'wcfg': {
                        'text': 'CONTINUE',
                        'command': self.continue_cb
                    },
                    'gridcfg': {
                        'sticky': 'we'
                    }
                })

                self.idf.append({
                    'name': 'Cancel Button',
                    'widgetType': Tkinter.Button,
                    'wcfg': {
                        'text': 'CANCEL',
                        'command': self.cancel_cb
                    },
                    'gridcfg': {
                        'row': -1,
                        'sticky': 'we'
                    }
                })
            self.vf.getUserInput(self.idf, okcancel=0)
Exemplo n.º 13
0
 def buildFormDescr(self, formName):
     if formName == 'template':
         idf = self.idf = InputFormDescr(title=self.name)
         # append to idf here
         idf.append({
             'name': 'template',
             'widgetType': tkinter.Button,
             'wcfg': {
                 'text': 'template button label'
             },
             'gridcfg': {
                 'sticky': 'we'
             }
         })
         # only return idf for template
         return idf
Exemplo n.º 14
0
 def buildFormDescr(self, formName):
     if formName == 'display':
         idf = InputFormDescr(title=self.name)
         idf.append({
             'name': 'display',
             'widgetType': Pmw.RadioSelect,
             'listtext': ['display', 'display only', 'undisplay'],
             'defaultValue': 'display',
             'wcfg': {
                 'orient': 'horizontal',
                 'buttontype': 'radiobutton'
             },
             'gridcfg': {
                 'sticky': 'we'
             }
         })
         return idf
Exemplo n.º 15
0
    def buildFormDescr(self, formName):
        if formName == 'saveViewsToFile':
            if self.vf.commands.has_key("viewsPanel"):
                if len(self.vf.viewsPanel.views) == 0:
                    return
            else:
                return
            idf = InputFormDescr(title="Save Views to file")
            idf.append({
                'name': 'filename',
                'widgetType': Pmw.EntryField,
                'tooltip':
                "Enter the filename, a 'filename_oprient.py' (saves orientation)\nand 'filename_repr.db'(saves representation) will be created.",
                'wcfg': {
                    'label_text': 'Filename:',
                    'labelpos': 'w'
                },
                'gridcfg': {
                    'sticky': 'we'
                },
            })

            idf.append({
                'widgetType': SaveButton,
                'name': 'filebrowse',
                'wcfg': {
                    'buttonType':
                    Tkinter.Button,
                    'title':
                    'Save In File ...',
                    'types': [('Views orientation', '*_orient.py'),
                              ('Views representation', '*_repr.db'),
                              ("", '*')],
                    'callback':
                    self.setEntry_cb,
                    'widgetwcfg': {
                        'text': 'BROWSE'
                    }
                },
                'gridcfg': {
                    'row': -1,
                    'sticky': 'we'
                }
            })

            return idf
Exemplo n.º 16
0
    def buildInputFormDescr(self):
        """to be implemented by sub-class"""

        ifd = InputFormDescr()
        ifd.title = "MSMSsel picker"
        ifd.append({
            'widgetType': Tkinter.Label,
            'name': 'event',
            'wcfg': {
                'text': 'event: ' + self.event
            },
            'gridcfg': {
                'sticky': Tkinter.W
            }
        })
        ifd.append({
            'widgetType': Pmw.EntryField,
            'name': 'Surface',
            'wcfg': {
                'labelpos': 'w',
                'label_text': 'Surface name: ',
                'validate': None
            },
            'gridcfg': {
                'sticky': 'we'
            }
        })
        ifd.append({
            'widgetType': Tkinter.Button,
            'name': 'Cancel',
            'wcfg': {
                'text': 'Cancel',
                'command': self.Cancel
            }
        })

        if self.numberOfObjects == None:
            ifd.append({
                'widgetType': Tkinter.Button,
                'wcfg': {
                    'text': 'Done'
                },
                'command': self.stop
            })
        return ifd
Exemplo n.º 17
0
    def buildFormDescr(self, formName):
        if formName == "saveBspt":
            entries = self.vf.SL.setdict.keys()
            idf = self.idf = InputFormDescr(title="Save Bspt in file")
            idf.append({
                'widgetType': Pmw.ScrolledListBox,
                'name': 'BsptList',
                'wcfg': {
                    'items': entries,
                    'labelpos': 'n',
                    'label_text': "Select a BSPT"
                },
                'gridcfg': {
                    'sticky': 'we',
                    'columnspan': 2
                }
            })
            idf.append({
                'widgetType': Tkinter.Button,
                'wcfg': {
                    'text': 'OK',
                    'relief': Tkinter.RAISED,
                    'borderwidth': 2,
                    'command': self.select_cb
                },
                'gridcfg': {
                    'sticky': 'we',
                },
            })

            idf.append({
                'widgetType': Tkinter.Button,
                'wcfg': {
                    'text': 'Cancel',
                    'relief': Tkinter.RAISED,
                    'borderwidth': 3,
                    'command': self.cancel_cb
                },
                'gridcfg': {
                    'sticky': 'we',
                    'row': -1
                },
            })

            return idf
Exemplo n.º 18
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)
Exemplo n.º 19
0
    def doit(self, trajFile, ask=True):
        """creates a Trajectory object, uses its parser to read the trajectory file,
        adds created Trajectory object to self.vf.Trajectories dictionary"""
        
        name = os.path.split(trajFile)[1]
        trajnames = self.vf.Trajectories.keys()
        if name in trajnames:
            if ask:
                from mglutil.gui.InputForm.Tk.gui import InputFormDescr
                ifd = InputFormDescr(title = '')
                ifd.append({'widgetType':Pmw.EntryField,
                            'name':'newtraj',
                            'required':1,
                            'wcfg':{'labelpos':'w',
                                    'label_text': "Trajectory %s exists.\nEnter new name:"%(name,),
                                    'validate':None},
                            'gridcfg':{'sticky':'we'}
                            })

                vals = self.vf.getUserInput(ifd)
                if len(vals)>0:
                    assert not vals['newtraj'] in trajnames
                    name = vals['newtraj']
                else:
                    return None
            else:
                name = name+str(len(trajnames))
        trj = Trajectory(trajFile)
        if trj.parser:
            trj.readTrajectory()

            self.vf.Trajectories[name] = trj
            if self.vf.commands.has_key("playTrajectory"):
                if self.vf.playTrajectory.ifd:
                    cb = self.vf.playTrajectory.ifd.entryByName['trs']['widget']
                    sl = cb.component('scrolledlist')
                    trajnames = self.vf.Trajectories.keys()
                    sl.setlist(trajnames)
                    cb.selectitem(name)
            return name
        else: return None
Exemplo n.º 20
0
 def buildFormDescr(self, formName):
     if formName == "enterName":
         ifd = InputFormDescr(title="Pick Vect Name")
         vectNames = self.vf.vectfield.keys()
         ifd.append({
             'widgetType': Pmw.ComboBox,
             'name': 'vectName',
             'required': 1,
             'tooltip':
             "Please type-in a new name or chose one from the list below\n '_' are not accepted",
             'wcfg': {
                 'labelpos': 'nw',
                 'label_text': 'VectField Name: ',
                 'entryfield_validate': self.entryValidate,
                 'scrolledlist_items': vectNames,
             },
             'gridcfg': {
                 'sticky': 'we'
             }
         })
         return ifd
Exemplo n.º 21
0
 def buildInputFormDescr(self):
     ifd = InputFormDescr()
     all = self.allChoices()
     if len(all) > 0:
         ifd.append({
             'widgetType': 'ListChooser',
             'name': 'AllObjects',
             'entries': all,
             'title': 'All objects',
             'wcfg': {
                 'mode': 'multiple'
             },
         })
     if self.numberOfObjects == None:
         ifd.append({
             'widgetType': Tkinter.Button,
             'wcfg': {
                 'text': 'Done'
             },
             'command': self.stop
         })
     return ifd
Exemplo n.º 22
0
def createDescr():
    descr = InputFormDescr(title = 'Testing InputForm')
    descr.append({'name':'checkbutton',
                  'widgetType':Tkinter.Checkbutton,
                  'wcfg':{'text':'Checkbutton',
                          'variable':Tkinter.IntVar()},
                  'gridcfg':{'sticky':'w'}})
    

    descr.append({'name':'radioselect',
                'widgetType':Pmw.RadioSelect,
                'listtext':['rb1', 'rb2', 'rb3','rb4', 'rb5', 'rb6',
                            'rb7', 'rb8', 'rb9','rb10', 'rb11', 'rb12'],
                'wcfg':{'labelpos':'n',
                        'label_text':'Radiobuttons: ',
                        'orient':'vertical',
                        'buttontype':'radiobutton'},
                'gridcfg':{'sticky':'w'} })

    descr.append({'name':'radioselect2',
                'widgetType':Pmw.RadioSelect,
                'listtext':['rb1', 'rb2', 'rb3','rb4', 'rb5', 'rb6',
                            'rb7', 'rb8', 'rb9','rb10', 'rb11', 'rb12'],
                'wcfg':{'labelpos':'n',
                        'label_text':'Radiobuttons: ',
                        'orient':'horizontal',
                        'buttontype':'radiobutton'},
                'gridcfg':{'sticky':'w'} })
    entries = [('Chocolate',None), ('Vanilla', None), ('Strawberry', None),
               ('Coffee',None), ('Pistachio', None), ('Rasberry',None),
               ]

    descr.append({'name':'listchooser',
                  'widgetType':ListChooser,
                  'wcfg':{'entries':entries},
                  'gridcfg':{'sticky':'w'}
                  })
    
    return descr
Exemplo n.º 23
0
 def guiCallback(self):
     if not self.form:
         idf = self.idf = InputFormDescr(title="Views")
         idf.append({
             'name': 'viewsContainer',
             'widgetType': Pmw.Group,
             'container': {
                 'viewsContainer': "w.interior()"
             },
             'wcfg': {
                 'ring_borderwidth': 2,
                 'tag_pyclass': None,  #Tkinter.Button,
                 #'tag_text':'Save view',
                 #'tag_command': self.saveView
             },
             'gridcfg': {
                 'sticky': 'we',
                 'columnspan': 1
             }
         })
         idf.append({
             'widgetType': Tkinter.Button,
             'wcfg': {
                 'text': "Save View",  #'Close',
                 "width": 40,
                 'command': self.saveView  #self.dismissForm
             }
         })
         self.form = self.vf.getUserInput(self.idf, modal=0, blocking=0)
     else:
         self.form.deiconify()
     # place the form below the viewer (so that the form does not get into a saved image if
     # the user decides to save the view).
     x = self.form.master.winfo_x()
     y = self.form.master.winfo_y()
     w = self.form.master.winfo_width()
     h = self.form.master.winfo_height()
     self.form.root.geometry("+%d+%d" % (x + w / 2, y + h))
Exemplo n.º 24
0
 def buildForm(self):
     ifd = self.ifd = InputFormDescr(title="Selection level:")
     levelLabels = [
         'Molecule      ', 'Chain           ', 'Residue       ',
         'Atom           '
     ]
     self.levelVar.set("Molecule")
     for level, levlabel in zip(levels, levelLabels):
         ifd.append({
             'name': level,
             'widgetType': Tkinter.Radiobutton,
             'wcfg': {
                 'text': levlabel,
                 'variable': self.levelVar,
                 'value': level,
                 'justify': 'left',
                 'activebackground': self.levelColors[level],
                 'selectcolor': self.levelColors[level],
                 'command': self.setLevel_cb
             },
             'gridcfg': {
                 'sticky': 'we'
             }
         })
     ifd.append({
         'name': 'dismiss',
         'widgetType': Tkinter.Button,
         'defaultValue': 1,
         'wcfg': {
             'text': 'Dismiss',
             'command': self.Close_cb
         },
         'gridcfg': {
             'sticky': 'we'
         }
     })
     self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0)
     self.form.root.protocol('WM_DELETE_WINDOW', self.Close_cb)
Exemplo n.º 25
0
    def doit(self):
        import thread

        idf = InputFormDescr("Viewerframework server connection!")
        idf.append({'widgetType':Tkinter.Entry,
                    'name': 'host','defaultValue':'localhost',
                    'wcfg':{'label':'Host name or IP'}, 
                    'gridcfg':{'sticky':Tkinter.E}
                   })
        idf.append({'widgetType':Tkinter.Entry,
                    'name': 'port','defaultValue':'50000',
                    'wcfg':{'label':"Server's Port"}, 
                    'gridcfg':{'sticky':Tkinter.E}
                    })
        self.idf = idf
        val = self.vf.getUserInput(idf)
        self.vf.socketComm.connectToServer(val['host'], int(val['port']),
                                           self.vf.server_cb)

        # create a threadsafe command queue
        from Queue import Queue
        self.vf.cmdQueue = Queue(-1) # infinite size
        self.vf.GUI.ROOT.after(10, self.vf.runServerCommands)
Exemplo n.º 26
0
    def editShader(self):
		self.shader_edited= True
		shname = self.form.descr.entryByName['pigment']['widget'].get()	
		shaderP = self.shadDic[shname]
		idf = InputFormDescr(title =shname)
		k=0
		for i in shaderP : 
			W=4
			tmp=i.replace("\"","").split(",")
			P=tmp[0].split(" ")
			V=tmp[1]
			if P[0] == "string" : 
				P[0]="str"
				W=16
			else :	V=eval(V)	
			idf.append({	'name':P[1],
                    			'widgetType':Pmw.EntryField,
                    			'type':eval(P[0]),
                    			'wcfg':{'labelpos':'w',
                        		'label_text':tmp[0],
                            		'validate':'real',
                            		'value':V,
                            		'entry_width':W},
                    			'gridcfg':{'column':0, 'row':k, 'sticky':'w'}})
			k=k+1
      		idf.append({'name':'Set',
                    'widgetType':Tkinter.Button,
                    'wcfg':{'text':'ApplyChange','command': self.SetShader},
                    'gridcfg':{'column':0,
                               'row':k,'sticky':'ew'}})
	        idf.append({'name':'help',
                    'widgetType':Tkinter.Button,
                    'defaultValue':0,
                    'wcfg':{'text':'Help','command': self.helpShader},
                    'gridcfg':{'column':1, 'row':k,'sticky':'ew'}})

		self.formS = self.vf.getUserInput(idf, modal = 0, blocking = 0)
Exemplo n.º 27
0
    def guiCallback(self):
        molNames = []
        for mol in self.vf.Mols:
            if hasattr(mol, 'spaceGroup'):
                molNames.append(mol.name)
        if not molNames:
            tkMessageBox.showinfo(
                "Crystal Info is Needed",
                "No Molecule in the Viewer has Crystal Info.")
            return
        ifd = InputFormDescr(title='Crystal Info')
        ifd.append({
            'name': 'moleculeList',
            'widgetType': Pmw.ScrolledListBox,
            'tooltip': 'Select a molecule with Crystal Info.',
            'wcfg': {
                'label_text': 'Select Molecule: ',
                'labelpos': 'nw',
                'items': molNames,
                'listbox_selectmode': 'single',
                'listbox_exportselection': 0,
                'usehullsize': 1,
                'hull_width': 100,
                'hull_height': 150,
                'listbox_height': 5
            },
            'gridcfg': {
                'sticky': 'nsew',
                'row': 1,
                'column': 0
            }
        })
        val = self.vf.getUserInput(ifd, modal=1, blocking=1)
        if val:
            molecule = self.vf.getMolFromName(val['moleculeList'][0])
            matrices = instanceMatricesFromGroup(molecule)
            geom = molecule.geomContainer.geoms['master']
            geom.Set(instanceMatrices=matrices)
            if not molecule.geomContainer.geoms.has_key('Unit Cell'):
                fractCoords = ((1, 1, 0), (0, 1, 0), (0, 0, 0), (1, 0, 0),
                               (1, 1, 1), (0, 1, 1), (0, 0, 1), (1, 0, 1))
                coords = []
                coords = molecule.crystal.toCartesian(fractCoords)
                box = Box('Unit Cell', vertices=coords)
                self.vf.GUI.VIEWER.AddObject(box, parent=geom)
                molecule.geomContainer.geoms['Unit Cell'] = box
            ifd = InputFormDescr(title='Crystal Options')
            visible = molecule.geomContainer.geoms['Unit Cell'].visible
            if visible:
                showState = 'active'
            else:
                showState = 'normal'
            ifd.append({
                'name': 'Show Cell',
                'widgetType': Tkinter.Checkbutton,
                'text': 'Hide Unit Cell',
                'state': showState,
                'gridcfg': {
                    'sticky': Tkinter.W
                },
                'command': CallBackFunction(self.showUnitCell, molecule)
            })

            ifd.append({
                'name': 'Show Packing',
                'widgetType': Tkinter.Checkbutton,
                'text': 'Hide Packing',
                'state': 'active',
                'gridcfg': {
                    'sticky': Tkinter.W
                },
                'command': CallBackFunction(self.showPacking, molecule)
            })

            val = self.vf.getUserInput(ifd, modal=0, blocking=1)
            if not val:
                geom.Set(instanceMatrices=[numpy.eye(4, 4)])
                molecule.geomContainer.geoms['Unit Cell'].Set(visible=False)
Exemplo n.º 28
0
    def buildFormDescr(self, formName):
        if formName == 'choosecmd':
            cmdNames = filter(lambda x, self=self: self.vf.commands[x].flag &
                              self.objArgOnly,
                              self.vf.commands.keys())
            cmdNames.sort()
            cmdEntries = map(lambda x: (x, None), cmdNames)

            onAddCmds = map(lambda x: x[0], self.vf.onAddObjectCmds)
            cmdToApplyNames = []
            cmdToApplyNames = filter(lambda x, vf=self.vf, onAddCmds=onAddCmds:
                                     vf.commands[x] in onAddCmds,
                                     cmdNames)

            cmdtoapply = map(lambda x: (x, None), cmdToApplyNames)
            idf = InputFormDescr(title="Cmds called after adding an object")
            idf.append({
                'name': 'cmdlist',
                'widgetType': ListChooser,
                'tooltip': """list of the commands loaded so far in the
application which can be applied to the object
when loaded in the application""",
                'wcfg': {
                    'entries': cmdEntries,
                    'mode': 'extended',
                    'lbwcfg': {
                        'exportselection': 0
                    },
                    'title': 'Available commands'
                },
                'gridcfg': {
                    'sticky': 'wens',
                    'row': 0,
                    'column': 0,
                    'rowspan': 3
                }
            })

            idf.append({
                'name': 'add',
                'widgetType': Tkinter.Button,
                'tooltip': """ Add the selected command from to the list
of commands to be applied to the object when loaded in the application""",
                'wcfg': {
                    'text': '>>',
                    'command': self.add_cb
                },
                'gridcfg': {
                    'row': 0,
                    'column': 1,
                    'rowspan': 3
                }
            })

            idf.append({
                'name': 'cmdtoapply',
                'widgetType': ListChooser,
                'tooltip': """list of the commands the user chose to
apply to the object when loaded in the application""",
                'wcfg': {
                    'entries': cmdtoapply,
                    'mode': 'single',
                    'lbwcfg': {
                        'exportselection': 0
                    },
                    'title': 'Commands to be applied'
                },
                'gridcfg': {
                    'sticky': 'we',
                    'row': 0,
                    'column': 2,
                    'rowspan': 3
                }
            })

            idf.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
                }
            })

            idf.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
                }
            })

            idf.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
                }
            })

            return idf
Exemplo n.º 29
0
    def guiCallback(self):
        idf = InputFormDescr(title="Set User Preferences")

        categoryList = ['General']
        for value in self.vf.userpref.values():
            if not value['category'] in categoryList:
                categoryList.append(value['category'])

        widgetType = {
            'widgetType': Pmw.NoteBook,
            'name': 'prefNotebook',
            'container': {},
            'wcfg': {
                'borderwidth': 2
            },
            'componentcfg': [],
            'gridcfg': {
                'sticky': 'we'
            },
        }
        for item in categoryList:
            widgetType['container'][item] = "w.page('" + item + "')"
            widgetType['componentcfg'].append({'name': item, 'cfg': {}})

        idf.append(widgetType)
        for item in categoryList:
            idf.append({
                'name': item + "Group",
                'widgetType': Pmw.Group,
                'parent': item,
                'container': {
                    item + 'Group': 'w.interior()'
                },
                'wcfg': {
                    'tag_text': item
                },
                'gridcfg': {
                    'sticky': 'wne'
                }
            })
        for key, value in self.vf.userpref.items():
            if not self.updateGUI in self.vf.userpref[key]['callbackFunc']:
                self.vf.userpref.addCallback(key, self.updateGUI)
            # put a label to have more space between the widget Maybe
            # could replace it by using the options padx and pady.
            group = value['category'] + "Group"
            idf.append({
                'widgetType': Tkinter.Label,
                'parent': group,
                'wcfg': {
                    'text': ''
                },
                'gridcfg': {
                    'sticky': 'we',
                    'columnspan': 3
                }
            })

            if value.has_key('validValues') and value['validValues']:
                idf.append({
                    'widgetType': Pmw.ComboBox,
                    'parent': group,
                    'name': key,
                    'defaultValue': value['value'],
                    'wcfg': {
                        'label_text': key,
                        'labelpos': 'n',
                        'scrolledlist_items': value['validValues']
                    },
                    'gridcfg': {
                        'sticky': 'wens'
                    }
                })
            else:

                if value.has_key('validateFunc') and value['validateFunc']:

                    def valid(value, func=value['validateFunc']):
                        test = func(value)
                        if test == 1:
                            return Pmw.OK
                        else:
                            return Pmw.PARTIAL

                    idf.append({
                        'widgetType': Pmw.EntryField,
                        'parent': group,
                        'name': key,
                        'wcfg': {
                            'label_text': key,
                            'labelpos': 'n',
                            'value': value['value'],
                            'validate': {
                                'validator': valid
                            }
                        },
                        'gridcfg': {
                            'sticky': 'wens'
                        }
                    })
                else:
                    idf.append({
                        'widgetType': Pmw.EntryField,
                        'parent': group,
                        'name': key,
                        'wcfg': {
                            'label_text': key,
                            'labelpos': 'n'
                        },
                        'gridcfg': {
                            'sticky': 'wens'
                        }
                    })

            idf.append({
                'widgetType': Tkinter.Button,
                'parent': group,
                'wcfg': {
                    'bitmap': 'info',
                    'width': 50,
                    'height': 40,
                    'padx': 10,
                    'command': CallBackFunction(self.info_cb, value['doc'])
                },
                'gridcfg': {
                    'row': -1,
                    'sticky': 'wens'
                }
            })

            idf.append({
                'widgetType': Tkinter.Button,
                'parent': group,
                'wcfg': {
                    'text': 'Make \nDefault',
                    'padx': 10,
                    'command': CallBackFunction(self.default_cb, key)
                },
                'gridcfg': {
                    'row': -1,
                    'sticky': 'wens'
                }
            })

            idf.append({
                'widgetType': Tkinter.Button,
                'parent': group,
                'wcfg': {
                    'text': 'Set',
                    'padx': 10,
                    'height': 2,
                    'width': 5,
                    'command': CallBackFunction(self.set_cb, key)
                },
                'gridcfg': {
                    'row': -1,
                    'sticky': 'wens'
                }
            })

        idf.append({
            'widgetType': Tkinter.Button,
            'wcfg': {
                'text': 'Dismiss',
                'command': self.dismissForm
            },
            'gridcfg': {
                'sticky': 'we',
                'columnspan': 4
            }
        })

        self.form = self.vf.getUserInput(idf, modal=0, blocking=0)
Exemplo n.º 30
0
 def getIfd(self, atNames):
     #cylinders
     if not hasattr(self, 'ifd'):
         ifd = self.ifd = InputFormDescr(
             title='Show Hydrogen Bonds as Cylinders')
         ifd.append({
             'name': 'hbondLabel',
             'widgetType': Tkinter.Label,
             'wcfg': {
                 'text':
                 str(len(atNames)) +
                 ' Atoms in hbonds:\n(1=visible, 0 not visible)'
             },
             'gridcfg': {
                 'sticky': 'wens',
                 'columnspan': 2
             }
         })
         ifd.append({
             'name': 'atsLC',
             'widgetType': ListChooser,
             'wcfg': {
                 'entries': atNames,
                 'mode': 'multiple',
                 'title': '',
                 'command': CallBackFunction(self.showHBondLC, atNames),
                 'lbwcfg': {
                     'height': 5,
                     'selectforeground': 'red',
                     'exportselection': 0,
                     'width': 30
                 },
             },
             'gridcfg': {
                 'sticky': 'wens',
                 'row': 2,
                 'column': 0,
                 'columnspan': 2
             }
         })
         ifd.append({
             'name': 'radii',
             'widgetType': ExtendedSliderWidget,
             'wcfg': {
                 'label': 'radii',
                 'minval': .01,
                 'maxval': 1.0,
                 'immediate': 1,
                 'init': .2,
                 'width': 250,
                 'command': self.update,
                 'sliderType': 'float',
                 'entrypackcfg': {
                     'side': 'right'
                 }
             },
             'gridcfg': {
                 'sticky': 'wens',
                 'columnspan': 2
             }
         })
         ifd.append({
             'name': 'length',
             'widgetType': ExtendedSliderWidget,
             'wcfg': {
                 'label': 'length',
                 'minval': .01,
                 'maxval': 5.0,
                 'immediate': 1,
                 'init': 1.0,
                 'width': 250,
                 'command': self.update,
                 'sliderType': 'float',
                 'entrypackcfg': {
                     'side': 'right'
                 }
             },
             'gridcfg': {
                 'sticky': 'wens',
                 'columnspan': 2
             }
         })
         ifd.append({
             'name': 'changeVertsBut',
             'widgetType': Tkinter.Button,
             'wcfg': {
                 'text': 'Set anchors',
                 'command': self.changeDVerts
             },
             'gridcfg': {
                 'sticky': 'wens'
             }
         })
         ifd.append({
             'name': 'changeColorBut',
             'widgetType': Tkinter.Button,
             'wcfg': {
                 'text': 'Change color',
                 'command': self.changeColor
             },
             'gridcfg': {
                 'sticky': 'wes',
                 'row': -1,
                 'column': 1
             }
         })
         ifd.append({
             'name': 'closeBut',
             'widgetType': Tkinter.Button,
             'wcfg': {
                 'text': 'Dismiss',
                 'command': self.dismiss_cb
             },
             'gridcfg': {
                 'sticky': 'wens',
                 'columnspan': 2
             }
         })