def on_install(self, editor): """ Extends :meth:`pyqode.core.api.Mode.on_install` method to set the editor instance as the parent widget. .. warning:: Don't forget to call **super** if you override this method! :param editor: editor instance :type editor: pyqode.core.api.CodeEdit """ Mode.on_install(self, editor) self.setParent(editor) # Qt5 compatibility try: self.setPalette(QtWidgets.QApplication.instance().palette()) except: self.setPalette(QtGui.QGuiApplication.palette()) # Qt5 compatibility try: self.setFont(QtWidgets.QApplication.instance().font()) except: self.setFont(QtGui.QGuiApplication.font()) self.editor.panels.refresh() self._background_brush = QtGui.QBrush( QtGui.QColor(self.palette().window().color())) self._foreground_pen = QtGui.QPen( QtGui.QColor(self.palette().windowText().color()))
def test_style(editor): panel = get_panel(editor) panel.request_search('import') QTest.qWait(1000) panel.background = QtGui.QColor('green') panel.foreground = QtGui.QColor('red') QTest.qWait(1000)
def _on_command_started(self, cmd): old_color = self.ui.textEditCompilerOutput.textColor() color = QtGui.QColor('#629755') if Settings().dark_style else \ QtGui.QColor('#000080') self.ui.textEditCompilerOutput.setTextColor(color) self.ui.textEditCompilerOutput.append(cmd) self.ui.textEditCompilerOutput.setTextColor(old_color)
def __init__(self): super(SymbolMatcherMode, self).__init__() self._decorations = [] self._match_background = QtGui.QBrush(QtGui.QColor('#B4EEB4')) self._match_foreground = QtGui.QColor('red') self._unmatch_background = QtGui.QBrush(QtGui.QColor('transparent')) self._unmatch_foreground = QtGui.QColor('red')
def test_formats(editor): deco = TextDecoration(editor.textCursor(), start_line=10, end_line=15) deco.set_foreground(QtGui.QColor('#FF0000')) deco.set_outline(QtGui.QColor('#FF0000')) deco.set_as_spell_check(QtGui.QColor('#FF0000')) deco.set_as_error(QtGui.QColor('#FF0000')) deco.set_as_error() deco.set_as_warning()
def __init__(self): super(OccurrencesHighlighterMode, self).__init__() self._decorations = [] #: Timer used to run the search request with a specific delay self.timer = DelayJobRunner(delay=1000) self._sub = None self._background = QtGui.QColor('#80CC80') self._foreground = QtGui.QColor('#404040') self._underlined = True
def paintEvent(self, event): # Fills the panel background using QPalette if self.isVisible(): # fill background self._background_brush = QtGui.QBrush( QtGui.QColor(self.palette().window().color())) self._foreground_pen = QtGui.QPen( QtGui.QColor(self.palette().windowText().color())) painter = QtGui.QPainter(self) painter.fillRect(event.rect(), self._background_brush)
def _init_style(self): """ Inits style options """ self._background = QtGui.QColor('white') self._foreground = QtGui.QColor('black') self._whitespaces_foreground = QtGui.QColor('light gray') app = QtWidgets.QApplication.instance() self._sel_background = app.palette().highlight().color() self._sel_foreground = app.palette().highlightedText().color() self._font_size = 10 self.font_name = ""
def __init__(self): super(ReadOnlyPanel, self).__init__(dynamic=True) # leave it here otherwise you will have circular import errors from pyqode.core._forms.pnl_read_only_ui import Ui_Form self.ui = Ui_Form() self.ui.setupUi(self) self._color = None self.color = QtGui.QColor('#8AADD4') self._foreground = None self.foreground = QtGui.QColor('#FFFFFF') self.hide()
def merged_colors(colorA, colorB, factor): maxFactor = 100 colorA = QtGui.QColor(colorA) colorB = QtGui.QColor(colorB) tmp = colorA tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor) tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor) tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor) return tmp
def update_editor_settings(editor): from open_cobol_ide.settings import Settings settings = Settings() # general settings for all editors editor.tab_length = settings.tab_len editor.font_name = settings.font editor.font_size = settings.font_size editor.show_whitespaces = settings.show_whitespaces editor.syntax_highlighter.color_scheme = ColorScheme(settings.color_scheme) editor.panels.get('FoldingPanel').native_look = not settings.dark_style try: # cobol editor specific settings editor.backspace_mode.enabled = settings.enable_smart_backspace editor.comment_indicator = settings.comment_indicator editor.free_format = settings.free_format editor.caret_line_mode.enabled = settings.highlight_caret editor.auto_indent_mode.enabled = settings.enable_autoindent editor.code_completion_mode.trigger_length = \ settings.code_completion_trigger_len editor.line_nbr_panel.enabled = settings.display_lines editor.line_nbr_panel.setVisible(settings.display_lines) editor.linter_mode.enabled = settings.show_errors editor.lower_case_keywords = settings.lower_case_keywords editor.file.autodetect_eol = settings.autodetect_eol editor.file.preferred_eol = settings.preferred_eol editor.modes.get('CodeCompletionMode').smart_completion = \ bool(settings.completion_filter_mode) editor.margins.positions = settings.margin_positions editor.margins.colors = [ QtGui.QColor(c) for c in settings.margin_colors ] except AttributeError as e: print(e) editor.syntax_highlighter.pygments_style = settings.color_scheme
def _get_color(color): """ Returns a QColor built from a Pygments color string. """ color = str(color).replace("#", "") qcolor = QtGui.QColor() qcolor.setRgb(int(color[:2], base=16), int(color[2:4], base=16), int(color[4:6], base=16)) return qcolor
def main(): app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() # code from the simple example editor = api.CodeEdit() editor.file.open(__file__) editor.modes.append(modes.CaretLineHighlighterMode()) sh = modes.PygmentsSyntaxHighlighter(editor.document()) editor.modes.append(sh) editor.panels.append(panels.SearchAndReplacePanel(), api.Panel.Position.TOP) # make the code edit show whitespaces in dark gray editor.show_white_spaces = True editor.whitespaces_foreground = QtGui.QColor('#606020') # make a dark editor using the monokai theme sh.pygments_style = 'monokai' window.setCentralWidget(editor) window.show() app.exec_() editor.file.close() del editor del window del app
def __init__(self, highlight_caret_scope=False): Panel.__init__(self) self._native = True self._custom_indicators = ( ':/pyqode-icons/rc/arrow_right_off.png', ':/pyqode-icons/rc/arrow_right_on.png', ':/pyqode-icons/rc/arrow_down_off.png', ':/pyqode-icons/rc/arrow_down_on.png' ) self._custom_color = QtGui.QColor('gray') self._block_nbr = -1 self._highlight_caret = False self.highlight_caret_scope = highlight_caret_scope self._indic_size = 16 #: the list of deco used to highlight the current fold region ( #: surrounding regions are darker) self._scope_decos = [] #: the list of folded blocs decorations self._block_decos = [] self.setMouseTracking(True) self.scrollable = True self._mouse_over_line = None self._current_scope = None self._prev_cursor = None self.context_menu = None self.action_collapse = None self.action_expand = None self.action_collapse_all = None self.action_expand_all = None self._original_background = None self._highlight_runner = DelayJobRunner(delay=250)
def __init__(self, add_context_menu=True): super(EncodingPanel, self).__init__(dynamic=True) # leave it here otherwise you will have circular import errors from pyqode.core._forms.pnl_encoding_ui import Ui_Form self.ui = Ui_Form() self.ui.setupUi(self) self.__add_ctx_mnu = add_context_menu self._labels = [self.ui.label, self.ui.lblDescription] self._color = None self.color = QtGui.QColor('#8AADD4') self._foreground = None self.foreground = QtGui.QColor('#FFFFFF') self._deco = None self.ui.pushButtonRetry.clicked.connect(self._reload) self.ui.pushButtonEdit.clicked.connect(self._edit_anyway) self.ui.pushButtonCancel.clicked.connect(self.cancel) self.hide()
def set_as_warning(self, color=QtGui.QColor("orange")): """ Highlights text as a syntax warning :param color: Underline color :type color: QtGui.QColor """ self.format.setUnderlineStyle(QtGui.QTextCharFormat.WaveUnderline) self.format.setUnderlineColor(color)
def __init__(self, parent=None): super(PyInteractiveConsole, self).__init__(parent) self.set_writer(self._write) self.setMouseTracking(True) self.PROG = QtCore.QRegExp(r'\s*File ".*", line [0-9]*, in ') self.FILENAME_PROG = QtCore.QRegExp(r'".*"') self.LINE_PROG = QtCore.QRegExp(r'line [0-9]*') self.setLineWrapMode(self.NoWrap) self._module_color = QtGui.QColor('blue')
def _show_error(self, error): if error: self._set_widget_background_color(self.lineEditSearch, QtGui.QColor('#FFCCCC')) self.lineEditSearch.setToolTip(str(error)) else: self._set_widget_background_color( self.lineEditSearch, self.palette().color(self.palette().Base)) self.lineEditSearch.setToolTip('')
def pick_color(self): """ Show color-picker dialog to select color. Qt will use the native dialog by default. """ dlg = QtWidgets.QColorDialog(self) dlg.setCurrentColor(QtGui.QColor(self._color)) dlg.exec_() self.color = dlg.currentColor()
def __init__(self): Panel.__init__(self) self._background = QtGui.QColor('#FFC8C8') self._markers = [] self._icons = {} self._previous_line = -1 self.scrollable = True self._job_runner = DelayJobRunner(delay=100) self.setMouseTracking(True) self._to_remove = []
def drift_color(base_color, factor=110): """ Return color that is lighter or darker than the base color. If base_color.lightness is higher than 128, the returned color is darker otherwise is is lighter. :param base_color: The base color to drift from ;:param factor: drift factor (%) :return A lighter or darker color. """ base_color = QtGui.QColor(base_color) if base_color.lightness() > 128: return base_color.darker(factor) else: if base_color == QtGui.QColor('#000000'): return drift_color(QtGui.QColor('#101010'), factor + 20) else: return base_color.lighter(factor + 10)
def _update_full_path(self): path = os.path.join(self.ui.dir_picker.path, self.ui.lineedit_name.text()) exists = os.path.exists(path) self.ui.buttonBox.button(self.ui.buttonBox.Ok).setEnabled(not exists) self.ui.label_full_path.setText(path) color = QtGui.QColor('#FFCCCC') if exists else self.palette().color( self.palette().Base) self._set_widget_background_color(self.ui.lineedit_name, color) self.ui.lineedit_name.setToolTip( 'Path already exists' if exists else '')
def __init__(self, parent=None): super(PyInteractiveConsole, self).__init__(parent) self.set_writer(self._write) self.setMouseTracking(True) self.PROG = QtCore.QRegExp( r'\s*File "[a-zA-Z\/_\d:\\\.]*((.\.[a-zA-Z\/_\d:\\]*")|(")), ' r'line [0-9]*.*') self.FILENAME_PROG = QtCore.QRegExp(r'"[a-zA-Z\/_\.\d:\\]*"') self.LINE_PROG = QtCore.QRegExp(r'line [0-9]*') self.setLineWrapMode(self.NoWrap) self._module_color = QtGui.QColor('blue')
def test_add_decoration(editor): helper = TextHelper(editor) helper.goto_line(2, 2) cursor = helper.word_under_cursor(select_whole_word=True) deco = TextDecoration(cursor) deco.set_as_bold() deco.set_as_underlined(QtGui.QColor("#FF0000")) editor.decorations.append(deco) assert not editor.decorations.append(deco) assert deco.contains_cursor(cursor) # keep editor clean for next tests editor.decorations.clear()
def test_clear_decoration(editor): # should work even when there are no more decorations helper = TextHelper(editor) editor.decorations.clear() cursor = helper.word_under_cursor(select_whole_word=True) deco = TextDecoration(cursor) deco.set_as_bold() deco.set_as_underlined(QtGui.QColor("#FF0000")) editor.decorations.append(deco) assert not editor.decorations.append(deco) editor.decorations.clear() assert editor.decorations.append(deco) assert editor.decorations.remove(deco)
def test_remove_decoration(editor): helper = TextHelper(editor) TextHelper(editor).goto_line(1, 2) cursor = helper.word_under_cursor(select_whole_word=True) deco = TextDecoration(cursor) deco.set_as_bold() deco.set_as_underlined(QtGui.QColor("#FF0000")) editor.decorations.append(deco) assert editor.decorations.remove(deco) # already removed, return False assert not editor.decorations.remove(deco) assert editor.decorations.append(deco) # keep editor clean for next tests editor.decorations.clear()
def test_drift_color(): assert utils.drift_color(QtGui.QColor("#FFFFFF")).name() == \ QtGui.QColor("#e8e8e8").name() assert utils.drift_color(QtGui.QColor("#202020")).name() == \ QtGui.QColor("#262626").name() assert utils.drift_color(QtGui.QColor("#000000")).name() == \ QtGui.QColor("#161616").name()
def _add_fold_decoration(self, block, region): """ Add fold decorations (boxes arround a folded block in the editor widget). """ deco = TextDecoration(block) deco.signals.clicked.connect(self._on_fold_deco_clicked) deco.tooltip = region.text(max_lines=25) deco.draw_order = 1 deco.block = block deco.select_line() deco.set_outline(drift_color(self._get_scope_highlight_color(), 110)) deco.set_background(self._get_scope_highlight_color()) deco.set_foreground(QtGui.QColor('#808080')) self._block_decos.append(deco) self.editor.decorations.append(deco)
def _add_decoration(self, cursor): """ Adds a decoration for the word under ``cursor``. """ if self._deco is None: if cursor.selectedText(): self._deco = TextDecoration(cursor) if self.editor.background.lightness() < 128: self._deco.set_foreground(QtGui.QColor('#0681e0')) else: self._deco.set_foreground(QtCore.Qt.blue) self._deco.set_as_underlined() self.editor.decorations.append(self._deco) self.editor.set_mouse_cursor(QtCore.Qt.PointingHandCursor) else: self.editor.set_mouse_cursor(QtCore.Qt.IBeamCursor)
def test_properties(editor): mode = get_mode(editor) c = QtGui.QColor('yellow') assert isinstance(mode.match_background, QtGui.QBrush) mode.match_background = c assert mode.match_background.name() == c.name() assert isinstance(mode.match_foreground, QtGui.QColor) mode.match_foreground = c assert mode.match_foreground.name() == c.name() assert isinstance(mode.unmatch_background, QtGui.QBrush) mode.unmatch_background = c assert mode.unmatch_background.name() == c.name() assert isinstance(mode.unmatch_foreground, QtGui.QColor) mode.unmatch_foreground = c assert mode.unmatch_foreground.name() == c.name()