Ejemplo n.º 1
0
    def __init__(self, parent, title):
        super(Mywin, self).__init__(parent, title=title, size=(-1, 300))
        panel = wx.Panel(self)
        box = wx.BoxSizer(wx.HORIZONTAL)
        languages = [
            'C', 'C++', 'Java', 'Python', 'Perl', 'JavaScript', 'PHP',
            'VB.NET', 'C#'
        ]

        self.lst1 = wx.ListCtrl(panel, -1, style=wx.LC_LIST)
        self.lst2 = wx.ListCtrl(panel, -1, style=wx.LC_LIST)
        for lang in languages:
            self.lst1.InsertStringItem(0, lang)

        dt = MyTarget(self.lst2)
        self.lst2.SetDropTarget(dt)
        wx.EVT_LIST_BEGIN_DRAG(self, self.lst1.GetId(), self.OnDragInit)

        box.Add(self.lst1, 0, wx.EXPAND)
        box.Add(self.lst2, 1, wx.EXPAND)

        panel.SetSizer(box)
        panel.Fit()
        self.Centre()
        self.Show(True)
Ejemplo n.º 2
0
 def init_events(self):
     tID = self.GetId()
     wx.EVT_LIST_BEGIN_DRAG(self, tID, self.OnMouseDown)
     wx.EVT_LEFT_DCLICK(self, self.OnDoubleClick)
     wx.EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)
     wx.EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemSelected)
     wx.EVT_LIST_ITEM_RIGHT_CLICK(self, tID, self.OnRightClick)
     wx.EVT_CHAR(self, self.OnKeyPress)
Ejemplo n.º 3
0
    def __init__(self, parent, image_size=(16, 16), **traits):
        """ Creates a new table viewer.

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

        'image_size' is a tuple in the form (int width, int height) that
        specifies the size of the images (if any) displayed in the table.

        """

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

        # Create the toolkit-specific control.
        self.control = table = _Table(parent, image_size, self)

        # Get our actual id.
        wxid = table.GetId()

        # Table events.
        wx.EVT_LIST_ITEM_SELECTED(table, wxid, self._on_item_selected)
        wx.EVT_LIST_ITEM_ACTIVATED(table, wxid, self._on_item_activated)
        wx.EVT_LIST_BEGIN_DRAG(table, wxid, self._on_list_begin_drag)
        wx.EVT_LIST_BEGIN_RDRAG(table, wxid, self._on_list_begin_rdrag)

        wx.EVT_LIST_BEGIN_LABEL_EDIT(
            table, wxid, self._on_list_begin_label_edit
        )

        wx.EVT_LIST_END_LABEL_EDIT(
            table, wxid, self._on_list_end_label_edit
        )

        # fixme: Bug[732104] indicates that this event does not get fired
        # in a virtual list control (it *does* get fired in a regular list
        # control 8^().
        wx.EVT_LIST_ITEM_DESELECTED(table, wxid, self._on_item_deselected)

        # Create the widget!
        self._create_widget(parent)

        # We use a dynamic handler instead of a static handler here, as we
        # don't want to react if the input is set in the constructor.
        self.on_trait_change(self._on_input_changed, 'input')

        return
Ejemplo n.º 4
0
 def __init__(self, parent, id, title):
     wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
                       wx.Size(450, 400))
     splitter1 = wx.SplitterWindow(self, -1, style=wx.SP_3D)
     splitter2 = wx.SplitterWindow(splitter1, -1, style=wx.SP_3D)
     self.dir = wx.GenericDirCtrl(splitter1,
                                  -1,
                                  dir='/home/',
                                  style=wx.DIRCTRL_DIR_ONLY)
     self.lc1 = wx.ListCtrl(splitter2, -1, style=wx.LC_LIST)
     self.lc2 = wx.ListCtrl(splitter2, -1, style=wx.LC_LIST)
     dt = MyTextDropTarget(self.lc2)
     self.lc2.SetDropTarget(dt)
     wx.EVT_LIST_BEGIN_DRAG(self, self.lc1.GetId(), self.OnDragInit)
     tree = self.dir.GetTreeCtrl()
     splitter2.SplitHorizontally(self.lc1, self.lc2)
     splitter1.SplitVertically(self.dir, splitter2)
     wx.EVT_TREE_SEL_CHANGED(self, tree.GetId(), self.OnSelect)
     self.OnSelect(0)
     self.Centre()
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=(800, 600))
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        pnl1 = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
        pnl2 = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
        pnl3 = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
        hbox.Add(pnl1, 1, wx.EXPAND | wx.ALL, 3)
        hbox.Add(pnl2, 1, wx.EXPAND | wx.ALL, 3)
        hbox.Add(pnl3, 1, wx.EXPAND | wx.ALL, 3)
        self.SetSize((400, 500))
        self.SetSizer(hbox)
        self.dir = wx.GenericDirCtrl(pnl1,
                                     -1,
                                     size=(200, 600),
                                     dir='/home/',
                                     style=wx.DIRCTRL_DIR_ONLY
                                     | wx.BORDER_RAISED)
        tree = self.dir.GetTreeCtrl()
        wx.EVT_TREE_SEL_CHANGED(self, tree.GetId(), self.OnSelect)
        self.lc1 = wx.ListCtrl(pnl2, -1, size=(200, 600), style=wx.LC_LIST)
        wx.EVT_LIST_BEGIN_DRAG(self, self.lc1.GetId(), self.OnDragInit)
        tree = self.dir.GetTreeCtrl()
        self.textKey = wx.StaticText(pnl3, -1, 'Total: ', (20, 60))
        self.textValue = wx.StaticText(pnl3, -1, 'Total: ', (20, 80))
        self.picNum = wx.TextCtrl(pnl3,
                                  -1,
                                  'Export Number', (80, 60),
                                  size=(160, 30))
        self.exportBtn = wx.Button(pnl3, -1, 'Generate', (250, 60))
        self.exportBtn.Bind(wx.EVT_BUTTON, self.export)
        self.file_name_key = wx.StaticText(pnl3, -1, 'Filename', (60, 120))
        self.file_name_value = wx.TextCtrl(pnl3,
                                           -1,
                                           'Custom Filename', (120, 120),
                                           size=(160, 30))

        self.OnSelect(0)
        self.Centre()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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
        self.sync_value(factory.adapter_name, 'adapter', 'from')

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

        if factory.editable:
            style |= wx.LC_EDIT_LABELS

        if factory.horizontal_lines:
            style |= wx.LC_HRULES

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

        if (factory.title == '') and (factory.title_name == ''):
            style |= wx.LC_NO_HEADER

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

        # Create the list control column:
        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_ITEM_RIGHT_CLICK(parent, id, self._right_clicked)
        wx.EVT_LIST_ITEM_ACTIVATED(parent, id, self._item_activated)
        wx.EVT_SIZE(control, self._size_modified)

        # Handle key events:
        wx.EVT_CHAR(control, self._key_pressed)

        # Handle mouse events:
        if 'edit' in factory.operations:
            wx.EVT_LEFT_DOWN(control, self._left_down)

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

        # Initialize the editor title:
        self.title = factory.title
        self.sync_value(factory.title_name, 'title', 'from')

        # 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_index,
                            'multi_selected_indices',
                            'both',
                            is_list=True)
        else:
            self.sync_value(factory.selected, 'selected', 'both')
            self.sync_value(factory.selected_index, 'selected_index', 'both')

        # Synchronize other interesting traits as necessary:
        self.sync_value(factory.activated, 'activated', 'to')
        self.sync_value(factory.activated_index, 'activated_index', 'to')

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

        # Make sure we listen for 'items' changes as well as complete list
        # replacements:
        self.context_object.on_trait_change(self.update_editor,
                                            self.extended_name + '_items',
                                            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')

        # Set the list control's tooltip:
        self.set_tooltip()
Ejemplo n.º 9
0
    def __init_ctrls(self, prnt):
        wx.Panel.__init__(self,
                          id=wxID_,
                          name=u'mainPanel',
                          parent=prnt,
                          size=wx.DefaultSize,
                          style=wx.TAB_TRAVERSAL)

        self.staticText1 = wx.StaticText(id=wxID_STATICTEXT1,
                                         label=_(u"Available:"),
                                         name='staticText1',
                                         parent=self,
                                         style=0)

        self.availableOperations = wx.ListCtrl(
            id=wxID_AVAILABLEOPERATIONS,
            name=u'availableOperations',
            parent=self,
            style=wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL)
        self.availableOperations.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
                                      self.stack_operation,
                                      id=wxID_AVAILABLEOPERATIONS)

        self.availableOperations.InsertColumn(0,
                                              '',
                                              format=wx.LIST_FORMAT_LEFT,
                                              width=-1)

        # add operations to list
        i = 0
        for op in sorted(operations.defs.keys()):
            self.availableOperations.InsertStringItem(i, op)
            i += 1

        # set vertical size
        h = self.availableOperations.GetItemRect(0)[-1]
        ops = self.availableOperations.GetItemCount()
        if wx.Platform == '__WXMSW__':
            h = (h * ops) + 6
        else:
            h = h * ops

        # set horizontal size
        longest = operations.get_longest_name_length()
        w = app.fontParams['size'] * longest

        scrollBarSize = wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
        Size = (w, h)

        self.availableOperations.SetMinSize(Size)
        self.availableOperations.SetColumnWidth(0, w - scrollBarSize)

        self.usedOperations = UsedOperations(wxID_USEDOPERATIONS,
                                             u'usedOperations', self, w,
                                             scrollBarSize)
        self.usedOperations.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                 self.__used_operations_listbox,
                                 id=wxID_USEDOPERATIONS)

        self.staticText2 = wx.StaticText(id=wxID_STATICTEXT2,
                                         label=_(u"Used:"),
                                         name='staticText2',
                                         parent=self,
                                         style=0)

        self.moveDown = wx.BitmapButton(bitmap=wx.Bitmap(
            utils.icon_path(u'down.png'), wx.BITMAP_TYPE_PNG),
                                        id=wxID_MOVEDOWN,
                                        name=u'moveDown',
                                        parent=self,
                                        style=wx.BU_AUTODRAW)
        self.moveDown.SetToolTipString(_(u"Move current operation down by 1"))
        self.moveDown.Bind(wx.EVT_BUTTON,
                           self.__move_down_button,
                           id=wxID_MOVEDOWN)

        self.moveUp = wx.BitmapButton(bitmap=wx.Bitmap(
            utils.icon_path(u'up.png'), wx.BITMAP_TYPE_PNG),
                                      id=wxID_MOVEUP,
                                      name=u'moveUp',
                                      parent=self,
                                      style=wx.BU_AUTODRAW)
        self.moveUp.SetToolTipString(_(u"Move current operation up by 1"))
        self.moveUp.Bind(wx.EVT_BUTTON, self.__move_up_button, id=wxID_MOVEUP)

        self.enableOperation = wx.ToggleButton(id=wxID_ENABLEOPERATION,
                                               label=_(u"Disable"),
                                               name=u'enableOperation',
                                               parent=self,
                                               style=wx.BU_EXACTFIT)
        self.enableOperation.SetToolTipString(
            _(u"Enable or Disable current operation"))
        self.enableOperation.SetValue(False)
        self.enableOperation.Bind(wx.EVT_TOGGLEBUTTON,
                                  self.__operation_toggle_btn,
                                  id=wxID_ENABLEOPERATION)

        self.deleteOperations = wx.Choice(
            choices=[_(u"Delete"), _(u"Delete All")],
            id=wxID_DELETEOPERATIONS,
            name=u'actions',
            parent=self)
        self.deleteOperations.SetSelection(0)
        self.deleteOperations.SetToolTipString(_(u"Delete operations"))
        self.deleteOperations.Bind(wx.EVT_CHOICE,
                                   self.__actions_choice,
                                   id=wxID_DELETEOPERATIONS)

        self.resetOperationButton = wx.Button(id=wxID_RESETOPERATIONBUTTON,
                                              label=_(u"Reset"),
                                              name=u'resetOperationButton',
                                              parent=self,
                                              style=wx.BU_EXACTFIT)
        self.resetOperationButton.SetToolTipString(
            _(u"Reset the current operation"))
        self.resetOperationButton.Bind(wx.EVT_BUTTON,
                                       self.__reset_operation,
                                       id=wxID_RESETOPERATIONBUTTON)

        self.staticText3 = wx.StaticText(id=wxID_STATICTEXT3,
                                         label=_(u"Order:"),
                                         name='staticText3',
                                         parent=self,
                                         style=0)

        self.applyExtension = wx.CheckBox(id=wxID_APPLYEXTENSION,
                                          label=_(u"extension"),
                                          name=u'applyExtension',
                                          parent=self,
                                          style=0)
        self.applyExtension.SetValue(False)
        self.applyExtension.Bind(wx.EVT_CHECKBOX,
                                 self.__set_operations_apply,
                                 id=wxID_APPLYEXTENSION)

        self.applyName = wx.CheckBox(id=wxID_APPLYNAME,
                                     label=_(u"name"),
                                     name='applyName',
                                     parent=self,
                                     style=0)
        self.applyName.SetValue(True)
        self.applyName.Bind(wx.EVT_CHECKBOX,
                            self.__set_operations_apply,
                            id=wxID_APPLYNAME)

        self.staticText4 = wx.StaticText(id=wxID_STATICTEXT4,
                                         label=_(u"Apply to:"),
                                         name='staticText4',
                                         parent=self,
                                         style=0)

        self.staticText5 = IntroTextPanel(self, wxID_STATICTEXT5)

        dt = OperationDropTarget(self.usedOperations)
        self.usedOperations.SetDropTarget(dt)

        wx.EVT_LIST_BEGIN_DRAG(self.availableOperations,
                               self.availableOperations.GetId(),
                               self.__available_drag_init)
        wx.EVT_LIST_BEGIN_DRAG(self.usedOperations,
                               self.usedOperations.GetId(),
                               self.__used_drag_init)