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

The PM_PreviewGroupBox widget provides a preview pane for previewing
elements , clipboard items , library parts etc. from the element chooser
or list provided in the property manager. (The object being previewed can
then be deposited into the 3D workspace.)

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

History:
ninad 2007-08-29: Created.
"""

from PyQt4.Qt         import QSize
from graphics.widgets.ThumbView import MMKitView
from PM.PM_GroupBox   import PM_GroupBox

class PM_PreviewGroupBox(PM_GroupBox):
    """
    The PM_PreviewGroupBox widget provides a preview pane for previewing
    elements , clipboard items , library parts etc. from the element chooser
    or list provided in the property manager. (The object being previewed can
    then be deposited into the 3D workspace.)
    """
    elementViewer = None
    def __init__(self,
                 parentWidget,
                 glpane = None,
                 title = 'Preview'
                 ):
        """
        Appends a PM_PreviewGroupBox widget to I{parentWidget},a L{PM_Dialog}

        @param parentWidget: The parent dialog (Property manager) containing
                             this  widget.
        @type  parentWidget: L{PM_Dialog}

        @param glpane: GLPane object used in construction of the
                       L{self.elementViewer}
        @type  glpane: L{GLPane} or None

        @param title: The title (button) text.
        @type  title: str

        """
        PM_GroupBox.__init__(self, parentWidget, title)

        self.glpane = glpane
        self.parentWidget = parentWidget
        self._loadPreviewGroupBox()

    def _loadPreviewGroupBox(self):
        """
        Load the L{self.elementViewer} widget inside this preview groupbox.
        @attention: The L{self.elementViewer} widget is added to
                    L{self.previewGroupBox.gridLayout} in L{Thumbview.__init__}.
                    Based on  tests, it takes longer cpu time to complete this
                    operation (adding QGLWidget to a gridlayout. By doing this
                    inside L{Thumbview.__init__}, a time gain of ~ 0.1 sec
                    was noticed on Windows XP.
        """

        self.elementViewer = MMKitView(
                        self,
                        "MMKitView glPane",
                        self.glpane)
        self.elementViewer.setMinimumSize(QSize(150, 150))

        self.gridLayout.setMargin(0)
        self.gridLayout.setSpacing(0)
        #Append to the widget list. This is important for expand - collapse
        #functions (of the groupbox) to work properly.
        self._widgetList.append(self.elementViewer)
        ##self.previewGroupBox.gridLayout.addWidget(self.elementViewer,
        ##                                          0, 0, 1, 1)


    def expand(self):
        """
        Expand this group box i.e. show all its contents and change the look
        and feel of the groupbox button. It also sets the gridlayout margin and
        spacing to 0. (necessary to get rid of the extra space inside the
        groupbox.)

        @see: L{PM_GroupBox.expand}
        """
        PM_GroupBox.expand(self)
        self.gridLayout.setMargin(0)
        self.gridLayout.setSpacing(0)