コード例 #1
0
class LoggerDialog(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        self.setWindowTitle("Data Logger")
        self.groupbox1 = DataSetEditGroupBox("Parametres de lock",Loggerdataset,show_button = False)   
        self.groupbox1.dataset.parent = self
        self.values = self.groupbox1.dataset
        self.groupbox1.dataset.parent = self
        lay = QVBoxLayout()
        lay.addWidget(self.groupbox1)
        self.setLayout(lay)
        self.resize(800,300)
        
        self.timer = QTimer()
        self.timer.timeout.connect(self.log)
        #self.timer.timeout.connect(self.update_values)
        self.timer.setInterval(100) #ms
        self.show()
    
    def transform_number(self):
        self.values.next = self.values.next*self.values.mult + self.values.add
        self.groupbox1.get()
    
    def log(self):
        self.groupbox1.set()
        if not vsa.on_screen.meas_done():
            return
        if vsa.on_screen.current_average()<self.values.next:
            vsa.on_screen.resume()
            return
        if self.values.save:
            self.manual()
        else:
            vsa.on_screen.resume()
        self.transform_number()
        #vsa.on_screen.set_average(self.values.next)
        

    def manual(self):
        vsa.on_screen.pause()
        try:
            df = load(self.values.filename)
        except IOError:
            df = matched_df()
        append_one_av(df)
        df.save(self.values.filename)
        vsa.on_screen.resume()
        
    
    def start(self):
        print "starting"
        vsa.on_screen.set_average(self.values.next)
        vsa.on_screen.restart()
        self.timer.start()
コード例 #2
0
ファイル: editgroupbox.py プロジェクト: CARIBOuSystem/guidata
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowIcon(get_icon('python.png'))
        self.setWindowTitle("Application example")
        
        # Instantiate dataset-related widgets:
        self.groupbox1 = DataSetShowGroupBox("Activable dataset",
                                             ExampleDataSet, comment='')
        self.groupbox2 = DataSetShowGroupBox("Standard dataset",
                                             AnotherDataSet, comment='')
        self.groupbox3 = DataSetEditGroupBox("Standard dataset",
                                             OtherDataSet, comment='')
        self.groupbox4 = DataSetEditGroupBox("Standard dataset",
                                             ExampleMultiGroupDataSet, comment='')
        self.groupbox3.SIG_APPLY_BUTTON_CLICKED.connect(self.update_window)
        self.update_groupboxes()
        
        splitter = QSplitter(self)
        splitter.addWidget(self.groupbox1)
        splitter.addWidget(self.groupbox2)
        splitter.addWidget(self.groupbox3)
        splitter.addWidget(self.groupbox4)
        self.setCentralWidget(splitter)
        self.setContentsMargins(10, 5, 10, 5)
        
        # File menu
        file_menu = self.menuBar().addMenu("File")
        quit_action = create_action(self, "Quit",
                                    shortcut="Ctrl+Q",
                                    icon=get_std_icon("DialogCloseButton"),
                                    tip="Quit application",
                                    triggered=self.close)
        add_actions(file_menu, (quit_action, ))
        
        # Edit menu
        edit_menu = self.menuBar().addMenu("Edit")
        editparam1_action = create_action(self, "Edit dataset 1",
                                          triggered=self.edit_dataset1)
        editparam2_action = create_action(self, "Edit dataset 2",
                                          triggered=self.edit_dataset2)
        editparam4_action = create_action(self, "Edit dataset 4",
                                          triggered=self.edit_dataset4)
        add_actions(edit_menu, (editparam1_action,
                                editparam2_action,
                                editparam4_action))
        
    def update_window(self):
        dataset = self.groupbox3.dataset
        self.setWindowTitle(dataset.title)
        self.setWindowIcon(get_icon(dataset.icon))
        self.setWindowOpacity(dataset.opacity)
        
    def update_groupboxes(self):
        self.groupbox1.dataset.set_readonly() # This is an activable dataset
        self.groupbox1.get()
        self.groupbox2.get()
        self.groupbox4.get()
        
    def edit_dataset1(self):
        self.groupbox1.dataset.set_writeable() # This is an activable dataset
        if self.groupbox1.dataset.edit():
            self.update_groupboxes()
    
    def edit_dataset2(self):
        if self.groupbox2.dataset.edit():
            self.update_groupboxes()

    def edit_dataset4(self):
        if self.groupbox4.dataset.edit():
            self.update_groupboxes()
コード例 #3
0
class ParamWidget(QWidget):
    def __init__(self,
                 dataset,
                 title='',
                 settings=None,
                 settingskey=None,
                 parent=None):
        super(ParamWidget, self).__init__(parent=parent)

        self.settings = settings
        self.settingskey = settingskey

        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        if self.settings is not None and self.settingskey is not None:
            stored_list = self.settings.getValueOrDefault(
                'storedParameters/' + self.settingskey, [])

            h = QHBoxLayout()
            self.mainLayout.addLayout(h)
            h.addStretch(1)
            self.comboParam = QComboBox()
            h.addWidget(self.comboParam, 3)

            self.refreshCombo()
            self.comboParam.currentIndexChanged.connect(self.comboParamChanged)

            buttonSave = QPushButton(QIcon(':/list-add.png'), '')
            buttonSave.setMaximumSize(25, 25)
            h.addWidget(buttonSave)
            buttonSave.clicked.connect(self.saveNewParam)
            buttonDel = QPushButton(QIcon(':/list-remove.png'), '')
            buttonDel.setMaximumSize(25, 25)
            h.addWidget(buttonDel)
            buttonDel.clicked.connect(self.delSavedParam)

        self.params = DataSetEditGroupBox(title, dataset, show_button=False)
        self.mainLayout.addWidget(self.params)

        self.default_dict = self.to_dict()

    def to_dict(self):
        self.params.set()
        ds = self.params.dataset
        d = OrderedDict()
        for item in ds._items:
            if type(item) is ChoiceItem:
                val = None
                ind = getattr(ds, item._name)
                choices = item.get_prop_value("data", item, "choices")
                for choice in choices:
                    if choice[0] == ind:
                        val = choice[1]
            else:
                val = getattr(ds, item._name)
            d[item._name] = val
        return d

    def update(self, d):
        ds = self.params.dataset
        for item in ds._items:
            if item._name in d:
                if type(item) is ChoiceItem:
                    choices = item.get_prop_value("data", item, "choices")
                    choices = [c[1] for c in choices]
                    ind = choices.index(d[item._name])
                    setattr(ds, item._name, ind)
                else:
                    setattr(ds, item._name, d[item._name])
        self.params.get()

    def reset(self):
        self.update(self.default_dict)

    def refreshCombo(self):
        stored_list = self.settings['storedParameters/' + self.settingskey]
        self.comboParam.clear()
        list_name = [l[0] for l in stored_list]
        self.comboParam.addItems([
            'Default',
        ] + list_name)

    def comboParamChanged(self, pos):
        if pos <= 0:
            self.reset()
        else:
            stored_list = self.settings['storedParameters/' + self.settingskey]
            self.update(stored_list[pos - 1][1])

    def saveNewParam(self):
        class Parameters(DataSet):
            name = StringItem('name', default='')

        dia = ParamDialog(Parameters, title='key')
        ok = dia.exec_()
        if ok != QDialog.Accepted: return

        name = dia.to_dict()['name']
        stored_list = self.settings['storedParameters/' + self.settingskey]
        stored_list += [[name, self.to_dict()]]
        self.settings['storedParameters/' + self.settingskey] = stored_list

        self.refreshCombo()
        self.comboParam.setCurrentIndex(len(stored_list))

    def delSavedParam(self):
        pos = self.comboParam.currentIndex()
        if pos == 0: return

        stored_list = self.settings['storedParameters/' + self.settingskey]
        del stored_list[pos - 1]
        self.settings['storedParameters/' + self.settingskey] = stored_list

        self.refreshCombo()
        self.comboParam.setCurrentIndex(0)
コード例 #4
0
class MainWindow(Thread, QMainWindow):
    def __init__(self):
        # init main panel
        QMainWindow.__init__(self)
        Thread.__init__(self)
        widget = QWidget()
        self.setCentralWidget(widget)

        # define main objects
        self.remoteKoala = None
        self.aberrationCorrection = None
        self.stackDistance = None
        self.tracking = None
        self.db = None
        self.focusPoint = None
        self.trackingMode = 0  # 0 - Automatic, 1 - Single
        self.unwrapK = None
        self.setWindowTitle('3D tracking')

        # init dataset from gui_construction
        self.gb_dhm = DataSetEditGroupBox("DHM",
                                          gui_construction.DHMParameters,
                                          comment='')
        self.gb_sample = DataSetEditGroupBox("Sample",
                                             gui_construction.SampleParameters,
                                             comment='')
        self.gb_remote = DataSetEditGroupBox("Sequence",
                                             gui_construction.RemoteParameters,
                                             comment='')
        self.gb_holder = DataSetEditGroupBox("Focus",
                                             gui_construction.HolderParameters,
                                             comment='')
        self.gb_rec = DataSetEditGroupBox(
            "Preprocessing Parameters",
            gui_construction.ReconstructionParameters,
            comment='')
        #        self.gb_proc = DataSetEditGroupBox("Process",
        #                    gui_construction.ProcessParameters, comment='')
        #        self.gb_partchoice = DataSetEditGroupBox("Particle Choice",
        #                    gui_construction.ParticuleChoice, comment='')

        # associate events to dataset apply buttons
        self.connect(self.gb_dhm, SIGNAL("apply_button_clicked()"),
                     self.update_dhm_params)
        self.connect(self.gb_sample, SIGNAL("apply_button_clicked()"),
                     self.update_sample_params)
        self.connect(self.gb_remote, SIGNAL("apply_button_clicked()"),
                     self.update_remote_params)
        self.connect(self.gb_holder, SIGNAL("apply_button_clicked()"),
                     self.update_holder_params)

        # organize the subpanels
        splitter1 = QSplitter(QtCore.Qt.Vertical)
        splitter1.addWidget(self.gb_dhm)
        splitter1.addWidget(self.gb_sample)
        splitter1.addWidget(self.gb_remote)
        splitter1.addWidget(self.gb_holder)

        splitter2 = QSplitter(QtCore.Qt.Vertical)

        splitter = QSplitter(self)
        splitter.addWidget(splitter1)
        splitter.addWidget(splitter2)
        self.setCentralWidget(splitter)
        self.setContentsMargins(10, 5, 10, 5)

        # get all params from datasets
        self.gb_dhm.get()

    def update_dhm_params(self):
        utils.Log("DHM parameters updated")
        self.process()

#        self.stackDistance.from_dataset(self.db, self.gb_dhm.dataset)

    def update_sample_params(self):
        utils.Log("sample parameters updated")
        self.process()

    def update_remote_params(self):
        utils.Log("sequence parameters updated")
        self.process()

    def update_holder_params(self):
        utils.Log("focus parameter updated")
        self.process()

    def process(self):
        if self.db is None:
            self.db = SqliteDB.DBReader()
            self.db.ProductionNo = self.gb_dhm.dataset.MODB
            self.db.ParamFromChoice()
コード例 #5
0
ファイル: gui.py プロジェクト: zanppa/motor-sim
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowIcon(get_icon('python.png'))
        self.setWindowTitle("Electric motor simulator")

        # Dataset for editing motor parameters
        self.groupbox1 = DataSetShowGroupBox("Motor parameters",
                                             ExampleDataSet,
                                             comment='')
        self.groupbox2 = DataSetShowGroupBox("Controller parameters",
                                             AnotherDataSet,
                                             comment='')
        self.groupbox3 = DataSetEditGroupBox("Standard dataset",
                                             OtherDataSet,
                                             comment='')
        self.groupbox4 = DataSetEditGroupBox("Standard dataset",
                                             ExampleMultiGroupDataSet,
                                             comment='')
        #self.groupbox3.SIG_APPLY_BUTTON_CLICKED.connect(self.update_window)
        self.update_groupboxes()

        splitter = QSplitter(self)
        splitter.addWidget(self.groupbox1)
        splitter.addWidget(self.groupbox2)
        #splitter.addWidget(self.groupbox3)
        #splitter.addWidget(self.groupbox4)
        self.setCentralWidget(splitter)
        self.setContentsMargins(10, 5, 10, 5)

        # File menu
        file_menu = self.menuBar().addMenu("File")
        quit_action = create_action(self,
                                    "Quit",
                                    shortcut="Ctrl+Q",
                                    icon=get_std_icon("DialogCloseButton"),
                                    tip="Quit application",
                                    triggered=self.close)
        add_actions(file_menu, (quit_action, ))

        # Edit menu
        edit_menu = self.menuBar().addMenu("Edit")
        editparam1_action = create_action(self,
                                          "Edit dataset 1",
                                          triggered=self.edit_dataset1)
        editparam2_action = create_action(self,
                                          "Edit dataset 2",
                                          triggered=self.edit_dataset2)
        editparam4_action = create_action(self,
                                          "Edit dataset 4",
                                          triggered=self.edit_dataset4)
        add_actions(edit_menu,
                    (editparam1_action, editparam2_action, editparam4_action))

        # Toolbar
        tb = self.addToolBar("Tools")
        reset = QAction("Reset", self)
        tb.addAction(reset)
        pause = QAction("Pause", self)
        tb.addAction(pause)
        step = QAction("Step", self)
        tb.addAction(step)
        go = QAction("Go", self)
        tb.addAction(go)

    def update_window(self):
        dataset = self.groupbox3.dataset
        self.setWindowTitle(dataset.title)
        self.setWindowIcon(get_icon(dataset.icon))
        self.setWindowOpacity(dataset.opacity)

    def update_groupboxes(self):
        self.groupbox1.dataset.set_readonly()  # This is an activable dataset
        self.groupbox1.get()
        self.groupbox2.get()
        self.groupbox4.get()

    def edit_dataset1(self):
        self.groupbox1.dataset.set_writeable()  # This is an activable dataset
        if self.groupbox1.dataset.edit():
            self.update_groupboxes()

    def edit_dataset2(self):
        if self.groupbox2.dataset.edit():
            self.update_groupboxes()

    def edit_dataset4(self):
        if self.groupbox4.dataset.edit():
            self.update_groupboxes()
コード例 #6
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowIcon(get_icon('python.png'))
        self.setWindowTitle("Application example")

        # Instantiate dataset-related widgets:
        self.groupbox1 = DataSetShowGroupBox("Activable dataset",
                                             ExampleDataSet,
                                             comment='')
        self.groupbox2 = DataSetShowGroupBox("Standard dataset",
                                             AnotherDataSet,
                                             comment='')
        self.groupbox3 = DataSetEditGroupBox("Standard dataset",
                                             OtherDataSet,
                                             comment='')
        self.groupbox4 = DataSetEditGroupBox("Standard dataset",
                                             ExampleMultiGroupDataSet,
                                             comment='')
        self.groupbox3.SIG_APPLY_BUTTON_CLICKED.connect(self.update_window)
        self.update_groupboxes()

        splitter = QSplitter(self)
        splitter.addWidget(self.groupbox1)
        splitter.addWidget(self.groupbox2)
        splitter.addWidget(self.groupbox3)
        splitter.addWidget(self.groupbox4)
        self.setCentralWidget(splitter)
        self.setContentsMargins(10, 5, 10, 5)

        # File menu
        file_menu = self.menuBar().addMenu("File")
        quit_action = create_action(self,
                                    "Quit",
                                    shortcut="Ctrl+Q",
                                    icon=get_std_icon("DialogCloseButton"),
                                    tip="Quit application",
                                    triggered=self.close)
        add_actions(file_menu, (quit_action, ))

        # Edit menu
        edit_menu = self.menuBar().addMenu("Edit")
        editparam1_action = create_action(self,
                                          "Edit dataset 1",
                                          triggered=self.edit_dataset1)
        editparam2_action = create_action(self,
                                          "Edit dataset 2",
                                          triggered=self.edit_dataset2)
        editparam4_action = create_action(self,
                                          "Edit dataset 4",
                                          triggered=self.edit_dataset4)
        add_actions(edit_menu,
                    (editparam1_action, editparam2_action, editparam4_action))

    def update_window(self):
        dataset = self.groupbox3.dataset
        self.setWindowTitle(dataset.title)
        self.setWindowIcon(get_icon(dataset.icon))
        self.setWindowOpacity(dataset.opacity)

    def update_groupboxes(self):
        self.groupbox1.dataset.set_readonly()  # This is an activable dataset
        self.groupbox1.get()
        self.groupbox2.get()
        self.groupbox4.get()

    def edit_dataset1(self):
        self.groupbox1.dataset.set_writeable()  # This is an activable dataset
        if self.groupbox1.dataset.edit():
            self.update_groupboxes()

    def edit_dataset2(self):
        if self.groupbox2.dataset.edit():
            self.update_groupboxes()

    def edit_dataset4(self):
        if self.groupbox4.dataset.edit():
            self.update_groupboxes()
コード例 #7
0
ファイル: myguidata.py プロジェクト: Gjergj/OpenElectrophy
class ParamWidget(QWidget):
    def __init__(self, dataset, title = '', settings = None, settingskey = None, parent = None):
        super(ParamWidget, self).__init__(parent = parent)
        
        self.settings = settings
        self.settingskey = settingskey
        
        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)
        
        
        if self.settings is not None and self.settingskey is not None:
            stored_list = self.settings.getValueOrDefault('storedParameters/'+self.settingskey, [ ])

            h = QHBoxLayout()
            self.mainLayout.addLayout(h)
            h.addStretch(1)
            self.comboParam = QComboBox()
            h.addWidget(self.comboParam, 3)
            
            self.refreshCombo()
            self.comboParam.currentIndexChanged.connect(self.comboParamChanged)

            buttonSave = QPushButton(QIcon(':/list-add.png') ,'')
            buttonSave.setMaximumSize(25,25)
            h.addWidget(buttonSave)
            buttonSave.clicked.connect(self.saveNewParam)
            buttonDel = QPushButton(QIcon(':/list-remove.png') ,'')
            buttonDel.setMaximumSize(25,25)
            h.addWidget(buttonDel)
            buttonDel.clicked.connect(self.delSavedParam)
        
        self.params = DataSetEditGroupBox(title,dataset, show_button = False)
        self.mainLayout.addWidget( self.params )
        
        self.default_dict = self.to_dict()
        

    def to_dict(self):
        self.params.set()
        ds = self.params.dataset
        d = OrderedDict()
        for item in ds._items:
            if type(item) is ChoiceItem:
                val = None
                ind = getattr(ds,  item._name)
                choices = item.get_prop_value("data", item, "choices")
                for choice in choices:
                    if choice[0] == ind:
                        val = choice[1]
            else:
                val = getattr(ds,  item._name)
            d[item._name] = val
        return d
        
    def update(self, d):
        ds = self.params.dataset
        for item in ds._items:
            if item._name in d:
                if type(item) is ChoiceItem:
                    choices = item.get_prop_value("data", item, "choices")
                    choices = [ c[1] for c in choices ]
                    ind = choices.index(d[item._name])
                    setattr(ds,  item._name, ind)
                else:
                    setattr(ds,  item._name, d[item._name])
        self.params.get()
    
    def reset(self):
        self.update(self.default_dict)
    
    def refreshCombo(self):
        stored_list = self.settings['storedParameters/'+self.settingskey]
        self.comboParam.clear()
        list_name = [ l[0] for l in stored_list ]
        self.comboParam.addItems(['Default' , ]+list_name  )
        
    
    def comboParamChanged(self, pos) :
        if pos <= 0 :
            self.reset()
        else :
            stored_list = self.settings['storedParameters/'+self.settingskey]
            self.update(stored_list[pos-1][1])
    
    def saveNewParam( self ) :
        class Parameters(DataSet):
            name = StringItem('name', default = '')
        dia = ParamDialog(Parameters, title = 'key')
        ok = dia.exec_()
        if  ok !=  QDialog.Accepted: return
        
        name = dia.to_dict()['name']
        stored_list = self.settings['storedParameters/'+self.settingskey]
        stored_list += [ [ name , self.to_dict() ] ]
        self.settings['storedParameters/'+self.settingskey] = stored_list

        self.refreshCombo()
        self.comboParam.setCurrentIndex(len(stored_list))

    def delSavedParam( self) :
        pos = self.comboParam.currentIndex()
        if pos == 0: return

        stored_list = self.settings['storedParameters/'+self.settingskey]
        del stored_list[pos-1]
        self.settings['storedParameters/'+self.settingskey] = stored_list
            
        self.refreshCombo()
        self.comboParam.setCurrentIndex(0)
コード例 #8
0
class MainWindow(Thread, QMainWindow):
    def __init__(self):
        # init main panel
        QMainWindow.__init__(self)
        Thread.__init__(self)
        widget = QWidget()
        self.setCentralWidget(widget)

        # define main objects
        self.remoteKoala = None
        self.aberrationCorrection = None
        self.stackDistance = None
        self.tracking = None
        self.db = None
        self.focusPoint = None
        self.trackingMode = 0 # 0 - Automatic, 1 - Single
        self.unwrapK = None
        self.setWindowTitle('3D tracking')
        
        # init dataset from gui_construction
        self.gb_dhm = DataSetEditGroupBox("DHM", 
                    gui_construction.DHMParameters, comment='')
        self.gb_sample = DataSetEditGroupBox("Sample", 
                    gui_construction.SampleParameters, comment='')
        self.gb_remote = DataSetEditGroupBox("Sequence", 
                    gui_construction.RemoteParameters, comment='')       
        self.gb_holder = DataSetEditGroupBox("Focus", 
                    gui_construction.HolderParameters, comment='')
        self.gb_rec = DataSetEditGroupBox("Preprocessing Parameters", 
                    gui_construction.ReconstructionParameters, comment='')
#        self.gb_proc = DataSetEditGroupBox("Process", 
#                    gui_construction.ProcessParameters, comment='')
#        self.gb_partchoice = DataSetEditGroupBox("Particle Choice", 
#                    gui_construction.ParticuleChoice, comment='')
                    
        # associate events to dataset apply buttons
        self.connect(self.gb_dhm, SIGNAL("apply_button_clicked()"), 
                     self.update_dhm_params)
        self.connect(self.gb_sample, SIGNAL("apply_button_clicked()"), 
                     self.update_sample_params)
        self.connect(self.gb_remote, SIGNAL("apply_button_clicked()"), 
                     self.update_remote_params)
        self.connect(self.gb_holder, SIGNAL("apply_button_clicked()"), 
                     self.update_holder_params)
        
        # organize the subpanels
        splitter1 = QSplitter(QtCore.Qt.Vertical)
        splitter1.addWidget(self.gb_dhm)
        splitter1.addWidget(self.gb_sample)
        splitter1.addWidget(self.gb_remote)
        splitter1.addWidget(self.gb_holder)
        
        splitter2 = QSplitter(QtCore.Qt.Vertical)
        
        splitter = QSplitter(self)
        splitter.addWidget(splitter1)
        splitter.addWidget(splitter2)
        self.setCentralWidget(splitter)
        self.setContentsMargins(10, 5, 10, 5)   
        
        # get all params from datasets
        self.gb_dhm.get()

    def update_dhm_params(self):
        utils.Log("DHM parameters updated")
        self.process()
        
#        self.stackDistance.from_dataset(self.db, self.gb_dhm.dataset)
        
    def update_sample_params(self):
        utils.Log("sample parameters updated")
        self.process()
        
    def update_remote_params(self):
        utils.Log("sequence parameters updated")
        self.process()
      
    def update_holder_params(self):
        utils.Log("focus parameter updated")
        self.process()
        
        
        
    def process(self):
        if self.db is None:
            self.db = SqliteDB.DBReader()
            self.db.ProductionNo = self.gb_dhm.dataset.MODB
            self.db.ParamFromChoice()
コード例 #9
0
class GuidataView(view.GenericView):
    _CONST_Views = ['Splitter', 'Tabs', 'Standard']

    def __init__(self, viewname = '', viewtype ='Standard', qtapp=None):
        super().__init__(viewname)
        self._app = qtapp
        self._frame = None
        self._parentFrame = None
        self._viewtype = viewtype
        self._groupbox = None
        self._previousValues = OrderedDict()

    def getViewType(self):
        return self._viewtype

    viewtype = property(getViewType, doc='The view type, see _CONST_Views for available views. Readonly')

    def setParentView(self, parentview):
        '''
        Set the parent widget associated to this view (GenericView)
        :param parentview:
        :return:
        '''
        if self._parentFrame is not None:
            raise view.ViewInternalError(self, self._viewname, 'Parent was already set')
        # self._parentFrame = parentview.getViewContainer()
        self._parentFrame = parentview

    def show(self):
        # QT Stuff
        if self._app is None:
            self._app = QApplication([])
        if self._parentFrame is None:
            self._parentFrame = QMainWindow()

        # self._parentFrame.setWindowIcon(get_icon('python.png'))
        self._parentFrame.setWindowTitle(self.viewname)

         # Add the frame to this frame
        self._parentFrame.setCentralWidget(self.getFrame())
        self._parentFrame.setContentsMargins(10, 5, 10, 5)

        self._parentFrame.show()
        self._forceRefreshFromWidgets()
        self._previousValues = self._dumpValues()

    def close(self, closeapp=False):
        '''
        Implement the close view in the GerericView class, furthermore  close the QT application which this view belongs
        :param closeapp:
        :return:
        '''
        if self._parentFrame is not None:
            self._parentFrame.close()
            del self._parentFrame
        if self._app is not None and closeapp:
            del self._app

    def getFrame(self):
        '''
        Return the frame containing the presentation, check if the frame was created, otherwise it is created
        :return:
        '''
        if self._frame is None:
            self._generateFrame()
        return self._frame

    def _generateFrame(self):
        '''
        Return the frame containing the presentation, check if the frame was created, otherwise it is created
        :return:
        '''
        # generate the frame if necessary
        if self._frame is None:
            # Generate frame and define the layout based on the frame
            self._frame = QFrame(self._parentFrame)
            _layout = QVBoxLayout()
            self._frame.setLayout(_layout)

            # Add the "Main" group box for this view, if present. It is rendered in foreground
            if self._generateGroupBox() is not None:
                _layout.addWidget(self._groupbox)
            else:
                self._frame.setFrameStyle(QFrame.Panel|QFrame.Raised)
                self._frame.setLineWidth(1)

            # Add to layout eventually the other subview
            if self._viewtype == 'Tabs':
                _tabs = QTabWidget()
                _layout.addWidget(_tabs)
            elif self._viewtype == 'Splitter':
                _splitter =QSplitter()
                _layout.addWidget(_splitter)
            else:
                _sub_frame = QFrame()
                _sub_frame_layout = QHBoxLayout()
                _sub_frame.setLayout(_sub_frame_layout)
                _layout.addWidget(_sub_frame)

            # Add all the sub view as sub frames in the layout
            for sw in self._subViewDictionary.values():
                sw.setParentView(self._frame)
                if self._viewtype == 'Tabs':
                    _tabs.addTab(sw.getFrame(), sw.viewname)
                elif self._viewtype == 'Splitter':
                    _splitter.addWidget(sw.getFrame())
                else:
                    _sub_frame_layout.addWidget(sw.getFrame())

        return self._frame

    def _generateGroupBox(self):
        '''
        Generate if necessary the group box for this
        :return:
        '''
        if self._groupbox is None:
            # from  widgets create the view containing the datasets
            _dataSetView = self._generateGuidataDataset()
            if len(_dataSetView._items) > 0:
                if self._viewtype == 'Tabs':
                    self._groupbox = DataSetEditGroupBox(self.viewname, _dataSetView, comment='')
                else:
                    self._groupbox = DataSetEditGroupBox(self.viewname, _dataSetView, comment='')
                self._groupbox.SIG_APPLY_BUTTON_CLICKED.connect(self._updatedView)

        return self._groupbox

    def getViewContainer(self):
        '''
        This method must be reimplemented returning the proper window/frame etc.. It is based on the GUI implementation
        :return: a reference to the window container
        '''
        return self._parentFrame

    def getQTApp(self):
        '''
        Return the associated QT application, which is mandatory for guidata framework
        :return:
        '''
        return self._app

    def addWidget(self, widgetinstance):
        if not isinstance(widgetinstance, GuidataWidget):
            raise view.WrongWidgetClass(self, self._viewname, widgetinstance, GuidataWidget)
        super().addWidget(widgetinstance)

    def _dumpValues(self):
        widgetvalue = OrderedDict()

        for n, w in self._widgetDictionary.items():
            # I need to store the widget value and NOT the value returned (for example in a combo box I need to store
            # the index, not the value
            # widgetvalue[n] = w.getWidgetValue()
            widgetvalue[n] = GuidataWidget.convertValueToWidgetValue(w, w.getWidgetValue())

        return widgetvalue

    def _updatedViewHook(self):
        # En Widget ' + str(wtry point for a change...

        differences = {}
        differencesConverted = {}
        self._groupbox.get()
        dataset = self._groupbox.dataset

        for n, w in self._widgetDictionary.items():
            # if nameProp in  vars(dataset):
            # TODO: workaround,  the mechanism in the guidata framework is not very well documented.
            # TODO: then in order to get the proper value this is collected through the groupbox insteadm the value.
            # So i check in dataset every nameprop
            nameProp = w.name
            actualValue = getattr(dataset, nameProp) #, w.getWidgetValue())
            prevValue   = self._previousValues.get(n)
            logging.debug('--widgetname=' + w.name)

            if not (prevValue == actualValue):
                differences[n] = actualValue
                differencesConverted[n] = GuidataWidget.convertWidgetValueToValue(w, actualValue)
                #w._setWidgetValueHook(actualValue)
                logging.debug('  DIFFERENCE viewname={0}  prevvalue={1} - newvalue={2}'.format(n, prevValue, actualValue))
                logging.debug('  DIFFERENCE CONVERTED viewname={0}  prevvalue={1} - newvalue={2}'.format
                              (n, GuidataWidget.convertWidgetValueToValue(w, prevValue), differencesConverted[n]))
            else:
                logging.debug('  NO DIFFERENCE viewname={0}  prevvalue={1} - newvalue={2}'.format(n, prevValue, actualValue))

        if len(differences):
            self._forceRefreshToWidgets(differences)
            self._previousValues = self._dumpValues()
        return differencesConverted

    def _forceRefreshToWidgets(self, widget_to_set):
        '''
        A refresh to update the widget with the values stored in the groupbox associated
        This is a workaround relative to the guidata framework. (should be improved)
        :return:
        '''
        if self._groupbox == None:
            return

        #for key, w in self._widgetDictionary.items():
        for wname, valuetoconvert in widget_to_set.items():
            w = self.getWidget(wname)
            if w is None:
                raise RuntimeError('Widget cannot\'t be None')

            # TODO: this is horrible, but need a workaround for guidata to get the value from data set and force it in the GUI
            #valuetoconvert = getattr(self._groupbox.dataset, wname)
            converteddataset = GuidataWidget.convertWidgetValueToValue(w, valuetoconvert)
            logging.debug('For widget['+wname+'] Converted value from '+str(valuetoconvert)+' to ' + str(converteddataset))

            w.setWidgetValue(converteddataset) # Convertire from index to value
            logging.debug('\tValue set is '+str(w.getWidgetValue()))

    def _forceRefreshFromWidgets(self):
        '''
        A refresh to update the whole groupbox with the proper value associated in the widget
        A workaround in the bad documented guidata in order to  force the refresh from the data stored in the widget
        :return:
        '''
        if self._groupbox == None:
            return

        for key, w in self._widgetDictionary.items():
            value = w.getWidgetValue()
            valueconverted = w._getGuidataWidgetValue()
            logging.debug('For widget ['+key+'] Converted value from '+str(value)+' to ' + str(valueconverted))
            setattr(self._groupbox.dataset, key, valueconverted)
            logging.debug('\tRead back value  '+str(getattr(self._groupbox.dataset, key)))

        #PROBLEM IN GET!!! se faccio la get nelle combo box setto il valore del ITEM id e non del valore vero
        # in prarice il setattr dovrebbe settare l'ITEM ID per le combo box
        self._groupbox.get()

    def _userWidgetUpdatedHandler(self, sender):
        # WORKAROUND: the guidata need to be forced to update  the UI if the underlay widget is changed
        if not isinstance(sender, widget.GenericWidget):
            raise view.WrongWidgetClass(self,self.viewname, sender, widget.GenericWidget)
        self._forceRefreshFromWidgets()

        super()._userWidgetUpdatedHandler(sender)

    def _generateGuidataDataset(self):
        class DataSetView(DataSet):
            key = None
            value = None
            for key, value in self._widgetDictionary.items():
                locals()[key] = value.getDataSet()
            del key, value
        return DataSetView
コード例 #10
0
class ProjectGUI(QObject):
    logger = logging.getLogger()
    _new_project_signal = pyqtSignal()

    def __init__(self, parent):
        super(ProjectGUI, self).__init__()
        self.parent = parent
        self._connect_project_properties()

    def _reset_data(self):
        self.projectproperties.dataset._reset_values()
        self.rewrite_values_in_gui_with_variables()

    def _connect_project_properties(self):
        self.projectproperties = DataSetEditGroupBox(
            "Project Data",
            ProjectPropertiesDataset,
            comment="Parameters common to all assets")
        self.projectproperties.SIG_APPLY_BUTTON_CLICKED.connect(
            self._apply_dataset_values)

    def _apply_dataset_values(self):
        """This is connected to a signal. When mocking, use parent.apply_dataset_values method."""
        self.logger.info("Me pressed.")
        self.parent.apply_dataset_values()

    def check_epanetfile(self, enfile):
        if (os.path.isfile(enfile)):
            self.logger.info("EPANET valid file check. To be implemented")
            return enfile
        else:
            self.logger.info("Not a valid epanetfile: %s" % enfile)
            msgBox = QMessageBox(parent=self.parent)
            msgBox.setText("This is not a valid epanet file")
            msgBox.exec_()
            return None

    def log(self):
        try:
            k = self.projectproperties.dataset
            self.logger.info("discount rate =%s" % (k.discountrate))
        except Exception:
            pass

    def rewrite_values_in_gui_with_variables(self):
        self.logger.info("Writing: var>GUI ")
        self.log()
        self.projectproperties.get()

    def rewrite_values_in_variables_with_gui(self):
        self.logger.info("Writing: GUI>var ")
        self.log()
        # disable events from firing
        __status = self.projectproperties.blockSignals(True)
        self.projectproperties.set()
        # now enable them again
        self.projectproperties.blockSignals(__status)

    def new_project(self):
        self.logger.info("New Project")
        # first step, get the name of the epanet file from the user.
        if (self._new_project()):
            # now we inform the project_manager to do the calculation
            self._new_project_signal.emit()
            return True
        else:
            return False

    def _new_project(self):
        epanetfile, filter = self._getSaveFileName2(
            self.parent,
            "Select a valid EPANET 2.0 network file",
            self.parent.EPANETLOC or c.HOMEDIR,
            filter='*.inp')

        epanetfile = self.check_epanetfile(epanetfile)
        if (not epanetfile):
            return False
        msg = "New Project"
        self.projectproperties.dataset.projectname = self._create_empty_project(
            msg, epanetfile)
        self.parent.LASTPROJECT = self.projectproperties.dataset.projectname
        self.parent.EPANETLOC = os.path.dirname(epanetfile)
        self.rewrite_values_in_gui_with_variables()
        return True

    def _getSaveFileName(self, *args, **kwargs):
        # why this function and _getSaveFileName2? for tests to mock this method easily.
        self.logger.info("proxy calling QFileDialog.getSaveFileName ")
        return QFileDialog.getSaveFileName(*args, **kwargs)

    def _getSaveFileName2(self, *args, **kwargs):
        # why this function and _getSaveFileName? for tests to mock this method easily.
        self.logger.info("proxy calling QFileDialog.getOpenFileName ")
        return QFileDialog.getOpenFileName(*args, **kwargs)

    def _getOpenFileName(self, *args, **kwargs):
        self.logger.info("proxy calling QFileDialog.getOpenFileName ")
        return QFileDialog.getOpenFileName(*args, **kwargs)

    def _create_empty_project(self, msg, epanetfile):
        projectfile = self.get_save_filename(msg)
        self.logger.info(
            "creating empty project with filename %s and epanetfile %s " %
            (projectfile, epanetfile))
        if (not projectfile):
            return None
        else:
            return self._save_project_to_dest(projectfile,
                                              epanetfile=epanetfile)

    def get_save_filename(self, msg):
        projectfile, filter = self._getSaveFileName(
            self.parent,
            msg,
            self.parent.LASTPROJECT or c.HOMEDIR,
            filter='*' + c.PROJECTEXTENSION)
        self.logger.info("Selected file for save/new project : %s " %
                         projectfile)
        return projectfile

    def _update_results_with_gui_values(self):
        """Update the self.projectproperties.dataset.results object with
        group information. Call this before pickling data"""
        r = self.projectproperties.dataset.results
        if (not r):
            self.logger.info(
                "No results available yet with projectproperties. So, not updating"
            )
        else:
            self.logger.info(
                "Updating projectproperties.dataset.results with my_group")
            for item in r.links:
                item.asset_group = self.parent.datawindow.get_asset_group(
                    item.id)
                item.age = self.parent.datawindow.get_age(item.id)

    def _save_project_to_dest(self, projectfile, epanetfile=None):

        self.logger.info("Getting values from datawindow..")
        # First get latest values from dataWindow
        inf = self.parent.datawindow.get_information(all=True)
        self.projectproperties.dataset.group_list_to_save_or_load = inf
        self._update_results_with_gui_values()
        self.logger.info("Now writing data")
        prjname, subdir, ext = c._get_dir_and_extention(projectfile)
        self.projectproperties.dataset.write_data(prjname)

        if (not os.path.isdir(subdir)):
            os.mkdir(subdir)
            self.logger.info("Created  directory %s" % subdir)

        if (epanetfile):
            base = os.path.basename(epanetfile)
            dst = os.path.join(os.path.dirname(prjname), base)
            shutil.copy(epanetfile, dst)
            self.projectproperties.dataset.fname = base
            self.logger.info("copied epanet file to %s" % dst)
        return prjname

    def try_loading_project_properties(self, prj):
        try:
            self.logger.info("Trying to read properties from %s " % prj)
            if (self.projectproperties.dataset.read_data(prj)):
                self.logger.info(" %s project read successfully." % prj)
                return True
        except Exception as e:
            self.logger.exception("Could not load the project properties: %s" %
                                  e)
        return False

    def save_project(self):
        self.logger.info("Saving the project")
        # Implement the actions needed to save the project here.
        # first update any user changes in parameters
        self.rewrite_values_in_variables_with_gui()
        try:
            return self._save_project_to_dest(
                self.projectproperties.dataset.projectname)
        except Exception as e:
            self.logger.exception("Exception %s " % e)
            return False

    def save_project_as(self):
        msg = "Save project as"
        self.projectproperties.dataset.projectname = self.get_save_filename(
            msg)
        if (self.projectproperties.dataset.projectname):
            return self.save_project()
        else:
            return None

    def open_project(self):
        while (True):
            projectfile, filter = self._getOpenFileName(
                self.parent,
                "Open project",
                self.parent.LASTPROJECT or c.HOMEDIR,
                filter='*' + c.PROJECTEXTENSION)
            if (not projectfile):
                return None
            projectfile, dir, ext = c._get_dir_and_extention(projectfile)
            self.logger.info("Selected file to open : %s " % projectfile)
            # check if it is a valid project
            if (self._valid_project(projectfile)):
                self.projectproperties.dataset.projectname = projectfile
                self.parent.LASTPROJECT = self.projectproperties.dataset.projectname
                self.parent._display_project()
                # now update the dataWindow with project groups in opened project
                self.parent.datawindow.set_information(
                    self.projectproperties.dataset.group_list_to_save_or_load)
                self.logger.info("Updated dataWindow with project groups")
                # since we have done both (a) displaying network and
                # (b) updating the asset groups, now we can assign correct asset group
                # to each asset item
                if (self.projectproperties.dataset.results):
                    r = self.projectproperties.dataset.results.links
                    self.parent.datawindow.assign_values_to_asset_items(r)
                break
            else:
                self.logger.info("Project loading failed: Not a valid project")
                return None

        self.logger.info("Open Project valid")
        self.rewrite_values_in_gui_with_variables()
        self.parent.apply_dataset_values()
        return (projectfile)

    def _valid_project(self, prj):
        """Check if prj represents a valid project. """
        if (not os.path.isfile(prj)):
            return False
        if (not os.path.isdir(c._get_dir_and_extention(prj)[1])):
            return False
        # Try opening
        self.logger.info("Now calling try_loading_project_properties ")
        return self.try_loading_project_properties(prj)
コード例 #11
0
ファイル: main_window.py プロジェクト: zerodeku/tracking3d
class MainWindow(Thread, QMainWindow):
    def __init__(self):
        # init main panel
        QMainWindow.__init__(self, None)
#        QMainWindow.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
        Thread.__init__(self)
        widget = QWidget()
        self.setCentralWidget(widget)
        self.setWindowTitle('3D tracking')
        self.move(600, 150)
        # define main objects
        self.tracking = tracking_3d.Tracking3D.getInstance()
        
        # init dataset from gui_construction
        self.gb_sequence = DataSetEditGroupBox("Sequence", 
                    gui_construction.RemoteParameters, comment='')
        self.gb_sample = DataSetEditGroupBox("Sample", 
                    gui_construction.SampleParameters, comment='')
        self.gb_tracking = DataSetEditGroupBox("Tracking", 
                    gui_construction.TrackingParameters, comment='')
            
        self.btn_process = QPushButton("Start tracking", self)
        self.btn_process.clicked.connect(self.start_tracking)

        # associate events to dataset apply buttons
        self.connect(self.gb_sequence, SIGNAL("apply_button_clicked()"), 
                     self.update_remote_params)
        self.connect(self.gb_tracking, SIGNAL("apply_button_clicked()"), 
                     self.update_tracking_params)     
        self.connect(self.gb_sample, SIGNAL("apply_button_clicked()"), 
                     self.update_sample_parameters)
                     
        # organize the app panels
        splitter1 = QSplitter(QtCore.Qt.Vertical)
        splitter1.addWidget(self.gb_sequence)
        splitter1.addWidget(self.gb_sample)
        splitter1.addWidget(self.gb_tracking)
        splitter1.addWidget(self.btn_process)
        
        splitter = QSplitter(self)
        splitter.addWidget(splitter1)
        self.setCentralWidget(splitter)
        self.setContentsMargins(10, 5, 10, 5)   
        
        # get all params from datasets
        self.gb_sequence.get()
        self.gb_sample.get()
        self.gb_tracking.get()
        
    # when the main program is closed
    def closeEvent(self, event):
        remoteKoala = self.tracking.remoteKoala
        if remoteKoala is not None and remoteKoala.connected:
            self.tracking.remoteKoala.remoteCommands.ResetCorrSegments()
            self.tracking.remoteKoala.CloseConnection()

    # update the remote parameters
    def update_remote_params(self):
        utils.Log("Sequence parameters initialized")
        self.tracking.initRemoteKoala(self.gb_sequence.dataset)
        self.gb_sequence.dataset.last_holo_seq = \
                    (int)(self.tracking.remoteKoala.framesNumber) - 1
        self.gb_sequence.get()
#        self.gb_sequence.setEnabled(False)
        self.tracking.setupKoala()
    
    def update_sample_parameters(self):
        utils.Log("Sample paramters initialized")
        self.tracking.initSampleParams(self.gb_sample.dataset)
      
    # update tracking parameters 
    def update_tracking_params(self):
        utils.Log("Tracking paramters initialized")
        self.tracking.initTrackingParams(self.gb_tracking.dataset)
        self.gb_tracking.dataset.samplePlaneStepUM = self.tracking.stepUM
        self.gb_tracking.dataset.stackHeightUM = self.tracking.stackHeightUM
        self.gb_tracking.get()
        
    # initiate tracking process
    def start_tracking(self):
        utils.Log("Start tracking process")
        self.tracking.performTracking()
コード例 #12
0
class MainWindow(Thread, QMainWindow):
    def __init__(self):
        # init main panel
        QMainWindow.__init__(self, None)
        #        QMainWindow.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
        Thread.__init__(self)
        widget = QWidget()
        self.setCentralWidget(widget)
        self.setWindowTitle('3D tracking')
        self.move(600, 150)
        # define main objects
        self.tracking = tracking_3d.Tracking3D.getInstance()

        # init dataset from gui_construction
        self.gb_sequence = DataSetEditGroupBox(
            "Sequence", gui_construction.RemoteParameters, comment='')
        self.gb_sample = DataSetEditGroupBox("Sample",
                                             gui_construction.SampleParameters,
                                             comment='')
        self.gb_tracking = DataSetEditGroupBox(
            "Tracking", gui_construction.TrackingParameters, comment='')

        self.btn_process = QPushButton("Start tracking", self)
        self.btn_process.clicked.connect(self.start_tracking)

        # associate events to dataset apply buttons
        self.connect(self.gb_sequence, SIGNAL("apply_button_clicked()"),
                     self.update_remote_params)
        self.connect(self.gb_tracking, SIGNAL("apply_button_clicked()"),
                     self.update_tracking_params)
        self.connect(self.gb_sample, SIGNAL("apply_button_clicked()"),
                     self.update_sample_parameters)

        # organize the app panels
        splitter1 = QSplitter(QtCore.Qt.Vertical)
        splitter1.addWidget(self.gb_sequence)
        splitter1.addWidget(self.gb_sample)
        splitter1.addWidget(self.gb_tracking)
        splitter1.addWidget(self.btn_process)

        splitter = QSplitter(self)
        splitter.addWidget(splitter1)
        self.setCentralWidget(splitter)
        self.setContentsMargins(10, 5, 10, 5)

        # get all params from datasets
        self.gb_sequence.get()
        self.gb_sample.get()
        self.gb_tracking.get()

    # when the main program is closed
    def closeEvent(self, event):
        remoteKoala = self.tracking.remoteKoala
        if remoteKoala is not None and remoteKoala.connected:
            self.tracking.remoteKoala.remoteCommands.ResetCorrSegments()
            self.tracking.remoteKoala.CloseConnection()

    # update the remote parameters
    def update_remote_params(self):
        utils.Log("Sequence parameters initialized")
        self.tracking.initRemoteKoala(self.gb_sequence.dataset)
        self.gb_sequence.dataset.last_holo_seq = \
                    (int)(self.tracking.remoteKoala.framesNumber) - 1
        self.gb_sequence.get()
        #        self.gb_sequence.setEnabled(False)
        self.tracking.setupKoala()

    def update_sample_parameters(self):
        utils.Log("Sample paramters initialized")
        self.tracking.initSampleParams(self.gb_sample.dataset)

    # update tracking parameters
    def update_tracking_params(self):
        utils.Log("Tracking paramters initialized")
        self.tracking.initTrackingParams(self.gb_tracking.dataset)
        self.gb_tracking.dataset.samplePlaneStepUM = self.tracking.stepUM
        self.gb_tracking.dataset.stackHeightUM = self.tracking.stackHeightUM
        self.gb_tracking.get()

    # initiate tracking process
    def start_tracking(self):
        utils.Log("Start tracking process")
        self.tracking.performTracking()
コード例 #13
0
class MathPanel(PlotPanel):
    class cSet(DataSet):
        _bg1 = BeginGroup("Source 1").set_pos(0)
        tab1 = ChoiceItem("Tab", ['a'])
        data1 = ChoiceItem("Data", ['a'])
        _eg1 = EndGroup("")

        _bg2 = BeginGroup("Source 2").set_pos(1)
        tab2 = ChoiceItem("Tab", ['a'])
        data2 = ChoiceItem("Data", ['a'])
        _eg2 = EndGroup("")

        _bg3 = BeginGroup("Operation").set_pos(2)
        function = ChoiceItem("Function", [('y1-y2', 'y1-y2'),
                                           ('y1+y2', 'y1+y2'),
                                           ('y1/y2', 'y1/y2'),
                                           ('custom', 'f(x,y1,y2)')])
        custom = StringItem("f(x,y1,y2):")
        _eg3 = EndGroup("")

        text = TextItem("").set_pos(3)

    def __init__(self, parent):
        plots=\
         [[
          {'name':'Source 1','curves':['in1']},
          {'name':'Source 2','curves':['in2']}],
         [
          {'name':'Result','curves':['out']},
         ]]

        self.tabs = parent.sp

        df = [n.axisLimits[1] - n.axisLimits[0] for n in self.tabs]
        df2 = max(df) / 2

        axisLimits = [
            -df2, df2,
            min([n.axisLimits[2] for n in self.tabs]),
            max([n.axisLimits[3] for n in self.tabs])
        ]

        PlotPanel.__init__(self,
                           parent=parent,
                           plots=plots,
                           axisLimits=axisLimits)

        self._cBox = DataSetEditGroupBox("Control",
                                         self.cSet,
                                         show_button=False)
        self.addWidget(self._cBox)

        tabchoices = [(m, n.name, None) for m, n in enumerate(self.tabs)]
        curvechoices = [(n, n, None) for n in self.tabs[0].curves.keys()]

        self.cSet._items[1].set_prop('data', choices=tabchoices)
        self._cBox.dataset.tab1 = 0
        self.cSet._items[2].set_prop('data', choices=curvechoices)
        self._cBox.dataset.data1 = curvechoices[0][0]
        self.cSet._items[5].set_prop('data', choices=tabchoices)
        self._cBox.dataset.tab2 = 0
        self.cSet._items[6].set_prop('data', choices=curvechoices)
        self._cBox.dataset.data2 = curvechoices[0][0]
        self._cBox.get()

    def refreshTab(self):
        if self.curves is None: return
        self._cBox.set()
        d = self._cBox.dataset
        tab1, tab2 = self.tabs[d.tab1], self.tabs[d.tab2]

        x1, y1 = tab1.getx(), tab1.curves[d.data1].y
        x2, y2 = tab2.getx(), tab2.curves[d.data2].y

        if x1 is None or x2 is None: return

        x_min = min(min(x1), min(x2))
        x_max = max(max(x1), max(x2))
        dx1 = x1[1] - x1[0] if len(x1) > 1 else 1e9
        dx2 = x2[1] - x2[0] if len(x2) > 1 else 1e9
        dx = min(dx1, dx2)

        x = np.arange(x_min, x_max, dx)
        y1 = np.interp(x, x1, y1, left=0, right=0)
        y2 = np.interp(x, x2, y2, left=0, right=0)

        fun = self._cBox.dataset.function
        if fun == 'custom': fun = self._cBox.dataset.custom

        try:
            y = eval(fun)
        except:
            y = x * 0.

        self.curves['in1'].setplot(x, y1)
        self.curves['in2'].setplot(x, y2)
        self.curves['out'].setplot(x, y)