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

from dna.model.DnaStrand import DnaStrand

from command_support.Command_PropertyManager import Command_PropertyManager

_superclass = Command_PropertyManager
class ConvertDna_PropertyManager(Command_PropertyManager):
    """
    Provides a Property Manager for the B{Convert Dna} command.
    """

    title         =  "Convert DNA"
    pmName        =  title
    iconPath      =  "ui/actions/Command Toolbar/BuildDna/ConvertDna.png"

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

        _superclass.__init__(self, command)

        self.assy = self.win.assy

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

        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._convertButton,
                             SIGNAL("clicked()"),
                             self._convertDna)

        ##change_connect( self.includeStrandsComboBox,
                      ##SIGNAL("activated(int)"),
                      ##self.update_includeStrands )
        return

    # Ask Bruce where this should live (i.e. class Part?) --Mark
    # This method was copied from OrderDna_PropertyManager.py
    def _getAllDnaStrands(self, selectedOnly = False):
        """
        Returns a list of all the DNA strands in the current part, or only
        the selected strands if I{selectedOnly} is True.

        @param selectedOnly: If True, return only the selected DNA strands.
        @type  selectedOnly: bool
        """

        dnaStrandList = []

        def func(node):
            if isinstance(node, DnaStrand):
                if selectedOnly:
                    if node.picked:
                        dnaStrandList.append(node)
                else:
                    dnaStrandList.append(node)

        self.win.assy.part.topnode.apply2all(func)

        return dnaStrandList

    def _convertDna(self):

        _dnaStrandList = []
        _dnaStrandList = self._getAllDnaStrands(selectedOnly = True)

        if not _dnaStrandList:
            msg = "<font color=red>" \
                "Nothing converted since no DNA strands are currently selected."
            self.updateMessage(msg)
            return

        if self._convertChoiceComboBox.currentIndex() == 0:
            self._convertPAM3ToPAM5()
        else:
            self._convertPAM5ToPAM3()

        self.updateMessage()
        return

    def _convertPAM3ToPAM5(self):
        self.command.assy.convertPAM3to5Command()
        return

    def _convertPAM5ToPAM3(self):
        self.command.assy.convertPAM5to3Command()
        return

    def _addGroupBoxes( self ):
        """
        Add the Property Manager group boxes.
        """
        self._pmGroupBox1 = PM_GroupBox( self, title = "Conversion Options" )
        self._loadGroupBox1( self._pmGroupBox1 )
        return

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

        convertChoices = ["Convert from PAM3 to PAM5",
                        "Convert from PAM5 to PAM3"]

        self._convertChoiceComboBox  = \
            PM_ComboBox( pmGroupBox,
                         label         =  "",
                         choices       =  convertChoices,
                         index         =  0,
                         setAsDefault  =  True,
                         spanWidth     =  True)

        self._convertButton = \
            PM_PushButton( pmGroupBox,
                           label     = "",
                           text      = "Convert Selection Now",
                           spanWidth = True)
        return

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

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

    def show(self):
        """
        Show this property manager. Overrides EditCommand_PM.show()
        We need this here to force the message update whenever we show the PM
        since an old message might still be there.
        """
        _superclass.show(self)
        self.updateMessage()

    def updateMessage(self, msg = ''):
        """

        """
        if not msg:
            msg = "Select the DNA you want to convert, then select the appropriate "\
                "conversion option and press the <b>Convert Selection Now</b> button."

        _superclass.updateMessage(self, msg)
        return