From 8aec44d088112ff63010886f994ba8c2550b5d4c Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Tue, 6 Sep 2016 17:54:54 -0700 Subject: [PATCH] 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. --- pyqtgraph/console/Console.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/console/Console.py b/pyqtgraph/console/Console.py index 3ea1580f..ed4b7f08 100644 --- a/pyqtgraph/console/Console.py +++ b/pyqtgraph/console/Console.py @@ -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()