def make_font(font_size, is_bold=False): """creates a QFont""" font = QFont() font.setPointSize(font_size) if is_bold: font.setBold(is_bold) return font
def addPathEntry(self, parent, path, state, top=False): it = QTreeWidgetItem(parent, (path, )) ft = QFont(OCTXT._Table_Font) if top: ft.setBold(True) it.setFont(0, ft) if state == CGM.CHECK_FAIL: it.setIcon(0, self.IC(QW.I_C_SFL)) if state == CGM.CHECK_WARN: it.setIcon(0, self.IC(QW.I_C_SWR)) return it
def toggle_active(self): """ When a mesh corresponding to the item's region get's rendered, change the font to bold to highlight the fact. """ fnt = QFont("Roboto", 14) if self._checked: fnt.setBold(True) else: fnt.setBold(False) self.setFont(fnt)
class StatusBarWidget(QWidget): """Status bar widget base.""" TIP = None def __init__(self, parent, statusbar, icon=None): """Status bar widget base.""" super(StatusBarWidget, self).__init__(parent) # Variables self.value = None # Widget self._icon = icon self._pixmap = icon.pixmap(QSize(16, 16)) if icon is not None else None self.label_icon = QLabel() if icon is not None else None self.label_value = QLabel() # Widget setup if icon is not None: self.label_icon.setPixmap(self._pixmap) # See spyder-ide/spyder#9044. self.text_font = QFont(get_font(option='font')) self.text_font.setPointSize(self.font().pointSize()) self.text_font.setBold(True) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) if self.TIP: self.setToolTip(self.TIP) self.label_value.setToolTip(self.TIP) # Layout layout = QHBoxLayout() if icon is not None: layout.addWidget(self.label_icon) layout.addWidget(self.label_value) layout.addSpacing(20) # Layout setup layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Setup statusbar.addPermanentWidget(self) def set_value(self, value): """Set formatted text value.""" self.value = value if self.isVisible(): self.label_value.setText(value)
class StatusBarWidget(QWidget): """Status bar widget base.""" TIP = None def __init__(self, parent, statusbar, icon=None): """Status bar widget base.""" super(StatusBarWidget, self).__init__(parent) # Variables self.value = None # Widget self._icon = icon self._pixmap = icon.pixmap(QSize(16, 16)) if icon is not None else None self.label_icon = QLabel() if icon is not None else None self.label_value = QLabel() # Widget setup if icon is not None: self.label_icon.setPixmap(self._pixmap) self.text_font = QFont(get_font(option='font')) # See Issue #9044 self.text_font.setPointSize(self.font().pointSize()) self.text_font.setBold(True) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) if self.TIP: self.setToolTip(self.TIP) self.label_value.setToolTip(self.TIP) # Layout layout = QHBoxLayout() if icon is not None: layout.addWidget(self.label_icon) layout.addWidget(self.label_value) layout.addSpacing(20) # Layout setup layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Setup statusbar.addPermanentWidget(self) def set_value(self, value): """Set formatted text value.""" self.value = value if self.isVisible(): self.label_value.setText(value)
def addDiagEntry(self, parent, diag, top=False): dit = QTreeWidgetItem(parent, (self._data.message(diag), )) ft = QFont(OCTXT._Table_Font) if top: ft.setBold(True) dit.setFont(0, ft) if diag.level == CGM.CHECK_FAIL: dit.setIcon(0, self.IC(QW.I_C_SFL)) if diag.level == CGM.CHECK_WARN: dit.setIcon(0, self.IC(QW.I_C_SWR)) if diag.key not in self._filterItems: self._filterItems[diag.key] = [dit] else: self._filterItems[diag.key].insert(0, dit) return dit
def __init__(self, parameter, default=inspect._empty, parent=None): super().__init__(parent=parent) # Store parameter information self.parameter = parameter self.default = default self.setLayout(QHBoxLayout()) # Create our label self.param_label = QLabel(parent=self) self.param_label.setText(clean_attr(parameter)) self.layout().addWidget(self.param_label) # Indicate required parameters in bold font if default == inspect._empty: logger.debug("Inferring that %s has no default", parameter) bold = QFont() bold.setBold(True) self.param_label.setFont(bold)
def add_signal(self, signal): """Add a signal to the widget display""" # Create control widget widget = signal_widget(signal, read_only=is_signal_ro(signal)) # Create label widget label = QLabel(self) bold_font = QFont() bold_font.setBold(True) label.setFont(bold_font) # Add the label label.setText(clean_name(signal, strip_parent=self.device.root)) # Add to the layout # Annoying count block because insertWidget does not support negative # indexing count = self.command_layout.count() self.command_layout.insertWidget(count - 1, label, 0, Qt.AlignHCenter) self.command_layout.insertWidget(count, widget, 0, Qt.AlignHCenter)
def recalculate_size(self, font: QFont = None): """ If font is unspecified, Updates size unconditionally Otherwise, Updates size if the QFontMetrics is changed """ if font is not None: font_metrics = QFontMetrics(font) bold_font = QFont(font) bold_font.setBold(True) bold_font_metrics = QFontMetrics(bold_font) if self._bold_font_metrics == bold_font_metrics: return self._font_metrics = font_metrics self._bold_font_metrics = bold_font_metrics self._entry_height = self._font_metrics.height() max_num_of_entries = max((self.num_sinks, self.num_sources)) step = self._entry_height + self._spacing height = step * max_num_of_entries w = self._model.embedded_widget() if w: height = max((height, w.height())) height += self.caption_height self._input_port_width = self.port_width(PortType.input) self._output_port_width = self.port_width(PortType.output) width = self._input_port_width + self._output_port_width + 2 * self._spacing w = self._model.embedded_widget() if w: width += w.width() width = max((width, self.caption_width)) if self._model.validation_state() != NodeValidationState.valid: width = max((width, self.validation_width)) height += self.validation_height + self._spacing self._width = width self._height = height
def tuple_to_qfont(tup): """ Create a QFont from tuple: (family [string], size [int], italic [bool], bold [bool]) """ if not isinstance(tup, tuple) or len(tup) != 4 \ or not font_is_installed(tup[0]) \ or not isinstance(tup[1], int) \ or not isinstance(tup[2], bool) \ or not isinstance(tup[3], bool): return None font = QFont() family, size, italic, bold = tup font.setFamily(family) font.setPointSize(size) font.setItalic(italic) font.setBold(bold) return font
def __init__(self, node: NodeBase): super().__init__() self._node = node self._model = node.model self._dragging_pos = QPointF(-1000, -1000) self._entry_width = 0 self._entry_height = 20 self._font_metrics = QFontMetrics(QFont()) self._height = 150 self._hovered = False self._input_port_width = 70 self._output_port_width = 70 self._spacing = 20 self._style = node.style self._width = 100 f = QFont() f.setBold(True) self._bold_font_metrics = QFontMetrics(f)
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=None): super(EntryWidget, self).__init__(parent) self.textQVBoxLayout = QVBoxLayout() self.allQHBoxLayout = QHBoxLayout() self.allQHBoxLayout.setAlignment(Qt.AlignCenter) self.titleLabel = QLabel() boldFont = QFont() boldFont.setBold(True) self.titleLabel.setFont(boldFont) self.descriptionLabel = QLabel() self.textQVBoxLayout.addWidget(self.titleLabel) self.textQVBoxLayout.addWidget(self.descriptionLabel) self.dateLabel = QLabel() self.iconLabel = QLabel() self.allQHBoxLayout.addWidget(self.iconLabel, 0) self.allQHBoxLayout.addLayout(self.textQVBoxLayout, 1) self.allQHBoxLayout.addWidget(self.dateLabel, 0) self.setLayout(self.allQHBoxLayout)
def data(self, index, role=Qt.DisplayRole): """Override Qt method""" if not index.isValid() or not 0 <= index.row() < len(self._rows): return to_qvariant() row = index.row() column = index.column() # Carefull here with the order, this has to be adjusted manually if self._rows[row] == row: name, unlink, link, fetch = [u'', u'', u'', u''] else: name, unlink, link, fetch = self._rows[row] if role == Qt.DisplayRole: if column == 0: return to_qvariant(name) elif column == 1: return to_qvariant(unlink) elif column == 2: return to_qvariant(link) elif column == 3: return to_qvariant(fetch) elif role == Qt.TextAlignmentRole: if column in [0]: return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter)) elif column in [1, 2, 3]: return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) elif role == Qt.ForegroundRole: return to_qvariant() elif role == Qt.FontRole: font = QFont() if row in self._bold_rows: font.setBold(True) return to_qvariant(font) else: font.setBold(False) return to_qvariant(font) return to_qvariant()
def __init__(self, parent=None, standalone=False): super(GcodeLexer, self).__init__(parent) # This prevents doing unneeded initialization # when QtDesginer loads the plugin. if parent is None and not standalone: return self._styles = { 0: 'Default', 1: 'Comment', 2: 'Key', 3: 'Assignment', 4: 'Value', } for key, value in self._styles.iteritems(): setattr(self, value, key) font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) font.setBold(True) self.setFont(font, 2)
def get_preview_items(self, level): previewItem = QTableWidgetItem("Log message") previewItem.setBackground(QBrush(level.bg, Qt.SolidPattern)) previewItem.setForeground(QBrush(level.fg, Qt.SolidPattern)) previewItemDark = QTableWidgetItem("Log message") previewItemDark.setBackground(QBrush(level.bgDark, Qt.SolidPattern)) previewItemDark.setForeground(QBrush(level.fgDark, Qt.SolidPattern)) font = QFont(CONFIG.logger_table_font, CONFIG.logger_table_font_size) fontDark = QFont(font) if 'bold' in level.styles: font.setBold(True) if 'italic' in level.styles: font.setItalic(True) if 'underline' in level.styles: font.setUnderline(True) if 'bold' in level.stylesDark: fontDark.setBold(True) if 'italic' in level.stylesDark: fontDark.setItalic(True) if 'underline' in level.stylesDark: fontDark.setUnderline(True) previewItem.setFont(font) previewItemDark.setFont(fontDark) return previewItem, previewItemDark
def __init__(self, parent=None, args=None, macros=None): super(MirrorScreen, self).__init__(parent=parent, args=args, macros=macros) if macros != None: self.x_stop = EpicsSignal(macros['XAXIS'] + ".STOP") self.y_stop = EpicsSignal(macros['YAXIS'] + ".STOP") self.p_stop = EpicsSignal(macros['PITCH'] + ".STOP") self.alarm_box_x = QHBoxLayout() self.alarm_box_y = QHBoxLayout() self.alarm_box_p = QHBoxLayout() self.alarm_box_gantry_x = QHBoxLayout() self.alarm_box_gantry_y = QHBoxLayout() self.ghost = QHBoxLayout() self.alarm_x = TyphosAlarmCircle() self.alarm_x.channel = "ca://" + macros['XAXIS'] self.alarm_x.setMaximumHeight(35) self.alarm_x.setMaximumWidth(35) self.alarm_y = TyphosAlarmCircle() self.alarm_y.channel = "ca://" + macros['YAXIS'] self.alarm_y.setMaximumHeight(35) self.alarm_y.setMaximumWidth(35) self.alarm_p = TyphosAlarmCircle() self.alarm_p.channel = "ca://" + macros['PITCH'] self.alarm_p.setMaximumHeight(35) self.alarm_p.setMaximumWidth(35) label_font = QFont() label_font.setBold(True) self.x_label = QLabel("x") #self.x_label.setFont(label_font) self.y_label = QLabel("y") #self.y_label.setFont(label_font) self.p_label = QLabel("pitch") #self.p_label.setFont(label_font) self.gantry_x_label = QLabel("gantry x") #self.gantry_x_label.setFont(label_font) self.gantry_y_label = QLabel("gantry y") #self.gantry_y_label.setFont(label_font) self.alarm_gantry_x = TyphosAlarmCircle() self.alarm_gantry_x.channel = "ca://" + macros['MIRROR'] + ":HOMS:ALREADY_COUPLED_X_RBV" self.alarm_gantry_x.setMaximumHeight(35) self.alarm_gantry_x.setMaximumWidth(35) self.alarm_gantry_y = TyphosAlarmCircle() self.alarm_gantry_y.channel = "ca://" + macros['MIRROR'] + ":HOMS:ALREADY_COUPLED_Y_RBV" self.alarm_gantry_y.setMaximumHeight(35) self.alarm_gantry_y.setMaximumWidth(35) self.alarm_box_x.addWidget(self.x_label) self.alarm_box_x.setAlignment(self.x_label, Qt.AlignCenter) self.alarm_box_x.addWidget(self.alarm_x) self.alarm_box_y.addWidget(self.y_label) self.alarm_box_y.setAlignment(self.y_label, Qt.AlignCenter) self.alarm_box_y.addWidget(self.alarm_y) self.alarm_box_p.addWidget(self.p_label) self.alarm_box_p.setAlignment(self.p_label, Qt.AlignCenter) self.alarm_box_p.addWidget(self.alarm_p) self.alarm_box_gantry_x.addWidget(self.gantry_x_label) self.alarm_box_gantry_x.setAlignment(self.gantry_x_label, Qt.AlignCenter) self.alarm_box_gantry_x.addWidget(self.alarm_gantry_x) self.alarm_box_gantry_y.addWidget(self.gantry_y_label) self.alarm_box_gantry_y.setAlignment(self.gantry_y_label, Qt.AlignCenter) self.alarm_box_gantry_y.addWidget(self.alarm_gantry_y) self.stop_button = PyDMPushButton(label="Stop") self.stop_button.setMaximumHeight(120) self.stop_button.setMaximumWidth(120) self.stop_button.clicked.connect(self.stop_motors) self.stop_button.setStyleSheet("background: rgb(255,0,0)") self.advanced_button = TyphosRelatedSuiteButton() self.advanced_button.happi_names = [macros['MIRROR'].lower() + "_homs"] self.advanced_button.setText("Advanced") self.ui.horizontalLayout_8.addLayout(self.alarm_box_x) self.ui.horizontalLayout_8.addLayout(self.alarm_box_y) self.ui.horizontalLayout_8.addLayout(self.alarm_box_p) self.ui.horizontalLayout_8.addLayout(self.alarm_box_gantry_x) self.ui.horizontalLayout_8.addLayout(self.alarm_box_gantry_y) #self.ui.horizontalLayout_8.addWidget(self.alarm_x) #self.ui.horizontalLayout_8.addWidget(self.alarm_y) #self.ui.horizontalLayout_8.addWidget(self.alarm_p) #self.ui.horizontalLayout_8.addWidget(self.stop_button) #self.ui.verticalLayout_6.setAlignment(Qt.AlignCenter) self.ui.horizontalLayout_14.addWidget(self.advanced_button) self.ui.horizontalLayout_14.addSpacing(50) self.ui.horizontalLayout_14.addWidget(self.stop_button) self.ui.horizontalLayout_14.addSpacing(160) self.ui.setGeometry(QtCore.QRect(0,0, 360, 385))
def __init__(self, parent=None): QDialog.__init__(self, parent=parent) self._shortcuts_summary_title = SHORTCUTS_SUMMARY_TITLE # Calculate font and amount of elements in each column # according screen size width, height = self.get_screen_resolution() font_size = height / 80 font_size = max(min(font_size, MAX_FONT_SIZE), MIN_FONT_SIZE) shortcuts_column = (height - 8 * font_size) / (font_size + 16) # Widgets style = """ QDialog { margin:0px; padding:0px; border-radius: 2px; }""" self.setStyleSheet(style) font_names = QFont() font_names.setPointSize(font_size) font_names.setBold(True) font_keystr = QFont() font_keystr.setPointSize(font_size) font_title = QFont() font_title.setPointSize(font_size + 2) font_title.setBold(True) title_label = QLabel(self._shortcuts_summary_title) title_label.setAlignment(Qt.AlignCenter) title_label.setFont(font_title) # iter over shortcuts and create GroupBox for each context # with shortcuts in a grid columns_layout = QHBoxLayout() added_shortcuts = 0 group = None # group shortcuts by context shortcuts = groupby(sorted(CONF.iter_shortcuts()), key=itemgetter(0)) for __, group_shortcuts in shortcuts: for i, (context, name, keystr) in enumerate(group_shortcuts): # start of every column if added_shortcuts == 0: column_layout = QVBoxLayout() # at start of new context add previous context group if i == 0 and added_shortcuts > 0: column_layout.addWidget(group) # create group at start of column or context if added_shortcuts == 0 or i == 0: if context == '_': context = 'Global' group = QGroupBox(context.capitalize()) group.setFont(font_names) group_layout = QGridLayout() group.setLayout(group_layout) # Count space for titles added_shortcuts += 1 # Widgets label_name = QLabel(name.capitalize().replace('_', ' ')) label_name.setFont(font_names) keystr = QKeySequence(keystr).toString(QKeySequence.NativeText) label_keystr = QLabel(keystr) label_keystr.setFont(font_keystr) group_layout.addWidget(label_name, i, 0) group_layout.addWidget(label_keystr, i, 1) added_shortcuts += 1 if added_shortcuts >= shortcuts_column: column_layout.addWidget(group) columns_layout.addLayout(column_layout) added_shortcuts = 0 column_layout.addWidget(group) column_layout.addStretch() # avoid lasts sections to appear too big columns_layout.addLayout(column_layout) # Scroll widget self.scroll_widget = QWidget() self.scroll_widget.setLayout(columns_layout) self.scroll_area = QScrollArea() self.scroll_area.setWidget(self.scroll_widget) # widget setup self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowOpacity(0.95) # layout self._layout = QVBoxLayout() self._layout.addWidget(title_label) self._layout.addWidget(self.scroll_area) self.setLayout(self._layout) self.setGeometry(0, 0, width, height)
def data(self, index, role=Qt.DisplayRole): if not index.isValid(): return None result = None record = self.records[index.row()] if getattr(record, '_cutelog', False): return self.data_internal(index, record, role) if role == Qt.DisplayRole: column_name = self.table_header[index.column()].name if self.extra_mode and column_name == "message": result = self.get_extra(record.message, record) else: result = getattr(record, column_name, None) elif role == Qt.SizeHintRole: if self.extra_mode and self.table_header[ index.column()].name == 'message': return QSize( 1, CONFIG.logger_row_height * (1 + len(self.get_fields_for_extra(record)))) else: return QSize(1, CONFIG.logger_row_height) elif role == Qt.DecorationRole: if self.table_header[index.column()].name == 'message': if record.exc_text: mode = CONFIG['exception_indication'] should = mode in (Exc_Indication.MSG_ICON, Exc_Indication.ICON_AND_RED_BG) if should: result = self.parent_widget.style().standardIcon( QStyle.SP_BrowserStop) elif role == Qt.FontRole: level = self.levels.get(record.levelname, NO_LEVEL) styles = level.styles if not self.dark_theme else level.stylesDark result = QFont(CONFIG.logger_table_font, CONFIG.logger_table_font_size) if styles: if 'bold' in styles: result.setBold(True) if 'italic' in styles: result.setItalic(True) if 'underline' in styles: result.setUnderline(True) elif role == Qt.ForegroundRole: level = self.levels.get(record.levelname, NO_LEVEL) if not self.dark_theme: result = level.fg else: result = level.fgDark elif role == Qt.BackgroundRole: if record.exc_text: mode = CONFIG['exception_indication'] should = mode in (Exc_Indication.RED_BG, Exc_Indication.ICON_AND_RED_BG) if should: if not self.dark_theme: color = QColor(255, 180, 180) else: color = Qt.darkRed result = QBrush(color, Qt.DiagCrossPattern) return result level = self.levels.get(record.levelname, NO_LEVEL) if not self.dark_theme: result = level.bg else: result = level.bgDark elif role == SearchRole: result = record.message return result
def configure_plot(self): self.plot.setTitle(title=self.plot_config['title'], **{ 'color': 'w', 'size': '16pt' }) self.plot.hideButtons() if self.plot_config['image_plot']: self.img = pg.ImageItem() self.plot.addItem(self.img) pos = np.array(self.plot_config['c_lim']) # color = np.array([[0, 0, 0, 255], self.plot_config['pen_color'].getRgb()], dtype=np.ubyte) # c_map = pg.ColorMap(pos, color) # lut = c_map.getLookupTable(pos[0], pos[1], 1024) colormap = cm.get_cmap("inferno") # cm.get_cmap("CMRmap") colormap._init() lut = (colormap._lut * 255).view( np.ndarray ) # Convert matplotlib colormap from 0-1 to 0 -255 for Qt self.img.setLookupTable(lut) self.img.setLevels(pos) self.img.scale(1 / 1000, 1) self.img.setPos(DEPTHRANGE[0], 0) if self.plot_config['marker_line'] is not None: self.plot.addItem( pg.InfiniteLine(angle=0 if self.plot_config['swap_xy'] else 90, pos=self.plot_config['marker_line'], movable=False, pen='y')) self.plot.setMouseEnabled(x=self.plot_config['mouse_enabled'][0], y=self.plot_config['mouse_enabled'][1]) # if mouse is enabled, a right click will bring the plot range to its default values self.plot.scene().sigMouseClicked.connect(self.mouse_clicked) self.plot.vb.installEventFilter(self) if self.plot_config['x_range']: self.plot.setXRange(self.plot_config['x_range'][0], self.plot_config['x_range'][1], padding=0) if self.plot_config['y_range']: self.plot.setYRange(self.plot_config['y_range'][0], self.plot_config['y_range'][1], padding=0) self.plot.setLabel('bottom', self.plot_config['x_label']) self.plot.setLabel('left', self.plot_config['y_label']) if not self.plot_config['x_axis']: self.plot.hideAxis('bottom') if not self.plot_config['y_axis']: self.plot.hideAxis('left') font = QFont() font.setPixelSize(20) font.setBold(True) self.plot.getAxis('bottom').setStyle( showValues=self.plot_config['x_ticks'], tickFont=font, tickTextOffset=10) self.plot.getAxis('bottom').setTextPen((255, 255, 255, 255)) self.plot.getAxis('left').setStyle( showValues=self.plot_config['y_ticks'], tickFont=font) self.plot.getAxis('left').setTextPen((255, 255, 255, 255)) if self.plot_config['y_tick_labels']: self.plot.getAxis('left').setTicks( self.plot_config['y_tick_labels']) if self.plot_config['interactive']: self.plot.scene().sigMouseMoved.connect(self.mouse_moved) if self.plot_config['swap_xy']: self.line = pg.InfiniteLine(angle=0, pos=-9999, movable=False, pen='w') else: self.line = pg.InfiniteLine(angle=90, pos=-9999, movable=False, pen='w') self.line.setZValue(5) self.plot.addItem(self.line) self.text = pg.TextItem(text='', color='w', fill=(0, 0, 0, 0)) self.text.setAnchor(self.plot_config['text_anchor']) self.text.setX(0) # self.text.setY(0.5) self.text.setY(0) self.plot.addItem(self.text) self.text.setZValue(6)
QIcon, 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')
class StatusBarWidget(QWidget): """Status bar widget base.""" # Signals sig_clicked = Signal() def __init__(self, parent, statusbar, icon=None): """Status bar widget base.""" super(StatusBarWidget, self).__init__(parent) # Variables self.value = None # Widget self._status_bar = statusbar self._icon = None self._pixmap = None self._icon_size = QSize(16, 16) # Should this be adjustable? self.label_icon = QLabel() if icon is not None else None self.label_value = QLabel() # Widget setup self.set_icon(icon) # See spyder-ide/spyder#9044. self.text_font = QFont(get_font(option='font')) self.text_font.setPointSize(self.font().pointSize()) self.text_font.setBold(True) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) # Layout layout = QHBoxLayout() if icon is not None: layout.addWidget(self.label_icon) layout.addWidget(self.label_value) layout.addSpacing(20) # Layout setup layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Setup statusbar.addPermanentWidget(self) self.set_value('') self.update_tooltip() # --- Status bar widget API # ------------------------------------------------------------------------ def set_icon(self, icon): """Set the icon for the status bar widget.""" if icon is not None and isinstance(icon, QIcon): self._icon = icon self._pixmap = icon.pixmap(self._icon_size) self.label_icon.setPixmap(self._pixmap) def set_value(self, value): """Set formatted text value.""" self.value = value self.label_value.setText(value) def update_tooltip(self): """Update tooltip for widget.""" tooltip = self.get_tooltip() if tooltip: self.label_value.setToolTip(tooltip) if self.label_icon: self.label_icon.setToolTip(tooltip) self.setToolTip(tooltip) def mouseReleaseEvent(self, event): """Override Qt method to allow for click signal.""" super(StatusBarWidget, self).mousePressEvent(event) self.sig_clicked.emit() # --- API to be defined by user # ------------------------------------------------------------------------ def get_tooltip(self): """Return the widget tooltip text.""" return '' def get_icon(self): """Return the widget tooltip text.""" return None
def __init__(self, parent=None): QDialog.__init__(self, parent=parent) self._shortcuts_summary_title = _("Spyder Keyboard ShortCuts") # Calculate font and amount of elements in each column according screen size width, height = self.get_screen_resolution() font_size = height / 80 font_size = max(min(font_size, MAX_FONT_SIZE), MIN_FONT_SIZE) shortcuts_column = (height - 8 * font_size) / (font_size +16) # Widgets style = """ QDialog { margin:0px; padding:0px; border-radius: 2px; }""" self.setStyleSheet(style) font_names = QFont() font_names.setPointSize(font_size) font_names.setBold(True) font_keystr = QFont() font_keystr.setPointSize(font_size) font_title = QFont() font_title.setPointSize(font_size+2) font_title.setBold(True) title_label = QLabel(self._shortcuts_summary_title) title_label.setAlignment(Qt.AlignCenter) title_label.setFont(font_title) # iter over shortcuts and create GroupBox for each context # with shortcuts in a grid columns_layout = QHBoxLayout() added_shortcuts = 0 group = None # group shortcuts by context shortcuts = groupby(sorted(iter_shortcuts()), key=itemgetter(0)) for context, group_shortcuts in shortcuts: for i, (context, name, keystr) in enumerate(group_shortcuts): # start of every column if added_shortcuts == 0: column_layout = QVBoxLayout() # at start of new context add previous context group if i == 0 and added_shortcuts > 0: column_layout.addWidget(group) # create group at start of column or context if added_shortcuts == 0 or i == 0: if context == '_': context = 'Global' group = QGroupBox(context.capitalize()) group.setFont(font_names) group_layout = QGridLayout() group.setLayout(group_layout) # Count space for titles added_shortcuts += 1 # Widgets label_name = QLabel(name.capitalize().replace('_', ' ')) label_name.setFont(font_names) keystr = QKeySequence(keystr).toString(QKeySequence.NativeText) label_keystr = QLabel(keystr) label_keystr.setFont(font_keystr) group_layout.addWidget(label_name, i, 0) group_layout.addWidget(label_keystr, i, 1) added_shortcuts += 1 if added_shortcuts >= shortcuts_column: column_layout.addWidget(group) columns_layout.addLayout(column_layout) added_shortcuts = 0 column_layout.addWidget(group) column_layout.addStretch() # avoid lasts sections to appear too big columns_layout.addLayout(column_layout) # Scroll widget self.scroll_widget = QWidget() self.scroll_widget.setLayout(columns_layout) self.scroll_area = QScrollArea() self.scroll_area.setWidget(self.scroll_widget) # widget setup self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowOpacity(0.95) # layout self._layout = QVBoxLayout() self._layout.addWidget(title_label) self._layout.addWidget(self.scroll_area) self.setLayout(self._layout) self.setGeometry(0, 0, width, height)
def create_plots(self, theme='dark', **kwargs): bold_font = QFont() bold_font.setPixelSize(12) bold_font.setBold(True) self.layout().addStretch() self.layout().addWidget(QLabel("Channels: ", font=bold_font)) self.layout().addSpacing(10) # Add check boxes for channels self.channels = {} for chan_ix in range(len(self.group_info)): chan_lbl = self.group_info[chan_ix]['label'] chk_box = QCheckBox(chan_lbl) chk_box.stateChanged.connect(self.check_channel_and_stim) self.channels[chan_lbl] = chk_box self.layout().addWidget(chk_box) self.layout().addSpacing(10) bt_clear = QPushButton("Uncheck all") bt_clear.clicked.connect(lambda: self.uncheck_all(self.channels)) self.layout().addWidget(bt_clear) self.layout().addSpacing(20) # Stimuli types self.layout().addWidget(QLabel("Stimuli: ", font=bold_font)) self.layout().addSpacing(10) self.mapping_stimuli = {} for stim in MAPPINGSTIMULI: self.mapping_stimuli[stim] = QCheckBox(stim) self.mapping_stimuli[stim].stateChanged.connect( self.check_channel_and_stim) self.layout().addWidget(self.mapping_stimuli[stim]) self.mapping_stimuli['Custom'] = QCheckBox() l = QHBoxLayout() self.custom_stimulus = QLineEdit("Custom") l.addWidget(self.mapping_stimuli['Custom']) l.addSpacing(3) l.addWidget(self.custom_stimulus) self.layout().addLayout(l) self.layout().addSpacing(10) bt_clear = QPushButton("Uncheck all") bt_clear.clicked.connect( lambda: self.uncheck_all(self.mapping_stimuli)) self.layout().addWidget(bt_clear) self.layout().addSpacing(20) # side self.layout().addWidget(QLabel("Body Side: ", font=bold_font)) self.layout().addSpacing(10) self.sides = {'Left': QCheckBox("Left"), 'Right': QCheckBox("Right")} l = QHBoxLayout() l.addWidget(self.sides['Left']) l.addWidget(self.sides['Right']) self.layout().addLayout(l) self.layout().addSpacing(20) # Body part self.layout().addWidget(QLabel("Limb: ", font=bold_font)) body_widget = QWidget(self) body_widget.setLayout(QGridLayout()) body_widget.layout().setContentsMargins(0, 0, 0, 0) lbl = QLabel() lbl.setPixmap( QPixmap( os.path.join(os.path.dirname(__file__), 'icons', 'HalfBody.png'))) body_widget.layout().addWidget(lbl, 0, 0, 20, 10) self.body_parts = {} cb = QCheckBox('') self.body_parts['Head'] = cb body_widget.layout().addWidget(cb, 1, 0, 1, 1) cb = QCheckBox('') self.body_parts['Arm'] = cb body_widget.layout().addWidget(cb, 8, 4, 1, 1) cb = QCheckBox('') self.body_parts['Hand'] = cb body_widget.layout().addWidget(cb, 10, 5, 1, 1) cb = QCheckBox('') self.body_parts['Leg'] = cb body_widget.layout().addWidget(cb, 14, 1, 1, 1) cb = QCheckBox('') self.body_parts['Foot'] = cb body_widget.layout().addWidget(cb, 18, 1, 1, 1) bt_clear = QPushButton("Uncheck all") bt_clear.clicked.connect(lambda: self.uncheck_all(self.body_parts)) body_widget.layout().addWidget(bt_clear, 20, 0, 1, 10) self.layout().addWidget(body_widget) self.layout().addSpacing(20) self.bt_map = QPushButton("Submit Response") self.bt_map.setEnabled(False) self.bt_map.setMinimumHeight(40) self.bt_map.clicked.connect(self.submit_map) self.layout().addWidget(self.bt_map) self.layout().addSpacing(10) bt_clear = QPushButton("Clear Channel") bt_clear.setMinimumHeight(20) bt_clear.clicked.connect(self.clear_data) self.layout().addWidget(bt_clear) self.layout().addStretch() # manual notes self.layout().addWidget(QLabel("Note: ", font=bold_font)) self.note_field = QTextEdit() self.note_field.setMaximumHeight(80) self.note_field.textChanged.connect(self.check_note) self.layout().addWidget(self.note_field) self.layout().addSpacing(10) self.bt_note = QPushButton("Submit Note") self.bt_note.setEnabled(False) self.bt_note.setMinimumHeight(20) self.bt_note.clicked.connect(self.submit_note) self.layout().addWidget(self.bt_note) self.layout().addStretch()
def set_visible(self, is_visible: bool) -> None: font = QFont() font.setBold(is_visible) font.setItalic(not is_visible) self.setFont(0, font)