summaryrefslogtreecommitdiff
path: root/cad/src/ne1_ui/toolbars/Ui_NanotubeFlyout.py
blob: a40fee85d49717600b2472bdc83158fb2d663de9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright 2004-2007 Nanorex, Inc.  See LICENSE file for details.
"""
$Id$

TODO: (list copied and kept from Ui_DnaFlyout.py --Mark)
- Does the parentWidget for the NanotubeFlyout always needs to be a propertyManager
  The parentWidget is the propertyManager object of the currentCommand on the
  commandSequencer. What if the currentCommand doesn't have a PM but it wants
  its own commandToolbar?  Use the mainWindow as its parentWidget?
- The implementation may change after Command Manager (Command toolbar) code
  cleanup. The implementation as of 2007-12-20 is an attempt to define
  flyouttoolbar object in the 'Command.

History:
- Mark 2008-03-8: This file created from a copy of Ui_DnaFlyout.py and edited.
"""


from PyQt4 import QtGui
from PyQt4.Qt import SIGNAL
from utilities.icon_utilities import geticon

from ne1_ui.NE1_QWidgetAction import NE1_QWidgetAction



from ne1_ui.toolbars.Ui_AbstractFlyout import Ui_AbstractFlyout


_superclass = Ui_AbstractFlyout
class NanotubeFlyout(Ui_AbstractFlyout):

    def _action_in_controlArea_to_show_this_flyout(self):
        """
        Required action in the 'Control Area' as a reference for this
        flyout toolbar. See superclass method for documentation and todo note.
        """
        return self.win.buildNanotubeAction

    def _getExitActionText(self):
        """
        Overrides superclass method.
        @see: self._createActions()
        """
        return "Exit NT"


    def getFlyoutActionList(self):
        """
        Returns a tuple that contains lists of actions used to create
        the flyout toolbar.
        Called by CommandToolbar._createFlyoutToolBar().
        @return: params: A tuple that contains 3 lists:
        (subControlAreaActionList, commandActionLists, allActionsList)
        """
        #'allActionsList' returns all actions in the flyout toolbar
        #including the subcontrolArea actions.
        allActionsList = []


        #Action List for  subcontrol Area buttons.
        subControlAreaActionList = []
        subControlAreaActionList.append(self.exitModeAction)
        separator = QtGui.QAction(self.parentWidget)
        separator.setSeparator(True)
        subControlAreaActionList.append(separator)
        subControlAreaActionList.append(self.insertNanotubeAction)

        allActionsList.extend(subControlAreaActionList)

        commandActionLists = []
        #Append empty 'lists' in 'commandActionLists equal to the
        #number of actions in subControlArea
        for i in range(len(subControlAreaActionList)):
            lst = []
            commandActionLists.append(lst)

        params = (subControlAreaActionList, commandActionLists, allActionsList)

        return params

    def _createActions(self, parentWidget):

        _superclass._createActions(self, parentWidget)

        self.subControlActionGroup = QtGui.QActionGroup(self.parentWidget)
        self.subControlActionGroup.setExclusive(False)

        self.insertNanotubeAction = \
            NE1_QWidgetAction(self.subControlActionGroup,
                              win = self.win)
        self.insertNanotubeAction.setText("Insert NT")
        self.insertNanotubeAction.setCheckable(True)
        self.insertNanotubeAction.setIcon(
            geticon("ui/actions/Tools/Build Structures/InsertNanotube.png"))

        self.subControlActionGroup.addAction(self.insertNanotubeAction)

    def _addWhatsThisText(self):
        """
        Add 'What's This' help text for all actions on toolbar.
        """
        from ne1_ui.WhatsThisText_for_CommandToolbars import whatsThisTextForNanotubeCommandToolbar
        whatsThisTextForNanotubeCommandToolbar(self)
        return

    def _addToolTipText(self):
        """
        Add 'Tool tip' help text for all actions on toolbar.
        """
        from ne1_ui.ToolTipText_for_CommandToolbars import toolTipTextForNanotubeCommandToolbar
        toolTipTextForNanotubeCommandToolbar(self)
        return

    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        This can be overridden in subclasses. By default it does nothing.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean

        @see: self.activateFlyoutToolbar, self.deActivateFlyoutToolbar
        """
        if isConnect:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        _superclass.connect_or_disconnect_signals(self, isConnect)

        change_connect(self.insertNanotubeAction,
                             SIGNAL("triggered(bool)"),
                             self.activateInsertNanotubeLine_EditCommand)


    def resetStateOfActions(self):
        """
        Resets the state of actions in the flyout toolbar.
        Uncheck most of the actions. Basically it
        unchecks all the actions EXCEPT the ExitCntAction
        @see: self.deActivateFlyoutToolbar()
        @see: baseCommand.command_update_flyout()
        """

        #Uncheck all the actions in the flyout toolbar (subcontrol area)
        for action in self.subControlActionGroup.actions():
            if action.isChecked():
                action.setChecked(False)


    def activateInsertNanotubeLine_EditCommand(self, isChecked):
        """
        Slot for (Insert) B{Nanotube} action.
        """

        self.win.insertNanotube(isChecked)

        #IMPORTANT:
        #For a QAction, the method
        #setChecked does NOT emmit the 'triggered' SIGNAL. So
        #we can call self.capCntAction.setChecked without invoking its
        #slot method!
        #Otherwise we would have needed to block the signal when action is
        #emitted ..example we would have called something like :
        #'if self._block_insertNanotubeAction_event: return' at the beginning of
        #this method. Why we didn't use QAction group -- We need these actions
        #to be
        # a) exclusive as well as
        #(b) 'toggle-able' (e.g. if you click on a checked action , it should
        #uncheck)
        #QActionGroup achieves (a) but can't do (b)

        #Uncheck all the actions except the dna duplex action
        #in the flyout toolbar (subcontrol area)
        for action in self.subControlActionGroup.actions():
            if action is not self.insertNanotubeAction and action.isChecked():
                action.setChecked(False)