summaryrefslogtreecommitdiff
path: root/cad/src/prototype/test_command_PMs.py
blob: d85c998d7c21a42bc6b476e5a5066747649d24a9 (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
# Copyright 2007-2008 Nanorex, Inc.  See LICENSE file for details.
"""
test_command_PMs.py - property manager classes for test_commands.py.
See that file for more info.

@version: $Id$
"""

from PM.PM_Dialog        import PM_Dialog
from PM.PM_GroupBox      import PM_GroupBox
from PM.PM_DoubleSpinBox import PM_DoubleSpinBox
from PM.PM_ComboBox      import PM_ComboBox

##from command_support.GeneratorBaseClass import GeneratorBaseClass

import time

class PM_Dialog_with_example_widgets( PM_Dialog):
    """
    [private] PM_Dialog with some PM widgets common to several examples here
    """
    # NOTE: contains some code copied (and perhaps modified) from AtomGeneratorDialog.py

    # these class constants should be defined by each specific PM subclass
    # (we don't define them here, since we want errors to occur if you don't override them)
    #   title = "title"
    #   pmName = "pm" + title
    #   iconPath = "path-to-some-icon.png"

    #k all needed?
    _sMinCoordinateValue   = -30.0
    _sMaxCoordinateValue   =  30.0
    _sStepCoordinateValue  =  0.1
    _sCoordinateDecimals   =  4
    _sCoordinateUnit       =  'Angstrom'
    _sCoordinateUnits      =  _sCoordinateUnit + 's'
    _sElementSymbolList    =  ["H","O","C","S"]

    def __init__(self):
        PM_Dialog.__init__( self, self.pmName, self.iconPath, self.title )

        msg = "Example command created at %s" % time.asctime()

        # This causes the "Message" box to be displayed as well.
        self.MessageGroupBox.insertHtmlMessage( msg, setAsDefault = False )
        return

    def _addGroupBoxes(self):
        """
        Add group boxes to this Property Manager.
        """
        self.pmGroupBox1 = PM_GroupBox( self, title =  "Atom Parameters" )
        self._loadGroupBox1(self.pmGroupBox1)
        return

    def _loadGroupBox1(self, inPmGroupBox):
        """
        Load widgets into group box 1.
        """

        # User input to specify what type of element/atom to generate
        elementComboBoxItems  =  self._sElementSymbolList
        self.elementComboBox  =  \
            PM_ComboBox( inPmGroupBox,
                         label         =  "Elements :",
                         choices       =  elementComboBoxItems,
                         index         =  0,
                         setAsDefault  =  True,
                         spanWidth     =  False )

        # User input to specify x-coordinate
        # of the generated atom's position.
        self.xCoordinateField  =  \
            PM_DoubleSpinBox( inPmGroupBox,
                              label         =  "x :",
                              value         =  0.0,
                              setAsDefault  =  True,
                              minimum       =  self._sMinCoordinateValue,
                              maximum       =  self._sMaxCoordinateValue,
                              singleStep    =  self._sStepCoordinateValue,
                              decimals      =  self._sCoordinateDecimals,
                              suffix        =  ' ' + self._sCoordinateUnits )
        return

    def _addWhatsThisText(self):
        """
        What's This text for some of the widgets in the Property Manager.
        """

        self.xCoordinateField.setWhatsThis("<b>x</b><p>: The x-coordinate (up to </p>"
                                           + str( self._sMaxCoordinateValue )
                                           + self._sCoordinateUnits
                                           + ") of the Atom in "
                                           + self._sCoordinateUnits + '.')
    pass # end of class PM_Dialog_with_example_widgets

# ==

class ExampleCommand1_PM( PM_Dialog_with_example_widgets): # these supers are needed (but 'object' is evidently not needed)
    """
    Property Manager for Example Command 1 -- simplest that doesn't use GBC; buttons are noops
    """
    # <title> - the title that appears in the property manager header.
    title = "Example Command 1"
    # <pmName> - the name of this property manager. This will be set to
    # the name of the PropMgr (this) object via setObjectName(). ###k used only for debugging??
    pmName = "pm" + title
    # <iconPath> - full path to PNG file that appears in the header.
    iconPath = "ui/actions/Commands Toolbar/BuildAtoms/InsertAtom.png" ###e REVISE

    # bruce added these to make it work w/o GBC.
    # (It doesn't need restore_defaults_btn_clicked because PropMgrBaseClass defines that itself.
    #  So does GBC, but to a noop method. So GBC better be inherited *after* PropMgrBaseClass!)

    def ok_btn_clicked(self):
        print "ok_btn_clicked, doing Done in", self.command
        self.command.command_Done()
        pass

    def cancel_btn_clicked(self):
        print "cancel_btn_clicked, doing Cancel in", self.command
        self.command.command_Cancel()
        pass

    def preview_btn_clicked(self):
        print "preview_btn_clicked (noop or nim, I think)", self
        pass

    def __init__(self, command = None):
        # removed win argument, get it from command [bruce 080910]
        win = command.win
        print "creating", self ####
        self.command = command #bruce 080909 renamed commandrun -> command, in all classes in package prototype

        PM_Dialog_with_example_widgets.__init__( self ) ## ok before the next line? @@@
        if 1: # bruce added these, otherwise various AttributeErrors [still true??]
            self.win = win # needed in PropMgrBaseClass.show
            self.pw = win.activePartWindow() # same
        return

    pass # end of class ExampleCommand1_PM

##class ExampleCommand2_PM( PM_Dialog_with_example_widgets, GeneratorBaseClass):
##    """
##    Property Manager for Example Command 2 -- simplest that uses GBC; generates a comment (ignores widget values)
##    """
##
##    title = "Example Command 2"
##    pmName = "pm" + title
##    iconPath = "ui/actions/Command Toolbar/BuildAtoms/InsertAtom.png" #e REVISE
##
##    # need these, at least to use Done:
##    prefix = "Thing2" # for names created by GBC [required when create_name_from_prefix is true (not sure about otherwise)]
##    cmdname = "Generate a Thing2" # Undo/history cmdname used by GBC [optional, but affects history messages]
##
##    def __init__(self, win, command = None):
##        print "creating", self ####
##        self.command = command
##
##        PM_Dialog_with_example_widgets.__init__( self )
##        GeneratorBaseClass.__init__( self, win)
##        return
##
##    def gather_parameters(self): ###REVIEW: the exception from this gets printed but not as a traceback...
##        return (1,2) ###e not yet grabbed from the widgets
##
##    def build_struct(self, name, params, position):
##        """
##        ... The return value should be the new structure, i.e. some flavor of a Node,
##        which has not yet been added to the model. ...
##           By convention ... the new node's name should be set to self.name,
##        which the caller will have set to self.prefix appended with a serial number.
##        """
##        print "build_struct(", self, name, params, position, ")"###
##        assert self.name == name # true by test and by examining GBC code
##        # ignoring params and position for now
##        assy = self.win.assy
##        from model.Comment import Comment
##        return Comment(assy, name, "comment created at " + time.asctime())
##
##    #e bugs that remain:
##    # - widget values not used for creating the thing
##    # - preview for comment is not visible except in MT tab or history
##    # - restore defaults does nothing useful
##    # - whats this button does nothing
##    # - when we leave this PM, the PM tab remains, tho it's empty
##
##    def ok_btn_clicked(self):
##        print "ok_btn_clicked, doing super then Done (kluge)", self
##        GeneratorBaseClass.ok_btn_clicked(self)
##        self.command.command_Done() ###k both command and Done -- and, kluge, instead GBC should call a done method in self.command
##        pass
##    def cancel_btn_clicked(self):
##        print "cancel_btn_clicked, doing super then Done (kluge)", self
##        GeneratorBaseClass.cancel_btn_clicked(self)
##        self.command.command_Done() #update 2008-09-26: should this be command_Cancel()? [-- Ninad]
##        pass
##
##    pass # end of class ExampleCommand2_PM

# end