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

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

History:

ninad 2007-08-14: Created.
"""

from PyQt4.Qt import QFont

from PM.PM_WidgetGrid import PM_WidgetGrid


class PM_LabelGrid( PM_WidgetGrid ):
    """
    The PM_LabelGrid widget (a groupbox) provides a grid of labels arranged in
    the  grid layout of the PM_LabelGrid

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

    """

    def __init__(self,
                 parentWidget,
                 title     = '',
                 labelList = [],
                 alignment = None,
                 isBold    = False
                 ):
        """
        Appends a PM_LabelGrid widget ( a groupbox) to the bottom of I{parentWidget},
        the Property Manager 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 labelList: A list of I{label info lists}. There is one label
                           info list for each label in the grid. The label
                           info list contains the following items:
                           1. Widget Type - in this case its 'Label'(str),
                           2. Label text (str),
                           3. Column (int),
                           4. Row (int).
        @type  labelList: list
        """

        self.isBold = isBold

        #Empty list that will contain all the labels in this widget.
        self.labels = []

        PM_WidgetGrid.__init__(self,
                               parentWidget ,
                               title,
                               labelList,
                               alignment)

    def _createWidgetUsingParameters(self, widgetParams):
        """
        Returns a label created using the parameters specified by the user

        @param widgetParams: A list of label parameters. This is a modified
                             using the original list returned
                             by L{self.getWidgetInfoList}. The modified list
                             doesn't contain the row and column information.
        @type  widgetParams: list
        @see:  L{PM_WidgetGrid._createWidgetUsingParameters} (overrided in this
               method)
        @see:  L{PM_WidgetGrid.loadWidgets} which calls this method.

        """
        labelParams  = list(widgetParams)
        label = self._createLabel(labelParams)
        labelFont = self.getLabelFont(self.isBold)
        label.setFont(labelFont)
        label.setUpdatesEnabled(True)
        self.labels.append(label)
        return label


    def getLabelFont(self, isBold = False):
        """
        Returns the font for the labels in the grid
        """
        # Font for labels.
        labelFont = QFont(self.font())
        labelFont.setBold(False)
        return labelFont

    def setBold(self, isBold = True):
        """
        Sets or unsets font of all labels in this widget to bold
        @param isBold: If true, sets the font of all labels in the widget to
                       bold.
        @type  isBold: bool
        @see:  B{MovePropertyManager.updateRotationDeltaLabels} for an example
               on how this function is used.
        """

        for label in self.labels:
            font = QFont(label.font())
            font.setBold(isBold)
            label.setFont(font)