def __init__(self, parent=None, language='Python'): super(Editor, self).__init__(parent) self.setIndentationsUseTabs(False) self.setIndentationWidth(4) # Set the default font font = QtGui.QFont() font.setFamily('DejaVu Sans Mono') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) self.zoomIn() # Margin 0 is used for line numbers fontmetrics = QtGui.QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QtGui.QColor("#cccccc")) self._marker = None # Clickable margin 1 for showing markers #self.setMarginSensitivity(1, True) #self.connect(self, # SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'), # self.on_margin_clicked) self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QtGui.QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = getattr(Qsci, 'QsciLexer' + language)() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, b'Courier') # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.setWrapMode(QsciScintilla.WrapWord) self.setEolMode(QsciScintilla.EolUnix)
logdpi = screen.logicalDotsPerInch() print( # f'screen number: {screen_num}\n', f'screen name: {name}\n' f'screen size: {size}\n' f'screen geometry: {geo}\n\n' f'devicePixelRationF(): {pxr}\n' f'physical dpi: {phydpi}\n' f'logical dpi: {logdpi}\n') # app-wide font font = QtGui.QFont("Hack") # use pixel size to be cross-resolution compatible? font.setPixelSize(6) fm = QtGui.QFontMetrics(font) fontdpi = fm.fontDpi() font_h = fm.height() string = '10000' str_br = fm.boundingRect(string) str_w = str_br.width() print( # f'screen number: {screen_num}\n', f'font dpi: {fontdpi}\n' f'font height: {font_h}\n' f'string bounding rect: {str_br}\n' f'string width : {str_w}\n')