Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Created May 1, 2013 00:17
Show Gist options
  • Save NathanW2/5492884 to your computer and use it in GitHub Desktop.
Save NathanW2/5492884 to your computer and use it in GitHub Desktop.
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.Qsci import QsciScintilla, QsciLexerPython
import os
import os.path
class Editor(QsciScintilla):
def __init__(self, parent=None):
super(Editor, self).__init__(parent)
self.mtime = 0
font = QFont()
font.setFamily('Courier')
font.setFixedPitch(True)
font.setPointSize(10)
self.setFont(font)
self.setMarginsFont(font)
lexer = QsciLexerPython()
lexer.setDefaultFont(font)
self.setLexer(lexer)
self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')
self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
self.setMinimumSize(600, 450)
def focusInEvent(self, e):
if (not os.path.exists(self.path)) or
(self.mtime == os.path.getmtime(self.path)):
return
self.printStuff(pathfile)
QsciScintilla.focusInEvent(self, e)
def printStuff(self, path):
self.path = path
self.mtime = os.path.getmtime(self.path)
self.setText(open(self.path).read())
print 'File reloaded'
if __name__ == "__main__":
app = QApplication(sys.argv)
editor = Editor()
editor.printStuff(r'C:\Temp\test.py').read())
editor.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment