Commit 469c5273d6f7c808e42898a538541b7a25d6dd34
1 parent
a657e6bb
Exists in
threshold_history
ENH: the undo and redo menu are saying what will be undone and redone
Showing
2 changed files
with
47 additions
and
36 deletions
Show diff stats
invesalius/data/mask.py
| @@ -34,6 +34,7 @@ from wx.lib.pubsub import pub as Publisher | @@ -34,6 +34,7 @@ from wx.lib.pubsub import pub as Publisher | ||
| 34 | class ThresholdHistoryNode(object): | 34 | class ThresholdHistoryNode(object): |
| 35 | def __init__(self, mask): | 35 | def __init__(self, mask): |
| 36 | self.threshold = mask.threshold_range | 36 | self.threshold = mask.threshold_range |
| 37 | + self.descr = _(u'Set threshold') | ||
| 37 | 38 | ||
| 38 | if mask.was_edited: | 39 | if mask.was_edited: |
| 39 | self.array_file = tempfile.mktemp() | 40 | self.array_file = tempfile.mktemp() |
| @@ -59,6 +60,7 @@ class EditionHistoryNode(object): | @@ -59,6 +60,7 @@ class EditionHistoryNode(object): | ||
| 59 | self.filename = tempfile.mktemp(suffix='.npy') | 60 | self.filename = tempfile.mktemp(suffix='.npy') |
| 60 | self.clean = clean | 61 | self.clean = clean |
| 61 | self.threshold = threshold | 62 | self.threshold = threshold |
| 63 | + self.descr = _(u'Edition at %s' % self.orientation) | ||
| 62 | 64 | ||
| 63 | self._save_array(array) | 65 | self._save_array(array) |
| 64 | 66 | ||
| @@ -96,8 +98,8 @@ class EditionHistory(object): | @@ -96,8 +98,8 @@ class EditionHistory(object): | ||
| 96 | self.index = -1 | 98 | self.index = -1 |
| 97 | self.size = size * 2 | 99 | self.size = size * 2 |
| 98 | 100 | ||
| 99 | - Publisher.sendMessage("Enable undo", False) | ||
| 100 | - Publisher.sendMessage("Enable redo", False) | 101 | + Publisher.sendMessage("Disable undo") |
| 102 | + Publisher.sendMessage("Disable redo") | ||
| 101 | 103 | ||
| 102 | def new_node(self, index, orientation, array, p_array, clean, threshold): | 104 | def new_node(self, index, orientation, array, p_array, clean, threshold): |
| 103 | # Saving the previous state, used to undo/redo correctly. | 105 | # Saving the previous state, used to undo/redo correctly. |
| @@ -123,8 +125,8 @@ class EditionHistory(object): | @@ -123,8 +125,8 @@ class EditionHistory(object): | ||
| 123 | self.index += 1 | 125 | self.index += 1 |
| 124 | 126 | ||
| 125 | print "INDEX", self.index, len(self.history), self.history | 127 | print "INDEX", self.index, len(self.history), self.history |
| 126 | - Publisher.sendMessage("Enable undo", True) | ||
| 127 | - Publisher.sendMessage("Enable redo", False) | 128 | + Publisher.sendMessage("Enable undo", self.history[self.index - 1].descr) |
| 129 | + Publisher.sendMessage("Disable redo") | ||
| 128 | 130 | ||
| 129 | def undo(self, mask, actual_slices=None): | 131 | def undo(self, mask, actual_slices=None): |
| 130 | h = self.history | 132 | h = self.history |
| @@ -143,14 +145,14 @@ class EditionHistory(object): | @@ -143,14 +145,14 @@ class EditionHistory(object): | ||
| 143 | self.index -= 1 | 145 | self.index -= 1 |
| 144 | h[self.index].commit_history(mask) | 146 | h[self.index].commit_history(mask) |
| 145 | self._reload_slice(self.index) | 147 | self._reload_slice(self.index) |
| 146 | - Publisher.sendMessage("Enable redo", True) | 148 | + Publisher.sendMessage("Enable redo", h[self.index + 1].descr) |
| 147 | else: | 149 | else: |
| 148 | self.index -= 1 | 150 | self.index -= 1 |
| 149 | h[self.index].commit_history(mask) | 151 | h[self.index].commit_history(mask) |
| 150 | - Publisher.sendMessage("Enable redo", True) | 152 | + Publisher.sendMessage("Enable redo", h[self.index + 1].descr) |
| 151 | 153 | ||
| 152 | if self.index == 0: | 154 | if self.index == 0: |
| 153 | - Publisher.sendMessage("Enable undo", False) | 155 | + Publisher.sendMessage("Disable undo") |
| 154 | #print "AT", self.index, len(self.history), self.history[self.index].filename | 156 | #print "AT", self.index, len(self.history), self.history[self.index].filename |
| 155 | 157 | ||
| 156 | def redo(self, mask, actual_slices=None): | 158 | def redo(self, mask, actual_slices=None): |
| @@ -171,14 +173,14 @@ class EditionHistory(object): | @@ -171,14 +173,14 @@ class EditionHistory(object): | ||
| 171 | self.index += 1 | 173 | self.index += 1 |
| 172 | h[self.index].commit_history(mask) | 174 | h[self.index].commit_history(mask) |
| 173 | self._reload_slice(self.index) | 175 | self._reload_slice(self.index) |
| 174 | - Publisher.sendMessage("Enable undo", True) | 176 | + Publisher.sendMessage("Enable undo", h[self.index - 1].descr) |
| 175 | else: | 177 | else: |
| 176 | self.index += 1 | 178 | self.index += 1 |
| 177 | h[self.index].commit_history(mask) | 179 | h[self.index].commit_history(mask) |
| 178 | - Publisher.sendMessage("Enable undo", True) | 180 | + Publisher.sendMessage("Enable undo", h[self.index - 1].descr) |
| 179 | 181 | ||
| 180 | if self.index == len(h) - 1: | 182 | if self.index == len(h) - 1: |
| 181 | - Publisher.sendMessage("Enable redo", False) | 183 | + Publisher.sendMessage("Disable redo") |
| 182 | #print "AT", self.index, len(h), h[self.index].filename | 184 | #print "AT", self.index, len(h), h[self.index].filename |
| 183 | 185 | ||
| 184 | def _reload_slice(self, index): | 186 | def _reload_slice(self, index): |
| @@ -186,8 +188,8 @@ class EditionHistory(object): | @@ -186,8 +188,8 @@ class EditionHistory(object): | ||
| 186 | self.history[index].index) | 188 | self.history[index].index) |
| 187 | 189 | ||
| 188 | def _config_undo_redo(self, visible): | 190 | def _config_undo_redo(self, visible): |
| 189 | - v_undo = False | ||
| 190 | - v_redo = False | 191 | + v_undo = "Disable Undo" |
| 192 | + v_redo = "Disable Redo" | ||
| 191 | 193 | ||
| 192 | if self.history and visible: | 194 | if self.history and visible: |
| 193 | v_undo = True | 195 | v_undo = True |
| @@ -197,14 +199,14 @@ class EditionHistory(object): | @@ -197,14 +199,14 @@ class EditionHistory(object): | ||
| 197 | elif self.index == len(self.history) - 1: | 199 | elif self.index == len(self.history) - 1: |
| 198 | v_redo = False | 200 | v_redo = False |
| 199 | 201 | ||
| 200 | - Publisher.sendMessage("Enable undo", v_undo) | ||
| 201 | - Publisher.sendMessage("Enable redo", v_redo) | 202 | + Publisher.sendMessage(v_undo) |
| 203 | + Publisher.sendMessage(v_redo) | ||
| 202 | 204 | ||
| 203 | def clear_history(self): | 205 | def clear_history(self): |
| 204 | self.history = [] | 206 | self.history = [] |
| 205 | self.index = -1 | 207 | self.index = -1 |
| 206 | - Publisher.sendMessage("Enable undo", False) | ||
| 207 | - Publisher.sendMessage("Enable redo", False) | 208 | + Publisher.sendMessage("Disable undo") |
| 209 | + Publisher.sendMessage("Disable redo") | ||
| 208 | 210 | ||
| 209 | 211 | ||
| 210 | class Mask(): | 212 | class Mask(): |
invesalius/gui/frame.py
| @@ -496,7 +496,9 @@ class MenuBar(wx.MenuBar): | @@ -496,7 +496,9 @@ class MenuBar(wx.MenuBar): | ||
| 496 | sub = Publisher.subscribe | 496 | sub = Publisher.subscribe |
| 497 | sub(self.OnEnableState, "Enable state project") | 497 | sub(self.OnEnableState, "Enable state project") |
| 498 | sub(self.OnEnableUndo, "Enable undo") | 498 | sub(self.OnEnableUndo, "Enable undo") |
| 499 | + sub(self.OnDisableUndo, "Disable undo") | ||
| 499 | sub(self.OnEnableRedo, "Enable redo") | 500 | sub(self.OnEnableRedo, "Enable redo") |
| 501 | + sub(self.OnDisableRedo, "Disable redo") | ||
| 500 | 502 | ||
| 501 | def __init_items(self): | 503 | def __init_items(self): |
| 502 | """ | 504 | """ |
| @@ -546,8 +548,8 @@ class MenuBar(wx.MenuBar): | @@ -546,8 +548,8 @@ class MenuBar(wx.MenuBar): | ||
| 546 | file_edit = wx.Menu() | 548 | file_edit = wx.Menu() |
| 547 | file_edit.AppendMenu(wx.NewId(), _('Flip'), flip_menu) | 549 | file_edit.AppendMenu(wx.NewId(), _('Flip'), flip_menu) |
| 548 | file_edit.AppendMenu(wx.NewId(), _('Swap axes'), swap_axes_menu) | 550 | file_edit.AppendMenu(wx.NewId(), _('Swap axes'), swap_axes_menu) |
| 549 | - file_edit.Append(wx.ID_UNDO, "Undo\tCtrl+Z").Enable(False) | ||
| 550 | - file_edit.Append(wx.ID_REDO, "Redo\tCtrl+Y").Enable(False) | 551 | + file_edit.Append(wx.ID_UNDO, _(u"Undo\tCtrl+Z")).Enable(False) |
| 552 | + file_edit.Append(wx.ID_REDO, _(u"Redo\tCtrl+Y")).Enable(False) | ||
| 551 | #app(const.ID_EDIT_LIST, "Show Undo List...") | 553 | #app(const.ID_EDIT_LIST, "Show Undo List...") |
| 552 | ################################################################# | 554 | ################################################################# |
| 553 | 555 | ||
| @@ -630,18 +632,22 @@ class MenuBar(wx.MenuBar): | @@ -630,18 +632,22 @@ class MenuBar(wx.MenuBar): | ||
| 630 | self.Enable(item, True) | 632 | self.Enable(item, True) |
| 631 | 633 | ||
| 632 | def OnEnableUndo(self, pubsub_evt): | 634 | def OnEnableUndo(self, pubsub_evt): |
| 633 | - value = pubsub_evt.data | ||
| 634 | - if value: | ||
| 635 | - self.FindItemById(wx.ID_UNDO).Enable(True) | ||
| 636 | - else: | ||
| 637 | - self.FindItemById(wx.ID_UNDO).Enable(False) | 635 | + descr = pubsub_evt.data |
| 636 | + self.FindItemById(wx.ID_UNDO).Enable(True) | ||
| 637 | + self.FindItemById(wx.ID_UNDO).SetItemLabel(_(u"Undo: %s \tCtrl+Z" % descr)) | ||
| 638 | + | ||
| 639 | + def OnDisableUndo(self, pubsub_evt): | ||
| 640 | + self.FindItemById(wx.ID_UNDO).Enable(False) | ||
| 641 | + self.FindItemById(wx.ID_UNDO).SetItemLabel(_(u"Undo:\tCtrl+Z")) | ||
| 638 | 642 | ||
| 639 | def OnEnableRedo(self, pubsub_evt): | 643 | def OnEnableRedo(self, pubsub_evt): |
| 640 | - value = pubsub_evt.data | ||
| 641 | - if value: | ||
| 642 | - self.FindItemById(wx.ID_REDO).Enable(True) | ||
| 643 | - else: | ||
| 644 | - self.FindItemById(wx.ID_REDO).Enable(False) | 644 | + descr = pubsub_evt.data |
| 645 | + self.FindItemById(wx.ID_REDO).Enable(True) | ||
| 646 | + self.FindItemById(wx.ID_REDO).SetItemLabel(_(u"Redo: %s \tCtrl+Y" % descr)) | ||
| 647 | + | ||
| 648 | + def OnDisableRedo(self, pubsub_evt): | ||
| 649 | + self.FindItemById(wx.ID_REDO).Enable(False) | ||
| 650 | + self.FindItemById(wx.ID_REDO).SetItemLabel(_(u"Redo:\tCtrl+Y")) | ||
| 645 | # ------------------------------------------------------------------ | 651 | # ------------------------------------------------------------------ |
| 646 | # ------------------------------------------------------------------ | 652 | # ------------------------------------------------------------------ |
| 647 | # ------------------------------------------------------------------ | 653 | # ------------------------------------------------------------------ |
| @@ -1464,7 +1470,10 @@ class HistoryToolBar(wx.ToolBar): | @@ -1464,7 +1470,10 @@ class HistoryToolBar(wx.ToolBar): | ||
| 1464 | #sub(self._SetLayoutWithTask, "Set layout button data only") | 1470 | #sub(self._SetLayoutWithTask, "Set layout button data only") |
| 1465 | #sub(self._SetLayoutWithoutTask, "Set layout button full") | 1471 | #sub(self._SetLayoutWithoutTask, "Set layout button full") |
| 1466 | sub(self.OnEnableUndo, "Enable undo") | 1472 | sub(self.OnEnableUndo, "Enable undo") |
| 1473 | + sub(self.OnDisableUndo, "Disable undo") | ||
| 1474 | + | ||
| 1467 | sub(self.OnEnableRedo, "Enable redo") | 1475 | sub(self.OnEnableRedo, "Enable redo") |
| 1476 | + sub(self.OnDisableRedo, "Disable redo") | ||
| 1468 | 1477 | ||
| 1469 | def __bind_events_wx(self): | 1478 | def __bind_events_wx(self): |
| 1470 | """ | 1479 | """ |
| @@ -1582,14 +1591,14 @@ class HistoryToolBar(wx.ToolBar): | @@ -1582,14 +1591,14 @@ class HistoryToolBar(wx.ToolBar): | ||
| 1582 | 1591 | ||
| 1583 | def OnEnableUndo(self, pubsub_evt): | 1592 | def OnEnableUndo(self, pubsub_evt): |
| 1584 | value = pubsub_evt.data | 1593 | value = pubsub_evt.data |
| 1585 | - if value: | ||
| 1586 | - self.EnableTool(wx.ID_UNDO, True) | ||
| 1587 | - else: | ||
| 1588 | - self.EnableTool(wx.ID_UNDO, False) | 1594 | + self.EnableTool(wx.ID_UNDO, True) |
| 1595 | + | ||
| 1596 | + def OnDisableUndo(self, pubsub_evt): | ||
| 1597 | + self.EnableTool(wx.ID_UNDO, False) | ||
| 1589 | 1598 | ||
| 1590 | def OnEnableRedo(self, pubsub_evt): | 1599 | def OnEnableRedo(self, pubsub_evt): |
| 1591 | value = pubsub_evt.data | 1600 | value = pubsub_evt.data |
| 1592 | - if value: | ||
| 1593 | - self.EnableTool(wx.ID_REDO, True) | ||
| 1594 | - else: | ||
| 1595 | - self.EnableTool(wx.ID_REDO, False) | 1601 | + self.EnableTool(wx.ID_REDO, True) |
| 1602 | + | ||
| 1603 | + def OnDisableRedo(self, pubsub_evt): | ||
| 1604 | + self.EnableTool(wx.ID_REDO, False) |