Commit 0dba500c57301d2cdaf7172190bbe20d662ee1c2
1 parent
696200d1
Exists in
master
Listctrl events working with wxpython4
Showing
2 changed files
with
29 additions
and
20 deletions
Show diff stats
invesalius/gui/data_notebook.py
| @@ -41,6 +41,7 @@ import invesalius.constants as const | @@ -41,6 +41,7 @@ import invesalius.constants as const | ||
| 41 | import invesalius.data.slice_ as slice_ | 41 | import invesalius.data.slice_ as slice_ |
| 42 | import invesalius.gui.dialogs as dlg | 42 | import invesalius.gui.dialogs as dlg |
| 43 | import invesalius.gui.widgets.listctrl as listmix | 43 | import invesalius.gui.widgets.listctrl as listmix |
| 44 | +# import wx.lib.mixins.listctrl as listmix | ||
| 44 | import invesalius.utils as ul | 45 | import invesalius.utils as ul |
| 45 | 46 | ||
| 46 | 47 | ||
| @@ -491,7 +492,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -491,7 +492,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
| 491 | evt.Skip() | 492 | evt.Skip() |
| 492 | 493 | ||
| 493 | def OnItemActivated(self, evt): | 494 | def OnItemActivated(self, evt): |
| 494 | - self.ToggleItem(evt.m_itemIndex) | 495 | + self.ToggleItem(evt.Index) |
| 495 | 496 | ||
| 496 | def OnCheckItem(self, index, flag): | 497 | def OnCheckItem(self, index, flag): |
| 497 | if flag: | 498 | if flag: |
| @@ -783,7 +784,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -783,7 +784,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
| 783 | # Otherwise the parent's method will be overwritten and other | 784 | # Otherwise the parent's method will be overwritten and other |
| 784 | # things will stop working, e.g.: OnCheckItem | 785 | # things will stop working, e.g.: OnCheckItem |
| 785 | 786 | ||
| 786 | - last_surface_index = evt.m_itemIndex | 787 | + last_surface_index = evt.Index |
| 787 | Publisher.sendMessage('Change surface selected', | 788 | Publisher.sendMessage('Change surface selected', |
| 788 | last_surface_index) | 789 | last_surface_index) |
| 789 | evt.Skip() | 790 | evt.Skip() |
| @@ -840,7 +841,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -840,7 +841,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
| 840 | evt.Skip() | 841 | evt.Skip() |
| 841 | 842 | ||
| 842 | def OnItemActivated(self, evt): | 843 | def OnItemActivated(self, evt): |
| 843 | - self.ToggleItem(evt.m_itemIndex) | 844 | + self.ToggleItem(evt.Index) |
| 844 | evt.Skip() | 845 | evt.Skip() |
| 845 | 846 | ||
| 846 | def OnCheckItem(self, index, flag): | 847 | def OnCheckItem(self, index, flag): |
| @@ -1055,7 +1056,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -1055,7 +1056,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
| 1055 | # Otherwise the parent's method will be overwritten and other | 1056 | # Otherwise the parent's method will be overwritten and other |
| 1056 | # things will stop working, e.g.: OnCheckItem | 1057 | # things will stop working, e.g.: OnCheckItem |
| 1057 | 1058 | ||
| 1058 | - last_index = evt.m_itemIndex | 1059 | + last_index = evt.Index |
| 1059 | Publisher.sendMessage('Change measurement selected', | 1060 | Publisher.sendMessage('Change measurement selected', |
| 1060 | last_index) | 1061 | last_index) |
| 1061 | evt.Skip() | 1062 | evt.Skip() |
| @@ -1113,7 +1114,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -1113,7 +1114,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
| 1113 | evt.Skip() | 1114 | evt.Skip() |
| 1114 | 1115 | ||
| 1115 | def OnItemActivated(self, evt): | 1116 | def OnItemActivated(self, evt): |
| 1116 | - self.ToggleItem(evt.m_itemIndex) | 1117 | + self.ToggleItem(evt.Index) |
| 1117 | evt.Skip() | 1118 | evt.Skip() |
| 1118 | 1119 | ||
| 1119 | 1120 | ||
| @@ -1314,7 +1315,7 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -1314,7 +1315,7 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
| 1314 | 1315 | ||
| 1315 | 1316 | ||
| 1316 | def OnItemActivated(self, evt): | 1317 | def OnItemActivated(self, evt): |
| 1317 | - self.ToggleItem(evt.m_itemIndex) | 1318 | + self.ToggleItem(evt.Index) |
| 1318 | 1319 | ||
| 1319 | def OnCheckItem(self, index, flag): | 1320 | def OnCheckItem(self, index, flag): |
| 1320 | # TODO: use pubsub to communicate to models | 1321 | # TODO: use pubsub to communicate to models |
invesalius/gui/widgets/listctrl.py
| @@ -644,19 +644,23 @@ class TextEditMixin: | @@ -644,19 +644,23 @@ class TextEditMixin: | ||
| 644 | 644 | ||
| 645 | # give the derived class a chance to Allow/Veto this edit. | 645 | # give the derived class a chance to Allow/Veto this edit. |
| 646 | evt = wx.ListEvent(wx.wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, self.GetId()) | 646 | evt = wx.ListEvent(wx.wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, self.GetId()) |
| 647 | - evt.m_itemIndex = row | ||
| 648 | - evt.m_col = col | 647 | + try: |
| 648 | + evt.SetIndex(row) | ||
| 649 | + evt.SetColumn(col) | ||
| 650 | + except AttributeError: | ||
| 651 | + evt.m_itemIndex = row | ||
| 652 | + evt.m_col = col | ||
| 649 | item = self.GetItem(row, col) | 653 | item = self.GetItem(row, col) |
| 650 | - evt.m_item.SetId(item.GetId()) | ||
| 651 | - evt.m_item.SetColumn(item.GetColumn()) | ||
| 652 | - evt.m_item.SetData(item.GetData()) | ||
| 653 | - evt.m_item.SetText(item.GetText()) | 654 | + evt.Item.SetId(item.GetId()) |
| 655 | + evt.Item.SetColumn(item.GetColumn()) | ||
| 656 | + evt.Item.SetData(item.GetData()) | ||
| 657 | + evt.Item.SetText(item.GetText()) | ||
| 654 | ret = self.GetEventHandler().ProcessEvent(evt) | 658 | ret = self.GetEventHandler().ProcessEvent(evt) |
| 655 | if ret and not evt.IsAllowed(): | 659 | if ret and not evt.IsAllowed(): |
| 656 | return # user code doesn't allow the edit. | 660 | return # user code doesn't allow the edit. |
| 657 | 661 | ||
| 658 | - if self.GetColumn(col).m_format != self.col_style: | ||
| 659 | - self.make_editor(self.GetColumn(col).m_format) | 662 | + if self.GetColumn(col).Align != self.col_style: |
| 663 | + self.make_editor(self.GetColumn(col).Align) | ||
| 660 | 664 | ||
| 661 | x0 = self.col_locs[col] | 665 | x0 = self.col_locs[col] |
| 662 | x1 = self.col_locs[col+1] - x0 | 666 | x1 = self.col_locs[col+1] - x0 |
| @@ -717,13 +721,17 @@ class TextEditMixin: | @@ -717,13 +721,17 @@ class TextEditMixin: | ||
| 717 | # Event can be vetoed. It doesn't has SetEditCanceled(), what would | 721 | # Event can be vetoed. It doesn't has SetEditCanceled(), what would |
| 718 | # require passing extra argument to CloseEditor() | 722 | # require passing extra argument to CloseEditor() |
| 719 | evt = wx.ListEvent(wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT, self.GetId()) | 723 | evt = wx.ListEvent(wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT, self.GetId()) |
| 720 | - evt.m_itemIndex = self.curRow | ||
| 721 | - evt.m_col = self.curCol | 724 | + try: |
| 725 | + evt.SetIndex(self.curRow) | ||
| 726 | + evt.SetColumn(self.curCol) | ||
| 727 | + except AttributeError: | ||
| 728 | + evt.m_itemIndex = self.curRow | ||
| 729 | + evt.m_col = self.curCol | ||
| 722 | item = self.GetItem(self.curRow, self.curCol) | 730 | item = self.GetItem(self.curRow, self.curCol) |
| 723 | - evt.m_item.SetId(item.GetId()) | ||
| 724 | - evt.m_item.SetColumn(item.GetColumn()) | ||
| 725 | - evt.m_item.SetData(item.GetData()) | ||
| 726 | - evt.m_item.SetText(text) #should be empty string if editor was canceled | 731 | + evt.Item.SetId(item.GetId()) |
| 732 | + evt.Item.SetColumn(item.GetColumn()) | ||
| 733 | + evt.Item.SetData(item.GetData()) | ||
| 734 | + evt.Item.SetText(text) #should be empty string if editor was canceled | ||
| 727 | ret = self.GetEventHandler().ProcessEvent(evt) | 735 | ret = self.GetEventHandler().ProcessEvent(evt) |
| 728 | if not ret or evt.IsAllowed(): | 736 | if not ret or evt.IsAllowed(): |
| 729 | if self.IsVirtual(): | 737 | if self.IsVirtual(): |