summaryrefslogtreecommitdiff
path: root/cad/src/command_support/Command_PropertyManager.py
blob: ac53991ee2a24420d4a23c721c9374aaefc2b071 (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
# Copyright 2007-2008 Nanorex, Inc.  See LICENSE file for details.
"""
This is a superclass for the property managers of various command objects

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

History:
2008-10-01 : Created this to make it a common superclass of all command PMs
Moved common code from EditCommand_PM to here.

TODO as of 2008-10-01
- get rid of "not KEEP_SIGNALS_CONNECTED"  case
- revise/ remove self.enable_or_disable_gui_actions() completely
"""
from PM.PM_Dialog import PM_Dialog
from utilities.exception_classes import AbstractMethod
#debug flag to keep signals always connected
from utilities.GlobalPreferences import KEEP_SIGNALS_ALWAYS_CONNECTED
from utilities.Comparison import same_vals

_superclass = PM_Dialog

class Command_PropertyManager(PM_Dialog):
    """
    This is a superclass for the property managers of various command objects
    @see: B{PlanePropertyManager} as an example
    @see: B{PM_Dialog}
    """
    # The title that appears in the Property Manager header.
    title = "Property Manager"
    # The name of this Property Manager. This will be set to
    # the name of the PM_Dialog object via setObjectName().
    pmName = title
    # The relative path to the PNG file that appears in the header
    iconPath = ""

    def __init__(self, command):
        """
        Constructor for Command_PropertyManager.
        """
        self.command = command
        self.win = self.command.win
        self.w = self.win
        self.pw = self.command.pw
        self.o = self.win.glpane

        _superclass.__init__(self, self.pmName, self.iconPath, self.title)

        if KEEP_SIGNALS_ALWAYS_CONNECTED:
            self.connect_or_disconnect_signals(True)


    def show(self):
        """
        Shows the Property Manager. Extends superclass method.
        """
        _superclass.show(self)

        if not KEEP_SIGNALS_ALWAYS_CONNECTED:
            self.connect_or_disconnect_signals(True)

        self.enable_or_disable_gui_actions(bool_enable = False)


    def close(self):
        """
        Closes the Property Manager. Extends superclass method.
        """
        if not KEEP_SIGNALS_ALWAYS_CONNECTED:
            self.connect_or_disconnect_signals(False)

        self.enable_or_disable_gui_actions(bool_enable = True)
        _superclass.close(self)


    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        This can be overridden in subclasses. By default it does nothing.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean
        """
        pass

    def enable_or_disable_gui_actions(self, bool_enable = False):
        """
        Enable or disable some gui actions when this property manager is
        opened or closed, depending on the bool_enable.
        Subclasses can override this method.
        """
        pass


    def update_UI(self):
        """
        Update whatever is shown in this PM based on current state
        of the rest of the system, especially the state of self.command
        and of the model it shows.

        This method SHOULD NOT BE overridden in subclasses. Instead override the
        submethods '_update_UI_check_change_indicators' and
        '_update_UI_do_updates'
        """
        anything_changed = self._update_UI_check_change_indicators()

        if not anything_changed:
            return

        self._update_UI_do_updates()
        return

    def _update_UI_check_change_indicators(self):
        """
        This method does a basic check to see if something in the assembly
        changed since last call of this method.
        It compares various change indicators defined in assembly class against
        an attribute of this class. This class attr stores the previous values
        of all these change indicators when it was last called.

        @see: self.update_UI()
        """
        current_change_indicators = (self.win.assy.model_change_indicator(),
                              self.win.assy.selection_change_indicator(),
                              self.win.assy.command_stack_change_indicator())

        if same_vals(current_change_indicators,
                     self._previous_all_change_indicators):
            return False

        self._previous_all_change_indicators = current_change_indicators
        return True

    def _update_UI_do_updates(self):
        """
        Subclasses must override this method to do the actual updates.
        """
        pass


    def _addGroupBoxes(self):
        """
        Add various group boxes to this PM.
        Abstract method.
        """
        raise AbstractMethod()

    def _addWhatsThisText(self):
        """
        Add what's this text.
        Abstract method.
        """
        raise AbstractMethod()