Example #1
0
class SnippetEditor(QWidget):
	def __init__(self):
		QWidget.__init__(self)

		self.editor = QTextEdit()
		self.editor.setTabStopWidth(20)
		self.highlighter = PythonSyntaxHighlighter( self.editor )

		lay = QHBoxLayout()
		lay.setContentsMargins(0, 0, 0, 0)
		lay.addWidget(self.editor)
		self.setLayout(lay)

	def runCode(self, context):
		name = threading.current_thread().name
		sys.stdout.flush(name)
		try:
			scode = str(self.editor.toPlainText()).strip()
			code = compile(scode, '', 'exec')
			exec code in context
		except:
			traceback.print_exc()
		finally:
			data = sys.stdout.getOutput(name)
			self.emit(SIGNAL('codeOutput'), data)