-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_designer_menu.py
234 lines (226 loc) · 7.98 KB
/
class_designer_menu.py
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
# -*- coding: utf-8 -*-
import sys
from dabo import events
from dabo.localization import _
from dabo.ui import dMenu
def mkDesignerMenu(parent, target=None):
"""This creates a common menu for all forms in the ClassDesigner. The two
parameters refer to the parent of the menu (i.e., the form to which the
menu is being attached. If this is a child of the main ClassDesigner form, the
second parameter is a reference to that form, which contains the code
that the menus will be bound to.
"""
if target is None:
target = parent
try:
mb = parent.MenuBar
except AttributeError:
mb = None
if mb:
app = target.Controller
fm = mb.fileMenu
em = mb.editMenu
vm = mb.viewMenu
app.barShowPropSheet = vm.append(
("Hide Object Info Form"),
OnHit=app.onTogglePropSheet,
ItemID="view_objinfo",
help=_("Show/hide the Object Info form"),
)
app.barShowEditor = vm.append(
("Hide Code Editor"),
OnHit=app.onToggleEditor,
ItemID="view_codeeditor",
help=_("Show/hide the Code Editor"),
)
app.barShowPalette = vm.append(
("Show Tool Palette"),
OnHit=app.onTogglePalette,
ItemID="view_toolpalette",
help=_("Show/hide the Tool Palette"),
)
app.barShowSizerPalette = vm.append(
("Show Sizer Palette"),
OnHit=app.onToggleSizerPalette,
ItemID="view_sizerpalette",
help=("Show/hide the Sizer Palette"),
)
# Add some hotkeys for displaying the various PemObject panels
vm.appendSeparator()
vm.append(
("Display Properties"),
HotKey="Ctrl+Shift+P",
OnHit=app.onShowProp,
ItemID="view_properties",
help=("Display the property editing page"),
)
vm.append(
("Display Object Tree"),
HotKey="Ctrl+Shift+O",
OnHit=app.onShowObjTree,
ItemID="view_objecttree",
help=("Display the object tree page"),
)
vm.append(
_("Display Methods"),
HotKey="Ctrl+Shift+M",
OnHit=app.onShowMethods,
ItemID="view_methods",
help=("Display the method selection page"),
)
vm.append(
_("Select Prior Object"),
HotKey="Ctrl+PgUp",
OnHit=app.onPriorObj,
ItemID="view_priorobj",
help=("Select the object on the previous node of the object tree"),
)
vm.append(
("Select Next Object"),
HotKey="Ctrl+PgDn",
OnHit=app.onNextObj,
ItemID="view_nextobj",
help=("Select the object on the next node of the object tree"),
)
# Add a separator and the 'Run...' item after the
# Open/Save items. Since we are prepending, we need
# to prepend them in reverse order.
fm.prependSeparator()
fm.prepend(
_("&Run..."),
HotKey="Ctrl+Shift+R",
OnHit=app.onRunDesign,
ItemID="file_run",
help=_("Test your design by running the form"),
)
fm.prependSeparator()
fm.prepend(
_("Revert to Saved"),
OnHit=app.onRevert,
ItemID="file_revert",
help=_("Re-load the form from disk, losing any pending changes"),
)
fm.prepend(
_("Save Runnable App"),
OnHit=app.onSaveRunnable,
ItemID="file_saverunnable",
help=_("Create a mini app to run your form"),
)
fm.prependSeparator()
itm = fm.prepend(
_("&Import Declarations..."),
HotKey="Ctrl-I",
OnHit=app.onDeclareImports,
ItemID="file_import",
help=_("Edit the import statements for the code for this class"),
)
itm = fm.prepend(
_("Single &File for Layout and Code"),
OnHit=app.onToggleSaveType,
ItemID="file_singlefile",
help=_("Toggle whether you want code saved in the XML or in a separate file"),
menutype="check",
)
itm.Checked = target.Application.getUserSetting("saveCodeInXML", False)
itm = fm.prepend(
_("Save as C&lass"),
HotKey="Ctrl+Shift+S",
OnHit=app.onSaveClassDesign,
ItemID="file_saveasclass",
help=_("Save the ClassDesigner contents as a class"),
)
itm.DynamicEnabled = app.shouldEnableSaveAsClass
fm.prepend(
_("Save &As..."),
HotKey="Ctrl+Shift+V",
OnHit=app.onSaveAsDesign,
ItemID="file_saveas",
help=_("Save the ClassDesigner contents in a new file"),
)
fm.prepend(
_("&Save"),
HotKey="Ctrl+S",
OnHit=app.onSaveDesign,
ItemID="file_save",
help=_("Save the ClassDesigner contents as a form"),
)
fm.prepend(
_("&Edit Text File..."),
HotKey="Ctrl+E",
OnHit=app.onEditTextFile,
ItemID="file_edit_textfile",
help=_("Open a text file for editing"),
)
recent = dMenu(Caption=_("Open Recent"), MenuID="file_open_recent", MRU=True)
fm.prependMenu(recent)
fm.prepend(
_("&Open"),
HotKey="Ctrl+O",
OnHit=app.onOpenDesign,
ItemID="file_open",
help=_("Open a saved design file"),
)
fm.prepend(
_("&New Class..."),
HotKey="Ctrl+N",
OnHit=app.onNewDesign,
ItemID="file_new",
help=_("Create a new design file"),
)
alignMenu = dMenu(Caption=_("Align"), MenuID="base_align")
itm = alignMenu.append(
_("Align Top Edges"),
OnHit=app.onAlignTopEdge,
ItemID="align_top",
help=_("Align controls by their top edge"),
)
itm.DynamicEnabled = app.shouldEnableAlignControls
itm = alignMenu.append(
_("Align Bottom Edges"),
OnHit=app.onAlignBottomEdge,
ItemID="align_bottom",
help=_("Align controls by their bottom edge"),
)
itm.DynamicEnabled = app.shouldEnableAlignControls
itm = alignMenu.append(
_("Align Left Edges"),
OnHit=app.onAlignLeftEdge,
ItemID="align_left",
help=_("Align controls by their left edge"),
)
itm.DynamicEnabled = app.shouldEnableAlignControls
itm = alignMenu.append(
_("Align Right Edges"),
OnHit=app.onAlignRightEdge,
ItemID="align_right",
help=_("Align controls by their right edge"),
)
itm.DynamicEnabled = app.shouldEnableAlignControls
itm = alignMenu.append(
_("Bring to Front"),
OnHit=app.onBringToFront,
ItemID="align_bringtofront",
help=_("Move control to the top of the visible stack"),
)
itm.DynamicEnabled = app.shouldEnableZOrdering
itm = alignMenu.append(
_("Send to Back"),
OnHit=app.onSendToBack,
ItemID="align_sendtoback",
help=_("Move control to the bottom of the visible stack"),
)
itm.DynamicEnabled = app.shouldEnableZOrdering
emCnt = len(em.Children)
em.insertMenu(emCnt - 1, alignMenu)
# alignMenu.DynamicEnabled = app.shouldEnableAlignMenu
try:
isMain = parent._isMain
except:
isMain = False
if isMain:
cm = mb.append(_("Controls"))
ctlList = [(ct["order"], ct["name"]) for ct in app.designerControls]
ctlList.sort()
for ctl in ctlList:
itm = cm.append(ctl[1], OnHit=parent.onAddControl)
itm.DynamicEnabled = app.shouldEnableAddControl