def setupUi(self): self.resize(640, 480) self.verticalLayout = QVBoxLayout(self) self.textEdit = QPlainTextEdit(self) self.closeButton = QPushButton(self) self.copyButton = QPushButton(self) self.verticalLayout.addWidget(self.textEdit) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setSizeConstraint(QLayout.SetDefaultConstraint) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.horizontalLayout.addWidget(self.copyButton) self.horizontalLayout.addWidget(self.closeButton) self.verticalLayout.addLayout(self.horizontalLayout) self.closeButton.clicked.connect(self.reject) font = QFont(CONFIG['text_view_dialog_font'], CONFIG['text_view_dialog_font_size']) font.setStyleHint(QFont.Monospace) self.textEdit.setFont(font) self.closeButton.setText('Close') self.copyButton.setText('Copy to clipboard') self.textEdit.setPlainText(self.text) self.copyButton.clicked.connect(self.copy_text)
def _resize_widgets(build_popup, visible): output = build_popup.textBrowser_output cmd = build_popup.lineEdit_cmd font = QFont('Monospace' if visible else '') font.setStyleHint(QFont.TypeWriter) metrics = QFontMetrics(font) output.setFont(font) mw = build_popup.min_width = metrics.width(' ' * 80) output.setMinimumSize(QSize(mw, 20*metrics.height())) cmd.setMinimumSize(QSize(metrics.width(' ' * 40), metrics.height()))
def _init_font(self): # There isn't a standard way of getting the system default monospace # font in Qt4 (it was introduced in Qt5.2). If QFontDatabase.FixedFont # exists, then we can assume that this functionality exists and ask for # the correct font directly. Otherwise we ask for a font that doesn't # exist and specify our requirements. Qt then finds an existing font # that best matches our parameters. if hasattr(QFontDatabase, "systemFont") and hasattr( QFontDatabase, "FixedFont"): font = QFontDatabase.systemFont(QFontDatabase.FixedFont) else: font = QFont("") font.setFixedPitch(True) font.setStyleHint(QFont.Monospace) self.setFont(font)
def drawContents(self, painter): """ @type painter: QPainter """ w = self.width() h = self.height() margin = 10 background = QColor(210, 211, 215) text_color = QColor(0, 0, 0) foreground = QColor(255, 255, 255) painter.setBrush(background) painter.fillRect(0, 0, w, h, background) pen = QPen() pen.setWidth(2) pen.setColor(foreground) painter.setPen(pen) painter.drawRect(0, 0, w - 1, h - 1) text_x = 2 * margin top_offset = margin text_area_width = w - 2 * margin painter.setPen(text_color) text_size = 150 font = QFont("Serif") font.setStyleHint(QFont.Serif) font.setPixelSize(text_size) painter.setFont(font) painter.drawText(text_x, margin + top_offset, text_area_width, text_size, int(Qt.AlignHCenter | Qt.AlignCenter), self.ert) top_offset += text_size + 2 * margin text_size = 25 font.setPixelSize(text_size) painter.setFont(font) painter.drawText(text_x, top_offset, text_area_width, text_size, int(Qt.AlignHCenter | Qt.AlignCenter), self.ert_title) top_offset += text_size + 4 * margin text_size = 20 font.setPixelSize(text_size) painter.setFont(font) painter.drawText(text_x, top_offset, text_area_width, text_size, int(Qt.AlignHCenter | Qt.AlignCenter), self.version)
def render__label_qfont(self) -> QFont: qfont = QFont() qfont.setStyleHint(QFont.SansSerif) # no-op on X11 font = self.cfg.render.label_font if font.toString: qfont.fromString(font.toString) return qfont # Passing None or "" to QFont(family) results in qfont.family() = "", and # wrong font being selected (Abyssinica SIL, which appears early in the list). family = coalesce(font.family, qfont.defaultFamily()) # Font file selection qfont.setFamily(family) qfont.setBold(font.bold) qfont.setItalic(font.italic) # Font size qfont.setPointSizeF(font.size) return qfont
def __init__(self, parent, history): super().__init__(parent=parent) self.setWindowTitle("History") layout = QVBoxLayout() text = QPlainTextEdit() font = QFont() font.setFamily("monospace") font.setStyleHint(QFont.Monospace) text.setFont(font) highlighter = PythonHighlighter(text.document()) # noqa: F841 text.setReadOnly(True) text.setPlainText(history) layout.addWidget(text) buttonbox = QDialogButtonBox(QDialogButtonBox.Ok) clipboardbutton = QPushButton("Copy to clipboard") buttonbox.addButton(clipboardbutton, QDialogButtonBox.ActionRole) clipboard = QGuiApplication.clipboard() clipboardbutton.clicked.connect( lambda: clipboard.setText(history + "\n")) layout.addWidget(buttonbox) self.setLayout(layout) buttonbox.accepted.connect(self.accept) self.resize(700, 500)
def __init__(self, plot_window, parent=None): super(LineListsWindow, self).__init__() self.plot_window = plot_window # Builds GUI self._main_window = ClosableMainWindow() self.setupUi(self._main_window, str(plot_window)) self.tabWidget.tabCloseRequested.connect(self.tab_close) # Request that line lists be read from wherever are they sources. dispatch.on_request_linelists.emit() # Populate line list selector with internal line lists model = self.line_list_selector.model() item = QStandardItem("Select line list") font = QFont("Monospace") font.setStyleHint(QFont.TypeWriter) font.setPointSize(12) item.setFont(font) model.appendRow(item) for description in linelist.descriptions(): item = QStandardItem(str(description)) item.setFont(font) model.appendRow(item) #------------ UNCOMMENT TO LOAD LISTS AUTOMATICALLY -------------- # # Populate GUI. # # This is commented out for now to comply with the decision about # not showing any line list automatically upon startup. In case # we need that capability back, just uncomment this line. # self._buildViews(plot_window) #--------------------------------------------------------------- # Connect controls to appropriate signals. # # Note that, for the Draw operation, we have to pass the table views to # the handler, even though it would be better to handle the row selections # all in here for the sake of encapsulation. This is so because this class # is not a QWidget or one of its subclasses, thus it cannot implement a # DispatchHandle signal handler. self.draw_button.clicked.connect( lambda: dispatch.on_plot_linelists.emit( table_views=self._getTableViews(), panes=self._getPanes(), units=plot_window.waverange[0].unit, caller=plot_window)) self.erase_button.clicked.connect( lambda: dispatch.on_erase_linelabels.emit(caller=plot_window)) self.dismiss_button.clicked.connect( lambda: dispatch.on_dismiss_linelists_window.emit(close=False)) self.actionOpen.triggered.connect( lambda: self._open_linelist_file(file_name=None)) self.actionExport.triggered.connect( lambda: self._export_to_file(file_name=None)) self.line_list_selector.currentIndexChanged.connect( self._lineList_selection_change)
QPixmap, QFont, ) from pyslvs import edges_view from pyslvs.graph import Graph, external_loop_layout from pyslvs_ui.info import logger from .color import color_qt, color_num from .canvas import convex_hull, LINK_COLOR _Pos = Dict[int, Tuple[float, float]] engines = ("External Loop", ) _font = QFont("Monospace") _font.setBold(True) _font.setStyleHint(QFont.TypeWriter) def engine_picker(g: Graph, engine: str, node_mode: bool) -> _Pos: """Generate a position dict.""" if engine == "External Loop": try: layout: _Pos = external_loop_layout(g, node_mode, scale=30) except ValueError as error: logger.warn(error) return {} else: raise ValueError(f"engine {engine} is not exist") inf = float('inf') x_max = -inf
def __init__(self, plot_window, parent=None): super(LineListsWindow, self).__init__(plot_window) self.plot_window = plot_window loadUi(os.path.join(os.path.dirname(__file__), "ui", "linelists_window.ui"), self) self.setWindowTitle(str(self.plot_window._title)) # QtDesigner can't add a combo box to a tool bar... self.line_list_selector = QComboBox() self.line_list_selector.setToolTip("Select line list from internal library") self.mainToolBar.addWidget(self.line_list_selector) # QtDesigner creates tabbed widgets with 2 tabs, and doesn't allow # removing then in the designer itself. Remove in here then. while self.tabWidget.count() > 0: self.tabWidget.removeTab(0) # Request that line lists be read from wherever are they sources. plot_window.request_linelists() # Populate line list selector with internal line lists model = self.line_list_selector.model() item = QStandardItem("Select line list") font = QFont("Monospace") font.setStyleHint(QFont.TypeWriter) font.setPointSize(12) item.setFont(font) model.appendRow(item) for description in linelist.descriptions(): item = QStandardItem(str(description)) item.setFont(font) model.appendRow(item) #------------ UNCOMMENT TO LOAD LISTS AUTOMATICALLY -------------- # # Populate GUI. # # This is commented out for now to comply with the decision about # not showing any line list automatically upon startup. In case # we need that capability back, just uncomment this line. # self._buildViews(plot_window) #--------------------------------------------------------------- # Connect controls to appropriate signals. # # Note that, for the Draw operation, we have to pass the table views to # the handler, even though it would be better to handle the row selections # all in here for the sake of encapsulation. This used to be necessary # because this class is not a QWidget or one of its subclasses, thus it # cannot implement a DispatchHandle signal handler. Once we gt rid of the # Dispatch facility, this design decision could likely be modified. We # decide to keep the same old design for now, to prevent breaks in logic. self.draw_button.clicked.connect( lambda:self.plot_window.line_labels_plotter.plot_linelists( table_views=self._getTableViews(), panes=self._getPanes(), units=self.plot_window.spectral_axis_unit, caller=self.plot_window)) self.erase_button.clicked.connect(lambda:self.plot_window.erase_linelabels.emit(self.plot_window)) self.dismiss_button.clicked.connect(lambda:self.plot_window.dismiss_linelists_window.emit(False)) self.actionOpen.triggered.connect(lambda:self._open_linelist_file(file_name=None)) self.actionExport.triggered.connect(lambda:self._export_to_file(file_name=None)) self.line_list_selector.currentIndexChanged.connect(self._lineList_selection_change) self.tabWidget.tabCloseRequested.connect(self.tab_close)
"""Check if the problem is solved.""" n_lights = self.manage_puzzle.n_lights_1axis for idx_row in range(n_lights): for idx_col in range(n_lights): btn = self.btn_grid_table.cellWidget(idx_row, idx_col) if btn is not None: if btn.isChecked(): return n_solution = self.manage_puzzle.count_1_of_solution() QMessageBox.information(self, "Succeess", ("Congratulation\n" f"clicked : {self.n_clicked}\n" f"solution : {n_solution}")) if __name__ == '__main__': APP = QApplication(sys.argv) style_sheet = qdarkstyle.load_stylesheet_pyqt5() APP.setStyleSheet(style_sheet) FONT = QFont("D2Coding Ligature", 12) FONT.setStyleHint(QFont.Monospace) APP.setFont(FONT) MAIN_WINDOW = MainWindowLightsOut() MAIN_WINDOW.show() sys.exit(APP.exec_())
def __init__(self, hub, *args, **kwargs): super().__init__(*args, **kwargs) self.hub = hub self.wave_range = (None, None) loadUi(os.path.join(os.path.dirname(__file__), "ui", "linelists_window.ui"), self) # QtDesigner can't add a combo box to a tool bar... self.line_list_selector = QComboBox() self.line_list_selector.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.line_list_selector.setMinimumWidth(230) self.line_list_selector.setToolTip("Select line list from internal library") self.main_toolbar.addWidget(self.line_list_selector) # QtDesigner creates tabbed widgets with 2 tabs, and doesn't allow # removing then in the designer itself. Remove in here then. while self.tab_widget.count() > 0: self.tab_widget.removeTab(0) # Local references for often used objects. self.plot_window = self.hub.plot_window # Request that line lists be read from wherever are they sources. if not hasattr(self, 'linelists'): self._request_linelists() # Populate line list selector with internal line lists model = self.line_list_selector.model() item = QStandardItem("Select line list") font = QFont("Monospace") font.setStyleHint(QFont.TypeWriter) font.setPointSize(12) item.setFont(font) model.appendRow(item) for description in linelist.descriptions(): item = QStandardItem(str(description)) item.setFont(font) model.appendRow(item) self.line_labels_plotter = LineLabelsPlotter(self) # Connect controls to appropriate signals. self.draw_button.clicked.connect( lambda:self.line_labels_plotter._plot_linelists( table_views=self._get_table_views(), panes=self._get_panes(), units=self.hub.plot_widget.spectral_axis_unit, caller=self.line_labels_plotter)) self.erase_button.clicked.connect(lambda:self.erase_linelabels.emit(self.plot_window.plot_widget)) self.dismiss_button.clicked.connect(self.dismiss_linelists_window.emit) self.actionOpen.triggered.connect(lambda:self._open_linelist_file(file_name=None)) self.actionExport.triggered.connect(lambda:self._export_to_file(file_name=None)) self.line_list_selector.currentIndexChanged.connect(self._lineList_selection_change) self.tab_widget.tabCloseRequested.connect(self._on_tab_close) self.hub.plot_window.window_removed.connect(self.dismiss_linelists_window.emit)
def drawContents(self, painter): """ @type painter: QPainter """ w = self.width() h = self.height() margin = 10 background = QColor(210, 211, 215) text_color = QColor(0, 0, 0) foreground = QColor(255, 255, 255) painter.setBrush(background) painter.fillRect(0, 0, w, h, background) pen = QPen() pen.setWidth(2) pen.setColor(foreground) painter.setPen(pen) painter.drawRect(0, 0, w - 1, h - 1) image_width = self.splash_image.width() image_height = self.splash_image.height() aspect = 1.0 if image_height: aspect = float(image_width) / float(image_height) scaled_height = h - 2 * margin scaled_width = scaled_height * aspect painter.drawRect(margin, margin, scaled_width, scaled_height) painter.drawPixmap(margin, margin, scaled_width, scaled_height, self.splash_image) text_x = scaled_width + 2 * margin top_offset = margin text_area_width = w - scaled_width - 2 * margin painter.setPen(text_color) text_size = 150 font = QFont("Serif") font.setStyleHint(QFont.Serif) font.setPixelSize(text_size) painter.setFont(font) painter.drawText(text_x, margin + top_offset, text_area_width, text_size, Qt.AlignHCenter | Qt.AlignCenter, self.ert) top_offset += text_size + 2 * margin text_size = 25 font.setPixelSize(text_size) painter.setFont(font) painter.drawText(text_x, top_offset, text_area_width, text_size, Qt.AlignHCenter | Qt.AlignCenter, self.ert_title) top_offset += text_size + 4 * margin text_size = 20 font.setPixelSize(text_size) painter.setFont(font) painter.drawText(text_x, top_offset, text_area_width, text_size, Qt.AlignHCenter | Qt.AlignCenter, self.version) text_size = 12 font.setPixelSize(text_size) painter.setFont(font) painter.drawText(text_x, h - text_size - margin - 5, text_area_width, text_size + 5, Qt.AlignHCenter | Qt.AlignCenter, self.copyright)