Example #1
0
    def dispose(self):
        """ Disposes of the contents of an editor.
        """
        # Remove all of the wx event handlers:
        control = self.control
        parent = control.GetParent()
        id = control.GetId()
        wx.EVT_LIST_BEGIN_DRAG(parent, id, None)
        wx.EVT_LIST_BEGIN_LABEL_EDIT(parent, id, None)
        wx.EVT_LIST_END_LABEL_EDIT(parent, id, None)
        wx.EVT_LIST_ITEM_SELECTED(parent, id, None)
        wx.EVT_LIST_ITEM_DESELECTED(parent, id, None)
        wx.EVT_LIST_KEY_DOWN(parent, id, None)
        wx.EVT_LIST_ITEM_ACTIVATED(parent, id, None)
        wx.EVT_LIST_COL_END_DRAG(parent, id, None)
        wx.EVT_LIST_COL_RIGHT_CLICK(parent, id, None)
        wx.EVT_LIST_COL_CLICK(parent, id, None)
        wx.EVT_LEFT_DOWN(control, None)
        wx.EVT_LEFT_DCLICK(control, None)
        wx.EVT_RIGHT_DOWN(control, None)
        wx.EVT_RIGHT_DCLICK(control, None)
        wx.EVT_MOTION(control, None)
        wx.EVT_SIZE(control, None)

        self.context_object.on_trait_change(
            self.update_editor,
            self.extended_name + '_items',
            remove=True)

        if self.factory.auto_update:
            self.context_object.on_trait_change(
                self.refresh_editor, self.extended_name + '.-', remove=True)

        self.on_trait_change(self._refresh, 'adapter.+update', remove=True)
        self.on_trait_change(self._rebuild_all, 'adapter.columns',
                             remove=True)

        super(TabularEditor, self).dispose()
Example #2
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory

        # Set up the adapter to use:
        self.adapter = factory.adapter

        # Determine the style to use for the list control:
        style = wx.LC_REPORT | wx.LC_VIRTUAL | wx.BORDER_NONE

        if factory.editable_labels:
            style |= wx.LC_EDIT_LABELS

        if factory.horizontal_lines:
            style |= wx.LC_HRULES

        if factory.vertical_lines:
            style |= wx.LC_VRULES

        if not factory.multi_select:
            style |= wx.LC_SINGLE_SEL

        if not factory.show_titles:
            style |= wx.LC_NO_HEADER

        # Create the list control and link it back to us:
        self.control = control = wxListCtrl(
            parent,
            -1,
            style=style,
            can_edit=factory.editable,
            edit_labels=factory.editable_labels)
        control._editor = self

        # Create the list control column:
        #fixme: what do we do here?
        #control.InsertColumn( 0, '' )

        # Set up the list control's event handlers:
        id = control.GetId()
        wx.EVT_LIST_BEGIN_DRAG(parent, id, self._begin_drag)
        wx.EVT_LIST_BEGIN_LABEL_EDIT(parent, id, self._begin_label_edit)
        wx.EVT_LIST_END_LABEL_EDIT(parent, id, self._end_label_edit)
        wx.EVT_LIST_ITEM_SELECTED(parent, id, self._item_selected)
        wx.EVT_LIST_ITEM_DESELECTED(parent, id, self._item_selected)
        wx.EVT_LIST_KEY_DOWN(parent, id, self._key_down)
        wx.EVT_LIST_ITEM_ACTIVATED(parent, id, self._item_activated)
        wx.EVT_LIST_COL_END_DRAG(parent, id, self._size_modified)
        wx.EVT_LIST_COL_RIGHT_CLICK(parent, id, self._column_right_clicked)
        wx.EVT_LIST_COL_CLICK(parent, id, self._column_clicked)
        wx.EVT_LEFT_DOWN(control, self._left_down)
        wx.EVT_LEFT_DCLICK(control, self._left_dclick)
        wx.EVT_RIGHT_DOWN(control, self._right_down)
        wx.EVT_RIGHT_DCLICK(control, self._right_dclick)
        wx.EVT_MOTION(control, self._motion)
        wx.EVT_SIZE(control, self._size_modified)

        # Set up the drag and drop target:
        if PythonDropTarget is not None:
            control.SetDropTarget(PythonDropTarget(self))

        # Set up the selection listener (if necessary):
        if factory.multi_select:
            self.sync_value(factory.selected,
                            'multi_selected',
                            'both',
                            is_list=True)
            self.sync_value(factory.selected_row,
                            'multi_selected_rows',
                            'both',
                            is_list=True)
        else:
            self.sync_value(factory.selected, 'selected', 'both')
            self.sync_value(factory.selected_row, 'selected_row', 'both')

        # Synchronize other interesting traits as necessary:
        self.sync_value(factory.update, 'update', 'from')

        self.sync_value(factory.activated, 'activated', 'to')
        self.sync_value(factory.activated_row, 'activated_row', 'to')

        self.sync_value(factory.clicked, 'clicked', 'to')
        self.sync_value(factory.dclicked, 'dclicked', 'to')

        self.sync_value(factory.right_clicked, 'right_clicked', 'to')
        self.sync_value(factory.right_dclicked, 'right_dclicked', 'to')

        self.sync_value(factory.column_clicked, 'column_clicked', 'to')

        # Make sure we listen for 'items' changes as well as complete list
        # replacements:
        try:
            self.context_object.on_trait_change(self.update_editor,
                                                self.extended_name + '_items',
                                                dispatch='ui')
        except:
            pass

        # If the user has requested automatic update, attempt to set up the
        # appropriate listeners:
        if factory.auto_update:
            self.context_object.on_trait_change(self.refresh_editor,
                                                self.extended_name + '.-',
                                                dispatch='ui')

        # Create the mapping from user supplied images to wx.ImageList indices:
        for image_resource in factory.images:
            self._add_image(image_resource)

        # Refresh the editor whenever the adapter changes:
        self.on_trait_change(self._refresh, 'adapter.+update', dispatch='ui')

        # Rebuild the editor columns and headers whenever the adapter's
        # 'columns' changes:
        self.on_trait_change(self._rebuild_all,
                             'adapter.columns',
                             dispatch='ui')

        # Make sure the tabular view gets initialized:
        self._rebuild()

        # Set the list control's tooltip:
        self.set_tooltip()