summaryrefslogtreecommitdiff
path: root/cad/src/PM/PM_GroupBox.py
blob: a794b1e557b8a056c00c78d2e74f39c5cc9b5038 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details.
"""
PM_GroupBox.py

@author: Mark
@version: $Id$
@copyright: 2006-2007 Nanorex, Inc.  All rights reserved.

History:

mark 2007-07-22: Split PropMgrGroupBox out of PropMgrBaseClass.py into this
file and renamed it PM_GroupBox.
"""

import sys
from utilities import debug_flags

from PM.PM_Colors import pmGrpBoxButtonBorderColor
from PM.PM_Colors import pmGrpBoxButtonTextColor
from PM.PM_Colors import pmGrpBoxExpandedIconPath
from PM.PM_Colors import pmGrpBoxCollapsedIconPath
from PM.PM_Colors import pmGrpBoxColor
from PM.PM_Colors import pmGrpBoxBorderColor
from PM.PM_Colors import pmGrpBoxButtonColor

from PM.PM_Constants import PM_GROUPBOX_SPACING
from PM.PM_Constants import PM_GROUPBOX_VBOXLAYOUT_MARGIN
from PM.PM_Constants import PM_GROUPBOX_VBOXLAYOUT_SPACING
from PM.PM_Constants import PM_GROUPBOX_GRIDLAYOUT_MARGIN
from PM.PM_Constants import PM_GROUPBOX_GRIDLAYOUT_SPACING

from PM.PM_Constants import PM_GRIDLAYOUT_MARGIN
from PM.PM_Constants import PM_GRIDLAYOUT_SPACING

from PM.PM_Constants import PM_LABEL_LEFT_ALIGNMENT, PM_LABEL_RIGHT_ALIGNMENT

from PyQt4.Qt import QGroupBox
from PyQt4.Qt import QGridLayout
from PyQt4.Qt import QLabel
from PyQt4.Qt import QPushButton
from PyQt4.Qt import QPalette
from PyQt4.Qt import QSizePolicy
from PyQt4.Qt import QSpacerItem
from PyQt4.Qt import QVBoxLayout
from PyQt4.Qt import QWidget
from PyQt4.Qt import SIGNAL

from widgets.widget_helpers import QColor_to_Hex
from utilities.icon_utilities import geticon, getpixmap

from utilities.GlobalPreferences import debug_pref_support_Qt_4point2

#This import is only used in isinstance check--
from PM.PM_CheckBox import PM_CheckBox

# ==

_SUPPORT_QT_4point2 = debug_pref_support_Qt_4point2() #bruce 080725

# ==

class PM_GroupBox( QGroupBox ):
    """
    The PM_GroupBox widget provides a group box container with a
    collapse/expand button and a title button.

    PM group boxes can be nested by supplying an existing PM_GroupBox as the
    parentWidget of a new PM_GroupBox (as an argument to its constructor).
    If the parentWidget is a PM_GroupBox, no title button will be created
    for the new group box.

    @cvar setAsDefault: Determines whether to reset the value of all
                        widgets in the group box when the user clicks
                        the "Restore Defaults" button. If set to False,
                        no widgets will be reset regardless thier own
                        I{setAsDefault} value.
    @type setAsDefault: bool

    @cvar labelWidget: The Qt label widget of this group box.
    @type labelWidget: U{B{QLabel}<http://doc.trolltech.com/4/qlabel.html>}

    @cvar expanded: Expanded flag.
    @type expanded: bool

    @cvar _title: The group box title.
    @type _title: str

    @cvar _widgetList: List of widgets in the group box
                      (except the title button).
    @type _widgetList: list

    @cvar _rowCount: Number of rows in the group box.
    @type _rowCount: int

    @cvar _groupBoxCount: Number of group boxes in this group box.
    @type _groupBoxCount: int

    @cvar _lastGroupBox: The last group box in this group box (i.e. the
                         most recent PM group box added).
    @type _lastGroupBox: PM_GroupBox
    """

    setAsDefault = True
    labelWidget  = None
    expanded     = True

    _title         = ""
    _widgetList    = []
    _rowCount      = 0
    _groupBoxCount = 0
    _lastGroupBox  = None
    titleButtonRequested = True

    def __init__(self,
                 parentWidget,
                 title          = '',
                 connectTitleButton = True,
                 setAsDefault   = True
                 ):
        """
        Appends a PM_GroupBox widget to I{parentWidget}, a L{PM_Dialog} or a
        L{PM_GroupBox}.

        If I{parentWidget} is a L{PM_Dialog}, the group box will have a title
        button at the top for collapsing and expanding the group box. If
        I{parentWidget} is a PM_GroupBox, the title will simply be a text
        label at the top of the group box.

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

        @param title: The title (button) text. If empty, no title is added.
        @type  title: str

        @param connectTitleButton: If True, this class will automatically
                      connect the title button of the groupbox to send signal
                      to expand or collapse the groupbox. Otherwise, the caller
                      has to connect this signal by itself. See:
                      B{Ui_MovePropertyManager.addGroupBoxes} and
                      B{MovePropertyManager.connect_or_disconnect_signals} for
                      examples where the client connects this slot.
        @type  connectTitleButton: bool


        @param setAsDefault: If False, no widgets in this group box will have
                             thier default values restored when the B{Restore
                             Defaults} button is clicked, regardless thier own
                             I{setAsDefault} value.
        @type  setAsDefault: bool

        @see: U{B{QGroupBox}<http://doc.trolltech.com/4/qgroupbox.html>}
        """

        QGroupBox.__init__(self)

        self.parentWidget = parentWidget

        # Calling addWidget() here is important. If done at the end,
        # the title button does not get assigned its palette for some
        # unknown reason. Mark 2007-05-20.
        # Add self to PropMgr's vBoxLayout
        if parentWidget:
            parentWidget._groupBoxCount += 1
            parentWidget.vBoxLayout.addWidget(self)
            parentWidget._widgetList.append(self)

        _groupBoxCount = 0
        self._widgetList = []
        self._title = title
        self.setAsDefault = setAsDefault

        self.setAutoFillBackground(True)
        self.setStyleSheet(self._getStyleSheet())

        # Create vertical box layout which will contain two widgets:
        # - the group box title button (or title) on row 0.
        # - the container widget for all PM widgets on row 1.
        self._vBoxLayout = QVBoxLayout(self)
        self._vBoxLayout.setMargin(0)
        self._vBoxLayout.setSpacing(0)

        # _containerWidget contains all PM widgets in this group box.
        # Its sole purpose is to easily support the collapsing and
        # expanding of a group box by calling this widget's hide()
        # and show() methods.
        self._containerWidget = QWidget()

        self._vBoxLayout.insertWidget(0, self._containerWidget)

        # Create vertical box layout
        self.vBoxLayout = QVBoxLayout(self._containerWidget)
        self.vBoxLayout.setMargin(PM_GROUPBOX_VBOXLAYOUT_MARGIN)
        self.vBoxLayout.setSpacing(PM_GROUPBOX_VBOXLAYOUT_SPACING)

        # Create grid layout
        self.gridLayout = QGridLayout()
        self.gridLayout.setMargin(PM_GRIDLAYOUT_MARGIN)
        self.gridLayout.setSpacing(PM_GRIDLAYOUT_SPACING)

        # Insert grid layout in its own vBoxLayout
        self.vBoxLayout.addLayout(self.gridLayout)

        # Add title button (or just a title if the parent is not a PM_Dialog).
        if not parentWidget or isinstance(parentWidget, PM_GroupBox):
            self.setTitle(title)
        else: # Parent is a PM_Dialog, so add a title button.
            if not self.titleButtonRequested:
                self.setTitle(title)
            else:
                self.titleButton = self._getTitleButton(self, title)
                self._vBoxLayout.insertWidget(0, self.titleButton)
                if connectTitleButton:
                    self.connect( self.titleButton,
                                  SIGNAL("clicked()"),
                                  self.toggleExpandCollapse)
                self._insertMacSpacer()

        # Fixes the height of the group box. Very important. Mark 2007-05-29
        self.setSizePolicy(
            QSizePolicy(QSizePolicy.Policy(QSizePolicy.Preferred),
                        QSizePolicy.Policy(QSizePolicy.Fixed)))

        self._addBottomSpacer()
        return

    def _insertMacSpacer(self, spacerHeight = 6):
        """
        This addresses a Qt 4.3.5 layout bug on Mac OS X in which the
        title button will overlap with and cover the first widget in
        the group box. This workaround inserts a I{spacerHeight} tall
        spacer between the group box's title button and container widget.
        """
        if sys.platform != "darwin":
            return

        self._macVerticalSpacer = QSpacerItem(10, spacerHeight,
                                        QSizePolicy.MinimumExpanding,
                                        QSizePolicy.Fixed)
        self._vBoxLayout.insertItem(1, self._macVerticalSpacer)
        return

    def _addBottomSpacer(self):
        """
        Add a vertical spacer below this group box.

        Method: Assume this is going to be the last group box in the PM, so set
        its spacer's vertical sizePolicy to MinimumExpanding. We then set the
        vertical sizePolicy of the last group box's spacer to Fixed and set its
        height to PM_GROUPBOX_SPACING.
        """
        # Spacers are only added to groupboxes in the PropMgr, not
        # nested groupboxes.

##        from PM.PM_Dialog import PM_Dialog
##        if not isinstance(self.parentWidget, PM_Dialog):

        if not self.parentWidget or isinstance(self.parentWidget, PM_GroupBox):
            #bruce 071103 revised test to remove import cycle; I assume that
            # self.parentWidget is either a PM_GroupBox or a PM_Dialog, since
            # comments about similar code in __init__ imply that.
            #
            # A cleaner fix would involve asking self.parentWidget whether to
            # do this, with instances of PM_GroupBox and PM_Dialog giving
            # different answers, and making them both inherit an API class
            # which documents the method or attr with which we ask them that
            # question; the API class would be inherited by any object to
            # which PM_GroupBox's such as self can be added.
            #
            # Or, an even cleaner fix would just call a method in
            # self.parentWidget to do what this code does now (implemented
            # differently in PM_GroupBox and PM_Dialog).
            self.verticalSpacer = None
            return

        if self.parentWidget._lastGroupBox:
            # _lastGroupBox is no longer the last one. <self> will be the
            # _lastGroupBox, so we must change the verticalSpacer height
            # and sizePolicy of _lastGroupBox to be a fixed
            # spacer between it and <self>.
            defaultHeight = PM_GROUPBOX_SPACING
            self.parentWidget._lastGroupBox.verticalSpacer.changeSize(
                10, defaultHeight,
                QSizePolicy.Fixed,
                QSizePolicy.Fixed)
            self.parentWidget._lastGroupBox.verticalSpacer.defaultHeight = \
                defaultHeight

        # Add a 1 pixel high, MinimumExpanding VSpacer below this group box.
        # This keeps all group boxes in the PM layout squeezed together as
        # group boxes  are expanded, collapsed, hidden and shown again.
        defaultHeight = 1
        self.verticalSpacer = QSpacerItem(10, defaultHeight,
                                        QSizePolicy.Fixed,
                                        QSizePolicy.MinimumExpanding)

        self.verticalSpacer.defaultHeight = defaultHeight

        self.parentWidget.vBoxLayout.addItem(self.verticalSpacer)

        # This groupbox is now the last one in the PropMgr.
        self.parentWidget._lastGroupBox = self
        return

    def restoreDefault (self):
        """
        Restores the default values for all widgets in this group box.
        """
        for widget in self._widgetList:
            if debug_flags.atom_debug:
                print "PM_GroupBox.restoreDefault(): widget =", \
                      widget.objectName()
            widget.restoreDefault()

        return

    def getTitle(self):
        """
        Returns the group box title.

        @return: The group box title.
        @rtype:  str
        """
        return self._title

    def setTitle(self, title):
        """
        Sets the groupbox title to <title>.

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

        @attention: This overrides QGroupBox's setTitle() method.
        """

        if not title:
            return

        # Create QLabel widget.
        if not self.labelWidget:
            self.labelWidget = QLabel()
            self.vBoxLayout.insertWidget(0, self.labelWidget)
            labelAlignment = PM_LABEL_LEFT_ALIGNMENT
            self.labelWidget.setAlignment(labelAlignment)

        self._title = title
        self.labelWidget.setText(title)
        return

    def getPmWidgetPlacementParameters(self, pmWidget):
        """
        Returns all the layout parameters needed to place
        a PM_Widget in the group box grid layout.

        @param pmWidget: The PM widget.
        @type  pmWidget: PM_Widget
        """

        row = self._rowCount

        #PM_CheckBox doesn't have a label. So do the following to decide the
        #placement of the checkbox. (can be placed either in column 0 or 1 ,
        #This also needs to be implemented for PM_RadioButton, but at present
        #the following code doesn't support PM_RadioButton.
        if isinstance(pmWidget, PM_CheckBox):
            spanWidth = pmWidget.spanWidth

            if not spanWidth:
                # Set the widget's row and column parameters.
                widgetRow      = row
                widgetColumn   = pmWidget.widgetColumn
                widgetSpanCols = 1
                widgetAlignment = PM_LABEL_LEFT_ALIGNMENT
                rowIncrement   = 1
                #set a virtual label
                labelRow       = row
                labelSpanCols  = 1
                labelAlignment = PM_LABEL_RIGHT_ALIGNMENT

                if widgetColumn == 0:
                    labelColumn   = 1
                elif widgetColumn == 1:
                    labelColumn   = 0
            else:
                # Set the widget's row and column parameters.
                widgetRow      = row
                widgetColumn   = pmWidget.widgetColumn
                widgetSpanCols = 2
                widgetAlignment = PM_LABEL_LEFT_ALIGNMENT
                rowIncrement   = 1
                #no label
                labelRow       = 0
                labelColumn    = 0
                labelSpanCols  = 0
                labelAlignment = PM_LABEL_RIGHT_ALIGNMENT


            return widgetRow, \
               widgetColumn, \
               widgetSpanCols, \
               widgetAlignment, \
               rowIncrement, \
               labelRow, \
               labelColumn, \
               labelSpanCols, \
               labelAlignment


        label       = pmWidget.label
        labelColumn = pmWidget.labelColumn
        spanWidth   = pmWidget.spanWidth

        if not spanWidth:
            # This widget and its label are on the same row
            labelRow       = row
            labelSpanCols  = 1
            labelAlignment = PM_LABEL_RIGHT_ALIGNMENT
            # Set the widget's row and column parameters.
            widgetRow      = row
            widgetColumn   = 1
            widgetSpanCols = 1
            widgetAlignment = PM_LABEL_LEFT_ALIGNMENT
            rowIncrement   = 1

            if labelColumn == 1:
                widgetColumn   = 0
                labelAlignment = PM_LABEL_LEFT_ALIGNMENT
                widgetAlignment = PM_LABEL_RIGHT_ALIGNMENT

        else:

            # This widget spans the full width of the groupbox
            if label:
                # The label and widget are on separate rows.
                # Set the label's row, column and alignment.
                labelRow       = row
                labelColumn    = 0
                labelSpanCols  = 2

                # Set this widget's row and column parameters.
                widgetRow      = row + 1 # Widget is below the label.
                widgetColumn   = 0
                widgetSpanCols = 2

                rowIncrement   = 2
            else:  # No label. Just the widget.
                labelRow       = 0
                labelColumn    = 0
                labelSpanCols  = 0

                # Set the widget's row and column parameters.
                widgetRow      = row
                widgetColumn   = 0
                widgetSpanCols = 2
                rowIncrement   = 1

            labelAlignment = PM_LABEL_LEFT_ALIGNMENT
            widgetAlignment = PM_LABEL_LEFT_ALIGNMENT

        return widgetRow, \
               widgetColumn, \
               widgetSpanCols, \
               widgetAlignment, \
               rowIncrement, \
               labelRow, \
               labelColumn, \
               labelSpanCols, \
               labelAlignment

    def addPmWidget(self, pmWidget):
        """
        Add a PM widget and its label to this group box.

        @param pmWidget: The PM widget to add.
        @type  pmWidget: PM_Widget
        """

        # Get all the widget and label layout parameters.
        widgetRow, \
        widgetColumn, \
        widgetSpanCols, \
        widgetAlignment, \
        rowIncrement, \
        labelRow, \
        labelColumn, \
        labelSpanCols, \
        labelAlignment = \
            self.getPmWidgetPlacementParameters(pmWidget)

        if pmWidget.labelWidget:
            #Create Label as a pixmap (instead of text) if a valid icon path
            #is provided
            labelPath = str(pmWidget.label)
            if labelPath and labelPath.startswith("ui/"): #bruce 080325 revised
                labelPixmap = getpixmap(labelPath)
                if not labelPixmap.isNull():
                    pmWidget.labelWidget.setPixmap(labelPixmap)
                    pmWidget.labelWidget.setText('')

            self.gridLayout.addWidget( pmWidget.labelWidget,
                                       labelRow,
                                       labelColumn,
                                       1,
                                       labelSpanCols,
                                       labelAlignment )


        # The following is a workaround for a Qt bug. If addWidth()'s
        # <alignment> argument is not supplied, the widget spans the full
        # column width of the grid cell containing it. If <alignment>
        # is supplied, this desired behavior is lost and there is no
        # value that can be supplied to maintain the behavior (0 doesn't
        # work). The workaround is to call addWidget() without the <alignment>
        # argument. Mark 2007-07-27.

        if widgetAlignment == PM_LABEL_LEFT_ALIGNMENT:
            self.gridLayout.addWidget( pmWidget,
                                       widgetRow,
                                       widgetColumn,
                                       1,
                                       widgetSpanCols)
                                       # aligment = 0 doesn't work.
        else:
            self.gridLayout.addWidget( pmWidget,
                                       widgetRow,
                                       widgetColumn,
                                       1,
                                       widgetSpanCols,
                                       widgetAlignment
                                     )

        self._widgetList.append(pmWidget)

        self._rowCount += rowIncrement
        return

    def getRowCount(self):
        """
        Return the row count of gridlayout of L{PM_Groupbox}

        @return: The row count of L{self.gridlayout}
        @rtype: int
        """
        return self._rowCount

    def incrementRowCount(self, increment = 1):
        """
        Increment the row count of the gridlayout of L{PM_groupBox}
        @param increment: The incremental value
        @type  increment: int
        """
        self._rowCount += increment
        return

    def addQtWidget(self, qtWidget, column = 0, spanWidth = False):
        """
        Add a Qt widget to this group box.

        @param qtWidget: The Qt widget to add.
        @type  qtWidget: QWidget

        @warning: this method has not been tested yet.
        """
        # Set the widget's row and column parameters.
        widgetRow      = self._rowCount
        widgetColumn   = column
        if spanWidth:
            widgetSpanCols = 2
        else:
            widgetSpanCols = 1

        self.gridLayout.addWidget( qtWidget,
                                   widgetRow,
                                   widgetColumn,
                                   1,
                                   widgetSpanCols )

        self._rowCount += 1
        return

    def collapse(self):
        """
        Collapse this group box i.e. hide all its contents and change the look
        and feel of the groupbox button.
        """
        self.vBoxLayout.setMargin(0)
        self.vBoxLayout.setSpacing(0)
        self.gridLayout.setMargin(0)
        self.gridLayout.setSpacing(0)
        # The styleSheet contains the expand/collapse.
        styleSheet = self._getTitleButtonStyleSheet(showExpanded = False)
        self.titleButton.setStyleSheet(styleSheet)
        self._containerWidget.hide()
        self.expanded = False
        return

    def expand(self):
        """
        Expand this group box i.e. show all its contents and change the look
        and feel of the groupbox button.
        """
        self.vBoxLayout.setMargin(PM_GROUPBOX_VBOXLAYOUT_MARGIN)
        self.vBoxLayout.setSpacing(PM_GROUPBOX_VBOXLAYOUT_SPACING)
        self.gridLayout.setMargin(PM_GROUPBOX_GRIDLAYOUT_MARGIN)
        self.gridLayout.setSpacing(PM_GROUPBOX_GRIDLAYOUT_SPACING)

        # The styleSheet contains the expand/collapse.
        styleSheet = self._getTitleButtonStyleSheet(showExpanded = True)
        self.titleButton.setStyleSheet(styleSheet)
        self._containerWidget.show()
        self.expanded = True
        return

    def hide(self):
        """
        Hides the group box .

        @see: L{show}
        """
        QWidget.hide(self)
        if self.labelWidget:
            self.labelWidget.hide()

        # Change the spacer height to zero to "hide" it unless
        # self is the last GroupBox in the Property Manager.
        if self.parentWidget._lastGroupBox is self:
            return

        if self.verticalSpacer:
            self.verticalSpacer.changeSize(10, 0)
        return

    def show(self):
        """
        Unhides the group box.

        @see: L{hide}
        """
        QWidget.show(self)
        if self.labelWidget:
            self.labelWidget.show()

        if self.parentWidget._lastGroupBox is self:
            return

        if self.verticalSpacer:
            self.verticalSpacer.changeSize(10,
                                           self.verticalSpacer.defaultHeight)
        return

    # Title Button Methods #####################################

    def _getTitleButton(self,
                        parentWidget = None,
                        title        = '',
                        showExpanded = True ):
        """
        Return the group box title push button. The push button is customized
        such that it appears as a title bar at the top of the group box.
        If the user clicks on this 'title bar' it sends a signal to open or
        close the group box.

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

        @param title: The button title.
        @type  title: str

        @param showExpanded: dDetermines whether the expand or collapse image is
                             displayed on the title button.
        @type  showExpanded: bool

        @see: L{_getTitleButtonStyleSheet()}

        @Note: Including a title button should only be legal if the parentWidget
               is a PM_Dialog.
        """

        button  = QPushButton(title, parentWidget)
        button.setFlat(False)
        button.setAutoFillBackground(True)

        button.setStyleSheet(self._getTitleButtonStyleSheet(showExpanded))

        return button

    def _getTitleButtonStyleSheet(self, showExpanded = True):
        """
        Returns the style sheet for a group box title button (or checkbox).

        @param showExpanded: Determines whether to include an expand or
                             collapse icon.
        @type  showExpanded: bool

        @return: The title button style sheet.
        @rtype:  str
        """

        # Need to move border color and text color to top
        # (make global constants).
        if showExpanded:
            styleSheet = \
                       "QPushButton {"\
                       "border-style: outset; "\
                       "border-width: 2px; "\
                       "border-color: #%s; "\
                       "border-radius: 2px; "\
                       "background-color: #%s; "\
                       "font: bold 12px 'Arial'; "\
                       "color: #%s; "\
                       "min-width: 10em; "\
                       "background-image: url(%s); "\
                       "background-position: right; "\
                       "background-repeat: no-repeat; "\
                       "text-align: left; "\
                       "}" % (QColor_to_Hex(pmGrpBoxButtonBorderColor),
                              QColor_to_Hex(pmGrpBoxButtonColor),
                              QColor_to_Hex(pmGrpBoxButtonTextColor),
                              pmGrpBoxExpandedIconPath
                              )

        else:
            # Collapsed.
            styleSheet = \
                       "QPushButton {"\
                       "border-style: outset; "\
                       "border-width: 2px; "\
                       "border-color: #%s; "\
                       "border-radius: 2px; "\
                       "background-color: #%s; "\
                       "font: bold 12px 'Arial'; "\
                       "color: #%s; "\
                       "min-width: 10em; "\
                       "background-image: url(%s); "\
                       "background-position: right; "\
                       "background-repeat: no-repeat; "\
                       "text-align: left; "\
                       "}" % (QColor_to_Hex(pmGrpBoxButtonBorderColor),
                              QColor_to_Hex(pmGrpBoxButtonColor),
                              QColor_to_Hex(pmGrpBoxButtonTextColor),
                              pmGrpBoxCollapsedIconPath
                              )

        if _SUPPORT_QT_4point2:
            styleSheet = styleSheet.replace("text-align: left; ", "")

        return styleSheet

    def toggleExpandCollapse(self):
        """
        Slot method for the title button to expand/collapse the group box.
        """
        if self._widgetList:
            if self.expanded:
                self.collapse()
            else: # Expand groupbox by showing all widgets in groupbox.
                self.expand()
        else:
            print "Clicking on the group box button has no effect "\
                   "since it has no widgets."
        return

    # GroupBox stylesheet methods. ##############################

    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

        @return: The group box style sheet.
        @rtype:  str
        """

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

# End of PM_GroupBox ############################