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

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

History:

ninad 2007-08-09: Created.

@attention: This file is subject to heavy modifications.
"""

from PM.PM_WidgetGrid import PM_WidgetGrid
from widgets.widget_helpers import QColor_to_Hex
from PM.PM_Colors import pmGrpBoxColor

class PM_WidgetRow( PM_WidgetGrid ):
    """
    The B{PM_WidgetRow} provides a convenient way to create different
    types of widgets (such as ToolButtons, Labels, PushButtons etc) in a single
    row and add them to a groupbox.

    #Example of how a caller creates a PM_WidgetRow object:

    # Format of the widget list that is passed to the widget row --
        # - Widget type,
        # - Middle portion of any tuple in the list is either a widget object
        #   or some other parameters if the widget object of
        #   given type needs to be created by the PM_WidgetRow. For example--
        #   If widget type  is 'QLabel' , then it will be created by
        #   PM_WidgetRow class and user just need to provide the text for the
        #   QLabel.
        # - column number (the last item in a tuple)

    aWidgetList = [('PM_ComboBox', self.latticeTypeComboBox, 0),
                   ('PM_PushButton', self.addLayerButton, 1),
                   ('QLabel', "Some Label", 2)  ]

    widgetRow = PM_WidgetRow(parentWidget,
                             title     = '',
                             widgetList = aWidgetList,
                             label = "Layer:",
                             labelColumn  = 0,
                             )
    @see: B{PM_WidgetGrid._createWidgetUsingParameters }
    @see: B{Ui_BuildCrystal_PropertyManager._loadLayerPropertiesGroupBox} that uses
          a B{PM_WidgetRow}

    """
    titleButtonRequested = False

    def __init__(self,
                 parentWidget,
                 title     = '',
                 widgetList = [],
                 alignment  = None,
                 label = '',
                 labelColumn = 0,
                 spanWidth   = False
                 ):

        """
        Appends a PM_WidgetRow (a group box widget) to the bottom of
        I{parentWidget},the Property Manager Group box.

        @param parentWidget: The parent group box containing this widget.
        @type  parentWidget: L{PM_GroupBox}

        @param title: The group box title.
        @type  title: str

        @param widgetList: A list of I{widget info lists}. There is one widget
                           info list for each widget in the grid. The widget
                           info list contains custom information about the
                           widget but the following items are always present:
                           - First Item       : Widget Type (str),
                           - Second Last Item : Column (int),
                           - Last Item        : Row (int).
        @type  widgetList: list

        @param alignment:  The alignment of the widget row in the parent
                           groupbox. Based on its value,spacer items is added
                           to the grid layout of the parent groupbox.
        @type  alignment:  str

        @param label:      The label for the widget row. .
        @type  label:      str

        @param labelColumn: The column in the parentWidget's grid layout to which
                            this widget's label will be added. The labelColum
                            can only be E{0} or E{1}
        @type  labelColumn: int

        @param spanWidth: If True, the widget and its label will span the width
                      of the group box. Its label will appear directly above
                      the widget (unless the label is empty) and is left justified.
        @type  spanWidth: bool (default False)

        """

        PM_WidgetGrid.__init__(self,
                               parentWidget ,
                               title,
                               widgetList,
                               alignment ,
                               label,
                               labelColumn,
                               spanWidth
                              )


    def getWidgetInfoList(self, widgetInfo):
        """
        Returns the label information provided by the user.
        Overrides PM_LabelGrid.getLabelInfoList if they need to provide
        custom information (e.g. a fixed value for row) .
        @param  labelInfo: list containing the label information
        @type   labelInfo: list
        @return : A list containing the label information.
                This can be same as I{labelInfo} or can be modified further.
        @rtype  : list
        @see:   L{PM_WidgetGrid.getWidgetInfoList (this method is overridden
        here)

        """

        row    = 0
        widgetInfoList = list(widgetInfo)
        widgetInfoList.append(row)

        return widgetInfoList

    def _getStyleSheet(self):
        """
        Return the style sheet for the groupbox. This sets the following
        properties only:
         - border style
         - border width
         - border color
         - border radius (on corners)
         - background color
        @see: L{PM_GroupBox._getStyleSheet} (overrided here)
        """

        styleSheet = "QGroupBox {border-style:hidden; "\
        "border-width: 0px; "\
        "border-color: ""; "\
        "border-radius: 0px;"\
        "min-width: 10em; "\
        "background-color: #%s;"\
        "}" % ( QColor_to_Hex(pmGrpBoxColor))


        return styleSheet