def format_pg_plotitem(plot, x_lim, y_lim, x_range=None, y_range=None): ''' Applies a standard format to a pyqtgraph chart. :param plot: the plot item. :param x_lim: the x axis limits. :param y_lim: the y axis limits. :param x_range: the visible x limits. :param y_range: the visible y limits. ''' label_font = QFont() label_font.setPointSize(9) label_font.setFamily('DejaVu Sans') for name in ['left', 'right', 'bottom', 'top']: plot.getAxis(name).setTickFont(label_font) plot.showGrid(x=True, y=True, alpha=0.5) plot.disableAutoRange() plot.setLimits(xMin=x_lim[0], xMax=x_lim[1], yMin=y_lim[0], yMax=y_lim[1]) plot.setXRange(*x_lim, padding=0.0) if x_range is None: plot.setXRange(*x_lim, padding=0.0) else: plot.setXRange(*x_range, padding=0.0) if y_range is None: plot.setYRange(*y_lim, padding=0.0) else: plot.setYRange(*y_range, padding=0.0) plot.setDownsampling(ds=False) plot.layout.setContentsMargins(10, 20, 30, 20)
def setFont(self, font=None): if font is None: font = QFont() # default font font.setFamily('Courier New') font.setPointSize(11) self.find.txtSearch.setFont(font) self.tree.setFont(font) self.form.setFont(font)
def font(self, prefix, size): """Return a QFont corresponding to the given prefix and size.""" font = QFont() font.setFamily(self.fontname[prefix]) font.setPixelSize(round(size)) if prefix[-1] == 's': # solid style font.setStyleName('Solid') return font
def __init__(self, parent=None): """ very similar to: https://stackoverflow.com/questions/40002373/qscintilla-based-text-editor-in-pyqt5-with-clickable-functions-and-variables """ super(SimplePythonEditorWidget, self).__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) self.set_font(font) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) if qt_version == 'pyqt4': self.connect(self, QtCore.SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'), self.on_margin_clicked) else: self.marginClicked.connect(self.on_margin_clicked) self.markerDefine(Qsci.QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) if qt_version == 'pyqt4': self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') else: font_style = bytearray(str.encode("Courier")) self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, font_style) # 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(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)
def get_code_block(): if is_pygments and IS_SCINTILLA: #self.enter_data = QSyntaxHighlighting() enter_data = SimplePythonEditorWidget() else: enter_data = QTextEditAdd() font = QFont() font.setFamily('Courier') enter_data.setFont(font) return enter_data
def __init__(self, parent=None): super(SimplePythonEditorWidget, self).__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) self.connect( self, QtCore.SIGNAL( 'marginClicked(int, int, Qt::KeyboardModifiers)'), self.on_margin_clicked) self.markerDefine(Qsci.QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, '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(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)
def __init__(self, parent=None): super(EditorBase, self).__init__(parent) # linuxcnc defaults self.idle_line_reset = False # don't allow editing by default self.setReadOnly(True) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(14) # Set custom gcode lexer self.lexer = GcodeLexer(self) self.lexer.setDefaultFont(font) self.setLexer(self.lexer) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("0") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) # setting marker margin width to zero make the marker highlight line self.setMarginWidth(1, 10) self.marginClicked.connect(self.on_margin_clicked) self.markerDefine(QsciScintilla.RightTriangle, self.ARROW_MARKER_NUM) # #ffe4e4 self.setMarkerBackgroundColor(QColor("slate"), 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(QColor("#ffe4e4")) # default gray background self.set_background_color('#C0C0C0') self.highlit = None
def show_remux_cmd(self): ''' Pops the ffmpeg command into a message box ''' if self.__executor is not None and self.__executor.filter_complex_script_content is not None: msg_box = QMessageBox() font = QFont() font.setFamily("Consolas") font.setPointSize(8) msg_box.setFont(font) msg_box.setText( self.__executor.filter_complex_script_content.replace( ';', ';\n')) msg_box.setIcon(QMessageBox.Information) msg_box.setWindowTitle('Remux Script') msg_box.exec()
def refreshEditorFont(self): """Taking the new default font and build a new lexer instance. Apply the new lexer to the editor. """ # Note that if you do not create a new lexer the # the font does not get applied/used. font = QFont() font.setFamily(self.default_font_name) font.setFixedPitch(True) font.setPointSize(14) self.lexer = GcodeLexer(self) self.lexer.setDefaultFont(font) self.setLexer(self.lexer) # rebuild gutter for new font self.setNumberGutter(self.lines()) # set the gutter font to be aligned to main font self.setMarginsFont(font)
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 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 main(): app = QApplication(sys.argv) if getattr(sys, 'frozen', False): iconPath = os.path.join(sys._MEIPASS, 'Icon.ico') else: iconPath = os.path.abspath( os.path.join(os.path.dirname('__file__'), '../icons/Icon.ico')) if os.path.exists(iconPath): app.setWindowIcon(QIcon(iconPath)) form = PyPolarmap(app) # setup the error handler global e_dialog e_dialog = QErrorMessage(form) e_dialog.setWindowModality(QtCore.Qt.WindowModal) font = QFont() font.setFamily("Consolas") font.setPointSize(8) e_dialog.setFont(font) form.show() app.exec_()
def __init__(self, parent): self.parent = parent super(PythonConsoleWidget, self).__init__('Python Console', parent=parent) #super(QDockWidget, self).__init__('Python Console', parent=parent) # I think this works by accident in qt4/5 self.listMenu = QMenu() self.execute_python_button = QPushButton('Execute') self.execute_and_clear_python_button = QPushButton('Execute and Clear') if is_pygments and is_scintilla: #self.enter_data = QSyntaxHighlighting() self.enter_data = SimplePythonEditorWidget() else: self.enter_data = QTextEdit() font = QFont() font.setFamily('Courier') self.enter_data.setFont(font) self.setup_connections() self.layout()
def __init__(self, chart, crest_factor, rms_level, headroom, x_min, x_max, y_min, y_max, on_x_range_change): self.idx = 0 self.__chart = chart self.__on_x_range_change = on_x_range_change self.__x_min = x_min self.__x_max = x_max self.__x_min.editingFinished.connect(self.__update_x_range) self.__x_max.editingFinished.connect(self.__update_x_range) self.__y_min = y_min self.__y_max = y_max self.__y_min.editingFinished.connect(self.__update_y_range) self.__y_max.editingFinished.connect(self.__update_y_range) self.__chart = chart label_font = QFont() fp = FontProperties() label_font.setPointSize(fp.get_size_in_points() * 0.7) label_font.setFamily(fp.get_name()) for name in ['left', 'right', 'bottom', 'top']: self.__chart.getPlotItem().getAxis(name).setTickFont(label_font) self.__chart.getPlotItem().showGrid(x=True, y=True, alpha=0.5) self.__chart.getPlotItem().disableAutoRange() self.__chart.getPlotItem().setLimits(xMin=0.0, xMax=1.0, yMin=-1.0, yMax=1.0) self.__chart.getPlotItem().setXRange(0, 1, padding=0.0) self.__chart.getPlotItem().setYRange(-1, 1, padding=0.0) self.__chart.getPlotItem().setDownsampling(ds=True, auto=True, mode='peak') self.__chart.getPlotItem().layout.setContentsMargins(10, 20, 30, 20) self.__chart.getPlotItem().sigXRangeChanged.connect( self.__propagate_x_range) self.__chart.getPlotItem().sigYRangeChanged.connect( self.__propagate_y_range) self.__headroom = headroom self.__rms_level = rms_level self.__crest_factor = crest_factor self.__signal = None self.__curve = None
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 __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)
else: icon_path = os.path.abspath( os.path.join(os.path.dirname('__file__'), '../icons/Icon.ico')) if os.path.exists(icon_path): app.setWindowIcon(QIcon(icon_path)) return app, Preferences(QSettings("3ll3d00d", "qvibe-analyser")) if __name__ == '__main__': app, prefs = make_app() form = QVibe(app, prefs) # setup the error handler e_dialog = QErrorMessage(form) e_dialog.setWindowModality(QtCore.Qt.WindowModal) font = QFont() font.setFamily("Consolas") font.setPointSize(8) e_dialog.setFont(font) # add the exception handler so we can see the errors in a QErrorMessage sys._excepthook = sys.excepthook def dump_exception_to_log(exctype, value, tb): import traceback print(exctype, value, tb) global e_dialog if e_dialog is not None: formatted = traceback.format_exception(etype=exctype, value=value, tb=tb) e_dialog.setWindowTitle('Unexpected Error') url = 'https://github.com/3ll3d00d/qvibe-analyser/issues/new'
def initialize_editor(self): self.editor = QsciScintilla() # self.editor.cursorPositionChanged.connect(self.e) # self.editor.copyAvailable.connect(self.e) # self.editor.indicatorClicked.connect(self.e) # self.editor.indicatorReleased.connect(self.e) # self.editor.linesChanged.connect(self.e) # self.editor.marginClicked.connect(self.e) # self.editor.modificationAttempted.connect(self.e) # self.editor.modificationChanged.connect(self.e) # self.editor.selectionChanged.connect(self.e) # self.editor.textChanged.connect(self.e) # self.editor.userListActivated.connect(self.e) if self.editor.__class__.__name__ == "LineTextWidget": return # When using PySide without QSciScintilla # define the font to use font = QFont() font.setFamily("Consolas") font.setFixedPitch(True) font.setPointSize(10) # the font metrics here will help # building the margin width later fm = QFontMetrics(font) # set the default font of the self.editor # and take the same font for line numbers self.editor.setFont(font) self.editor.setMarginsFont(font) # Line numbers # conventionnaly, margin 0 is for line numbers self.editor.setMarginWidth(0, fm.width("00000") + 5) self.editor.setMarginLineNumbers(0, True) self.editor.setTabWidth(4) # Folding visual : we will use boxes self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.editor.setAutoIndent(True) # Braces matching self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Editing line color self.editor.setCaretLineVisible(True) self.editor.setCaretLineBackgroundColor(QColor("#CDA869")) # Margins colors # line numbers margin self.editor.setMarginsBackgroundColor(QColor("#333333")) self.editor.setMarginsForegroundColor(QColor("#CCCCCC")) # folding margin colors (foreground,background) self.editor.setFoldMarginColors(QColor("#99CC66"), QColor("#333300")) # Choose a lexer self.lexer = QsciLexerPython() self.lexer.setDefaultFont(font) # Set the length of the string before the editor tries to autocomplete # In practise this would be higher than 1 # But its set lower here to make the autocompletion more obvious self.editor.setAutoCompletionThreshold(1) # Tell the editor we are using a QsciAPI for the autocompletion self.editor.setAutoCompletionSource(QsciScintilla.AcsAPIs) self.editor.setLexer(self.lexer) self.editor.setCallTipsStyle(QsciScintilla.CallTipsContext) # self.editor.setCallTipsVisible(0) # Create an API for us to populate with our autocomplete terms self.api = QsciAPIs(self.lexer) # Compile the api for use in the lexer self.api.prepare()