class FileBrowserView(View, FileBrowser):
    """ A view containing a file browser. """

    #### 'IView' interface ####################################################

    # The part's globally unique identifier.
    id = 'etsdevtools.developer.tools.file_browser'

    # The part's name (displayed to the user).
    name = 'Workspace'

    # The default position of the view relative to the item specified in the
    # 'relative_to' trait.
    position = 'bottom'

    #### 'IExtensionPointUser' interface ######################################

    traits_view = TraitsView(Item(name='root',
                                  editor=tree_editor,
                                  show_label=False),
                             handler=FileBrowserHandler)

    ###########################################################################
    # 'View' interface.
    ###########################################################################

    def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the view. """

        self.ui = self.edit_traits(parent=parent, kind='subpanel')
        # Register the file browser as a service.
        self.window.application.register_service(FileBrowser, self)
        return self.ui.control

    def run(self, filename=None, shell=None):
        """
        """
        if filename is None:
            filename = self.path

        if shell is None:
            shell = self.window.get_view_by_id(
                'envisage.plugins.python_shell_view')

        if shell is not None:
            self.run_dir(shell, filename)

    def run_dir(self, view, path):
        if isfile(path):
            self.run_script(view, path)
        elif isdir(path):
            for file in glob.iglob(join(path, '*.py')):
                self.run_script(view, file)
        for dir in glob.iglob(join(path, '*') + sep):
            self.run_dir(view, dir)
        return

    def run_script(self, view, filename):
        view.execute_command('%run  ' + '"%s"' % filename, hidden=False)
示例#2
0
    class MyClass(HasTraits):
        the_object = obj

        view = TraitsView(
            Item('the_object', style='custom', show_label=False),
            resizable=True,
            title=name,
            width=600,
        )
示例#3
0
    def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the view.

        'parent' is the toolkit-specific control that is the view's parent.

        """

        self.model = DebugViewModel(window=self.window)

        ui = self.model.edit_traits(parent=parent,
                                    kind='subpanel',
                                    view=TraitsView('active_part',
                                                    'active_editor',
                                                    'active_view'))

        return ui.control
示例#4
0
class NamespaceView(View):
    """ A view containing the contents of the Python shell namespace. """

    implements(INamespaceView)

    #### 'IView' interface ####################################################

    # The part's globally unique identifier.
    id = 'envisage.plugins.ipython_shell.namespace_view'

    # The view's name.
    name = 'Namespace'

    # The default position of the view relative to the item specified in the
    # 'relative_to' trait.
    position = 'left'

    #### 'NamespaceView' interface ############################################

    # The different tree nodes
    tree_nodes = Property(depends_on='search_text')

    # Search text
    search_text = Str

    tree_editor = Property(depends_on="ui")

    # The timer used to refresh the ui
    _refresh_tree_nodes_timer = Instance(Timer)

    def __refresh_tree_nodes_timer_default(self):
        return Timer(100, self._refresh_tree_nodes)

    ###########################################################################
    # 'View' interface.
    ###########################################################################

    traits_view = TraitsView(
        Group(Item('search_text', label='Search')),
        Item('tree_nodes',
             id='table',
             editor=TreeEditor(
                 auto_open=1,
                 hide_root=True,
                 editable=False,
                 nodes=value_tree_nodes,
                 on_dclick='object._explore',
             ),
             springy=True,
             resizable=True,
             show_label=False),
        resizable=True,
    )

    def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the view.

        'parent' is the toolkit-specific control that is the view's parent.

        """
        self.ui = self.edit_traits(parent=parent, kind='subpanel')

        # Register the view as a service.
        self.window.application.register_service(INamespaceView, self)

        shell = self.window.application.get_service(IPythonShell)
        if shell is not None:
            shell.on_trait_change(self._on_names_changed, 'names')
            self._on_names_changed(shell.names)

        return self.ui.control

    def destroy_control(self):
        """ Destroys the toolkit-specific control that represents the view.

        """

        super(NamespaceView, self).destroy_control()

        # Remove the namespace change handler
        shell = self.window.application.get_service(IPythonShell)
        if shell is not None:
            shell.on_trait_change(self._on_names_changed, 'names', remove=True)

    ###########################################################################
    # 'NamespaceView' interface.
    ###########################################################################

    #### Properties ###########################################################

    def _get_tree_nodes(self):
        """ Property getter. """

        shell = self.window.application.get_service(IPythonShell)

        # Cater for an un-initialized python shell view
        if shell is None:
            return NamespaceNode(value={}, readonly=True)
        filtered_namespace = dict()

        for name in shell.names:
            filtered_namespace[name] = shell.lookup(name)

        if not self.search_text == '':
            filtered_namespace = filter_namespace(filtered_namespace,
                                                  self.search_text)

        return NamespaceNode(value=filtered_namespace, readonly=True)

    def _get_tree_editor(self):
        """ Walk the editor list to retrieve the instance of the
            tree editor currently used.
        """
        for editor in self.ui._editors:
            print editor
        return self.ui._editors[-1]

    def _refresh_tree_nodes(self):
        """ Callback called by a timer to refresh the UI.

            The UI is refreshed by a timer to buffer the refreshes,
            in order not to slow down the execution engine.
        """
        self.trait_property_changed('tree_nodes', None)
        self._refresh_tree_nodes_timer.Stop()

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

    #### Trait change handlers ################################################

    def _on_names_changed(self, new):
        """ Dynamic trait change handler. """

        if not self._refresh_tree_nodes_timer.IsRunning():
            GUI.invoke_later(self._refresh_tree_nodes_timer.Start)

    def _explore(self, object):
        """ Displays a view of the object.
        """
        explore(object)
示例#5
0
class NamespaceView(View):
    """ A view containing the contents of the Python shell namespace. """

    #### 'IView' interface ####################################################

    # The part's globally unique identifier.
    id = "enthought.plugins.python_shell.view.namespace_view"

    # The view's name.
    name = "Namespace"

    # The default position of the view relative to the item specified in the
    # 'relative_to' trait.
    position = "left"

    #### 'NamespaceView' interface ############################################

    # The bindings in the namespace.  This is a list of HasTraits objects with
    # 'name', 'type' and 'module' string attributes.
    bindings = Property(List, depends_on=["namespace"])

    shell_view = Instance(PythonShellView)

    namespace = DelegatesTo("shell_view")

    # The default traits UI view.
    traits_view = TraitsView(
        VGroup(
            Item(
                "bindings",
                id="table",
                editor=table_editor,
                springy=True,
                resizable=True,
            ),
            show_border=True,
            show_labels=False,
        ),
        resizable=True,
    )

    ###########################################################################
    # 'View' interface.
    ###########################################################################

    def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the view.

        'parent' is the toolkit-specific control that is the view's parent.

        """

        self.ui = self.edit_traits(parent=parent, kind="subpanel")

        self.shell_view = self.window.application.get_service(IPythonShell)
        # 'shell_view' is an instance of the class PythonShellView from the
        # module envisage.plugins.python_shell.view.python_shell_view.

        return self.ui.control

    ###########################################################################
    # 'NamespaceView' interface.
    ###########################################################################

    #### Properties ###########################################################

    @cached_property
    def _get_bindings(self):
        """ Property getter. """

        if self.shell_view is None:
            return []

        class item(HasTraits):
            name = Str
            type = Str
            module = Str

        data = [
            item(
                name=name, type=type_to_str(value), module=module_to_str(value)
            )
            for name, value in self.shell_view.namespace.items()
        ]

        return data