def __init__(self, parent, codigo_inicial): super(InterpreteTextEdit, self).__init__(parent) self.ventana = parent sys.stdout = self sys.stderr = Output(self) self.refreshMarker = False self.multiline = False self.command = '' self.history = [] self.historyIndex = -1 self.interpreterLocals = {} # setting the color for bg and text #palette = QPalette() #palette.setColor(QPalette.Base, QColor(20, 20, 20)) #palette.setColor(QPalette.Text, QColor(0, 255, 0)) #self.setPalette(palette) self._set_font_size(16) self._highlighter = highlighter.Highlighter(self.document(), 'python', highlighter.COLOR_SCHEME) if codigo_inicial: for line in codigo_inicial.split("\n"): self.insertar_comando_falso(line) self.marker()
def setupEditor(self): font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.editor = QTextEdit() self.editor.setFont(font) self.highlighter = highlighter.Highlighter(self.editor.document())
def __init__(self, parent, codigo_inicial): super(InterpreteTextEdit, self).__init__(parent, self.funcion_valores_autocompletado) font_path = self._buscar_fuente_personalizada() if font_path: fuente_id = QFontDatabase.addApplicationFont(font_path) self.font_family = QFontDatabase.applicationFontFamilies( fuente_id)[0] else: self.font_family = "Courier New" self.ventana = parent self.stdout_original = sys.stdout sys.stdout = io.NormalOutput(self) sys.stderr = io.ErrorOutput(self) self.refreshMarker = False self.multiline = False self.command = '' self.history = [] self.historyIndex = -1 self.interpreterLocals = {} # setting the color for bg and text palette = QPalette() #palette.setColor(QPalette.Base, QColor(20, 20, 20)) palette.setColor(QPalette.Text, QColor(0, 0, 0)) self.setPalette(palette) if sys.platform == 'darwin': self._set_font_size(15) else: self._set_font_size(14) self._highlighter = highlighter.Highlighter(self.document(), 'python', highlighter.COLOR_SCHEME) if codigo_inicial: for line in codigo_inicial.split("\n"): self.insertar_comando_falso(line) self.marker() self.setUndoRedoEnabled(False) self.setContextMenuPolicy(Qt.NoContextMenu) self.timer_cursor = QTimer() self.timer_cursor.start(1000) self.timer_cursor.timeout.connect(self.marker_si_es_necesario)
def initGui(self): # Create action that will start plugin configuration self.action = QAction(QIcon(":/plugins/postgislayer/icon.png"), "Fast SQL Layer", self.iface.mainWindow()) #Add toolbar button and menu item self.iface.addPluginToDatabaseMenu("&Fast SQL Layer", self.action) #self.iface.addToolBarIcon(self.action) #load the form path = os.path.dirname(os.path.abspath(__file__)) self.dock = uic.loadUi(os.path.join(path, "ui_postgislayer.ui")) self.iface.addDockWidget(Qt.BottomDockWidgetArea, self.dock) #connect the action to the run method QObject.connect(self.action, SIGNAL("triggered()"), self.show) QObject.connect(self.dock.buttonRun, SIGNAL('clicked()'), self.run) QObject.connect(self.dock.buttonGet, SIGNAL('clicked()'), self.get) QObject.connect(self.dock.buttonRefreshConnections, SIGNAL('clicked()'), self.refresh) # Set an icon on the refresh button self.dock.buttonRefreshConnections.setIcon( QIcon(':/plugins/postgislayer/refresh.png')) # set a fixed font in the query editor, makes it easier to read self.dock.textQuery.document().setDefaultFont( QFont('Lucida Console', 9)) #populate the combo with connections self.refresh() #populate the gid/id and the_geom/geom combos self.dock.uniqueCombo.addItem('id') self.dock.uniqueCombo.addItem('gid') self.dock.geomCombo.addItem('geom') self.dock.geomCombo.addItem('the_geom') #populate the replace layer_combo self.dock.layerCombo.addItem('add layer') self.dock.layerCombo.addItem('replace layer') #start the highlight engine self.higlight_text = hl.Highlighter(self.dock.textQuery.document(), "sql")
def initGui(self): # Create action that will start plugin configuration self.action = QAction(QIcon(":/plugins/postgislayer/icon.png"), "Fast SQL Layer", self.iface.mainWindow()) #Add toolbar button and menu item self.iface.addToolBarIcon(self.action) #load the form path = os.path.dirname(os.path.abspath(__file__)) self.dock = uic.loadUi(os.path.join(path, "ui_postgislayer.ui")) self.iface.addDockWidget(Qt.BottomDockWidgetArea, self.dock) #connect the action to the run method QObject.connect(self.action, SIGNAL("triggered()"), self.show) QObject.connect(self.dock.buttonRun, SIGNAL('clicked()'), self.run) #populate the id and the_geom combos self.dock.uniqueCombo.addItem('id') self.dock.geomCombo.addItem('the_geom') #start the highlight engine self.higlight_text = hl.Highlighter(self.dock.textQuery.document(), "sql")
def createTab(self, tabTitle="untitled", editorText=None, filePath=None): tab = QtWidgets.QWidget() gridLayout = QtWidgets.QGridLayout(tab) gridLayout.setContentsMargins(0, 0, 0, 0) verticalLayout = QtWidgets.QVBoxLayout() editor = textEdit.AwesomeTextEdit(tab) editor.setLineWrapMode(editor.NoWrap) if editorText != None: editor.insertPlainText(str(editorText)) editor.setTabStopWidth(editor.fontMetrics().width(' ') * 8) editor.setObjectName("editor") editor.filePath = filePath editor.setTabStopDistance( QtGui.QFontMetricsF(editor.font()).width(' ') * 8) self.highlighter = highlighter.Highlighter(editor.document()) editor.textChanged.connect(editor.add_indent) editor.textChanged.connect( partial(editor.add_kw, self.highlighter.userkw)) new_font = QtGui.QFont("Consolas", 12) new_font.setLetterSpacing(QtGui.QFont.AbsoluteSpacing, 1.2) editor.setFont(new_font) verticalLayout.addWidget(editor) gridLayout.addLayout(verticalLayout, 0, 0, 1, 1) count = 1 title = tabTitle while True: if title in self.getAllTabTitles(): title = tabTitle + "(" + str(count) + ")" count += 1 continue break self.tabWidget.addTab(tab, title) self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1)
import sys import sip sip.setapi('QString', 2) from PyQt4.QtGui import QApplication, QTextEdit import highlighter code = \ """ (define func (x) (map (lambda (y) (+ x y)) x)) (display "hello, define world") """ code1 = ' "f**k(" )' if __name__ == '__main__': app = QApplication(sys.argv) edit = QTextEdit() hl = highlighter.Highlighter(edit) edit.setPlainText(code) edit.show() app.exec_()
def __init__(self, mitScheme, *args): termwidget.TermWidget.__init__(self, *args) self._mitScheme = mitScheme self._hl = highlighter.Highlighter(self._edit)
def _cargar_resaltador_de_sintaxis(self): self._highlighter = highlighter.Highlighter(self.document(), 'python', highlighter.COLOR_SCHEME)
def __init__(self): QtGui.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) # Configure the user interface. self.setupUi(self) # Snippets special Variables # snippet self.insideSnippet = False self.start_snip = 0 # Field courant self.snippets = [] self.field = None self.field_start = 0 self.field_long = 0 self.oldsnip = None # Editor # Editor tabs = 4 chars self.tab_long = 4 self.setTabEditorWidth(self.tab_long) # Coloration syntaxique self.highlighter = highlighter.Highlighter(self.editor) self.highlighter.modeRest() # Browser (viewer) # Set permissions to open external links # by clicking on them self.viewer.openExternalLinks = True self.viewer.setOpenExternalLinks(True) # Big Hack not to have to create a particluar # classe for the browser. # TODO : clean derivation self.viewer.loadResource = imageBrowser().loadResource ## Special attributes : # name of the current edited file self.fileName = "Noname.rst" # absolute path self.filePath = INREP # boolean to know if file has been saved or not self.isSaved = False # default directory self.default_dir = INREP # or APPLIREP (up to you) ## Conversion Dialog self.ConvDialog = QtGui.QDialog(self) ui = Ui_Converter() ui.setupUi(self.ConvDialog) self.converterdial = ui ## SIGNALS/SLOTS # we need to know if source as changed self.connect(self.editor, QtCore.SIGNAL("textChanged()"), self.needSave) ## ScrollBars editor-viewer # scrollbar editor self.esb = self.editor.verticalScrollBar() # scrollbar viewer self.vsb = self.viewer.verticalScrollBar() # connexions scrollbar editor --> synchronise view in browser self.connect(self.esb, QtCore.SIGNAL("valueChanged(int) "), self.actualiseBSlider) # connexions scrollbar viewer --> synchronise view in editor self.connect(self.vsb, QtCore.SIGNAL("valueChanged(int) "), self.actualiseESlider) ## zoom event for editor and viewer import types self.editor.wheelEvent = types.MethodType(zoomEditor, self.editor, self.editor.__class__) self.viewer.wheelEvent = types.MethodType(zoomViewer, self.viewer, self.viewer.__class__) ## MENU ACTIONS self.createActions() ## BUTTONS self.actionSave.setEnabled(self.isSaved) ## APPLY SAVED APP SETTINGS self.readSettings() ## KEYBOARD SHORTCUTS keyTab = QtGui.QShortcut(QtGui.QKeySequence(self.tr("Tab")), self) self.connect(keyTab, QtCore.SIGNAL("activated()"), self.whatToDoOnTab) QtGui.QShortcut(QtGui.QKeySequence("F1"), self, self.showHelp) QtGui.QShortcut(QtGui.QKeySequence("F2"), self, self.indentRegion) QtGui.QShortcut(QtGui.QKeySequence("F3"), self, self.unindentRegion) QtGui.QShortcut(QtGui.QKeySequence("F4"), self, self.chooseFont) QtGui.QShortcut(QtGui.QKeySequence("F5"), self, self.tableCreate) QtGui.QShortcut(QtGui.QKeySequence("F6"), self, self.columnMode) self.connect(self.editor, QtCore.SIGNAL("textChanged()"), self.updateChilds) ## STATUSBAR self.statusBar().showMessage("Welcome to reStInPeace, press F1 for Help.")