コード例 #1
0
ファイル: pvoscillator.py プロジェクト: emayssat/python-eggs
    def __init__(self, parent = None):
        super(LPvOscillatorWidget, self).__init__(parent)
        self.setupUi(self)
        self.debug = (DEBUG & WIDGET)
        self.setName(WIDGET_NAME)
        self.tableView.setItemDelegate(LItemDelegate(self))

        self.dataContainer = LDataContainer(self)
        self.tableModel = LTableModel(self)
        self.tableView.setModel(self.tableModel)

        # Attached process
        self.process = QProcess(self)
        self.connect(self.process,SIGNAL('started()'), self.on_process_started)
        self.connect(self.process,SIGNAL('finished(int)'), self.on_process_finished)

        #FROM Sequencer ... doen't seem to work here!
        self.itemSelectionModel = QItemSelectionModel(self.tableModel)
        self.tableView.setSelectionModel(self.itemSelectionModel)
        index = self.tableModel.index(SELECTION_ROW_AT_INIT-1,0, QModelIndex())
        self.itemSelectionModel.setCurrentIndex(index, QItemSelectionModel.Select | QItemSelectionModel.Rows)
コード例 #2
0
ファイル: pvoscillator.py プロジェクト: emayssat/python-eggs
class LPvOscillatorWidget(QWidget, Ui_pvOscillatorWidget):

    dataChanged = pyqtSignal()

    def __init__(self, parent = None):
        super(LPvOscillatorWidget, self).__init__(parent)
        self.setupUi(self)
        self.debug = (DEBUG & WIDGET)
        self.setName(WIDGET_NAME)
        self.tableView.setItemDelegate(LItemDelegate(self))

        self.dataContainer = LDataContainer(self)
        self.tableModel = LTableModel(self)
        self.tableView.setModel(self.tableModel)

        # Attached process
        self.process = QProcess(self)
        self.connect(self.process,SIGNAL('started()'), self.on_process_started)
        self.connect(self.process,SIGNAL('finished(int)'), self.on_process_finished)

        #FROM Sequencer ... doen't seem to work here!
        self.itemSelectionModel = QItemSelectionModel(self.tableModel)
        self.tableView.setSelectionModel(self.itemSelectionModel)
        index = self.tableModel.index(SELECTION_ROW_AT_INIT-1,0, QModelIndex())
        self.itemSelectionModel.setCurrentIndex(index, QItemSelectionModel.Select | QItemSelectionModel.Rows)
        #self.itemSelectionModel.setCurrentIndex(index, QItemSelectionModel.Select)
        #self.connect(self.itemSelectionModel, SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.emitSelectionChanged)


    #----------------------------------------------------------------------
    # Interface

    def setOptions(self,options):
        self.setConfigurationFile(options.configurationFile)
        self.setName(options.name)
        self.setPreferredGeometry(options.geometryHint)
        self.setPrecision(options.precision)
        self.load()

    def setConfigurationFile(self, str):
        self.dataContainer.configurationFile = str
    def configurationFile(self):
        return self.dataContainer.configurationFile
    configurationFile = property(configurationFile,setConfigurationFile)

    def setPreferredGeometry(self,hint):
        self.dataContainer.geometryHint = hint
        wnh,xoff,yoff = hint.split('+')
        w,h = wnh.split('x')
        self.setGeometry(int(xoff),int(yoff),int(w),int(h))

    def setPrecision(self,int):
        if int >= 0 :
            self.dataContainer.precision = int

    def setName(self, name):
        self.name = name

    #----------------------------------------------------------------------
    # Events

    def contextMenuEvent(self, e):
        ''' The context menu created each time it is clicked! '''
        menu = LContextMenu(self)
        menu.exec_(e.globalPos())

    def closeEvent(self, event):
        ''' Closing the widget stops the process '''
        if self.process.state() != QProcess.NotRunning:
            self.on_stopButton_pressed()


    #----------------------------------------------------------------------
    # Widget slots

    def on_insertButton_pressed(self):
        LContextMenu(self).on_insertRowAction_triggered()

    def on_removeButton_pressed(self):
        LContextMenu(self).on_removeRowAction_triggered()

    @LInAndOut(DEBUG & WIDGET)
    def on_oscillateButton_pressed(self):
        LContextMenu(self).on_runAction_triggered()

    @LInAndOut(DEBUG & WIDGET)
    def on_stopButton_pressed(self):
        LContextMenu(self).on_killAction_triggered()

    def on_periodDurationSpinBox_valueChanged(self):
        self.dataContainer.periodDuration = self.periodDurationSpinBox.value()

    def on_numberOfPeriodsSpinBox_valueChanged(self):
        self.dataContainer.numberOfPeriods = self.numberOfPeriodsSpinBox.value()

    def on_stepsPerPeriodSpinBox_valueChanged(self):
        self.dataContainer.stepsPerPeriod = self.stepsPerPeriodSpinBox.value()

    @LInAndOut(DEBUG & WIDGET)
    def getCommandLine(self):
        ''' Print command line based on encapsulated data '''
        s = SHELL_PROGRAM + ' '
        s += "--stepsPerPeriod %d " % (self.dataContainer.stepsPerPeriod)
        s += "--periodDuration %f " % (self.dataContainer.periodDuration)
        s += "--numberOfPeriods %d " % (self.dataContainer.numberOfPeriods)
        for oscillatePv in self.dataContainer.oscillatePvs:
            s+= " --oscillatePv %s,%f,%s" % (oscillatePv.pvName, oscillatePv.amplitude, oscillatePv.action)
        return s


    #----------------------------------------------------------------------
    # Slots

    @pyqtSlot()
    def run(self):
        self.on_oscillateButton_pressed()

    @pyqtSlot()
    def save(self):
        try: 
            self.dataContainer.save()
        except Exception as e:
            if __name__ == "__main__":
                QMessageBox.critical(self, "PvOscillatorWidget - Critical", "Could not save: %s" % e )
            else:
                raise e

    @pyqtSlot()
    def load(self):
        try: 
            self.dataContainer.load()
            self.tableModel.signalLayoutChanged()
            self.resizeColumnToContents()
            self.periodDurationSpinBox.setValue(self.dataContainer.periodDuration)
            self.numberOfPeriodsSpinBox.setValue(self.dataContainer.numberOfPeriods)
            self.stepsPerPeriodSpinBox.setValue(self.dataContainer.stepsPerPeriod)
        except Exception as e:
            if __name__ == "__main__":
                QMessageBox.critical(self, "PvOscillatorWidget - Critical", "Could not load: %s" % e )
            else:
                raise e

    #----------------------------------------------------------------------
    # Methods

    @LInAndOut(DEBUG & WIDGET)
    def on_process_started(self):
        if self.debug : print "Process started ~~>"
        self.oscillateButton.setEnabled(False)
        self.stopButton.setEnabled(True)
        self.insertButton.setEnabled(False)
        self.removeButton.setEnabled(False)

    @LInAndOut(DEBUG & WIDGET)
    def on_process_finished(self,exitCode):
        if self.debug : print "Process finished ~~>"
        self.oscillateButton.setEnabled(True)
        self.stopButton.setEnabled(False)
        self.insertButton.setEnabled(True)
        self.removeButton.setEnabled(True)

    @LInAndOut(DEBUG & WIDGET)
    def resizeColumnToContents(self):
        for column in range(self.tableModel.columnCount(self)+1):
            self.tableView.resizeColumnToContents(column)