~ubuntu-branches/ubuntu/trusty/spyder/trusty-backports

« back to all changes in this revision

Viewing changes to spyderlib/widgets/onecolumntree.py

  • Committer: Bazaar Package Importer
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2011-04-11 12:46:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110411124623-7mb7fyc9vumvrl93
Tags: 2.0.10-1
Imported Upstream version 2.0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
spyderlib.widgets
9
9
=================
10
10
 
11
 
Widgets defined in this module may be used in any other PyQt4-based application
 
11
Widgets defined in this module may be used in any other Qt-based application
12
12
 
13
13
They are also used in Spyder through the Plugin interface
14
14
(see spyderlib.plugins)
15
15
"""
16
16
 
17
 
from PyQt4.QtGui import QTreeWidget, QMenu
18
 
from PyQt4.QtCore import SIGNAL
 
17
from spyderlib.qt.QtGui import QTreeWidget, QMenu
 
18
from spyderlib.qt.QtCore import SIGNAL
19
19
 
20
20
# Local imports
21
 
from spyderlib.config import get_icon
22
 
from spyderlib.utils.qthelpers import (create_action, add_actions, translate,
 
21
from spyderlib.config import get_icon, _
 
22
from spyderlib.utils.qthelpers import (create_action, add_actions,
23
23
                                       get_item_user_text)
24
24
 
25
25
class OneColumnTree(QTreeWidget):
57
57
    def setup_common_actions(self):
58
58
        """Setup context menu common actions"""
59
59
        self.collapse_all_action = create_action(self,
60
 
                         text=translate('OneColumnTree', 'Collapse all'),
61
 
                         icon=get_icon('collapse.png'),
62
 
                         triggered=self.collapseAll)
 
60
                                     text=_('Collapse all'),
 
61
                                     icon=get_icon('collapse.png'),
 
62
                                     triggered=self.collapseAll)
63
63
        self.expand_all_action = create_action(self,
64
 
                         text=translate('OneColumnTree', 'Expand all'),
65
 
                         icon=get_icon('expand.png'),
66
 
                         triggered=self.expandAll)
 
64
                                     text=_('Expand all'),
 
65
                                     icon=get_icon('expand.png'),
 
66
                                     triggered=self.expandAll)
67
67
        self.restore_action = create_action(self,
68
 
                         text=translate('OneColumnTree', 'Restore'),
69
 
                         tip=translate('OneColumnTree',
70
 
                                       'Restore original tree layout'),
71
 
                         icon=get_icon('restore.png'),
72
 
                         triggered=self.restore)
 
68
                                     text=_('Restore'),
 
69
                                     tip=_('Restore original tree layout'),
 
70
                                     icon=get_icon('restore.png'),
 
71
                                     triggered=self.restore)
73
72
        self.collapse_selection_action = create_action(self,
74
 
                         text=translate('OneColumnTree', 'Collapse selection'),
75
 
                         icon=get_icon('collapse_selection.png'),
76
 
                         triggered=self.collapse_selection)
 
73
                                     text=_('Collapse selection'),
 
74
                                     icon=get_icon('collapse_selection.png'),
 
75
                                     triggered=self.collapse_selection)
77
76
        self.expand_selection_action = create_action(self,
78
 
                         text=translate('OneColumnTree', 'Expand selection'),
79
 
                         icon=get_icon('expand_selection.png'),
80
 
                         triggered=self.expand_selection)
 
77
                                     text=_('Expand selection'),
 
78
                                     icon=get_icon('expand_selection.png'),
 
79
                                     triggered=self.expand_selection)
81
80
        return [self.collapse_all_action, self.expand_all_action,
82
81
                self.restore_action, None,
83
82
                self.collapse_selection_action, self.expand_selection_action]
181
180
        self.__expanded_state = {}
182
181
        def add_to_state(item):
183
182
            user_text = get_item_user_text(item)
184
 
            self.__expanded_state[user_text] = item.isExpanded()
 
183
            self.__expanded_state[hash(user_text)] = item.isExpanded()
185
184
        def browse_children(item):
186
185
            add_to_state(item)
187
186
            for index in range(item.childCount()):
188
187
                citem = item.child(index)
189
188
                user_text = get_item_user_text(citem)
190
 
                self.__expanded_state[user_text] = citem.isExpanded()
 
189
                self.__expanded_state[hash(user_text)] = citem.isExpanded()
191
190
                browse_children(citem)
192
191
        for tlitem in self.get_top_level_items():
193
192
            browse_children(tlitem)
198
197
            return
199
198
        for item in self.get_items()+self.get_top_level_items():
200
199
            user_text = get_item_user_text(item)
201
 
            is_expanded = self.__expanded_state.get(user_text)
 
200
            is_expanded = self.__expanded_state.get(hash(user_text))
202
201
            if is_expanded is not None:
203
202
                item.setExpanded(is_expanded)
204
203