Ejemplo n.º 1
0
class CommandDialog(QDialog):
    
    def __init__(self, command=None, parent=None):
        QDialog.__init__(self)
        self.ui = Ui_CommandDialog()
        self.ui.setupUi(self)
        
        self.ui.namesView.setModel(QStringListModel(self))
        
        self.ui.commandEdit.textChanged.connect(self.parseNames)
        #self.ui.nameEdit.textChanged.connect(self.activate)
        #self.ui.addButton.clicked.connect(self.addName)
        #self.ui.deleteButton.clicked.connect(self.deleteName)
        self.ui.deleteButton.setVisible(False)
        self.ui.addButton.setVisible(False)
        self.ui.nameEdit.setVisible(False)
        
        if command:
            self.ui.commandEdit.setText(command.command)
            self.ui.infoEdit.setText(command.info)
        
    @property
    def command(self):
        return CommandTemplate(unicode(self.ui.commandEdit.text()), 
                               unicode(self.ui.infoEdit.toPlainText()),
                               map(unicode, self.ui.namesView.model().\
                                        stringList()))
    
    #def activate(self, text):
        #state = False
        #if len(text) > 0:
            #state = True
        #self.ui.addButton.setEnabled(state)
        #self.ui.deleteButton.setEnabled(state)
    
    #def addName(self):
        #model = self.ui.namesView.model()
        #model.insertRows(0, 1)
        #model.setData(model.createIndex(0, 0), QVariant(
                #self.ui.nameEdit.text()))
        
    #def deleteName(self):
        #model = self.ui.namesView.model()
        #model.removeRows(self.ui.namesView.currentIndex().row(), 1)
    
    def parseNames(self, text):
        try:
            names = [FIELDNAME(token) for token in unicode(text).\
                    _formatter_parser() if FIELDNAME(token) is not None and
                    len(FIELDNAME(token))]
        # einzelne "{" oder "}"; beim Tippen tritt das logischer Weise auf
        except ValueError:
            pass
        else:
            # doppelte Einträge elemenieren
            #self.ui.namesView.model().setStringList(list(set(map(unicode,            
                    #self.ui.namesView.model().stringList())) | set(names)))
            self.ui.namesView.model().setStringList(list(set(names)))
Ejemplo n.º 2
0
 def __init__(self, command=None, parent=None):
     QDialog.__init__(self)
     self.ui = Ui_CommandDialog()
     self.ui.setupUi(self)
     
     self.ui.namesView.setModel(QStringListModel(self))
     
     self.ui.commandEdit.textChanged.connect(self.parseNames)
     #self.ui.nameEdit.textChanged.connect(self.activate)
     #self.ui.addButton.clicked.connect(self.addName)
     #self.ui.deleteButton.clicked.connect(self.deleteName)
     self.ui.deleteButton.setVisible(False)
     self.ui.addButton.setVisible(False)
     self.ui.nameEdit.setVisible(False)
     
     if command:
         self.ui.commandEdit.setText(command.command)
         self.ui.infoEdit.setText(command.info)