Esempio n. 1
0
class MultiSelectionListSkeleton:
 
  def __init__(self, parent, selectionList, selectionDict = {}, selectedItems = [], title = 'MultiSelect', text = 'MultiSelect', endText = None, dismissText = 'dismiss', urlFile = None, modal = False):
  
    self.selectionList = selectionList
    self.selectionDict = selectionDict
    self.selectedItems = selectedItems
    self.text = text
    self.endText = endText
    self.dismissText = dismissText
    self.isSelectedList = None
    
    self.setUrlFile(urlFile)
    
    self.startBasePopup(parent,title,modal,True)
    
  def startBasePopup(self,parent,title,modal,True):
  
    pass
     
  def setUrlFile(self,urlFile):
  
    self.help_url = None
 
  def body(self, master):
    
    #
    # Popup window
    #

    row = 0
    label = Label(master, text= self.text)
    label.grid(row=row, column=0, sticky=Tkinter.EW)

    row = row + 1
    self.multiSelect = ScrolledListbox(master,
                                       width = 50,
	                                      height = 5,
	                                      selectmode = Tkinter.MULTIPLE,
                                       initial_list = self.selectionList)
    self.multiSelect.grid(row=row, column=0, sticky=Tkinter.E, ipadx = 20)
    master.grid_columnconfigure(0, weight=1)
    master.grid_rowconfigure(row, weight=1)
    
    if self.selectedItems:
      self.multiSelect.setSelectedItems(self.selectedItems)
 
    if self.endText:
      row = row + 1
      label = Label(master, text= self.endText)
      label.grid(row=row, column=0, sticky=Tkinter.EW)
 
    row = row + 1
    texts = [ 'OK' ]
    commands = [ self.ok ]   # This calls 'ok' in BasePopup, this then calls 'apply' in here
    buttons = createDismissHelpButtonList(master, texts=texts, commands=commands, dismiss_text = self.dismissText, help_url=self.help_url)
    buttons.grid(row=row, column=0)
   

  def apply(self):
    
    self.isSelectedList = []
    
    for selectedItem in self.multiSelect.getSelectedItems():
    
      if self.selectionDict.has_key(selectedItem):
        self.isSelectedList.append(self.selectionDict[selectedItem])
      else:
        self.isSelectedList.append(selectedItem)
        
    return True
Esempio n. 2
0
class WriteMappingPopup(BasePopup):
 
  help_url = joinPath(getHelpUrlDir(),'WriteMapping.html')

  def __init__(self, parent, project):

    self.project = project
    self.selectedFormats = []
    self.defaultText = 'Select file'
    
    self.formats = allFormatsDict.keys()
    self.formats.sort()
     
    BasePopup.__init__(self, parent=parent, title= "Project '%s': " % project.name +  'Write ccpNmr mapping file', modal=False, transient=True)

  def body(self, master):
      
    row = 0
    
    label = Label(master, text= "CcpNmr resonance -> atom mapping file writer.")
    label.grid(row=row, column=0, columnspan = 2, sticky=Tkinter.W)
    
    row += 1
    
    label = Label(master, text= "File formats:")
    label.grid(row=row, column=0, sticky=Tkinter.W)

    self.formatListBox = ScrolledListbox(master, width = 50, height = 5, selectmode = Tkinter.MULTIPLE,
                                       initial_list = self.formats)
    self.formatListBox.grid(row=row, column=1, sticky=Tkinter.EW)
    
    # Default is all formats selected...
    self.formatListBox.setSelectedItems(self.formatListBox.getItems())

    row += 1
    
    label = Label(master, text= "Mapping output file:")
    label.grid(row=row, column=0, sticky=Tkinter.W)

    self.fileButton = Tkinter.Button(master, text = self.defaultText, command = self.selectFile)
    self.fileButton.grid(row=row, column=1, sticky=Tkinter.W)

    row += 1

    texts = [ 'Write mapping' ]
    commands = [ self.ok ]   # This calls 'ok' in BasePopup, this then calls 'apply' in here
    buttons = createDismissHelpButtonList(master, texts=texts, commands=commands, help_url=self.help_url)
    buttons.grid(row=row, columnspan = 2, column=0)

  def selectFile(self):
   
    fileName = self.fileButton.__getitem__('text')
    
    if fileName == self.defaultText:
      fileName = 'ccpNmr.map'
    
    popup = FormatFilePopup(self, file = fileName, component = 'mapping', format = ccpNmr_kw)
    
    if popup.fileSelected:
    
      self.fileButton.config(text = popup.file)      
      popup.destroy()

  def apply(self):
    
    self.selectedFormats = self.formatListBox.getSelectedItems()
    
    fileName = self.fileButton.__getitem__('text')
    
    if fileName == self.defaultText:
      return False
    
    fileCreated = writeMappingFile(self.project,fileName,originalFormats = self.selectedFormats)
    
    if fileCreated:
      showInfo("Success","Succesfully wrote mapping file")
    else:
      showError("Not written","Error writing file %s. File not written" % fileName)
      return False
          
    return True