Пример #1
0
    def selection_table_selection_changed(self):

        # update table and then update GUI
        selection = self.ui.selection_table.selectedRanges()
        nbr_row = self.ui.selection_table.rowCount()

        table_dictionary = self.parent.table_dictionary

        for _entry in table_dictionary.keys():
            table_dictionary[_entry]['active'] = False

        for _select in selection:
            top_row = _select.topRow()
            left_col = _select.leftColumn()
            bottom_row = _select.bottomRow()
            right_col = _select.rightColumn()
            for _row in np.arange(top_row, bottom_row + 1):
                for _col in np.arange(left_col, right_col + 1):
                    fitting_row = _col * nbr_row + _row
                    _entry = table_dictionary[str(fitting_row)]
                    _entry['active'] = True
                    table_dictionary[str(fitting_row)] = _entry

        self.parent.table_dictionary = table_dictionary
        o_filling_table = FillingTableHandler(parent=self.parent)

        self.parent.fitting_ui.ui.value_table.blockSignals(True)
        o_filling_table.fill_table()
        self.parent.fitting_ui.ui.value_table.blockSignals(False)
        self.parent.fitting_ui.update_image_view_selection()
        self.parent.fitting_ui.update_bragg_edge_plot()
Пример #2
0
    def unselect_all(self):

        QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)

        o_table = TableDictionaryHandler(parent=self.parent)
        o_table.unselect_full_table()

        o_fitting = FillingTableHandler(parent=self.parent)
        o_fitting.fill_table()

        self.parent.fitting_ui.selection_in_value_table_of_rows_cell_clicked(
            -1, -1)

        #if self.parent.advanced_selection_ui:
        #self.parent.advanced_selection_ui.ui.selection_table.blockSignals(True)
        #nbr_row = self.parent.fitting_ui.ui.value_table.rowCount()
        #nbr_column = self.parent.fitting_ui.ui.value_table.columnCount()
        #_selection_range = QtGui.QTableWidgetSelectionRange(0, 0, nbr_row-1, nbr_column-1)
        #self.parent.fitting_ui.ui.value_table.setRangeSelected(_selection_range, False)
        #o_fitting = FillingTableHandler(parent=self.parent)
        #o_fitting.unselect_full_table()
        #self.parent.fitting_ui.selection_in_value_table_of_rows_cell_clicked(-1, -1)
        #if self.parent.advanced_selection_ui:
        #self.parent.advanced_selection_ui.ui.selection_table.blockSignals(False)

        QApplication.restoreOverrideCursor()
 def update_table(self):
     QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
     variable_selected = self.get_variable_selected()
     o_handler = SetFittingVariablesHandler(parent=self.parent)
     o_handler.populate_table_with_variable(variable=variable_selected)
     o_filling_table = FillingTableHandler(parent=self.parent)
     self.parent.fitting_ui.ui.value_table.blockSignals(True)
     o_filling_table.fill_table()
     self.parent.fitting_ui.ui.value_table.blockSignals(False)
     QApplication.restoreOverrideCursor()
    def update_fitting_ui(self, name='active'):
        if name == 'lock':
            self.parent.fitting_ui.update_image_view_lock()
        elif name == 'active':
            self.parent.fitting_ui.update_image_view_selection()

        o_filling_table = FillingTableHandler(parent=self.parent)
        self.parent.fitting_ui.ui.value_table.blockSignals(True)
        o_filling_table.fill_table()

        self.parent.fitting_ui.ui.value_table.blockSignals(False)
Пример #5
0
    def fill_table(self):
        if len(
                np.array(self.parent.data_metadata['normalized']
                         ['data_live_selection'])) == 0:
            return

        if not self.parent.fitting_ui.there_is_a_roi:
            return

        o_table = TableDictionaryHandler(parent=self.parent)
        o_table.create_table_dictionary()

        o_fill_table = FillingTableHandler(parent=self.parent)
        o_fill_table.fill_table()
 def apply_new_value_to_selection(self):
     variable_selected = self.get_variable_selected()
     selection = self.parent.fitting_set_variables_ui.ui.variable_table.selectedRanges(
     )
     o_handler = SetFittingVariablesHandler(parent=self.parent)
     new_variable = np.float(
         str(self.parent.fitting_set_variables_ui.ui.new_value_text_edit.
             text()))
     o_handler.set_new_value_to_selected_bins(
         selection=selection,
         variable_name=variable_selected,
         variable_value=new_variable,
         table_nbr_row=self.nbr_row)
     self.parent.fitting_set_variables_ui.ui.new_value_text_edit.setText('')
     o_filling_table = FillingTableHandler(parent=self.parent)
     self.parent.fitting_ui.ui.value_table.blockSignals(True)
     o_filling_table.fill_table()
     self.parent.fitting_ui.ui.value_table.blockSignals(False)
Пример #7
0
    def changed_fixed_variables_status(self, status=True):
        selection = self.parent.fitting_ui.ui.value_table.selectedRanges()
        nbr_row = self.parent.fitting_ui.ui.value_table.rowCount()

        o_fill_table = FillingTableHandler(parent=self.parent)
        row_to_show_status = o_fill_table.get_row_to_show_state()

        table_dictionary = self.parent.table_dictionary

        column_variable_match = {
            5: 'd_spacing',
            7: 'sigma',
            9: 'alpha',
            11: 'a1',
            13: 'a2',
            15: 'a5',
            17: 'a7',
        }

        for _select in selection:
            left_column = _select.leftColumn()
            right_column = _select.rightColumn()
            col_range = np.arange(left_column, right_column + 1)
            for _col in col_range:

                if _col < 5:
                    continue

                # only work with even col number
                if (_col % 2) == 0:
                    continue

                name_variable = column_variable_match.get(_col)

                for _index in np.arange(nbr_row):

                    _entry = table_dictionary[str(_index)]
                    if _entry['lock']:
                        continue

                    if row_to_show_status == 'all':

                        _entry[name_variable]['fixed'] = status
                        table_dictionary[str(_index)] = _entry

                    elif row_to_show_status == 'active':

                        if _entry['active']:
                            _entry[name_variable]['fixed'] = status
                            table_dictionary[str(_index)] = _entry

            self.parent.table_dictionary = table_dictionary

            o_fitting = FillingTableHandler(parent=self.parent)
            o_fitting.fill_table()
Пример #8
0
    def roi_selection_widgets_modified(self):
                
        if self.data == []:
            return
        
        QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
        
        self.parent.table_dictionary = {}
        
        if self.parent.binning_line_view['ui']:
            _image_view = self.parent.binning_line_view['image_view']
            _image_view.removeItem(self.parent.binning_line_view['ui'])
            self.parent.binning_line_view['ui'] = None
            
        x0 = self.get_correct_widget_value(ui = self.ui.selection_x0,
                                               variable_name = 'x0')
        y0 = self.get_correct_widget_value(ui = self.ui.selection_y0,
                                               variable_name = 'y0')
        width = self.get_correct_widget_value(ui = self.ui.selection_width,
                                                  variable_name = 'width')
        height = self.get_correct_widget_value(ui = self.ui.selection_height,
                                                   variable_name = 'height')
        bin_size = self.get_correct_widget_value(ui = self.ui.pixel_bin_size,
                                                         variable_name = 'bin_size')        
        
        self.parent.binning_bin_size = bin_size
        self.parent.binning_done = True        
    
        #self.widgets_ui['roi'].setPos([x0, y0], update=False, finish=False)
        #self.widgets_ui['roi'].setSize([width, height], update=False, finish=False)
    
        self.parent.binning_line_view['roi'].setPos([x0, y0], update=False, finish=False)
        self.parent.binning_line_view['roi'].setSize([width, height], update=False, finish=False)

        pos_adj_dict = self.calculate_matrix_of_pixel_bins(bin_size=bin_size,
                                                               x0=x0,
                                                               y0=y0,
                                                               width=width,
                                                               height=height)
    
        pos = pos_adj_dict['pos']
        adj = pos_adj_dict['adj']

        line_color = (255,0,0,255,1)    
        lines = np.array([line_color for n in np.arange(len(pos))],
                             dtype=[('red',np.ubyte),('green',np.ubyte),
                                   ('blue',np.ubyte),('alpha',np.ubyte),
                                   ('width',float)]) 
    

        self.parent.binning_line_view['pos'] = pos
        self.parent.binning_line_view['adj'] = adj
        self.parent.binning_line_view['pen'] = lines

        self.update_binning_bins()

        if self.parent.fitting_ui:
            
            self.parent.fitting_ui.check_status_widgets()
            
            o_table = TableDictionaryHandler(parent=self.parent)
            o_table.create_table_dictionary()
            
            o_fitting = FillingTableHandler(parent=self.parent)
            o_fitting.fill_table()
            
            self.parent.fitting_ui.selection_in_value_table_of_rows_cell_clicked(-1, -1)
            
            o_hanlder = FittingHandler(parent=self.parent)

            o_hanlder.display_roi()
            
            
        #if self.parent.fitting_ui:
            #if self.parent.fitting_ui.line_view:
                #if self.parent.fitting_ui.line_view in self.parent.fitting_ui.image_view.children():
                    #self.parent.fitting_ui.image_view.removeItem(self.parent.fitting_ui.line_view)
                #self.parent.fitting_ui.line_view = None
                    
            ## remove pre-defined lock and selected item
            #table_dictionary = self.parent.fitting_ui.table_dictionary
            #for _entry in table_dictionary.keys():
                #if table_dictionary[_entry]['selected_item'] in self.parent.fitting_ui.image_view.children():
                    #self.parent.fitting_ui.image_view.removeItem(table_dictionary[_entry]['selected_item'])
                #if table_dictionary[_entry]['locked_item'] in self.parent.fitting_ui.image_view.children():
                    #self.parent.fitting_ui.image_view.removeItem(table_dictionary[_entry]['locked_item'])
        
        #self.line_view_binning = line_view_binning
        #self.pos = pos
        #self.adj = adj
        #self.lines = lines
        
        #if self.parent.fitting_ui:
            
            #o_fitting_ui = FittingHandler(parent=self.parent)
            #o_fitting_ui.display_image()
            #o_fitting_ui.display_roi()
            #o_fitting_ui.fill_table()

        QApplication.restoreOverrideCursor()
Пример #9
0
 def update_table(self):
     o_filling_table = FillingTableHandler(parent=self.parent)
     self.parent.fitting_ui.ui.value_table.blockSignals(True)
     o_filling_table.fill_table()
     self.parent.fitting_ui.ui.value_table.blockSignals(False)
Пример #10
0
 def advanced_table_clicked(self, status):
     QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
     o_table_handler = FillingTableHandler(parent=self.parent)
     o_table_handler.set_mode(advanced_mode=status)
     QApplication.restoreOverrideCursor()
Пример #11
0
    def lock_button_state_changed(self, status, row_clicked):
        '''
        status: 0: off
                2: on
                
        we also need to make sure that if the button is lock, it can not be activated !
                
        '''
        update_selection_flag = False

        if self.parent.advanced_selection_ui:
            self.parent.advanced_selection_ui.ui.lock_table.blockSignals(True)

        if status == 0:
            status = False
        else:
            status = True

        # perform same status on all rows
        _selection = self.ui.value_table.selectedRanges()
        _this_column_is_selected = False
        for _select in _selection:
            if 2 in [_select.leftColumn(), _select.rightColumn()]:
                _this_column_is_selected = True
                break

        table_dictionary = self.parent.table_dictionary
        if _this_column_is_selected:
            update_selection_flag = True  #we change the state so we need to update the selection
            for _index in table_dictionary:
                table_dictionary[_index]['lock'] = status
                _widget_lock = self.ui.value_table.cellWidget(int(_index), 2)
                _widget_lock.blockSignals(True)
                _widget_lock.setChecked(status)
                _widget_lock.blockSignals(False)
                if status:
                    _widget = self.ui.value_table.cellWidget(int(_index), 3)
                    if _widget.isChecked(
                    ):  # because we can not be active and locked at the same time
                        table_dictionary[_index]['active'] = False
                        _widget.blockSignals(True)
                        _widget.setChecked(False)
                        _widget.blockSignals(False)
        else:
            table_dictionary[str(row_clicked)]['lock'] = status
            if status:
                _widget = self.ui.value_table.cellWidget(row_clicked, 3)
                if _widget.isChecked(
                ):  # because we can not be active and locked at the same time
                    table_dictionary[str(row_clicked)]['active'] = False
                    _widget.blockSignals(True)
                    _widget.setChecked(False)
                    _widget.blockSignals(False)
                    update_selection_flag = True  #we change the state so we need to update the selection

        self.parent.table_dictionary = table_dictionary

        # hide this row if status is False and user only wants to see locked items
        o_filling_handler = FillingTableHandler(parent=self.parent)
        if (status == False) and (o_filling_handler.get_row_to_show_state()
                                  == 'lock'):
            self.parent.fitting_ui.ui.value_table.hideRow(row_clicked)

        o_bin_handler = SelectedBinsHandler(parent=self.parent)
        o_bin_handler.update_bins_locked()
        self.update_bragg_edge_plot()
        o_bin_handler.update_bins_selected()

        if self.parent.advanced_selection_ui:
            self.parent.advanced_selection_ui.update_lock_table()
            if update_selection_flag:
                self.parent.advanced_selection_ui.update_selection_table()
            self.parent.advanced_selection_ui.ui.lock_table.blockSignals(False)