def _init_widget(self, parent): """Initialise the matrix widgets.""" self._grid_layout = QtWidgets.QGridLayout() self._grid_layout.setHorizontalSpacing(10) self._grid_layout.setVerticalSpacing(0) self._grid_layout.setRowMinimumHeight(0, int(1.5 * self._BAND_PIXMAP_HEIGHT)) self._reset_button = QtWidgets.QPushButton(parent) self._reset_button.setText(translate("colour_decoder", "Reset")) self._reset_button.clicked.connect(self.reset) self._grid_layout.addWidget(self._reset_button, 0, 0, 1, 1, _CENTERED_ALIGNEMENT) self._band_labels = [] for band in self._band_iterator(): label = QtWidgets.QLabel(parent) self._grid_layout.addWidget(label, 0, band +1, 1, 1, _CENTERED_ALIGNEMENT) self._band_labels.append(label) self._band_button_groups = [] for band in self._band_iterator(): button_group = QtWidgets.QButtonGroup(parent) self._band_button_groups.append(button_group) button_group.setExclusive(True) callback = self._make_button_clicked_callback(band) button_group.buttonClicked.connect(callback) for row, colour in enumerate(self._colour_names): label = QtWidgets.QLabel(parent) label.setText(translate("colour_decoder", colour)) self._grid_layout.addWidget(label, row +1, 0, 1, 1) for band in self._band_iterator(): self._init_cell(parent, band, row, colour) self.reset()
def _init_action(self): """ Initialise the actions. """ self._about_action = QtGui.QAction(self._main_window) self._about_action.setText(translate('colour_decoder', 'About')) self._about_action.triggered.connect(self._about)
def _init_hypotheses_widget(self): """ Initialise the hypothesis table widget. """ self._hypotheses_group_box = QtGui.QGroupBox(self._main_window) self._hypotheses_group_box.setTitle(translate("colour_decoder", 'Hypotheses')) self._vertical_layout.addWidget(self._hypotheses_group_box) horizontal_layout = QtGui.QHBoxLayout(self._hypotheses_group_box) self._hypotheses_table_model = HypothesesTableModel() self._table_view = QtGui.QTableView(self._hypotheses_group_box) self._table_view.setAlternatingRowColors(True) self._table_view.setSortingEnabled(True) self._table_view.setModel(self._hypotheses_table_model) self._table_view.resizeColumnsToContents() size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self._table_view.setSizePolicy(size_policy) horizontal_layout.addWidget(self._table_view) margin = 5 resistor_pixmap_size = QtCore.QSize(100, 50) # Fixme: no effect image_delegate = ResistorImageDelegate(None, margin, resistor_pixmap_size) column = self._hypotheses_table_model.column_index('colour code') self._table_view.setItemDelegateForColumn(column, image_delegate)
def _init_menu(self): """ Initialise the menu bar. """ self._menu_bar = QtGui.QMenuBar(self._main_window) self._main_window.setMenuBar(self._menu_bar) self._help_menu = QtGui.QMenu(self._menu_bar) self._help_menu.setTitle(translate('colour_decoder', 'Help')) self._help_menu.addAction(self._about_action) self._menu_bar.addAction(self._help_menu.menuAction())
def _init_colour_matrix_widget(self): """ Initialise the colour matrix widget. """ self._colour_code_group_box = QtGui.QGroupBox(self._main_window) self._colour_code_group_box.setTitle(translate("colour_decoder", 'Colour Code')) self._vertical_layout.addWidget(self._colour_code_group_box) horizontal_layout = QtGui.QHBoxLayout(self._colour_code_group_box) self._colour_matrix = ColourMatrix(self._colour_code_group_box) horizontal_layout.addLayout(self._colour_matrix.widget()) help_label = QtGui.QLabel(self._colour_code_group_box) help_label.setTextFormat(QtCore.Qt.RichText) help_label.setTextFormat(QtCore.Qt.RichText) help_label.setWordWrap(True) help_label.setOpenExternalLinks(True) help_label.setMargin(25) help_label.setAlignment(QtCore.Qt.AlignLeading| QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) help_label.setText(translate("colour_decoder", Help.colour_matrix_help)) size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) help_label.setSizePolicy(size_policy) horizontal_layout.addWidget(help_label)