0

I'm working on a multi-threaded application and using ShellEditor to create an embedded Python terminal.

I need to get a notification before and after a command has been executed in the embedded shell so I can acquire and release a threading lock.

I'm setting up my ShellEditor as shown below, can anyone think of a hack to get this working?

ShellEditor(share=False, command_executed="did_execute_command", command_to_execute="will_execute_command")

The command_executed notification is working, but I never see the command_to_execute get called.

Here is a full example, that shows the issues on traitsui 8.0.0.

from traits.api import HasTraits, Dict, Event, observe
from traitsui.api import View, Item, ShellEditor


class PythonShellExample(HasTraits):

    shared = Dict({"msg": "Hello world"})

    will_execute_command = Event(False)

    did_execute_command = Event(False)

     # NEVER CALLED
    @observe("will_execute_command")
    def on_will_execute_command_changed(self, event):
        print(event)

    @observe("did_execute_command")
    def on_did_execute_command_changed(self, event):
        print(event)

    def default_traits_view(self):
        return View(
            Item(
                "shared",
                editor=ShellEditor(
                    share=False, command_executed="did_execute_command", command_to_execute="will_execute_command"
                ),
                label="Shell",
                show_label=False,
            ),
        )


if __name__ == "__main__":
    app = PythonShellExample()
    app.configure_traits()

Screenshot showing only the 'command_executed' notification fired.

Daniel Farrell
  • 9,316
  • 8
  • 39
  • 62

0 Answers0