summaryrefslogtreecommitdiff
path: root/cad/src/PM/PM_DnaBaseNumberLabelsGroupBox.py
blob: f2bcfceb23d7d6e0eff635f85887a9c83b6aae7b (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
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""

@author: Ninad
@copyright: 2008 Nanorex, Inc.  See LICENSE file for details.
@version:$Id$

History:
2008-08-12 created.

TODO 2008-08-12:
- This uses global pref keys (hardcoded) because the preference is supposed
to remain in all commands. Other option is to ask the command or parentWidget
for the prefs_key. If we want to support local prefs keys (e.g. turn on the labels
while in certain commands only, then perhaps it should ask for prefs keys from
the command. (and there needs an API method in command so that its implemented for all
command classes. The latter seems unncecessary at this time,
"""
import foundation.env as env
from PM.PM_GroupBox import PM_GroupBox
from PM.PM_ComboBox import PM_ComboBox
from PM.PM_ColorComboBox import PM_ColorComboBox

from utilities.prefs_constants import dnaBaseNumberLabelColor_prefs_key
from utilities.prefs_constants import dnaBaseNumberingOrder_prefs_key
from utilities.prefs_constants import dnaBaseNumberLabelChoice_prefs_key

from PyQt4.Qt import SIGNAL
from widgets.prefs_widgets import connect_comboBox_with_pref

_superclass = PM_GroupBox

class PM_DnaBaseNumberLabelsGroupBox(PM_GroupBox):
    """
    """
    def __init__(self,
                 parentWidget,
                 command,
                 title = 'Base Number Labels' ):
        """
        """

        self.command = command
        self.win = self.command.win

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

    def connect_or_disconnect_signals(self, isConnect):
        """
        """
        if isConnect:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        change_connect(self._baseNumberLabelColorChooser,
                      SIGNAL("editingFinished()"),
                      self._colorChanged_dnaBaseNumberLabel)

        self._connect_widgets_with_prefs_keys()



    def _connect_widgets_with_prefs_keys(self):
        """
        Connect various widgets with a prefs_key
        """
        prefs_key = dnaBaseNumberLabelChoice_prefs_key
        connect_comboBox_with_pref(self._baseNumberComboBox,
                                   prefs_key )

        prefs_key = dnaBaseNumberingOrder_prefs_key
        connect_comboBox_with_pref(self._baseNumberingOrderComboBox ,
                                   prefs_key )


    def _loadWidgets(self):
        """
        Load the widgets in the Groupbox
        """
        baseNumberChoices = ('None (default)',
                             'Strands and segments',
                             'Strands only',
                             'Segments only')

        self._baseNumberComboBox = \
            PM_ComboBox( self,
                         label         =  "Base numbers:",
                         choices       =  baseNumberChoices,
                         setAsDefault  =  True)

        numberingOrderChoices = ('5\' to 3\' (default)',
                           '3\' to 5\'' )

        self._baseNumberingOrderComboBox = \
            PM_ComboBox( self,
                         label         =  "Base numbers:",
                         choices       =  numberingOrderChoices,
                         setAsDefault  =  True)

        prefs_key = dnaBaseNumberLabelColor_prefs_key
        self._baseNumberLabelColorChooser = \
            PM_ColorComboBox(self,
                             color      = env.prefs[prefs_key])


    def _colorChanged_dnaBaseNumberLabel(self):
        """
        Choose custom color for 5' ends
        """
        color = self._baseNumberLabelColorChooser.getColor()
        prefs_key = dnaBaseNumberLabelColor_prefs_key
        env.prefs[prefs_key] = color
        self.win.glpane.gl_update()
        return

    def _updateColor_dnaBaseNumberLabel(self):
        """
        Update the color in the base number label combobox while calling
        self.show()
        @see: self.show().
        """
        prefs_key = dnaBaseNumberLabelColor_prefs_key
        color = env.prefs[prefs_key]
        self._baseNumberLabelColorChooser.setColor(color)
        return

    def updateWidgets(self):
        """
        Called in BreakorJoinstrands_PropertyManager.show()
        """
        #@TODO: revise this.
        #Ideally the color combobox  should be connected with state.
        #(e.g. 'connect_colorCombobox_with_state' , which will make the
        #following update call unncessary. but connecting with state
        #for the color combobox has some issues not resolved yet.
        #(e.g. the current index changed won't always allow you to set the
        #proper color -- because the 'Other color' can be anything)
        #--Ninad 2008-08-12
        self._updateColor_dnaBaseNumberLabel()