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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# Copyright 2004-2007 Nanorex, Inc. See LICENSE file for details.
"""
@author: Urmi
@copyright: 2008 Nanorex, Inc. See LICENSE file for details.
@version $Id$
piotr 080713: Added editRotamers action.
"""
import foundation.env as env
from PyQt4 import QtCore, QtGui
from PyQt4.Qt import Qt
from PyQt4.Qt import SIGNAL
from utilities.icon_utilities import geticon
from utilities.Log import greenmsg
from ne1_ui.NE1_QWidgetAction import NE1_QWidgetAction
_theProteinFlyout = None
def setupUi(mainWindow):
"""
Construct the QWidgetActions for the Dna flyout on the
Command Manager toolbar.
"""
global _theDnaFlyout
_theProteinFlyout = ProteinFlyout(mainWindow)
# probably needs a retranslateUi to add tooltips too...
def activateProteinFlyout(mainWindow):
mainWindow.commandToolbar.updateCommandToolbar(mainWindow.buildProteinAction,
_theProteinFlyout)
class ProteinFlyout:
def __init__(self, mainWindow, parentWidget):
"""
Create necessary flyout action list and update the flyout toolbar in
the command toolbar with the actions provided by the object of this
class.
@param mainWindow: The mainWindow object
@type mainWindow: B{MWsemantics}
@param parentWidget: The parentWidget to which actions defined by this
object belong to. This needs to be revised.
"""
self.parentWidget = parentWidget
self.win = mainWindow
self._isActive = False
self._createActions(self.parentWidget)
self._addWhatsThisText()
self._addToolTipText()
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.exitProteinAction)
separator = QtGui.QAction(self.parentWidget)
separator.setSeparator(True)
subControlAreaActionList.append(separator)
subControlAreaActionList.append(self.buildPeptideAction)
subControlAreaActionList.append(self.editRotamersAction)
subControlAreaActionList.append(self.editResiduesAction)
subControlAreaActionList.append(self.compareProteinsAction)
subControlAreaActionList.append(self.displayProteinStyleAction)
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):
self.exitProteinAction = NE1_QWidgetAction(parentWidget,
win = self.win)
self.exitProteinAction.setText("Exit Protein")
self.exitProteinAction.setIcon(
geticon("ui/actions/Command Toolbar/ControlArea/Exit.png"))
self.exitProteinAction.setCheckable(True)
self.buildPeptideAction = NE1_QWidgetAction(parentWidget,
win = self.win)
self.buildPeptideAction.setText("Insert Peptide")
self.buildPeptideAction.setCheckable(True)
self.buildPeptideAction.setIcon(
geticon("ui/actions/Command Toolbar/BuildProtein/InsertPeptide.png"))
self.editRotamersAction = NE1_QWidgetAction(parentWidget, win = self.win)
self.editRotamersAction.setText("Rotamers")
self.editRotamersAction.setCheckable(True)
self.editRotamersAction.setIcon(
geticon("ui/actions/Command Toolbar/BuildProtein/Rotamers.png"))
self.editResiduesAction = NE1_QWidgetAction(parentWidget, win = self.win)
self.editResiduesAction.setText("Residues")
self.editResiduesAction.setCheckable(True)
self.editResiduesAction.setIcon(
geticon("ui/actions/Command Toolbar/BuildProtein/Residues.png"))
self.compareProteinsAction = NE1_QWidgetAction(parentWidget, win = self.win)
self.compareProteinsAction.setText("Compare")
self.compareProteinsAction.setCheckable(True)
self.compareProteinsAction.setIcon(
geticon("ui/actions/Command Toolbar/BuildProtein/Compare.png"))
self.displayProteinStyleAction = NE1_QWidgetAction(parentWidget,
win = self.win)
self.displayProteinStyleAction.setText("Edit Style")
self.displayProteinStyleAction.setCheckable(True)
self.displayProteinStyleAction.setIcon(
geticon("ui/actions/Command Toolbar/BuildProtein/EditProteinDisplayStyle.png"))
self.subControlActionGroup = QtGui.QActionGroup(self.parentWidget)
self.subControlActionGroup.setExclusive(False)
self.subControlActionGroup.addAction(self.buildPeptideAction)
self.subControlActionGroup.addAction(self.displayProteinStyleAction)
def _addWhatsThisText(self):
"""
Add 'What's This' help text for all actions on toolbar.
"""
#change this later
from ne1_ui.WhatsThisText_for_CommandToolbars import whatsThisTextForProteinCommandToolbar
whatsThisTextForProteinCommandToolbar(self)
return
def _addToolTipText(self):
"""
Add 'Tool tip' help text for all actions on toolbar.
"""
#add something here later
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
change_connect(self.exitProteinAction,
SIGNAL("triggered(bool)"),
self.activateExitProtein)
change_connect(self.buildPeptideAction,
SIGNAL("triggered(bool)"),
self.activateBuildPeptide_EditCommand)
change_connect(self.editRotamersAction,
SIGNAL("triggered(bool)"),
self.activateEditRotamers_EditCommand)
change_connect(self.editResiduesAction,
SIGNAL("triggered(bool)"),
self.activateEditResidues_EditCommand)
change_connect(self.compareProteinsAction,
SIGNAL("triggered(bool)"),
self.activateCompareProteins_EditCommand)
change_connect(self.displayProteinStyleAction,
SIGNAL("triggered(bool)"),
self.activateProteinDisplayStyle_Command)
def activateFlyoutToolbar(self):
"""
Updates the flyout toolbar with the actions this class provides.
"""
if self._isActive:
return
self._isActive = True
self.win.commandToolbar.cmdButtonGroup.button(0).setChecked(True)
#Now update the command toolbar (flyout area)
self.win.commandToolbar.updateCommandToolbar(self.win.buildProteinAction,
self)
#self.win.commandToolbar._setControlButtonMenu_in_flyoutToolbar(
#self.cmdButtonGroup.checkedId())
self.exitProteinAction.setChecked(True)
self.connect_or_disconnect_signals(True)
def deActivateFlyoutToolbar(self):
"""
Updates the flyout toolbar with the actions this class provides.
"""
if not self._isActive:
return
self._isActive = False
self.resetStateOfActions()
self.connect_or_disconnect_signals(False)
self.win.commandToolbar.updateCommandToolbar(self.win.buildProteinAction,
self,
entering = False)
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 ExitDnaAction
@see: self.deActivateFlyoutToolbar()
@see: self.activateBreakStrands_Command()
@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 activateExitProtein(self, isChecked):
"""
Slot for B{Exit DNA} action.
"""
#@TODO: This needs to be revised.
if hasattr(self.parentWidget, 'ok_btn_clicked'):
if not isChecked:
self.parentWidget.ok_btn_clicked()
def activateBuildPeptide_EditCommand(self, isChecked):
"""
Slot for B{Duplex} action.
"""
self.win.insertPeptide(isChecked)
#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.buildPeptideAction and action.isChecked():
action.setChecked(False)
def activateEditRotamers_EditCommand(self, isChecked):
"""
Slot for B{EditRotamers} action.
"""
self.win.enterEditRotamersCommand(isChecked)
for action in self.subControlActionGroup.actions():
if action is not self.editRotamersAction and action.isChecked():
action.setChecked(False)
def activateEditResidues_EditCommand(self, isChecked):
"""
Slot for B{EditResidues} action.
"""
self.win.enterEditResiduesCommand(isChecked)
for action in self.subControlActionGroup.actions():
if action is not self.editResiduesAction and action.isChecked():
action.setChecked(False)
def activateCompareProteins_EditCommand(self, isChecked):
"""
Slot for B{CompareProteins} action.
"""
self.win.enterCompareProteinsCommand(isChecked)
for action in self.subControlActionGroup.actions():
if action is not self.compareProteinsAction and action.isChecked():
action.setChecked(False)
def activateProteinDisplayStyle_Command(self, isChecked):
"""
Call the method that enters DisplayStyle_Command.
(After entering the command) Also make sure that
all the other actions on the DnaFlyout toolbar are unchecked AND
the DisplayStyle Action is checked.
"""
self.win.enterProteinDisplayStyleCommand(isChecked)
#Uncheck all the actions except the (DNA) display style action
#in the flyout toolbar (subcontrol area)
for action in self.subControlActionGroup.actions():
if action is not self.displayProteinStyleAction and action.isChecked():
action.setChecked(False)
|