From a328392c381bd7afceb88bd499afff14b7a78238 Mon Sep 17 00:00:00 2001 From: Jan von Rickenbach Date: Mon, 23 Sep 2019 17:24:51 +0200 Subject: [PATCH 1/2] Pass __init__ keyword arguments also to _create_control. Allows to set constructor arguments of PyShell. --- pyface/ui/wx/python_shell.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyface/ui/wx/python_shell.py b/pyface/ui/wx/python_shell.py index 423a8380e..c78690b1c 100644 --- a/pyface/ui/wx/python_shell.py +++ b/pyface/ui/wx/python_shell.py @@ -62,7 +62,7 @@ def __init__(self, parent, **traits): super(PythonShell, self).__init__(**traits) # Create the toolkit-specific control that represents the widget. - self.control = self._create_control(parent) + self.control = self._create_control(parent, **traits) # Set up to be notified whenever a Python statement is executed: self.control.handlers.append(self._on_command_executed) @@ -166,8 +166,8 @@ def set_history(self, history, history_index): # 'IWidget' interface. ########################################################################### - def _create_control(self, parent): - shell = PyShell(parent, -1) + def _create_control(self, parent, **kwargs): + shell = PyShell(parent, -1, **kwargs) # Listen for key press events. wx.EVT_CHAR(shell, self._wx_on_char) From af25ea263b611281b3f47ea938f09894c480521f Mon Sep 17 00:00:00 2001 From: janvonrickenbach Date: Wed, 2 Oct 2019 23:28:42 +0200 Subject: [PATCH 2/2] use traits to implement welcome_message for python shell --- pyface/i_python_shell.py | 4 +++- pyface/ui/qt4/python_shell.py | 6 ++++-- pyface/ui/wx/python_shell.py | 10 ++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pyface/i_python_shell.py b/pyface/i_python_shell.py index ed16df54d..58e4cfe75 100644 --- a/pyface/i_python_shell.py +++ b/pyface/i_python_shell.py @@ -14,7 +14,7 @@ """ The interface for an interactive Python shell. """ # Enthought library imports. -from traits.api import Event +from traits.api import Event, String # Local imports. from pyface.key_pressed_event import KeyPressedEvent @@ -32,6 +32,8 @@ class IPythonShell(IWidget): #: A key has been pressed. key_pressed = Event(KeyPressedEvent) + welcome_message = String + ########################################################################### # 'IPythonShell' interface. ########################################################################### diff --git a/pyface/ui/qt4/python_shell.py b/pyface/ui/qt4/python_shell.py index 65cb0f04d..149af1dbc 100644 --- a/pyface/ui/qt4/python_shell.py +++ b/pyface/ui/qt4/python_shell.py @@ -22,7 +22,7 @@ from pygments.lexers import PythonLexer # Enthought library imports. -from traits.api import Event, provides +from traits.api import Event, provides, String from traits.util.clean_strings import python_name # Local imports. @@ -46,6 +46,8 @@ class PythonShell(MPythonShell, Widget): command_executed = Event + welcome_message = String + key_pressed = Event(KeyPressedEvent) #-------------------------------------------------------------------------- @@ -423,7 +425,7 @@ def _get_banner(self): """ banner = 'Python %s on %s\nType "help", "copyright", "credits" or ' \ '"license" for more information.' - return banner % (sys.version, sys.platform) + return banner % (sys.version, sys.platform) + self.welcome_message def _get_context(self, cursor=None): """ Gets the context for the specified cursor (or the current cursor diff --git a/pyface/ui/wx/python_shell.py b/pyface/ui/wx/python_shell.py index c78690b1c..9ee73db72 100644 --- a/pyface/ui/wx/python_shell.py +++ b/pyface/ui/wx/python_shell.py @@ -24,7 +24,7 @@ import wx # Enthought library imports. -from traits.api import Event, provides +from traits.api import Event, provides, String # Private Enthought library imports. from traits.util.clean_strings import python_name @@ -49,6 +49,8 @@ class PythonShell(MPythonShell, Widget): key_pressed = Event(KeyPressedEvent) + welcome_message = String + ########################################################################### # 'object' interface. ########################################################################### @@ -62,7 +64,7 @@ def __init__(self, parent, **traits): super(PythonShell, self).__init__(**traits) # Create the toolkit-specific control that represents the widget. - self.control = self._create_control(parent, **traits) + self.control = self._create_control(parent) # Set up to be notified whenever a Python statement is executed: self.control.handlers.append(self._on_command_executed) @@ -166,8 +168,8 @@ def set_history(self, history, history_index): # 'IWidget' interface. ########################################################################### - def _create_control(self, parent, **kwargs): - shell = PyShell(parent, -1, **kwargs) + def _create_control(self, parent): + shell = PyShell(parent, -1, introText=self.welcome_message) # Listen for key press events. wx.EVT_CHAR(shell, self._wx_on_char)