def newFile(self,file): # self.tabWidget.setTabBar(HorizontalTabBar()) #获取QtabBar id信号槽 self.NewTab = QtGui.QWidget() #显示右键菜单 self.NewTab.setContextMenuPolicy(3) self.NewTab.customContextMenuRequested.connect(self.TabRightMenu) self.loxLayout = QtGui.QVBoxLayout(self.NewTab) self.loxLayout.setContentsMargins(0, 0, 0, 0) self.textEdit = QsciScintilla(self.NewTab) self.textEdit.setToolTip(_fromUtf8("")) self.textEdit.setWhatsThis(_fromUtf8("")) if file: self.loxLayout.addWidget(self.textEdit) self.tabWidget.addTab(self.NewTab, _fromUtf8("")) self.textEdit.setText(open(file,'r').read()) #获取文件名称 file_name = os.path.basename(file) self.tabWidget.setTabText(self.tabWidget.indexOf(self.NewTab), _translate("MainWindow", file_name, None)) self.setWindowTitle(file+" - Raymond Text") else: self.loxLayout.addWidget(self.textEdit) self.tabWidget.addTab(self.NewTab, _fromUtf8("")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.NewTab), _translate("MainWindow", "新建文件", None)) self.setWindowTitle(u"Raymond Text") # self.tabWidget.setStatusTip(u'行 113, 列 55') self.tabWidget.setCurrentIndex(self.tabWidget.currentIndex()+1) self.setTextEdit()
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) font = QFont() font.setFamily("courier") font.setFixedPitch(True) font.setPointSize(14) self.setFont(font) self.setMarginsFont(font) fontMetrics = QFontMetrics(font) self.setMarginWidth(0, fontMetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#CCCCCC")) self.setMarginSensitivity(1, True) self.marginClicked.connect(self.onMarginClicked) self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#EE1111"), self.ARROW_MARKER_NUM) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setFolding(QsciScintilla.BoxedTreeFoldStyle) lexer = PythonLexer() print lexer.styleNames() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, "Courier") self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.setMinimumSize(600, 450)
def openFile(self): file_path = QtGui.QFileDialog.getOpenFileName(self,u'打开文件',"" ,u"All Files(*.*);;纯文本 (*.txt)") self.setWindowTitle(file_path+" - Raymond Text") self.NewTab = QtGui.QWidget() #显示右键菜单 self.NewTab.customContextMenuRequested.connect(self.TabRightMenu) self.loxLayout = QtGui.QVBoxLayout(self.NewTab) self.loxLayout.setContentsMargins(0, 0, 0, 0) self.textEdit = QsciScintilla(self.NewTab) self.textEdit.setToolTip(_fromUtf8("")) self.textEdit.setWhatsThis(_fromUtf8("")) if file_path: self.loxLayout.addWidget(self.textEdit) self.tabWidget.addTab(self.NewTab, _fromUtf8("")) self.textEdit.setText(open(file_path,'r').read()) #获取文件名称 file_name=os.path.basename(str(file_path)) con=connect(self.dataBaseName) cur=con.cursor() res=(file_name,str(file_path),0,0) cur.execute('insert into grouping_data (name,address,groupid,iconPath) values (?,?,?,?)',res) con.commit() con.close() self.tabWidget.setTabText(self.tabWidget.indexOf(self.NewTab), _translate("MainWindow", file_name, None)) self.tabWidget.setCurrentIndex(self.tabWidget.currentIndex()+1) self.setTextEdit()
def dragMoveEvent(self, event): """ Drag move event """ if event.mimeData().hasFormat( "application/x-%s-help-item" % Settings.instance().readValue(key='Common/acronym').lower()): event.setDropAction(Qt.CopyAction) event.accept() elif event.mimeData().hasFormat( "application/x-%s-parameter-item" % Settings.instance().readValue(key='Common/acronym').lower()): event.setDropAction(Qt.CopyAction) event.accept() elif event.mimeData().hasFormat( "application/x-%s-agent-item" % Settings.instance().readValue(key='Common/acronym').lower()): event.setDropAction(Qt.CopyAction) event.accept() elif event.mimeData().hasFormat( "application/x-%s-description-item" % Settings.instance().readValue(key='Common/acronym').lower()): event.setDropAction(Qt.CopyAction) event.accept() else: QsciScintilla.dragMoveEvent(self, event)
def keyPressEvent(self, ev): """ Re-implemented to handle the user input a key at a time. @param ev key event (QKeyEvent) """ txt = ev.text() key = ev.key() ctrl = ev.modifiers() & Qt.ControlModifier shift = ev.modifiers() & Qt.ShiftModifier # See it is text to insert. if (self.keymap.has_key(key) and not shift and not ctrl): self.keymap[key]() elif self.__isCursorOnLastLine() and txt.length(): QsciScintilla.keyPressEvent(self, ev) self.incrementalSearchActive = True if (txt == '.'): self.__showDynCompletion() elif (ctrl or shift): QsciScintilla.keyPressEvent(self, ev) else: ev.ignore()
def __init__(self, filename='', parent=None): ''' Constructor ''' QWidget.__init__(self, parent) self.filename = filename self.label = 'untitled' self.modified = False self.layout = QVBoxLayout(self) self.editor = QsciScintilla() self.layout.addWidget(self.editor, stretch=1) # Give the editor its content if len(filename) > 0: # Open the file and read in its contents f = open(filename, 'r') contents = f.read() self.editor.setText(contents) f.close() self.label = os.path.basename(filename) # Setup the features of the editor lexer = QsciLexerJavaScript() self.editor.setLexer(lexer) # Connect signals self.editor.textChanged.connect(self.onTextChanged)
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) # Set the default font font = QFont() font.setFamily(fontName) font.setFixedPitch(True) font.setPointSize(fontSize) fontmetrics = QFontMetrics(font) # Margin 0 is used for line numbers self.setMarginsFont(font) self.setMarginWidth(1, fontmetrics.width("00000")) self.setMarginLineNumbers(1, True) #self.setMarginsBackgroundColor(QColor("#cccccc")) # 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(caretBackground) # Set Python lexer self.setLexer(QsciLexerPython()) # override style settings to the same font and size # (python lexer has styles 0 ... 15) for i in range(16): self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, i, fontName) self.SendScintilla(QsciScintilla.SCI_STYLESETSIZE, i, fontSize) # make the source read-only self.SendScintilla(QsciScintilla.SCI_SETREADONLY, True)
def __init__(self): QsciScintilla.__init__(self) # Configuración de Qscintilla self.setCaretLineVisible(ESettings.get('editor/margen')) self.setIndentationsUseTabs(False) self.setAutoIndent(True) self.setBackspaceUnindents(True) # Scrollbar self.send("sci_sethscrollbar", 0) # Indicadores self.indicador = 0 self.indicador_warning = 1 self.indicador_error = 2 # Estilo de indicadores self.send("sci_indicsetstyle", self.indicador, "indic_container") self.send("sci_indicsetalpha", self.indicador, 100) self.send("sci_indicsetfore", self.indicador, 0x0000ff) self.send("sci_indicsetstyle", self.indicador_warning, "indic_dots") self.send("sci_indicsetfore", self.indicador_warning, QColor('yellow')) self.send("sci_indicsetstyle", self.indicador_error, "indic_dots") self.send("sci_indicsetfore", self.indicador_error, 0x0000ff) # Folding self.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.colorFoldMargen(recursos.TEMA['foldFore'], recursos.TEMA['foldBack']) self._fuente = None self.linesChanged.connect(self.actualizar_sidebar)
def showEvent(self, event): QsciScintilla.showEvent(self, event) # prevent issues with initially invisible cursor / caret line self.setFocus() #self.jumpToLine(0) # prevent issues with incorrect initial scroll position self.standardCommands().find(QsciCommand.VerticalCentreCaret).execute()
def setDefaultShortcuts(self): reply = QtGui.QMessageBox.warning( self, "Default Keymap", "Setting keymap to default will wipe away your current keymap.\n\nProceed?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, ) if reply == QtGui.QMessageBox.Yes: for key, value in self.useData.DEFAULT_SHORTCUTS["Ide"].items(): default = self.useData.DEFAULT_SHORTCUTS["Ide"][key] self.useData.CUSTOM_SHORTCUTS["Ide"][key] = default sc = QsciScintilla() standardCommands = sc.standardCommands() for key, value in self.useData.DEFAULT_SHORTCUTS["Editor"].items(): default = self.useData.DEFAULT_SHORTCUTS["Editor"][key] command = standardCommands.find(default[1]) keyValue = command.key() self.useData.CUSTOM_SHORTCUTS["Editor"][key] = [default[0], keyValue] self.save() self.useData.loadKeymap() self.updateShortcutsView() else: return
def keyPressEvent(self, ev): """ Re-implemented to handle the user input a key at a time. @param ev key event (QKeyEvent) """ txt = ev.text() key = ev.key() ctrl = ev.modifiers() & Qt.ControlModifier if(ctrl): QsciScintilla.keyPressEvent(self, ev) elif(self.keymap.has_key(key)): self.keymap[key]() # See it is text to insert. elif self.__isCursorOnLastLine() and txt.length() : QsciScintilla.keyPressEvent(self, ev) self.incrementalSearchActive = True if(txt == '.'): self.__showDynCompletion() else: ev.ignore()
def __init__(self, editorId, parent=None, activePyLexer=True, activePropertiesLexer=False, wrappingText=False): """ Python editor based on QsciScintilla @param editorId: @type editorId: @param parent: @type parent: """ QsciScintilla.__init__(self, parent) self.editorId = editorId self.activePyLexer = activePyLexer self.activePropertiesLexer = activePropertiesLexer self.setAcceptDrops(True) self.wrappingText = wrappingText self.opening = ['(', '{', '[', "'", '"'] self.closing = [')', '}', ']', "'", '"'] self.createActions() self.createWidgets() self.createConnections() self.setupContextMenu()
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) font = QFont() font.setFamily('courier') font.setFixedPitch(True) font.setPointSize(14) self.setFont(font) self.setMarginsFont(font) fontMetrics = QFontMetrics(font) self.setMarginWidth(0, fontMetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor('#CCCCCC')) self.setMarginSensitivity(1, True) self.marginClicked.connect(self.onMarginClicked) self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#EE1111"), self.ARROW_MARKER_NUM) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setFolding(QsciScintilla.BoxedTreeFoldStyle) lexer = PythonLexer() print lexer.styleNames() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.setMinimumSize(600, 450)
def focusOutEvent(self, e): """Send a focusLost signal if we lose focus""" self.emit(QtCore.SIGNAL("focusLost")) self.focusLost.emit() QsciScintilla.focusOutEvent(self, e)
def zoomOut( self, zoom = 1 ): """ Decreases the zoom factor """ self.zoom -= zoom QsciScintilla.zoomOut( self, zoom ) self._charWidth = -1 self._lineHeight = -1 return
def keyPressEvent(self, e): startLine, _, endLine, _ = self.getSelection() # handle invalid cursor position and multiline selections if not self.is_cursor_on_edition_zone() or startLine < endLine: # allow to copy and select if e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier): if e.key() in (Qt.Key_C, Qt.Key_A): QsciScintilla.keyPressEvent(self, e) return # allow selection if e.modifiers() & Qt.ShiftModifier: if e.key() in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Home, Qt.Key_End): QsciScintilla.keyPressEvent(self, e) return # all other keystrokes get sent to the input line self.move_cursor_to_end() line, index = self.getCursorPosition() cmd = self.text(line) if e.key() in (Qt.Key_Return, Qt.Key_Enter) and not self.isListActive(): self.entered() elif e.key() in (Qt.Key_Left, Qt.Key_Home): QsciScintilla.keyPressEvent(self, e) # check whether the cursor is moved out of the edition zone newline, newindex = self.getCursorPosition() if newline < line or newindex < 4: # fix selection and the cursor position if self.hasSelectedText(): self.setSelection(line, self.getSelection()[3], line, 4) else: self.setCursorPosition(line, 4) elif e.key() in (Qt.Key_Backspace, Qt.Key_Delete): QsciScintilla.keyPressEvent(self, e) # check whether the cursor is moved out of the edition zone _, newindex = self.getCursorPosition() if newindex < 4: # restore the prompt chars (if removed) and # fix the cursor position self.insert(cmd[:3 - newindex] + " ") self.setCursorPosition(line, 4) self.recolor() elif e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier) and \ e.key() == Qt.Key_V: self.paste() e.accept() elif e.key() == Qt.Key_Down and not self.isListActive(): self.showPrevious() elif e.key() == Qt.Key_Up and not self.isListActive(): self.showNext() ## TODO: press event for auto-completion file directory else: QsciScintilla.keyPressEvent(self, e)
def zoomOut(self, zoom=1): """ Decreases the zoom factor """ self.zoom -= zoom QsciScintilla.zoomOut(self, zoom) self._charWidth = -1 self._lineHeight = -1 return
def __init__(self, isnewfile, filename, text, parent=None): QsciScintilla.__init__(self, parent) print('Creating TextEdit', isnewfile, filename) self.setObjectName('TextEdit') self.currentfile = filename self.setUtf8(True) self.isnewfile = isnewfile self.nedits = 0 self.bookmarks = {} self.zen = common.Common() self.bookmark = self.markerDefine(QtGui.QPixmap(':/png/bookmark.png')) self.prefs = preferences.Preferences() self.setIndentationsUseTabs(False) self.copyAvailable.connect(self.enable_copy) self.textChanged.connect(self.text_changed) self.setText(text) self.setModified(False) self.lexer_ = None self.set_lexer() self.set_style_and_config() self.marginClicked.connect(self.on_margin_clicked) self.modificationChanged.connect(self.document_was_modified) self.linesChanged.connect(self.lines_changed)
def paintEvent(self, e): """Optionally refresh the layout before a paint event""" if self.refresh_layout: self.set_layout() self.refresh_layout = False QsciScintilla.paintEvent(self, e)
def keyPressEvent(self, event): """ desc: Intercepts certain keypress events to implement custom copy-pasting and zooming. arguments: event: type: QKeyPressEvent """ key = event.key() ctrl = event.modifiers() & QtCore.Qt.ControlModifier shift = event.modifiers() & QtCore.Qt.ShiftModifier # Zoom in/out if ((key == QtCore.Qt.Key_Plus) and ctrl) \ or ((key == QtCore.Qt.Key_Equal) and shift and ctrl): self.zoomIn() event.accept() elif (key == QtCore.Qt.Key_Minus) and ctrl: self.zoomOut() event.accept() elif (key == QtCore.Qt.Key_V) and ctrl: self.paste() event.accept() else: QsciScintilla.keyPressEvent(self, event)
def __init__(self,parent,text,lang,colorStyle): QsciScintilla.__init__(self,parent) self.parent = parent self.lang = lang self.fontSize = fontSize self.colorStyle = colorStyle #self.init() self.setText(text) #self.addAction(QAction("gg",self)) # 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.registerImage(0,os_pixmap("class_obj")) self.registerImage(1,os_pixmap("method_obj")) self.registerImage(2,os_pixmap("field_public_obj")) # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setAutoCompletionThreshold(threshold) self.setAutoCompletionSource(QsciScintilla.AcsAPIs) #self.setFolding(QsciScintilla.BoxedTreeFoldStyle) #self.setAutoCompletionSource(QsciScintilla.AcsAll) #self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') self.init()
def keyPressEvent(self, ev): """ Re-implemented to handle the user input a key at a time. @param ev key event (QKeyEvent) """ txt = ev.text() key = ev.key() ctrl = ev.modifiers() & Qt.ControlModifier shift = ev.modifiers() & Qt.ShiftModifier # See it is text to insert. if(self.keymap.has_key(key) and not shift and not ctrl): self.keymap[key]() elif ev == QtGui.QKeySequence.Paste: self.paste() elif self.__isCursorOnLastLine() and len(txt) : QsciScintilla.keyPressEvent(self, ev) self.incrementalSearchActive = True if(txt == '.'): self.__showDynCompletion() elif(ctrl or shift): QsciScintilla.keyPressEvent(self, ev) else: ev.ignore()
def keyPressEvent(self, e): startLine, _, endLine, _ = self.getSelection() # handle invalid cursor position and multiline selections if not self.is_cursor_on_edition_zone() or startLine < endLine: # allow to copy and select if e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier): if e.key() in (Qt.Key_C, Qt.Key_A): QsciScintilla.keyPressEvent(self, e) return # allow selection if e.modifiers() & Qt.ShiftModifier: if e.key() in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Home, Qt.Key_End): QsciScintilla.keyPressEvent(self, e) return # all other keystrokes get sent to the input line self.move_cursor_to_end() line, index = self.getCursorPosition() cmd = self.text(line) if e.key() in (Qt.Key_Return, Qt.Key_Enter) and not self.isListActive(): self.entered() elif e.key() in (Qt.Key_Left, Qt.Key_Home): QsciScintilla.keyPressEvent(self, e) # check whether the cursor is moved out of the edition zone newline, newindex = self.getCursorPosition() if newline < line or newindex < 4: # fix selection and the cursor position if self.hasSelectedText(): self.setSelection(line, self.getSelection()[3], line, 4) else: self.setCursorPosition(line, 4) elif e.key() in (Qt.Key_Backspace, Qt.Key_Delete): QsciScintilla.keyPressEvent(self, e) # check whether the cursor is moved out of the edition zone _, newindex = self.getCursorPosition() if newindex < 4: # restore the prompt chars (if removed) and # fix the cursor position self.insert( cmd[:3-newindex] + " " ) self.setCursorPosition(line, 4) self.recolor() elif e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier) and \ e.key() == Qt.Key_V: self.paste() e.accept() elif e.key() == Qt.Key_Down and not self.isListActive(): self.showPrevious() elif e.key() == Qt.Key_Up and not self.isListActive(): self.showNext() ## TODO: press event for auto-completion file directory else: QsciScintilla.keyPressEvent(self, e)
def zoomTo(self, zoom): """ Public method used to zoom to a specific zoom factor. @param zoom zoom factor """ self.zoom = zoom QsciScintilla.zoomTo(self, zoom)
def zoomOut(self, zoom = 1): """ Public method used to decrease the zoom factor. @param zoom zoom factor decrement """ self.zoom -= zoom QsciScintilla.zoomOut(self, zoom)
def zoomIn(self, zoom = 1): """ Public method used to increase the zoom factor. @param zoom zoom factor increment """ self.zoom += zoom QsciScintilla.zoomIn(self, zoom)
def __init__(self, parent): QsciScintilla.__init__(self,parent) # self.nrOfLines = 0 # self.line_nr = 0 # self.pos = 0 self.parser = Parser() self.set_up()
def focusInEvent(self, e): """Refresh the layout on a focus in event""" # Only update the layout if the config is outdated if self.cfg_ver != config.get_config("cfg_ver"): self.set_layout() self.cfg_ver = config.get_config("cfg_ver") QsciScintilla.focusInEvent(self, e)
def zoomTo(self, zoom): """ Zooms to the specific zoom factor """ self.zoom = zoom QsciScintilla.zoomTo(self, zoom) self.setLineNumMarginWidth() self._charWidth = -1 self._lineHeight = -1 return
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) self.mylexer = None self.api = None self.setCommonOptions() self.initShortcuts()
def zoomTo( self, zoom ): """ Zooms to the specific zoom factor """ self.zoom = zoom QsciScintilla.zoomTo( self, zoom ) self.setLineNumMarginWidth() self._charWidth = -1 self._lineHeight = -1 return
def setLexer( self, lex = None ): """ Sets the new lexer or resets if None """ QsciScintilla.setLexer( self, lex ) if lex is None: self.clearStyles() self._charWidth = -1 self._lineHeight = -1 return
def setLexer(self, lex=None): """ Sets the new lexer or resets if None """ QsciScintilla.setLexer(self, lex) if lex is None: self.clearStyles() self._charWidth = -1 self._lineHeight = -1 return
def setLexer(self, lex = None): """ Public method to set the lexer. @param lex the lexer to be set or None to reset it. """ QsciScintilla.setLexer(self, lex) if lex is None: self.clearStyles()
def focusOutEvent(self, event): """ Reimplemented to handle focus @param event: @type event: """ if self.isVisible(): self.FocusChanged.emit() QsciScintilla.focusOutEvent(self, event)
def mouseMoveEvent(self, event): # This reimplementation adds support for tool tips QsciScintilla.mouseMoveEvent(self, event) QToolTip.hideText() self._global_mouse_position = event.globalPos() self._mouse_position = event.pos() self._tool_tip_timer.stop() self._tool_tip_timer.start(self.tool_tip_delay * 1000)
def __init__(self, parent, jsonLexer=False): """ Text raw editor """ QsciScintilla.__init__(self, parent) self.jsonLexer = jsonLexer self.createConnections() self.createWidget()
def focusOutEvent(self, event): """ Public method called when the editor loses focus. @param event event object (QFocusEvent) """ if self.isListActive(): self.cancelList() QsciScintilla.focusOutEvent(self, event)
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) ## set the default font of the editor ## and take the same font for line numbers font = CurrentTheme.PYTHON_SOURCE_EDITOR_FONT self.setFont(font) fm = QtGui.QFontMetrics(font) ## Line numbers # conventionally, margin 0 is for line numbers self.setMarginWidth(0, fm.width("0000") + 4) self.setMarginLineNumbers(0, True) self.setAutoIndent(True) ## Edge Mode shows a red vetical bar at 80 chars self.setEdgeMode(QsciScintilla.EdgeLine) self.setEdgeColumn(80) self.setEdgeColor(QtGui.QColor("#CCCCCC")) ## Folding visual : we will use boxes self.setFolding(QsciScintilla.BoxedTreeFoldStyle) ## Braces matching self.setBraceMatching(QsciScintilla.SloppyBraceMatch) ## Editing line color # self.setCaretLineVisible(True) # self.setCaretLineBackgroundColor(QtGui.QColor("#CDA869")) ## Margins colors # line numbers margin self.setMarginsBackgroundColor(QtGui.QColor("#FFFFFF")) self.setMarginsForegroundColor(QtGui.QColor("#000000")) # folding margin colors (foreground,background) self.setFoldMarginColors(QtGui.QColor("#DDDDDD"), QtGui.QColor("#DDDDDD")) # do not use tabs self.setIndentationsUseTabs(False) self.setTabWidth(4) self.setTabIndents(True) ## Choose a lexer lexer = QsciLexerPython() lexer.setDefaultFont(font) lexer.setFont(font) self.setLexer(lexer) # set autocompletion self.setAutoCompletionThreshold(2) self.setAutoCompletionSource(QsciScintilla.AcsDocument) self.setAutoCompletionCaseSensitivity(True) self.setAutoCompletionReplaceWord(True) self.setAutoCompletionFillupsEnabled(True)
def keyPressEvent(self, event): """Reimplement Qt method""" key = event.key() ctrl = event.modifiers() & Qt.ControlModifier shift = event.modifiers() & Qt.ShiftModifier # Zoom in/out if key in (Qt.Key_Enter, Qt.Key_Return) and not shift and not ctrl: QsciScintilla.keyPressEvent(self, event) self.fix_indent() elif ((key == Qt.Key_Plus) and ctrl) \ or ((key == Qt.Key_Equal) and shift and ctrl): self.zoomIn() event.accept() elif (key == Qt.Key_Minus) and ctrl: self.zoomOut() event.accept() # Indent/unindent elif key == Qt.Key_Backtab: self.unindent() event.accept() elif (key == Qt.Key_Tab): if self.is_completion_widget_visible(): self.SendScintilla(QsciScintilla.SCI_TAB) else: self.indent() event.accept() elif (key == Qt.Key_V) and ctrl: self.paste() event.accept() elif os.name == 'posix' and key == Qt.Key_Z and shift and ctrl: self.redo() event.accept() #TODO: find other shortcuts... # elif (key == Qt.Key_3) and ctrl: # self.comment() # event.accept() # elif (key == Qt.Key_2) and ctrl: # self.uncomment() # event.accept() # elif (key == Qt.Key_4) and ctrl: # self.blockcomment() # event.accept() # elif (key == Qt.Key_5) and ctrl: # self.unblockcomment() # event.accept() else: QsciScintilla.keyPressEvent(self, event) if CONF.get('main', 'workaround/gnome_qscintilla'): # Workaround for QScintilla's completion with Gnome from PyQt4.QtGui import QListWidget if self.is_completion_widget_visible(): for w in self.children(): if isinstance(w, QListWidget): w.setWindowFlags(Qt.Dialog| Qt.FramelessWindowHint) w.show()
def keyPressEvent(self, ev): k = ev.key() mdf = ev.modifiers() Return = QtCore.Qt.Key_Return Control = QtCore.Qt.ControlModifier Shift = QtCore.Qt.ShiftModifier Slash = QtCore.Qt.Key_Slash Question = QtCore.Qt.Key_Question Minus = QtCore.Qt.Key_Minus V = QtCore.Qt.Key_V Z = QtCore.Qt.Key_Z passthru = True if k == Return: lineno, _linedex = self.getCursorPosition() line = self.text(lineno).strip() indent = self.indentation(lineno) char = line[-1:] colon = ':' if char == colon: # auto indent indent += 4 QsciScintilla.keyPressEvent(self, ev) self.insert(' ' * indent) self.setCursorPosition(lineno + 1, indent) passthru = False elif mdf & Control and k == Slash: self.commentlines() passthru = False elif mdf & Control and k == Question: self.commentlines(un=True) passthru = False elif mdf & Control and k == Minus: self.editor.zoomout() passthru = False elif mdf & Control and k == V: self.paste() passthru = False elif mdf & Control and mdf & Shift and k == Z: self.redo() passthru = False if passthru: QsciScintilla.keyPressEvent(self, ev) self.editor.settitle() self.update_window_modified()
def mousePressEvent(self, event): """ Protected method to handle the mouse press event. @param event the mouse press event (QMouseEvent) """ self.setFocus() if event.button() == Qt.MidButton: self.__middleMouseButton() else: QsciScintilla.mousePressEvent(self, event)
def __init__(self): QMainWindow.__init__(self) self.setWindowTitle('Custom Lexer For Config Files') self.setGeometry(50, 200, 400, 400) self.editor = QsciScintilla(self) self.editor.setUtf8(True) self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.setCentralWidget(self.editor) self.lexer = ConfigLexer(self.editor) self.editor.setLexer(self.lexer) self.editor.setText(_sample)
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) ## set the default font of the editor ## and take the same font for line numbers font = CurrentTheme.PYTHON_SOURCE_EDITOR_FONT self.setFont(font) fm = QtGui.QFontMetrics(font) ## Line numbers # conventionally, margin 0 is for line numbers self.setMarginWidth(0, fm.width( "0000" ) + 4) self.setMarginLineNumbers(0, True) self.setAutoIndent(True) ## Edge Mode shows a red vetical bar at 80 chars self.setEdgeMode(QsciScintilla.EdgeLine) self.setEdgeColumn(80) self.setEdgeColor(QtGui.QColor("#CCCCCC")) ## Folding visual : we will use boxes self.setFolding(QsciScintilla.BoxedTreeFoldStyle) ## Braces matching self.setBraceMatching(QsciScintilla.SloppyBraceMatch) ## Editing line color # self.setCaretLineVisible(True) # self.setCaretLineBackgroundColor(QtGui.QColor("#CDA869")) ## Margins colors # line numbers margin self.setMarginsBackgroundColor(QtGui.QColor("#FFFFFF")) self.setMarginsForegroundColor(QtGui.QColor("#000000")) # folding margin colors (foreground,background) self.setFoldMarginColors(QtGui.QColor("#DDDDDD"),QtGui.QColor("#DDDDDD")) # do not use tabs self.setIndentationsUseTabs(False) self.setTabWidth(4) self.setTabIndents(True) ## Choose a lexer lexer = QsciLexerPython() lexer.setDefaultFont(font) lexer.setFont(font) self.setLexer(lexer) # set autocompletion self.setAutoCompletionThreshold(2) self.setAutoCompletionSource(QsciScintilla.AcsDocument) self.setAutoCompletionCaseSensitivity(True) self.setAutoCompletionReplaceWord(True) self.setAutoCompletionFillupsEnabled(True)
def keyPressEvent(self, event): # This reimplementation add support for auto indentation # for blocks need_indent = (event.key() == Qt.Key_Return and self._need_auto_indent_open()) QsciScintilla.keyPressEvent(self, event) if need_indent: self._insert_indent()
def keyPressEvent(self, e): if e.key() in (Qt.Key_Return, Qt.Key_Enter): self.entered() elif e.key() == Qt.Key_Escape: self.close() elif e.key() in (Qt.Key_Backspace, Qt.Key_Delete): _, newindex = self.getCursorPosition() if newindex > len(self.prompt): QsciScintilla.keyPressEvent(self, e) else: QsciScintilla.keyPressEvent(self, e)
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) self.setup() # Code completion / calltips self.codecompletion = True self.codecompletion_enter = False self.calltips = True self.completion_text = "" self.calltip_position = None self.connect(self, SIGNAL('userListActivated(int, const QString)'), lambda user_id, text: self.completion_list_selected(text))
class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.setWindowTitle('Custom Lexer For Config Files') self.setGeometry(50, 200, 400, 400) self.editor = QsciScintilla(self) self.editor.setUtf8(True) self.editor.setMarginWidth(2, 15) self.editor.setFolding(True) self.setCentralWidget(self.editor) self.lexer = ConfigLexer(self.editor) self.editor.setLexer(self.lexer) self.editor.setText(_sample)
def mousePressEvent(self, e): """ Re-implemented to handle the mouse press event. e: the mouse press event (QMouseEvent) """ self.setFocus() if e.button() == Qt.MidButton: stringSel = unicode(QApplication.clipboard().text(QClipboard.Selection)) if not self.is_cursor_on_last_line(): self.move_cursor_to_end() self.insertFromDropPaste(stringSel) e.accept() else: QsciScintilla.mousePressEvent(self, e)
def __init__(self, mainwindow): QsciScintilla.__init__(self, mainwindow) self.mainwindow = mainwindow ## 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 editor ## and take the same font for line numbers self.setFont(font) self.setMarginsFont(font) ## Line numbers # conventionnaly, margin 0 is for line numbers self.setMarginWidth(0, fm.width( "00000" ) + 5) self.setMarginLineNumbers(0, True) ## Edge Mode shows a red vetical bar at 80 chars self.setEdgeMode(QsciScintilla.EdgeLine) self.setEdgeColumn(80) self.setEdgeColor(QColor("#CCCCCC")) ## Folding visual : we will use boxes self.setFolding(QsciScintilla.BoxedTreeFoldStyle) ## Braces matching self.setBraceMatching(QsciScintilla.SloppyBraceMatch) ## Editing line color #self.setCaretLineVisible(True) #self.setCaretLineBackgroundColor(QColor("#CDA869")) ## Margins colors # line numbers margin self.setMarginsBackgroundColor(QColor("#333333")) self.setMarginsForegroundColor(QColor("#CCCCCC")) # folding margin colors (foreground,background) #self.setFoldMarginColors(QColor("#99CC66"),QColor("#333300")) self.setFoldMarginColors(QColor("#CCCCCC"),QColor("#CCCCCC")) ## Choose a lexer lexer = QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer)
def _key_pressed(self, event): """ Handle KeyPressed event We only care about CTRL-S in order to save changes :param event: key event """ QsciScintilla.keyPressEvent(self._code_editor, event) if event.key() in [Qt.Key_S, Qt.Key_Save]: modifiers = QtGui.QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier and self.is_modified(): self.logger.debug("Saving...") self.on_save_changes() self.key_pressed(event)
def __init__(self, parent=None): QsciScintilla.__init__(self, parent) self.SendScintilla(self.SCI_SETLAYOUTCACHE, self.SC_CACHE_DOCUMENT) self.zoom = 0 self._charWidth = -1 self._lineHeight = -1 self.__targetSearchFlags = 0 self.__targetSearchExpr = "" self.__targetSearchStart = 0 self.__targetSearchEnd = -1 self.__targetSearchActive = False return
def scrollContentsBy(self, dx, dy): for w in iter(self.__overlayWidgets.values()): # simply assume that all lines are of equal height p = w.pos() + QPoint(dx, dy * self.textHeight(0)) w.move(p) return QsciScintilla.scrollContentsBy(self, dx, dy)
def __init__(self, lexer): QsciScintilla.__init__(self) BaseEdit.__init__(self) self.setMarginWidth(0, 30) self.setMarginLineNumbers(0, True) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#CCCCCC")) self.setBackspaceUnindents(True) self.setAutoCompletionSource(QsciScintilla.AcsAll) self.setAutoCompletionThreshold(1) self.setAutoCompletionCaseSensitivity(True) self.setTabIndents(True) self.setTabWidth(4) self.setLexer(lexer) self.edit_id = "source"