diff options
author | Jasper St. Pierre <[email protected]> | 2012-06-01 03:35:21 -0400 |
---|---|---|
committer | Alexei Sorokin <[email protected]> | 2016-08-23 00:42:10 +0300 |
commit | a820b36d34cd875a41cb038a2373858d733395af (patch) | |
tree | a011f43602b8b28a1f41b529266fbbc4257f101a /Mozo/MainWindow.py | |
parent | 3fb93cf527611d24eb39977d74da8a45bdf4009f (diff) | |
download | mozo-a820b36d34cd875a41cb038a2373858d733395af.tar.bz2 mozo-a820b36d34cd875a41cb038a2373858d733395af.tar.xz |
MainWindow: refactor button sensitivity code a bit
Diffstat (limited to 'Mozo/MainWindow.py')
-rw-r--r-- | Mozo/MainWindow.py | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/Mozo/MainWindow.py b/Mozo/MainWindow.py index 08a1d2c..dc986b9 100644 --- a/Mozo/MainWindow.py +++ b/Mozo/MainWindow.py @@ -448,32 +448,24 @@ class MainWindow: items, iter = treeview.get_selection().get_selected() if iter is None: return + item = items[iter][3] self.tree.get_object('edit_delete').set_sensitive(True) self.tree.get_object('new_separator_button').set_sensitive(True) self.tree.get_object('delete_button').set_sensitive(True) - if self.editor.canRevert(item): - self.tree.get_object('edit_revert_to_original').set_sensitive(True) - else: - self.tree.get_object('edit_revert_to_original').set_sensitive(False) - if not item.get_type() == matemenu.TYPE_SEPARATOR: - self.tree.get_object('edit_properties').set_sensitive(True) - self.tree.get_object('properties_button').set_sensitive(True) - else: - self.tree.get_object('edit_properties').set_sensitive(False) - self.tree.get_object('properties_button').set_sensitive(False) - # If first item... - if items.get_path(iter).get_indices()[0] == 0: - self.tree.get_object('move_up_button').set_sensitive(False) - else: - self.tree.get_object('move_up_button').set_sensitive(True) + can_revert = self.editor.canRevert(item) + self.tree.get_object('edit_revert_to_original').set_sensitive(can_revert) - # If last item... - if items.get_path(iter).get_indices()[0] == (len(items)-1): - self.tree.get_object('move_down_button').set_sensitive(False) - else: - self.tree.get_object('move_down_button').set_sensitive(True) + can_edit = not item.get_type() == matemenu.TYPE_SEPARATOR + self.tree.get_object('edit_properties').set_sensitive(can_edit) + self.tree.get_object('properties_button').set_sensitive(can_edit) + + index = items.get_path(iter).get_indices()[0] + can_go_up = index > 0 + can_go_down = index < len(items) - 1 + self.tree.get_object('move_up_button').set_sensitive(can_go_up) + self.tree.get_object('move_down_button').set_sensitive(can_go_down) def on_item_tree_row_activated(self, treeview, path, column): self.on_edit_properties_activate(None) |