Пример #1
0
 def __init__(self, master):
     ttk.LabelFrame.__init__(self, master, text="Constraints Files")
     self.constraintsFileList = Tk.StringVar()
     self.infoLabelString = Tk.StringVar()
     self.loadFileButton = ttk.Button(self, text=u"Load file",
                                     command=self.loadFile)
     self.removeFileButton = ttk.Button(self, text=u"Remove file",
                                       command=self.removeFile)
     self.constraintsList = ScrolledList(self, listvariable=self.constraintsFileList)
     self.downloadButton = ttk.Button(self, text=u"Download \nfrom PDB",
                                     command=self.downloadRestraintFileWin)
     self.saveButton = ttk.Button(self, text=u'Save File',
                                  command=self.saveFile)
     self.infoLabel = ttk.Label(self, textvariable=self.infoLabelString)
     self.selectedFile = ""
     self.widgetCreation()
     self.NMRCommands = ""  # Must be set by application at run time
     self.mainGUI = ""  # Must be set at run time
Пример #2
0
class FileSelectionPanel(ttk.LabelFrame):
    """This panel allows to import constraint file
    into the Core. Also it allows the selection of the file
    for the following calculations.
    """
    def __init__(self, master):
        ttk.LabelFrame.__init__(self, master, text="Constraints Files")
        self.constraintsFileList = Tk.StringVar()
        self.infoLabelString = Tk.StringVar()
        self.loadFileButton = ttk.Button(self, text=u"Load file",
                                        command=self.loadFile)
        self.removeFileButton = ttk.Button(self, text=u"Remove file",
                                          command=self.removeFile)
        self.constraintsList = ScrolledList(self, listvariable=self.constraintsFileList)
        self.downloadButton = ttk.Button(self, text=u"Download \nfrom PDB",
                                        command=self.downloadRestraintFileWin)
        self.saveButton = ttk.Button(self, text=u'Save File',
                                     command=self.saveFile)
        self.infoLabel = ttk.Label(self, textvariable=self.infoLabelString)
        self.selectedFile = ""
        self.widgetCreation()
        self.NMRCommands = ""  # Must be set by application at run time
        self.mainGUI = ""  # Must be set at run time

    def widgetCreation(self):
        """
        """
        self.constraintsList.listbox.exportselection = 0
        self.constraintsList.grid(row=0, column=1, rowspan=4)
        self.loadFileButton.grid(row=0, column=0)
        self.removeFileButton.grid(row=1, column=0)
        self.downloadButton.grid(row=2, column=0)
        self.saveButton.grid(row=3, column=0)
        self.infoLabel.grid(row=4, column=0, columnspan=2)
        self.constraintsList.bind('<<ListboxSelect>>', self.onStructureSelect)

    def loadFile(self):
        """Use a standard Tk dialog to get filename,
        constraint type is selected prior to the opening of dialog.
        Use the filename to load the constraint file in the Core.
        """
        filename = tkFileDialog.askopenfilename(
            title="Open a constraint file")
        if len(filename):
            self.NMRCommands.loadNOE(filename)
            self.updateFilelist()

    def updateFilelist(self):
        """
        """
        managerList = " ".join(self.NMRCommands.ManagersList.keys()).strip()
        self.constraintsFileList.set(managerList)
        if len(managerList) == 0:
            self.infoLabelString.set('')
        else:
            self.constraintsList.listbox.activate(len(managerList) - 1)

    def removeFile(self):
        """
        """
        toRemove = self.selectedFile
        if toRemove:
            del self.NMRCommands.ManagersList[toRemove]
        self.updateFilelist()

    def saveFile(self):
        """
        """
        toSave = self.selectedFile
        if toSave:
            filename = tkFileDialog.asksaveasfilename(
                title="Save constraint file as", initialfile=toSave)
            if filename is not None:
                self.NMRCommands.saveConstraintsFile(toSave, filename)

    def downloadRestraintFileWin(self):
        """
        """
        pdbCode = tkSimpleDialog.askstring('PDB NMR Restraints',
                                           'Please enter a 4-digit pdb code:',
                                           parent=self)
        if pdbCode:
            infos = self.mainGUI.getInfo()
            self.NMRCommands.downloadFromPDB(pdbCode, infos["urlPDB"])
            self.updateFilelist()

    def onStructureSelect(self, evt):
        """
        """
        # Note here that Tkinter passes an event object
        w = evt.widget
        selection = w.curselection()
        if len(selection) == 1:
            index = int(selection[0])
            self.selectedFile = w.get(index)
            self.infoLabelString.set("Contains " +
                                     str(len(self.NMRCommands.ManagersList[self.selectedFile])) +
                                     " Constraints (" + self.NMRCommands.ManagersList[self.selectedFile].format + ")")

    def getInfo(self):
        """
        """
        if self.selectedFile:
            return {"constraintFile": self.selectedFile}
        else:
            return {"constraintFile": ""}