Пример #1
0
    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 _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in group box 1.
        """
        #Following toolbutton facilitates entering a temporary NanotubeLineMode
        #to create a CNT using endpoints of the specified line.
        self.specifyCntLineButton = PM_ToolButton(
            pmGroupBox,
            text="Specify Endpoints",
            iconPath="ui/actions/Properties Manager/Pencil.png",
            spanWidth=True)
        self.specifyCntLineButton.setCheckable(True)
        self.specifyCntLineButton.setAutoRaise(True)
        self.specifyCntLineButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

        #EndPoint1 and endPoint2 coordinates. These widgets are hidden
        # as of 2007- 12 - 05
        self._endPoint1SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label="End Point 1")
        self.x1SpinBox = self._endPoint1SpinBoxes.xSpinBox
        self.y1SpinBox = self._endPoint1SpinBoxes.ySpinBox
        self.z1SpinBox = self._endPoint1SpinBoxes.zSpinBox

        self._endPoint2SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label="End Point 2")
        self.x2SpinBox = self._endPoint2SpinBoxes.xSpinBox
        self.y2SpinBox = self._endPoint2SpinBoxes.ySpinBox
        self.z2SpinBox = self._endPoint2SpinBoxes.zSpinBox

        self._endPoint1SpinBoxes.hide()
        self._endPoint2SpinBoxes.hide()
Пример #3
0
 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 )
Пример #4
0
 def _loadPM_ToolButton(self, inPmGroupBox):
     """
     PM_ToolButton widgets.
     """
     
     self.toolButton1 = \
         PM_ToolButton( inPmGroupBox,
                        label = "",
                        text  = "ToolButton 1" )
     
     self.toolButton2 = \
         PM_ToolButton( inPmGroupBox,
                        label     = "",
                        text      = "ToolButton 2",
                        spanWidth = True )
    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in group box 1.
        """
        #Following toolbutton facilitates entering a temporary NanotubeLineMode
        #to create a CNT using endpoints of the specified line.
        self.specifyCntLineButton = PM_ToolButton(
            pmGroupBox,
            text = "Specify Endpoints",
            iconPath  = "ui/actions/Properties Manager/Pencil.png",
            spanWidth = True
        )
        self.specifyCntLineButton.setCheckable(True)
        self.specifyCntLineButton.setAutoRaise(True)
        self.specifyCntLineButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

        #EndPoint1 and endPoint2 coordinates. These widgets are hidden
        # as of 2007- 12 - 05
        self._endPoint1SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                label = "End Point 1")
        self.x1SpinBox = self._endPoint1SpinBoxes.xSpinBox
        self.y1SpinBox = self._endPoint1SpinBoxes.ySpinBox
        self.z1SpinBox = self._endPoint1SpinBoxes.zSpinBox

        self._endPoint2SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                label = "End Point 2")
        self.x2SpinBox = self._endPoint2SpinBoxes.xSpinBox
        self.y2SpinBox = self._endPoint2SpinBoxes.ySpinBox
        self.z2SpinBox = self._endPoint2SpinBoxes.zSpinBox

        self._endPoint1SpinBoxes.hide()
        self._endPoint2SpinBoxes.hide()
Пример #6
0
    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in 2nd group box.

        @param pmGroupBox: The 1st group box in the PM.
        @type  pmGroupBox: L{PM_GroupBox}
        """

        self.launchQuteMolButton = PM_ToolButton(
            pmGroupBox,
            text      = "Launch QuteMolX",
            iconPath  = "ui/actions/Properties Manager/QuteMol.png",
            spanWidth = True )

        self.launchQuteMolButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
 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 )
Пример #8
0
    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 _loadMovieFilesGroupBox(self, inPmGroupBox):
     """
     Load widgets in the Open/Save Movie Files group box.
     @param inPmGroupBox: The Open/Save Movie Files groupbox in the PM
     @type  inPmGroupBox: L{PM_GroupBox} 
     """
     
     for action in self.fileOpenMovieAction, self.fileSaveMovieAction:
         btn = PM_ToolButton(inPmGroupBox,
                             text = str(action.text()),
                             spanWidth = True)
         btn.setDefaultAction(action)
         btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
Пример #10
0
 def _loadFreeDragRotateGroupBox(self, inPmGroupBox):
     """
     Load widgets in the Free Drag Rotate group box, which is 
     present within the Rotate groupbox.
     @param inPmGroupBox: The Free Drag Rotate group box in the Rotate 
                          group box.
     @type  inPmGroupBox: L{PM_GroupBox}
     """
     # Button list to create a toolbutton row.
     # Format: 
     # - buttonId, 
     # - buttonText , 
     # - iconPath
     # - tooltip
     # - shortcut
     # - column
     
     BUTTON_LIST = [ 
         ( "QToolButton", 1,  "ROTATEDEFAULT", 
           "ui/actions/Properties Manager/Rotate_Free.png", "", "F", 0 ),
         
         ( "QToolButton", 2,  "ROTATEX", 
           "ui/actions/Properties Manager/RotateX.png", "", "X", 1 ),
         
         ( "QToolButton", 3,  "ROTATEY",  
           "ui/actions/Properties Manager/RotateY.png", "", "Y", 2 ),
         
         ( "QToolButton", 4,  "ROTATEZ",  
           "ui/actions/Properties Manager/RotateZ.png", "", "Z", 3 ),
         
         ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",  
           "ui/actions/Properties Manager/translate+rotate-A.png", "", \
           "A", 4 )
                     
         ]
         
     self.freeDragRotateButtonGroup = \
         PM_ToolButtonRow( inPmGroupBox, 
                            title        = "",
                            buttonList   = BUTTON_LIST,
                            spanWidth = True,
                            checkedId    = 1,
                            setAsDefault = True,
                         )
             
     self.rotateFreeButton = self.freeDragRotateButtonGroup.getButtonById(1)
     self.rotateXButton    = self.freeDragRotateButtonGroup.getButtonById(2)
     self.rotateYButton    = self.freeDragRotateButtonGroup.getButtonById(3)
     self.rotateZButton    = self.freeDragRotateButtonGroup.getButtonById(4)
     self.rotAlongAxisButton = \
         self.freeDragRotateButtonGroup.getButtonById(5)
     
     inPmGroupBox.setStyleSheet(
         self.freeDragRotateButtonGroup._getStyleSheet())
             
     X_ROW_LABELS = [("QLabel", "Delta Theta X:", 0),
                     ("QLabel", "", 1),
                     ("QLabel", "0.00", 2),
                     ("QLabel", "Degrees", 3)]
     
     Y_ROW_LABELS = [("QLabel", "Delta Theta Y:", 0),
                     ("QLabel", "", 1),
                     ("QLabel", "0.00", 2),
                     ("QLabel", "Degrees", 3)]
     
     Z_ROW_LABELS = [("QLabel", "Delta Theta Z:", 0),
                     ("QLabel", "", 1),
                     ("QLabel", "0.00", 2),
                     ("QLabel", "Degrees", 3)]
     
     self.rotateXLabelRow = PM_LabelRow( inPmGroupBox,
                                         title = "",
                                         labelList = X_ROW_LABELS )  
     self.deltaThetaX_lbl = self.rotateXLabelRow.labels[2]
                                        
     self.rotateYLabelRow = PM_LabelRow( inPmGroupBox,
                                         title = "",
                                         labelList = Y_ROW_LABELS )
     self.deltaThetaY_lbl = self.rotateYLabelRow.labels[2]
                                       
     self.rotateZLabelRow = PM_LabelRow( inPmGroupBox,
                                         title = "",
                                         labelList = Z_ROW_LABELS )  
     self.deltaThetaZ_lbl = self.rotateZLabelRow.labels[2]    
     
     self.rotateAboutPointButton = PM_ToolButton(
                 inPmGroupBox, 
                 text = "Rotate selection about a point",
                 iconPath  = "ui/actions/Properties Manager"\
                 "/Rotate_Components.png",
                 spanWidth = True                    
                 )
     self.rotateAboutPointButton.setCheckable(True)
     self.rotateAboutPointButton.setAutoRaise(True)
     self.rotateAboutPointButton.setToolButtonStyle(
         Qt.ToolButtonTextBesideIcon)
     
     
     self.rotateStartCoordLineEdit = PM_LineEdit( 
         inPmGroupBox, 
         label        = "ui/actions/Properties Manager"\
                 "/Move_Start_Point.png",
         text         = "Define 3 points",
         setAsDefault = False,
         )
     self.rotateStartCoordLineEdit.setReadOnly(True)
     self.rotateStartCoordLineEdit.setEnabled(False)
Пример #11
0
    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.searchTypeComboBox  = \
            PM_ComboBox( self,
                         label         =  "Search options:",
                         choices       =  ["By node name", "By # of bases (DNA only)"],
                         setAsDefault  =  True)

        #Find  widgets --
        self._nucleotidesSpinBox_1 = PM_SpinBox(self,
                                                label="",
                                                value=10,
                                                setAsDefault=False,
                                                singleStep=10,
                                                minimum=1,
                                                maximum=50000)

        self._nucleotidesSpinBox_2 = PM_SpinBox(self,
                                                label="",
                                                value=50,
                                                setAsDefault=False,
                                                singleStep=10,
                                                minimum=1,
                                                maximum=50000)


        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)

        self.findLineEdit.setMaximumWidth(80)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        ##self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        ##self._setFindOptionsToolButtonMenu()

        self.searchToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Next.png")
        self.searchToolButton.setAutoRaise(False)

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done --

        # When the widget type starts with the word 'PM_' , the
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned
        # labels (and if they were recreated as mentioned above),
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2]
        #Cleanup in PM_widgetGrid could be to check if the widget starts with
        #'Q'  instead of 'PM_'

        #Widgets to include in the widget row.

        widgetList1 = [('QLabel', "     Search for name:", 1),
                       ('PM_LineEdit', self.findLineEdit, 2),
                       ('PM_ToolButton', self.findOptionsToolButton, 3),
                       ('PM_ToolButton', self.searchToolButton, 4),
                       ('PM_Label', self.warningSign, 5),
                       ('PM_Label', self.phraseNotFoundLabel, 6),
                       ('QSpacerItem', 5, 5, 7)]

        widgetList2 = [('QLabel', "     Number of bases: >=", 1),
                       ('PM_SpinBox', self._nucleotidesSpinBox_1, 2),
                       ('QLabel', "     <=", 3),
                       ('PM_SpinBox', self._nucleotidesSpinBox_2, 4),
                       ('QSpacerItem', 5, 5, 5)]

        widgetList3 = [('QSpacerItem', 5, 5, 1),
                       ('PM_ToolButton', self.searchToolButton, 2),
                       ('PM_Label', self.warningSign, 3),
                       ('PM_Label', self.phraseNotFoundLabel, 4),
                       ('QSpacerItem', 5, 5, 5)]

        self._widgetRow1 = PM_WidgetRow(self,
                                        title='',
                                        widgetList=widgetList1,
                                        label="",
                                        spanWidth=True)

        self._widgetRow2 = PM_WidgetRow(self,
                                        title='',
                                        widgetList=widgetList2,
                                        label="",
                                        spanWidth=True)

        self._widgetRow3 = PM_WidgetRow(self,
                                        title='',
                                        widgetList=widgetList3,
                                        label="",
                                        spanWidth=True)
Пример #12
0
class Ui_MovePropertyManager(Command_PropertyManager):

    # The title that appears in the Property Manager header
    title = "Move"
    # The name of this Property Manager. This will be set to
    # the name of the PM_Dialog object via setObjectName().
    pmName = title
    # The relative path to the PNG file that appears in the header
    iconPath = "ui/actions/Properties Manager/Translate_Components.png"

    # The title(s) that appear in the property manager header.
    # (these are changed depending on the active group box)
    translateTitle = "Translate"
    rotateTitle = "Rotate"

    # The full path to PNG file(s) that appears in the header.
    translateIconPath = "ui/actions/Properties Manager/Translate_Components.png"
    rotateIconPath = "ui/actions/Properties Manager/Rotate_Components.png"

    def __init__(self, command):
        _superclass.__init__(self, command)
        self.showTopRowButtons(PM_DONE_BUTTON | PM_WHATS_THIS_BUTTON)

    def _addGroupBoxes(self):
        """
        Add groupboxes to the Property Manager dialog. 
        """

        self.translateGroupBox = PM_GroupBox(self,
                                             title="Translate",
                                             connectTitleButton=False)
        self.translateGroupBox.titleButton.setShortcut('T')
        self._loadTranslateGroupBox(self.translateGroupBox)

        self.rotateGroupBox = PM_GroupBox(self,
                                          title="Rotate",
                                          connectTitleButton=False)
        self.rotateGroupBox.titleButton.setShortcut('R')
        self._loadRotateGroupBox(self.rotateGroupBox)

        self.translateGroupBox.collapse()
        self.rotateGroupBox.collapse()

    # == Begin Translate Group Box =====================

    def _loadTranslateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Translate group box.
        @param inPmGroupBox: The Translate group box in the PM
        @type  inPmGroupBox: L{PM_GroupBox}
        """

        translateChoices = ["Free Drag", "By Delta XYZ", "To XYZ Position"]

        self.translateComboBox = \
            PM_ComboBox( inPmGroupBox,
                         label        = '',
                         choices      = translateChoices,
                         index        = 0,
                         setAsDefault = False,
                         spanWidth    = True )

        self.freeDragTranslateGroupBox = PM_GroupBox(inPmGroupBox)
        self._loadFreeDragTranslateGroupBox(self.freeDragTranslateGroupBox)

        self.byDeltaGroupBox = PM_GroupBox(inPmGroupBox)
        self._loadByDeltaGroupBox(self.byDeltaGroupBox)

        self.toPositionGroupBox = PM_GroupBox(inPmGroupBox)
        self._loadToPositionGroupBox(self.toPositionGroupBox)

        self.updateTranslateGroupBoxes(0)

    def _loadFreeDragTranslateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Free Drag Translate group box, which is present 
        within the Translate groupbox.
        @param inPmGroupBox: The Free Drag Translate group box in the Translate 
                             group box. 
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format:
        # - buttonId,
        # - buttonText ,
        # - iconPath
        # - tooltip
        # - shortcut
        # - column


        BUTTON_LIST = [
            ( "QToolButton", 1,  "MOVEDEFAULT",
              "ui/actions/Properties Manager/Move_Free.png", "", "F", 0),
            ( "QToolButton", 2,  "TRANSX",
              "ui/actions/Properties Manager/TranslateX.png", "", "X", 1),
            ( "QToolButton", 3,  "TRANSY",
              "ui/actions/Properties Manager/TranslateY.png", "", "Y", 2),
            ( "QToolButton", 4,  "TRANSZ",
              "ui/actions/Properties Manager/TranslateZ.png", "", "Z", 3),
            ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",
              "ui/actions/Properties Manager/translate+rotate-A.png", "", \
              "A", 4)

            ]

        self.freeDragTranslateButtonGroup = \
            PM_ToolButtonRow( inPmGroupBox,
                               title        = "",
                               buttonList   = BUTTON_LIST,
                               checkedId    = 1,
                               setAsDefault = True,
                               )
        self.transFreeButton = self.freeDragTranslateButtonGroup.getButtonById(
            1)
        self.transXButton = self.freeDragTranslateButtonGroup.getButtonById(2)
        self.transYButton = self.freeDragTranslateButtonGroup.getButtonById(3)
        self.transZButton = self.freeDragTranslateButtonGroup.getButtonById(4)
        self.transAlongAxisButton = \
            self.freeDragTranslateButtonGroup.getButtonById(5)

        self.moveFromToButton = PM_ToolButton(
                    inPmGroupBox,
                    text = "Translate from/to",
                    iconPath  = "ui/actions/Properties Manager"\
                    "/Translate_Components.png",
                    spanWidth = True

                    )
        self.moveFromToButton.setCheckable(True)
        self.moveFromToButton.setAutoRaise(True)
        self.moveFromToButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)


        self.startCoordLineEdit = PM_LineEdit(
            inPmGroupBox,
            label        = "ui/actions/Properties Manager"\
                    "/Move_Start_Point.png",
            text         = "Define 'from' and 'to' points",
            setAsDefault = False,
            )
        self.startCoordLineEdit.setReadOnly(True)
        self.startCoordLineEdit.setEnabled(False)

    def _loadByDeltaGroupBox(self, inPmGroupBox):
        """
        Load widgets in the translate By Delta group box, which is present 
        within the Translate groupbox.
        @param inPmGroupBox: The Translate By Delta group box in the translate 
                             group box. 
        @type  inPmGroupBox: L{PM_GroupBox}
        """

        self.moveDeltaXSpinBox = \
            PM_DoubleSpinBox(
                inPmGroupBox,
                label        = "ui/actions/Properties Manager/Delta_X.png",
                value        = 0.0,
                setAsDefault = True,
                minimum      = -100.0,
                maximum      =  100.0,
                singleStep   = 1.0,
                decimals     = 3,
                suffix       = ' Angstroms',
                spanWidth    = False )

        self.moveDeltaYSpinBox = \
            PM_DoubleSpinBox(
                inPmGroupBox,
                label        = "ui/actions/Properties Manager/Delta_Y.png",
                value        = 0.0,
                setAsDefault = True,
                minimum      = -100.0,
                maximum      =  100.0,
                singleStep   = 1.0,
                decimals     = 3,
                suffix       = ' Angstroms',
                spanWidth    = False )

        self.moveDeltaZSpinBox = \
            PM_DoubleSpinBox(
                inPmGroupBox,
                label        = "ui/actions/Properties Manager/Delta_Z.png",
                value        = 0.0,
                setAsDefault = True,
                minimum      = -100.0,
                maximum      =  100.0,
                singleStep   = 1.0,
                decimals     = 3,
                suffix       = ' Angstroms',
                spanWidth    = False )

        DELTA_BUTTONS = [
            ("QToolButton", 1, "Delta Plus",
             "ui/actions/Properties Manager/Move_Delta_Plus.png", "", "+", 0),
            ("QToolButton", 2, "Delta Minus",
             "ui/actions/Properties Manager/Move_Delta_Minus.png", "", "-", 1)
        ]

        self.translateDeltaButtonRow = \
            PM_ToolButtonRow( inPmGroupBox,
                              title        = "",
                              buttonList   = DELTA_BUTTONS,
                              label        = 'Translate:',
                              isAutoRaise  =  True,
                              isCheckable  =  False
                            )
        self.transDeltaPlusButton = \
            self.translateDeltaButtonRow.getButtonById(1)
        self.transDeltaMinusButton = \
            self.translateDeltaButtonRow.getButtonById(2)

    def _loadToPositionGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Translate To a given Position group box, which is 
        present within the Translate groupbox.
        @param inPmGroupBox: Translate To Position group box in the Translate 
                             group box.
        @type  inPmGroupBox: L{PM_GroupBox}
        """

        self.toPositionspinboxes = PM_CoordinateSpinBoxes(inPmGroupBox)

        self.moveXSpinBox = self.toPositionspinboxes.xSpinBox
        self.moveYSpinBox = self.toPositionspinboxes.ySpinBox
        self.moveZSpinBox = self.toPositionspinboxes.zSpinBox


        self.moveAbsoluteButton = \
            PM_PushButton( inPmGroupBox,
                           label     = "",
                           text      = "Move Selection",
                           spanWidth = True )

    # == Begin Rotate Group Box =====================
    def _loadRotateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Rotate group box, 
        @param inPmGroupBox: The Rotate GroupBox in the PM
        @type  inPmGroupBox: L{PM_GroupBox}
        """

        rotateChoices = ["Free Drag", "By Specified Angle"]

        self.rotateComboBox = \
            PM_ComboBox( inPmGroupBox,
                         label        = '',
                         choices      = rotateChoices,
                         index        = 0,
                         setAsDefault = False,
                         spanWidth    = True )

        self.rotateAsUnitCB = \
            PM_CheckBox( inPmGroupBox,
                         text         = 'Rotate as a unit' ,
                         widgetColumn = 0,
                         state        = Qt.Checked )

        self.freeDragRotateGroupBox = PM_GroupBox(inPmGroupBox)
        self._loadFreeDragRotateGroupBox(self.freeDragRotateGroupBox)

        self.bySpecifiedAngleGroupBox = PM_GroupBox(inPmGroupBox)
        self._loadBySpecifiedAngleGroupBox(self.bySpecifiedAngleGroupBox)

        self.updateRotateGroupBoxes(0)

    def _loadFreeDragRotateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Free Drag Rotate group box, which is 
        present within the Rotate groupbox.
        @param inPmGroupBox: The Free Drag Rotate group box in the Rotate 
                             group box.
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format:
        # - buttonId,
        # - buttonText ,
        # - iconPath
        # - tooltip
        # - shortcut
        # - column

        BUTTON_LIST = [
            ( "QToolButton", 1,  "ROTATEDEFAULT",
              "ui/actions/Properties Manager/Rotate_Free.png", "", "F", 0 ),

            ( "QToolButton", 2,  "ROTATEX",
              "ui/actions/Properties Manager/RotateX.png", "", "X", 1 ),

            ( "QToolButton", 3,  "ROTATEY",
              "ui/actions/Properties Manager/RotateY.png", "", "Y", 2 ),

            ( "QToolButton", 4,  "ROTATEZ",
              "ui/actions/Properties Manager/RotateZ.png", "", "Z", 3 ),

            ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",
              "ui/actions/Properties Manager/translate+rotate-A.png", "", \
              "A", 4 )

            ]

        self.freeDragRotateButtonGroup = \
            PM_ToolButtonRow( inPmGroupBox,
                               title        = "",
                               buttonList   = BUTTON_LIST,
                               spanWidth = True,
                               checkedId    = 1,
                               setAsDefault = True,
                            )

        self.rotateFreeButton = self.freeDragRotateButtonGroup.getButtonById(1)
        self.rotateXButton = self.freeDragRotateButtonGroup.getButtonById(2)
        self.rotateYButton = self.freeDragRotateButtonGroup.getButtonById(3)
        self.rotateZButton = self.freeDragRotateButtonGroup.getButtonById(4)
        self.rotAlongAxisButton = \
            self.freeDragRotateButtonGroup.getButtonById(5)

        inPmGroupBox.setStyleSheet(
            self.freeDragRotateButtonGroup._getStyleSheet())

        X_ROW_LABELS = [("QLabel", "Delta Theta X:", 0), ("QLabel", "", 1),
                        ("QLabel", "0.00", 2), ("QLabel", "Degrees", 3)]

        Y_ROW_LABELS = [("QLabel", "Delta Theta Y:", 0), ("QLabel", "", 1),
                        ("QLabel", "0.00", 2), ("QLabel", "Degrees", 3)]

        Z_ROW_LABELS = [("QLabel", "Delta Theta Z:", 0), ("QLabel", "", 1),
                        ("QLabel", "0.00", 2), ("QLabel", "Degrees", 3)]

        self.rotateXLabelRow = PM_LabelRow(inPmGroupBox,
                                           title="",
                                           labelList=X_ROW_LABELS)
        self.deltaThetaX_lbl = self.rotateXLabelRow.labels[2]

        self.rotateYLabelRow = PM_LabelRow(inPmGroupBox,
                                           title="",
                                           labelList=Y_ROW_LABELS)
        self.deltaThetaY_lbl = self.rotateYLabelRow.labels[2]

        self.rotateZLabelRow = PM_LabelRow(inPmGroupBox,
                                           title="",
                                           labelList=Z_ROW_LABELS)
        self.deltaThetaZ_lbl = self.rotateZLabelRow.labels[2]

        self.rotateAboutPointButton = PM_ToolButton(
                    inPmGroupBox,
                    text = "Rotate selection about a point",
                    iconPath  = "ui/actions/Properties Manager"\
                    "/Rotate_Components.png",
                    spanWidth = True
                    )
        self.rotateAboutPointButton.setCheckable(True)
        self.rotateAboutPointButton.setAutoRaise(True)
        self.rotateAboutPointButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)


        self.rotateStartCoordLineEdit = PM_LineEdit(
            inPmGroupBox,
            label        = "ui/actions/Properties Manager"\
                    "/Move_Start_Point.png",
            text         = "Define 3 points",
            setAsDefault = False,
            )
        self.rotateStartCoordLineEdit.setReadOnly(True)
        self.rotateStartCoordLineEdit.setEnabled(False)

    def _loadBySpecifiedAngleGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Rotate By Specified Angle group box, which is 
        present within the Rotate groupbox.
        @param inPmGroupBox: Rotate By Specified Angle group box in the Rotate 
                             group box.
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format:
        # - buttonId,
        # - buttonText ,
        # - iconPath
        # - tooltip
        # - shortcut
        # - column

        BUTTON_LIST = [
            ("QToolButton", 1, "ROTATEX",
             "ui/actions/Properties Manager/RotateX.png",
             "Rotate about X axis", "X", 0),
            ("QToolButton", 2, "ROTATEY",
             "ui/actions/Properties Manager/RotateY.png",
             "Rotate about Y axis", "Y", 1),
            ("QToolButton", 3, "ROTATEZ",
             "ui/actions/Properties Manager/RotateZ.png",
             "Rotate about Z axis", "Z", 2),
        ]



        self.rotateAroundAxisButtonRow = \
            PM_ToolButtonRow( inPmGroupBox,
                              title        = "",
                              buttonList   = BUTTON_LIST,
                              alignment    = 'Right',
                              label        = 'Rotate Around:'
                            )
        self.rotXaxisButton = \
            self.rotateAroundAxisButtonRow.getButtonById(1)

        self.rotYaxisButton = \
            self.rotateAroundAxisButtonRow.getButtonById(2)

        self.rotZaxisButton = \
            self.rotateAroundAxisButtonRow.getButtonById(3)



        self.rotateThetaSpinBox = \
            PM_DoubleSpinBox(inPmGroupBox,
                             label        = "Rotate By:",
                             value        = 0.0,
                             setAsDefault = True,
                             minimum      = 0,
                             maximum      = 360.0,
                             singleStep   = 1.0,
                             decimals     = 2,
                             suffix       = ' Degrees')

        THETA_BUTTONS = [
            ("QToolButton", 1, "Theta Plus",
             "ui/actions/Properties Manager/Move_Theta_Plus.png", "", "+", 0),
            ("QToolButton", 2, "Theta Minus",
             "ui/actions/Properties Manager/Move_Theta_Minus.png", "", "-", 1)
        ]

        self.rotateThetaButtonRow = \
            PM_ToolButtonRow( inPmGroupBox,
                              title        = "",
                              buttonList   = THETA_BUTTONS,
                              label        = 'Direction:',
                              isAutoRaise  =  True,
                              isCheckable  =  False
                            )
        self.rotateThetaPlusButton = self.rotateThetaButtonRow.getButtonById(1)
        self.rotateThetaMinusButton = self.rotateThetaButtonRow.getButtonById(
            2)

    # == End Rotate Group Box =====================

    # == Slots for Translate group box
    def _hideAllTranslateGroupBoxes(self):
        """
        Hides all Translate group boxes.
        """
        self.toPositionGroupBox.hide()
        self.byDeltaGroupBox.hide()
        self.freeDragTranslateGroupBox.hide()

    def updateTranslateGroupBoxes(self, id):
        """
        Update the translate group boxes displayed based on the translate
        option selected.
        @param id: Integer value corresponding to the combobox item in the 
                   Translate group box. 
        @type  id: int
        """
        self._hideAllTranslateGroupBoxes()

        if id is 0:
            self.freeDragTranslateGroupBox.show()

        if id is 1:
            self.byDeltaGroupBox.show()
        if id is 2:
            self.toPositionGroupBox.show()

        self.updateMessage()

    def changeMoveOption(self, button):
        """
        Subclasses should reimplement this method.
        
        @param button: QToolButton that decides the type of translate operation 
        to be set.
        @type  button: QToolButton 
                       L{http://doc.trolltech.com/4.2/qtoolbutton.html}
        @see: B{MovePropertyManager.changeMoveOption} which overrides this
              method
        """
        pass

    # == Slots for Rotate group box
    def updateRotateGroupBoxes(self, id):
        """
        Update the translate group boxes displayed based on the translate
        option selected.
        @param id: Integer value corresponding to the combobox item in the 
                   Rotate group box. 
        @type  id: int
        """
        if id is 0:
            self.bySpecifiedAngleGroupBox.hide()
            self.freeDragRotateGroupBox.show()
        if id is 1:
            self.freeDragRotateGroupBox.hide()
            self.bySpecifiedAngleGroupBox.show()

        self.updateMessage()

    def changeRotateOption(self, button):
        """
        Subclasses should reimplement this method. 
        
        @param button: QToolButton that decides the type of rotate operation 
        to be set.
        @type  button: QToolButton 
                       L{http://doc.trolltech.com/4.2/qtoolbutton.html}
        @see: B{MovePropertyManage.changeRotateOption} which overrides this 
             method
        """
        pass

    def _addWhatsThisText(self):
        """
        What's This text for some of the widgets in this Property Manager.  

        """
        from ne1_ui.WhatsThisText_for_PropertyManagers import whatsThis_MovePropertyManager
        whatsThis_MovePropertyManager(self)

    def _addToolTipText(self):
        """
        Tool Tip text for widgets in this Property Manager.  
        """
        from ne1_ui.ToolTipText_for_PropertyManagers import ToolTip_MovePropertyManager
        ToolTip_MovePropertyManager(self)
Пример #13
0
    def _loadFreeDragTranslateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Free Drag Translate group box, which is present 
        within the Translate groupbox.
        @param inPmGroupBox: The Free Drag Translate group box in the Translate 
                             group box. 
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format:
        # - buttonId,
        # - buttonText ,
        # - iconPath
        # - tooltip
        # - shortcut
        # - column


        BUTTON_LIST = [
            ( "QToolButton", 1,  "MOVEDEFAULT",
              "ui/actions/Properties Manager/Move_Free.png", "", "F", 0),
            ( "QToolButton", 2,  "TRANSX",
              "ui/actions/Properties Manager/TranslateX.png", "", "X", 1),
            ( "QToolButton", 3,  "TRANSY",
              "ui/actions/Properties Manager/TranslateY.png", "", "Y", 2),
            ( "QToolButton", 4,  "TRANSZ",
              "ui/actions/Properties Manager/TranslateZ.png", "", "Z", 3),
            ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",
              "ui/actions/Properties Manager/translate+rotate-A.png", "", \
              "A", 4)

            ]

        self.freeDragTranslateButtonGroup = \
            PM_ToolButtonRow( inPmGroupBox,
                               title        = "",
                               buttonList   = BUTTON_LIST,
                               checkedId    = 1,
                               setAsDefault = True,
                               )
        self.transFreeButton = self.freeDragTranslateButtonGroup.getButtonById(
            1)
        self.transXButton = self.freeDragTranslateButtonGroup.getButtonById(2)
        self.transYButton = self.freeDragTranslateButtonGroup.getButtonById(3)
        self.transZButton = self.freeDragTranslateButtonGroup.getButtonById(4)
        self.transAlongAxisButton = \
            self.freeDragTranslateButtonGroup.getButtonById(5)

        self.moveFromToButton = PM_ToolButton(
                    inPmGroupBox,
                    text = "Translate from/to",
                    iconPath  = "ui/actions/Properties Manager"\
                    "/Translate_Components.png",
                    spanWidth = True

                    )
        self.moveFromToButton.setCheckable(True)
        self.moveFromToButton.setAutoRaise(True)
        self.moveFromToButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)


        self.startCoordLineEdit = PM_LineEdit(
            inPmGroupBox,
            label        = "ui/actions/Properties Manager"\
                    "/Move_Start_Point.png",
            text         = "Define 'from' and 'to' points",
            setAsDefault = False,
            )
        self.startCoordLineEdit.setReadOnly(True)
        self.startCoordLineEdit.setEnabled(False)
Пример #14
0
    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.loadSequenceButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Open.png")

        self.saveSequenceButton = PM_ToolButton(
            self,
            iconPath="ui/actions/Properties Manager/Save_Strand_Sequence.png")

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        # Only supporting 5' to 3' direction until bug 2956 is fixed.
        # Mark 2008-12-19
        editDirectionChoices = ["5' to 3'"]  # , "3' to 5'"]
        self.baseDirectionChoiceComboBox = \
            PM_ComboBox( self,
                         choices = editDirectionChoices,
                         index     = 0,
                         spanWidth = False )

        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)


        self.replaceLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text="Replace")

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done --

        # When the widget type starts with the word 'PM_' , the
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned
        # labels (and if they were recreated as mentioned above),
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2]
        #Cleanup in PM_widgetGrid could be to check if the widget starts with
        #'Q'  instead of 'PM_'

        #Widgets to include in the widget row.
        widgetList = [('PM_ToolButton', self.loadSequenceButton, 0),
                      ('PM_ToolButton', self.saveSequenceButton, 1),
                      ('QLabel', "     Sequence direction:", 2),
                      ('PM_ComboBox', self.baseDirectionChoiceComboBox, 3),
                      ('QLabel', "     Find:", 4),
                      ('PM_LineEdit', self.findLineEdit, 5),
                      ('PM_ToolButton', self.findOptionsToolButton, 6),
                      ('PM_ToolButton', self.findPreviousToolButton, 7),
                      ('PM_ToolButton', self.findNextToolButton, 8),
                      ('QLabel', "     Replace:", 9),
                      ('PM_TextEdit', self.replaceLineEdit, 10),
                      ('PM_PushButton', self.replacePushButton, 11),
                      ('PM_Label', self.warningSign, 12),
                      ('PM_Label', self.phraseNotFoundLabel, 13),
                      ('QSpacerItem', 5, 5, 14)]

        widgetRow = PM_WidgetRow(self,
                                 title='',
                                 widgetList=widgetList,
                                 label="",
                                 spanWidth=True)
        return
Пример #15
0
    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options,
        Find and replace widgets etc.
        """

        self.loadSequenceButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Open.png")

        self.saveSequenceButton = PM_ToolButton(
            self,
            iconPath="ui/actions/Properties Manager/Save_Strand_Sequence.png")

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        # Hide load and save buttons until they are implemented. -Mark 2008-12-20.
        self.loadSequenceButton.hide()
        self.saveSequenceButton.hide()

        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)

        self.replaceLineEdit = \
            PM_LineEdit( self,
                         label        = "  Replace:",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text="Replace")

        # Hide Replace widgets until we add support for transmuting residues.
        # Mark 2008-12-19
        #self.replaceLabel.hide()
        self.replacePushButton.hide()
        self.replaceLineEdit.hide()

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        #Widgets to include in the widget row.
        widgetList = [
            ('PM_ToolButton', self.loadSequenceButton, 0),
            ('PM_ToolButton', self.saveSequenceButton, 1),
            ('QLabel', "                                     Find:", 4),
            ('PM_LineEdit', self.findLineEdit, 5),
            ('PM_ToolButton', self.findOptionsToolButton, 6),
            ('PM_ToolButton', self.findPreviousToolButton, 7),
            ('PM_ToolButton', self.findNextToolButton, 8),
            #('PM_Label',      self.replaceLabel, 9),
            ('PM_TextEdit', self.replaceLineEdit, 9),
            ('PM_PushButton', self.replacePushButton, 10),
            ('PM_Label', self.warningSign, 11),
            ('PM_Label', self.phraseNotFoundLabel, 12),
            ('QSpacerItem', 5, 5, 13)
        ]

        widgetRow = PM_WidgetRow(self,
                                 title='',
                                 widgetList=widgetList,
                                 label="",
                                 spanWidth=True)
        return
Пример #16
0
    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.loadSequenceButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Open.png")  

        self.saveSequenceButton = PM_ToolButton(
            self, 
            iconPath = "ui/actions/Properties Manager/Save_Strand_Sequence.png") 

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        editDirectionChoices = ["5' to 3'", "3' to 5'"]
        self.baseDirectionChoiceComboBox = \
            PM_ComboBox( self,
                         choices = editDirectionChoices,
                         index     = 0, 
                         spanWidth = False )   

        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)


        self.replaceLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text = "Replace")

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done -- 

        # When the widget type starts with the word 'PM_' , the 
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned 
        # labels (and if they were recreated as mentioned above), 
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2] 
        #Cleanup in PM_widgetGrid could be to check if the widget starts with 
        #'Q'  instead of 'PM_' 


        #Widgets to include in the widget row. 
        widgetList = [('PM_ToolButton', self.loadSequenceButton, 0),
                      ('PM_ToolButton', self.saveSequenceButton, 1),
                      ('QLabel', "     Sequence direction:", 2),
                      ('PM_ComboBox',  self.baseDirectionChoiceComboBox , 3),
                      ('QLabel', "     Find:", 4),
                      ('PM_LineEdit', self.findLineEdit, 5),
                      ('PM_ToolButton', self.findOptionsToolButton, 6),
                      ('PM_ToolButton', self.findPreviousToolButton, 7),
                      ('PM_ToolButton', self.findNextToolButton, 8), 
                      ('QLabel', "     Replace:", 9),
                      ('PM_TextEdit', self.replaceLineEdit, 10), 
                      ('PM_PushButton', self.replacePushButton, 11),
                      ('PM_Label', self.warningSign, 12),
                      ('PM_Label', self.phraseNotFoundLabel, 13),
                      ('QSpacerItem', 5, 5, 14) ]

        widgetRow = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList,
                                 label = "",
                                 spanWidth = True )
Пример #17
0
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 Ui_ProteinSequenceEditor(PM_DockWidget):
    """
    The Ui_DnaSequenceEditor class defines UI elements for the Sequence Editor
    object. The sequence editor is usually visible while in DNA edit mode.
    It is a DockWidget that is doced at the bottom of the MainWindow
    """
    _title         =  "Sequence Editor"
    _groupBoxCount = 0
    _lastGroupBox = None

    def __init__(self, win):
        """
        Constructor for the Ui_DnaSequenceEditor 
        @param win: The parentWidget (MainWindow) for the sequence editor 
        """
        
        self.win = win
        # Should parentWidget for a docwidget always be win? 
        #Not necessary but most likely it will be the case.        
        parentWidget = win 
        
        _superclass.__init__(self, parentWidget, title = self._title)
        
        #A flag used to restore the state of the Reports dock widget 
        #(which can be accessed through View  >  Reports) see self.show() and
        #self.closeEvent() for more details. 
        self._reportsDockWidget_closed_in_show_method = False
        self.setFixedHeight(90)

    def show(self):
        """
        Shows the sequence editor. While doing this, it also closes the reports
        dock widget (if visible) the state of the reports dockwidget will be
        restored when the sequence editor is closed. 
        @see:self.closeEvent()
        """
        self._reportsDockWidget_closed_in_show_method = False
        
        if self.win.viewFullScreenAction.isChecked() or \
           self.win.viewSemiFullScreenAction.isChecked():
            pass
        else:
            if self.win.reportsDockWidget.isVisible():
                self.win.reportsDockWidget.close()
                self._reportsDockWidget_closed_in_show_method = True

        _superclass.show(self)  
        
    def closeEvent(self, event):
        """
        Overrides close event. Makes sure that the visible state of the reports
        widgetis restored when the sequence editor is closed. 
        @see: self.show()
        """
        _superclass.closeEvent(self, event)
       
        if self.win.viewFullScreenAction.isChecked() or \
           self.win.viewSemiFullScreenAction.isChecked():
            pass
        else:
            if self._reportsDockWidget_closed_in_show_method:
                self.win.viewReportsAction.setChecked(True) 
                self._reportsDockWidget_closed_in_show_method = False

    def _loadWidgets(self):
        """
        Overrides PM.PM_DockWidget._loadWidgets. Loads the widget in this
        dockwidget.
        """
        self._loadMenuWidgets()
        self._loadTextEditWidget()


    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.loadSequenceButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Open.png")  

        self.saveSequenceButton = PM_ToolButton(
            self, 
            iconPath = "ui/actions/Properties Manager/Save_Strand_Sequence.png") 

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        
        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)


        self.replaceLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text = "Replace")

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        

        #Widgets to include in the widget row. 
        widgetList = [('PM_ToolButton', self.loadSequenceButton, 0),
                      ('PM_ToolButton', self.saveSequenceButton, 1),
                      ('QLabel', "     Find:", 4),
                      ('PM_LineEdit', self.findLineEdit, 5),
                      ('PM_ToolButton', self.findOptionsToolButton, 6),
                      ('PM_ToolButton', self.findPreviousToolButton, 7),
                      ('PM_ToolButton', self.findNextToolButton, 8), 
                      ('QLabel', "     Replace:", 9),
                      ('PM_TextEdit', self.replaceLineEdit, 10), 
                      ('PM_PushButton', self.replacePushButton, 11),
                      ('PM_Label', self.warningSign, 12),
                      ('PM_Label', self.phraseNotFoundLabel, 13),
                      ('QSpacerItem', 5, 5, 14) ]

        widgetRow = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList,
                                 label = "",
                                 spanWidth = True )
        
        

    def _loadTextEditWidget(self):
        """
        Load the SequenceTexteditWidgets.         
        """        
        self.aaRulerTextEdit = \
            PM_TextEdit( self, 
                         label = "", 
                         spanWidth = False,
                         permit_enter_keystroke = False) 
        
        palette = getPalette(None, 
                             QPalette.Base, 
                             pmGrpBoxColor)
        self.aaRulerTextEdit.setPalette(palette)     
        self.aaRulerTextEdit.setWordWrapMode( QTextOption.WrapAnywhere )
        self.aaRulerTextEdit.setFixedHeight(20)
        self.aaRulerTextEdit.setReadOnly(True)
        
        self.sequenceTextEdit = \
            PM_TextEdit( self, 
                         label = " Sequence: ", 
                         spanWidth = False,
                         permit_enter_keystroke = False) 
        
        
        self.sequenceTextEdit.setCursorWidth(2)
        self.sequenceTextEdit.setWordWrapMode( QTextOption.WrapAnywhere )
        self.sequenceTextEdit.setFixedHeight(20)
        
        self.secStrucTextEdit = \
            PM_TextEdit( self, 
                         label = " Secondary structure: ", 
                         spanWidth = False,
                         permit_enter_keystroke = False) 
        
        palette = getPalette(None, 
                             QPalette.Base, 
                             sequenceEditStrandMateBaseColor)
        self.secStrucTextEdit.setPalette(palette)     
        self.secStrucTextEdit.setWordWrapMode( QTextOption.WrapAnywhere )
        self.secStrucTextEdit.setFixedHeight(20)
        self.secStrucTextEdit.setReadOnly(True)

        #Important to make sure that the horizontal and vertical scrollbars 
        #for these text edits are never displayed. 
        
        self.sequenceTextEdit.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.sequenceTextEdit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.secStrucTextEdit.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.secStrucTextEdit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.aaRulerTextEdit.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.aaRulerTextEdit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

    def _getFindLineEditStyleSheet(self):
        """
        Return the style sheet for the findLineEdit. This sets the following 
        properties only:
         - background-color

        This style is set whenever the searchStrig can't be found (sets
        a light red color background to the lineedit when this happens)   

        @return: The line edit style sheet.
        @rtype:  str

        """
        styleSheet = \
                   "QLineEdit {\
                   background-color: rgb(255, 102, 102)\
                   }"
        #Not used:
        #  background-color: rgb(217, 255, 216)\       

        return styleSheet

    def _setFindOptionsToolButtonMenu(self):
        """
        Sets the menu for the findOptionstoolbutton that appears a small 
        menu button next to the findLineEdit.
        """
        self.findOptionsMenu = QMenu(self.findOptionsToolButton)

        self.caseSensitiveFindAction = QAction(self.findOptionsToolButton)
        self.caseSensitiveFindAction.setText('Match Case')
        self.caseSensitiveFindAction.setCheckable(True)
        self.caseSensitiveFindAction.setChecked(False)

        self.findOptionsMenu.addAction(self.caseSensitiveFindAction)
        self.findOptionsMenu.addSeparator()

        self.findOptionsToolButton.setMenu(self.findOptionsMenu)

    def _addToolTipText(self):
        """
            What's Tool Tip text for widgets in this Property Manager.  
            """ 
        pass

    def _addWhatsThisText(self):
        """
            What's This text for widgets in this Property Manager.  

            """
        pass
    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.loadSequenceButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Open.png")  

        self.saveSequenceButton = PM_ToolButton(
            self, 
            iconPath = "ui/actions/Properties Manager/Save_Strand_Sequence.png") 

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        
        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)


        self.replaceLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text = "Replace")

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        

        #Widgets to include in the widget row. 
        widgetList = [('PM_ToolButton', self.loadSequenceButton, 0),
                      ('PM_ToolButton', self.saveSequenceButton, 1),
                      ('QLabel', "     Find:", 4),
                      ('PM_LineEdit', self.findLineEdit, 5),
                      ('PM_ToolButton', self.findOptionsToolButton, 6),
                      ('PM_ToolButton', self.findPreviousToolButton, 7),
                      ('PM_ToolButton', self.findNextToolButton, 8), 
                      ('QLabel', "     Replace:", 9),
                      ('PM_TextEdit', self.replaceLineEdit, 10), 
                      ('PM_PushButton', self.replacePushButton, 11),
                      ('PM_Label', self.warningSign, 12),
                      ('PM_Label', self.phraseNotFoundLabel, 13),
                      ('QSpacerItem', 5, 5, 14) ]

        widgetRow = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList,
                                 label = "",
                                 spanWidth = True )
class QuteMolPropertyManager(PM_Dialog):
    """
    The QuteMolPropertyManager class provides a Property Manager for 
    QuteMolX, allowing its launch for external rendering of the model.
    """
    
    # The title that appears in the Property Manager header.
    title = "QuteMolX"
    # The name of this Property Manager. This will be set to
    # the name of the PM_Dialog object via setObjectName().
    pmName = title
    # The relative path to the PNG file that appears in the header
    iconPath = "ui/actions/Properties Manager/QuteMol.png"
    
    # DNA Display choices.
    _axes_display_choices = [ "Render axes", 
                              "Hide axes" ]
    
    _bases_display_choices = [ "Render bases", 
                               "Hide bases" ]
                               #"Color bases black",
                               #"Color bases by type" ]
                       
    # PDB exclude flags = _axesFlags | _basesFlags
    _axesFlags  = EXCLUDE_HIDDEN_ATOMS
    _basesFlags = EXCLUDE_HIDDEN_ATOMS
    
    def __init__(self, win):
        """
        Construct the QuteMolX Property Manager.
        
        @param win: The main window.
        @type  win: QMainWindow
        """
        self.win = win
        self.pw  = None
        
        PM_Dialog.__init__( self, self.pmName, self.iconPath, self.title )
        
        msg = "Select a QuteMolX rendering style and click the \
        <b>Launch QuteMolX</b> button when ready."
        
        # This causes the "Message" box to be displayed as well.
        self.updateMessage(msg)
        
        # Hide Preview and Restore defaults button for Alpha9.
        self.hideTopRowButtons(PM_RESTORE_DEFAULTS_BUTTON | PM_PREVIEW_BUTTON)

    def _addGroupBoxes(self):
        """
        Add the 1st group box to the Property Manager.
        """
        self.pmGroupBox1 = PM_GroupBox(self, title = "DNA Display Options")
        self._loadGroupBox1(self.pmGroupBox1)
        
        self.pmGroupBox2 = PM_GroupBox(self, title = "Launch")
        self._loadGroupBox2(self.pmGroupBox2)
        
    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in 1st group box.
        
        @param pmGroupBox: The 1st group box in the PM.
        @type  pmGroupBox: L{PM_GroupBox}
        """
        
        self.axesCombobox = PM_ComboBox( 
            pmGroupBox,
            label        = 'Axes: ', 
            choices      = self._axes_display_choices, 
            index        = 0, 
            setAsDefault = True,
            spanWidth    = False )
        
        self.basesCombobox = PM_ComboBox( 
            pmGroupBox,
            label        = 'Bases: ', 
            choices      = self._bases_display_choices, 
            index        = 0, 
            setAsDefault = True,
            spanWidth    = False )
        
    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in 2nd group box.
        
        @param pmGroupBox: The 1st group box in the PM.
        @type  pmGroupBox: L{PM_GroupBox}
        """
        
        self.launchQuteMolButton = PM_ToolButton(
            pmGroupBox, 
            text      = "Launch QuteMolX",
            iconPath  = "ui/actions/Properties Manager/QuteMol.png",
            spanWidth = True )           

        self.launchQuteMolButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        
    def _addWhatsThisText(self):
        """
        "What's This" text for widgets in this Property Manager.
        """
        from ne1_ui.WhatsThisText_for_PropertyManagers import whatsThis_QuteMolPropertyManager
        whatsThis_QuteMolPropertyManager(self)
        
    def _addToolTipText(self):
        """
        Tool Tip text for widgets in this Property Manager.  
        """
        from ne1_ui.ToolTipText_for_PropertyManagers import ToolTip_QuteMolPropertyManager
        ToolTip_QuteMolPropertyManager(self)
    
    def show(self):
        """
        Shows the Property Manager. Overrides PM_Dialog.show)
        """
        if self.isVisible(): # Fixes bug 2680. --Mark 2008-03-19
            return
        PM_Dialog.show(self)
        self.connect_or_disconnect_signals(isConnect = True)

    def close(self):
        """
        Closes the Property Manager. Overrides PM_Dialog.close.
        """   
        #First exit temporary modes (e.g. Pan mode) if any.
        currentCommand = self.win.commandSequencer.currentCommand 
        if not currentCommand.command_has_its_own_gui:
            currentCommand.Done()
        self.connect_or_disconnect_signals(isConnect = False)
        PM_Dialog.close(self) 
        
    def ok_btn_clicked(self):
        """
        Slot for the OK button
        """
        self.accept() 
        self.close() # Close the property manager.        

        # The following reopens the property manager of the mode after 
        # when the PM of the reference geometry is closed. -- Ninad 20070603 
        # Note: the value of self.modePropertyManager can be None
        # @see: anyMode.propMgr
        #
        # (Note: once we have a real command sequencer, it will be
        #  handling this kind of thing itself, and the situation
        #  in which the currentCommand does not correspond to
        #  the current PM (as is true here while this separate PM
        #  is open, since it's not currentCommand.propMgr)
        #  will be deprecated or impossible. [bruce 071011 comment])
        self.modePropertyManager = self.win.currentCommand.propMgr

        if self.modePropertyManager:
            # (re)open the PM of the current command (i.e. "Build > Atoms").
            self.open(self.modePropertyManager)
        return
    
    def cancel_btn_clicked(self):
        """
        Slot for the Cancel button.
        """
        self.reject() 
        self.close() 

        # The following reopens the property manager of the command after
        # the PM of the reference geometry editCommand (i.e. Plane) is closed.
        # Note: the value of self.modePropertyManager can be None.
        # See anyMode.propMgr
        # (See similar code in ok_btn_clicked [bruce 071011 comment])
        self.modePropertyManager = self.win.currentCommand.propMgr

        if self.modePropertyManager:
            # (re)open the PM of the current command (i.e. "Build > Atoms").
            self.open(self.modePropertyManager)
        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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect
        
        change_connect(self.axesCombobox,
                     SIGNAL("currentIndexChanged(const QString&)"),
                     self.changeAxesDisplay)
        
        change_connect(self.basesCombobox,
                     SIGNAL("currentIndexChanged(const QString&)"),
                     self.changeBasesDisplay)
        
        change_connect(self.launchQuteMolButton, 
                       SIGNAL("clicked()"), 
                       self.launchQuteMol)
    
    def updateMessage(self, msg = ''):
        """
        Updates the message box with an informative message
        @param msg: Message to be displayed in the Message groupbox of 
                        the property manager
        @type  msg: string
        """
        self.MessageGroupBox.insertHtmlMessage(msg, 
                                               setAsDefault = False,
                                               minLines     = 5)
    
    def changeAxesDisplay(self, optionText):
        """
        Slot to change the axes display style.
        
        @param optionText: The text of the combobox option selected.
        @type  optionText: str        
        """
        
        if optionText == self._axes_display_choices[0]:
            self._axesFlags = EXCLUDE_HIDDEN_ATOMS
            # Cannot display axes if axis atoms are excluded.
            self.basesCombobox.setCurrentIndex(0)
        elif optionText == self._axes_display_choices[1]:
            self._axesFlags = EXCLUDE_HIDDEN_ATOMS | EXCLUDE_DNA_AXIS_BONDS
        else:
            print "Unknown axes display option: ", optionText
            
        #print "Axes display option=", optionText
        #print "Axes Flags=", self._axesFlags
    
    def changeBasesDisplay(self, optionText):
        """
        Slot to change the bases display style.
        
        @param optionText: The text of the combobox option selected.
        @type  optionText: str
        """
        if optionText == self._bases_display_choices[0]:
            self._basesFlags = EXCLUDE_HIDDEN_ATOMS
        elif optionText == self._bases_display_choices[1]:
            self._basesFlags = EXCLUDE_HIDDEN_ATOMS | EXCLUDE_DNA_AXIS_ATOMS
            # Cannot display axesif axis atoms are excluded.
            self.axesCombobox.setCurrentIndex(1)
        else:
            print "Unknown bases display option: ", optionText
            
        #print "Bases display option=", optionText
        #print "Bases Flags=", self._basesFlags
    
    def launchQuteMol(self):
        """
        Slot for 'Launch QuteMolX' button.
        Opens the QuteMolX rendering program and loads a copy of the current 
        model.

        Method:

        1. Write a PDB file of the current part.
        2. Write an atom attributes table text file containing atom radii and
           color information.
        3. Launches QuteMolX (with the PDB file as an argument). 

        """    
        cmd = greenmsg("QuteMolX : ")
        
        excludeFlags = self._axesFlags | self._basesFlags
        #print "Exclude flags=", excludeFlags
        
        pdb_file = write_qutemol_files(self.win.assy, excludeFlags)
        # Launch QuteMolX. It will verify the plugin.
        errorcode, msg = launch_qutemol(pdb_file) 
        # errorcode is ignored. 
        env.history.message(cmd + msg)
class QuteMolPropertyManager(PM_Dialog):
    """
    The QuteMolPropertyManager class provides a Property Manager for 
    QuteMolX, allowing its launch for external rendering of the model.
    """

    # The title that appears in the Property Manager header.
    title = "QuteMolX"
    # The name of this Property Manager. This will be set to
    # the name of the PM_Dialog object via setObjectName().
    pmName = title
    # The relative path to the PNG file that appears in the header
    iconPath = "ui/actions/Properties Manager/QuteMol.png"

    # DNA Display choices.
    _axes_display_choices = ["Render axes", "Hide axes"]

    _bases_display_choices = ["Render bases", "Hide bases"]
    #"Color bases black",
    #"Color bases by type" ]

    # PDB exclude flags = _axesFlags | _basesFlags
    _axesFlags = EXCLUDE_HIDDEN_ATOMS
    _basesFlags = EXCLUDE_HIDDEN_ATOMS

    def __init__(self, win):
        """
        Construct the QuteMolX Property Manager.
        
        @param win: The main window.
        @type  win: QMainWindow
        """
        self.win = win
        self.pw = None

        PM_Dialog.__init__(self, self.pmName, self.iconPath, self.title)

        msg = "Select a QuteMolX rendering style and click the \
        <b>Launch QuteMolX</b> button when ready."

        # This causes the "Message" box to be displayed as well.
        self.updateMessage(msg)

        # Hide Preview and Restore defaults button for Alpha9.
        self.hideTopRowButtons(PM_RESTORE_DEFAULTS_BUTTON | PM_PREVIEW_BUTTON)

    def _addGroupBoxes(self):
        """
        Add the 1st group box to the Property Manager.
        """
        self.pmGroupBox1 = PM_GroupBox(self, title="DNA Display Options")
        self._loadGroupBox1(self.pmGroupBox1)

        self.pmGroupBox2 = PM_GroupBox(self, title="Launch")
        self._loadGroupBox2(self.pmGroupBox2)

    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in 1st group box.
        
        @param pmGroupBox: The 1st group box in the PM.
        @type  pmGroupBox: L{PM_GroupBox}
        """

        self.axesCombobox = PM_ComboBox(pmGroupBox,
                                        label='Axes: ',
                                        choices=self._axes_display_choices,
                                        index=0,
                                        setAsDefault=True,
                                        spanWidth=False)

        self.basesCombobox = PM_ComboBox(pmGroupBox,
                                         label='Bases: ',
                                         choices=self._bases_display_choices,
                                         index=0,
                                         setAsDefault=True,
                                         spanWidth=False)

    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in 2nd group box.
        
        @param pmGroupBox: The 1st group box in the PM.
        @type  pmGroupBox: L{PM_GroupBox}
        """

        self.launchQuteMolButton = PM_ToolButton(
            pmGroupBox,
            text="Launch QuteMolX",
            iconPath="ui/actions/Properties Manager/QuteMol.png",
            spanWidth=True)

        self.launchQuteMolButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

    def _addWhatsThisText(self):
        """
        "What's This" text for widgets in this Property Manager.
        """
        from ne1_ui.WhatsThisText_for_PropertyManagers import whatsThis_QuteMolPropertyManager
        whatsThis_QuteMolPropertyManager(self)

    def _addToolTipText(self):
        """
        Tool Tip text for widgets in this Property Manager.  
        """
        from ne1_ui.ToolTipText_for_PropertyManagers import ToolTip_QuteMolPropertyManager
        ToolTip_QuteMolPropertyManager(self)

    def show(self):
        """
        Shows the Property Manager. Overrides PM_Dialog.show)
        """
        if self.isVisible():  # Fixes bug 2680. --Mark 2008-03-19
            return
        PM_Dialog.show(self)
        self.connect_or_disconnect_signals(isConnect=True)

    def close(self):
        """
        Closes the Property Manager. Overrides PM_Dialog.close.
        """
        #First exit temporary modes (e.g. Pan mode) if any.
        currentCommand = self.win.commandSequencer.currentCommand
        if not currentCommand.command_has_its_own_gui:
            currentCommand.Done()
        self.connect_or_disconnect_signals(isConnect=False)
        PM_Dialog.close(self)

    def ok_btn_clicked(self):
        """
        Slot for the OK button
        """
        self.accept()
        self.close()  # Close the property manager.

        # The following reopens the property manager of the mode after
        # when the PM of the reference geometry is closed. -- Ninad 20070603
        # Note: the value of self.modePropertyManager can be None
        # @see: anyMode.propMgr
        #
        # (Note: once we have a real command sequencer, it will be
        #  handling this kind of thing itself, and the situation
        #  in which the currentCommand does not correspond to
        #  the current PM (as is true here while this separate PM
        #  is open, since it's not currentCommand.propMgr)
        #  will be deprecated or impossible. [bruce 071011 comment])
        self.modePropertyManager = self.win.currentCommand.propMgr

        if self.modePropertyManager:
            # (re)open the PM of the current command (i.e. "Build > Atoms").
            self.open(self.modePropertyManager)
        return

    def cancel_btn_clicked(self):
        """
        Slot for the Cancel button.
        """
        self.reject()
        self.close()

        # The following reopens the property manager of the command after
        # the PM of the reference geometry editCommand (i.e. Plane) is closed.
        # Note: the value of self.modePropertyManager can be None.
        # See anyMode.propMgr
        # (See similar code in ok_btn_clicked [bruce 071011 comment])
        self.modePropertyManager = self.win.currentCommand.propMgr

        if self.modePropertyManager:
            # (re)open the PM of the current command (i.e. "Build > Atoms").
            self.open(self.modePropertyManager)
        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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        change_connect(self.axesCombobox,
                       SIGNAL("currentIndexChanged(const QString&)"),
                       self.changeAxesDisplay)

        change_connect(self.basesCombobox,
                       SIGNAL("currentIndexChanged(const QString&)"),
                       self.changeBasesDisplay)

        change_connect(self.launchQuteMolButton, SIGNAL("clicked()"),
                       self.launchQuteMol)

    def updateMessage(self, msg=''):
        """
        Updates the message box with an informative message
        @param msg: Message to be displayed in the Message groupbox of 
                        the property manager
        @type  msg: string
        """
        self.MessageGroupBox.insertHtmlMessage(msg,
                                               setAsDefault=False,
                                               minLines=5)

    def changeAxesDisplay(self, optionText):
        """
        Slot to change the axes display style.
        
        @param optionText: The text of the combobox option selected.
        @type  optionText: str        
        """

        if optionText == self._axes_display_choices[0]:
            self._axesFlags = EXCLUDE_HIDDEN_ATOMS
            # Cannot display axes if axis atoms are excluded.
            self.basesCombobox.setCurrentIndex(0)
        elif optionText == self._axes_display_choices[1]:
            self._axesFlags = EXCLUDE_HIDDEN_ATOMS | EXCLUDE_DNA_AXIS_BONDS
        else:
            print "Unknown axes display option: ", optionText

        #print "Axes display option=", optionText
        #print "Axes Flags=", self._axesFlags

    def changeBasesDisplay(self, optionText):
        """
        Slot to change the bases display style.
        
        @param optionText: The text of the combobox option selected.
        @type  optionText: str
        """
        if optionText == self._bases_display_choices[0]:
            self._basesFlags = EXCLUDE_HIDDEN_ATOMS
        elif optionText == self._bases_display_choices[1]:
            self._basesFlags = EXCLUDE_HIDDEN_ATOMS | EXCLUDE_DNA_AXIS_ATOMS
            # Cannot display axesif axis atoms are excluded.
            self.axesCombobox.setCurrentIndex(1)
        else:
            print "Unknown bases display option: ", optionText

        #print "Bases display option=", optionText
        #print "Bases Flags=", self._basesFlags

    def launchQuteMol(self):
        """
        Slot for 'Launch QuteMolX' button.
        Opens the QuteMolX rendering program and loads a copy of the current 
        model.

        Method:

        1. Write a PDB file of the current part.
        2. Write an atom attributes table text file containing atom radii and
           color information.
        3. Launches QuteMolX (with the PDB file as an argument). 

        """
        cmd = greenmsg("QuteMolX : ")

        excludeFlags = self._axesFlags | self._basesFlags
        #print "Exclude flags=", excludeFlags

        pdb_file = write_qutemol_files(self.win.assy, excludeFlags)
        # Launch QuteMolX. It will verify the plugin.
        errorcode, msg = launch_qutemol(pdb_file)
        # errorcode is ignored.
        env.history.message(cmd + msg)
Пример #22
0
class Ui_MovePropertyManager(Command_PropertyManager):
    
       
    # The title that appears in the Property Manager header        
    title = "Move"
    # The name of this Property Manager. This will be set to
    # the name of the PM_Dialog object via setObjectName().
    pmName = title
    # The relative path to the PNG file that appears in the header
    iconPath = "ui/actions/Properties Manager/Translate_Components.png"
    
    # The title(s) that appear in the property manager header.
    # (these are changed depending on the active group box) 
    translateTitle = "Translate"
    rotateTitle = "Rotate"

    # The full path to PNG file(s) that appears in the header.
    translateIconPath = "ui/actions/Properties Manager/Translate_Components.png"
    rotateIconPath = "ui/actions/Properties Manager/Rotate_Components.png"
    
    def __init__(self, command):  
        _superclass.__init__(self, command)       
        self.showTopRowButtons(PM_DONE_BUTTON | PM_WHATS_THIS_BUTTON)
    
    def _addGroupBoxes(self):
        """
        Add groupboxes to the Property Manager dialog. 
        """
        
        self.translateGroupBox = PM_GroupBox( self, 
                                              title = "Translate",
                                              connectTitleButton = False)
        self.translateGroupBox.titleButton.setShortcut('T')
        self._loadTranslateGroupBox(self.translateGroupBox)
        
        self.rotateGroupBox = PM_GroupBox( self, 
                                           title = "Rotate",
                                           connectTitleButton = False)
        self.rotateGroupBox.titleButton.setShortcut('R')
        self._loadRotateGroupBox(self.rotateGroupBox)
        
        self.translateGroupBox.collapse()
        self.rotateGroupBox.collapse()
            
    # == Begin Translate Group Box =====================
    
    def _loadTranslateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Translate group box.
        @param inPmGroupBox: The Translate group box in the PM
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        
        translateChoices = [ "Free Drag", 
                             "By Delta XYZ", 
                             "To XYZ Position" ]
        
        self.translateComboBox = \
            PM_ComboBox( inPmGroupBox,
                         label        = '', 
                         choices      = translateChoices, 
                         index        = 0, 
                         setAsDefault = False,
                         spanWidth    = True )
        
        self.freeDragTranslateGroupBox = PM_GroupBox( inPmGroupBox )
        self._loadFreeDragTranslateGroupBox(self.freeDragTranslateGroupBox)
                
        self.byDeltaGroupBox = PM_GroupBox( inPmGroupBox )
        self._loadByDeltaGroupBox(self.byDeltaGroupBox)
        
        self.toPositionGroupBox = PM_GroupBox( inPmGroupBox )
        self._loadToPositionGroupBox(self.toPositionGroupBox)
        
        self.updateTranslateGroupBoxes(0)
    
    def _loadFreeDragTranslateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Free Drag Translate group box, which is present 
        within the Translate groupbox.
        @param inPmGroupBox: The Free Drag Translate group box in the Translate 
                             group box. 
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format: 
        # - buttonId, 
        # - buttonText , 
        # - iconPath
        # - tooltip
        # - shortcut
        # - column
        
         
        BUTTON_LIST = [ 
            ( "QToolButton", 1,  "MOVEDEFAULT", 
              "ui/actions/Properties Manager/Move_Free.png", "", "F", 0),
            ( "QToolButton", 2,  "TRANSX", 
              "ui/actions/Properties Manager/TranslateX.png", "", "X", 1),
            ( "QToolButton", 3,  "TRANSY",  
              "ui/actions/Properties Manager/TranslateY.png", "", "Y", 2),
            ( "QToolButton", 4,  "TRANSZ",  
              "ui/actions/Properties Manager/TranslateZ.png", "", "Z", 3),
            ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",  
              "ui/actions/Properties Manager/translate+rotate-A.png", "", \
              "A", 4)
                        
            ]
            
        self.freeDragTranslateButtonGroup = \
            PM_ToolButtonRow( inPmGroupBox, 
                               title        = "",
                               buttonList   = BUTTON_LIST,
                               checkedId    = 1,
                               setAsDefault = True,
                               )
        self.transFreeButton =self.freeDragTranslateButtonGroup.getButtonById(1)
        self.transXButton = self.freeDragTranslateButtonGroup.getButtonById(2)
        self.transYButton = self.freeDragTranslateButtonGroup.getButtonById(3)
        self.transZButton = self.freeDragTranslateButtonGroup.getButtonById(4)
        self.transAlongAxisButton = \
            self.freeDragTranslateButtonGroup.getButtonById(5)
        
        self.moveFromToButton = PM_ToolButton(
                    inPmGroupBox, 
                    text = "Translate from/to",
                    iconPath  = "ui/actions/Properties Manager"\
                    "/Translate_Components.png",
                    spanWidth = True
                    
                    )
        self.moveFromToButton.setCheckable(True)
        self.moveFromToButton.setAutoRaise(True)
        self.moveFromToButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        
        
        self.startCoordLineEdit = PM_LineEdit( 
            inPmGroupBox, 
            label        = "ui/actions/Properties Manager"\
                    "/Move_Start_Point.png",
            text         = "Define 'from' and 'to' points",
            setAsDefault = False,
            )
        self.startCoordLineEdit.setReadOnly(True)
        self.startCoordLineEdit.setEnabled(False)
        
    def _loadByDeltaGroupBox(self, inPmGroupBox):
        """
        Load widgets in the translate By Delta group box, which is present 
        within the Translate groupbox.
        @param inPmGroupBox: The Translate By Delta group box in the translate 
                             group box. 
        @type  inPmGroupBox: L{PM_GroupBox}
        """

        self.moveDeltaXSpinBox = \
            PM_DoubleSpinBox( 
                inPmGroupBox, 
                label        = "ui/actions/Properties Manager/Delta_X.png",
                value        = 0.0, 
                setAsDefault = True,
                minimum      = -100.0, 
                maximum      =  100.0, 
                singleStep   = 1.0, 
                decimals     = 3, 
                suffix       = ' Angstroms',
                spanWidth    = False )
        
        self.moveDeltaYSpinBox = \
            PM_DoubleSpinBox( 
                inPmGroupBox, 
                label        = "ui/actions/Properties Manager/Delta_Y.png",
                value        = 0.0, 
                setAsDefault = True,
                minimum      = -100.0, 
                maximum      =  100.0, 
                singleStep   = 1.0, 
                decimals     = 3, 
                suffix       = ' Angstroms',
                spanWidth    = False )
        
        self.moveDeltaZSpinBox = \
            PM_DoubleSpinBox( 
                inPmGroupBox, 
                label        = "ui/actions/Properties Manager/Delta_Z.png",
                value        = 0.0, 
                setAsDefault = True,
                minimum      = -100.0, 
                maximum      =  100.0, 
                singleStep   = 1.0, 
                decimals     = 3, 
                suffix       = ' Angstroms',
                spanWidth    = False )
        
        DELTA_BUTTONS = [
                        ("QToolButton",1,  "Delta Plus", 
                         "ui/actions/Properties Manager/Move_Delta_Plus.png", 
                         "", "+", 0 ),
            
                        ( "QToolButton", 2,  "Delta Minus",  
                          "ui/actions/Properties Manager/Move_Delta_Minus.png", 
                          "", "-", 1 )
                        ]
        
        self.translateDeltaButtonRow = \
            PM_ToolButtonRow( inPmGroupBox, 
                              title        = "",
                              buttonList   = DELTA_BUTTONS,
                              label        = 'Translate:',
                              isAutoRaise  =  True,
                              isCheckable  =  False                           
                            )
        self.transDeltaPlusButton = \
            self.translateDeltaButtonRow.getButtonById(1)
        self.transDeltaMinusButton = \
            self.translateDeltaButtonRow.getButtonById(2)
        
            
    def _loadToPositionGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Translate To a given Position group box, which is 
        present within the Translate groupbox.
        @param inPmGroupBox: Translate To Position group box in the Translate 
                             group box.
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        
        self.toPositionspinboxes = PM_CoordinateSpinBoxes(inPmGroupBox)
        
        self.moveXSpinBox = self.toPositionspinboxes.xSpinBox
        self.moveYSpinBox = self.toPositionspinboxes.ySpinBox
        self.moveZSpinBox = self.toPositionspinboxes.zSpinBox
        
        
        self.moveAbsoluteButton = \
            PM_PushButton( inPmGroupBox,
                           label     = "",
                           text      = "Move Selection",
                           spanWidth = True )
            
    # == Begin Rotate Group Box =====================
    def _loadRotateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Rotate group box, 
        @param inPmGroupBox: The Rotate GroupBox in the PM
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        
        rotateChoices = [ "Free Drag", "By Specified Angle"]
        
        self.rotateComboBox = \
            PM_ComboBox( inPmGroupBox,
                         label        = '', 
                         choices      = rotateChoices, 
                         index        = 0, 
                         setAsDefault = False,
                         spanWidth    = True )
        
        self.rotateAsUnitCB = \
            PM_CheckBox( inPmGroupBox,
                         text         = 'Rotate as a unit' ,
                         widgetColumn = 0,
                         state        = Qt.Checked )
        
               
        self.freeDragRotateGroupBox = PM_GroupBox( inPmGroupBox )
        self._loadFreeDragRotateGroupBox(self.freeDragRotateGroupBox)
        
        self.bySpecifiedAngleGroupBox = PM_GroupBox( inPmGroupBox )
        self._loadBySpecifiedAngleGroupBox(self.bySpecifiedAngleGroupBox)
        
        self.updateRotateGroupBoxes(0)    
        
    def _loadFreeDragRotateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Free Drag Rotate group box, which is 
        present within the Rotate groupbox.
        @param inPmGroupBox: The Free Drag Rotate group box in the Rotate 
                             group box.
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format: 
        # - buttonId, 
        # - buttonText , 
        # - iconPath
        # - tooltip
        # - shortcut
        # - column
        
        BUTTON_LIST = [ 
            ( "QToolButton", 1,  "ROTATEDEFAULT", 
              "ui/actions/Properties Manager/Rotate_Free.png", "", "F", 0 ),
            
            ( "QToolButton", 2,  "ROTATEX", 
              "ui/actions/Properties Manager/RotateX.png", "", "X", 1 ),
            
            ( "QToolButton", 3,  "ROTATEY",  
              "ui/actions/Properties Manager/RotateY.png", "", "Y", 2 ),
            
            ( "QToolButton", 4,  "ROTATEZ",  
              "ui/actions/Properties Manager/RotateZ.png", "", "Z", 3 ),
            
            ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",  
              "ui/actions/Properties Manager/translate+rotate-A.png", "", \
              "A", 4 )
                        
            ]
            
        self.freeDragRotateButtonGroup = \
            PM_ToolButtonRow( inPmGroupBox, 
                               title        = "",
                               buttonList   = BUTTON_LIST,
                               spanWidth = True,
                               checkedId    = 1,
                               setAsDefault = True,
                            )
                
        self.rotateFreeButton = self.freeDragRotateButtonGroup.getButtonById(1)
        self.rotateXButton    = self.freeDragRotateButtonGroup.getButtonById(2)
        self.rotateYButton    = self.freeDragRotateButtonGroup.getButtonById(3)
        self.rotateZButton    = self.freeDragRotateButtonGroup.getButtonById(4)
        self.rotAlongAxisButton = \
            self.freeDragRotateButtonGroup.getButtonById(5)
        
        inPmGroupBox.setStyleSheet(
            self.freeDragRotateButtonGroup._getStyleSheet())
                
        X_ROW_LABELS = [("QLabel", "Delta Theta X:", 0),
                        ("QLabel", "", 1),
                        ("QLabel", "0.00", 2),
                        ("QLabel", "Degrees", 3)]
        
        Y_ROW_LABELS = [("QLabel", "Delta Theta Y:", 0),
                        ("QLabel", "", 1),
                        ("QLabel", "0.00", 2),
                        ("QLabel", "Degrees", 3)]
        
        Z_ROW_LABELS = [("QLabel", "Delta Theta Z:", 0),
                        ("QLabel", "", 1),
                        ("QLabel", "0.00", 2),
                        ("QLabel", "Degrees", 3)]
        
        self.rotateXLabelRow = PM_LabelRow( inPmGroupBox,
                                            title = "",
                                            labelList = X_ROW_LABELS )  
        self.deltaThetaX_lbl = self.rotateXLabelRow.labels[2]
                                           
        self.rotateYLabelRow = PM_LabelRow( inPmGroupBox,
                                            title = "",
                                            labelList = Y_ROW_LABELS )
        self.deltaThetaY_lbl = self.rotateYLabelRow.labels[2]
                                          
        self.rotateZLabelRow = PM_LabelRow( inPmGroupBox,
                                            title = "",
                                            labelList = Z_ROW_LABELS )  
        self.deltaThetaZ_lbl = self.rotateZLabelRow.labels[2]    
        
        self.rotateAboutPointButton = PM_ToolButton(
                    inPmGroupBox, 
                    text = "Rotate selection about a point",
                    iconPath  = "ui/actions/Properties Manager"\
                    "/Rotate_Components.png",
                    spanWidth = True                    
                    )
        self.rotateAboutPointButton.setCheckable(True)
        self.rotateAboutPointButton.setAutoRaise(True)
        self.rotateAboutPointButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        
        
        self.rotateStartCoordLineEdit = PM_LineEdit( 
            inPmGroupBox, 
            label        = "ui/actions/Properties Manager"\
                    "/Move_Start_Point.png",
            text         = "Define 3 points",
            setAsDefault = False,
            )
        self.rotateStartCoordLineEdit.setReadOnly(True)
        self.rotateStartCoordLineEdit.setEnabled(False)
            
            
    def _loadBySpecifiedAngleGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Rotate By Specified Angle group box, which is 
        present within the Rotate groupbox.
        @param inPmGroupBox: Rotate By Specified Angle group box in the Rotate 
                             group box.
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format: 
        # - buttonId, 
        # - buttonText , 
        # - iconPath
        # - tooltip
        # - shortcut
        # - column
        
        BUTTON_LIST = [ 
            ( "QToolButton", 1,  "ROTATEX", 
              "ui/actions/Properties Manager/RotateX.png", 
              "Rotate about X axis", "X", 0 ),
            
            ( "QToolButton", 2,  "ROTATEY",  
              "ui/actions/Properties Manager/RotateY.png", 
              "Rotate about Y axis", "Y", 1 ),
            
            ( "QToolButton", 3,  "ROTATEZ",  
              "ui/actions/Properties Manager/RotateZ.png", 
              "Rotate about Z axis","Z", 2 ),
            ]
        
        
        
        self.rotateAroundAxisButtonRow = \
            PM_ToolButtonRow( inPmGroupBox, 
                              title        = "",
                              buttonList   = BUTTON_LIST,
                              alignment    = 'Right',
                              label        = 'Rotate Around:'
                            )
        self.rotXaxisButton = \
            self.rotateAroundAxisButtonRow.getButtonById(1)
        
        self.rotYaxisButton = \
            self.rotateAroundAxisButtonRow.getButtonById(2)
        
        self.rotZaxisButton = \
            self.rotateAroundAxisButtonRow.getButtonById(3)
        
        

        self.rotateThetaSpinBox = \
            PM_DoubleSpinBox(inPmGroupBox,
                             label        = "Rotate By:",
                             value        = 0.0, 
                             setAsDefault = True,
                             minimum      = 0, 
                             maximum      = 360.0,
                             singleStep   = 1.0, 
                             decimals     = 2, 
                             suffix       = ' Degrees')
        
        
        THETA_BUTTONS = [ 
            ( "QToolButton", 1,  "Theta Plus", 
              "ui/actions/Properties Manager/Move_Theta_Plus.png", "", "+", 0 ),
            
            ( "QToolButton", 2,  "Theta Minus",  
              "ui/actions/Properties Manager/Move_Theta_Minus.png", "", "-", 1 )
            ]
        
        self.rotateThetaButtonRow = \
            PM_ToolButtonRow( inPmGroupBox, 
                              title        = "",
                              buttonList   = THETA_BUTTONS,
                              label        = 'Direction:',
                              isAutoRaise  =  True,
                              isCheckable  =  False                           
                            )
        self.rotateThetaPlusButton =  self.rotateThetaButtonRow.getButtonById(1)
        self.rotateThetaMinusButton = self.rotateThetaButtonRow.getButtonById(2)
    
    # == End Rotate Group Box =====================
        
    # == Slots for Translate group box
    def _hideAllTranslateGroupBoxes(self):
        """
        Hides all Translate group boxes.
        """
        self.toPositionGroupBox.hide()
        self.byDeltaGroupBox.hide()
        self.freeDragTranslateGroupBox.hide()
            
    def updateTranslateGroupBoxes(self, id):
        """
        Update the translate group boxes displayed based on the translate
        option selected.
        @param id: Integer value corresponding to the combobox item in the 
                   Translate group box. 
        @type  id: int
        """
        self._hideAllTranslateGroupBoxes()
        
        if id is 0:
            self.freeDragTranslateGroupBox.show()
                               
        if id is 1:
            self.byDeltaGroupBox.show()                    
        if id is 2:
            self.toPositionGroupBox.show()
           
        self.updateMessage()
    
    def changeMoveOption(self, button):
        """
        Subclasses should reimplement this method.
        
        @param button: QToolButton that decides the type of translate operation 
        to be set.
        @type  button: QToolButton 
                       L{http://doc.trolltech.com/4.2/qtoolbutton.html}
        @see: B{MovePropertyManager.changeMoveOption} which overrides this
              method
        """
        pass
    
    # == Slots for Rotate group box
    def updateRotateGroupBoxes(self, id):
        """
        Update the translate group boxes displayed based on the translate
        option selected.
        @param id: Integer value corresponding to the combobox item in the 
                   Rotate group box. 
        @type  id: int
        """
        if id is 0:
            self.bySpecifiedAngleGroupBox.hide()
            self.freeDragRotateGroupBox.show()   
        if id is 1:
            self.freeDragRotateGroupBox.hide()
            self.bySpecifiedAngleGroupBox.show()
            
        self.updateMessage()
            
    def changeRotateOption(self, button):
        """
        Subclasses should reimplement this method. 
        
        @param button: QToolButton that decides the type of rotate operation 
        to be set.
        @type  button: QToolButton 
                       L{http://doc.trolltech.com/4.2/qtoolbutton.html}
        @see: B{MovePropertyManage.changeRotateOption} which overrides this 
             method
        """
        pass
    
    def _addWhatsThisText(self):
        """
        What's This text for some of the widgets in this Property Manager.  

        """
        from ne1_ui.WhatsThisText_for_PropertyManagers import whatsThis_MovePropertyManager
        whatsThis_MovePropertyManager(self)
        
    def _addToolTipText(self):
        """
        Tool Tip text for widgets in this Property Manager.  
        """
        from ne1_ui.ToolTipText_for_PropertyManagers import ToolTip_MovePropertyManager
        ToolTip_MovePropertyManager(self)
Пример #23
0
class SelectNodeByNameDockWidget(PM_DockWidget):
    """
    The Ui_DnaSequenceEditor class defines UI elements for the Sequence Editor
    object. The sequence editor is usually visible while in DNA edit mode.
    It is a DockWidget that is doced at the bottom of the MainWindow
    """
    _title = "Select Node by Name"
    _groupBoxCount = 0
    _lastGroupBox = None

    def __init__(self, win):
        """
        Constructor for the Ui_DnaSequenceEditor 
        @param win: The parentWidget (MainWindow) for the sequence editor 
        """

        self.win = win
        parentWidget = win

        _superclass.__init__(self, parentWidget, title=self._title)

        win.addDockWidget(Qt.BottomDockWidgetArea, self)
        self.setFixedHeight(120)
        ##self.setFixedWidth(90)
        self.connect_or_disconnect_signals(True)

        if not self.win.selectByNameAction.isChecked():
            self.close()

    def show(self):
        """
        Overrides superclass method.
        """
        _superclass.show(self)
        val = env.prefs[dnaSearchTypeLabelChoice_prefs_key]
        self.searchTypeComboBox_indexChanged(val)

    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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        self._listWidget.connect_or_disconnect_signals(isConnect)

        change_connect(self.searchToolButton, SIGNAL("clicked()"),
                       self.searchNodes)

        prefs_key = dnaSearchTypeLabelChoice_prefs_key
        connect_comboBox_with_pref(self.searchTypeComboBox, prefs_key)

        change_connect(self.searchTypeComboBox,
                       SIGNAL("currentIndexChanged(int)"),
                       self.searchTypeComboBox_indexChanged)

    def searchTypeComboBox_indexChanged(self, val):
        if val == 0:
            ##self._widgetRow1.show()
            ##self._widgetRow2.hide()
            self._widgetRow1.setEnabled(True)
            self._widgetRow2.setEnabled(False)
        else:
            ##self._widgetRow2.show()
            ##self._widgetRow1.hide()
            self._widgetRow2.setEnabled(True)
            self._widgetRow1.setEnabled(False)

    def searchNodes(self):
        """
        ONLY implemented for DnaStrand or DnaSegments. 
        """

        assy = self.win.assy

        topnode = assy.part.topnode
        lst = []

        def func(node):
            if isinstance(node, assy.DnaStrandOrSegment):
                lst.append(node)

        topnode.apply2all(func)

        choice = env.prefs[dnaSearchTypeLabelChoice_prefs_key]

        if choice == 0:
            nodes = self._searchNodesByName(lst)
        elif choice == 1:
            nodes = self._searchNodesByNucleotides(lst)

        self._listWidget.insertItems(row=0, items=nodes)

    def _searchNodesByNucleotides(self, nodeList):
        lst = nodeList
        min_val = self._nucleotidesSpinBox_1.value()
        max_val = self._nucleotidesSpinBox_2.value()
        if min_val > max_val:
            print "Lower value for number of nucleotides exceeds max search value"
            return ()

        def func2(node):
            n = node.getNumberOfNucleotides()

            return (n >= min_val and n <= max_val)

        return filter(lambda m: func2(m), lst)

    def _searchNodesByName(self, nodeList):
        nodeNameString = self.findLineEdit.text()
        nodeNameString = str(nodeNameString)

        lst = nodeList

        def func2(node):
            n = len(nodeNameString)
            if len(node.name) < n:
                return False

            nameString = str(node.name[:n])

            if nameString.lower() == nodeNameString.lower():
                return True

            return False

        return filter(lambda m: func2(m), lst)

    def closeEvent(self, event):
        self.win.selectByNameAction.setChecked(False)
        _superclass.closeEvent(self, event)

    def _loadWidgets(self):
        """
        Overrides PM.PM_DockWidget._loadWidgets. Loads the widget in this
        dockwidget.
        """
        self._loadMenuWidgets()
        self._loadTableWidget()

    def _loadTableWidget(self):
        self._listWidget = PM_DnaSearchResultTable(self, self.win)

    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.searchTypeComboBox  = \
            PM_ComboBox( self,
                         label         =  "Search options:",
                         choices       =  ["By node name", "By # of bases (DNA only)"],
                         setAsDefault  =  True)

        #Find  widgets --
        self._nucleotidesSpinBox_1 = PM_SpinBox(self,
                                                label="",
                                                value=10,
                                                setAsDefault=False,
                                                singleStep=10,
                                                minimum=1,
                                                maximum=50000)

        self._nucleotidesSpinBox_2 = PM_SpinBox(self,
                                                label="",
                                                value=50,
                                                setAsDefault=False,
                                                singleStep=10,
                                                minimum=1,
                                                maximum=50000)


        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)

        self.findLineEdit.setMaximumWidth(80)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        ##self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        ##self._setFindOptionsToolButtonMenu()

        self.searchToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Next.png")
        self.searchToolButton.setAutoRaise(False)

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done --

        # When the widget type starts with the word 'PM_' , the
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned
        # labels (and if they were recreated as mentioned above),
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2]
        #Cleanup in PM_widgetGrid could be to check if the widget starts with
        #'Q'  instead of 'PM_'

        #Widgets to include in the widget row.

        widgetList1 = [('QLabel', "     Search for name:", 1),
                       ('PM_LineEdit', self.findLineEdit, 2),
                       ('PM_ToolButton', self.findOptionsToolButton, 3),
                       ('PM_ToolButton', self.searchToolButton, 4),
                       ('PM_Label', self.warningSign, 5),
                       ('PM_Label', self.phraseNotFoundLabel, 6),
                       ('QSpacerItem', 5, 5, 7)]

        widgetList2 = [('QLabel', "     Number of bases: >=", 1),
                       ('PM_SpinBox', self._nucleotidesSpinBox_1, 2),
                       ('QLabel', "     <=", 3),
                       ('PM_SpinBox', self._nucleotidesSpinBox_2, 4),
                       ('QSpacerItem', 5, 5, 5)]

        widgetList3 = [('QSpacerItem', 5, 5, 1),
                       ('PM_ToolButton', self.searchToolButton, 2),
                       ('PM_Label', self.warningSign, 3),
                       ('PM_Label', self.phraseNotFoundLabel, 4),
                       ('QSpacerItem', 5, 5, 5)]

        self._widgetRow1 = PM_WidgetRow(self,
                                        title='',
                                        widgetList=widgetList1,
                                        label="",
                                        spanWidth=True)

        self._widgetRow2 = PM_WidgetRow(self,
                                        title='',
                                        widgetList=widgetList2,
                                        label="",
                                        spanWidth=True)

        self._widgetRow3 = PM_WidgetRow(self,
                                        title='',
                                        widgetList=widgetList3,
                                        label="",
                                        spanWidth=True)
class DnaDuplexPropertyManager( DnaOrCnt_PropertyManager ):
    """
    The DnaDuplexPropertyManager class provides a Property Manager
    for the B{Build > DNA > Duplex} 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         =  "Insert DNA"
    pmName        =  title
    iconPath      =  "ui/actions/Tools/Build Structures/InsertDsDna.png"

    def __init__( self, win, editCommand ):
        """
        Constructor for the DNA Duplex property manager.
        """
        self.endPoint1 = None
        self.endPoint2 = None

        self._conformation  = "B-DNA"
        self._numberOfBases = 0
        self._basesPerTurn  = getDuplexBasesPerTurn(self._conformation)
        self._duplexRise    = getDuplexRise(self._conformation)
        self._duplexLength  = getDuplexLength(self._conformation,
                                              self._numberOfBases)


        _superclass.__init__( self,
                              win,
                              editCommand)

        self.showTopRowButtons( PM_DONE_BUTTON | \
                                PM_CANCEL_BUTTON | \
                                PM_WHATS_THIS_BUTTON)


    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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect


        change_connect(self._placementOptions.buttonGroup,
                       SIGNAL("buttonClicked(int)"),
                       self.activateSpecifyReferencePlaneTool)

        change_connect( self.conformationComboBox,
                        SIGNAL("currentIndexChanged(int)"),
                        self.conformationComboBoxChanged )

        change_connect( self.numberOfBasePairsSpinBox,
                        SIGNAL("valueChanged(int)"),
                        self.numberOfBasesChanged )

        change_connect( self.basesPerTurnDoubleSpinBox,
                        SIGNAL("valueChanged(double)"),
                        self.basesPerTurnChanged )

        change_connect( self.duplexRiseDoubleSpinBox,
                        SIGNAL("valueChanged(double)"),
                        self.duplexRiseChanged )

        change_connect(self.showCursorTextCheckBox,
                       SIGNAL('stateChanged(int)'),
                       self._update_state_of_cursorTextGroupBox)
        
        self.duplexRiseDoubleSpinBox.connectWithState(
            Preferences_StateRef_double( bdnaRise_prefs_key, 
                                         env.prefs[bdnaRise_prefs_key] )
            )
        
        self.basesPerTurnDoubleSpinBox.connectWithState(
            Preferences_StateRef_double( bdnaBasesPerTurn_prefs_key, 
                                         env.prefs[bdnaBasesPerTurn_prefs_key] )
            )

        
                
 
    def ok_btn_clicked(self):
        """
        Slot for the OK button
        """
        if self.editCommand:
            self.editCommand.preview_or_finalize_structure(previewing = False)
            ##env.history.message(self.editCommand.logMessage)
        self.win.toolsDone()

    def cancel_btn_clicked(self):
        """
        Slot for the Cancel button.
        """
        if self.editCommand:
            self.editCommand.cancelStructure()
        self.win.toolsCancel()


    def _update_widgets_in_PM_before_show(self):
        """
        Update various widgets  in this Property manager.
        Overrides superclass method

        @see: MotorPropertyManager._update_widgets_in_PM_before_show
        @see: self.show where it is called.
        """
        pass

    def getFlyoutActionList(self):
        """ returns custom actionlist that will be used in a specific mode
        or editing a feature etc Example: while in movie mode,
        the _createFlyoutToolBar method calls
        this """


        #'allActionsList' returns all actions in the flyout toolbar
        #including the subcontrolArea actions
        allActionsList = []

        #Action List for  subcontrol Area buttons.
        #In this mode there is really no subcontrol area.
        #We will treat subcontrol area same as 'command area'
        #(subcontrol area buttons will have an empty list as their command area
        #list). We will set  the Comamnd Area palette background color to the
        #subcontrol area.

        subControlAreaActionList =[]

        self.exitEditCommandAction.setChecked(True)
        subControlAreaActionList.append(self.exitEditCommandAction)

        separator = QAction(self.w)
        separator.setSeparator(True)
        subControlAreaActionList.append(separator)


        allActionsList.extend(subControlAreaActionList)

        #Empty actionlist for the 'Command Area'
        commandActionLists = []

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

        params = (subControlAreaActionList, commandActionLists, allActionsList)

        return params

    def _addGroupBoxes( self ):
        """
        Add the DNA Property Manager group boxes.
        """
        self._pmReferencePlaneGroupBox = PM_GroupBox( self,
                                                      title = "Placement Options" )
        self._loadReferencePlaneGroupBox( self._pmReferencePlaneGroupBox )

        self._pmGroupBox1 = PM_GroupBox( self, title = "Endpoints" )
        self._loadGroupBox1( self._pmGroupBox1 )

        self._pmGroupBox1.hide()

        self._pmGroupBox2 = PM_GroupBox( self, title = "Parameters" )
        self._loadGroupBox2( self._pmGroupBox2 )

        self._displayOptionsGroupBox = PM_GroupBox( self,
                                                    title = "Display Options" )
        self._loadDisplayOptionsGroupBox( self._displayOptionsGroupBox )


    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in group box 3.
        """
        #Folllowing toolbutton facilitates entering a temporary DnaLineMode
        #to create a DNA using endpoints of the specified line.
        self.specifyDnaLineButton = PM_ToolButton(
            pmGroupBox,
            text = "Specify Endpoints",
            iconPath  = "ui/actions/Properties Manager/Pencil.png",
            spanWidth = True
        )
        self.specifyDnaLineButton.setCheckable(True)
        self.specifyDnaLineButton.setAutoRaise(True)
        self.specifyDnaLineButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

        #EndPoint1 and endPoint2 coordinates. These widgets are hidden
        # as of 2007- 12 - 05
        self._endPoint1SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label = "End Point 1")
        self.x1SpinBox = self._endPoint1SpinBoxes.xSpinBox
        self.y1SpinBox = self._endPoint1SpinBoxes.ySpinBox
        self.z1SpinBox = self._endPoint1SpinBoxes.zSpinBox

        self._endPoint2SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label = "End Point 2")
        self.x2SpinBox = self._endPoint2SpinBoxes.xSpinBox
        self.y2SpinBox = self._endPoint2SpinBoxes.ySpinBox
        self.z2SpinBox = self._endPoint2SpinBoxes.zSpinBox

        self._endPoint1SpinBoxes.hide()
        self._endPoint2SpinBoxes.hide()

    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in group box 4.
        """

        self.conformationComboBox  = \
            PM_ComboBox( pmGroupBox,
                         label         =  "Conformation:",
                         choices       =  ["B-DNA"],
                         setAsDefault  =  True)

        dnaModelChoices = ['PAM3', 'PAM5']
        self.dnaModelComboBox = \
            PM_ComboBox( pmGroupBox,
                         label         =  "Model:",
                         choices       =  dnaModelChoices,
                         setAsDefault  =  True)


        self.basesPerTurnDoubleSpinBox  =  \
            PM_DoubleSpinBox( pmGroupBox,
                              label         =  "Bases per turn:",
                              value         =  env.prefs[bdnaBasesPerTurn_prefs_key],
                              setAsDefault  =  True,
                              minimum       =  8.0,
                              maximum       =  20.0,
                              decimals      =  2,
                              singleStep    =  0.1 )
        
        
        self.duplexRiseDoubleSpinBox  =  \
            PM_DoubleSpinBox( pmGroupBox,
                              label         =  "Rise:",
                              value         =  env.prefs[bdnaRise_prefs_key],
                              setAsDefault  =  True,
                              minimum       =  2.0,
                              maximum       =  4.0,
                              decimals      =  3,
                              singleStep    =  0.01 )
        
        
        

        # Strand Length (i.e. the number of bases)
        self.numberOfBasePairsSpinBox = \
            PM_SpinBox( pmGroupBox,
                        label         =  "Base pairs:",
                        value         =  self._numberOfBases,
                        setAsDefault  =  False,
                        minimum       =  0,
                        maximum       =  10000 )

        self.numberOfBasePairsSpinBox.setDisabled(True)

        # Duplex Length
        self.duplexLengthLineEdit  =  \
            PM_LineEdit( pmGroupBox,
                         label         =  "Duplex length: ",
                         text          =  "0.0 Angstroms",
                         setAsDefault  =  False)

        self.duplexLengthLineEdit.setDisabled(True)


    def _loadDisplayOptionsGroupBox(self, pmGroupBox):
        """
        Load widgets in the Display Options GroupBox
        @see: DnaOrCnt_PropertyManager. _loadDisplayOptionsGroupBox
        """
        #Call the superclass method that loads the cursor text checkboxes.
        #Note, as of 2008-05-19, the superclass, DnaOrCnt_PropertyManager
        #only loads the cursor text groupboxes. Subclasses like this can
        #call custom methods like self._loadCursorTextCheckBoxes etc if they
        #don't need all groupboxes that the superclass loads.
        _superclass._loadDisplayOptionsGroupBox(self, pmGroupBox)

        self._rubberbandLineGroupBox = PM_GroupBox(
            pmGroupBox,
            title = 'Rubber band line:')

        dnaLineChoices = ['Ribbons', 'Ladder']
        self.dnaRubberBandLineDisplayComboBox = \
            PM_ComboBox( self._rubberbandLineGroupBox ,
                         label         =  " Display as:",
                         choices       =  dnaLineChoices,
                         setAsDefault  =  True)

        self.lineSnapCheckBox = \
            PM_CheckBox(self._rubberbandLineGroupBox ,
                        text         = 'Enable line snap' ,
                        widgetColumn = 1,
                        state        = Qt.Checked
                    )

    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 ,
            dnaDuplexEditCommand_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",
             dnaDuplexEditCommand_cursorTextCheckBox_numberOfBasePairs_prefs_key),

            ("Number of turns",
             dnaDuplexEditCommand_cursorTextCheckBox_numberOfTurns_prefs_key),

            ("Duplex length",
             dnaDuplexEditCommand_cursorTextCheckBox_length_prefs_key),

            ("Angle",
             dnaDuplexEditCommand_cursorTextCheckBox_angle_prefs_key) ]

        return params


    def _addToolTipText(self):
        """
        Tool Tip text for widgets in the DNA Property Manager.
        """
        pass


    def conformationComboBoxChanged( self, inIndex ):
        """
        Slot for the Conformation combobox. It is called whenever the
        Conformation choice is changed.

        @param inIndex: The new index.
        @type  inIndex: int
        """
        conformation  =  self.conformationComboBox.currentText()

        if conformation == "B-DNA":
            self.basesPerTurnDoubleSpinBox.setValue("10.0")

        elif conformation == "Z-DNA":
            self.basesPerTurnDoubleSpinBox.setValue("12.0")

        else:
            msg = redmsg("conformationComboBoxChanged(): \
                         Error - unknown DNA conformation. Index = "+ inIndex)
            env.history.message(msg)

        self.duplexLengthSpinBox.setSingleStep(getDuplexRise(conformation))

    def numberOfBasesChanged( self, numberOfBases ):
        """
        Slot for the B{Number of Bases} spinbox.
        """
        # Update the Duplex Length lineEdit widget.
        text = str(getDuplexLength(self._conformation,
                                   numberOfBases,
                                   self._duplexRise)) \
             + " Angstroms"
        self.duplexLengthLineEdit.setText(text)
        return

    def basesPerTurnChanged( self, basesPerTurn ):
        """
        Slot for the B{Bases per turn} spinbox.
        """
        self.editCommand.basesPerTurn = basesPerTurn
        self._basesPerTurn = basesPerTurn
        return

    def duplexRiseChanged( self, rise ):
        """
        Slot for the B{Rise} spinbox.
        """
        self.editCommand.duplexRise = rise
        self._duplexRise = rise
        return

    def getParameters(self):
        """
        Return the parameters from this property manager
        to be used to create the DNA duplex.
        @return: A tuple containing the parameters
        @rtype: tuple
        @see: L{DnaDuplex_EditCommand._gatherParameters} where this is used
        """
        numberOfBases = self.numberOfBasePairsSpinBox.value()
        dnaForm  = str(self.conformationComboBox.currentText())
        basesPerTurn = self.basesPerTurnDoubleSpinBox.value()
        duplexRise = self.duplexRiseDoubleSpinBox.value()

        dnaModel = str(self.dnaModelComboBox.currentText())

        # First endpoint (origin) of DNA duplex
        x1 = self.x1SpinBox.value()
        y1 = self.y1SpinBox.value()
        z1 = self.z1SpinBox.value()

        # Second endpoint (direction vector/axis) of DNA duplex.
        x2 = self.x2SpinBox.value()
        y2 = self.y2SpinBox.value()
        z2 = self.z2SpinBox.value()

        if not self.endPoint1:
            self.endPoint1 = V(x1, y1, z1)
        if not self.endPoint2:
            self.endPoint2 = V(x2, y2, z2)

        return (numberOfBases,
                dnaForm,
                dnaModel,
                basesPerTurn,
                duplexRise,
                self.endPoint1,
                self.endPoint2)

    def _addWhatsThisText(self):
        """
        What's This text for widgets in this Property Manager.
        """
        whatsThis_DnaDuplexPropertyManager(self)
Пример #25
0
class Ui_DnaSequenceEditor(PM_DockWidget):
    """
    The Ui_DnaSequenceEditor class defines UI elements for the Sequence Editor
    object. The sequence editor is usually visible while in DNA edit mode.
    It is a DockWidget that is doced at the bottom of the MainWindow
    """
    _title         =  "Sequence Editor"
    _groupBoxCount = 0
    _lastGroupBox = None

    def __init__(self, win):
        """
        Constructor for the Ui_DnaSequenceEditor 
        @param win: The parentWidget (MainWindow) for the sequence editor 
        """
        
        self.win = win
        # Should parentWidget for a docwidget always be win? 
        #Not necessary but most likely it will be the case.        
        parentWidget = win 
        
        _superclass.__init__(self, parentWidget, title = self._title)
        
        #A flag used to restore the state of the Reports dock widget 
        #(which can be accessed through View  >  Reports) see self.show() and
        #self.closeEvent() for more details. 
        self._reportsDockWidget_closed_in_show_method = False
        self.setFixedHeight(90)

    def show(self):
        """
        Shows the sequence editor. While doing this, it also closes the reports
        dock widget (if visible) the state of the reports dockwidget will be
        restored when the sequence editor is closed. 
        @see:self.closeEvent()
        """
        self._reportsDockWidget_closed_in_show_method = False
        #hide the history widget first
        #(It will be shown back during self.close)
        #The history widget is hidden or shown only when both 
        # 'View > Full Screen' and View > Semi Full Screen actions 
        # are *unchecked*
        #Thus show or close methods won't do anything to history widget
        # if either of the above mentioned actions is checked.
        if self.win.viewFullScreenAction.isChecked() or \
           self.win.viewSemiFullScreenAction.isChecked():
            pass
        else:
            if self.win.reportsDockWidget.isVisible():
                self.win.reportsDockWidget.close()
                self._reportsDockWidget_closed_in_show_method = True

        _superclass.show(self)  
        
    def closeEvent(self, event):
        """
        Overrides close event. Makes sure that the visible state of the reports
        widgetis restored when the sequence editor is closed. 
        @see: self.show()
        """
        _superclass.closeEvent(self, event)
       
        if self.win.viewFullScreenAction.isChecked() or \
           self.win.viewSemiFullScreenAction.isChecked():
            pass
        else:
            if self._reportsDockWidget_closed_in_show_method:
                self.win.viewReportsAction.setChecked(True) 
                self._reportsDockWidget_closed_in_show_method = False

    def _loadWidgets(self):
        """
        Overrides PM.PM_DockWidget._loadWidgets. Loads the widget in this
        dockwidget.
        """
        self._loadMenuWidgets()
        self._loadTextEditWidget()


    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.loadSequenceButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Open.png")  

        self.saveSequenceButton = PM_ToolButton(
            self, 
            iconPath = "ui/actions/Properties Manager/Save_Strand_Sequence.png") 

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        editDirectionChoices = ["5' to 3'", "3' to 5'"]
        self.baseDirectionChoiceComboBox = \
            PM_ComboBox( self,
                         choices = editDirectionChoices,
                         index     = 0, 
                         spanWidth = False )   

        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)


        self.replaceLineEdit = \
            PM_LineEdit( self, 
                         label        = "",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text = "Replace")

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done -- 

        # When the widget type starts with the word 'PM_' , the 
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned 
        # labels (and if they were recreated as mentioned above), 
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2] 
        #Cleanup in PM_widgetGrid could be to check if the widget starts with 
        #'Q'  instead of 'PM_' 


        #Widgets to include in the widget row. 
        widgetList = [('PM_ToolButton', self.loadSequenceButton, 0),
                      ('PM_ToolButton', self.saveSequenceButton, 1),
                      ('QLabel', "     Sequence direction:", 2),
                      ('PM_ComboBox',  self.baseDirectionChoiceComboBox , 3),
                      ('QLabel', "     Find:", 4),
                      ('PM_LineEdit', self.findLineEdit, 5),
                      ('PM_ToolButton', self.findOptionsToolButton, 6),
                      ('PM_ToolButton', self.findPreviousToolButton, 7),
                      ('PM_ToolButton', self.findNextToolButton, 8), 
                      ('QLabel', "     Replace:", 9),
                      ('PM_TextEdit', self.replaceLineEdit, 10), 
                      ('PM_PushButton', self.replacePushButton, 11),
                      ('PM_Label', self.warningSign, 12),
                      ('PM_Label', self.phraseNotFoundLabel, 13),
                      ('QSpacerItem', 5, 5, 14) ]

        widgetRow = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList,
                                 label = "",
                                 spanWidth = True )

    def _loadTextEditWidget(self):
        """
        Load the SequenceTexteditWidgets.         
        """        
        self.sequenceTextEdit = \
            PM_TextEdit( self, 
                         label = " Sequence: ", 
                         spanWidth = False,
                         permit_enter_keystroke = False)        
        self.sequenceTextEdit.setCursorWidth(2)
        self.sequenceTextEdit.setWordWrapMode( QTextOption.WrapAnywhere )
        self.sequenceTextEdit.setFixedHeight(20)

        #The StrandSequence 'Mate' it is a read only etxtedit that shows
        #the complementary strand sequence.         
        self.sequenceTextEdit_mate = \
            PM_TextEdit(self, 
                        label = "", 
                        spanWidth = False,
                        permit_enter_keystroke = False
                        )        
        palette = getPalette(None, 
                             QPalette.Base, 
                             sequenceEditStrandMateBaseColor)
        self.sequenceTextEdit_mate.setPalette(palette)        
        self.sequenceTextEdit_mate.setFixedHeight(20)
        self.sequenceTextEdit_mate.setReadOnly(True)
        self.sequenceTextEdit_mate.setWordWrapMode(QTextOption.WrapAnywhere)

        #Important to make sure that the horizontal and vertical scrollbars 
        #for these text edits are never displayed. 
        for textEdit in (self.sequenceTextEdit, self.sequenceTextEdit_mate):
            textEdit.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            textEdit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)


    def _getFindLineEditStyleSheet(self):
        """
        Return the style sheet for the findLineEdit. This sets the following 
        properties only:
         - background-color

        This style is set whenever the searchStrig can't be found (sets
        a light red color background to the lineedit when this happens)   

        @return: The line edit style sheet.
        @rtype:  str

        """
        styleSheet = \
                   "QLineEdit {\
                   background-color: rgb(255, 102, 102)\
                   }"
        #Not used:
        #  background-color: rgb(217, 255, 216)\       

        return styleSheet

    def _setFindOptionsToolButtonMenu(self):
        """
        Sets the menu for the findOptionstoolbutton that appears a small 
        menu button next to the findLineEdit.
        """
        self.findOptionsMenu = QMenu(self.findOptionsToolButton)

        self.caseSensitiveFindAction = QAction(self.findOptionsToolButton)
        self.caseSensitiveFindAction.setText('Match Case')
        self.caseSensitiveFindAction.setCheckable(True)
        self.caseSensitiveFindAction.setChecked(False)

        self.findOptionsMenu.addAction(self.caseSensitiveFindAction)
        self.findOptionsMenu.addSeparator()

        self.findOptionsToolButton.setMenu(self.findOptionsMenu)

    def _addToolTipText(self):
        """
            What's Tool Tip text for widgets in this Property Manager.  
            """ 
        from ne1_ui.ToolTipText_for_PropertyManagers import ToolTip_SequenceEditor
        ToolTip_SequenceEditor(self)

    def _addWhatsThisText(self):
        """
            What's This text for widgets in this Property Manager.  

            """
        from ne1_ui.WhatsThisText_for_PropertyManagers import whatsThis_SequenceEditor
        whatsThis_SequenceEditor(self)
    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options,
        Find and replace widgets etc.
        """

        self.loadSequenceButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Open.png")

        self.saveSequenceButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Save_Strand_Sequence.png")

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        # Hide load and save buttons until they are implemented. -Mark 2008-12-20.
        self.loadSequenceButton.hide()
        self.saveSequenceButton.hide()

        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)

        self.replaceLineEdit = \
            PM_LineEdit( self,
                         label        = "  Replace:",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text = "Replace")

        # Hide Replace widgets until we add support for transmuting residues.
        # Mark 2008-12-19
        #self.replaceLabel.hide()
        self.replacePushButton.hide()
        self.replaceLineEdit.hide()

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        #Widgets to include in the widget row.
        widgetList = [('PM_ToolButton', self.loadSequenceButton, 0),
                      ('PM_ToolButton', self.saveSequenceButton, 1),
                      ('QLabel', "                                     Find:", 4),
                      ('PM_LineEdit',   self.findLineEdit, 5),
                      ('PM_ToolButton', self.findOptionsToolButton, 6),
                      ('PM_ToolButton', self.findPreviousToolButton, 7),
                      ('PM_ToolButton', self.findNextToolButton, 8),
                      #('PM_Label',      self.replaceLabel, 9),
                      ('PM_TextEdit',   self.replaceLineEdit, 9),
                      ('PM_PushButton', self.replacePushButton, 10),
                      ('PM_Label', self.warningSign, 11),
                      ('PM_Label', self.phraseNotFoundLabel, 12),
                      ('QSpacerItem', 5, 5, 13) ]

        widgetRow = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList,
                                 label = "",
                                 spanWidth = True )
        return
Пример #27
0
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)
Пример #28
0
class QuteMolPropertyManager(Command_PropertyManager):
    """
    The QuteMolPropertyManager class provides a Property Manager for
    QuteMolX, allowing its launch for external rendering of the model.
    """

    # The title that appears in the Property Manager header.
    title = "QuteMolX"
    # The name of this Property Manager. This will be set to
    # the name of the PM_Dialog object via setObjectName().
    pmName = title
    # The relative path to the PNG file that appears in the header
    iconPath = "ui/actions/Properties Manager/QuteMol.png"

    # DNA Display choices.
    _axes_display_choices = [ "Render axes",
                              "Hide axes" ]

    _bases_display_choices = [ "Render bases",
                               "Hide bases" ]
                               #"Color bases black",
                               #"Color bases by type" ]

    # PDB exclude flags = _axesFlags | _basesFlags
    _axesFlags  = EXCLUDE_HIDDEN_ATOMS
    _basesFlags = EXCLUDE_HIDDEN_ATOMS

    def __init__( self, command ):
        """
        Constructor for the property manager.
        """

        _superclass.__init__(self, command)

        self.showTopRowButtons( PM_DONE_BUTTON | \
                                PM_WHATS_THIS_BUTTON)

        msg = "Select a QuteMolX rendering style and click the "\
        "<b>Launch QuteMolX</b> button when ready."

        # This causes the "Message" box to be displayed as well.
        self.updateMessage(msg)

    def _addGroupBoxes(self):
        """
        Add the 1st group box to the Property Manager.
        """
        self.pmGroupBox1 = PM_GroupBox(self, title = "DNA Display Options")
        self._loadGroupBox1(self.pmGroupBox1)

        self.pmGroupBox2 = PM_GroupBox(self, title = "Launch")
        self._loadGroupBox2(self.pmGroupBox2)

    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in 1st group box.

        @param pmGroupBox: The 1st group box in the PM.
        @type  pmGroupBox: L{PM_GroupBox}
        """

        self.axesCombobox = PM_ComboBox(
            pmGroupBox,
            label        = 'Axes: ',
            choices      = self._axes_display_choices,
            index        = 0,
            setAsDefault = True,
            spanWidth    = False )

        self.basesCombobox = PM_ComboBox(
            pmGroupBox,
            label        = 'Bases: ',
            choices      = self._bases_display_choices,
            index        = 0,
            setAsDefault = True,
            spanWidth    = False )

    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in 2nd group box.

        @param pmGroupBox: The 1st group box in the PM.
        @type  pmGroupBox: L{PM_GroupBox}
        """

        self.launchQuteMolButton = PM_ToolButton(
            pmGroupBox,
            text      = "Launch QuteMolX",
            iconPath  = "ui/actions/Properties Manager/QuteMol.png",
            spanWidth = True )

        self.launchQuteMolButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

    def _addWhatsThisText(self):
        """
        "What's This" text for widgets in this Property Manager.
        """
        from ne1_ui.WhatsThisText_for_PropertyManagers import whatsThis_QuteMolPropertyManager
        whatsThis_QuteMolPropertyManager(self)

    def _addToolTipText(self):
        """
        Tool Tip text for widgets in this Property Manager.
        """
        from ne1_ui.ToolTipText_for_PropertyManagers import ToolTip_QuteMolPropertyManager
        ToolTip_QuteMolPropertyManager(self)



    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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        change_connect(self.axesCombobox,
                     SIGNAL("currentIndexChanged(const QString&)"),
                     self.changeAxesDisplay)

        change_connect(self.basesCombobox,
                     SIGNAL("currentIndexChanged(const QString&)"),
                     self.changeBasesDisplay)

        change_connect(self.launchQuteMolButton,
                       SIGNAL("clicked()"),
                       self.launchQuteMol)

    def updateMessage(self, msg = ''):
        """
        Updates the message box with an informative message
        @param msg: Message to be displayed in the Message groupbox of
                        the property manager
        @type  msg: string
        """
        self.MessageGroupBox.insertHtmlMessage(msg,
                                               setAsDefault = False,
                                               minLines     = 5)

    def changeAxesDisplay(self, optionText):
        """
        Slot to change the axes display style.

        @param optionText: The text of the combobox option selected.
        @type  optionText: str
        """

        if optionText == self._axes_display_choices[0]:
            self._axesFlags = EXCLUDE_HIDDEN_ATOMS
            # Cannot display axes if axis atoms are excluded.
            self.basesCombobox.setCurrentIndex(0)
        elif optionText == self._axes_display_choices[1]:
            self._axesFlags = EXCLUDE_HIDDEN_ATOMS | EXCLUDE_DNA_AXIS_BONDS
        else:
            print "Unknown axes display option: ", optionText

        #print "Axes display option=", optionText
        #print "Axes Flags=", self._axesFlags

    def changeBasesDisplay(self, optionText):
        """
        Slot to change the bases display style.

        @param optionText: The text of the combobox option selected.
        @type  optionText: str
        """
        if optionText == self._bases_display_choices[0]:
            self._basesFlags = EXCLUDE_HIDDEN_ATOMS
        elif optionText == self._bases_display_choices[1]:
            self._basesFlags = EXCLUDE_HIDDEN_ATOMS | EXCLUDE_DNA_AXIS_ATOMS
            # Cannot display axesif axis atoms are excluded.
            self.axesCombobox.setCurrentIndex(1)
        else:
            print "Unknown bases display option: ", optionText

        #print "Bases display option=", optionText
        #print "Bases Flags=", self._basesFlags

    def launchQuteMol(self):
        """
        Slot for 'Launch QuteMolX' button.
        Opens the QuteMolX rendering program and loads a copy of the current
        model.

        Method:

        1. Write a PDB file of the current part.
        2. Write an atom attributes table text file containing atom radii and
           color information.
        3. Launches QuteMolX (with the PDB file as an argument).

        """
        cmd = greenmsg("QuteMolX : ")

        excludeFlags = self._axesFlags | self._basesFlags
        #print "Exclude flags=", excludeFlags

        pdb_file = write_qutemol_files(self.win.assy, excludeFlags)
        # Launch QuteMolX. It will verify the plugin.
        errorcode, msg = launch_qutemol(pdb_file)
        # errorcode is ignored.
        env.history.message(cmd + msg)
class InsertNanotube_PropertyManager(DnaOrCnt_PropertyManager):
    """
    The InsertNanotube_PropertyManager class provides a Property Manager
    for the B{Build > Nanotube > 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 = "Insert Nanotube"
    pmName = title
    iconPath = "ui/actions/Tools/Build Structures/InsertNanotube.png"

    def __init__(self, win, editCommand):
        """
        Constructor for the Nanotube property manager.
        """
        self.endPoint1 = None
        self.endPoint2 = None

        self.nanotube = Nanotube()  # A 5x5 CNT.

        _superclass.__init__(self, win, editCommand)

        self.showTopRowButtons( PM_DONE_BUTTON | \
                                PM_CANCEL_BUTTON | \
                                PM_WHATS_THIS_BUTTON)

    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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        change_connect(self.ntTypeComboBox,
                       SIGNAL("currentIndexChanged(const QString&)"),
                       self._ntTypeComboBoxChanged)

        change_connect(self.chiralityNSpinBox, SIGNAL("valueChanged(int)"),
                       self._chiralityFixup)

        change_connect(self.chiralityMSpinBox, SIGNAL("valueChanged(int)"),
                       self._chiralityFixup)

        change_connect(self.endingsComboBox,
                       SIGNAL("currentIndexChanged(const QString&)"),
                       self._endingsComboBoxChanged)

        # This spin box is currently hidden.
        change_connect(self.bondLengthDoubleSpinBox,
                       SIGNAL("valueChanged(double)"), self._bondLengthChanged)

        change_connect(self.showCursorTextCheckBox,
                       SIGNAL('stateChanged(int)'),
                       self._update_state_of_cursorTextGroupBox)

    def ok_btn_clicked(self):
        """
        Slot for the OK button
        """
        if self.editCommand:
            self.editCommand.preview_or_finalize_structure(previewing=False)
            ##env.history.message(self.editCommand.logMessage)
        self.win.toolsDone()

    def cancel_btn_clicked(self):
        """
        Slot for the Cancel button.
        """
        if self.editCommand:
            self.editCommand.cancelStructure()
        self.win.toolsCancel()

    def _update_widgets_in_PM_before_show(self):
        """
        Update various widgets in this Property manager.
        Overrides MotorPropertyManager._update_widgets_in_PM_before_show.
        The various  widgets , (e.g. spinboxes) will get values from the
        structure for which this propMgr is constructed for
        (self.editcCntroller.struct)

        @see: MotorPropertyManager._update_widgets_in_PM_before_show
        @see: self.show where it is called.
        """
        pass

    def getFlyoutActionList(self):
        """
        Returns custom actionlist that will be used in a specific mode
        or editing a feature etc Example: while in movie mode,
        the _createFlyoutToolBar method calls this.
        """
        #'allActionsList' returns all actions in the flyout toolbar
        #including the subcontrolArea actions
        allActionsList = []

        #Action List for  subcontrol Area buttons.
        #In this mode there is really no subcontrol area.
        #We will treat subcontrol area same as 'command area'
        #(subcontrol area buttons will have an empty list as their command area
        #list). We will set  the Comamnd Area palette background color to the
        #subcontrol area.

        subControlAreaActionList = []

        self.exitEditCommandAction.setChecked(True)
        subControlAreaActionList.append(self.exitEditCommandAction)

        separator = QAction(self.w)
        separator.setSeparator(True)
        subControlAreaActionList.append(separator)

        allActionsList.extend(subControlAreaActionList)

        #Empty actionlist for the 'Command Area'
        commandActionLists = []

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

        params = (subControlAreaActionList, commandActionLists, allActionsList)

        return params

    def _addGroupBoxes(self):
        """
        Add the Insert Nanotube Property Manager group boxes.
        """

        self._pmGroupBox1 = PM_GroupBox(self, title="Endpoints")
        self._loadGroupBox1(self._pmGroupBox1)
        self._pmGroupBox1.hide()

        self._pmGroupBox2 = PM_GroupBox(self, title="Parameters")
        self._loadGroupBox2(self._pmGroupBox2)

        self._displayOptionsGroupBox = PM_GroupBox(self,
                                                   title="Display Options")
        self._loadDisplayOptionsGroupBox(self._displayOptionsGroupBox)

        self._pmGroupBox3 = PM_GroupBox(self, title="Nanotube Distortion")
        self._loadGroupBox3(self._pmGroupBox3)
        self._pmGroupBox3.hide()  #@ Temporary.

        self._pmGroupBox4 = PM_GroupBox(self, title="Multi-Walled CNTs")
        self._loadGroupBox4(self._pmGroupBox4)
        self._pmGroupBox4.hide()  #@ Temporary.

        self._pmGroupBox5 = PM_GroupBox(self, title="Advanced Options")
        self._loadGroupBox5(self._pmGroupBox5)
        self._pmGroupBox5.hide()  #@ Temporary.

    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in group box 1.
        """
        #Following toolbutton facilitates entering a temporary NanotubeLineMode
        #to create a CNT using endpoints of the specified line.
        self.specifyCntLineButton = PM_ToolButton(
            pmGroupBox,
            text="Specify Endpoints",
            iconPath="ui/actions/Properties Manager/Pencil.png",
            spanWidth=True)
        self.specifyCntLineButton.setCheckable(True)
        self.specifyCntLineButton.setAutoRaise(True)
        self.specifyCntLineButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

        #EndPoint1 and endPoint2 coordinates. These widgets are hidden
        # as of 2007- 12 - 05
        self._endPoint1SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label="End Point 1")
        self.x1SpinBox = self._endPoint1SpinBoxes.xSpinBox
        self.y1SpinBox = self._endPoint1SpinBoxes.ySpinBox
        self.z1SpinBox = self._endPoint1SpinBoxes.zSpinBox

        self._endPoint2SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label="End Point 2")
        self.x2SpinBox = self._endPoint2SpinBoxes.xSpinBox
        self.y2SpinBox = self._endPoint2SpinBoxes.ySpinBox
        self.z2SpinBox = self._endPoint2SpinBoxes.zSpinBox

        self._endPoint1SpinBoxes.hide()
        self._endPoint2SpinBoxes.hide()

    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in group box 2.
        """

        _ntTypeChoices = ['Carbon', 'Boron Nitride']
        self.ntTypeComboBox  = \
            PM_ComboBox( pmGroupBox,
                         label         =  "Type:",
                         choices       =  _ntTypeChoices,
                         setAsDefault  =  True)

        self.ntRiseDoubleSpinBox  =  \
            PM_DoubleSpinBox( pmGroupBox,
                              label         =  "Rise:",
                              value         =  self.nanotube.getRise(),
                              setAsDefault  =  True,
                              minimum       =  2.0,
                              maximum       =  4.0,
                              decimals      =  3,
                              singleStep    =  0.01 )

        self.ntRiseDoubleSpinBox.hide()

        # Nanotube Length
        self.ntLengthLineEdit  =  \
            PM_LineEdit( pmGroupBox,
                         label         =  "Nanotube Length: ",
                         text          =  "0.0 Angstroms",
                         setAsDefault  =  False)

        self.ntLengthLineEdit.setDisabled(True)
        self.ntLengthLineEdit.hide()

        # Nanotube diameter
        self.ntDiameterLineEdit  =  \
            PM_LineEdit( pmGroupBox,
                         label         =  "Diameter: ",
                         setAsDefault  =  False)

        self.ntDiameterLineEdit.setDisabled(True)
        self.updateNanotubeDiameter()

        self.chiralityNSpinBox = \
            PM_SpinBox( pmGroupBox,
                        label        = "Chirality (n):",
                        value        = self.nanotube.getChiralityN(),
                        minimum      =  2,
                        maximum      =  100,
                        setAsDefault = True )

        self.chiralityMSpinBox = \
            PM_SpinBox( pmGroupBox,
                        label        = "Chirality (m):",
                        value        = self.nanotube.getChiralityM(),
                        minimum      =  0,
                        maximum      =  100,
                        setAsDefault = True )

        # How about having user prefs for CNT and BNNT bond lengths?
        # I'm guessing that if the user wants to set these values, they will
        # do it once and would like those bond length values persist forever.
        # Need to discuss with others to determine if this spinbox comes out.
        # --Mark 2008-03-29
        self.bondLengthDoubleSpinBox = \
            PM_DoubleSpinBox( pmGroupBox,
                              label        = "Bond length:",
                              value        = self.nanotube.getBondLength(),
                              setAsDefault = True,
                              minimum      = 1.0,
                              maximum      = 3.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

        #self.bondLengthDoubleSpinBox.hide()

        endingChoices = ["Hydrogen", "None"]  # Removed:, "Nitrogen"]

        self.endingsComboBox= \
            PM_ComboBox( pmGroupBox,
                         label        = "Endings:",
                         choices      = endingChoices,
                         index        = 0,
                         setAsDefault = True,
                         spanWidth    = False )

    def _loadGroupBox3(self, inPmGroupBox):
        """
        Load widgets in group box 3.
        """

        self.zDistortionDoubleSpinBox = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Z-distortion:",
                              value        = 0.0,
                              setAsDefault = True,
                              minimum      = 0.0,
                              maximum      = 10.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

        self.xyDistortionDoubleSpinBox = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "XY-distortion:",
                              value        = 0.0,
                              setAsDefault = True,
                              minimum      = 0.0,
                              maximum      = 2.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

        self.twistSpinBox = \
            PM_SpinBox( inPmGroupBox,
                        label        = "Twist:",
                        value        = 0,
                        setAsDefault = True,
                        minimum      = 0,
                        maximum      = 100, # What should maximum be?
                        suffix       = " deg/A" )

        self.bendSpinBox = \
            PM_SpinBox( inPmGroupBox,
                        label        = "Bend:",
                        value        = 0,
                        setAsDefault = True,
                        minimum      = 0,
                        maximum      = 360,
                        suffix       = " deg" )

    def _loadGroupBox4(self, inPmGroupBox):
        """
        Load widgets in group box 4.
        """

        # "Number of Nanotubes" SpinBox
        self.mwntCountSpinBox = \
            PM_SpinBox( inPmGroupBox,
                        label        = "Number:",
                        value        = 1,
                        setAsDefault = True,
                        minimum      = 1,
                        maximum      = 10,
                        suffix       = " nanotubes" )

        self.mwntCountSpinBox.setSpecialValueText("SWNT")

        # "Spacing" lineedit.
        self.mwntSpacingDoubleSpinBox = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Spacing:",
                              value        = 2.46,
                              setAsDefault = True,
                              minimum      = 1.0,
                              maximum      = 10.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

    def _loadGroupBox5(self, pmGroupBox):
        """
        Load widgets in group box 5.
        """
        self._rubberbandLineGroupBox = PM_GroupBox(pmGroupBox,
                                                   title='Rubber band Line:')

        ntLineChoices = ['Ladder']
        self.ntRubberBandLineDisplayComboBox = \
            PM_ComboBox( self._rubberbandLineGroupBox ,
                         label         =  " Display as:",
                         choices       =  ntLineChoices,
                         setAsDefault  =  True)

        self.lineSnapCheckBox = \
            PM_CheckBox(self._rubberbandLineGroupBox ,
                        text         = 'Enable line snap' ,
                        widgetColumn = 1,
                        state        = Qt.Checked
                        )

    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,
            insertNanotubeEditCommand_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)

                   ("Nanotube length",
                    insertNanotubeEditCommand_cursorTextCheckBox_length_prefs_key ),

                    ("Angle",
                     insertNanotubeEditCommand_cursorTextCheckBox_angle_prefs_key )
                 ]

        return params

    def _addToolTipText(self):
        """
        Tool Tip text for widgets in the Insert Nanotube Property Manager.
        """
        pass

    def _setEndPoints(self):
        """
        Set the two endpoints of the nanotube using the values from the
        X, Y, Z coordinate spinboxes in the property manager.

        @note: The group box containing the 2 sets of XYZ spin boxes are
        currently hidden.
        """
        # First endpoint (origin) of nanotube
        x1 = self.x1SpinBox.value()
        y1 = self.y1SpinBox.value()
        z1 = self.z1SpinBox.value()

        # Second endpoint (direction vector/axis) of nanotube.
        x2 = self.x2SpinBox.value()
        y2 = self.y2SpinBox.value()
        z2 = self.z2SpinBox.value()

        if not self.endPoint1:
            self.endPoint1 = V(x1, y1, z1)
        if not self.endPoint2:
            self.endPoint2 = V(x2, y2, z2)

        self.nanotube.setEndPoints(self.endPoint1, self.endPoint2)
        # Need arg "recompute=True", which will recompute the second
        # endpoint (endPoint2) using the nanotube rise.

    def getParameters(self):
        """
        Return the parameters from this property manager to be used to create
        the nanotube.

        @return: A nanotube instance with its attrs set to the current
                 parameters in the property manager.
        @rtype: L{Nanotube}

        @see: L{InsertNanotube_EditCommand._gatherParameters} where this is used
        """
        self._setEndPoints()
        return (self.nanotube)

    def _ntTypeComboBoxChanged(self, type):
        """
        Slot for the Type combobox. It is called whenever the
        Type choice is changed.

        @param inIndex: The new index.
        @type  inIndex: int
        """
        self.nanotube.setType(str(type))
        print "Bond Length =", self.nanotube.getBondLength()
        self.bondLengthDoubleSpinBox.setValue(self.nanotube.getBondLength())
        #self.bondLengthDoubleSpinBox.setValue(ntBondLengths[inIndex])

    def _bondLengthChanged(self, bondLength):
        """
        Slot for the B{Bond Length} spinbox.
        """
        self.nanotube.setBondLength(bondLength)
        self.updateNanotubeDiameter()
        return

    def _chiralityFixup(self, spinBoxValueJunk=None):
        """
        Slot for several validators for different parameters.
        This gets called whenever the user changes the n, m chirality values.

        @param spinBoxValueJunk: This is the Spinbox value from the valueChanged
                                 signal. It is not used. We just want to know
                                 that the spinbox value has changed.
        @type  spinBoxValueJunk: double or None
        """
        _n, _m = self.nanotube.setChirality(self.chiralityNSpinBox.value(),
                                            self.chiralityMSpinBox.value())

        #self.n, self.m = self.nanotube.getChirality()

        self.connect_or_disconnect_signals(isConnect=False)
        self.chiralityNSpinBox.setValue(_n)
        self.chiralityMSpinBox.setValue(_m)
        self.connect_or_disconnect_signals(isConnect=True)

        self.updateNanotubeDiameter()

    def updateNanotubeDiameter(self):
        """
        Update the nanotube Diameter lineEdit widget.
        """
        diameterText = "%-7.4f Angstroms" % (self.nanotube.getDiameter())
        self.ntDiameterLineEdit.setText(diameterText)

        # ntRiseDoubleSpinBox is currently hidden.
        self.ntRiseDoubleSpinBox.setValue(self.nanotube.getRise())

    def _endingsComboBoxChanged(self, endings):
        """
        Slot for the B{Ending} combobox.

        @param endings: The option's text.
        @type  endings: string
        """
        self.nanotube.setEndings(str(endings))
        return

    def _addWhatsThisText(self):
        """
        What's This text for widgets in this Property Manager.
        """
        whatsThis_InsertNanotube_PropertyManager(self)
        return
Пример #30
0
class InsertDna_PropertyManager(DnaOrCnt_PropertyManager):
    """
    The InsertDna_PropertyManager class provides a Property Manager
    for the B{Insert Dna} 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 = "Insert DNA"
    pmName = title
    iconPath = "ui/actions/Command Toolbar/BuildDna/InsertDna.png"

    def __init__(self, command):
        """
        Constructor for the DNA Duplex property manager.
        """
        self.endPoint1 = None
        self.endPoint2 = None

        self._conformation = "B-DNA"
        self._numberOfBases = 0
        self._basesPerTurn = getDuplexBasesPerTurn(self._conformation)
        self._duplexRise = getDuplexRise(self._conformation)
        self._duplexLength = getDuplexLength(self._conformation,
                                             self._numberOfBases)

        _superclass.__init__(self, command)

        self.showTopRowButtons( PM_DONE_BUTTON | \
                                PM_CANCEL_BUTTON | \
                                PM_WHATS_THIS_BUTTON)

    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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        change_connect(self._placementOptions.buttonGroup,
                       SIGNAL("buttonClicked(int)"),
                       self.activateSpecifyReferencePlaneTool)

        change_connect(self.conformationComboBox,
                       SIGNAL("currentIndexChanged(int)"),
                       self.conformationComboBoxChanged)

        change_connect(self.numberOfBasePairsSpinBox,
                       SIGNAL("valueChanged(int)"), self.numberOfBasesChanged)

        change_connect(self.basesPerTurnDoubleSpinBox,
                       SIGNAL("valueChanged(double)"),
                       self.basesPerTurnChanged)

        change_connect(self.duplexRiseDoubleSpinBox,
                       SIGNAL("valueChanged(double)"), self.duplexRiseChanged)

        change_connect(self.showCursorTextCheckBox,
                       SIGNAL('stateChanged(int)'),
                       self._update_state_of_cursorTextGroupBox)

        self.duplexRiseDoubleSpinBox.connectWithState(
            Preferences_StateRef_double(bdnaRise_prefs_key,
                                        env.prefs[bdnaRise_prefs_key]))

        self.basesPerTurnDoubleSpinBox.connectWithState(
            Preferences_StateRef_double(bdnaBasesPerTurn_prefs_key,
                                        env.prefs[bdnaBasesPerTurn_prefs_key]))

    def show(self):
        _superclass.show(self)
        self.updateMessage("Specify the DNA parameters below, then click "\
                           "two endpoints in the graphics area to insert a DNA duplex.")

    def _addGroupBoxes(self):
        """
        Add the DNA Property Manager group boxes.
        """
        self._pmReferencePlaneGroupBox = PM_GroupBox(self,
                                                     title="Placement Options")
        self._loadReferencePlaneGroupBox(self._pmReferencePlaneGroupBox)

        self._pmGroupBox1 = PM_GroupBox(self, title="Endpoints")
        self._loadGroupBox1(self._pmGroupBox1)

        self._pmGroupBox1.hide()

        self._pmGroupBox2 = PM_GroupBox(self, title="Parameters")
        self._loadGroupBox2(self._pmGroupBox2)

        self._displayOptionsGroupBox = PM_GroupBox(self,
                                                   title="Display Options")
        self._loadDisplayOptionsGroupBox(self._displayOptionsGroupBox)

    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in group box 3.
        """
        #Folllowing toolbutton facilitates entering a temporary DnaLineMode
        #to create a DNA using endpoints of the specified line.
        self.specifyDnaLineButton = PM_ToolButton(
            pmGroupBox,
            text="Specify Endpoints",
            iconPath="ui/actions/Properties Manager/Pencil.png",
            spanWidth=True)
        self.specifyDnaLineButton.setCheckable(True)
        self.specifyDnaLineButton.setAutoRaise(True)
        self.specifyDnaLineButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

        #EndPoint1 and endPoint2 coordinates. These widgets are hidden
        # as of 2007- 12 - 05
        self._endPoint1SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label="End Point 1")
        self.x1SpinBox = self._endPoint1SpinBoxes.xSpinBox
        self.y1SpinBox = self._endPoint1SpinBoxes.ySpinBox
        self.z1SpinBox = self._endPoint1SpinBoxes.zSpinBox

        self._endPoint2SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                          label="End Point 2")
        self.x2SpinBox = self._endPoint2SpinBoxes.xSpinBox
        self.y2SpinBox = self._endPoint2SpinBoxes.ySpinBox
        self.z2SpinBox = self._endPoint2SpinBoxes.zSpinBox

        self._endPoint1SpinBoxes.hide()
        self._endPoint2SpinBoxes.hide()

    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in group box 4.
        """

        self.conformationComboBox  = \
            PM_ComboBox( pmGroupBox,
                         label         =  "Conformation:",
                         choices       =  ["B-DNA"],
                         setAsDefault  =  True)

        dnaModelChoices = ['PAM3', 'PAM5']
        self.dnaModelComboBox = \
            PM_ComboBox( pmGroupBox,
                         label         =  "Model:",
                         choices       =  dnaModelChoices,
                         setAsDefault  =  True)


        self.basesPerTurnDoubleSpinBox  =  \
            PM_DoubleSpinBox( pmGroupBox,
                              label         =  "Bases per turn:",
                              value         =  env.prefs[bdnaBasesPerTurn_prefs_key],
                              setAsDefault  =  True,
                              minimum       =  8.0,
                              maximum       =  20.0,
                              decimals      =  2,
                              singleStep    =  0.1 )


        self.duplexRiseDoubleSpinBox  =  \
            PM_DoubleSpinBox( pmGroupBox,
                              label         =  "Rise:",
                              value         =  env.prefs[bdnaRise_prefs_key],
                              setAsDefault  =  True,
                              minimum       =  2.0,
                              maximum       =  4.0,
                              decimals      =  3,
                              singleStep    =  0.01 )

        # Strand Length (i.e. the number of bases)
        self.numberOfBasePairsSpinBox = \
            PM_SpinBox( pmGroupBox,
                        label         =  "Base pairs:",
                        value         =  self._numberOfBases,
                        setAsDefault  =  False,
                        minimum       =  0,
                        maximum       =  10000 )

        self.numberOfBasePairsSpinBox.setDisabled(True)

        # Duplex Length
        self.duplexLengthLineEdit  =  \
            PM_LineEdit( pmGroupBox,
                         label         =  "Duplex length: ",
                         text          =  "0.0 Angstroms",
                         setAsDefault  =  False)

        self.duplexLengthLineEdit.setDisabled(True)

    def _loadDisplayOptionsGroupBox(self, pmGroupBox):
        """
        Load widgets in the Display Options GroupBox
        @see: DnaOrCnt_PropertyManager. _loadDisplayOptionsGroupBox
        """
        #Call the superclass method that loads the cursor text checkboxes.
        #Note, as of 2008-05-19, the superclass, DnaOrCnt_PropertyManager
        #only loads the cursor text groupboxes. Subclasses like this can
        #call custom methods like self._loadCursorTextCheckBoxes etc if they
        #don't need all groupboxes that the superclass loads.
        _superclass._loadDisplayOptionsGroupBox(self, pmGroupBox)

        self._rubberbandLineGroupBox = PM_GroupBox(pmGroupBox,
                                                   title='Rubber band line:')

        dnaLineChoices = ['Ribbons', 'Ladder']
        self.dnaRubberBandLineDisplayComboBox = \
            PM_ComboBox( self._rubberbandLineGroupBox ,
                         label         =  " Display as:",
                         choices       =  dnaLineChoices,
                         setAsDefault  =  True)

        self.lineSnapCheckBox = \
            PM_CheckBox(self._rubberbandLineGroupBox ,
                        text         = 'Enable line snap' ,
                        widgetColumn = 1,
                        state        = Qt.Checked
                    )

    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,
            dnaDuplexEditCommand_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",
             dnaDuplexEditCommand_cursorTextCheckBox_numberOfBasePairs_prefs_key),

            ("Number of turns",
             dnaDuplexEditCommand_cursorTextCheckBox_numberOfTurns_prefs_key),

            ("Duplex length",
             dnaDuplexEditCommand_cursorTextCheckBox_length_prefs_key),

            ("Angle",
             dnaDuplexEditCommand_cursorTextCheckBox_angle_prefs_key) ]

        return params

    def _addToolTipText(self):
        """
        Tool Tip text for widgets in the DNA Property Manager.
        """
        pass

    def conformationComboBoxChanged(self, inIndex):
        """
        Slot for the Conformation combobox. It is called whenever the
        Conformation choice is changed.

        @param inIndex: The new index.
        @type  inIndex: int
        """
        conformation = self.conformationComboBox.currentText()

        if conformation == "B-DNA":
            self.basesPerTurnDoubleSpinBox.setValue("10.0")

        elif conformation == "Z-DNA":
            self.basesPerTurnDoubleSpinBox.setValue("12.0")

        else:
            msg = redmsg("conformationComboBoxChanged(): \
                         Error - unknown DNA conformation. Index = " + inIndex)
            env.history.message(msg)

        self.duplexLengthSpinBox.setSingleStep(getDuplexRise(conformation))

    def numberOfBasesChanged(self, numberOfBases):
        """
        Slot for the B{Number of Bases} spinbox.
        """
        # Update the Duplex Length lineEdit widget.
        text = str(getDuplexLength(self._conformation,
                                   numberOfBases,
                                   self._duplexRise)) \
             + " Angstroms"
        self.duplexLengthLineEdit.setText(text)
        return

    def basesPerTurnChanged(self, basesPerTurn):
        """
        Slot for the B{Bases per turn} spinbox.
        """
        self.command.basesPerTurn = basesPerTurn
        self._basesPerTurn = basesPerTurn
        return

    def duplexRiseChanged(self, rise):
        """
        Slot for the B{Rise} spinbox.
        """
        self.command.duplexRise = rise
        self._duplexRise = rise
        return

    def getParameters(self):
        """
        Return the parameters from this property manager
        to be used to create the DNA duplex.
        @return: A tuple containing the parameters
        @rtype: tuple
        @see: L{InsertDna_EditCommand._gatherParameters} where this is used
        """
        numberOfBases = self.numberOfBasePairsSpinBox.value()
        dnaForm = str(self.conformationComboBox.currentText())
        basesPerTurn = self.basesPerTurnDoubleSpinBox.value()
        duplexRise = self.duplexRiseDoubleSpinBox.value()

        dnaModel = str(self.dnaModelComboBox.currentText())

        # First endpoint (origin) of DNA duplex
        x1 = self.x1SpinBox.value()
        y1 = self.y1SpinBox.value()
        z1 = self.z1SpinBox.value()

        # Second endpoint (direction vector/axis) of DNA duplex.
        x2 = self.x2SpinBox.value()
        y2 = self.y2SpinBox.value()
        z2 = self.z2SpinBox.value()

        if not self.endPoint1:
            self.endPoint1 = V(x1, y1, z1)
        if not self.endPoint2:
            self.endPoint2 = V(x2, y2, z2)

        return (numberOfBases, dnaForm, dnaModel, basesPerTurn, duplexRise,
                self.endPoint1, self.endPoint2)

    def _addWhatsThisText(self):
        """
        What's This text for widgets in this Property Manager.
        """
        whatsThis_InsertDna_PropertyManager(self)
Пример #31
0
class Ui_DnaSequenceEditor(PM_DockWidget):
    """
    The Ui_DnaSequenceEditor class defines UI elements for the Sequence Editor
    object. The sequence editor is usually visible while in while editing
    a DnaStrand.
    
    It is a DockWidget that is docked at the bottom of the MainWindow.
    """
    _title = "Sequence Editor"
    _groupBoxCount = 0
    _lastGroupBox = None

    def __init__(self, win):
        """
        Constructor for the Ui_DnaSequenceEditor 
        @param win: The parentWidget (MainWindow) for the sequence editor 
        """

        self.win = win
        # Should parentWidget for a docwidget always be win?
        #Not necessary but most likely it will be the case.
        parentWidget = win

        _superclass.__init__(self, parentWidget, title=self._title)

        #A flag used to restore the state of the Reports dock widget
        #(which can be accessed through View  >  Reports) see self.show() and
        #self.closeEvent() for more details.
        self._reportsDockWidget_closed_in_show_method = False
        self.setFixedHeight(90)
        return

    def show(self):
        """
        Shows the sequence editor. While doing this, it also closes the reports
        dock widget (if visible) the state of the reports dockwidget will be
        restored when the sequence editor is closed. 
        @see:self.closeEvent()
        """
        self._reportsDockWidget_closed_in_show_method = False
        #hide the history widget first
        #(It will be shown back during self.close)
        #The history widget is hidden or shown only when both
        # 'View > Full Screen' and View > Semi Full Screen actions
        # are *unchecked*
        #Thus show or close methods won't do anything to history widget
        # if either of the above mentioned actions is checked.
        if self.win.viewFullScreenAction.isChecked() or \
           self.win.viewSemiFullScreenAction.isChecked():
            pass
        else:
            if self.win.reportsDockWidget.isVisible():
                self.win.reportsDockWidget.close()
                self._reportsDockWidget_closed_in_show_method = True

        _superclass.show(self)
        return

    def closeEvent(self, event):
        """
        Overrides close event. Makes sure that the visible state of the reports
        widgetis restored when the sequence editor is closed. 
        @see: self.show()
        """
        _superclass.closeEvent(self, event)

        if self.win.viewFullScreenAction.isChecked() or \
           self.win.viewSemiFullScreenAction.isChecked():
            pass
        else:
            if self._reportsDockWidget_closed_in_show_method:
                self.win.viewReportsAction.setChecked(True)
                self._reportsDockWidget_closed_in_show_method = False
        return

    def _loadWidgets(self):
        """
        Overrides PM.PM_DockWidget._loadWidgets. Loads the widget in this
        dockwidget.
        """
        self._loadMenuWidgets()
        self._loadTextEditWidget()
        return

    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options, 
        Find and replace widgets etc. 
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.loadSequenceButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Open.png")

        self.saveSequenceButton = PM_ToolButton(
            self,
            iconPath="ui/actions/Properties Manager/Save_Strand_Sequence.png")

        self.loadSequenceButton.setAutoRaise(True)
        self.saveSequenceButton.setAutoRaise(True)

        # Only supporting 5' to 3' direction until bug 2956 is fixed.
        # Mark 2008-12-19
        editDirectionChoices = ["5' to 3'"]  # , "3' to 5'"]
        self.baseDirectionChoiceComboBox = \
            PM_ComboBox( self,
                         choices = editDirectionChoices,
                         index     = 0,
                         spanWidth = False )

        #Find and replace widgets --
        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)
        self.findLineEdit.setMaximumWidth(60)


        self.replaceLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)
        self.replaceLineEdit.setMaximumWidth(60)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        self._setFindOptionsToolButtonMenu()

        self.findNextToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Next.png")
        self.findNextToolButton.setAutoRaise(True)

        self.findPreviousToolButton = PM_ToolButton(
            self, iconPath="ui/actions/Properties Manager/Find_Previous.png")
        self.findPreviousToolButton.setAutoRaise(True)

        self.replacePushButton = PM_PushButton(self, text="Replace")

        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Sequence Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done --

        # When the widget type starts with the word 'PM_' , the
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned
        # labels (and if they were recreated as mentioned above),
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2]
        #Cleanup in PM_widgetGrid could be to check if the widget starts with
        #'Q'  instead of 'PM_'

        #Widgets to include in the widget row.
        widgetList = [('PM_ToolButton', self.loadSequenceButton, 0),
                      ('PM_ToolButton', self.saveSequenceButton, 1),
                      ('QLabel', "     Sequence direction:", 2),
                      ('PM_ComboBox', self.baseDirectionChoiceComboBox, 3),
                      ('QLabel', "     Find:", 4),
                      ('PM_LineEdit', self.findLineEdit, 5),
                      ('PM_ToolButton', self.findOptionsToolButton, 6),
                      ('PM_ToolButton', self.findPreviousToolButton, 7),
                      ('PM_ToolButton', self.findNextToolButton, 8),
                      ('QLabel', "     Replace:", 9),
                      ('PM_TextEdit', self.replaceLineEdit, 10),
                      ('PM_PushButton', self.replacePushButton, 11),
                      ('PM_Label', self.warningSign, 12),
                      ('PM_Label', self.phraseNotFoundLabel, 13),
                      ('QSpacerItem', 5, 5, 14)]

        widgetRow = PM_WidgetRow(self,
                                 title='',
                                 widgetList=widgetList,
                                 label="",
                                 spanWidth=True)
        return

    def _loadTextEditWidget(self):
        """
        Load the SequenceTexteditWidgets.         
        """
        self.sequenceTextEdit = \
            PM_TextEdit( self,
                         label = " Sequence: ",
                         spanWidth = False,
                         permit_enter_keystroke = False)
        self.sequenceTextEdit.setCursorWidth(2)
        self.sequenceTextEdit.setWordWrapMode(QTextOption.WrapAnywhere)
        self.sequenceTextEdit.setFixedHeight(20)

        #The StrandSequence 'Mate' it is a read only etxtedit that shows
        #the complementary strand sequence.
        self.sequenceTextEdit_mate = \
            PM_TextEdit(self,
                        label = "",
                        spanWidth = False,
                        permit_enter_keystroke = False
                        )
        palette = getPalette(None, QPalette.Base,
                             sequenceEditStrandMateBaseColor)
        self.sequenceTextEdit_mate.setPalette(palette)
        self.sequenceTextEdit_mate.setFixedHeight(20)
        self.sequenceTextEdit_mate.setReadOnly(True)
        self.sequenceTextEdit_mate.setWordWrapMode(QTextOption.WrapAnywhere)

        #Important to make sure that the horizontal and vertical scrollbars
        #for these text edits are never displayed.
        for textEdit in (self.sequenceTextEdit, self.sequenceTextEdit_mate):
            textEdit.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            textEdit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        return

    def _getFindLineEditStyleSheet(self):
        """
        Return the style sheet for the findLineEdit. This sets the following 
        properties only:
         - background-color

        This style is set whenever the searchStrig can't be found (sets
        a light red color background to the lineedit when this happens)   

        @return: The line edit style sheet.
        @rtype:  str

        """
        styleSheet = "QLineEdit {"\
                   "background-color: rgb(255, 102, 102)"\
                   "}"
        #Not used:
        #  background-color: rgb(217, 255, 216)\

        return styleSheet

    def _setFindOptionsToolButtonMenu(self):
        """
        Sets the menu for the findOptionstoolbutton that appears a small 
        menu button next to the findLineEdit.
        """
        self.findOptionsMenu = QMenu(self.findOptionsToolButton)

        self.caseSensitiveFindAction = QAction(self.findOptionsToolButton)
        self.caseSensitiveFindAction.setText('Match Case')
        self.caseSensitiveFindAction.setCheckable(True)
        self.caseSensitiveFindAction.setChecked(False)

        self.findOptionsMenu.addAction(self.caseSensitiveFindAction)
        self.findOptionsMenu.addSeparator()

        self.findOptionsToolButton.setMenu(self.findOptionsMenu)
        return

    def _addToolTipText(self):
        """
            What's Tool Tip text for widgets in this Property Manager.  
            """
        from ne1_ui.ToolTipText_for_PropertyManagers import ToolTip_DnaSequenceEditor
        ToolTip_DnaSequenceEditor(self)
        return

    def _addWhatsThisText(self):
        """
            What's This text for widgets in this Property Manager.  

            """
        from ne1_ui.WhatsThisText_for_PropertyManagers import whatsThis_DnaSequenceEditor
        whatsThis_DnaSequenceEditor(self)
        return
Пример #32
0
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)
Пример #33
0
    def _loadFreeDragRotateGroupBox(self, inPmGroupBox):
        """
        Load widgets in the Free Drag Rotate group box, which is 
        present within the Rotate groupbox.
        @param inPmGroupBox: The Free Drag Rotate group box in the Rotate 
                             group box.
        @type  inPmGroupBox: L{PM_GroupBox}
        """
        # Button list to create a toolbutton row.
        # Format:
        # - buttonId,
        # - buttonText ,
        # - iconPath
        # - tooltip
        # - shortcut
        # - column

        BUTTON_LIST = [
            ( "QToolButton", 1,  "ROTATEDEFAULT",
              "ui/actions/Properties Manager/Rotate_Free.png", "", "F", 0 ),

            ( "QToolButton", 2,  "ROTATEX",
              "ui/actions/Properties Manager/RotateX.png", "", "X", 1 ),

            ( "QToolButton", 3,  "ROTATEY",
              "ui/actions/Properties Manager/RotateY.png", "", "Y", 2 ),

            ( "QToolButton", 4,  "ROTATEZ",
              "ui/actions/Properties Manager/RotateZ.png", "", "Z", 3 ),

            ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",
              "ui/actions/Properties Manager/translate+rotate-A.png", "", \
              "A", 4 )

            ]

        self.freeDragRotateButtonGroup = \
            PM_ToolButtonRow( inPmGroupBox,
                               title        = "",
                               buttonList   = BUTTON_LIST,
                               spanWidth = True,
                               checkedId    = 1,
                               setAsDefault = True,
                            )

        self.rotateFreeButton = self.freeDragRotateButtonGroup.getButtonById(1)
        self.rotateXButton = self.freeDragRotateButtonGroup.getButtonById(2)
        self.rotateYButton = self.freeDragRotateButtonGroup.getButtonById(3)
        self.rotateZButton = self.freeDragRotateButtonGroup.getButtonById(4)
        self.rotAlongAxisButton = \
            self.freeDragRotateButtonGroup.getButtonById(5)

        inPmGroupBox.setStyleSheet(
            self.freeDragRotateButtonGroup._getStyleSheet())

        X_ROW_LABELS = [("QLabel", "Delta Theta X:", 0), ("QLabel", "", 1),
                        ("QLabel", "0.00", 2), ("QLabel", "Degrees", 3)]

        Y_ROW_LABELS = [("QLabel", "Delta Theta Y:", 0), ("QLabel", "", 1),
                        ("QLabel", "0.00", 2), ("QLabel", "Degrees", 3)]

        Z_ROW_LABELS = [("QLabel", "Delta Theta Z:", 0), ("QLabel", "", 1),
                        ("QLabel", "0.00", 2), ("QLabel", "Degrees", 3)]

        self.rotateXLabelRow = PM_LabelRow(inPmGroupBox,
                                           title="",
                                           labelList=X_ROW_LABELS)
        self.deltaThetaX_lbl = self.rotateXLabelRow.labels[2]

        self.rotateYLabelRow = PM_LabelRow(inPmGroupBox,
                                           title="",
                                           labelList=Y_ROW_LABELS)
        self.deltaThetaY_lbl = self.rotateYLabelRow.labels[2]

        self.rotateZLabelRow = PM_LabelRow(inPmGroupBox,
                                           title="",
                                           labelList=Z_ROW_LABELS)
        self.deltaThetaZ_lbl = self.rotateZLabelRow.labels[2]

        self.rotateAboutPointButton = PM_ToolButton(
                    inPmGroupBox,
                    text = "Rotate selection about a point",
                    iconPath  = "ui/actions/Properties Manager"\
                    "/Rotate_Components.png",
                    spanWidth = True
                    )
        self.rotateAboutPointButton.setCheckable(True)
        self.rotateAboutPointButton.setAutoRaise(True)
        self.rotateAboutPointButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)


        self.rotateStartCoordLineEdit = PM_LineEdit(
            inPmGroupBox,
            label        = "ui/actions/Properties Manager"\
                    "/Move_Start_Point.png",
            text         = "Define 3 points",
            setAsDefault = False,
            )
        self.rotateStartCoordLineEdit.setReadOnly(True)
        self.rotateStartCoordLineEdit.setEnabled(False)
class SelectNodeByNameDockWidget(PM_DockWidget):
    """
    The Ui_DnaSequenceEditor class defines UI elements for the Sequence Editor
    object. The sequence editor is usually visible while in DNA edit mode.
    It is a DockWidget that is doced at the bottom of the MainWindow
    """
    _title         =  "Select Node by Name"
    _groupBoxCount = 0
    _lastGroupBox = None

    def __init__(self, win):
        """
        Constructor for the Ui_DnaSequenceEditor
        @param win: The parentWidget (MainWindow) for the sequence editor
        """

        self.win = win
        parentWidget = win

        _superclass.__init__(self, parentWidget, title = self._title)

        win.addDockWidget(Qt.BottomDockWidgetArea, self)
        self.setFixedHeight(120)
        ##self.setFixedWidth(90)
        self.connect_or_disconnect_signals(True)

        if not self.win.selectByNameAction.isChecked():
            self.close()

    def show(self):
        """
        Overrides superclass method.
        """
        _superclass.show(self)
        val = env.prefs[dnaSearchTypeLabelChoice_prefs_key]
        self.searchTypeComboBox_indexChanged(val)


    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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        self._listWidget.connect_or_disconnect_signals(isConnect)

        change_connect( self.searchToolButton,
                      SIGNAL("clicked()"),
                      self.searchNodes)

        prefs_key = dnaSearchTypeLabelChoice_prefs_key
        connect_comboBox_with_pref(self.searchTypeComboBox,
                                   prefs_key )

        change_connect( self.searchTypeComboBox,
                      SIGNAL("currentIndexChanged(int)"),
                      self.searchTypeComboBox_indexChanged)

    def searchTypeComboBox_indexChanged(self, val):
        if val == 0:
            ##self._widgetRow1.show()
            ##self._widgetRow2.hide()
            self._widgetRow1.setEnabled(True)
            self._widgetRow2.setEnabled(False)
        else:
            ##self._widgetRow2.show()
            ##self._widgetRow1.hide()
            self._widgetRow2.setEnabled(True)
            self._widgetRow1.setEnabled(False)

    def searchNodes(self):
        """
        ONLY implemented for DnaStrand or DnaSegments.
        """

        assy = self.win.assy

        topnode = assy.part.topnode
        lst = []
        def func(node):
            if isinstance(node, assy.DnaStrandOrSegment):
                lst.append(node)

        topnode.apply2all(func)

        choice = env.prefs[dnaSearchTypeLabelChoice_prefs_key]

        if choice == 0:
            nodes = self._searchNodesByName(lst)
        elif choice == 1:
            nodes = self._searchNodesByNucleotides(lst)

        self._listWidget.insertItems(
                row = 0,
                items = nodes)

    def _searchNodesByNucleotides(self, nodeList):
        lst = nodeList
        min_val = self._nucleotidesSpinBox_1.value()
        max_val = self._nucleotidesSpinBox_2.value()
        if min_val > max_val:
            print "Lower value for number of nucleotides exceeds max search value"
            return ()

        def func2(node):
            n = node.getNumberOfNucleotides()

            return (n >= min_val and n <= max_val)

        return filter(lambda m:func2(m), lst)


    def _searchNodesByName(self, nodeList):
        nodeNameString = self.findLineEdit.text()
        nodeNameString = str(nodeNameString)

        lst = nodeList
        def func2(node):
            n = len(nodeNameString)
            if len(node.name)< n:
                return False

            nameString = str(node.name[:n])

            if  nameString.lower() == nodeNameString.lower():
                return True

            return False

        return filter(lambda m:func2(m), lst)




    def closeEvent(self, event):
        self.win.selectByNameAction.setChecked(False)
        _superclass.closeEvent(self, event)


    def _loadWidgets(self):
        """
        Overrides PM.PM_DockWidget._loadWidgets. Loads the widget in this
        dockwidget.
        """
        self._loadMenuWidgets()
        self._loadTableWidget()

    def _loadTableWidget(self):
        self._listWidget = PM_DnaSearchResultTable(self, self.win)

    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options,
        Find and replace widgets etc.
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.searchTypeComboBox  = \
            PM_ComboBox( self,
                         label         =  "Search options:",
                         choices       =  ["By node name", "By # of bases (DNA only)"],
                         setAsDefault  =  True)


        #Find  widgets --
        self._nucleotidesSpinBox_1 = PM_SpinBox(self,
                        label         =  "",
                        value         =  10,
                        setAsDefault  =  False,
                        singleStep = 10,
                        minimum       =  1,
                        maximum       =  50000)

        self._nucleotidesSpinBox_2 = PM_SpinBox(self,
                        label         =  "",
                        value         =  50,
                        setAsDefault  =  False,
                        singleStep = 10,
                        minimum       =  1,
                        maximum       =  50000)


        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)

        self.findLineEdit.setMaximumWidth(80)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        ##self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        ##self._setFindOptionsToolButtonMenu()

        self.searchToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Next.png")
        self.searchToolButton.setAutoRaise(False)


        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done --

        # When the widget type starts with the word 'PM_' , the
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned
        # labels (and if they were recreated as mentioned above),
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2]
        #Cleanup in PM_widgetGrid could be to check if the widget starts with
        #'Q'  instead of 'PM_'


        #Widgets to include in the widget row.


        widgetList1 = [
                      ('QLabel', "     Search for name:", 1),
                      ('PM_LineEdit', self.findLineEdit, 2),
                      ('PM_ToolButton', self.findOptionsToolButton, 3),
                      ('PM_ToolButton', self.searchToolButton, 4),
                      ('PM_Label', self.warningSign, 5),
                      ('PM_Label', self.phraseNotFoundLabel, 6),
                      ('QSpacerItem', 5, 5, 7) ]

        widgetList2 = [
                      ('QLabel', "     Number of bases: >=", 1),
                      ('PM_SpinBox', self._nucleotidesSpinBox_1, 2),
                      ('QLabel', "     <=", 3),
                      ('PM_SpinBox', self._nucleotidesSpinBox_2, 4),
                      ('QSpacerItem', 5, 5, 5)]

        widgetList3 = [
                      ('QSpacerItem', 5, 5, 1),
                      ('PM_ToolButton', self.searchToolButton, 2),
                      ('PM_Label', self.warningSign, 3),
                      ('PM_Label', self.phraseNotFoundLabel, 4),
                      ('QSpacerItem', 5, 5, 5) ]


        self._widgetRow1 = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList1,
                                 label = "",
                                 spanWidth = True )

        self._widgetRow2 = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList2,
                                 label = "",
                                 spanWidth = True )

        self._widgetRow3 = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList3,
                                 label = "",
                                 spanWidth = True )
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 InsertNanotube_PropertyManager( DnaOrCnt_PropertyManager):
    """
    The InsertNanotube_PropertyManager class provides a Property Manager
    for the B{Build > Nanotube > 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         =  "Insert Nanotube"
    pmName        =  title
    iconPath      =  "ui/actions/Tools/Build Structures/InsertNanotube.png"

    def __init__( self, win, editCommand ):
        """
        Constructor for the Nanotube property manager.
        """
        self.endPoint1 = None
        self.endPoint2 = None

        self.nanotube = Nanotube() # A 5x5 CNT.

        _superclass.__init__( self,
                                 win,
                                 editCommand)

        self.showTopRowButtons( PM_DONE_BUTTON | \
                                PM_CANCEL_BUTTON | \
                                PM_WHATS_THIS_BUTTON)

    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:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        change_connect( self.ntTypeComboBox,
                      SIGNAL("currentIndexChanged(const QString&)"),
                      self._ntTypeComboBoxChanged )

        change_connect(self.chiralityNSpinBox,
                       SIGNAL("valueChanged(int)"),
                       self._chiralityFixup)

        change_connect(self.chiralityMSpinBox,
                       SIGNAL("valueChanged(int)"),
                       self._chiralityFixup)

        change_connect(self.endingsComboBox,
                       SIGNAL("currentIndexChanged(const QString&)"),
                       self._endingsComboBoxChanged )

        # This spin box is currently hidden.
        change_connect(self.bondLengthDoubleSpinBox,
                       SIGNAL("valueChanged(double)"),
                       self._bondLengthChanged)

        change_connect(self.showCursorTextCheckBox,
                       SIGNAL('stateChanged(int)'),
                       self._update_state_of_cursorTextGroupBox)

    def ok_btn_clicked(self):
        """
        Slot for the OK button
        """
        if self.editCommand:
            self.editCommand.preview_or_finalize_structure(previewing = False)
            ##env.history.message(self.editCommand.logMessage)
        self.win.toolsDone()

    def cancel_btn_clicked(self):
        """
        Slot for the Cancel button.
        """
        if self.editCommand:
            self.editCommand.cancelStructure()
        self.win.toolsCancel()


    def _update_widgets_in_PM_before_show(self):
        """
        Update various widgets in this Property manager.
        Overrides MotorPropertyManager._update_widgets_in_PM_before_show.
        The various  widgets , (e.g. spinboxes) will get values from the
        structure for which this propMgr is constructed for
        (self.editcCntroller.struct)

        @see: MotorPropertyManager._update_widgets_in_PM_before_show
        @see: self.show where it is called.
        """
        pass

    def getFlyoutActionList(self):
        """
        Returns custom actionlist that will be used in a specific mode
        or editing a feature etc Example: while in movie mode,
        the _createFlyoutToolBar method calls this.
        """
        #'allActionsList' returns all actions in the flyout toolbar
        #including the subcontrolArea actions
        allActionsList = []

        #Action List for  subcontrol Area buttons.
        #In this mode there is really no subcontrol area.
        #We will treat subcontrol area same as 'command area'
        #(subcontrol area buttons will have an empty list as their command area
        #list). We will set  the Comamnd Area palette background color to the
        #subcontrol area.

        subControlAreaActionList =[]

        self.exitEditCommandAction.setChecked(True)
        subControlAreaActionList.append(self.exitEditCommandAction)

        separator = QAction(self.w)
        separator.setSeparator(True)
        subControlAreaActionList.append(separator)


        allActionsList.extend(subControlAreaActionList)

        #Empty actionlist for the 'Command Area'
        commandActionLists = []

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

        params = (subControlAreaActionList, commandActionLists, allActionsList)

        return params

    def _addGroupBoxes( self ):
        """
        Add the Insert Nanotube Property Manager group boxes.
        """

        self._pmGroupBox1 = PM_GroupBox( self, title = "Endpoints" )
        self._loadGroupBox1( self._pmGroupBox1 )
        self._pmGroupBox1.hide()

        self._pmGroupBox2 = PM_GroupBox( self, title = "Parameters" )
        self._loadGroupBox2( self._pmGroupBox2 )

        self._displayOptionsGroupBox = PM_GroupBox( self,
                                                    title = "Display Options" )
        self._loadDisplayOptionsGroupBox( self._displayOptionsGroupBox )

        self._pmGroupBox3 = PM_GroupBox( self, title = "Nanotube Distortion" )
        self._loadGroupBox3( self._pmGroupBox3 )
        self._pmGroupBox3.hide() #@ Temporary.

        self._pmGroupBox4 = PM_GroupBox( self, title = "Multi-Walled CNTs" )
        self._loadGroupBox4( self._pmGroupBox4 )
        self._pmGroupBox4.hide() #@ Temporary.

        self._pmGroupBox5 = PM_GroupBox( self, title = "Advanced Options" )
        self._loadGroupBox5( self._pmGroupBox5 )
        self._pmGroupBox5.hide() #@ Temporary.

    def _loadGroupBox1(self, pmGroupBox):
        """
        Load widgets in group box 1.
        """
        #Following toolbutton facilitates entering a temporary NanotubeLineMode
        #to create a CNT using endpoints of the specified line.
        self.specifyCntLineButton = PM_ToolButton(
            pmGroupBox,
            text = "Specify Endpoints",
            iconPath  = "ui/actions/Properties Manager/Pencil.png",
            spanWidth = True
        )
        self.specifyCntLineButton.setCheckable(True)
        self.specifyCntLineButton.setAutoRaise(True)
        self.specifyCntLineButton.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

        #EndPoint1 and endPoint2 coordinates. These widgets are hidden
        # as of 2007- 12 - 05
        self._endPoint1SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                label = "End Point 1")
        self.x1SpinBox = self._endPoint1SpinBoxes.xSpinBox
        self.y1SpinBox = self._endPoint1SpinBoxes.ySpinBox
        self.z1SpinBox = self._endPoint1SpinBoxes.zSpinBox

        self._endPoint2SpinBoxes = PM_CoordinateSpinBoxes(pmGroupBox,
                                                label = "End Point 2")
        self.x2SpinBox = self._endPoint2SpinBoxes.xSpinBox
        self.y2SpinBox = self._endPoint2SpinBoxes.ySpinBox
        self.z2SpinBox = self._endPoint2SpinBoxes.zSpinBox

        self._endPoint1SpinBoxes.hide()
        self._endPoint2SpinBoxes.hide()

    def _loadGroupBox2(self, pmGroupBox):
        """
        Load widgets in group box 2.
        """

        _ntTypeChoices = ['Carbon',
                          'Boron Nitride']
        self.ntTypeComboBox  = \
            PM_ComboBox( pmGroupBox,
                         label         =  "Type:",
                         choices       =  _ntTypeChoices,
                         setAsDefault  =  True)

        self.ntRiseDoubleSpinBox  =  \
            PM_DoubleSpinBox( pmGroupBox,
                              label         =  "Rise:",
                              value         =  self.nanotube.getRise(),
                              setAsDefault  =  True,
                              minimum       =  2.0,
                              maximum       =  4.0,
                              decimals      =  3,
                              singleStep    =  0.01 )

        self.ntRiseDoubleSpinBox.hide()

        # Nanotube Length
        self.ntLengthLineEdit  =  \
            PM_LineEdit( pmGroupBox,
                         label         =  "Nanotube Length: ",
                         text          =  "0.0 Angstroms",
                         setAsDefault  =  False)

        self.ntLengthLineEdit.setDisabled(True)
        self.ntLengthLineEdit.hide()

        # Nanotube diameter
        self.ntDiameterLineEdit  =  \
            PM_LineEdit( pmGroupBox,
                         label         =  "Diameter: ",
                         setAsDefault  =  False)

        self.ntDiameterLineEdit.setDisabled(True)
        self.updateNanotubeDiameter()

        self.chiralityNSpinBox = \
            PM_SpinBox( pmGroupBox,
                        label        = "Chirality (n):",
                        value        = self.nanotube.getChiralityN(),
                        minimum      =  2,
                        maximum      =  100,
                        setAsDefault = True )

        self.chiralityMSpinBox = \
            PM_SpinBox( pmGroupBox,
                        label        = "Chirality (m):",
                        value        = self.nanotube.getChiralityM(),
                        minimum      =  0,
                        maximum      =  100,
                        setAsDefault = True )

        # How about having user prefs for CNT and BNNT bond lengths?
        # I'm guessing that if the user wants to set these values, they will
        # do it once and would like those bond length values persist forever.
        # Need to discuss with others to determine if this spinbox comes out.
        # --Mark 2008-03-29
        self.bondLengthDoubleSpinBox = \
            PM_DoubleSpinBox( pmGroupBox,
                              label        = "Bond length:",
                              value        = self.nanotube.getBondLength(),
                              setAsDefault = True,
                              minimum      = 1.0,
                              maximum      = 3.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

        #self.bondLengthDoubleSpinBox.hide()

        endingChoices = ["Hydrogen", "None"] # Removed:, "Nitrogen"]

        self.endingsComboBox= \
            PM_ComboBox( pmGroupBox,
                         label        = "Endings:",
                         choices      = endingChoices,
                         index        = 0,
                         setAsDefault = True,
                         spanWidth    = False )

    def _loadGroupBox3(self, inPmGroupBox):
        """
        Load widgets in group box 3.
        """

        self.zDistortionDoubleSpinBox = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Z-distortion:",
                              value        = 0.0,
                              setAsDefault = True,
                              minimum      = 0.0,
                              maximum      = 10.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

        self.xyDistortionDoubleSpinBox = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "XY-distortion:",
                              value        = 0.0,
                              setAsDefault = True,
                              minimum      = 0.0,
                              maximum      = 2.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

        self.twistSpinBox = \
            PM_SpinBox( inPmGroupBox,
                        label        = "Twist:",
                        value        = 0,
                        setAsDefault = True,
                        minimum      = 0,
                        maximum      = 100, # What should maximum be?
                        suffix       = " deg/A" )

        self.bendSpinBox = \
            PM_SpinBox( inPmGroupBox,
                        label        = "Bend:",
                        value        = 0,
                        setAsDefault = True,
                        minimum      = 0,
                        maximum      = 360,
                        suffix       = " deg" )

    def _loadGroupBox4(self, inPmGroupBox):
        """
        Load widgets in group box 4.
        """

        # "Number of Nanotubes" SpinBox
        self.mwntCountSpinBox = \
            PM_SpinBox( inPmGroupBox,
                        label        = "Number:",
                        value        = 1,
                        setAsDefault = True,
                        minimum      = 1,
                        maximum      = 10,
                        suffix       = " nanotubes" )

        self.mwntCountSpinBox.setSpecialValueText("SWNT")

        # "Spacing" lineedit.
        self.mwntSpacingDoubleSpinBox = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Spacing:",
                              value        = 2.46,
                              setAsDefault = True,
                              minimum      = 1.0,
                              maximum      = 10.0,
                              singleStep   = 0.1,
                              decimals     = 3,
                              suffix       = " Angstroms" )

    def _loadGroupBox5(self, pmGroupBox):
        """
        Load widgets in group box 5.
        """
        self._rubberbandLineGroupBox = PM_GroupBox(
            pmGroupBox,
            title = 'Rubber band Line:')

        ntLineChoices = ['Ladder']
        self.ntRubberBandLineDisplayComboBox = \
            PM_ComboBox( self._rubberbandLineGroupBox ,
                         label         =  " Display as:",
                         choices       =  ntLineChoices,
                         setAsDefault  =  True)

        self.lineSnapCheckBox = \
            PM_CheckBox(self._rubberbandLineGroupBox ,
                        text         = 'Enable line snap' ,
                        widgetColumn = 1,
                        state        = Qt.Checked
                        )


    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 ,
            insertNanotubeEditCommand_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)

                   ("Nanotube length",
                    insertNanotubeEditCommand_cursorTextCheckBox_length_prefs_key ),

                    ("Angle",
                     insertNanotubeEditCommand_cursorTextCheckBox_angle_prefs_key )
                 ]

        return params


    def _addToolTipText(self):
        """
        Tool Tip text for widgets in the Insert Nanotube Property Manager.
        """
        pass

    def _setEndPoints(self):
        """
        Set the two endpoints of the nanotube using the values from the
        X, Y, Z coordinate spinboxes in the property manager.

        @note: The group box containing the 2 sets of XYZ spin boxes are
        currently hidden.
        """
        # First endpoint (origin) of nanotube
        x1 = self.x1SpinBox.value()
        y1 = self.y1SpinBox.value()
        z1 = self.z1SpinBox.value()

        # Second endpoint (direction vector/axis) of nanotube.
        x2 = self.x2SpinBox.value()
        y2 = self.y2SpinBox.value()
        z2 = self.z2SpinBox.value()

        if not self.endPoint1:
            self.endPoint1 = V(x1, y1, z1)
        if not self.endPoint2:
            self.endPoint2 = V(x2, y2, z2)

        self.nanotube.setEndPoints(self.endPoint1, self.endPoint2)
            # Need arg "recompute=True", which will recompute the second
            # endpoint (endPoint2) using the nanotube rise.

    def getParameters(self):
        """
        Return the parameters from this property manager to be used to create
        the nanotube.

        @return: A nanotube instance with its attrs set to the current
                 parameters in the property manager.
        @rtype: L{Nanotube}

        @see: L{InsertNanotube_EditCommand._gatherParameters} where this is used
        """
        self._setEndPoints()
        return (self.nanotube)

    def _ntTypeComboBoxChanged( self, type ):
        """
        Slot for the Type combobox. It is called whenever the
        Type choice is changed.

        @param inIndex: The new index.
        @type  inIndex: int
        """
        self.nanotube.setType(str(type))
        print "Bond Length =", self.nanotube.getBondLength()
        self.bondLengthDoubleSpinBox.setValue(self.nanotube.getBondLength())
        #self.bondLengthDoubleSpinBox.setValue(ntBondLengths[inIndex])

    def _bondLengthChanged(self, bondLength):
        """
        Slot for the B{Bond Length} spinbox.
        """
        self.nanotube.setBondLength(bondLength)
        self.updateNanotubeDiameter()
        return

    def _chiralityFixup(self, spinBoxValueJunk = None):
        """
        Slot for several validators for different parameters.
        This gets called whenever the user changes the n, m chirality values.

        @param spinBoxValueJunk: This is the Spinbox value from the valueChanged
                                 signal. It is not used. We just want to know
                                 that the spinbox value has changed.
        @type  spinBoxValueJunk: double or None
        """
        _n, _m = self.nanotube.setChirality(self.chiralityNSpinBox.value(),
                                            self.chiralityMSpinBox.value())

        #self.n, self.m = self.nanotube.getChirality()

        self.connect_or_disconnect_signals(isConnect = False)
        self.chiralityNSpinBox.setValue(_n)
        self.chiralityMSpinBox.setValue(_m)
        self.connect_or_disconnect_signals(isConnect = True)

        self.updateNanotubeDiameter()

    def updateNanotubeDiameter(self):
        """
        Update the nanotube Diameter lineEdit widget.
        """
        diameterText = "%-7.4f Angstroms" %  (self.nanotube.getDiameter())
        self.ntDiameterLineEdit.setText(diameterText)

        # ntRiseDoubleSpinBox is currently hidden.
        self.ntRiseDoubleSpinBox.setValue(self.nanotube.getRise())

    def _endingsComboBoxChanged(self, endings):
        """
        Slot for the B{Ending} combobox.

        @param endings: The option's text.
        @type  endings: string
        """
        self.nanotube.setEndings(str(endings))
        return

    def _addWhatsThisText(self):
        """
        What's This text for widgets in this Property Manager.
        """
        whatsThis_InsertNanotube_PropertyManager(self)
        return
Пример #37
0
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()
Пример #38
0
 def _loadFreeDragTranslateGroupBox(self, inPmGroupBox):
     """
     Load widgets in the Free Drag Translate group box, which is present 
     within the Translate groupbox.
     @param inPmGroupBox: The Free Drag Translate group box in the Translate 
                          group box. 
     @type  inPmGroupBox: L{PM_GroupBox}
     """
     # Button list to create a toolbutton row.
     # Format: 
     # - buttonId, 
     # - buttonText , 
     # - iconPath
     # - tooltip
     # - shortcut
     # - column
     
      
     BUTTON_LIST = [ 
         ( "QToolButton", 1,  "MOVEDEFAULT", 
           "ui/actions/Properties Manager/Move_Free.png", "", "F", 0),
         ( "QToolButton", 2,  "TRANSX", 
           "ui/actions/Properties Manager/TranslateX.png", "", "X", 1),
         ( "QToolButton", 3,  "TRANSY",  
           "ui/actions/Properties Manager/TranslateY.png", "", "Y", 2),
         ( "QToolButton", 4,  "TRANSZ",  
           "ui/actions/Properties Manager/TranslateZ.png", "", "Z", 3),
         ( "QToolButton", 5,  "ROT_TRANS_ALONG_AXIS",  
           "ui/actions/Properties Manager/translate+rotate-A.png", "", \
           "A", 4)
                     
         ]
         
     self.freeDragTranslateButtonGroup = \
         PM_ToolButtonRow( inPmGroupBox, 
                            title        = "",
                            buttonList   = BUTTON_LIST,
                            checkedId    = 1,
                            setAsDefault = True,
                            )
     self.transFreeButton =self.freeDragTranslateButtonGroup.getButtonById(1)
     self.transXButton = self.freeDragTranslateButtonGroup.getButtonById(2)
     self.transYButton = self.freeDragTranslateButtonGroup.getButtonById(3)
     self.transZButton = self.freeDragTranslateButtonGroup.getButtonById(4)
     self.transAlongAxisButton = \
         self.freeDragTranslateButtonGroup.getButtonById(5)
     
     self.moveFromToButton = PM_ToolButton(
                 inPmGroupBox, 
                 text = "Translate from/to",
                 iconPath  = "ui/actions/Properties Manager"\
                 "/Translate_Components.png",
                 spanWidth = True
                 
                 )
     self.moveFromToButton.setCheckable(True)
     self.moveFromToButton.setAutoRaise(True)
     self.moveFromToButton.setToolButtonStyle(
         Qt.ToolButtonTextBesideIcon)
     
     
     self.startCoordLineEdit = PM_LineEdit( 
         inPmGroupBox, 
         label        = "ui/actions/Properties Manager"\
                 "/Move_Start_Point.png",
         text         = "Define 'from' and 'to' points",
         setAsDefault = False,
         )
     self.startCoordLineEdit.setReadOnly(True)
     self.startCoordLineEdit.setEnabled(False)
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
    def _loadMenuWidgets(self):
        """
        Load the various menu widgets (e.g. Open, save sequence options,
        Find and replace widgets etc.
        """
        #Note: Find and replace widgets might be moved to their own class.

        self.searchTypeComboBox  = \
            PM_ComboBox( self,
                         label         =  "Search options:",
                         choices       =  ["By node name", "By # of bases (DNA only)"],
                         setAsDefault  =  True)


        #Find  widgets --
        self._nucleotidesSpinBox_1 = PM_SpinBox(self,
                        label         =  "",
                        value         =  10,
                        setAsDefault  =  False,
                        singleStep = 10,
                        minimum       =  1,
                        maximum       =  50000)

        self._nucleotidesSpinBox_2 = PM_SpinBox(self,
                        label         =  "",
                        value         =  50,
                        setAsDefault  =  False,
                        singleStep = 10,
                        minimum       =  1,
                        maximum       =  50000)


        self.findLineEdit = \
            PM_LineEdit( self,
                         label        = "",
                         spanWidth    = False)

        self.findLineEdit.setMaximumWidth(80)

        self.findOptionsToolButton = PM_ToolButton(self)
        self.findOptionsToolButton.setMaximumWidth(12)
        self.findOptionsToolButton.setAutoRaise(True)

        ##self.findOptionsToolButton.setPopupMode(QToolButton.MenuButtonPopup)

        ##self._setFindOptionsToolButtonMenu()

        self.searchToolButton = PM_ToolButton(
            self,
            iconPath = "ui/actions/Properties Manager/Find_Next.png")
        self.searchToolButton.setAutoRaise(False)


        self.warningSign = QLabel(self)
        self.warningSign.setPixmap(
            getpixmap('ui/actions/Properties Manager/Warning.png'))
        self.warningSign.hide()

        self.phraseNotFoundLabel = QLabel(self)
        self.phraseNotFoundLabel.setText("Not Found")
        self.phraseNotFoundLabel.hide()

        # NOTE: Following needs cleanup in the PM_WidgetRow/ PM_WidgetGrid
        # but this explanation is sufficient  until thats done --

        # When the widget type starts with the word 'PM_' , the
        # PM_WidgetRow treats it as a well defined widget and thus doesn't try
        # to create a QWidget object (or its subclasses)
        # This is the reason why qLabels such as self.warningSign and
        # self.phraseNotFoundLabel  are defined as PM_Labels and not 'QLabels'
        # If they were defined as 'QLabel'(s) then PM_WidgetRow would have
        # recreated the label. Since we want to show/hide the above mentioned
        # labels (and if they were recreated as mentioned above),
        # we would have needed to define  those something like this:
        # self.phraseNotFoundLabel = widgetRow._widgetList[-2]
        #Cleanup in PM_widgetGrid could be to check if the widget starts with
        #'Q'  instead of 'PM_'


        #Widgets to include in the widget row.


        widgetList1 = [
                      ('QLabel', "     Search for name:", 1),
                      ('PM_LineEdit', self.findLineEdit, 2),
                      ('PM_ToolButton', self.findOptionsToolButton, 3),
                      ('PM_ToolButton', self.searchToolButton, 4),
                      ('PM_Label', self.warningSign, 5),
                      ('PM_Label', self.phraseNotFoundLabel, 6),
                      ('QSpacerItem', 5, 5, 7) ]

        widgetList2 = [
                      ('QLabel', "     Number of bases: >=", 1),
                      ('PM_SpinBox', self._nucleotidesSpinBox_1, 2),
                      ('QLabel', "     <=", 3),
                      ('PM_SpinBox', self._nucleotidesSpinBox_2, 4),
                      ('QSpacerItem', 5, 5, 5)]

        widgetList3 = [
                      ('QSpacerItem', 5, 5, 1),
                      ('PM_ToolButton', self.searchToolButton, 2),
                      ('PM_Label', self.warningSign, 3),
                      ('PM_Label', self.phraseNotFoundLabel, 4),
                      ('QSpacerItem', 5, 5, 5) ]


        self._widgetRow1 = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList1,
                                 label = "",
                                 spanWidth = True )

        self._widgetRow2 = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList2,
                                 label = "",
                                 spanWidth = True )

        self._widgetRow3 = PM_WidgetRow(self,
                                 title     = '',
                                 widgetList = widgetList3,
                                 label = "",
                                 spanWidth = True )