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
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()
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()
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()
def __init__(self, mainwindow, parent): super(PlaylistWidget, self).__init__(parent, -1) self._mw=mainwindow self._data=[] self._master=[] self.ignoredirty=False self.dirty=False # main box sizer vbs=wx.BoxSizer(wx.VERTICAL) # horizontal sizer for the main contents hbs=wx.BoxSizer(wx.HORIZONTAL) # the list box self._item_list=gizmos.EditableListBox(self, -1, 'Play Lists:', style=gizmos.EL_ALLOW_NEW|\ gizmos.EL_ALLOW_EDIT|\ gizmos.EL_ALLOW_DELETE) self._item_list.GetUpButton().Show(False) self._item_list.GetDownButton().Show(False) self._item_list_w=self._item_list.GetListCtrl() hbs.Add(self._item_list, 1, wx.EXPAND|wx.ALL, border=5) hbs.Add(wx.StaticLine(self, -1, style=wx.LI_VERTICAL), 0, wx.EXPAND|wx.ALL, 5) # the detailed panel hbs1=wx.BoxSizer(wx.HORIZONTAL) # the playlist _vbs1=wx.BoxSizer(wx.VERTICAL) self._pl_list=gizmos.EditableListBox(self, -1, "Play List Content:", style=gizmos.EL_ALLOW_DELETE) self._pl_list_w=self._pl_list.GetListCtrl() _vbs1.Add(self._pl_list, 1, wx.EXPAND, 0) self._count_lbl=wx.StaticText(self, -1, '') _vbs1.Add(self._count_lbl, 0, wx.EXPAND|wx.TOP, 5) hbs1.Add(_vbs1, 1, wx.EXPAND|wx.ALL, 5) _add_btn=wx.Button(self, -1, '<-Add') hbs1.Add(_add_btn, 0, wx.ALL, 5) self._master_list=gizmos.EditableListBox(self, -1, 'Available Songs:', style=0) self._master_list_w=self._master_list.GetListCtrl() self._master_list.GetUpButton().Show(False) self._master_list.GetDownButton().Show(False) hbs1.Add(self._master_list, 1, wx.EXPAND|wx.ALL, 5) hbs.Add(hbs1, 3, wx.EXPAND|wx.ALL, 5) # the bottom buttons hbs1=wx.BoxSizer(wx.HORIZONTAL) self._save_btn=wx.Button(self, wx.ID_SAVE) self._revert_btn=wx.Button(self, wx.ID_REVERT_TO_SAVED) help_btn=wx.Button(self, wx.ID_HELP) hbs1.Add(self._save_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(help_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(self._revert_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) # all done vbs.Add(hbs, 1, wx.EXPAND|wx.ALL, 5) vbs.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5) vbs.Add(hbs1, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) # event handlers wx.EVT_LIST_ITEM_SELECTED(self._item_list, self._item_list_w.GetId(), self.OnPlaylistSelected) wx.EVT_LIST_BEGIN_LABEL_EDIT(self._item_list, self._item_list_w.GetId(), self.OnStartLabelChanged) wx.EVT_LIST_END_LABEL_EDIT(self._item_list, self._item_list_w.GetId(), self.OnLabelChanged) wx.EVT_BUTTON(self, _add_btn.GetId(), self.OnAdd2Playlist) wx.EVT_BUTTON(self, self._save_btn.GetId(), self.OnSave) wx.EVT_BUTTON(self, self._revert_btn.GetId(), self.OnRevert) wx.EVT_LIST_DELETE_ITEM(self._item_list, self._item_list_w.GetId(), self.OnMakeDirty) wx.EVT_LIST_DELETE_ITEM(self._pl_list, self._pl_list_w.GetId(), self.OnMakeDirty) wx.EVT_BUTTON(self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid(helpids.ID_TAB_PLAYLIST)) wx.EVT_BUTTON(self._pl_list, self._pl_list.GetUpButton().GetId(), self._OnUpDown) wx.EVT_BUTTON(self._pl_list, self._pl_list.GetDownButton().GetId(), self._OnUpDown) # populate data self._populate() # turn on dirty flag self.setdirty(False)
def __init__(self, parent, ID, mainControl, wikiWordFilter): EnhancedListControl.__init__(self, parent, ID, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_NO_HEADER | wx.LC_EDIT_LABELS) TimePresentationBase.__init__(self, mainControl, wikiWordFilter) self.InsertColumn(0, u"", width=1) # date self.InsertColumn(1, u"", width=1) # number of wiki words # Now gather some information self.InsertStringItem(0, u"1") self.itemHeight = self.GetItemRect(0).GetHeight() self.popupShiftX = 20 self.popupShiftY = self.itemHeight - 2 self.stdFont = self.GetFont() self.boldFont = cloneFont(self.stdFont) # # Clone font # self.boldFont = wx.Font(self.stdFont.GetPointSize(), # self.stdFont.GetFamily(), self.stdFont.GetStyle(), # self.stdFont.GetWeight(), self.stdFont.GetUnderlined(), # self.stdFont.GetFaceName(), self.stdFont.GetDefaultEncoding()) self.boldFont.SetWeight(wx.FONTWEIGHT_BOLD) self.stepDays = 1 self.DeleteAllItems() self.clientHeight = self.GetClientSizeTuple()[1] self.visibleItemCount = (self.clientHeight - 6) // self.itemHeight self.contextMenuWikiWords = IdRecycler() # {menuid: wiki word to go to} self.listContent = [] # Tuples (wx.DateTime day, <number of wikiwords for day>) self.listMaxWordCount = 0 # max number of wikiwords over entries in listContent self.wikiWordListPopup = None self.firstResize = True # Hack # self.topDay = None # currTime - wx.TimeSpan_Days(self.visibleItemCount - 1) # Sets which day should be shown at which index self.fixedItemDay = None self.fixedItemIndex = 0 self.minMaxDayCache = None wx.EVT_KEY_DOWN(self, self.OnKeyDown) # wx.EVT_SIZE(self, self.OnSize) # wx.EVT_ERASE_BACKGROUND(self, self.OnEraseBg) wx.EVT_CONTEXT_MENU(self, self.OnContextMenu) # wx.EVT_MOTION(self, self.OnMouseMotion) wx.EVT_LIST_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated) wx.EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected) wx.EVT_LIST_BEGIN_LABEL_EDIT(self, self.GetId(), self.OnBeginLabelEdit) wx.EVT_LIST_END_LABEL_EDIT(self, self.GetId(), self.OnEndLabelEdit) wx.EVT_MENU(self, GUI_ID.CMD_CHECKBOX_TIMELINE_SHOW_EMPTY_DAYS, self.OnCmdCheckShowEmptyDays) wx.EVT_UPDATE_UI(self, GUI_ID.CMD_CHECKBOX_TIMELINE_SHOW_EMPTY_DAYS, self.OnCmdCheckUpdateEmptyDays) wx.EVT_MENU(self, GUI_ID.CMD_CHECKBOX_TIMELINE_DATE_ASCENDING, self.OnCmdCheckDateAscending) wx.EVT_UPDATE_UI(self, GUI_ID.CMD_CHECKBOX_TIMELINE_DATE_ASCENDING, self.OnCmdCheckUpdateDateAscending)