X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/23a023642cc8975a88ae02953a15234c4f4d1ee5..68fc5c8025e38b9d827383fbfe7ce509ae331c1f:/wxPython/wx/lib/mixins/listctrl.py diff --git a/wxPython/wx/lib/mixins/listctrl.py b/wxPython/wx/lib/mixins/listctrl.py index 71504759da..921e250415 100644 --- a/wxPython/wx/lib/mixins/listctrl.py +++ b/wxPython/wx/lib/mixins/listctrl.py @@ -115,9 +115,10 @@ class ColumnSorterMixin: def __OnColClick(self, evt): oldCol = self._col self._col = col = evt.GetColumn() - self._colSortFlag[col] = not self._colSortFlag[col] + self._colSortFlag[col] = int(not self._colSortFlag[col]) self.GetListCtrl().SortItems(self.GetColumnSorter()) - self.__updateImages(oldCol) + if wx.Platform != "__WXMAC__" or wx.SystemOptions.GetOptionInt("mac.listctrl.always_use_generic") == 1: + self.__updateImages(oldCol) evt.Skip() @@ -248,6 +249,9 @@ class ListCtrlAutoWidthMixin: if not self: # avoid a PyDeadObject error return + + if self.GetSize().height < 32: + return # avoid an endless update bug when the height is small. numCols = self.GetColumnCount() if numCols == 0: return # Nothing to resize. @@ -424,7 +428,6 @@ class TextEditMixin: def make_editor(self, col_style=wx.LIST_FORMAT_LEFT): - editor = wx.PreTextCtrl() style =wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB|wx.TE_RICH2 style |= {wx.LIST_FORMAT_LEFT: wx.TE_LEFT, @@ -432,7 +435,7 @@ class TextEditMixin: wx.LIST_FORMAT_CENTRE : wx.TE_CENTRE }[col_style] - editor.Create(self, -1, style=style) + editor = wx.TextCtrl(self, -1, style=style) editor.SetBackgroundColour(self.editorBgColour) editor.SetForegroundColour(self.editorFgColour) font = self.GetFont() @@ -442,6 +445,8 @@ class TextEditMixin: self.curCol = 0 editor.Hide() + if hasattr(self, 'editor'): + self.editor.Destroy() self.editor = editor self.col_style = col_style @@ -522,6 +527,19 @@ class TextEditMixin: def OpenEditor(self, col, row): ''' Opens an editor at the current position. ''' + # give the derived class a chance to Allow/Veto this edit. + evt = wx.ListEvent(wx.wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, self.GetId()) + evt.m_itemIndex = row + evt.m_col = col + item = self.GetItem(row, col) + evt.m_item.SetId(item.GetId()) + evt.m_item.SetColumn(item.GetColumn()) + evt.m_item.SetData(item.GetData()) + evt.m_item.SetText(item.GetText()) + ret = self.GetEventHandler().ProcessEvent(evt) + if ret and not evt.IsAllowed(): + return # user code doesn't allow the edit. + if self.GetColumn(col).m_format != self.col_style: self.make_editor(self.GetColumn(col).m_format) @@ -574,6 +592,8 @@ class TextEditMixin: # it is binded to wx.EVT_KILL_FOCUS. Can it be avoided? (MW) def CloseEditor(self, evt=None): ''' Close the editor and save the new value to the ListCtrl. ''' + if not self.editor.IsShown(): + return text = self.editor.GetValue() self.editor.Hide() self.SetFocus() @@ -686,12 +706,17 @@ class CheckListCtrlMixin: """ This is a mixin for ListCtrl which add a checkbox in the first column of each row. It is inspired by limodou's CheckList.py(which - can be got from his NewEdit) and improved: + can be got from his NewEdit) and improved: + - You can just use InsertStringItem() to insert new items; - - Once a checkbox is checked/unchecked, the corresponding item is not - selected; + + - Once a checkbox is checked/unchecked, the corresponding item + is not selected; + - You can use SetItemData() and GetItemData(); - - Interfaces are changed to OnCheckItem(), IsChecked(), CheckItem(). + + - Interfaces are changed to OnCheckItem(), IsChecked(), + CheckItem(). You should not set a imagelist for the ListCtrl once this mixin is used. """