class MultipleDnaSegmentResize_PropertyManager( DnaOrCnt_PropertyManager ): title = "Resize Dna Segments" iconPath = "ui/actions/Properties Manager/Resize_Multiple_Segments.png" def __init__( self, command ): """ Constructor for the Build DNA property manager. """ self.endPoint1 = V(0, 0, 0) self.endPoint2 = V(0, 0, 0) self._numberOfBases = 0 self._conformation = 'B-DNA' self.duplexRise = 3.18 self.basesPerTurn = 10 self.dnaModel = 'PAM3' _superclass.__init__( self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_WHATS_THIS_BUTTON) msg = "Use resize handles to resize the segments." self.updateMessage(msg) 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 """ #TODO: This is a temporary fix for a bug. When you invoke a #temporary mode entering such a temporary mode keeps the signals of #PM from the previous mode connected ( #but while exiting that temporary mode and reentering the #previous mode, it atucally reconnects the signal! This gives rise to #lots of bugs. This needs more general fix in Temporary mode API. # -- Ninad 2008-01-09 (similar comment exists in MovePropertyManager.py if isConnect and self.isAlreadyConnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to connect widgets"\ "in this PM that are already connected." ) return if not isConnect and self.isAlreadyDisconnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to disconnect widgets"\ "in this PM that are already disconnected.") return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self.segmentListWidget.connect_or_disconnect_signals(isConnect) change_connect(self.addSegmentsToolButton, SIGNAL("toggled(bool)"), self.activateAddSegmentsTool) change_connect(self.removeSegmentsToolButton, SIGNAL("toggled(bool)"), self.activateRemoveSegmentsTool) def _update_UI_do_updates(self): """ @see: Command_PropertyManager._update_UI_do_updates() @see: DnaSegment_EditCommand.model_changed() @see: DnaSegment_EditCommand.hasResizableStructure() @see: self._current_model_changed_params() """ currentParams = self._current_model_changed_params() #Optimization. Return from the model_changed method if the #params are the same. if same_vals(currentParams, self._previous_model_changed_params): return number_of_segments, isStructResizable, why_not = currentParams #update the self._previous_model_changed_params with this new param set. self._previous_model_changed_params = currentParams if not isStructResizable: if not number_of_segments == 0: #disable all widgets self._pmGroupBox1.setEnabled(False) msg = redmsg("DnaSegment is not resizable. Reason: %s"%(why_not)) self.updateMessage(msg) else: if not self._pmGroupBox1.isEnabled(): self._pmGroupBox1.setEnabled(True) msg = "Use resize handles to resize the segments" self.updateMessage(msg) self.updateListWidgets() ##self.command.updateHandlePositions() def _current_model_changed_params(self): """ Returns a tuple containing the parameters that will be compared against the previously stored parameters. This provides a quick test to determine whether to do more things in self.model_changed() @see: self.model_changed() which calls this @see: self._previous_model_changed_params attr. """ params = None if self.command: #update the list first. self.command.updateResizeSegmentList() number_of_segments = len(self.command.getResizeSegmentList()) isStructResizable, why_not = self.command.hasResizableStructure() params = (number_of_segments, isStructResizable, why_not) return params def isAddSegmentsToolActive(self): """ Returns True if the add segments tool (which adds the segments to the list of segments to be resized) is active """ if self.addSegmentsToolButton.isChecked(): #For safety if not self.removeSegmentsToolButton.isChecked(): return True return False def isRemoveSegmentsToolActive(self): """ Returns True if the remove segments tool (which removes the segments from the list of segments to be resized) is active """ if self.removeSegmentsToolButton.isChecked(): if not self.addSegmentsToolButton.isChecked(): #For safety return True return False def activateAddSegmentsTool(self,enable): """ Change the appearance of the list widget (that lists the dna segments to be resized) so as to indicate that the add dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the add segments tool is active. @type enable: bool """ if enable: if not self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(True) if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.segmentListWidget.setColor(lightgreen_2) else: if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def activateRemoveSegmentsTool(self,enable): """ Change the appearance of the list widget (that lists the dna segments to be resized) so as to indicate that the REMOVE dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the REMOVE segments tool is active. @type enable: bool """ if enable: if not self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(True) if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.segmentListWidget.setColor(lightred_1) else: if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def removeListWidgetItems(self): """ Removes selected atoms from the resize dna segment list widget Example: User selects a bunch of items in the list widget and hits delete key to remove the selected items from the list IMPORTANT NOTE: This method does NOT delete the correspoinging model item in the GLPane (i.e. corresponding dnasegment). It just 'removes' the item from the list widget (indicating its no longer being resized) This is intentional. """ self.segmentListWidget.deleteSelection() itemDict = self.segmentListWidget.getItemDictonary() self.command.setResizeStructList(itemDict.values()) self.updateListWidgets() self.win.win_update() def _addGroupBoxes( self ): """ Add the Property Manager group boxes. """ self._pmGroupBox1 = PM_GroupBox( self, title = "Segments for Resizing" ) self._loadGroupBox1( self._pmGroupBox1 ) self._displayOptionsGroupBox = PM_GroupBox( self, title = "Display Options" ) self._loadDisplayOptionsGroupBox( self._displayOptionsGroupBox ) def _loadGroupBox1(self, pmGroupBox): """ load widgets in groupbox1 """ self.segmentListWidget = PM_SelectionListWidget( pmGroupBox, self.win, label = "", heightByRows = 12) self.segmentListWidget.setFocusPolicy(Qt.StrongFocus) self.segmentListWidget.setFocus() self.setFocusPolicy(Qt.StrongFocus) self.addSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Add segments to the list", iconPath = "ui/actions/Properties Manager"\ "/AddSegment_To_ResizeSegmentList.png", spanWidth = True ) self.addSegmentsToolButton.setCheckable(True) self.addSegmentsToolButton.setAutoRaise(True) self.removeSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Remove segments from the list", iconPath = "ui/actions/Properties Manager"\ "/RemoveSegment_From_ResizeSegmentList.png", spanWidth = True ) self.removeSegmentsToolButton.setCheckable(True) self.removeSegmentsToolButton.setAutoRaise(True) #Widgets to include in the widget row. widgetList = [ ('QLabel', " Add/Remove Segments:", 0), ('QSpacerItem', 5, 5, 1), ('PM_ToolButton', self.addSegmentsToolButton, 2), ('QSpacerItem', 5, 5, 3), ('PM_ToolButton', self.removeSegmentsToolButton, 4), ('QSpacerItem', 5, 5, 5) ] widgetRow = PM_WidgetRow(pmGroupBox, title = '', widgetList = widgetList, label = "", spanWidth = True ) def _addWhatsThisText(self): """ Add what's this text. Abstract method. """ pass def show(self): """ Overrides the superclass method @see: self._deactivateAddRemoveSegmentsTool """ _superclass.show(self) ##self.updateListWidgets() self._deactivateAddRemoveSegmentsTool() def _deactivateAddRemoveSegmentsTool(self): """ Deactivate tools that allow adding or removing the segments to the segment list in the Property manager. This can be simply done by resetting the state of toolbuttons to False. Example: toolbuttons that add or remove segments to the segment list in the Property manager. When self.show is called these need to be unchecked. @see: self.isAddSegmentsToolActive() @see:self.isRemoveSegmentsToolActive() @see: self.show() """ self.addSegmentsToolButton.setChecked(False) self.removeSegmentsToolButton.setChecked(False) def listWidgetHasFocus(self): """ Checks if the list widget that lists dnasegments to be resized has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Dnasegment in the GLPane) @see: MultipleDnaSegment_GraphicsMode.keyPressEvent() where it is called """ if self.segmentListWidget.hasFocus(): return True return False def setParameters(self, params): pass def getParameters(self): return () def updateListWidgets(self): self.updateSegmentListWidget() def updateSegmentListWidget(self): """ Update the list of segments shown in the segments list widget @see: self.updateListWidgets, self.updateStrandListWidget """ segmentList = [] segmentList = self.command.getResizeSegmentList() self.segmentListWidget.insertItems( row = 0, items = segmentList) def _connect_showCursorTextCheckBox(self): """ Connect the show cursor text checkbox with user prefs_key. Overrides DnaOrCnt_PropertyManager._connect_showCursorTextCheckBox """ connect_checkbox_with_boolean_pref( self.showCursorTextCheckBox , dnaSegmentEditCommand_showCursorTextCheckBox_prefs_key) def _params_for_creating_cursorTextCheckBoxes(self): """ Returns params needed to create various cursor text checkboxes connected to prefs_keys that allow custom cursor texts. @return: A list containing tuples in the following format: ('checkBoxTextString' , preference_key). PM_PrefsCheckBoxes uses this data to create checkboxes with the the given names and connects them to the provided preference keys. (Note that PM_PrefsCheckBoxes puts thes within a GroupBox) @rtype: list @see: PM_PrefsCheckBoxes @see: self._loadDisplayOptionsGroupBox where this list is used. @see: Superclass method which is overridden here -- DnaOrCnt_PropertyManager._params_for_creating_cursorTextCheckBoxes() """ params = \ [ #Format: (" checkbox text", prefs_key) ("Number of base pairs", dnaSegmentEditCommand_cursorTextCheckBox_numberOfBasePairs_prefs_key), ("Duplex length", dnaSegmentEditCommand_cursorTextCheckBox_length_prefs_key), ("Number of basepairs to be changed", dnaSegmentEditCommand_cursorTextCheckBox_changedBasePairs_prefs_key) ] return params
class PM_ObjectChooser(PM_GroupBox): def __init__(self, parentWidget, command, modelObjectType, title = '' , addIcon = "ui/actions/Properties Manager"\ "/AddSegment_To_ResizeSegmentList.png", removeIcon = "ui/actions/Properties Manager"\ "/RemoveSegment_From_ResizeSegmentList.png"): """ """ self.isAlreadyConnected = False self.isAlreadyDisconnected = False _superclass.__init__(self, parentWidget, title = title) self.command = command self.win = self.command.win self._modelObjectType = modelObjectType self._addIcon = addIcon self._removeIcon = removeIcon self._loadWidgets() def getModelObjectType(self): return self._modelObjectType def setModelObjectType(self, modelObjtype): self._modelObjectType = modelObjtype 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 """ #TODO: This is a temporary fix for a bug. When you invoke a temporary mode # entering such a temporary mode keeps the signals of #PM from the previous mode connected ( #but while exiting that temporary mode and reentering the #previous mode, it atucally reconnects the signal! This gives rise to #lots of bugs. This needs more general fix in Temporary mode API. # -- Ninad 2008-01-09 (similar comment exists in MovePropertyManager.py if isConnect and self.isAlreadyConnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to connect widgets"\ "in this PM that are already connected." ) return if not isConnect and self.isAlreadyDisconnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to disconnect widgets"\ "in this PM that are already disconnected.") return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self._listWidget.connect_or_disconnect_signals(isConnect) change_connect(self._addToolButton, SIGNAL("toggled(bool)"), self.activateAddTool) change_connect(self._removeToolButton, SIGNAL("toggled(bool)"), self.activateRemoveTool) def _loadWidgets(self): """ """ self._loadSelectionListWidget() self._loadAddRemoveButtons() def _loadSelectionListWidget(self): """ """ self._listWidget = PM_SelectionListWidget( self, self.win, label = "", heightByRows = 12) self._listWidget.setFocusPolicy(Qt.StrongFocus) self._listWidget.setFocus() self.setFocusPolicy(Qt.StrongFocus) def _loadAddRemoveButtons(self): """ """ self._addToolButton = PM_ToolButton( self, text = "Add items to the list", iconPath = self._addIcon, spanWidth = True ) self._addToolButton.setCheckable(True) self._addToolButton.setAutoRaise(True) self._removeToolButton = PM_ToolButton( self, text = "Remove items from the list", iconPath = self._removeIcon, spanWidth = True ) self._removeToolButton.setCheckable(True) self._removeToolButton.setAutoRaise(True) #Widgets to include in the widget row. widgetList = [ ('QLabel', " Add/Remove Items:", 0), ('QSpacerItem', 5, 5, 1), ('PM_ToolButton', self._addToolButton, 2), ('QSpacerItem', 5, 5, 3), ('PM_ToolButton', self._removeToolButton, 4), ('QSpacerItem', 5, 5, 5) ] widgetRow = PM_WidgetRow(self, title = '', widgetList = widgetList, label = "", spanWidth = True ) def isAddToolActive(self): """ Returns True if the add objects tool is active. """ if self._addToolButton.isChecked(): #For safety if not self._removeToolButton.isChecked(): return True return False def isRemoveToolActive(self): """ Returns True if the remove segments tool (which removes the segments from the list of segments ) is active """ if self._removeToolButton.isChecked(): if not self._addToolButton.isChecked(): #For safety return True return False def hasFocus(self): """ Checks if the list widget that lists dnasegments (that will undergo special operations such as 'resizing them at once or making crossovers between the segments etc) has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Dnasegment in the GLPane) @see: MultipleDnaSegment_GraphicsMode.keyPressEvent() where it is called """ if self._listWidget.hasFocus(): return True return False def activateAddTool(self,enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the add dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the add segments tool is active. @type enable: bool """ if enable: if not self._addToolButton.isChecked(): self._addToolButton.setChecked(True) if self._removeToolButton.isChecked(): self._removeToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(False) self._listWidget.setColor(lightgreen_2) ##objectType = self._modelObjectType ##objectChooserType = 'ADD' ##self.command.activateObjectChooser((objectType, objectChooserType)) ##self.command.logMessage('ADD_SEGMENTS_ACTIVATED') else: if self._addToolButton.isChecked(): self._addToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(True) self._listWidget.resetColor() def activateRemoveTool(self,enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the REMOVE dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the REMOVE segments tool is active. @type enable: bool """ if enable: if not self._removeToolButton.isChecked(): self._removeToolButton.setChecked(True) if self._addToolButton.isChecked(): self._addToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(False) ##self.command.logMessage('REMOVE_SEGMENTS_ACTIVATED') self._listWidget.setColor(lightred_1) else: if self._removeToolButton.isChecked(): self._removeToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(True) self._listWidget.resetColor() def _deactivateAddRemoveTools(self): """ Deactivate tools that allow adding or removing the segments to the segment list in the Property manager. This can be simply done by resetting the state of toolbuttons to False. Example: toolbuttons that add or remove segments to the segment list in the Property manager. When self.show is called these need to be unchecked. @see: self.isAddSegmentsToolActive() @see:self.isRemoveSegmentsToolActive() @see: self.show() """ self._addToolButton.setChecked(False) self._removeToolButton.setChecked(False) def removeItems(self): """ Removes selected itoms from the dna segment list widget Example: User selects a bunch of items in the list widget and hits delete key to remove the selected items from the list IMPORTANT NOTE: This method does NOT delete the correspoinging model item in the GLPane (i.e. corresponding dnasegment). It just 'removes' the item from the list widget This is intentional. """ self._listWidget.deleteSelection() itemDict = self._listWidget.getItemDictonary() self.command.setSegmentList(itemDict.values()) self.updateListWidget() self.win.win_update() def updateListWidget(self, objectList = []): """ Update the list of segments shown in the segments list widget @see: self.updateListWidgets, self.updateStrandListWidget """ self._listWidget.insertItems( row = 0, items = objectList)
class ListWidgetItems_PM_Mixin: def _loadSegmentListWidget(self, pmGroupBox): self.segmentListWidget = PM_SelectionListWidget(pmGroupBox, self.win, label="", heightByRows=12) self.segmentListWidget.setFocusPolicy(Qt.StrongFocus) self.segmentListWidget.setFocus() self.setFocusPolicy(Qt.StrongFocus) self.addSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Add segments to the list", iconPath = "ui/actions/Properties Manager"\ "/AddSegment_To_ResizeSegmentList.png", spanWidth = True ) self.addSegmentsToolButton.setCheckable(True) self.addSegmentsToolButton.setAutoRaise(True) self.removeSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Remove segments from the list", iconPath = "ui/actions/Properties Manager"\ "/RemoveSegment_From_ResizeSegmentList.png", spanWidth = True ) self.removeSegmentsToolButton.setCheckable(True) self.removeSegmentsToolButton.setAutoRaise(True) #Widgets to include in the widget row. widgetList = [('QLabel', " Add/Remove Segments:", 0), ('QSpacerItem', 5, 5, 1), ('PM_ToolButton', self.addSegmentsToolButton, 2), ('QSpacerItem', 5, 5, 3), ('PM_ToolButton', self.removeSegmentsToolButton, 4), ('QSpacerItem', 5, 5, 5)] widgetRow = PM_WidgetRow(pmGroupBox, title='', widgetList=widgetList, label="", spanWidth=True) def listWidgetHasFocus(self): """ Checkes if the list widget that lists dnasegments (that will undergo special operations such as 'resizing them at once or making crossovers between the segments etc) has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Dnasegment in the GLPane) @see: MultipleDnaSegment_GraphicsMode.keyPressEvent() where it is called """ if self.segmentListWidget.hasFocus(): return True return False def updateListWidgets(self): self.updateSegmentListWidget() def updateSegmentListWidget(self): """ Update the list of segments shown in the segments list widget @see: self.updateListWidgets, self.updateStrandListWidget """ segmentList = [] segmentList = self.command.getSegmentList() self.segmentListWidget.insertItems(row=0, items=segmentList) def isAddSegmentsToolActive(self): """ Returns True if the add segments tool (which adds the segments to the list of segments) is active """ if self.addSegmentsToolButton.isChecked(): #For safety if not self.removeSegmentsToolButton.isChecked(): return True return False def isRemoveSegmentsToolActive(self): """ Returns True if the remove segments tool (which removes the segments from the list of segments ) is active """ if self.removeSegmentsToolButton.isChecked(): if not self.addSegmentsToolButton.isChecked(): #For safety return True return False def activateAddSegmentsTool(self, enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the add dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the add segments tool is active. @type enable: bool """ if enable: if not self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(True) if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.segmentListWidget.setColor(lightgreen_2) self.command.logMessage('ADD_SEGMENTS_ACTIVATED') else: if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def activateRemoveSegmentsTool(self, enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the REMOVE dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the REMOVE segments tool is active. @type enable: bool """ if enable: if not self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(True) if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.command.logMessage('REMOVE_SEGMENTS_ACTIVATED') self.segmentListWidget.setColor(lightred_1) else: if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def _deactivateAddRemoveSegmentsTool(self): """ Deactivate tools that allow adding or removing the segments to the segment list in the Property manager. This can be simply done by resetting the state of toolbuttons to False. Example: toolbuttons that add or remove segments to the segment list in the Property manager. When self.show is called these need to be unchecked. @see: self.isAddSegmentsToolActive() @see:self.isRemoveSegmentsToolActive() @see: self.show() """ self.addSegmentsToolButton.setChecked(False) self.removeSegmentsToolButton.setChecked(False) def removeListWidgetItems(self): """ Removes selected itoms from the dna segment list widget Example: User selects a bunch of items in the list widget and hits delete key to remove the selected items from the list IMPORTANT NOTE: This method does NOT delete the correspoinging model item in the GLPane (i.e. corresponding dnasegment). It just 'removes' the item from the list widget This is intentional. """ self.segmentListWidget.deleteSelection() itemDict = self.segmentListWidget.getItemDictonary() self.command.setSegmentList(itemDict.values()) self.updateListWidgets() self.win.win_update()
class PM_ObjectChooser(PM_GroupBox): def __init__(self, parentWidget, command, modelObjectType, title = '' , addIcon = "ui/actions/Properties Manager"\ "/AddSegment_To_ResizeSegmentList.png", removeIcon = "ui/actions/Properties Manager"\ "/RemoveSegment_From_ResizeSegmentList.png"): """ """ self.isAlreadyConnected = False self.isAlreadyDisconnected = False _superclass.__init__(self, parentWidget, title=title) self.command = command self.win = self.command.win self._modelObjectType = modelObjectType self._addIcon = addIcon self._removeIcon = removeIcon self._loadWidgets() def getModelObjectType(self): return self._modelObjectType def setModelObjectType(self, modelObjtype): self._modelObjectType = modelObjtype 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 """ #TODO: This is a temporary fix for a bug. When you invoke a temporary mode # entering such a temporary mode keeps the signals of #PM from the previous mode connected ( #but while exiting that temporary mode and reentering the #previous mode, it atucally reconnects the signal! This gives rise to #lots of bugs. This needs more general fix in Temporary mode API. # -- Ninad 2008-01-09 (similar comment exists in MovePropertyManager.py if isConnect and self.isAlreadyConnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to connect widgets"\ "in this PM that are already connected." ) return if not isConnect and self.isAlreadyDisconnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to disconnect widgets"\ "in this PM that are already disconnected.") return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self._listWidget.connect_or_disconnect_signals(isConnect) change_connect(self._addToolButton, SIGNAL("toggled(bool)"), self.activateAddTool) change_connect(self._removeToolButton, SIGNAL("toggled(bool)"), self.activateRemoveTool) def _loadWidgets(self): """ """ self._loadSelectionListWidget() self._loadAddRemoveButtons() def _loadSelectionListWidget(self): """ """ self._listWidget = PM_SelectionListWidget(self, self.win, label="", heightByRows=12) self._listWidget.setFocusPolicy(Qt.StrongFocus) self._listWidget.setFocus() self.setFocusPolicy(Qt.StrongFocus) def _loadAddRemoveButtons(self): """ """ self._addToolButton = PM_ToolButton(self, text="Add items to the list", iconPath=self._addIcon, spanWidth=True) self._addToolButton.setCheckable(True) self._addToolButton.setAutoRaise(True) self._removeToolButton = PM_ToolButton( self, text="Remove items from the list", iconPath=self._removeIcon, spanWidth=True) self._removeToolButton.setCheckable(True) self._removeToolButton.setAutoRaise(True) #Widgets to include in the widget row. widgetList = [('QLabel', " Add/Remove Items:", 0), ('QSpacerItem', 5, 5, 1), ('PM_ToolButton', self._addToolButton, 2), ('QSpacerItem', 5, 5, 3), ('PM_ToolButton', self._removeToolButton, 4), ('QSpacerItem', 5, 5, 5)] widgetRow = PM_WidgetRow(self, title='', widgetList=widgetList, label="", spanWidth=True) def isAddToolActive(self): """ Returns True if the add objects tool is active. """ if self._addToolButton.isChecked(): #For safety if not self._removeToolButton.isChecked(): return True return False def isRemoveToolActive(self): """ Returns True if the remove segments tool (which removes the segments from the list of segments ) is active """ if self._removeToolButton.isChecked(): if not self._addToolButton.isChecked(): #For safety return True return False def hasFocus(self): """ Checks if the list widget that lists dnasegments (that will undergo special operations such as 'resizing them at once or making crossovers between the segments etc) has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Dnasegment in the GLPane) @see: MultipleDnaSegment_GraphicsMode.keyPressEvent() where it is called """ if self._listWidget.hasFocus(): return True return False def activateAddTool(self, enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the add dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the add segments tool is active. @type enable: bool """ if enable: if not self._addToolButton.isChecked(): self._addToolButton.setChecked(True) if self._removeToolButton.isChecked(): self._removeToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(False) self._listWidget.setColor(lightgreen_2) ##objectType = self._modelObjectType ##objectChooserType = 'ADD' ##self.command.activateObjectChooser((objectType, objectChooserType)) ##self.command.logMessage('ADD_SEGMENTS_ACTIVATED') else: if self._addToolButton.isChecked(): self._addToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(True) self._listWidget.resetColor() def activateRemoveTool(self, enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the REMOVE dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the REMOVE segments tool is active. @type enable: bool """ if enable: if not self._removeToolButton.isChecked(): self._removeToolButton.setChecked(True) if self._addToolButton.isChecked(): self._addToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(False) ##self.command.logMessage('REMOVE_SEGMENTS_ACTIVATED') self._listWidget.setColor(lightred_1) else: if self._removeToolButton.isChecked(): self._removeToolButton.setChecked(False) self._listWidget.setAlternatingRowColors(True) self._listWidget.resetColor() def _deactivateAddRemoveTools(self): """ Deactivate tools that allow adding or removing the segments to the segment list in the Property manager. This can be simply done by resetting the state of toolbuttons to False. Example: toolbuttons that add or remove segments to the segment list in the Property manager. When self.show is called these need to be unchecked. @see: self.isAddSegmentsToolActive() @see:self.isRemoveSegmentsToolActive() @see: self.show() """ self._addToolButton.setChecked(False) self._removeToolButton.setChecked(False) def removeItems(self): """ Removes selected itoms from the dna segment list widget Example: User selects a bunch of items in the list widget and hits delete key to remove the selected items from the list IMPORTANT NOTE: This method does NOT delete the correspoinging model item in the GLPane (i.e. corresponding dnasegment). It just 'removes' the item from the list widget This is intentional. """ self._listWidget.deleteSelection() itemDict = self._listWidget.getItemDictonary() self.command.setSegmentList(itemDict.values()) self.updateListWidget() self.win.win_update() def updateListWidget(self, objectList=[]): """ Update the list of segments shown in the segments list widget @see: self.updateListWidgets, self.updateStrandListWidget """ self._listWidget.insertItems(row=0, items=objectList)
class BuildNanotube_PropertyManager(EditCommand_PM): """ The BuildNanotube_PropertyManager class provides a Property Manager for the B{Build > CNT } command. @ivar title: The title that appears in the property manager header. @type title: str @ivar pmName: The name of this property manager. This is used to set the name of the PM_Dialog object via setObjectName(). @type name: str @ivar iconPath: The relative path to the PNG file that contains a 22 x 22 icon image that appears in the PM header. @type iconPath: str """ title = "Build Nanotube" pmName = title iconPath = "ui/actions/Command Toolbar/BuildNanotube/BuildNanotube.png" def __init__(self, command): """ Constructor for the Build Nanotube property manager. """ #Attributes for self._update_UI_do_updates() to keep track of changes #in these , since the last call of that method. These are used to #determine whether certain UI updates are needed. self._previousSelectionParams = None self._previousStructureParams = None self._previousCommandStackParams = None #see self.connect_or_disconnect_signals for comment about this flag self.isAlreadyConnected = False self.isAlreadyDisconnected = False EditCommand_PM.__init__(self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_WHATS_THIS_BUTTON) 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 """ #TODO: This is a temporary fix for a bug. When you invoke a temporary #mode, entering such a temporary mode keeps the signals of PM from the #previous mode connected (but while exiting that temporary mode and #reentering the previous mode, it actually reconnects the signal! #This gives rise to lots of bugs. This needs a more general fix in #the Temporary mode API. # -- Ninad 2008-01-09 (similar comment exists in MovePropertyManager.py if isConnect and self.isAlreadyConnected: return if not isConnect and self.isAlreadyDisconnected: return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self.nanotubeListWidget.connect_or_disconnect_signals(isConnect) change_connect(self.editNanotubePropertiesButton, SIGNAL("clicked()"), self._editNanotube) return def enable_or_disable_gui_actions(self, bool_enable=False): """ Enable or disable some gui actions when this property manager is opened or closed, depending on the bool_enable. """ #For new command API, we will always show the exit button to check #if Exit button really exits the subcommand and the parent command #(earlier there were bugs) . Regaring 'whether this should be the #default behavior', its a UI design issue and we will worry about it #later -- Ninad 2008-08-27 (based on an email exchanged with Bruce) pass def _update_UI_do_updates(self): """ Overrides superclass method. @see: Command_PropertyManager._update_UI_do_updates() """ newSelectionParams = self._currentSelectionParams() current_struct_params = self._currentStructureParams() selection_params_unchanged = same_vals(newSelectionParams, self._previousSelectionParams) #introducing self._previousStructureParams and #adding structure_params_unchanged check to the 'if' condition below #fixes bug 2910. structure_params_unchanged = same_vals(self._previousStructureParams, current_struct_params) current_command_stack_params = self._currentCommandStackParams() #Check if command stack params changed since last call of this #PM update method. This is used to fix bugs like 2940 command_stack_params_unchanged = same_vals( self._previousCommandStackParams, current_command_stack_params) #No need to proceed if any of the selection/ structure and commandstack #parameters remained unchanged since last call. --- [CONDITION A] if selection_params_unchanged and \ structure_params_unchanged and \ command_stack_params_unchanged: return self._previousStructureParams = current_struct_params self._previousSelectionParams = newSelectionParams self._previousCommandStackParams = current_command_stack_params if structure_params_unchanged: #NOTE: We checked if either of the selection struct or command stack #parameters or both changed. (this was referred as '[CONDITION A]' #above). So, this condition (structure_params_unchanged)also means #either selection or command stack or both parameters were changed. if not command_stack_params_unchanged: #update the nanotube list widget *before* updating the selection if #the command stack changed. This ensures that the selection box #appears around the list widget items that are selected. self.updateNanotubesListWidget() selectedNanotubeSegments = newSelectionParams self.nanotubeListWidget.updateSelection(selectedNanotubeSegments) self.updateNanotubePropertiesButton() return self.updateNanotubesListWidget() return def _currentCommandStackParams(self): """ The return value is supposed to be used by BUILD_NANOTUBE command PM ONLY and NOT by any subclasses. Returns a tuple containing current command stack change indicator and the name of the command 'BUILD_NANOTUBE'. These parameters are then used to decide whether updating widgets in this property manager is needed, when self._update_UI_do_updates() is called. @NOTE: - Command_PropertyManager.update_UI() already does a check to see if any of the global change indicators in assembly (command_stack_change, model_change, selection_change) changed since last call and then only calls self._update_UI_do_updates(). - But this method is just used to keep track of the local command stack change counter in order to update the list widgets. - This is used to fix bug 2940 @see: self._update_UI_do_updates() """ commandStackCounter = self.command.assy.command_stack_change_indicator( ) #Append 'BUILD_NANOTUBE to the tuple to be returned. This is just to remind #us that this method is meant for BUILD_NANOTUBE command PM only. (and not #by any subclasses) Should we assert this? I think it will slow things #down so this comment is enough -- Ninad 2008-09-30 return (commandStackCounter, 'BUILD_NANOTUBE') def _currentSelectionParams(self): """ Returns a tuple containing current selection parameters. These parameters are then used to decide whether updating widgets in this property manager is needed when L{self.model_changed} method is called. @return: A tuple that contains total number of selected nanotubes. @rtype: tuple @NOTE: This method may be renamed in future. It's possible that there are other groupboxes in the PM that need to be updated when something changes in the glpane. """ selectedNanotubeSegments = [] if self.command is not None: # and self.command.hasValidStructure(): selectedNanotubeSegments = self.win.assy.getSelectedNanotubeSegments( ) return (selectedNanotubeSegments) def _currentStructureParams(self): """ Return current structure parameters of interest to self.model_changed. Right now it only returns the number of nanotubes within the structure (or None). This is a good enough check (and no need to compare each and every nanotube within the structure with a previously stored set of strands). """ params = None if self.command: # and self.command.hasValidStructure(): nanotubeSegmentList = [] nanotubeSegmentList = getAllNanotubeSegmentsInPart(self.win.assy) params = len(nanotubeSegmentList) return params def close(self): """ Closes the Property Manager. Overrides EditCommand_PM.close() """ #Clear tags, if any, due to the selection in the self.strandListWidget. #self.nanotubeListWidget.clear() env.history.statusbar_msg("") EditCommand_PM.close(self) return def show(self): """ Show the PM. Extends superclass method. @note: _update_UI_do_updates() gets called immediately after this and updates PM widgets with their correct values/settings. """ env.history.statusbar_msg("") EditCommand_PM.show(self) # NOTE: Think about moving this msg to _update_UI_do_updates() where # custom msgs can be created based on the current selection, etc. # Mark 2008-12-14 msg = "Select <b>Insert Nanotube</b> to create a nanotube or "\ "select an existing nantube to modify it." self.updateMessage(msg) return def _editNanotube(self): """ Slot for the "Edit Properties" button. """ #if not self.command.hasValidStructure(): # return nanotubeSegment = self.win.assy.getSelectedNanotubeSegment() if nanotubeSegment: nanotubeSegment.edit() return def _addWhatsThisText(self): """ What's This text for widgets in the CNT Property Manager. """ pass def _addToolTipText(self): """ Tool Tip text for widgets in the CNT Property Manager. """ pass def _addGroupBoxes(self): """ Add the Nanotube Property Manager group boxes. """ self._pmGroupBox1 = PM_GroupBox(self, title="Nanotubes") self._loadGroupBox1(self._pmGroupBox1) return def _loadGroupBox1(self, pmGroupBox): """ load widgets in groupbox1 """ self.nanotubeListWidget = PM_SelectionListWidget(pmGroupBox, self.win, label="", heightByRows=12) self.nanotubeListWidget.setObjectName('nanotubeListWidget') self.nanotubeListWidget.setTagInstruction('PICK_ITEM_IN_GLPANE') self.editNanotubePropertiesButton = PM_PushButton( pmGroupBox, label="", text="Edit Properties...") self.editNanotubePropertiesButton.setEnabled(False) return def updateNanotubesListWidget(self): """ Updates the nanotubes (selection) groupbox. This includes both the nanotube selection list widget (showing all nanotubes in the part) and the B{Edit Properties} button just below it (enabled if only one of the nanotubes is selected). """ nanotubeSegmentList = getAllNanotubeSegmentsInPart(self.win.assy) if nanotubeSegmentList: self.nanotubeListWidget.insertItems(row=0, items=nanotubeSegmentList) else: self.nanotubeListWidget.clear() self.updateNanotubePropertiesButton() return def updateNanotubePropertiesButton(self): """ Enables the B{Edit Properties} button if a single nanotube is currently selected. Otherwise, the button is disabled. """ self.editNanotubePropertiesButton.setEnabled( bool(self.win.assy.getSelectedNanotubeSegment())) return
class MultipleDnaSegmentResize_PropertyManager(DnaOrCnt_PropertyManager): title = "Resize Dna Segments" iconPath = "ui/actions/Properties Manager/Resize_Multiple_Segments.png" def __init__(self, command): """ Constructor for the Build DNA property manager. """ self.endPoint1 = V(0, 0, 0) self.endPoint2 = V(0, 0, 0) self._numberOfBases = 0 self._conformation = 'B-DNA' self.duplexRise = 3.18 self.basesPerTurn = 10 self.dnaModel = 'PAM3' _superclass.__init__(self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_WHATS_THIS_BUTTON) msg = "Use resize handles to resize the segments." self.updateMessage(msg) 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 """ #TODO: This is a temporary fix for a bug. When you invoke a #temporary mode entering such a temporary mode keeps the signals of #PM from the previous mode connected ( #but while exiting that temporary mode and reentering the #previous mode, it atucally reconnects the signal! This gives rise to #lots of bugs. This needs more general fix in Temporary mode API. # -- Ninad 2008-01-09 (similar comment exists in MovePropertyManager.py if isConnect and self.isAlreadyConnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to connect widgets"\ "in this PM that are already connected." ) return if not isConnect and self.isAlreadyDisconnected: if debug_flags.atom_debug: print_compact_stack("warning: attempt to disconnect widgets"\ "in this PM that are already disconnected.") return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self.segmentListWidget.connect_or_disconnect_signals(isConnect) change_connect(self.addSegmentsToolButton, SIGNAL("toggled(bool)"), self.activateAddSegmentsTool) change_connect(self.removeSegmentsToolButton, SIGNAL("toggled(bool)"), self.activateRemoveSegmentsTool) def _update_UI_do_updates(self): """ @see: Command_PropertyManager._update_UI_do_updates() @see: DnaSegment_EditCommand.model_changed() @see: DnaSegment_EditCommand.hasResizableStructure() @see: self._current_model_changed_params() """ currentParams = self._current_model_changed_params() #Optimization. Return from the model_changed method if the #params are the same. if same_vals(currentParams, self._previous_model_changed_params): return number_of_segments, isStructResizable, why_not = currentParams #update the self._previous_model_changed_params with this new param set. self._previous_model_changed_params = currentParams if not isStructResizable: if not number_of_segments == 0: #disable all widgets self._pmGroupBox1.setEnabled(False) msg = redmsg("DnaSegment is not resizable. Reason: %s" % (why_not)) self.updateMessage(msg) else: if not self._pmGroupBox1.isEnabled(): self._pmGroupBox1.setEnabled(True) msg = "Use resize handles to resize the segments" self.updateMessage(msg) self.updateListWidgets() ##self.command.updateHandlePositions() def _current_model_changed_params(self): """ Returns a tuple containing the parameters that will be compared against the previously stored parameters. This provides a quick test to determine whether to do more things in self.model_changed() @see: self.model_changed() which calls this @see: self._previous_model_changed_params attr. """ params = None if self.command: #update the list first. self.command.updateResizeSegmentList() number_of_segments = len(self.command.getResizeSegmentList()) isStructResizable, why_not = self.command.hasResizableStructure() params = (number_of_segments, isStructResizable, why_not) return params def isAddSegmentsToolActive(self): """ Returns True if the add segments tool (which adds the segments to the list of segments to be resized) is active """ if self.addSegmentsToolButton.isChecked(): #For safety if not self.removeSegmentsToolButton.isChecked(): return True return False def isRemoveSegmentsToolActive(self): """ Returns True if the remove segments tool (which removes the segments from the list of segments to be resized) is active """ if self.removeSegmentsToolButton.isChecked(): if not self.addSegmentsToolButton.isChecked(): #For safety return True return False def activateAddSegmentsTool(self, enable): """ Change the appearance of the list widget (that lists the dna segments to be resized) so as to indicate that the add dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the add segments tool is active. @type enable: bool """ if enable: if not self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(True) if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.segmentListWidget.setColor(lightgreen_2) else: if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def activateRemoveSegmentsTool(self, enable): """ Change the appearance of the list widget (that lists the dna segments to be resized) so as to indicate that the REMOVE dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the REMOVE segments tool is active. @type enable: bool """ if enable: if not self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(True) if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.segmentListWidget.setColor(lightred_1) else: if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def removeListWidgetItems(self): """ Removes selected atoms from the resize dna segment list widget Example: User selects a bunch of items in the list widget and hits delete key to remove the selected items from the list IMPORTANT NOTE: This method does NOT delete the correspoinging model item in the GLPane (i.e. corresponding dnasegment). It just 'removes' the item from the list widget (indicating its no longer being resized) This is intentional. """ self.segmentListWidget.deleteSelection() itemDict = self.segmentListWidget.getItemDictonary() self.command.setResizeStructList(itemDict.values()) self.updateListWidgets() self.win.win_update() def _addGroupBoxes(self): """ Add the Property Manager group boxes. """ self._pmGroupBox1 = PM_GroupBox(self, title="Segments for Resizing") self._loadGroupBox1(self._pmGroupBox1) self._displayOptionsGroupBox = PM_GroupBox(self, title="Display Options") self._loadDisplayOptionsGroupBox(self._displayOptionsGroupBox) def _loadGroupBox1(self, pmGroupBox): """ load widgets in groupbox1 """ self.segmentListWidget = PM_SelectionListWidget(pmGroupBox, self.win, label="", heightByRows=12) self.segmentListWidget.setFocusPolicy(Qt.StrongFocus) self.segmentListWidget.setFocus() self.setFocusPolicy(Qt.StrongFocus) self.addSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Add segments to the list", iconPath = "ui/actions/Properties Manager"\ "/AddSegment_To_ResizeSegmentList.png", spanWidth = True ) self.addSegmentsToolButton.setCheckable(True) self.addSegmentsToolButton.setAutoRaise(True) self.removeSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Remove segments from the list", iconPath = "ui/actions/Properties Manager"\ "/RemoveSegment_From_ResizeSegmentList.png", spanWidth = True ) self.removeSegmentsToolButton.setCheckable(True) self.removeSegmentsToolButton.setAutoRaise(True) #Widgets to include in the widget row. widgetList = [('QLabel', " Add/Remove Segments:", 0), ('QSpacerItem', 5, 5, 1), ('PM_ToolButton', self.addSegmentsToolButton, 2), ('QSpacerItem', 5, 5, 3), ('PM_ToolButton', self.removeSegmentsToolButton, 4), ('QSpacerItem', 5, 5, 5)] widgetRow = PM_WidgetRow(pmGroupBox, title='', widgetList=widgetList, label="", spanWidth=True) def _addWhatsThisText(self): """ Add what's this text. Abstract method. """ pass def show(self): """ Overrides the superclass method @see: self._deactivateAddRemoveSegmentsTool """ _superclass.show(self) ##self.updateListWidgets() self._deactivateAddRemoveSegmentsTool() def _deactivateAddRemoveSegmentsTool(self): """ Deactivate tools that allow adding or removing the segments to the segment list in the Property manager. This can be simply done by resetting the state of toolbuttons to False. Example: toolbuttons that add or remove segments to the segment list in the Property manager. When self.show is called these need to be unchecked. @see: self.isAddSegmentsToolActive() @see:self.isRemoveSegmentsToolActive() @see: self.show() """ self.addSegmentsToolButton.setChecked(False) self.removeSegmentsToolButton.setChecked(False) def listWidgetHasFocus(self): """ Checks if the list widget that lists dnasegments to be resized has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Dnasegment in the GLPane) @see: MultipleDnaSegment_GraphicsMode.keyPressEvent() where it is called """ if self.segmentListWidget.hasFocus(): return True return False def setParameters(self, params): pass def getParameters(self): return () def updateListWidgets(self): self.updateSegmentListWidget() def updateSegmentListWidget(self): """ Update the list of segments shown in the segments list widget @see: self.updateListWidgets, self.updateStrandListWidget """ segmentList = [] segmentList = self.command.getResizeSegmentList() self.segmentListWidget.insertItems(row=0, items=segmentList) def _connect_showCursorTextCheckBox(self): """ Connect the show cursor text checkbox with user prefs_key. Overrides DnaOrCnt_PropertyManager._connect_showCursorTextCheckBox """ connect_checkbox_with_boolean_pref( self.showCursorTextCheckBox, dnaSegmentEditCommand_showCursorTextCheckBox_prefs_key) def _params_for_creating_cursorTextCheckBoxes(self): """ Returns params needed to create various cursor text checkboxes connected to prefs_keys that allow custom cursor texts. @return: A list containing tuples in the following format: ('checkBoxTextString' , preference_key). PM_PrefsCheckBoxes uses this data to create checkboxes with the the given names and connects them to the provided preference keys. (Note that PM_PrefsCheckBoxes puts thes within a GroupBox) @rtype: list @see: PM_PrefsCheckBoxes @see: self._loadDisplayOptionsGroupBox where this list is used. @see: Superclass method which is overridden here -- DnaOrCnt_PropertyManager._params_for_creating_cursorTextCheckBoxes() """ params = \ [ #Format: (" checkbox text", prefs_key) ("Number of base pairs", dnaSegmentEditCommand_cursorTextCheckBox_numberOfBasePairs_prefs_key), ("Duplex length", dnaSegmentEditCommand_cursorTextCheckBox_length_prefs_key), ("Number of basepairs to be changed", dnaSegmentEditCommand_cursorTextCheckBox_changedBasePairs_prefs_key) ] return params
class ListWidgetItems_PM_Mixin: def _loadSegmentListWidget(self, pmGroupBox): self.segmentListWidget = PM_SelectionListWidget( pmGroupBox, self.win, label = "", heightByRows = 12) self.segmentListWidget.setFocusPolicy(Qt.StrongFocus) self.segmentListWidget.setFocus() self.setFocusPolicy(Qt.StrongFocus) self.addSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Add segments to the list", iconPath = "ui/actions/Properties Manager"\ "/AddSegment_To_ResizeSegmentList.png", spanWidth = True ) self.addSegmentsToolButton.setCheckable(True) self.addSegmentsToolButton.setAutoRaise(True) self.removeSegmentsToolButton = PM_ToolButton( pmGroupBox, text = "Remove segments from the list", iconPath = "ui/actions/Properties Manager"\ "/RemoveSegment_From_ResizeSegmentList.png", spanWidth = True ) self.removeSegmentsToolButton.setCheckable(True) self.removeSegmentsToolButton.setAutoRaise(True) #Widgets to include in the widget row. widgetList = [ ('QLabel', " Add/Remove Segments:", 0), ('QSpacerItem', 5, 5, 1), ('PM_ToolButton', self.addSegmentsToolButton, 2), ('QSpacerItem', 5, 5, 3), ('PM_ToolButton', self.removeSegmentsToolButton, 4), ('QSpacerItem', 5, 5, 5) ] widgetRow = PM_WidgetRow(pmGroupBox, title = '', widgetList = widgetList, label = "", spanWidth = True ) def listWidgetHasFocus(self): """ Checks if the list widget that lists dnasegments (that will undergo special operations such as 'resizing them at once or making crossovers between the segments etc) has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Dnasegment in the GLPane) @see: MultipleDnaSegment_GraphicsMode.keyPressEvent() where it is called """ if self.segmentListWidget.hasFocus(): return True return False def updateListWidgets(self): self.updateSegmentListWidget() def updateSegmentListWidget(self): """ Update the list of segments shown in the segments list widget @see: self.updateListWidgets, self.updateStrandListWidget """ segmentList = [] segmentList = self.command.getSegmentList() if segmentList: self.segmentListWidget.insertItems( row = 0, items = segmentList) else: self.segmentListWidget.clear() def isAddSegmentsToolActive(self): """ Returns True if the add segments tool (which adds the segments to the list of segments) is active """ if self.addSegmentsToolButton.isChecked(): #For safety if not self.removeSegmentsToolButton.isChecked(): return True return False def isRemoveSegmentsToolActive(self): """ Returns True if the remove segments tool (which removes the segments from the list of segments ) is active """ if self.removeSegmentsToolButton.isChecked(): if not self.addSegmentsToolButton.isChecked(): #For safety return True return False def activateAddSegmentsTool(self,enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the add dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the add segments tool is active. @type enable: bool """ if enable: if not self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(True) if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.segmentListWidget.setColor(lightgreen_2) self.command.logMessage('ADD_SEGMENTS_ACTIVATED') else: if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def activateRemoveSegmentsTool(self,enable): """ Change the appearance of the list widget (that lists the dna segments ) so as to indicate that the REMOVE dna segments tool is active @param enable: If True, changes the appearance of list widget to indicate that the REMOVE segments tool is active. @type enable: bool """ if enable: if not self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(True) if self.addSegmentsToolButton.isChecked(): self.addSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(False) self.command.logMessage('REMOVE_SEGMENTS_ACTIVATED') self.segmentListWidget.setColor(lightred_1) else: if self.removeSegmentsToolButton.isChecked(): self.removeSegmentsToolButton.setChecked(False) self.segmentListWidget.setAlternatingRowColors(True) self.segmentListWidget.resetColor() def _deactivateAddRemoveSegmentsTool(self): """ Deactivate tools that allow adding or removing the segments to the segment list in the Property manager. This can be simply done by resetting the state of toolbuttons to False. Example: toolbuttons that add or remove segments to the segment list in the Property manager. When self.show is called these need to be unchecked. @see: self.isAddSegmentsToolActive() @see:self.isRemoveSegmentsToolActive() @see: self.show() """ self.addSegmentsToolButton.setChecked(False) self.removeSegmentsToolButton.setChecked(False) def removeListWidgetItems(self): """ Removes selected itoms from the dna segment list widget Example: User selects a bunch of items in the list widget and hits delete key to remove the selected items from the list IMPORTANT NOTE: This method does NOT delete the correspoinging model item in the GLPane (i.e. corresponding dnasegment). It just 'removes' the item from the list widget This is intentional. """ self.segmentListWidget.deleteSelection() itemDict = self.segmentListWidget.getItemDictonary() self.command.setSegmentList(itemDict.values()) self.updateListWidgets() self.win.win_update()
class BuildProtein_PropertyManager(EditCommand_PM): """ The BuildProtein_PropertyManager class provides a Property Manager for the B{Build Protein} command. @ivar title: The title that appears in the property manager header. @type title: str @ivar pmName: The name of this property manager. This is used to set the name of the PM_Dialog object via setObjectName(). @type name: str @ivar iconPath: The relative path to the PNG file that contains a 22 x 22 icon image that appears in the PM header. @type iconPath: str """ title = "Build Protein" pmName = title iconPath = "ui/actions/Command Toolbar/BuildProtein/BuildProtein.png" current_protein = "" # name of the single selected peptide. To be deprecated soon. --Mark 2008-12-14 def __init__(self, command): """ Constructor for the Build Protein property manager. """ #Attributes for self._update_UI_do_updates() to keep track of changes #in these , since the last call of that method. These are used to #determine whether certain UI updates are needed. self._previousSelectionParams = None self._previousStructureParams = None self._previousCommandStackParams = None #see self.connect_or_disconnect_signals for comment about this flag self.isAlreadyConnected = False self.isAlreadyDisconnected = False EditCommand_PM.__init__(self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_CANCEL_BUTTON | \ PM_WHATS_THIS_BUTTON) 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 """ if isConnect and self.isAlreadyConnected: return if not isConnect and self.isAlreadyDisconnected: return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self.proteinListWidget.connect_or_disconnect_signals(isConnect) change_connect(self.editPeptidePropertiesButton, SIGNAL("clicked()"), self._editPeptide) change_connect(self.compareProteinsButton, SIGNAL("clicked()"), self._compareProteins) return def enable_or_disable_gui_actions(self, bool_enable=False): """ Enable or disable some gui actions when this property manager is opened or closed, depending on the bool_enable. """ #For new command API, we will always show the exit button to check #if Exit button really exits the subcommand and the parent command #(earlier there were bugs) . Regaring 'whether this should be the #default behavior', its a UI design issue and we will worry about it #later -- Ninad 2008-08-27 (based on an email exchanged with Bruce) pass def _update_UI_do_updates(self): """ Overrides superclass method. @see: Command_PropertyManager._update_UI_do_updates() """ newSelectionParams = self._currentSelectionParams() current_struct_params = self._currentStructureParams() selection_params_unchanged = same_vals(newSelectionParams, self._previousSelectionParams) #introducing self._previousStructureParams and #adding structure_params_unchanged check to the 'if' condition below #fixes bug 2910. structure_params_unchanged = same_vals(self._previousStructureParams, current_struct_params) current_command_stack_params = self._currentCommandStackParams() #Check if command stack params changed since last call of this #PM update method. This is used to fix bugs like 2940 command_stack_params_unchanged = same_vals( self._previousCommandStackParams, current_command_stack_params) #No need to proceed if any of the selection/ structure and commandstack #parameters remained unchanged since last call. --- [CONDITION A] if selection_params_unchanged and structure_params_unchanged and command_stack_params_unchanged: #This second condition above fixes bug 2888 if 0: print "Build Protein: _update_UI_do_updates() - DO NOTHING" return self._previousStructureParams = current_struct_params self._previousSelectionParams = newSelectionParams self._previousCommandStackParams = current_command_stack_params ##if not selection_params_unchanged or not command_stack_params_unchanged and structure_params_unchanged: if structure_params_unchanged: #NOTE: We checked if either of the selection struct or command stack #parameters or both changed. (this was referred as '[CONDITION A]' #above). So, this condition (structure_params_unchanged)also means #either selection or command stack or both parameters were changed. if not command_stack_params_unchanged: #update the protein list widget *before* updating the selection if #the command stack changed. This ensures that the selection box #appears around the list widget items that are selected. self.updateProteinListWidget() selectedProteins = newSelectionParams self.proteinListWidget.updateSelection(selectedProteins) # Enable/disable "Edit Sequence" button. if len(selectedProteins) == 1: self.editPeptidePropertiesButton.setEnabled(True) else: self.editPeptidePropertiesButton.setEnabled(False) # Enable/disable "Compare Proteins" button. if len(selectedProteins) == 2: self.compareProteinsButton.setEnabled(True) else: self.compareProteinsButton.setEnabled(False) return self.updateProteinListWidget() return def _currentCommandStackParams(self): """ The return value is supposed to be used by BUILD_PROTEIN command PM ONLY and NOT by any subclasses. Returns a tuple containing current command stack change indicator and the name of the command 'BUILD_PROTEIN'. These parameters are then used to decide whether updating widgets in this property manager is needed, when self._update_UI_do_updates() is called. @NOTE: - Command_PropertyManager.update_UI() already does a check to see if any of the global change indicators in assembly (command_stack_change, model_change, selection_change) changed since last call and then only calls self._update_UI_do_updates(). - But this method is just used to keep track of the local command stack change counter in order to update the list widgets. - This is used to fix bug 2940 @see: self._update_UI_do_updates() """ commandStackCounter = self.command.assy.command_stack_change_indicator( ) #Append 'BUILD_PROTEIN to the tuple to be returned. This is just to remind #us that this method is meant for BUILD_PROTEIN command PM only. (and not #by any subclasses) Should we assert this? I think it will slow things #down so this comment is enough -- Ninad 2008-09-30 return (commandStackCounter, 'BUILD_PROTEIN') def _currentSelectionParams(self): """ Returns a tuple containing current selection parameters. These parameters are then used to decide whether updating widgets in this property manager is needed when L{self.model_changed} method is called. @return: A tuple that contains total number of selected peptides. @rtype: tuple @NOTE: This method may be renamed in future. It's possible that there are other groupboxes in the PM that need to be updated when something changes in the glpane. """ selectedProteins = [] if self.command is not None: # and self.command.hasValidStructure(): selectedProteins = self.win.assy.getSelectedProteinChunks() return (selectedProteins) def _currentStructureParams(self): """ Return current structure parameters of interest to self.model_changed. Right now it only returns the number of peptides within the structure (or None). This is a good enough check (and no need to compare each and every peptide within the structure with a previously stored set of strands). """ #Can it happen that the total number of peptides remains the same even #after some alterations to the peptides? Unlikely. (Example: a single #(future) Break peptide operation will increase the number of peptides #by one. Or Join peptides decrease it by 1) params = None if self.command: # and self.command.hasValidStructure(): proteinList = [] proteinList = getAllProteinChunksInPart(self.win.assy) params = len(proteinList) return params def close(self): """ Closes the Property Manager. Overrides EditCommand_PM.close() """ #Clear tags, if any, due to the selection in the self.strandListWidget. #self.proteinListWidget.clear() env.history.statusbar_msg("") EditCommand_PM.close(self) return def show(self): """ Show the PM. Extends superclass method. @note: _update_UI_do_updates() gets called immediately after this and updates PM widgets with their correct values/settings. """ env.history.statusbar_msg("") EditCommand_PM.show(self) # NOTE: Think about moving this msg to _update_UI_do_updates() where # custom msgs can be created based on the current selection, etc. # Mark 2008-12-14 msg = "Select <b>Insert Peptide</b> to create a peptide chain or "\ "select another modeling tool to modify an existing protein." self.updateMessage(msg) return def _editPeptide(self): """ Slot for the "Edit Properties" button. """ #if not self.command.hasValidStructure(): # return proteinChunk = self.win.assy.getSelectedProteinChunk() if proteinChunk: proteinChunk.protein.edit(self.win) return def _compareProteins(self): """ Slot for the "Compare Proteins" button. """ self.win.commandSequencer.userEnterCommand('COMPARE_PROTEINS') return def _addWhatsThisText(self): """ What's This text for widgets in the DNA Property Manager. """ pass def _addToolTipText(self): """ Tool Tip text for widgets in the DNA Property Manager. """ pass def _addGroupBoxes(self): """ Add the Build Protein Property Manager group boxes. """ self._pmGroupBox1 = PM_GroupBox(self, title="Peptides") self._loadGroupBox1(self._pmGroupBox1) return def _loadGroupBox1(self, pmGroupBox): """ Load widgets in groupbox1. """ self.proteinListWidget = PM_SelectionListWidget(pmGroupBox, self.win, label="", heightByRows=6) self.proteinListWidget.setObjectName('Peptide_list_widget') self.proteinListWidget.setTagInstruction('PICK_ITEM_IN_GLPANE') self.editPeptidePropertiesButton = PM_PushButton( pmGroupBox, label="", text="Edit Properties...") self.editPeptidePropertiesButton.setEnabled(False) self.compareProteinsButton = PM_PushButton(pmGroupBox, label="", text="Compare Proteins...") self.compareProteinsButton.setEnabled(False) return def updateProteinListWidget(self): """ Update the peptide list widget. It shows all peptides in the part. """ proteinChunkList = getAllProteinChunksInPart(self.win.assy) if proteinChunkList: self.proteinListWidget.insertItems(row=0, items=proteinChunkList) else: self.proteinListWidget.clear() return
class BuildNanotube_PropertyManager(EditCommand_PM): """ The BuildNanotube_PropertyManager class provides a Property Manager for the B{Build > CNT } command. @ivar title: The title that appears in the property manager header. @type title: str @ivar pmName: The name of this property manager. This is used to set the name of the PM_Dialog object via setObjectName(). @type name: str @ivar iconPath: The relative path to the PNG file that contains a 22 x 22 icon image that appears in the PM header. @type iconPath: str """ title = "Build Nanotube" pmName = title iconPath = "ui/actions/Command Toolbar/BuildNanotube/BuildNanotube.png" def __init__( self, command ): """ Constructor for the Build Nanotube property manager. """ #Attributes for self._update_UI_do_updates() to keep track of changes #in these , since the last call of that method. These are used to #determine whether certain UI updates are needed. self._previousSelectionParams = None self._previousStructureParams = None self._previousCommandStackParams = None #see self.connect_or_disconnect_signals for comment about this flag self.isAlreadyConnected = False self.isAlreadyDisconnected = False EditCommand_PM.__init__( self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_WHATS_THIS_BUTTON) 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 """ #TODO: This is a temporary fix for a bug. When you invoke a temporary #mode, entering such a temporary mode keeps the signals of PM from the #previous mode connected (but while exiting that temporary mode and #reentering the previous mode, it actually reconnects the signal! #This gives rise to lots of bugs. This needs a more general fix in #the Temporary mode API. # -- Ninad 2008-01-09 (similar comment exists in MovePropertyManager.py if isConnect and self.isAlreadyConnected: return if not isConnect and self.isAlreadyDisconnected: return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self.nanotubeListWidget.connect_or_disconnect_signals(isConnect) change_connect(self.editNanotubePropertiesButton, SIGNAL("clicked()"), self._editNanotube) return def enable_or_disable_gui_actions(self, bool_enable = False): """ Enable or disable some gui actions when this property manager is opened or closed, depending on the bool_enable. """ #For new command API, we will always show the exit button to check #if Exit button really exits the subcommand and the parent command #(earlier there were bugs) . Regaring 'whether this should be the #default behavior', its a UI design issue and we will worry about it #later -- Ninad 2008-08-27 (based on an email exchanged with Bruce) pass def _update_UI_do_updates(self): """ Overrides superclass method. @see: Command_PropertyManager._update_UI_do_updates() """ newSelectionParams = self._currentSelectionParams() current_struct_params = self._currentStructureParams() selection_params_unchanged = same_vals(newSelectionParams, self._previousSelectionParams) #introducing self._previousStructureParams and #adding structure_params_unchanged check to the 'if' condition below #fixes bug 2910. structure_params_unchanged = same_vals(self._previousStructureParams, current_struct_params) current_command_stack_params = self._currentCommandStackParams() #Check if command stack params changed since last call of this #PM update method. This is used to fix bugs like 2940 command_stack_params_unchanged = same_vals( self._previousCommandStackParams, current_command_stack_params) #No need to proceed if any of the selection/ structure and commandstack #parameters remained unchanged since last call. --- [CONDITION A] if selection_params_unchanged and \ structure_params_unchanged and \ command_stack_params_unchanged: return self._previousStructureParams = current_struct_params self._previousSelectionParams = newSelectionParams self._previousCommandStackParams = current_command_stack_params if structure_params_unchanged: #NOTE: We checked if either of the selection struct or command stack #parameters or both changed. (this was referred as '[CONDITION A]' #above). So, this condition (structure_params_unchanged)also means #either selection or command stack or both parameters were changed. if not command_stack_params_unchanged: #update the nanotube list widget *before* updating the selection if #the command stack changed. This ensures that the selection box #appears around the list widget items that are selected. self.updateNanotubesListWidget() selectedNanotubeSegments = newSelectionParams self.nanotubeListWidget.updateSelection(selectedNanotubeSegments) self.updateNanotubePropertiesButton() return self.updateNanotubesListWidget() return def _currentCommandStackParams(self): """ The return value is supposed to be used by BUILD_NANOTUBE command PM ONLY and NOT by any subclasses. Returns a tuple containing current command stack change indicator and the name of the command 'BUILD_NANOTUBE'. These parameters are then used to decide whether updating widgets in this property manager is needed, when self._update_UI_do_updates() is called. @NOTE: - Command_PropertyManager.update_UI() already does a check to see if any of the global change indicators in assembly (command_stack_change, model_change, selection_change) changed since last call and then only calls self._update_UI_do_updates(). - But this method is just used to keep track of the local command stack change counter in order to update the list widgets. - This is used to fix bug 2940 @see: self._update_UI_do_updates() """ commandStackCounter = self.command.assy.command_stack_change_indicator() #Append 'BUILD_NANOTUBE to the tuple to be returned. This is just to remind #us that this method is meant for BUILD_NANOTUBE command PM only. (and not #by any subclasses) Should we assert this? I think it will slow things #down so this comment is enough -- Ninad 2008-09-30 return (commandStackCounter, 'BUILD_NANOTUBE') def _currentSelectionParams(self): """ Returns a tuple containing current selection parameters. These parameters are then used to decide whether updating widgets in this property manager is needed when L{self.model_changed} method is called. @return: A tuple that contains total number of selected nanotubes. @rtype: tuple @NOTE: This method may be renamed in future. It's possible that there are other groupboxes in the PM that need to be updated when something changes in the glpane. """ selectedNanotubeSegments = [] if self.command is not None: # and self.command.hasValidStructure(): selectedNanotubeSegments = self.win.assy.getSelectedNanotubeSegments() return (selectedNanotubeSegments) def _currentStructureParams(self): """ Return current structure parameters of interest to self.model_changed. Right now it only returns the number of nanotubes within the structure (or None). This is a good enough check (and no need to compare each and every nanotube within the structure with a previously stored set of strands). """ params = None if self.command: # and self.command.hasValidStructure(): nanotubeSegmentList = [] nanotubeSegmentList = getAllNanotubeSegmentsInPart(self.win.assy) params = len(nanotubeSegmentList) return params def close(self): """ Closes the Property Manager. Overrides EditCommand_PM.close() """ #Clear tags, if any, due to the selection in the self.strandListWidget. #self.nanotubeListWidget.clear() env.history.statusbar_msg("") EditCommand_PM.close(self) return def show(self): """ Show the PM. Extends superclass method. @note: _update_UI_do_updates() gets called immediately after this and updates PM widgets with their correct values/settings. """ env.history.statusbar_msg("") EditCommand_PM.show(self) # NOTE: Think about moving this msg to _update_UI_do_updates() where # custom msgs can be created based on the current selection, etc. # Mark 2008-12-14 msg = "Select <b>Insert Nanotube</b> to create a nanotube or "\ "select an existing nantube to modify it." self.updateMessage(msg) return def _editNanotube(self): """ Slot for the "Edit Properties" button. """ #if not self.command.hasValidStructure(): # return nanotubeSegment = self.win.assy.getSelectedNanotubeSegment() if nanotubeSegment: nanotubeSegment.edit() return def _addWhatsThisText( self ): """ What's This text for widgets in the CNT Property Manager. """ pass def _addToolTipText(self): """ Tool Tip text for widgets in the CNT Property Manager. """ pass def _addGroupBoxes( self ): """ Add the Nanotube Property Manager group boxes. """ self._pmGroupBox1 = PM_GroupBox( self, title = "Nanotubes" ) self._loadGroupBox1( self._pmGroupBox1 ) return def _loadGroupBox1(self, pmGroupBox): """ load widgets in groupbox1 """ self.nanotubeListWidget = PM_SelectionListWidget(pmGroupBox, self.win, label = "", heightByRows = 12) self.nanotubeListWidget.setObjectName('nanotubeListWidget') self.nanotubeListWidget.setTagInstruction('PICK_ITEM_IN_GLPANE') self.editNanotubePropertiesButton = PM_PushButton(pmGroupBox, label = "", text = "Edit Properties..." ) self.editNanotubePropertiesButton.setEnabled(False) return def updateNanotubesListWidget(self): """ Updates the nanotubes (selection) groupbox. This includes both the nanotube selection list widget (showing all nanotubes in the part) and the B{Edit Properties} button just below it (enabled if only one of the nanotubes is selected). """ nanotubeSegmentList = getAllNanotubeSegmentsInPart(self.win.assy) if nanotubeSegmentList: self.nanotubeListWidget.insertItems( row = 0, items = nanotubeSegmentList) else: self.nanotubeListWidget.clear() self.updateNanotubePropertiesButton() return def updateNanotubePropertiesButton(self): """ Enables the B{Edit Properties} button if a single nanotube is currently selected. Otherwise, the button is disabled. """ self.editNanotubePropertiesButton.setEnabled( bool(self.win.assy.getSelectedNanotubeSegment())) return
class DnaOrCnt_PropertyManager(EditCommand_PM): """ DnaOrCnt_PropertyManager class provides common functionality (e.g. groupboxes etc) to the subclasses that define various Dna and Cnt (Carbon nanotube) Property Managers. @see: DnaSegment_PropertyManager (subclass) @see: InsertDna_PropertyManager (subclass) """ def __init__(self, command): """ Constructor for the DNA Duplex property manager. """ self._cursorTextGroupBox = None self._colorChooser = None self.showCursorTextCheckBox = None self.referencePlaneListWidget = None #For model changed signal #@see: self.model_changed() and self._current_model_changed_params #for example use self._previous_model_changed_params = None #see self.connect_or_disconnect_signals for comment about this flag self.isAlreadyConnected = False self.isAlreadyDisconnected = False _superclass.__init__(self, command) def show(self): """ Show this PM """ _superclass.show(self) if isinstance(self.showCursorTextCheckBox, PM_CheckBox): self._update_state_of_cursorTextGroupBox( self.showCursorTextCheckBox.isChecked()) def _loadDisplayOptionsGroupBox(self, pmGroupBox): """ Load widgets in the Display Options GroupBox """ self._loadCursorTextGroupBox(pmGroupBox) def _loadColorChooser(self, pmGroupBox): self._colorChooser = PM_ColorComboBox(pmGroupBox) def _loadCursorTextGroupBox(self, pmGroupBox): """ Load various checkboxes within the cursor text groupbox. @see: self. _loadDisplayOptionsGroupBox() @see: self._connect_showCursorTextCheckBox() @see: self._params_for_creating_cursorTextCheckBoxes() """ self.showCursorTextCheckBox = \ PM_CheckBox( pmGroupBox, text = "Show cursor text", widgetColumn = 0, state = Qt.Checked) self._connect_showCursorTextCheckBox() paramsForCheckBoxes = self._params_for_creating_cursorTextCheckBoxes() self._cursorTextGroupBox = PM_PrefsCheckBoxes( pmGroupBox, paramsForCheckBoxes=paramsForCheckBoxes, title='Cursor text options:') def connect_or_disconnect_signals(self, isConnect): if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect if self._colorChooser: change_connect(self._colorChooser, SIGNAL("editingFinished()"), self._changeStructureColor) pass def _connect_showCursorTextCheckBox(self): """ Connect the show cursor text checkbox with user prefs_key. Subclasses should override this method. The default implementation does nothing. """ pass def _params_for_creating_cursorTextCheckBoxes(self): """ Subclasses should override this method. The default implementation returns an empty list. Returns params needed to create various cursor text checkboxes connected to prefs_keys that allow custom cursor texts. @return: A list containing tuples in the following format: ('checkBoxTextString' , preference_key). PM_PrefsCheckBoxes uses this data to create checkboxes with the the given names and connects them to the provided preference keys. (Note that PM_PrefsCheckBoxes puts thes within a GroupBox) @rtype: list @see: PM_PrefsCheckBoxes @see: self._loadDisplayOptionsGroupBox where this list is used. #see: self._loadCursorTextGroupBox() @see: subclass method: DnaSegment_PropertyManager._params_for_creating_cursorTextCheckBoxes() """ params = [] #Format: (" checkbox text", prefs_key) return params def _update_state_of_cursorTextGroupBox(self, enable): """ """ if not isinstance(self._cursorTextGroupBox, PM_PrefsCheckBoxes): return if enable: self._cursorTextGroupBox.setEnabled(True) else: self._cursorTextGroupBox.setEnabled(False) def _loadReferencePlaneGroupBox(self, pmGroupBox): """ Load widgets in reference plane groupbox @see: InsertDna_PropertyManager._addGroupBoxes where this groupbox is added. """ # Placement Options radio button list to create radio button list. # Format: buttonId, buttonText, tooltip PLACEMENT_OPTIONS_BUTTON_LIST = [ \ ( 0, "Parallel to screen (default)", "Parallel to screen" ), ( 1, "On the specified plane:", "On specified plane" )] self._placementOptions = \ PM_RadioButtonList( pmGroupBox, ##label = "Duplex Placement Options:", buttonList = PLACEMENT_OPTIONS_BUTTON_LIST, checkedId = 0, spanWidth = True, borders = False) self._specifyReferencePlane_radioButton = self._placementOptions.getButtonById( 1) self.referencePlaneListWidget = PM_SelectionListWidget(pmGroupBox, self.win, label="", heightByRows=2) def useSpecifiedDrawingPlane(self): """ Tells if the the command (rather the graphicsmode) should use the user specified drawing plane on which the structure (such as dna duplex or CNT) will be created. Returns True if a Palne is specified by the user AND 'use specified plane' radio button in the Property manager is checked. @see: InsertDna_GraphicsMode.getDrawingPlane() """ if self.referencePlaneListWidget is None: return False if self._specifyReferencePlane_radioButton.isChecked(): itemDict = self.referencePlaneListWidget.getItemDictonary() planeList = itemDict.values() if len(planeList) == 1: return True return False def activateSpecifyReferencePlaneTool(self, index): """ Slot method that changes the appearance of some ui elements, suggesting that the Specify reference plane tool is active. @see: self.isSpecifyPlaneToolActive() """ if self.referencePlaneListWidget is None: return if index == 0: self.referencePlaneListWidget.resetColor() else: itemDict = self.referencePlaneListWidget.getItemDictonary() planeList = itemDict.values() if len(planeList) == 0: self.referencePlaneListWidget.setColor(lightgreen_2) else: self.referencePlaneListWidget.resetColor() def isSpecifyPlaneToolActive(self): """ Returns True if the add segments tool (which adds the segments to the list of segments) is active @see: InsertDna_EditCommand.isSpecifyPlaneToolActive() @see: InsertDna_GraphicsMode.isSpecifyPlaneToolActive() @see: InsertDna_GraphicsMode.jigLeftUp() """ if self.referencePlaneListWidget is None: return False if self._specifyReferencePlane_radioButton.isChecked(): itemDict = self.referencePlaneListWidget.getItemDictonary() planeList = itemDict.values() if len(planeList) == 1: return False else: return True return False def removeListWidgetItems(self): """ Removes all the items in the list widget @TODO: At the moment the list widget means 'self.referencePlaneListWidget' the method name needs renaming if there are some more list widgets in the Property manager. """ if self.referencePlaneListWidget is None: return self.referencePlaneListWidget.insertItems(row=0, items=()) self.referencePlaneListWidget.setColor(lightgreen_2) def updateReferencePlaneListWidget(self, plane=None): """ Update the reference plane list widget by replacing the current item (if any) with the specified <plane >. This plane object (if not None) will be used as a referecne plane on which the structure will be constructed. @param plane: Plane object to be """ if self.referencePlaneListWidget is None: return planeList = [] if plane is not None: planeList = [plane] self.referencePlaneListWidget.insertItems(row=0, items=planeList) def listWidgetHasFocus(self): """ Checks if the list widget that lists the referecne plane, on which the dna will be created, has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Plane in the GLPane) @see: InsertDna_GraphicsMode.keyPressEvent() where this is called """ if self.referencePlaneListWidget and \ self.referencePlaneListWidget.hasFocus(): return True return False def _changeStructureColor(self): """ """ if self._colorChooser is None: return if self.command and self.command.hasValidStructure(): color = self._colorChooser.getColor() if hasattr(self.command.struct, 'setColor'): self.command.struct.setColor(color) self.win.glpane.gl_update()
class DnaOrCnt_PropertyManager(EditCommand_PM): """ DnaOrCnt_PropertyManager class provides common functionality (e.g. groupboxes etc) to the subclasses that define various Dna and Cnt (Carbon nanotube) Property Managers. @see: DnaSegment_PropertyManager (subclass) @see: InsertDna_PropertyManager (subclass) """ def __init__( self, command ): """ Constructor for the DNA Duplex property manager. """ self._cursorTextGroupBox = None self._colorChooser = None self.showCursorTextCheckBox = None self.referencePlaneListWidget = None #For model changed signal #@see: self.model_changed() and self._current_model_changed_params #for example use self._previous_model_changed_params = None #see self.connect_or_disconnect_signals for comment about this flag self.isAlreadyConnected = False self.isAlreadyDisconnected = False _superclass.__init__( self, command) def show(self): """ Show this PM """ _superclass.show(self) if isinstance(self.showCursorTextCheckBox, PM_CheckBox): self._update_state_of_cursorTextGroupBox( self.showCursorTextCheckBox.isChecked()) def _loadDisplayOptionsGroupBox(self, pmGroupBox): """ Load widgets in the Display Options GroupBox """ self._loadCursorTextGroupBox(pmGroupBox) def _loadColorChooser(self, pmGroupBox): self._colorChooser = PM_ColorComboBox(pmGroupBox) def _loadCursorTextGroupBox(self, pmGroupBox): """ Load various checkboxes within the cursor text groupbox. @see: self. _loadDisplayOptionsGroupBox() @see: self._connect_showCursorTextCheckBox() @see: self._params_for_creating_cursorTextCheckBoxes() """ self.showCursorTextCheckBox = \ PM_CheckBox( pmGroupBox, text = "Show cursor text", widgetColumn = 0, state = Qt.Checked) self._connect_showCursorTextCheckBox() paramsForCheckBoxes = self._params_for_creating_cursorTextCheckBoxes() self._cursorTextGroupBox = PM_PrefsCheckBoxes( pmGroupBox, paramsForCheckBoxes = paramsForCheckBoxes, title = 'Cursor text options:') def connect_or_disconnect_signals(self, isConnect): if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect if self._colorChooser: change_connect(self._colorChooser, SIGNAL("editingFinished()"), self._changeStructureColor) pass def _connect_showCursorTextCheckBox(self): """ Connect the show cursor text checkbox with user prefs_key. Subclasses should override this method. The default implementation does nothing. """ pass def _params_for_creating_cursorTextCheckBoxes(self): """ Subclasses should override this method. The default implementation returns an empty list. Returns params needed to create various cursor text checkboxes connected to prefs_keys that allow custom cursor texts. @return: A list containing tuples in the following format: ('checkBoxTextString' , preference_key). PM_PrefsCheckBoxes uses this data to create checkboxes with the the given names and connects them to the provided preference keys. (Note that PM_PrefsCheckBoxes puts thes within a GroupBox) @rtype: list @see: PM_PrefsCheckBoxes @see: self._loadDisplayOptionsGroupBox where this list is used. #see: self._loadCursorTextGroupBox() @see: subclass method: DnaSegment_PropertyManager._params_for_creating_cursorTextCheckBoxes() """ params = [] #Format: (" checkbox text", prefs_key) return params def _update_state_of_cursorTextGroupBox(self, enable): """ """ if not isinstance(self._cursorTextGroupBox, PM_PrefsCheckBoxes): return if enable: self._cursorTextGroupBox.setEnabled(True) else: self._cursorTextGroupBox.setEnabled(False) def _loadReferencePlaneGroupBox(self, pmGroupBox): """ Load widgets in reference plane groupbox @see: InsertDna_PropertyManager._addGroupBoxes where this groupbox is added. """ # Placement Options radio button list to create radio button list. # Format: buttonId, buttonText, tooltip PLACEMENT_OPTIONS_BUTTON_LIST = [ \ ( 0, "Parallel to screen (default)", "Parallel to screen" ), ( 1, "On the specified plane:", "On specified plane" )] self._placementOptions = \ PM_RadioButtonList( pmGroupBox, ##label = "Duplex Placement Options:", buttonList = PLACEMENT_OPTIONS_BUTTON_LIST, checkedId = 0, spanWidth = True, borders = False) self._specifyReferencePlane_radioButton = self._placementOptions.getButtonById(1) self.referencePlaneListWidget = PM_SelectionListWidget( pmGroupBox, self.win, label = "", heightByRows = 2) def useSpecifiedDrawingPlane(self): """ Tells if the the command (rather the graphicsmode) should use the user specified drawing plane on which the structure (such as dna duplex or CNT) will be created. Returns True if a Palne is specified by the user AND 'use specified plane' radio button in the Property manager is checked. @see: InsertDna_GraphicsMode.getDrawingPlane() """ if self.referencePlaneListWidget is None: return False if self._specifyReferencePlane_radioButton.isChecked(): itemDict = self.referencePlaneListWidget.getItemDictonary() planeList = itemDict.values() if len(planeList) == 1: return True return False def activateSpecifyReferencePlaneTool(self, index): """ Slot method that changes the appearance of some ui elements, suggesting that the Specify reference plane tool is active. @see: self.isSpecifyPlaneToolActive() """ if self.referencePlaneListWidget is None: return if index == 0: self.referencePlaneListWidget.resetColor() else: itemDict = self.referencePlaneListWidget.getItemDictonary() planeList = itemDict.values() if len(planeList) == 0: self.referencePlaneListWidget.setColor(lightgreen_2) else: self.referencePlaneListWidget.resetColor() def isSpecifyPlaneToolActive(self): """ Returns True if the add segments tool (which adds the segments to the list of segments) is active @see: InsertDna_EditCommand.isSpecifyPlaneToolActive() @see: InsertDna_GraphicsMode.isSpecifyPlaneToolActive() @see: InsertDna_GraphicsMode.jigLeftUp() """ if self.referencePlaneListWidget is None: return False if self._specifyReferencePlane_radioButton.isChecked(): itemDict = self.referencePlaneListWidget.getItemDictonary() planeList = itemDict.values() if len(planeList) == 1: return False else: return True return False def removeListWidgetItems(self): """ Removes all the items in the list widget @TODO: At the moment the list widget means 'self.referencePlaneListWidget' the method name needs renaming if there are some more list widgets in the Property manager. """ if self.referencePlaneListWidget is None: return self.referencePlaneListWidget.insertItems( row = 0, items = ()) self.referencePlaneListWidget.setColor(lightgreen_2) def updateReferencePlaneListWidget(self, plane = None): """ Update the reference plane list widget by replacing the current item (if any) with the specified <plane >. This plane object (if not None) will be used as a referecne plane on which the structure will be constructed. @param plane: Plane object to be """ if self.referencePlaneListWidget is None: return planeList = [ ] if plane is not None: planeList = [plane] self.referencePlaneListWidget.insertItems( row = 0, items = planeList) def listWidgetHasFocus(self): """ Checks if the list widget that lists the referecne plane, on which the dna will be created, has the Qt focus. This is used to just remove items from the list widget (without actually 'deleting' the corresponding Plane in the GLPane) @see: InsertDna_GraphicsMode.keyPressEvent() where this is called """ if self.referencePlaneListWidget and \ self.referencePlaneListWidget.hasFocus(): return True return False def _changeStructureColor(self): """ """ if self._colorChooser is None: return if self.command and self.command.hasValidStructure(): color = self._colorChooser.getColor() if hasattr(self.command.struct, 'setColor'): self.command.struct.setColor(color) self.win.glpane.gl_update()
class BuildProtein_PropertyManager(EditCommand_PM): """ The BuildProtein_PropertyManager class provides a Property Manager for the B{Build Protein} command. @ivar title: The title that appears in the property manager header. @type title: str @ivar pmName: The name of this property manager. This is used to set the name of the PM_Dialog object via setObjectName(). @type name: str @ivar iconPath: The relative path to the PNG file that contains a 22 x 22 icon image that appears in the PM header. @type iconPath: str """ title = "Build Protein" pmName = title iconPath = "ui/actions/Command Toolbar/BuildProtein/BuildProtein.png" current_protein = "" # name of the single selected peptide. To be deprecated soon. --Mark 2008-12-14 def __init__( self, command): """ Constructor for the Build Protein property manager. """ #Attributes for self._update_UI_do_updates() to keep track of changes #in these , since the last call of that method. These are used to #determine whether certain UI updates are needed. self._previousSelectionParams = None self._previousStructureParams = None self._previousCommandStackParams = None #see self.connect_or_disconnect_signals for comment about this flag self.isAlreadyConnected = False self.isAlreadyDisconnected = False EditCommand_PM.__init__( self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_CANCEL_BUTTON | \ PM_WHATS_THIS_BUTTON) 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 """ if isConnect and self.isAlreadyConnected: return if not isConnect and self.isAlreadyDisconnected: return self.isAlreadyConnected = isConnect self.isAlreadyDisconnected = not isConnect if isConnect: change_connect = self.win.connect else: change_connect = self.win.disconnect self.proteinListWidget.connect_or_disconnect_signals(isConnect) change_connect(self.editPeptidePropertiesButton, SIGNAL("clicked()"), self._editPeptide) change_connect(self.compareProteinsButton, SIGNAL("clicked()"), self._compareProteins) return def enable_or_disable_gui_actions(self, bool_enable = False): """ Enable or disable some gui actions when this property manager is opened or closed, depending on the bool_enable. """ #For new command API, we will always show the exit button to check #if Exit button really exits the subcommand and the parent command #(earlier there were bugs) . Regaring 'whether this should be the #default behavior', its a UI design issue and we will worry about it #later -- Ninad 2008-08-27 (based on an email exchanged with Bruce) pass def _update_UI_do_updates(self): """ Overrides superclass method. @see: Command_PropertyManager._update_UI_do_updates() """ newSelectionParams = self._currentSelectionParams() current_struct_params = self._currentStructureParams() selection_params_unchanged = same_vals(newSelectionParams, self._previousSelectionParams) #introducing self._previousStructureParams and #adding structure_params_unchanged check to the 'if' condition below #fixes bug 2910. structure_params_unchanged = same_vals(self._previousStructureParams, current_struct_params) current_command_stack_params = self._currentCommandStackParams() #Check if command stack params changed since last call of this #PM update method. This is used to fix bugs like 2940 command_stack_params_unchanged = same_vals( self._previousCommandStackParams, current_command_stack_params) #No need to proceed if any of the selection/ structure and commandstack #parameters remained unchanged since last call. --- [CONDITION A] if selection_params_unchanged and structure_params_unchanged and command_stack_params_unchanged: #This second condition above fixes bug 2888 if 0: print "Build Protein: _update_UI_do_updates() - DO NOTHING" return self._previousStructureParams = current_struct_params self._previousSelectionParams = newSelectionParams self._previousCommandStackParams = current_command_stack_params ##if not selection_params_unchanged or not command_stack_params_unchanged and structure_params_unchanged: if structure_params_unchanged: #NOTE: We checked if either of the selection struct or command stack #parameters or both changed. (this was referred as '[CONDITION A]' #above). So, this condition (structure_params_unchanged)also means #either selection or command stack or both parameters were changed. if not command_stack_params_unchanged: #update the protein list widget *before* updating the selection if #the command stack changed. This ensures that the selection box #appears around the list widget items that are selected. self.updateProteinListWidget() selectedProteins = newSelectionParams self.proteinListWidget.updateSelection(selectedProteins) # Enable/disable "Edit Sequence" button. if len(selectedProteins) == 1: self.editPeptidePropertiesButton.setEnabled(True) else: self.editPeptidePropertiesButton.setEnabled(False) # Enable/disable "Compare Proteins" button. if len(selectedProteins) == 2: self.compareProteinsButton.setEnabled(True) else: self.compareProteinsButton.setEnabled(False) return self.updateProteinListWidget() return def _currentCommandStackParams(self): """ The return value is supposed to be used by BUILD_PROTEIN command PM ONLY and NOT by any subclasses. Returns a tuple containing current command stack change indicator and the name of the command 'BUILD_PROTEIN'. These parameters are then used to decide whether updating widgets in this property manager is needed, when self._update_UI_do_updates() is called. @NOTE: - Command_PropertyManager.update_UI() already does a check to see if any of the global change indicators in assembly (command_stack_change, model_change, selection_change) changed since last call and then only calls self._update_UI_do_updates(). - But this method is just used to keep track of the local command stack change counter in order to update the list widgets. - This is used to fix bug 2940 @see: self._update_UI_do_updates() """ commandStackCounter = self.command.assy.command_stack_change_indicator() #Append 'BUILD_PROTEIN to the tuple to be returned. This is just to remind #us that this method is meant for BUILD_PROTEIN command PM only. (and not #by any subclasses) Should we assert this? I think it will slow things #down so this comment is enough -- Ninad 2008-09-30 return (commandStackCounter, 'BUILD_PROTEIN') def _currentSelectionParams(self): """ Returns a tuple containing current selection parameters. These parameters are then used to decide whether updating widgets in this property manager is needed when L{self.model_changed} method is called. @return: A tuple that contains total number of selected peptides. @rtype: tuple @NOTE: This method may be renamed in future. It's possible that there are other groupboxes in the PM that need to be updated when something changes in the glpane. """ selectedProteins = [] if self.command is not None: # and self.command.hasValidStructure(): selectedProteins = self.win.assy.getSelectedProteinChunks() return (selectedProteins) def _currentStructureParams(self): """ Return current structure parameters of interest to self.model_changed. Right now it only returns the number of peptides within the structure (or None). This is a good enough check (and no need to compare each and every peptide within the structure with a previously stored set of strands). """ #Can it happen that the total number of peptides remains the same even #after some alterations to the peptides? Unlikely. (Example: a single #(future) Break peptide operation will increase the number of peptides #by one. Or Join peptides decrease it by 1) params = None if self.command: # and self.command.hasValidStructure(): proteinList = [] proteinList = getAllProteinChunksInPart(self.win.assy) params = len(proteinList) return params def close(self): """ Closes the Property Manager. Overrides EditCommand_PM.close() """ #Clear tags, if any, due to the selection in the self.strandListWidget. #self.proteinListWidget.clear() env.history.statusbar_msg("") EditCommand_PM.close(self) return def show(self): """ Show the PM. Extends superclass method. @note: _update_UI_do_updates() gets called immediately after this and updates PM widgets with their correct values/settings. """ env.history.statusbar_msg("") EditCommand_PM.show(self) # NOTE: Think about moving this msg to _update_UI_do_updates() where # custom msgs can be created based on the current selection, etc. # Mark 2008-12-14 msg = "Select <b>Insert Peptide</b> to create a peptide chain or "\ "select another modeling tool to modify an existing protein." self.updateMessage(msg) return def _editPeptide(self): """ Slot for the "Edit Properties" button. """ #if not self.command.hasValidStructure(): # return proteinChunk = self.win.assy.getSelectedProteinChunk() if proteinChunk: proteinChunk.protein.edit(self.win) return def _compareProteins(self): """ Slot for the "Compare Proteins" button. """ self.win.commandSequencer.userEnterCommand('COMPARE_PROTEINS') return def _addWhatsThisText( self ): """ What's This text for widgets in the DNA Property Manager. """ pass def _addToolTipText(self): """ Tool Tip text for widgets in the DNA Property Manager. """ pass def _addGroupBoxes(self): """ Add the Build Protein Property Manager group boxes. """ self._pmGroupBox1 = PM_GroupBox(self, title = "Peptides") self._loadGroupBox1(self._pmGroupBox1) return def _loadGroupBox1(self, pmGroupBox): """ Load widgets in groupbox1. """ self.proteinListWidget = PM_SelectionListWidget(pmGroupBox, self.win, label = "", heightByRows = 6 ) self.proteinListWidget.setObjectName('Peptide_list_widget') self.proteinListWidget.setTagInstruction('PICK_ITEM_IN_GLPANE') self.editPeptidePropertiesButton = PM_PushButton(pmGroupBox, label = "", text = "Edit Properties..." ) self.editPeptidePropertiesButton.setEnabled(False) self.compareProteinsButton = PM_PushButton(pmGroupBox, label = "", text = "Compare Proteins..." ) self.compareProteinsButton.setEnabled(False) return def updateProteinListWidget(self): """ Update the peptide list widget. It shows all peptides in the part. """ proteinChunkList = getAllProteinChunksInPart(self.win.assy) if proteinChunkList: self.proteinListWidget.insertItems( row = 0, items = proteinChunkList) else: self.proteinListWidget.clear() return