def __addWidgets__(self): '''adds all of the custom widgets not specified in the .ui file''' #interpreter = Interpreter(self.localVars.__dict__)#original interpreter = Interpreter(self.varDict) #interpreter = Interpreter() shellClass = shell.get_shell_class() self.shell = shellClass(interpreter, parent=self.ui.pyDockWidget) self.shell.setObjectName("shell") self.ui.pyDockWidget.setWidget(self.shell)
def main(): # Test the widget independently. from code import InteractiveInterpreter as Interpreter a = QtGui.QApplication(sys.argv) # Restore default signal handler for CTRL+C import signal signal.signal(signal.SIGINT, signal.SIG_DFL) interpreter = Interpreter() aw = SciShell(interpreter) # static resize aw.resize(600, 400) aw.show() a.exec_()
def __init__(self, parent=None, locals=None, log='', fontSize=10, commandWidget=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Form() self.ui.setupUi(self) # Setup TextBrowser self.ui.tb_view.setWordWrapMode(QtGui.QTextOption.WrapAnywhere) self.ui.tb_view.keyPressEvent = self.tb_out_keypress # Setup Command if not commandWidget: try: import scintilla_cmd commandWidget = scintilla_cmd.cmd_widget() except: commandWidget = None if commandWidget: # Scintilla Commandline self.ui.le_cmd = commandWidget else: # Line Edit self.ui.le_cmd = QtGui.QLineEdit() self.ui.le_cmd.widgetObject = QtGui.QLineEdit self.ui.le_cmd.type = 'qlineedit' self.ui.frame.layout().addWidget(self.ui.le_cmd, 0, 2, 1, 1) self.ui.le_cmd.keyPressEvent = self.cmdKeyPress # font if os.name == 'posix': font = QtGui.QFont("Monospace", fontSize) elif os.name == 'nt' or os.name == 'dos': font = QtGui.QFont("Courier New", fontSize) else: print(SystemExit, "FIXME for 'os2', 'mac', 'ce' or 'riscos'") ## raise Exception(SystemExit, "FIXME for 'os2', 'mac', 'ce' or 'riscos'") font.setFixedPitch(1) ## self.setFont(font) self.ui.tb_view.setFont(font) self.ui.le_cmd.setFont(font) self.ui.l_prompt.setFont(font) # geometry height = 40 * QtGui.QFontMetrics(font).lineSpacing() self.ui.tb_view.setTabStopWidth( QtGui.QFontMetrics(font).width(' ') - 1) # Setup Interpreter if locals == None: locals = {'self': self, 'scope': parent} self.interpreter = Interpreter(locals) # Exit with Ctrl+D if parent is None: self.eofKey = Qt.Key_D else: self.eofKey = None ## self.viewers = [] class SplitStdErr: def __init__(self, default_stderr, console_stderr): ## self._targets=targets self.default_stderr = default_stderr self.console_stderr = console_stderr def write(self, line): self.default_stderr.write(line) self.console_stderr.write(line, mode=2) ## for target in self._targets: ## target.write(line) # capture all interactive input/output sys.stdout = self sys.stderr = SplitStdErr(sys.stderr, self) sys.stdin = self # last line + last incomplete lines self.lines = [] # the cursor position in the last line self.point = 0 # flag: the interpreter needs more input to run the last lines. self.more = 0 # flag: readline() is being used for e.g. raw_input() and input() self.reading = 0 # history self.history = [] self.pointer = 0 self.indent = '' self.prompt = '>>>' self.writecount = 0 # interpreter prompt. try: sys.ps1 except AttributeError: sys.ps1 = ">>> " try: sys.ps2 except AttributeError: sys.ps2 = "... " self.write('# Python ' + '(' + str(sys.version_info.major) + '.' + str(sys.version_info.minor) + '.' + str(sys.version_info.micro) + ')\n', mode=1) self.write('\n') # Focus to command prompt self.ui.le_cmd.setFocus()
def __init__(self, locals=None, log='', parent=None): """Constructor. The optional 'locals' argument specifies the dictionary in which code will be executed; it defaults to a newly created dictionary with key "__name__" set to "__console__" and key "__doc__" set to None. The optional 'log' argument specifies the file in which the interpreter session is to be logged. The optional 'parent' argument specifies the parent widget. If no parent widget has been specified, it is possible to exit the interpreter by Ctrl-D. """ QMultiLineEdit.__init__(self, parent) self.interpreter = Interpreter(locals) # session log self.log = log or '' # to exit the main interpreter by a Ctrl-D if PyCute has no parent if parent is None: self.eofKey = Qt.Key_D else: self.eofKey = None # capture all interactive input/output sys.stdout = self sys.stderr = self sys.stdin = self # last line + last incomplete lines self.line = QString() self.lines = [] # the cursor position in the last line self.point = 0 # flag: the interpreter needs more input to run the last lines. self.more = 0 # flag: readline() is being used for e.g. raw_input() and input() self.reading = 0 # history self.history = [] self.pointer = 0 self.xLast = 0 self.yLast = 0 # user interface setup # no word wrapping simplifies cursor <-> numLines() mapping self.setWordWrap(QMultiLineEdit.NoWrap) self.setCaption('PyCute -- a Python Shell for PyQt --' 'http://gerard.vermeulen.free.fr') # font if os.name == 'posix': font = QFont("Fixed", 12) elif os.name == 'nt' or os.name == 'dos': font = QFont("Courier New", 8) else: raise SystemExit, "FIXME for 'os2', 'mac', 'ce' or 'riscos'" font.setFixedPitch(1) self.setFont(font) # geometry height = 40 * QFontMetrics(font).lineSpacing() request = QSize(600, height) if parent is not None: request = request.boundedTo(parent.size()) self.resize(request) # interpreter prompt. try: sys.ps1 except AttributeError: sys.ps1 = ">>> " try: sys.ps2 except AttributeError: sys.ps2 = "... " # interpreter banner self.write('The PyCute shell running Python %s on %s.\n' % (sys.version, sys.platform)) self.write('Type "copyright", "credits" or "license"' ' for more information on Python.\n') self.write(sys.ps1)
def __init__(self, locals=None, log='', parent=None): """Constructor. The optional 'locals' argument specifies the dictionary in which code will be executed; it defaults to a newly created dictionary with key "__name__" set to "__console__" and key "__doc__" set to None. The optional 'log' argument specifies the file in which the interpreter session is to be logged. The optional 'parent' argument specifies the parent widget. If no parent widget has been specified, you can exit the interpreter by typing Ctrl-D. """ QTextEdit.__init__(self) self.interpreter = Interpreter(locals) self.connect(self, SIGNAL("returnPressed()"), self.onReturnPressed) # session log self.log = log or 'PyCute.log' # to exit the main interpreter by a Ctrl-D if PyCute has no parent if parent is None: self.eofKey = Qt.Key_D else: self.eofKey = None # capture all interactive input/output sys.stdout = self sys.stderr = self sys.stdin = self # user interface setup self.setTextFormat(QTextEdit.PlainText) self.setWrapPolicy(QTextEdit.Anywhere) self.setCaption('PyCute -- a Python Shell for PyQt -- ' 'http://gerard.vermeulen.free.fr') # font if os.name == 'posix': font = QFont("Fixed", 12) elif os.name == 'nt' or os.name == 'dos': font = QFont("Courier New", 8) else: raise SystemExit, "FIXME for 'os2', 'mac', 'ce' or 'riscos'" font.setFixedPitch(1) self.setFont(font) # geometry height = 40*QFontMetrics(font).lineSpacing() request = QSize(600, height) if parent is not None: request = request.boundedTo(parent.size()) self.resize(request) # interpreter prompt. try: sys.ps1 except AttributeError: sys.ps1 = ">>> " try: sys.ps2 except AttributeError: sys.ps2 = "... " # interpreter banner self.write('The PyCute shell running Python %s on %s.\n' % (sys.version, sys.platform)) self.write('Type "copyright", "credits" or "license"' ' for more information on Python.') self.ps1()