示例#1
0
 def __init__(self, parent, suite, trait, name='TraitVariablesWindow'):
     BasePaellaWindow.__init__(self, parent, name=name)
     self.resize(500, 600)
     self.initPaellaCommon()
     self.mainView = QScrollView(self, 'TraitVariablesScrollView')
     self.tveditor = TraitVariablesEditor(self.mainView, suite, trait)
     self.mainView.addChild(self.tveditor)
     self.setCentralWidget(self.mainView)
     self.mainView.setResizePolicy(self.mainView.AutoOneFit)
     self.initActions()
     self.initMenus()
     self.initToolbar()
示例#2
0
 def __init__(self, parent, suite, trait, name='TraitVariablesWindow'):
     BasePaellaWindow.__init__(self, parent, name=name)
     self.resize(500, 600)
     self.initPaellaCommon()
     self.mainView = QScrollView(self, 'TraitVariablesScrollView')
     self.tveditor = TraitVariablesEditor(self.mainView, suite, trait)
     self.mainView.addChild(self.tveditor)
     self.setCentralWidget(self.mainView)
     self.mainView.setResizePolicy(self.mainView.AutoOneFit)
     self.initActions()
     self.initMenus()
     self.initToolbar()
示例#3
0
class TraitVariablesWindow(BasePaellaWindow):
    def __init__(self, parent, suite, trait, name='TraitVariablesWindow'):
        BasePaellaWindow.__init__(self, parent, name=name)
        self.resize(500, 600)
        self.initPaellaCommon()
        self.mainView = QScrollView(self, 'TraitVariablesScrollView')
        self.tveditor = TraitVariablesEditor(self.mainView, suite, trait)
        self.mainView.addChild(self.tveditor)
        self.setCentralWidget(self.mainView)
        self.mainView.setResizePolicy(self.mainView.AutoOneFit)
        self.initActions()
        self.initMenus()
        self.initToolbar()

    def initActions(self):
        collection = self.actionCollection()
        self.quitAction = KStdAction.quit(self.close, collection)
        self.saveAction = KStdAction.save(self.slotSave, collection)
        self.newAction = KStdAction.openNew(self.slotNew, collection)

    def initMenus(self):
        pass

    def initToolbar(self):
        toolbar = self.toolBar()
        self.newAction.plug(toolbar)
        self.saveAction.plug(toolbar)
        self.quitAction.plug(toolbar)

    def _varline(self, var):
        return '%s\n' % var

    def _changed_report(self, removed, added, changed):
        if removed or added or changed:
            msg = 'Changes to Trait Variables:\n'
            if removed:
                msg += 'Removed:\n\n'
                for var in removed:
                    msg += self._varline(var)
            if added:
                msg += 'Added:\n\n'
                for var in added:
                    msg += self._varline(var)
            if changed:
                msg += 'Changed:\n\n'
                for var in changed:
                    msg += self._varline(var)
        else:
            msg = 'No Changes'
        return msg

    def slotSave(self):
        newdata = self.tveditor.get_data()
        oldata = dict(self.tveditor.traitenv.items())
        removed = [k for k in oldata if k not in newdata]
        added = [k for k in newdata if k not in oldata]
        changed = [k for k in newdata if newdata[k] != oldata[k]]
        report = self._changed_report(removed, added, changed)
        from kdeui import KMessageBox
        KMessageBox.information(self, report)
        env = self.tveditor.traitenv
        for key in removed:
            del env[key]
        for key in added + changed:
            env[key] = newdata[key]

    def slotNew(self):
        win = NewTraitVariableDialog(self)
        win.show()
        win.connect(win, SIGNAL('okClicked()'), self.newVariableSelected)
        self._dialog = win

    def newVariableSelected(self):
        win = self._dialog
        data = win.getRecordData()
        self.tveditor.traitenv[data['name']] = data['value']
        #self.tveditor.reset_grid()
        self.tveditor.add_field(data['name'], value=data['value'])
示例#4
0
class TraitVariablesWindow(BasePaellaWindow):
    def __init__(self, parent, suite, trait, name='TraitVariablesWindow'):
        BasePaellaWindow.__init__(self, parent, name=name)
        self.resize(500, 600)
        self.initPaellaCommon()
        self.mainView = QScrollView(self, 'TraitVariablesScrollView')
        self.tveditor = TraitVariablesEditor(self.mainView, suite, trait)
        self.mainView.addChild(self.tveditor)
        self.setCentralWidget(self.mainView)
        self.mainView.setResizePolicy(self.mainView.AutoOneFit)
        self.initActions()
        self.initMenus()
        self.initToolbar()
        
    def initActions(self):
        collection = self.actionCollection()
        self.quitAction = KStdAction.quit(self.close, collection)
        self.saveAction = KStdAction.save(self.slotSave, collection)
        self.newAction = KStdAction.openNew(self.slotNew, collection)
        
    def initMenus(self):
        pass
    
    def initToolbar(self):
        toolbar = self.toolBar()
        self.newAction.plug(toolbar)
        self.saveAction.plug(toolbar)
        self.quitAction.plug(toolbar)

    def _varline(self, var):
        return '%s\n' % var
    
    def _changed_report(self, removed, added, changed):
        if removed or added or changed:
            msg = 'Changes to Trait Variables:\n'
            if removed:
                msg += 'Removed:\n\n'
                for var in removed:
                    msg += self._varline(var)
            if added:
                msg += 'Added:\n\n'
                for var in added:
                    msg += self._varline(var)
            if changed:
                msg += 'Changed:\n\n'
                for var in changed:
                    msg += self._varline(var)
        else:
            msg  = 'No Changes'
        return msg
        
    def slotSave(self):
        newdata = self.tveditor.get_data()
        oldata = dict(self.tveditor.traitenv.items())
        removed = [k for k in oldata if k not in newdata]
        added = [k for k in newdata if k not in oldata]
        changed = [k for k in newdata if newdata[k] != oldata[k]]
        report = self._changed_report(removed, added, changed)
        from kdeui import KMessageBox
        KMessageBox.information(self, report)
        env = self.tveditor.traitenv
        for key in removed:
            del env[key]
        for key in added + changed:
            env[key] = newdata[key]
            
        

    def slotNew(self):
        win = NewTraitVariableDialog(self)
        win.show()
        win.connect(win, SIGNAL('okClicked()'), self.newVariableSelected)
        self._dialog = win
        
    def newVariableSelected(self):
        win = self._dialog
        data = win.getRecordData()
        self.tveditor.traitenv[data['name']] = data['value']
        #self.tveditor.reset_grid()
        self.tveditor.add_field(data['name'], value=data['value'])