Esempio n. 1
0
    def make_filter_box(self):
        filter_box = QtWidgets.QWidget()
        layout = QtWidgets.QGridLayout()
        layout.setSpacing(10)
        prefix_label = QtWidgets.QLabel('File Prefix')
        self.prefix_box = QtWidgets.QLineEdit()
        self.prefix_box.editingFinished.connect(self.set_range)
        extension_label = QtWidgets.QLabel('File Extension')
        self.extension_box = QtWidgets.QLineEdit()
        self.extension_box.editingFinished.connect(self.set_extension)
        suffix_label = QtWidgets.QLabel('File Suffix')
        self.suffix_box = QtWidgets.QLineEdit('')
        self.suffix_box.editingFinished.connect(self.get_prefixes)
        layout.addWidget(prefix_label, 0, 0)
        layout.addWidget(self.prefix_box, 0, 1)
        layout.addWidget(extension_label, 0, 2)
        layout.addWidget(self.extension_box, 0, 3)
        layout.addWidget(suffix_label, 0, 4)
        layout.addWidget(self.suffix_box, 0, 5)
        self.prefix_combo = QtWidgets.QComboBox()
        self.prefix_combo.setSizeAdjustPolicy(
            QtWidgets.QComboBox.AdjustToContents)
        self.prefix_combo.activated.connect(self.choose_prefix)
        self.extension_combo = QtWidgets.QComboBox()
        self.extension_combo.setSizeAdjustPolicy(
            QtWidgets.QComboBox.AdjustToContents)
        self.extension_combo.activated.connect(self.choose_extension)
        layout.addWidget(self.prefix_combo, 1, 1, alignment=QtCore.Qt.AlignHCenter)
        layout.addWidget(self.extension_combo, 1, 3, alignment=QtCore.Qt.AlignHCenter)

        filter_box.setLayout(layout)
        filter_box.setVisible(False)
        return filter_box
Esempio n. 2
0
    def add_grid_headers(self):
        self.header_grid = QtWidgets.QGridLayout()
        self.header_widget = NXWidget()
        self.header_widget.set_layout(self.header_grid)

        row = 0
        columns = [
            'Scan', 'data', 'link', 'copy', 'max', 'find', 'refine', 'prepare',
            'transform', 'masked_transform', 'combine', 'masked_combine',
            'pdf', 'masked_pdf', 'overwrite', 'sync'
        ]
        header = {}
        for col, column in enumerate(columns):
            header[column] = NXLabel(column,
                                     bold=True,
                                     width=75,
                                     align='center')
            if column == 'transform' or column == 'combine' or column == 'pdf':
                self.header_grid.addWidget(header[column], row, col, 1, 2,
                                           QtCore.Qt.AlignHCenter)
            elif 'masked' not in column:
                self.header_grid.addWidget(header[column], row, col)
                header[column].setAlignment(QtCore.Qt.AlignHCenter)
        row = 1
        columns = 3 * ['regular', 'masked']
        for col, column in enumerate(columns):
            header[column] = NXLabel(column, width=75, align='center')
            self.header_grid.addWidget(header[column], row, col + 8)
        self.header_grid.setSpacing(0)
        self.header_widget.setFixedHeight(60)
        self.insert_layout(2, self.header_widget)
Esempio n. 3
0
    def __init__(self, parent=None):
        super(TransformDialog, self).__init__(parent)

        self.select_entry(self.initialize_grid)
        self.refine = NXRefine()

        grid = QtWidgets.QGridLayout()
        grid.setSpacing(10)
        header_font = QtGui.QFont()
        header_font.setBold(True)
        start_label = QtWidgets.QLabel('Start')
        start_label.setFont(header_font)
        grid.addWidget(start_label, 0, 1)
        step_label = QtWidgets.QLabel('Step')
        step_label.setFont(header_font)
        grid.addWidget(step_label, 0, 2)
        stop_label = QtWidgets.QLabel('Stop')
        stop_label.setFont(header_font)
        grid.addWidget(stop_label, 0, 3)
        grid.addWidget(QtWidgets.QLabel('H:'), 1, 0)
        grid.addWidget(QtWidgets.QLabel('K:'), 2, 0)
        grid.addWidget(QtWidgets.QLabel('L:'), 3, 0)
        self.start_h_box = QtWidgets.QLineEdit()
        self.step_h_box = QtWidgets.QLineEdit()
        self.stop_h_box = QtWidgets.QLineEdit()
        grid.addWidget(self.start_h_box, 1, 1)
        grid.addWidget(self.step_h_box, 1, 2)
        grid.addWidget(self.stop_h_box, 1, 3)
        self.start_k_box = QtWidgets.QLineEdit()
        self.step_k_box = QtWidgets.QLineEdit()
        self.stop_k_box = QtWidgets.QLineEdit()
        grid.addWidget(self.start_k_box, 2, 1)
        grid.addWidget(self.step_k_box, 2, 2)
        grid.addWidget(self.stop_k_box, 2, 3)
        self.start_l_box = QtWidgets.QLineEdit()
        self.step_l_box = QtWidgets.QLineEdit()
        self.stop_l_box = QtWidgets.QLineEdit()
        grid.addWidget(self.start_l_box, 3, 1)
        grid.addWidget(self.step_l_box, 3, 2)
        grid.addWidget(self.stop_l_box, 3, 3)
        self.set_layout(
            self.entry_layout, grid,
            self.checkboxes(
                ('copy', 'Copy to all entries', True),
                ('mask', 'Create masked transform group', True),
                ('overwrite', 'Overwrite existing transforms', False)),
            self.close_buttons(save=True))
        self.setWindowTitle('Transforming Data')
        try:
            self.initialize_grid()
        except Exception:
            pass
Esempio n. 4
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.select_entry(self.choose_entry)

        self.Qgrid = QtWidgets.QGridLayout()
        self.Qgrid.setSpacing(10)
        headers = ['Axis', 'Q', 'dQ', 'N', 'Max']
        width = [25, 50, 50, 25, 50]
        column = 0
        for header in headers:
            label = NXLabel(header, bold=True, align='center')
            self.Qgrid.addWidget(label, 0, column)
            self.Qgrid.setColumnMinimumWidth(column, width[column])
            column += 1
        self.Qbox = {}
        self.dQbox = {}
        self.Nbox = {}
        self.maxbox = {}
        for i, label in enumerate(['H', 'K', 'L']):
            self.Qgrid.addWidget(NXLabel(label, align='center'), i + 1, 0)
            self.Qbox[label] = NXLineEdit(slot=self.calculate,
                                          width=100,
                                          align='right')
            self.Qgrid.addWidget(self.Qbox[label], i + 1, 1)
            self.dQbox[label] = NXLineEdit(slot=self.calculate,
                                           width=100,
                                           align='right')
            self.Qgrid.addWidget(self.dQbox[label], i + 1, 2)
            self.Nbox[label] = NXLabel(align='center')
            self.Qgrid.addWidget(self.Nbox[label], i + 1, 3)
            self.maxbox[label] = NXLabel(align='center')
            self.Qgrid.addWidget(self.maxbox[label], i + 1, 4)
        self.set_layout(self.entry_layout, self.close_buttons(save=True))
        self.setWindowTitle('Transforming Data')
        try:
            self.initialize_grid()
        except Exception:
            pass
Esempio n. 5
0
    def update(self):
        if not self.sample_directory:
            raise NeXusError("No sample directory declared")

        if self.grid:
            self.delete_grid(self.grid)
            del self.grid_widget

        if self.scroll_area:
            self.scroll_area.close()
            self.scroll_area.deleteLater()

        # Map from wrapper files to scan directories
        wrapper_files = {
            w: self.get_scan(w)
            for w in sorted([
                os.path.join(self.sample_directory, filename)
                for filename in os.listdir(self.sample_directory)
                if self.is_valid(filename)
            ],
                            key=natural_sort)
        }
        self.grid = QtWidgets.QGridLayout()
        self.grid_widget = NXWidget()
        self.grid_widget.set_layout(self.grid, 'stretch')
        self.scroll_area = NXScrollArea(self.grid_widget)
        self.scroll_area.setMinimumSize(1250, 300)
        self.insert_layout(3, self.scroll_area)
        self.grid.setSpacing(1)

        self.scans = {}
        self.scans_backup = {}

        row = 0
        # Create (unchecked) checkboxes
        for wrapper_file, scan in wrapper_files.items():
            scan_label = os.path.basename(scan)
            status = {}
            status['scan'] = NXLabel(scan_label)
            if self.parent_file == wrapper_file:
                status['scan'].setStyleSheet('font-weight:bold')
            status['entries'] = []
            status['data'] = self.new_checkbox()
            status['link'] = self.new_checkbox()
            status['copy'] = self.new_checkbox()
            status['max'] = self.new_checkbox()
            status['find'] = self.new_checkbox()
            status['refine'] = self.new_checkbox()
            status['prepare'] = self.new_checkbox()
            status['transform'] = self.new_checkbox()
            status['masked_transform'] = self.new_checkbox()
            status['combine'] = self.new_checkbox()
            status['masked_combine'] = self.new_checkbox()
            status['pdf'] = self.new_checkbox()
            status['masked_pdf'] = self.new_checkbox()
            status['overwrite'] = self.new_checkbox(self.select_scans)
            status['sync'] = self.new_checkbox()
            self.grid.addWidget(status['scan'], row, 0, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['data'], row, 1, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['link'], row, 2, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['copy'], row, 3, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['max'], row, 4, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['find'], row, 5, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['refine'], row, 6,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['prepare'], row, 7,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['transform'], row, 8,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_transform'], row, 9,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['combine'], row, 10,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_combine'], row, 11,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['pdf'], row, 12, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_pdf'], row, 13,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['overwrite'], row, 14,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['sync'], row, 15, QtCore.Qt.AlignCenter)
            self.scans[scan] = status
            row += 1
        self.grid.addWidget(NXLabel('All'), row, 0, QtCore.Qt.AlignCenter)
        all_boxes = {}
        all_boxes['link'] = self.new_checkbox(
            lambda: self.select_status('link'))
        all_boxes['copy'] = self.new_checkbox(
            lambda: self.select_status('copy'))
        all_boxes['max'] = self.new_checkbox(lambda: self.select_status('max'))
        all_boxes['find'] = self.new_checkbox(
            lambda: self.select_status('find'))
        all_boxes['refine'] = self.new_checkbox(
            lambda: self.select_status('refine'))
        all_boxes['prepare'] = self.new_checkbox(
            lambda: self.select_status('prepare'))
        all_boxes['transform'] = self.new_checkbox(
            lambda: self.select_status('transform'))
        all_boxes['masked_transform'] = self.new_checkbox(
            lambda: self.select_status('masked_transform'))
        all_boxes['combine'] = self.new_checkbox(
            lambda: self.select_status('combine'))
        all_boxes['masked_combine'] = self.new_checkbox(
            lambda: self.select_status('masked_combine'))
        all_boxes['pdf'] = self.new_checkbox(lambda: self.select_status('pdf'))
        all_boxes['masked_pdf'] = self.new_checkbox(
            lambda: self.select_status('masked_pdf'))
        all_boxes['overwrite'] = self.new_checkbox(self.select_all)
        all_boxes['sync'] = self.new_checkbox(self.select_all)
        self.grid.addWidget(all_boxes['link'], row, 2, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['copy'], row, 3, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['max'], row, 4, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['find'], row, 5, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['refine'], row, 6, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['prepare'], row, 7,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['transform'], row, 8,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_transform'], row, 9,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['combine'], row, 10,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_combine'], row, 11,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['pdf'], row, 12, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_pdf'], row, 13,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['overwrite'], row, 14,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['sync'], row, 15, QtCore.Qt.AlignCenter)
        self.all_scans = all_boxes
        self.start_progress((0, len(wrapper_files)))

        # Populate the checkboxes based on the entries in self.db.File
        for i, (wrapper, scan) in enumerate(wrapper_files.items()):
            status = self.scans[scan]
            status['data'].setEnabled(False)
            f = self.db.get_file(wrapper)
            status['entries'] = f.get_entries()
            for task_name in self.db.task_names:
                # Database columns use nx* names while columns don't
                if task_name.startswith('nx'):
                    col_name = task_name[2:]
                else:
                    col_name = task_name
                checkbox = status[col_name]
                file_status = getattr(f, task_name)
                if file_status == self.db.DONE:
                    checkbox.setCheckState(QtCore.Qt.Checked)
                    checkbox.setEnabled(False)
                elif file_status == self.db.IN_PROGRESS:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                    checkbox.setStyleSheet("color: green")
                elif file_status == self.db.QUEUED:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                    checkbox.setStyleSheet("color: blue")
                elif file_status == self.db.FAILED:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                    checkbox.setStyleSheet("color: red")
            if status['data'].checkState() == QtCore.Qt.Unchecked:
                for task in [
                        'link', 'max', 'find', 'prepare', 'transform',
                        'masked_transform'
                ]:
                    status[task].setEnabled(False)
            self.update_progress(i)

        self.stop_progress()
        self.backup_scans()
        return self.grid
Esempio n. 6
0
    def update(self):
        if not self.sample_directory:
            raise NeXusError("No sample directory declared")

        if self.grid:
            self.delete_grid(self.grid)

        # Map from wrapper files to scan directories
        wrapper_files = {
            w: self.get_scan(w)
            for w in sorted([
                os.path.join(self.sample_directory, filename)
                for filename in os.listdir(self.sample_directory)
                if self.is_valid(filename)
            ],
                            key=natural_sort)
        }
        self.grid = QtWidgets.QGridLayout()
        self.insert_layout(2, self.grid)
        self.grid.setSpacing(1)
        row = 0
        columns = [
            'Scan', 'data', 'link', 'max', 'find', 'copy', 'refine',
            'transform', 'masked_transform', 'combine', 'masked_combine',
            'pdf', 'overwrite', 'reduce', 'sync'
        ]
        header = {}
        for col, column in enumerate(columns):
            header[column] = QtWidgets.QLabel(column)
            header[column].setFont(self.bold_font)
            header[column].setFixedWidth(75)
            if column == 'transform' or column == 'combine':
                self.grid.addWidget(header[column], row, col, 1, 2,
                                    QtCore.Qt.AlignHCenter)
            elif 'masked' not in column:
                self.grid.addWidget(header[column], row, col)
                header[column].setAlignment(QtCore.Qt.AlignHCenter)
        row = 1
        columns = ['regular', 'masked', 'regular', 'masked']
        for col, column in enumerate(columns):
            header[column] = QtWidgets.QLabel(column)
            header[column].setFixedWidth(75)
            header[column].setAlignment(QtCore.Qt.AlignHCenter)
            self.grid.addWidget(header[column], row, col + 7)

        self.scans = {}
        self.scans_backup = {}

        # Create (unchecked) checkboxes
        for wrapper_file, scan in wrapper_files.items():
            scan_label = os.path.basename(scan)
            row += 1
            status = {}
            status['scan'] = QtWidgets.QLabel(scan_label)
            if self.parent_file == wrapper_file:
                status['scan'].setStyleSheet('font-weight:bold')
            status['data'] = self.new_checkbox()
            status['link'] = self.new_checkbox()
            status['max'] = self.new_checkbox()
            status['find'] = self.new_checkbox()
            status['copy'] = self.new_checkbox()
            status['refine'] = self.new_checkbox()
            status['transform'] = self.new_checkbox()
            status['masked_transform'] = self.new_checkbox()
            status['combine'] = self.new_checkbox()
            status['masked_combine'] = self.new_checkbox()
            status['pdf'] = self.new_checkbox()
            status['overwrite'] = self.new_checkbox(self.select_scans)
            status['reduce'] = self.new_checkbox(self.select_scans)
            status['sync'] = self.new_checkbox()
            self.grid.addWidget(status['scan'], row, 0, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['data'], row, 1, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['link'], row, 2, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['max'], row, 3, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['find'], row, 4, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['copy'], row, 5, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['refine'], row, 6,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['transform'], row, 7,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_transform'], row, 8,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['combine'], row, 9,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_combine'], row, 10,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['pdf'], row, 11, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['overwrite'], row, 12,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['reduce'], row, 13,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['sync'], row, 14, QtCore.Qt.AlignCenter)
            self.scans[scan] = status
        row += 1
        self.grid.addWidget(QtWidgets.QLabel('All'), row, 0,
                            QtCore.Qt.AlignCenter)
        all_boxes = {}
        all_boxes['link'] = self.new_checkbox(
            lambda: self.select_status('link'))
        all_boxes['max'] = self.new_checkbox(lambda: self.select_status('max'))
        all_boxes['find'] = self.new_checkbox(
            lambda: self.select_status('find'))
        all_boxes['copy'] = self.new_checkbox(
            lambda: self.select_status('copy'))
        all_boxes['refine'] = self.new_checkbox(
            lambda: self.select_status('refine'))
        all_boxes['transform'] = self.new_checkbox(
            lambda: self.select_status('transform'))
        all_boxes['masked_transform'] = self.new_checkbox(
            lambda: self.select_status('masked_transform'))
        all_boxes['combine'] = self.new_checkbox(
            lambda: self.select_status('combine'))
        all_boxes['masked_combine'] = self.new_checkbox(
            lambda: self.select_status('masked_combine'))
        all_boxes['pdf'] = self.new_checkbox(lambda: self.select_status('pdf'))
        all_boxes['overwrite'] = self.new_checkbox(self.select_all)
        all_boxes['reduce'] = self.new_checkbox(self.select_all)
        all_boxes['sync'] = self.new_checkbox(self.select_all)
        self.grid.addWidget(all_boxes['link'], row, 2, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['max'], row, 3, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['find'], row, 4, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['copy'], row, 5, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['refine'], row, 6, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['transform'], row, 7,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_transform'], row, 8,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['combine'], row, 9,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_combine'], row, 10,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['pdf'], row, 11, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['overwrite'], row, 12,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['reduce'], row, 13,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['sync'], row, 14, QtCore.Qt.AlignCenter)
        self.all_scans = all_boxes
        self.start_progress((0, len(wrapper_files)))

        # Populate the checkboxes based on the entries in nxdb.File
        for i, (wrapper, scan) in enumerate(wrapper_files.items()):
            status = self.scans[scan]
            status['data'].setEnabled(False)
            f = nxdb.get_file(wrapper)
            for task_name in nxdb.task_names:
                # Database columns use nx* names while columns don't
                if task_name.startswith('nx'):
                    col_name = task_name[2:]
                else:
                    col_name = task_name
                checkbox = status[col_name]
                file_status = getattr(f, task_name)
                if file_status == nxdb.DONE:
                    checkbox.setCheckState(QtCore.Qt.Checked)
                    checkbox.setEnabled(False)
                elif file_status == nxdb.IN_PROGRESS:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                elif file_status == nxdb.QUEUED:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(False)
                elif file_status == nxdb.FAILED:
                    checkbox.setCheckState(QtCore.Qt.Unchecked)
                    checkbox.setEnabled(True)
                # TODO: do i need to account for last?
            if status['data'].checkState() == QtCore.Qt.Unchecked:
                self.disable_status(status)
            self.update_progress(i)

        self.stop_progress()
        self.backup_scans()
        return self.grid
Esempio n. 7
0
    def list_orientations(self):
        message_box = BaseDialog(self)
        message_box.setMinimumWidth(600)
        message_box.setMinimumHeight(600)
        header = [
            'i', 'x', 'y', 'z', 'Polar', 'Azi', 'Intensity', 'H', 'K', 'L',
            'Diff'
        ]
        peak_list = self.refine.get_peaks()
        self.refine.assign_rings()
        self.rings = self.refine.get_ring_hkls()
        orient_layout = QtWidgets.QHBoxLayout()
        if self.refine.primary is None:
            self.refine.primary = 0
        if self.refine.secondary is None:
            self.refine.secondary = 1
        self.primary_box = QtWidgets.QLineEdit(str(self.refine.primary))
        self.primary_box.setAlignment(QtCore.Qt.AlignRight)
        self.primary_box.setFixedWidth(80)
        self.secondary_box = QtWidgets.QLineEdit(str(self.refine.secondary))
        self.secondary_box.setAlignment(QtCore.Qt.AlignRight)
        self.secondary_box.setFixedWidth(80)
        orient_button = QtWidgets.QPushButton('Orient')
        orient_button.clicked.connect(self.orient)
        refine_button = QtWidgets.QPushButton('Refine')
        refine_button.clicked.connect(self.refine_orientation)
        restore_button = QtWidgets.QPushButton('Restore')
        restore_button.clicked.connect(self.restore_orientation)
        orient_layout.addStretch()
        orient_layout.addWidget(QtWidgets.QLabel('Primary'))
        orient_layout.addWidget(self.primary_box)
        orient_layout.addWidget(QtWidgets.QLabel('Secondary'))
        orient_layout.addWidget(self.secondary_box)
        orient_layout.addStretch()
        orient_layout.addWidget(orient_button)
        orient_layout.addWidget(refine_button)
        orient_layout.addWidget(restore_button)

        grid = QtWidgets.QGridLayout()
        grid.setSpacing(10)
        self.lattice = GridParameters()
        self.lattice.add('a', self.refine.a, 'a', False)
        self.lattice.add('b', self.refine.b, 'b', False)
        self.lattice.add('c', self.refine.c, 'c', False)
        self.lattice.add('alpha', self.refine.alpha, 'alpha', False)
        self.lattice.add('beta', self.refine.beta, 'beta', False)
        self.lattice.add('gamma', self.refine.gamma, 'gamma', False)
        p = self.lattice['a']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 0, 0, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 0, 1, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 0, 2, QtCore.Qt.AlignHCenter)
        p = self.lattice['b']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 0, 3, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 0, 4, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 0, 5, QtCore.Qt.AlignHCenter)
        p = self.lattice['c']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 0, 6, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 0, 7, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 0, 8, QtCore.Qt.AlignHCenter)
        p = self.lattice['alpha']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 1, 0, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 1, 1, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 1, 2, QtCore.Qt.AlignHCenter)
        p = self.lattice['beta']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 1, 3, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 1, 4, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 1, 5, QtCore.Qt.AlignHCenter)
        p = self.lattice['gamma']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 1, 6, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 1, 7, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 1, 8, QtCore.Qt.AlignHCenter)
        self.table_view = QtWidgets.QTableView()
        self.table_model = NXTableModel(self, peak_list, header)
        self.table_view.setModel(self.table_model)
        self.table_view.resizeColumnsToContents()
        self.table_view.horizontalHeader().stretchLastSection()
        self.table_view.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.table_view.doubleClicked.connect(self.plot_peak)
        self.table_view.setSortingEnabled(True)
        self.table_view.sortByColumn(0, QtCore.Qt.AscendingOrder)
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(orient_layout)
        layout.addLayout(grid)
        layout.addWidget(self.table_view)
        close_layout = QtWidgets.QHBoxLayout()
        self.status_text = QtWidgets.QLabel('Score: %.4f' %
                                            self.refine.score())
        self.tolerance_box = QtWidgets.QLineEdit(str(
            self.refine.hkl_tolerance))
        self.tolerance_box.setAlignment(QtCore.Qt.AlignRight)
        self.tolerance_box.setMaxLength(5)
        self.tolerance_box.editingFinished.connect(self.update_table)
        self.tolerance_box.setFixedWidth(80)
        save_button = QtWidgets.QPushButton('Save Orientation')
        save_button.clicked.connect(self.save_orientation)
        close_button = QtWidgets.QPushButton('Close Window')
        close_button.clicked.connect(message_box.close)
        close_layout.addWidget(self.status_text)
        close_layout.addStretch()
        close_layout.addWidget(QtWidgets.QLabel('Threshold'))
        close_layout.addWidget(self.tolerance_box)
        close_layout.addStretch()
        close_layout.addWidget(save_button)
        close_layout.addStretch()
        close_layout.addWidget(close_button)
        layout.addLayout(close_layout)
        message_box.setLayout(layout)
        message_box.setWindowTitle('%s Peak Table' % self.entry.nxtitle)
        message_box.adjustSize()
        message_box.show()
        self.plotview = None