def keyPressEvent(self, event): """Intercept the key event to lets plugin do something if they want""" if event.type() == QEvent.KeyPress: for plugin in filter_plugins_by_capability('beforeKeyPressEvent',self.enabled_plugins): plugin.do_beforeKeyPressEvent(self,event) QPlainTextEdit.keyPressEvent(self, event) for plugin in filter_plugins_by_capability('afterKeyPressEvent',self.enabled_plugins): plugin.do_afterKeyPressEvent(self,event)
def keyPressEvent(self, event): """Intercept the key event to lets plugin do something if they want""" if event.type() == QEvent.KeyPress: for plugin in filter_plugins_by_capability('beforeKeyPressEvent', self.enabled_plugins): plugin.do_beforeKeyPressEvent(self, event) QPlainTextEdit.keyPressEvent(self, event) for plugin in filter_plugins_by_capability('afterKeyPressEvent', self.enabled_plugins): plugin.do_afterKeyPressEvent(self, event)
def save(self): """Hum ... just save ...""" if self.filename.startswith("Unnamed"): filename = self.parent().parent().parent().saveAsFile() if not (filename == ''): return self.filename = filename self.setWindowTitle( QFileInfo(self.filename).fileName()) exception = None filehandle = None try: #Before FileSave plugin hook for plugin in filter_plugins_by_capability('beforeFileSave',self.enabled_plugins): plugin.do_beforeFileSave(self) filehandle = QFile(self.filename) if not filehandle.open( QIODevice.WriteOnly): raise IOError, unicode(filehandle.errorString()) stream = QTextStream(filehandle) stream.setCodec("UTF-8") stream << self.toPlainText() self.document().setModified(False) RecentFiles().append(self.filename) except (IOError, OSError), ioError: exception = ioError
def save(self): """Hum ... just save ...""" if self.filename.startswith("Unnamed"): filename = self.parent().parent().parent().saveAsFile() if not (filename == ''): return self.filename = filename self.setWindowTitle(QFileInfo(self.filename).fileName()) exception = None filehandle = None try: #Before FileSave plugin hook for plugin in filter_plugins_by_capability('beforeFileSave', self.enabled_plugins): plugin.do_beforeFileSave(self) filehandle = QFile(self.filename) if not filehandle.open(QIODevice.WriteOnly): raise IOError, unicode(filehandle.errorString()) stream = QTextStream(filehandle) stream.setCodec("UTF-8") stream << self.toPlainText() self.document().setModified(False) RecentFiles().append(self.filename) except (IOError, OSError), ioError: exception = ioError
def curPositionChanged(self): #Plugin hook for plugin in filter_plugins_by_capability('beforeCursorPositionChanged',self.enabled_plugins): plugin.do_beforeCursorPositionChanged(self) #Hilight current line #Workarround QTBUG-18720 self.highlightCurrentLine() #Make sure cursor is visible #self.ensureCursorVisible() cursor = self.cursorRect() pos = cursor.center() #self.ensureVisible(pos.x(),pos.y(), 2*cursor.width()+20, 2*cursor.height()) if self.scroller: self.scroller.ensureVisible(pos.x(),pos.y(),2*cursor.width()+20, 2*cursor.height())
def curPositionChanged(self): #Plugin hook for plugin in filter_plugins_by_capability( 'beforeCursorPositionChanged', self.enabled_plugins): plugin.do_beforeCursorPositionChanged(self) #Hilight current line #Workarround QTBUG-18720 self.highlightCurrentLine() #Make sure cursor is visible #self.ensureCursorVisible() cursor = self.cursorRect() pos = cursor.center() #self.ensureVisible(pos.x(),pos.y(), 2*cursor.width()+20, 2*cursor.height()) if self.scroller: self.scroller.ensureVisible(pos.x(), pos.y(), 2 * cursor.width() + 20, 2 * cursor.height())
def load(self): """Load ?""" exception = None filehandle = None try: filehandle = QFile(self.filename) if not filehandle.open( QIODevice.ReadOnly): raise IOError, unicode(filehandle.errorString()) stream = QTextStream(filehandle) stream.setCodec("UTF-8") QApplication.processEvents() self.setPlainText(stream.readAll()) self.document().setModified(False) self.setWindowTitle( QFileInfo(self.filename).fileName()) self.loadHighlighter(self.filename) for plugin in filter_plugins_by_capability('afterFileOpen',self.enabled_plugins): plugin.do_afterFileOpen(self) except (IOError, OSError), error: exception = error
def load(self): """Load ?""" exception = None filehandle = None try: filehandle = QFile(self.filename) if not filehandle.open(QIODevice.ReadOnly): raise IOError, unicode(filehandle.errorString()) stream = QTextStream(filehandle) stream.setCodec("UTF-8") QApplication.processEvents() self.setPlainText(stream.readAll()) self.document().setModified(False) self.setWindowTitle(QFileInfo(self.filename).fileName()) self.loadHighlighter(self.filename) for plugin in filter_plugins_by_capability('afterFileOpen', self.enabled_plugins): plugin.do_afterFileOpen(self) except (IOError, OSError), error: exception = error
plugin.do_beforeFileSave(self) filehandle = QFile(self.filename) if not filehandle.open( QIODevice.WriteOnly): raise IOError, unicode(filehandle.errorString()) stream = QTextStream(filehandle) stream.setCodec("UTF-8") stream << self.toPlainText() self.document().setModified(False) RecentFiles().append(self.filename) except (IOError, OSError), ioError: exception = ioError finally: if filehandle is not None: filehandle.close() for plugin in filter_plugins_by_capability('afterFileSave',self.enabled_plugins): plugin.do_afterFileSave(self) if exception is not None: raise exception def __find_brace_match(self, position, brace, forward): if forward: bracemap = {'(': ')', '[': ']', '{': '}'} text = self.get_text(position, 'eof') i_start_open = 1 i_start_close = 1 else: bracemap = {')': '(', ']': '[', '}': '{'} text = self.get_text('sob', position) i_start_open = len(text)-1
plugin.do_beforeFileSave(self) filehandle = QFile(self.filename) if not filehandle.open(QIODevice.WriteOnly): raise IOError, unicode(filehandle.errorString()) stream = QTextStream(filehandle) stream.setCodec("UTF-8") stream << self.toPlainText() self.document().setModified(False) RecentFiles().append(self.filename) except (IOError, OSError), ioError: exception = ioError finally: if filehandle is not None: filehandle.close() for plugin in filter_plugins_by_capability( 'afterFileSave', self.enabled_plugins): plugin.do_afterFileSave(self) if exception is not None: raise exception def __find_brace_match(self, position, brace, forward): if forward: bracemap = {'(': ')', '[': ']', '{': '}'} text = self.get_text(position, 'eof') i_start_open = 1 i_start_close = 1 else: bracemap = {')': '(', ']': '[', '}': '{'} text = self.get_text('sob', position) i_start_open = len(text) - 1