def _add_table(self, tab, cursor): fmt = QTextCharFormat() fmt.setFont(QFont(self.factory.font_name)) fmt.setFontPointSize(self.factory.font_size) bc = QColor(self.factory.bg_color) if self.factory.bg_color else None ec, oc, hc = bc, bc, bc if self.factory.even_color: ec = QColor(self.factory.even_color) if self.factory.odd_color: oc = QColor(self.factory.odd_color) if self.factory.header_color: hc = QColor(self.factory.header_color) with EditBlock(cursor): for i, row in enumerate(tab.items): cell = row.cells[0] if cell.bold: fmt.setFontWeight(QFont.Bold) else: fmt.setFontWeight(QFont.Normal) if i == 0 and hc: c = hc elif (i - 1) % 2 == 0: c = ec else: c = oc if c: fmt.setBackground(c) txt = ''.join([u'{{:<{}s}}'.format(cell.width).format(cell.text) for cell in row.cells ]) cursor.insertText(txt + '\n', fmt)
def _init_ui(self, txt): self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint) pal = QPalette() color = QColor() color.setNamedColor(self._window_bgcolor) color.setAlpha(255 * self._opacity) pal.setColor(QPalette.Background, color) self.setAutoFillBackground(True) self.setPalette(pal) wm, hm = 5, 5 spacing = 8 layout = QVBoxLayout() layout.setSpacing(spacing) layout.setContentsMargins(wm, hm, wm, hm) nlines, ts = self._generate_text(txt) qlabel = QLabel('\n'.join(ts)) ss = 'QLabel {{color: {}; font-family:{}, sans-serif; font-size: {}px}}'.format(self._color, self._font, self._fontsize) qlabel.setStyleSheet(ss) layout.addWidget(qlabel) hlabel = QLabel('double click to dismiss') hlabel.setStyleSheet('QLabel {font-size: 10px}') hlayout = QHBoxLayout() hlayout.addStretch() hlayout.addWidget(hlabel) hlayout.addStretch() layout.addLayout(hlayout) self.setLayout(layout) font = QFont(self._font, self._fontsize) fm = QFontMetrics(font) pw = max([fm.width(ti) for ti in ts]) ph = (fm.height() + 2) * nlines w = pw + wm * 2 h = ph + (hm + spacing + 1) * 2 self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.setFixedWidth(w) self.setFixedHeight(h) self.setMask(mask(self.rect(), 10))
def __init__(self, *args, **kw): super(PatchWidget, self).__init__(*args, **kw) self.aline_number_widget = DiffGutter(self) # self.aline_number_widget.min_char_width=3 self.aline_number_widget.anti_tag='+' self.bline_number_widget = DiffGutter(self) # self.bline_number_widget.min_char_width=3 self.bline_number_widget.anti_tag='-' self.bline_number_widget.adjust_width=-1 font =QFont() self.set_font(font)
def __init__(self, *args, **kw): super(myTableView, self).__init__(*args, **kw) editor = self._editor self.clear_selection_on_dclicked = editor.factory.clear_selection_on_dclicked font = editor.factory.cell_font if font is not None: fnt = QFont(font) size = QFontMetrics(fnt) vheader = self.verticalHeader() hheader = self.horizontalHeader() vheader.setDefaultSectionSize(size.height() + 2) #hheader.setStretchLastSection(editor.factory.stretch_last_section) hheader.setFont(fnt)
def init(self, parent): if self.control is None: self.control = self.control_klass() self.control.setReadOnly(True) if self.factory.max_blocks: self.control.setMaximumBlockCount(self.factory.max_blocks) self.sync_value(self.factory.clear, 'clear', mode='from') self.sync_value(self.factory.refresh, 'refresh', mode='from') self.sync_value(self.factory.font_size, 'font_size', mode='from') self.sync_value(self.factory.bgcolor, 'bgcolor', mode='from') # self.sync_value(self.factory.text_width, 'text_width', mode='to') fmt = self.control.currentCharFormat() if self.factory.font_name: fmt.setFont(QFont(self.factory.font_name)) #if self.factory.font_size: # fmt.setFontPointSize(self.factory.font_size) self.control.setCurrentCharFormat(fmt)
def test_create_traitsfont_qfont(self): font = QFont("Comic Sans", 18, QFont.Weight.Bold, False) traits_font = create_traitsfont(font) self.assertIsInstance(traits_font, TraitsFont) self.assert_qfont_equal(traits_font, font)
def font_to_toolkit_font(font): """ Convert a Pyface font to a Qfont. Parameters ---------- font : pyface.font.Font The Pyface font to convert. Returns ------- qt_font : QFont The best matching Qt font. """ qt_font = QFont() families = [] default_family = None for family in font.family: if family not in generic_family_to_qt_family: families.append(family) elif default_family is None: default_family = family if families and hasattr(qt_font, 'setFamilies'): # Qt 5.13 and later qt_font.setFamilies(families) elif families: qt_font.setFamily(families[0]) # Note: possibily could use substitutions here, # but not sure if global (which would be bad, so we don't) if default_family is not None: qt_font.setStyleHint(generic_family_to_qt_family[default_family]) qt_font.setPointSizeF(font.size) qt_font.setWeight(weight_to_qt_weight[font.weight_]) qt_font.setStretch(int(font.stretch)) qt_font.setStyle(style_to_qt_style[font.style]) qt_font.setUnderline('underline' in font.decorations) qt_font.setStrikeOut('strikethrough' in font.decorations) qt_font.setOverline('overline' in font.decorations) if 'small-caps' in font.variants: qt_font.setCapitalization(QFont.Capitalization.SmallCaps) return qt_font