Use console's namespace as both local and global context for exec/eval.

This allows functions defined in the console to access global variables.
Also expose the console itself via special __console__ variable.
This commit is contained in:
Luke Campagnola 2016-09-06 17:54:54 -07:00
parent 670d63cdf4
commit 8aec44d088

View File

@ -48,6 +48,7 @@ class ConsoleWidget(QtGui.QWidget):
QtGui.QWidget.__init__(self, parent)
if namespace is None:
namespace = {}
namespace['__console__'] = self
self.localNamespace = namespace
self.editor = editor
self.multiline = None
@ -134,7 +135,7 @@ class ConsoleWidget(QtGui.QWidget):
if frame is not None and self.ui.runSelectedFrameCheck.isChecked():
return self.currentFrame().tb_frame.f_globals
else:
return globals()
return self.localNamespace
def locals(self):
frame = self.currentFrame()