Commits

Henning Schröder committed cd8a447

small fixes

  • Participants
  • Parent commits 7f8fd43

Comments (0)

Files changed (1)

     syntax_number="darkBlue"
 scheme = DefaultColorScheme
 
+example = """
+for i in range(3):
+    print i, 'Hello, world!'
+"""
 
 class PythonHighlighter(QSyntaxHighlighter):
 
         self.base_format.setFont(font)
         self.empty_format = QTextCharFormat(self.base_format)
         #self.empty_format.setFontPointSize(font.pointSize()/4.0)
-		
+        
         self.keywordFormat = QTextCharFormat(self.base_format)
         self.keywordFormat.setForeground(QColor(scheme.syntax_keyword))
         #self.keywordFormat.setFontWeight(QFont.Bold)
 
 class EditorWidget(QPlainTextEdit):
 
-	
-	def __init__(self, parent):
-		super(EditorWidget, self).__init__(parent)
-		self.highlighter = PythonHighlighter(self)
+    
+    def __init__(self, parent):
+        super(EditorWidget, self).__init__(parent)
+        self.highlighter = PythonHighlighter(self)
 
 
 class OutputWidget(QPlainTextEdit):
 
-	
-	def __init__(self, parent):
-		super(OutputWidget, self).__init__(parent)
-		self.setReadOnly(True)
-		sys.stdout = self
-		sys.stderr = self
-		self.buf = u""
-		self.startTimer(500)
+    
+    def __init__(self, parent):
+        super(OutputWidget, self).__init__(parent)
+        self.setReadOnly(True)
+        sys.stdout = self
+        sys.stderr = self
+        self.buf = u""
+        self.startTimer(500)
 
-		
-	def write(self, s):
-		sys.__stdout__.write(s)
-		self.buf += unicode(s)
+        
+    def write(self, s):
+        sys.__stdout__.write(s)
+        self.buf += unicode(s)
 
-		
-	def writeline(self, s):
-		self.write(u"%s\n" % s)
+        
+    def writeline(self, s):
+        self.write(u"%s\n" % s)
 
-		
-	def timerEvent(self, event):
-		self.flush()
+        
+    def timerEvent(self, event):
+        self.flush()
 
-		
-	def flush(self):
-		if self.buf:
-			if not self.window().isVisible():
-				self.window().show()
-			self.moveCursor(QTextCursor.End, QTextCursor.MoveAnchor)
-			self.textCursor().insertText(self.buf)			
-			self.moveCursor(QTextCursor.End, QTextCursor.MoveAnchor)
-			self.ensureCursorVisible()
-			self.buf = ""
+        
+    def flush(self):
+        if self.buf:
+            if not self.window().isVisible():
+                self.window().show()
+            self.moveCursor(QTextCursor.End, QTextCursor.MoveAnchor)
+            self.textCursor().insertText(self.buf)          
+            self.moveCursor(QTextCursor.End, QTextCursor.MoveAnchor)
+            self.ensureCursorVisible()
+            self.buf = ""
 
 
-	
+    
 class Console(QDialog):
 
 
-	def __init__(self, namespace=None):
-		QDialog.__init__(self)
-		if namespace is None:
-			namespace = {}
-		self.namespace = namespace
-		self.vblayout = QVBoxLayout(self)
-		self.splitter = QSplitter(Qt.Vertical, self)
-		self.layout().addWidget(self.splitter)
-		self.edit = EditorWidget(self.splitter)
-		self.edit.setPlainText("print 'Hello, world'")
-		self.output = OutputWidget(self.splitter)		
-		self.runButton = QPushButton(self, text="&Run")
-		self.runButton.clicked.connect(self.run)
-		self.layout().addWidget(self.runButton)
-		self.edit.setFocus()
+    def __init__(self, namespace=None):
+        QDialog.__init__(self)
+        if namespace is None:
+            namespace = {}
+        self.namespace = namespace
+        self.vblayout = QVBoxLayout(self)
+        self.splitter = QSplitter(Qt.Vertical, self)
+        self.layout().addWidget(self.splitter)
+        self.edit = EditorWidget(self.splitter)
+        self.edit.setPlainText(example)
+        self.output = OutputWidget(self.splitter)       
+        self.runButton = QPushButton(self, text="&Run")
+        self.runButton.clicked.connect(self.run)
+        self.layout().addWidget(self.runButton)
+        self.edit.setFocus()
+        self.resize(800, 600)
+        
+    def run(self):
+        code = unicode(self.edit.toPlainText())
+        try:
+            exec code in self.namespace
+        except Exception, e:
+            print "\n", "-"*40
+            print e
+            import traceback
+            traceback.print_exc()
+    
+        
 
-		
-	def run(self):
-		code = unicode(self.edit.toPlainText())
-		try:
-			exec code in self.namespace
-		except Exception, e:
-			print e
-			import traceback
-			traceback.print_exc()
-	
-		
+        
 
-		
-
-		
+        
 if __name__ == "__main__":
-	import sys
-	from PyQt4.QtGui import QApplication
-	app = QApplication(sys.argv)
-	win = Console()
-	win.show()
-	app.exec_()
-	
+    import sys
+    from PyQt4.QtGui import QApplication
+    app = QApplication(sys.argv)
+    win = Console()
+    win.show()
+    app.exec_()
+