Exemplo n.º 1
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the style. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", self._tree_viewer)
        self._python_shell.bind("w", self._tree_viewer)

        return self._python_shell.control
Exemplo n.º 2
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', self._tree)
        self._python_shell.bind('w', self._tree)

        return self._python_shell.control
Exemplo n.º 3
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the style. """

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)

        return self.python_shell.control
Exemplo n.º 4
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        widget = self._grid

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", widget)
        self._python_shell.bind("w", widget)

        return self._python_shell.control
Exemplo n.º 5
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance."""

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)
        self.python_shell.bind('tvtk', tvtk)

        return self.python_shell.control
Exemplo n.º 6
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    # 'SplitApplicationWindow' interface -----------------------------------

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the panel is split.
    direction = Str("vertical")

    # ------------------------------------------------------------------------
    # Protected 'SplitApplicationWindow' interface.
    # ------------------------------------------------------------------------

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the style. """

        self._tree_viewer = FileTreeViewer(
            parent, input=os.path.abspath(os.curdir), sorter=FileSorter()
        )

        self._tree_viewer.observe(
            self._on_tree_anytrait_changed,
            match(lambda name, ctrait: True)  # listen to all traits
        )

        return self._tree_viewer.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the style. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", self._tree_viewer)
        self._python_shell.bind("w", self._tree_viewer)

        return self._python_shell.control

    # ------------------------------------------------------------------------
    # Private interface.
    # ------------------------------------------------------------------------

    # Trait event handlers -------------------------------------------------

    def _on_tree_anytrait_changed(self, event):
        """ Called when any trait on the tree has changed. """

        print("trait", event.name, "value", event.new)

        return
Exemplo n.º 7
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    # 'SplitApplicationWindow' interface -----------------------------------

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str("vertical")

    # ------------------------------------------------------------------------
    # Protected 'SplitApplicationWindow' interface.
    # ------------------------------------------------------------------------

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._expandable = expandable = ExpandablePanel(parent, create=False)
        self._expandable.create()

        for i in range(10):
            panel = self._create_content(expandable.control)
            expandable.add_panel("Panel %d" % i, panel)

        return expandable.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        widget = self._expandable

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", widget)
        self._python_shell.bind("w", widget)

        return self._python_shell.control

    # ------------------------------------------------------------------------
    # Private interface.
    # ------------------------------------------------------------------------

    def _create_content(self, parent):
        """ Create some context for an expandable panel. """

        tree = FileTree(parent, root=os.path.abspath(os.curdir))

        return tree.control
Exemplo n.º 8
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    #### 'SplitApplicationWindow' interface ###################################

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str('vertical')

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(
            parent,
            root=os.path.abspath(os.curdir),
        )

        self._tree.on_trait_change(self._on_tree_anytrait_changed)

        return self._tree.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', self._tree)
        self._python_shell.bind('w', self._tree)

        return self._python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    #### Trait event handlers #################################################

    def _on_tree_anytrait_changed(self, tree, trait_name, old, new):
        """ Called when any trait on the tree has changed. """

        print('trait', trait_name, 'value', new)

        return
Exemplo n.º 9
0
    def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the view. """

        self.shell = shell = PythonShell(parent)
        shell.on_trait_change(self._on_key_pressed, 'key_pressed')
        shell.on_trait_change(self._on_command_executed, 'command_executed')

        # Write application standard out to this shell instead of to DOS window
        self.on_trait_change(
            self._on_write_stdout, 'stdout_text', dispatch='ui'
        )
        self.original_stdout = sys.stdout
        sys.stdout = PseudoFile(self._write_stdout)

        # Namespace contributions.
        for bindings in self._bindings:
            for name, value in bindings.items():
                self.bind(name, value)

        for command in self._commands:
            self.execute_command(command)

        # We take note of the starting set of names and types bound in the
        # interpreter's namespace so that we can show the user what they have
        # added or removed in the namespace view.
        self._namespace_types = set((name, type(value)) for name, value in \
                                        self.namespace.items())

        # Register the view as a service.
        app = self.window.application
        self._service_id = app.register_service(IPythonShell, self)

        return self.shell.control
Exemplo n.º 10
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    # 'SplitApplicationWindow' interface -----------------------------------

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str("vertical")

    # ------------------------------------------------------------------------
    # Protected 'SplitApplicationWindow' interface.
    # ------------------------------------------------------------------------

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        model = NodeTreeModel(node_manager=node_manager)
        model.root = os.path.abspath(os.curdir)

        self._tree = NodeTree(parent, model=model)
        self._tree.on_trait_change(self._on_tree_anytrait_changed)

        return self._tree.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", self._tree)
        self._python_shell.bind("w", self._tree)

        return self._python_shell.control

    # ------------------------------------------------------------------------
    # Private interface.
    # ------------------------------------------------------------------------

    # Trait event handlers -------------------------------------------------

    def _on_tree_anytrait_changed(self, tree, trait_name, old, new):
        """ Called when any trait on the tree has changed. """

        print("trait", trait_name, "value", new)

        return
Exemplo n.º 11
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    #### 'SplitApplicationWindow' interface ###################################

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str('vertical')

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._expandable = expandable = ExpandablePanel(parent)

        for i in range(10):
            panel = self._create_content(expandable.control)
            expandable.add_panel('Panel %d' % i, panel)

        return expandable.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        widget = self._expandable

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', widget)
        self._python_shell.bind('w', widget)

        return self._python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _create_content(self, parent):
        """ Create some context for an expandable panel. """

        tree = FileTree(parent, root=os.path.abspath(os.curdir))

        return tree.control
Exemplo n.º 12
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    #### 'SplitApplicationWindow' interface ###################################

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str('vertical')

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(
            parent, root=os.path.abspath(os.curdir),
        )

        self._tree.on_trait_change(self._on_tree_anytrait_changed)

        return self._tree.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', self._tree)
        self._python_shell.bind('w', self._tree)

        return self._python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    #### Trait event handlers #################################################

    def _on_tree_anytrait_changed(self, tree, trait_name, old, new):
        """ Called when any trait on the tree has changed. """

        print('trait', trait_name, 'value', new)

        return
Exemplo n.º 13
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the style. """

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)

        return self.python_shell.control
Exemplo n.º 14
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', self._tree)
        self._python_shell.bind('w', self._tree)

        return self._python_shell.control
Exemplo n.º 15
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        widget = self._grid

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", widget)
        self._python_shell.bind("w", widget)

        return self._python_shell.control
Exemplo n.º 16
0
    def _create_python_shell(self, parent):
        """ Creates the Python shell. """

        self._python_shell = python_shell = PythonShell(parent)
        python_shell.bind('widget', self._tree_viewer)
        python_shell.bind('w', self._tree_viewer)
        python_shell.bind('window', self)
        python_shell.bind('actions', self._actions)

        return python_shell.control
Exemplo n.º 17
0
    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance."""

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)
        self.python_shell.bind('tvtk', tvtk)

        return self.python_shell.control
Exemplo n.º 18
0
    def create(self, parent):
        """ Create the python shell task pane

        This wraps the standard pyface PythonShell
        """
        logger.debug("PythonShellPane: creating python shell pane")
        self.editor = PythonShell(parent)
        self.control = self.editor.control

        # bind namespace
        logger.debug("PythonShellPane: binding variables")
        for binding in self.bindings:
            for name, value in binding.items():
                self.editor.bind(name, value)

        # execute commands
        logger.debug("PythonShellPane: executing startup commands")
        for command in self.commands:
            self.editor.execute_command(command)

        logger.debug("PythonShellPane: created")
Exemplo n.º 19
0
class IVTKWithCrust(SplitApplicationWindow):
    """ Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene."""

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.7)

    # The direction in which the panel is split.
    direction = Str('horizontal')

    # The `Scene` instance into which VTK renders.
    scene = Instance(Scene)

    # The `PythonShell` instance.
    python_shell = Instance(PythonShell)

    ###########################################################################
    # 'object' interface.
    ###########################################################################
    def __init__(self, **traits):
        """ Creates a new window. """

        # Base class constructor.
        super(IVTKWithCrust, self).__init__(**traits)
        self.title = 'TVTK Scene'
        # Create the window's menu bar.
        self.menu_bar_manager = create_ivtk_menu(self)

    ###########################################################################
    # `IWindow` interface.
    ###########################################################################
    def close(self):
        if self.scene is not None:
            self.scene.close()
        super(IVTKWithCrust, self).close()

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################
    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the style. """

        self.scene = DecoratedScene(parent)
        self.scene.renderer.background = 0.5, 0.5, 0.5
        return self.scene.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance."""

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)
        self.python_shell.bind('tvtk', tvtk)

        return self.python_shell.control
Exemplo n.º 20
0
    def _create_python_shell(self, parent):
        """ Creates the Python shell. """

        self._python_shell = python_shell = PythonShell(parent)

        # Bind useful names.
        python_shell.bind('widget', self._tree)
        python_shell.bind('w', self._tree)
        python_shell.bind('window', self)
        python_shell.bind('explore', explore)

        # Execute useful commands to bind useful names ;^)
        python_shell.execute_command('from apptools.naming.api import *')

        return python_shell.control
Exemplo n.º 21
0
class IVTKWithCrust(SplitApplicationWindow):
    """ Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene."""

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.7)

    # The direction in which the panel is split.
    direction = Str('horizontal')

    # The `Scene` instance into which VTK renders.
    scene = Instance(Scene)

    # The `PythonShell` instance.
    python_shell = Instance(PythonShell)

    ###########################################################################
    # 'object' interface.
    ###########################################################################
    def __init__(self, **traits):
        """ Creates a new window. """

        # Base class constructor.
        super(IVTKWithCrust, self).__init__(**traits)
        self.title = 'TVTK Scene'
        # Create the window's menu bar.
        self.menu_bar_manager = create_ivtk_menu(self)

    ###########################################################################
    # `IWindow` interface.
    ###########################################################################
    def close(self):
        if self.scene is not None:
            self.scene.close()
        super(IVTKWithCrust, self).close()

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################
    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the style. """

        self.scene = DecoratedScene(parent)
        self.scene.renderer.background = 0.5, 0.5, 0.5
        return self.scene.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance."""

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)
        self.python_shell.bind('tvtk', tvtk)

        return self.python_shell.control
Exemplo n.º 22
0
 def create(self, parent):
     """ Create the python shell task pane
     
     This wraps the standard pyface PythonShell
     """
     logger.debug('PythonShellPane: creating python shell pane')
     self.editor = PythonShell(parent)
     self.control = self.editor.control
     
     # bind namespace
     logger.debug('PythonShellPane: binding variables')
     for binding in self.bindings:
         for name, value in binding.items():
             self.editor.bind(name, value)
     
     # execute commands
     logger.debug('PythonShellPane: executing startup commands')
     for command in self.commands:
         self.editor.execute_command(command)
            
     logger.debug('PythonShellPane: created')
Exemplo n.º 23
0
class PythonShellPane(TaskPane):
    """ A Tasks Pane containing a Pyface PythonShell
    """

    id = "pyface.tasks.contrib.python_shell.pane"
    name = "Python Shell"

    editor = Instance(PythonShell)

    bindings = List(Dict)
    commands = List(Str)

    def create(self, parent):
        """ Create the python shell task pane

        This wraps the standard pyface PythonShell
        """
        logger.debug("PythonShellPane: creating python shell pane")
        self.editor = PythonShell(parent)
        self.control = self.editor.control

        # bind namespace
        logger.debug("PythonShellPane: binding variables")
        for binding in self.bindings:
            for name, value in binding.items():
                self.editor.bind(name, value)

        # execute commands
        logger.debug("PythonShellPane: executing startup commands")
        for command in self.commands:
            self.editor.execute_command(command)

        logger.debug("PythonShellPane: created")

    def destroy(self):
        """ Destroy the python shell task pane
        """
        logger.debug("PythonShellPane: destroying python shell pane")
        self.editor.destroy()
        self.control = self.editor = None
        logger.debug("PythonShellPane: destroyed")
Exemplo n.º 24
0
class PythonShellPane(TaskPane):
    """ A Tasks Pane containing a Pyface PythonShell
    """
    id = 'pyface.tasks.contrib.python_shell.pane'
    name = 'Python Shell'
    
    editor = Instance(PythonShell)
    
    bindings = List(Dict)
    commands = List(Str)
    
    def create(self, parent):
        """ Create the python shell task pane
        
        This wraps the standard pyface PythonShell
        """
        logger.debug('PythonShellPane: creating python shell pane')
        self.editor = PythonShell(parent)
        self.control = self.editor.control
        
        # bind namespace
        logger.debug('PythonShellPane: binding variables')
        for binding in self.bindings:
            for name, value in binding.items():
                self.editor.bind(name, value)
        
        # execute commands
        logger.debug('PythonShellPane: executing startup commands')
        for command in self.commands:
            self.editor.execute_command(command)
               
        logger.debug('PythonShellPane: created')
    
    def destroy(self):
        """ Destroy the python shell task pane
        """
        logger.debug('PythonShellPane: destroying python shell pane')
        self.editor.destroy()
        self.control = self.editor = None
        logger.debug('PythonShellPane: destroyed')
Exemplo n.º 25
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    #### 'SplitApplicationWindow' interface ###################################

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str("vertical")

    # The data used to create the SimpleGridModel
    data = [["bob", 1, True, Float], ["sarah", 45, True, Str], ["jonas", -3, False, direction]]

    rows = [GridRow(name="Row 1"), GridRow(name="Row 2"), GridRow(name="Row 3")]

    cols = [
        GridColumn(name="Name"),
        GridColumn(name="Index", read_only=True),
        GridColumn(name="Veracity"),
        GridColumn(name="Object"),
    ]

    # The data used to create the TraitGridModel
    trait_data = [
        GridRow(name="Bob", index=1, veracity=True, object=Float),
        GridRow(name="Sarah", index=45, veracity=True, object=Str),
        GridRow(name="Jonas", index=-3, veracity=False, object=direction),
    ]

    trait_col = [
        TraitGridColumn(name="name", label="Name"),
        TraitGridColumn(name="index", label="Index", read_only=True),
        TraitGridColumn(name="veracity", label="Veracity"),
        TraitGridColumn(name="object", label="Object"),
    ]

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        # self._model = model = SimpleGridModel(data = self.data,
        #                                      rows = self.rows,
        #                                      columns = self.cols)

        self._model = model = TraitGridModel(data=self.trait_data, columns=self.trait_col, row_name_trait="name")

        self._grid = grid = Grid(parent, model=model)

        self._grid.on_trait_change(self._on_grid_anytrait_changed)

        return grid.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        widget = self._grid

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", widget)
        self._python_shell.bind("w", widget)

        return self._python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _create_content(self, parent):
        """ Create some context for an expandable panel. """

        tree = FileTree(parent, root=os.path.abspath(os.curdir))

        return tree.control

    #### Trait event handlers #################################################

    def _on_grid_anytrait_changed(self, tree, trait_name, old, new):
        """ Called when any trait on the tree has changed. """

        print "trait", trait_name, "value", new

        return
Exemplo n.º 26
0
class ExampleWindow(SplitApplicationWindow):
    """ An example application window. """

    # The actors we can create.
    ACTORS = [
        arrow_actor, axes_actor, cone_actor, cube_actor, cylinder_actor,
        earth_actor, sphere_actor
    ]

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.75)

    # The direction in which the panel is split.
    direction = Str('horizontal')

    # The `Scene` instance into which VTK renders.
    scene = Instance(DecoratedScene)

    # The `PythonShell` instance.
    python_shell = Instance(PythonShell)

    ###########################################################################
    # 'object' interface.
    ###########################################################################
    def __init__(self, **traits):
        """ Creates a new window. """

        # Base class constructor.
        super(ExampleWindow, self).__init__(**traits)

        # Create the window's menu bar.
        self._create_my_menu_bar()

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the style. """

        self.scene = DecoratedScene(parent)
        self.scene.renderer.background = 0.1, 0.2, 0.4

        # Add some actors.
        for i in range(10):
            func = random.choice(ExampleWindow.ACTORS)
            actor = func()

            # Place the actor randomly.
            x = random.uniform(-3, 3)
            y = random.uniform(-3, 3)
            z = random.uniform(-3, 3)

            actor.position = x, y, z

            # Add the actor to the scene.
            self.scene.add_actors(actor)

        # Render it all!
        self.scene.render()

        # Reset the zoom nicely.
        self.scene.reset_zoom()

        return self.scene.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the style. """

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)

        return self.python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _create_my_menu_bar(self):
        """ Creates the window's menu bar. """

        self.menu_bar_manager = MenuBarManager(
            MenuManager(
                SaveImageAction(self),
                Separator(),
                ExitAction(self),
                name='&File',
            ), MenuManager(
                SaveToClipboardAction(self),
                name='&Edit',
            ),
            MenuManager(
                SpecialViewAction(self, "&Reset Zoom", 'reset_zoom'),
                Separator(),
                SpecialViewAction(self, "&Isometric", 'isometric_view'),
                SpecialViewAction(self, "&X positive", 'x_plus_view'),
                SpecialViewAction(self, "X negative", 'x_minus_view'),
                SpecialViewAction(self, "&Y positive", 'y_plus_view'),
                SpecialViewAction(self, "Y negative", 'y_minus_view'),
                SpecialViewAction(self, "&Z positive", 'z_plus_view'),
                SpecialViewAction(self, "Z negative", 'z_minus_view'),
                name='&View',
            ))
Exemplo n.º 27
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    # 'SplitApplicationWindow' interface -----------------------------------

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str("vertical")

    # The data used to create the SimpleGridModel
    data = [
        ["bob", 1, True, Float],
        ["sarah", 45, True, Str],
        ["jonas", -3, False, direction],
    ]

    rows = [
        GridRow(name="Row 1"),
        GridRow(name="Row 2"),
        GridRow(name="Row 3"),
    ]

    cols = [
        GridColumn(name="Name"),
        GridColumn(name="Index", read_only=True),
        GridColumn(name="Veracity"),
        GridColumn(name="Object"),
    ]

    # The data used to create the TraitGridModel
    trait_data = [
        GridRow(name="Bob", index=1, veracity=True, object=Float),
        GridRow(name="Sarah", index=45, veracity=True, object=Str),
        GridRow(name="Jonas", index=-3, veracity=False, object=direction),
    ]

    trait_col = [
        TraitGridColumn(name="name", label="Name"),
        TraitGridColumn(name="index", label="Index", read_only=True),
        TraitGridColumn(name="veracity", label="Veracity"),
        TraitGridColumn(name="object", label="Object"),
    ]

    # ------------------------------------------------------------------------
    # Protected 'SplitApplicationWindow' interface.
    # ------------------------------------------------------------------------

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._model = model = TraitGridModel(data=self.trait_data,
                                             columns=self.trait_col,
                                             row_name_trait="name")

        self._grid = grid = Grid(parent, model=model)

        self._grid.observe(
            self._on_grid_anytrait_changed,
            match(lambda name, ctrait: True)  # listen to all traits
        )

        return grid.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        widget = self._grid

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", widget)
        self._python_shell.bind("w", widget)

        return self._python_shell.control

    # ------------------------------------------------------------------------
    # Private interface.
    # ------------------------------------------------------------------------

    def _create_content(self, parent):
        """ Create some context for an expandable panel. """

        tree = FileTree(parent, root=os.path.abspath(os.curdir))

        return tree.control

    # Trait event handlers -------------------------------------------------

    def _on_grid_anytrait_changed(self, event):
        """ Called when any trait on the tree has changed. """

        print("trait", event.name, "value", event.new)

        return
Exemplo n.º 28
0
class ExampleWindow(SplitApplicationWindow):
    """ An example application window. """

    # The actors we can create.
    ACTORS = [
        arrow_actor, axes_actor, cone_actor, cube_actor, cylinder_actor,
        earth_actor, sphere_actor
    ]

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.75)

    # The direction in which the panel is split.
    direction = Str('horizontal')

    # The `Scene` instance into which VTK renders.
    scene = Instance(DecoratedScene)

    # The `PythonShell` instance.
    python_shell = Instance(PythonShell)

    ###########################################################################
    # 'object' interface.
    ###########################################################################
    def __init__(self, **traits):
        """ Creates a new window. """

        # Base class constructor.
        super(ExampleWindow, self).__init__(**traits)

        # Create the window's menu bar.
        self._create_my_menu_bar()


    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the style. """

        self.scene = DecoratedScene(parent)
        self.scene.renderer.background = 0.1, 0.2, 0.4

        # Add some actors.
        for i in range(10):
            func = random.choice(ExampleWindow.ACTORS)
            actor = func()

            # Place the actor randomly.
            x = random.uniform(-3, 3)
            y = random.uniform(-3, 3)
            z = random.uniform(-3, 3)

            actor.position = x, y, z

            # Add the actor to the scene.
            self.scene.add_actors(actor)

        # Render it all!
        self.scene.render()

        # Reset the zoom nicely.
        self.scene.reset_zoom()

        return self.scene.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the style. """

        self.python_shell = PythonShell(parent)
        self.python_shell.bind('scene', self.scene)
        self.python_shell.bind('s', self.scene)

        return self.python_shell.control


    ###########################################################################
    # Private interface.
    ###########################################################################

    def _create_my_menu_bar(self):
        """ Creates the window's menu bar. """

        self.menu_bar_manager = MenuBarManager(
            MenuManager(
                SaveImageAction(self),
                Separator(),
                ExitAction(self),
                name = '&File',
            ),
            MenuManager(
                SaveToClipboardAction(self),
                name = '&Edit',
            ),
            MenuManager(
                SpecialViewAction(self, "&Reset Zoom", 'reset_zoom'),
                Separator(),
                SpecialViewAction(self, "&Isometric", 'isometric_view'),
                SpecialViewAction(self, "&X positive", 'x_plus_view'),
                SpecialViewAction(self, "X negative", 'x_minus_view'),
                SpecialViewAction(self, "&Y positive", 'y_plus_view'),
                SpecialViewAction(self, "Y negative", 'y_minus_view'),
                SpecialViewAction(self, "&Z positive", 'z_plus_view'),
                SpecialViewAction(self, "Z negative", 'z_minus_view'),
                name = '&View',
            )
        )
    def _create_contents(self, parent):
        """ Create the editor. """

        self._shell = PythonShell(parent)

        return self._shell.control
Exemplo n.º 30
0
 def _create_contents(self, parent):
     """ Create the shell widget. """
     self.shell = PythonShell(parent)
     return self.shell.control
Exemplo n.º 31
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    #### 'SplitApplicationWindow' interface ###################################

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str('vertical')

    # The data used to create the SimpleGridModel
    data = [['bob', 1, True, Float], ['sarah', 45, True, Str],
            ['jonas', -3, False, direction]]

    rows = [
        GridRow(name='Row 1'),
        GridRow(name='Row 2'),
        GridRow(name='Row 3')
    ]

    cols = [
        GridColumn(name='Name'),
        GridColumn(name='Index', read_only=True),
        GridColumn(name='Veracity'),
        GridColumn(name='Object')
    ]

    # The data used to create the TraitGridModel
    trait_data = [
        GridRow(name='Bob', index=1, veracity=True, object=Float),
        GridRow(name='Sarah', index=45, veracity=True, object=Str),
        GridRow(name='Jonas', index=-3, veracity=False, object=direction)
    ]

    trait_col = [
        TraitGridColumn(name='name', label='Name'),
        TraitGridColumn(name='index', label='Index', read_only=True),
        TraitGridColumn(name='veracity', label='Veracity'),
        TraitGridColumn(name='object', label='Object')
    ]

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        #self._model = model = SimpleGridModel(data = self.data,
        #                                      rows = self.rows,
        #                                      columns = self.cols)

        self._model = model = TraitGridModel(data=self.trait_data,
                                             columns=self.trait_col,
                                             row_name_trait='name')

        self._grid = grid = Grid(parent, model=model)

        self._grid.on_trait_change(self._on_grid_anytrait_changed)

        return grid.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        widget = self._grid

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', widget)
        self._python_shell.bind('w', widget)

        return self._python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _create_content(self, parent):
        """ Create some context for an expandable panel. """

        tree = FileTree(parent, root=os.path.abspath(os.curdir))

        return tree.control

    #### Trait event handlers #################################################

    def _on_grid_anytrait_changed(self, tree, trait_name, old, new):
        """ Called when any trait on the tree has changed. """

        print(('trait', trait_name, 'value', new))

        return