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

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

History:

ninad 2007-08-07: Created.
ninad 2007-08-14: Changes due to the new superclass of PM_ToolButtonGrid.
"""

from PM.PM_ToolButtonGrid import PM_ToolButtonGrid


class PM_ToolButtonRow( PM_ToolButtonGrid ):
    """
    The PM_ToolButtonRow widget provides a row of tool buttons that function
    as an I{exclusive button group}.

    @see: B{Ui_MovePropertyManager} for an example of how this is used.

    """
    def __init__(self,
                 parentWidget,
                 title        = '',
                 buttonList   = [],
                 alignment    = None,
                 label        = '',
                 labelColumn  = 0,
                 spanWidth    = False,
                 checkedId    = -1,
                 setAsDefault = False,
                 isAutoRaise  = True,
                 isCheckable  = True
                 ):
        """
        Appends a PM_ToolButtonRow widget to the bottom of I{parentWidget},
        the Property Manager dialog or group box.

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

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

        @param buttonList: A list of I{button info lists}. There is one button
                           info list for each button in the grid. The button
                           info list contains the following items:
                           (notice that this list doesn't contain the 'row'
                           which is seen in B{PM_ToolButtonGrid}.)
                            1. Button Type - in this case its 'ToolButton'(str),
                            2. Button Id (int),
                            3. Button text (str),
                            4. Button icon path (str),
                            5. Button tool tip (str),
                            6. Column (int).
        @type  buttonList: list

        @param alignment:  The alignment of the toolbutton 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 toolbutton row. If present, it is
                           added to the same grid layout as the rest of the
                           toolbuttons, in column number E{0}.
        @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)

        @param checkedId:  Checked button id in the button group. Default value
                           is -1 that implies no button is checked.
        @type  checkedId:  int

        @param setAsDefault: If True, sets the I{checkedId} specified by the
                            user as the  default checked
        @type  setAsDefault: boolean

        """

        PM_ToolButtonGrid.__init__(self,
                                   parentWidget,
                                   title,
                                   buttonList,
                                   alignment,
                                   label,
                                   labelColumn,
                                   spanWidth,
                                   checkedId,
                                   setAsDefault,
                                   isAutoRaise,
                                   isCheckable)



    def getWidgetInfoList(self, buttonInfo):
        """
        Returns the button information provided by the user.
        Overrides the L{PM_WidgetGrid.getWidgetInfoList}
        This is used to set custom information (e.g. a fixed value for row)
        for the button.

        @param  buttonInfo: list containing the button information
        @type   buttonInfo: list

        @return: A list containing the button information.
                This can be same as I{buttonInfo} or can be modified further.
        @rtype:  list

        @see:   L{PM_WidgetGrid.getWidgetInfoList} (overrides this method)

        """

        buttonInfoList = []
        buttonType     = buttonInfo[0]
        buttonId       = buttonInfo[1]
        buttonText     = buttonInfo[2]
        buttonIconPath = buttonInfo[3]
        buttonToolTip  = buttonInfo[4]
        buttonShortcut = buttonInfo[5]
        column         = buttonInfo[6]
        row            = 0

        buttonInfoList = [
            buttonType,
            buttonId,
            buttonText,
            buttonIconPath,
            buttonToolTip,
            buttonShortcut,
            column,
            row]

        return buttonInfoList

    def _getStyleSheet(self):
        """
        Return the style sheet for the toolbutton row. This sets the following
        properties only:
         - border style
         - border width
         - border color
         - border radius (on corners)

        @see: L{PM_GroupBox._getStyleSheet} (overrides this method)
        """
        #For a toolbutton row, we don't (usually) need  a borders . So set
        #the style sheet accordingly
        styleSheet = \
                   "QGroupBox {border-style:hidden; \
                    border-width: 0px; \
                    border-color: ""; \
                    border-radius: 0px; \
                    min-width: 10em; }"

        return styleSheet