def __init__(self, crossword_index, grid_data, parent=None): super(Form, self).__init__(parent) self.setWindowTitle('{} {} {}'.format( app_title, bangla.convert_english_digit_to_bangla_digit(crossword_index), date.today().strftime("%A, %d %B, %Y"))) self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) tableModel = CrosswordGridModel(crossword_index, grid_data, self) tableView = QTableView(self) tableView.horizontalHeader().hide() tableView.verticalHeader().hide() tableView.setModel(tableModel) for i in range(grid_row_count): tableView.setRowHeight(i, grid_cell_size) for i in range(grid_column_count): tableView.setColumnWidth(i, grid_cell_size) generateIconFiles(icons_folder, tableView.columnWidth(0), tableView.rowHeight(0)) right_label = QLabel(self) right_pixmap = QPixmap('right_clues.png') right_label.setPixmap(right_pixmap) down_label = QLabel(self) down_pixmap = QPixmap('down_clues.png') down_label.setPixmap(down_pixmap) saveButton = QPushButton('Save progress', self) loadButton = QPushButton('Load progress', self) clearButton = QPushButton('Clear progress', self) saveButton.clicked.connect(tableModel.save_solution) loadButton.clicked.connect(tableModel.load_solution) clearButton.clicked.connect(tableModel.clear_solution) bbox = QDialogButtonBox(self) bbox.addButton(saveButton, QDialogButtonBox.AcceptRole) bbox.addButton(loadButton, QDialogButtonBox.AcceptRole) bbox.addButton(clearButton, QDialogButtonBox.AcceptRole) layout = QGridLayout(self) layout.addWidget(tableView, 0, 0) layout.addWidget(right_label, 0, 1, Qt.AlignLeft | Qt.AlignTop) layout.addWidget(down_label, 1, 0, Qt.AlignLeft | Qt.AlignTop) layout.addWidget(bbox, 1, 1, Qt.AlignHCenter | Qt.AlignBottom) self.setLayout(layout) windowWidth = tableView.columnWidth( 0 ) * grid_column_count + grid_column_count - 1 + right_clues_right - right_clues_left + layout.horizontalSpacing( ) + 27 windowHeight = tableView.rowHeight( 0 ) * grid_row_count + grid_row_count - 1 + down_clues_bottom - down_clues_top + layout.verticalSpacing( ) + 10 self.setFixedSize(QSize(windowWidth, windowHeight))
class SQLite(QSqlDatabase): """ Класс для инициализации и открытия базы данных каталога, полученный из Slot'а (openFile) """ def __init__(self, path=None): """ Инициализация экземпляра класса :param path: путь до каталога, полученный изиз Slot'а (openFile) """ super().__init__() self.path = path self.width = 0 self.heigh = 0 self.db = QSqlDatabase.addDatabase('QSQLITE') self.db.setDatabaseName(self.path) self.db.open() self.window = QWidget() self.window.setWindowTitle("Каталог книг") self.conn = sqlite3.connect(self.path) cursor = self.conn.cursor() sql = f'select * from sqlite_master where type = "table"' # получение имени таблицы(первая в списке), к которой будет # осуществлено подключение cursor.execute(sql) self.search_result = cursor.fetchall()[0][1] self.model = QSqlTableModel(parent=self.window, db=self.db) self.model.setTable(self.search_result) self.db_record = QSqlRecord(self.db.record(self.search_result)) self.tableView = QTableView() def on(self): """ Метод для подключения и отображения подключенного каталога :return: виджет self.window """ self.model.setEditStrategy(QSqlTableModel.OnManualSubmit) self.model.select() self.model.setHeaderData(-1, Qt.Horizontal, self.db_record.fieldName(0)) vbox = QVBoxLayout() self.tableView.setModel(self.model) self.tableView.resizeColumnsToContents() self.tableView.resizeRowsToContents() for i in range(self.model.columnCount() + 2): self.width += self.tableView.columnWidth(i) for j in range(self.model.rowCount() + 1): self.heigh += self.tableView.rowHeight(j) self.tableView.resize(self.width + 50, self.heigh + 50) vbox.addWidget(self.tableView) self.window.setLayout(vbox) self.window.resize(self.tableView.width() + 30, self.tableView.height() + 120) return self.window
class DLPSettingsGUI(QWidget): def __init__(self, dlp_controller=None, dlp_slicer=None, parent=None): QWidget.__init__(self, parent) self.parent = parent self.dlp_controller = dlp_controller self.dlp_slicer = dlp_slicer self.dlp_color_calibrator = DLPColorCalibrator() self.dlp_color_calibrator.analysis_completed_signal.connect(self.update_charts) self.__printer_parameters_list = {} self.__slicer_parameters_list = {} self.data_fit_chart_view = None self.data_fit_chart = None self.main_layout = QHBoxLayout() self.__init_table_widget__() self.__init_color_calibration_widget() self.__default_parameters_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.MinimumExpanding) self.main_layout.addWidget(self.__default_parameters_widget, stretch=1) self.main_layout.addWidget(self.__color_calibration_widget, stretch=2) self.setLayout(self.main_layout) self.main_layout.update() def __init_color_calibration_widget(self, parent=None): self.__color_calibration_widget = QGroupBox("Color Correction Options", parent) self.__color_calibration_widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) color_calibration_layout = QVBoxLayout(self.__color_calibration_widget) chart_widget = QWidget(self.__color_calibration_widget) chart_layout = QGridLayout(chart_widget) self.data_fit_chart = QtCharts.QChart() self.data_fit_chart_view = QtCharts.QChartView(self.data_fit_chart) self.axis_x = QtCharts.QValueAxis() self.axis_x.setTitleText("Pixel Intensity") self.axis_x.setRange(0, 1) self.data_fit_chart.addAxis(self.axis_x, Qt.AlignBottom) self.axis_y = QtCharts.QValueAxis() self.axis_y.setTitleText("Voxel Height (\u03BCm)") self.axis_y.setRange(0, 10) self.data_fit_chart.addAxis(self.axis_y, Qt.AlignLeft) chart_layout.addWidget(self.data_fit_chart_view, 0, 0, 1, 4) chart_widget.setLayout(chart_layout) buttons_widget = QWidget(self.__color_calibration_widget) buttons_layout = QHBoxLayout(buttons_widget) analyze_data_button = QPushButton("Analyze Data") analyze_data_button.clicked.connect(self.analyze_images) self.parameters_estimation_label = QLabel(f'Estimated parameters: \u03B1 = {self.dlp_color_calibrator.optimized_parameters[0]:.3f}, \u03B2 = {self.dlp_color_calibrator.optimized_parameters[1]:.3f}, \u03B3 = {self.dlp_color_calibrator.optimized_parameters[2]:.3f}', buttons_widget) buttons_layout.addWidget(analyze_data_button) buttons_layout.addWidget(self.parameters_estimation_label) buttons_widget.setLayout(buttons_layout) color_calibration_layout.addWidget(chart_widget) color_calibration_layout.addWidget(buttons_widget) self.__color_calibration_widget.setLayout(color_calibration_layout) @Slot() def analyze_images(self): file_names = QFileDialog.getOpenFileNames(caption='Select data', dir='../measured_data/grayscale_measured_data', filter="Image Files (*.asc)") self.dlp_color_calibrator.analyze_data_files(file_names[0]) @Slot() def update_charts(self): self.data_fit_chart = QtCharts.QChart() self.data_fit_chart.setAnimationOptions(QtCharts.QChart.AllAnimations) self.add_series(self.data_fit_chart, "Measured Data", self.dlp_color_calibrator.input_values, self.dlp_color_calibrator.average_data) self.add_series(self.data_fit_chart, "Fitted Curve", self.dlp_color_calibrator.input_values, self.dlp_color_calibrator.fitted_curve) self.add_series(self.data_fit_chart, "Predicted Result", self.dlp_color_calibrator.input_values, self.dlp_color_calibrator.corrected_output_values) series = self.data_fit_chart.series() self.data_fit_chart.addAxis(self.axis_x, Qt.AlignBottom) self.axis_y.setRange(0, self.dlp_color_calibrator.measured_thickness) self.data_fit_chart.addAxis(self.axis_y, Qt.AlignLeft) for s in series: s.attachAxis(self.axis_x) s.attachAxis(self.axis_y) self.data_fit_chart_view.setRenderHint(QPainter.Antialiasing) self.data_fit_chart_view.setChart(self.data_fit_chart) self.parameters_estimation_label.setText(f'Estimated parameters: \u03B1 = {self.dlp_color_calibrator.optimized_parameters[0]:.3f}, \u03B2 = {self.dlp_color_calibrator.optimized_parameters[1]:.3f}, \u03B3 = {self.dlp_color_calibrator.optimized_parameters[2]:.3f}') def add_series(self, chart, title, x, y): series = QtCharts.QLineSeries() series.setName(title) for idx, elem in enumerate(x): series.append(x[idx], y[idx]) chart.addSeries(series) def __init_table_widget__(self, parent=None): self.__default_parameters_widget = QGroupBox("Default Parameters", parent) self.printer_parameters_list = self.dlp_controller.get_default_parameters() self.table_view = QTableView() self.table_model = self.MyTableModel(parent=self.__default_parameters_widget, data_list=self.printer_parameters_list) self.table_view.setModel(self.table_model) self.table_view.horizontalHeader().setVisible(False) self.table_view.verticalHeader().setVisible(False) self.table_view.horizontalHeader().setStretchLastSection(False) # self.table_view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table_view.resizeColumnsToContents() self.table_view.update() # self.table_view.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) # self.table_view.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) apply_button = QPushButton("Apply Changes", self.__default_parameters_widget) apply_button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) apply_button.clicked.connect(self.dlp_controller.save_default_parameters) default_parameters_layout = QVBoxLayout(self.__default_parameters_widget) default_parameters_layout.addWidget(self.table_view) default_parameters_layout.addWidget(apply_button) self.__default_parameters_widget.setLayout(default_parameters_layout) self.__default_parameters_widget.updateGeometry() # default_parameters_layout.update() # QGuiApplication.processEvents() @Slot() def __adjust_table_size__(self): self.table_view.resizeColumnToContents(0) self.table_view.resizeColumnToContents(1) rect = self.table_view.geometry() rect.setWidth(1 + self.table_view.verticalHeader().width() + self.table_view.columnWidth(0) + self.table_view.columnWidth(1) + self.table_view.verticalScrollBar().width()) self.table_view.setGeometry(rect) self.table_view.resize(rect.width(), rect.height()) class MyTableModel(QAbstractTableModel): def __init__(self, parent, data_list, *args): QAbstractTableModel.__init__(self, parent, *args) self.parent = parent self.data_list = data_list def rowCount(self, parent): return len(self.data_list) def columnCount(self, parent): return 2 def data(self, index, role): if not index.isValid(): return None elif role != Qt.DisplayRole: return None return list(self.data_list.items())[index.row()][index.column()] def setData(self, index, value, role): if role == Qt.EditRole: if not index.isValid(): return False elif index.column() == 0: return False else: key = list(self.data_list.items())[index.row()][0] old_value = list(self.data_list.items())[index.row()][1] try: if isinstance(old_value, float): self.data_list[key] = float(value) elif isinstance(old_value, bool): if value == "True" or value == "true": self.data_list[key] = True else: self.data_list[key] = False elif isinstance(old_value, str): if index.row() == 0: if not (value.upper() == "TOP-DOWN" or value.upper() == "BOTTOM-UP"): return False self.data_list[key] = str(value).upper() except ValueError: return False self.dataChanged.emit(index, index) return True else: return False def flags(self, index): if not index.isValid() or index.column() == 0: return Qt.ItemIsEnabled return Qt.ItemFlags(QAbstractTableModel.flags(self, index) | Qt.ItemIsEditable)