forked from lmbelo/python4delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit1.lfm
More file actions
476 lines (476 loc) · 18.3 KB
/
Copy pathUnit1.lfm
File metadata and controls
476 lines (476 loc) · 18.3 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
object Form1: TForm1
Left = 659
Height = 647
Top = 47
Width = 685
VertScrollBar.Range = 210
ActiveControl = Memo1
Caption = 'Form1'
ClientHeight = 647
ClientWidth = 668
Color = clBtnFace
Font.Color = clWindowText
Font.Height = 11
Font.Name = 'MS Sans Serif'
Font.Pitch = fpVariable
OnCreate = FormCreate
LCLVersion = '0.9.30.2'
Visible = True
object Splitter1: TSplitter
Cursor = crVSplit
Left = 0
Height = 3
Top = 169
Width = 668
Align = alTop
ResizeAnchor = akTop
end
object Memo1: TMemo
Left = 0
Height = 434
Top = 172
Width = 668
Align = alClient
Lines.Strings = (
'from spam import DelphiVersion, MainForm, DVar, CreateComponent, Application, Screen, mrOk, Form, Button, CheckBox, caFree'
'from spam import Point, Monitor, DrawGrid, gdSelected, clBlue, ssCtrl, PageControl, TabSheet'
'if DelphiVersion >= 6:'
' from spam import mdNearest'
'import unittest'
'import sys'
'py_major, py_minor = sys.version_info[:2]'
''
'class MyForm(Form):'
' def __init__(self, Owner):'
' self.Caption = ''Subclassed form'''
' self.btnClose = Button(self)'
' self.btnClose.Parent = self'
' self.btnClose.Caption = ''Close'''
' self.btnClose.SetBounds(10, 10, 120, 30)'
' self.btnClose.OnClick = self.btnCloseClick'
''
' self.chkCanClose = CheckBox(self)'
' self.chkCanClose.Parent = self'
' self.chkCanClose.Caption = ''Can close?'''
' self.chkCanClose.SetBounds(10, 50, 120, 30)'
''
' self.grdTest = DrawGrid(self)'
' self.grdTest.Parent = self'
' self.grdTest.SetBounds(10, 100, 300, 250)'
' self.grdTest.OnDrawCell = self.grdTestDrawCell'
' self.grdTest.OnSelectCell = self.grdTestSelectCell'
''
' self.OnCloseQuery = self.MyFormCloseQuery'
' self.OnClose = self.MyFormClose'
' self.Width = 400'
' self.Height = 400'
''
' def btnCloseClick(self, Sender):'
' print("Close!")'
' self.Close()'
''
' def MyFormCloseQuery(self, Sender, CanClose):'
' CanClose.Value = self.chkCanClose.Checked'
''
' def MyFormClose(self, Sender, Action):'
' Action.Value = caFree'
''
' def grdTestDrawCell(self, Sender, Col, Row, Rect, State):'
' if gdSelected in State:'
' Sender.Canvas.Brush.Color = clBlue # 0x00ff0000 # blue'
' print("Cell[%d, %d] is selected, Rect=%s, State=%s" % (Col, Row, Rect, State))'
' Sender.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, "%d @ %d" % (Col, Row))'
''
' def grdTestSelectCell(self, Sender, Col, Row, CanSelect):'
' if Col == 2 and Row == 2:'
' CanSelect.Value = False'
''
'class TTestForm(Form):'
' def __init__(self, Owner):'
' self.Caption = self.Caption + '' - changed by Python subclass'''
' self.BindMethodsToEvents()'
''
' def handle_btnAdd_OnClick(self, Sender):'
' self.ListBox1.Items.Add(self.Edit1.Text)'
''
'class TestDelphiWrapper(unittest.TestCase):'
''
' def testReadWriteProperties(self):'
' DVar.SValue = ''Weight'''
' self.assertEqual(DVar.SValue, ''Weight'')'
' DVar.IValue = 70'
' self.assertEqual(DVar.IValue, 70)'
' MainForm.Caption = ''PyDelphi rocks!'' #setting properties'
' self.assertEqual(MainForm.Caption, ''PyDelphi rocks!'')'
' print()'
' print(''MainForm.ActiveControl='', MainForm.ActiveControl # class properties)'
' MainForm.BorderStyle = ''bsSizeable'' #enumeration property'
' MainForm.Anchors = [''akTop'', ''akLeft''] #set property'
' self.assertEqual(MainForm.Anchors, [''akTop'', ''akLeft''])'
''
' def testTObject(self):'
' self.assertEqual(MainForm.ClassName, ''TForm1'')'
' self.assert_(MainForm.InheritsFrom(''TObject''))'
''
' def testMethodCall(self):'
' if DelphiVersion >= 7:'
' DVar.SetMeUp(''Age'', 25)'
' self.assertEqual(DVar.SValue, ''Age'')'
' self.assertEqual(DVar.IValue, 25)'
' print()'
' print(DVar.DescribeMe() #method calls)'
''
' def testRepr(self):'
' print()'
' print(''Representation of Delphi objects'')'
' print(DVar)'
' print(MainForm)'
' if DelphiVersion >= 7:'
' print(DVar.DescribeMe # method object)'
' print(DVar.SL # TStrings)'
''
' def testTStrings(self):'
' SL = DVar.SL'
' self.assertEqual(len(SL), 2)'
' print()'
' for i in DVar.SL: print(i, '' contains '', DVar.SL[i])'
' SL.Add(''New String'')'
' self.assertEqual(len(SL), 3)'
' self.assertEqual(SL.IndexOf(''New String''), 2)'
' self.assertEqual(SL[0], ''Form1'')'
' self.assertEqual(SL.Objects[0], MainForm)'
' self.assertEqual(MainForm in SL.Objects, True)'
' SL[2] = ''Changed'''
' self.assertEqual(SL[2], ''Changed'')'
' self.assertEqual(SL.Objects[2], None)'
' SL.Objects[2] = MainForm'
' self.assertEqual(SL.Objects[2], MainForm)'
' self.assertEqual(MainForm in SL.Objects, True)'
' SL.Delete(2)'
' self.assertEqual(len(SL), 2)'
' print("str(SL) =", str(SL))'
' SL.Assign([1, 2, 3])'
' self.assertEqual(len(SL), 3)'
' self.assertEqual(''2'' in SL, True)'
' self.assertEqual(SL[1], ''2'')'
' tmp = [''a'', ''b'', ''c'']'
' SL.Assign(tmp)'
' self.assertEqual(SL.ToList(), tmp)'
' tmp = (''a'', ''b'', ''c'')'
' SL.Assign(tmp)'
' self.assertEqual(SL.ToTuple(), tmp)'
''
' def testTComponent(self):'
' self.assertEqual(MainForm.Name, ''Form1'')'
' count = MainForm.ComponentCount'
' def SetComponentCount():'
' MainForm.ComponentCount = 3'
' if py_major == 2 and py_minor < 5:'
' self.assertRaises(TypeError, SetComponentCount)'
' else:'
' self.assertRaises(AttributeError, SetComponentCount)'
' self.assertEquals(MainForm.__owned__, False)'
''
' def testSubComponents(self):'
' MainForm.Button1.Caption = ''Click me!!'''
' self.assertEqual(MainForm.Button1.Caption, ''Click me!!'')'
' # test alternate mapping notation'
' MainForm[''Button1''].Caption = ''Click me!!!!'''
' self.assertEqual(MainForm[''Button1''].Caption, ''Click me!!!!'')'
' self.assertEqual(MainForm.Button1.Caption, ''Click me!!!!'')'
' # Test Owner property and DelphiObject comparison'
' self.assert_(MainForm.Button1.Owner == MainForm)'
' print([i.Name for i in MainForm.Components])'
''
' def testCreateComponent(self):'
' NewButton = CreateComponent(''TButton'', None)'
' self.assertEquals(NewButton.__bound__, True)'
' self.assertEquals(NewButton.__owned__, True)'
' NewButton.Free()'
' self.assertEquals(NewButton.__bound__, False)'
''
' def testWinControls(self):'
' self.assertEqual(MainForm.Panel1.Parent, MainForm)'
' print()'
' print(''MainForm contains '', MainForm.ControlCount, '' controls'')'
' print([i.Name for i in MainForm.Controls])'
''
' def testForm(self):'
' MyForm = CreateComponent(''TForm'', None)'
' MyForm.Name = ''MyForm'''
' MyForm.Caption = ''Python Generated Form'''
' MyForm.Height = 300'
' MyForm.Width = 310'
' MyForm.Position = ''poDefaultPosOnly'''
' PC = PageControl(MyForm)'
' PC.Name = "MyPageControl"'
' PC.Parent = MyForm'
' PC.Align = "alClient"'
' P1 = TabSheet(MyForm)'
' P1.PageControl = PC'
' P1.Caption = "Page 1"'
' LB = CreateComponent(''TListBox'', MyForm)'
' B1 = CreateComponent(''TButton'', MyForm)'
' B2 = CreateComponent(''TButton'', MyForm)'
' Edit = CreateComponent(''TEdit'', MyForm)'
' LB.Name = ''ListBox1'''
' LB.Parent = P1'
' LB.Left = 20'
' LB.Top = 14'
' LB.Width = 121'
' LB.Height = 97'
' LB.TabOrder = 0'
' B1.Name = ''Button1'''
' B1.Parent = P1'
' B1.Left = 185'
' B1.Top = 60'
' B1.Width = 75'
' B1.Height = 25'
' B1.Caption = ''Add to list'''
' B1.TabOrder = 1'
' Edit.Name = ''Edit1'''
' Edit.Parent = P1'
' Edit.Left = 168'
' Edit.Top = 27'
' Edit.Width = 121'
' Edit.Height = 21'
' Edit.TabOrder = 2'
' Edit.Text = ''Add me to List'''
' B2.Name = ''Button2'''
' B2.Parent = P1'
' B2.Left = 121'
' B2.Top = 125'
' B2.Width = 75'
' B2.Height = 25'
' B2.Caption = ''Close'''
' B2.ModalResult = mrOk'
' B2.TabOrder = 3'
' def ClickHandler(Sender):'
' print(Sender.Name, '' was clicked'')'
' LB.Items.Add(Edit.Text)'
' B1.OnClick = ClickHandler'
' def KeyPressHandler(Sender, Key):'
' if Key.Value == ''a'':'
' Key.Value = ''z'''
' Edit.OnKeyPress = KeyPressHandler'
' def KeyDownHandler(Sender, Key, Shift):'
' # forbid Ctrl+Home'
' if Key.Value == 36 and ssCtrl in Shift:'
' Key.Value = 0'
' Edit.OnKeyDown = KeyDownHandler'
' BtnNextPage = Button(MyForm)'
' BtnNextPage.Parent = P1'
' BtnNextPage.SetBounds(10, 200, 150, 24)'
' BtnNextPage.Caption = "Select Next Page"'
' def NextPageClick(Sender):'
' Sender.Owner.MyPageControl.SelectNextPage(True, True)'
' BtnNextPage.OnClick = NextPageClick'
' P2 = TabSheet(MyForm)'
' P2.PageControl = PC'
' P2.Caption = "Page 2"'
' BtnGotoPage3 = Button(MyForm)'
' BtnGotoPage3.Parent = P2'
' BtnGotoPage3.SetBounds(10, 10, 150, 24)'
' BtnGotoPage3.Caption = "Goto Page 3"'
' def GotoPage3Click(Sender):'
' Sender.Owner.MyPageControl.ActivePage = Sender.Owner.Page3'
' BtnGotoPage3.OnClick = GotoPage3Click'
''
' P3 = TabSheet(MyForm)'
' P3.PageControl = PC'
' P3.Caption = "Page 3"'
' P3.Name = "Page3"'
' BtnGotoFirstPage = Button(MyForm)'
' BtnGotoFirstPage.Parent = P3'
' BtnGotoFirstPage.SetBounds(10, 10, 150, 24)'
' BtnGotoFirstPage.Caption = "Goto First Page"'
' def GotoFirstPageClick(Sender):'
' PC.ActivePageIndex = 0'
' BtnGotoFirstPage.OnClick = GotoFirstPageClick'
' chkAllowChange = CheckBox(MyForm)'
' chkAllowChange.Parent = P3'
' chkAllowChange.SetBounds(10, 40, 150, 24)'
' chkAllowChange.Caption = "Allow Page Change?"'
' chkAllowChange.Checked = True'
''
' def PCChanging(Sender, AllowChange):'
' AllowChange.Value = chkAllowChange.Checked'
' PC.OnChanging = PCChanging'
''
' MyForm.ShowModal()'
''
' def testFormSubclass(self):'
' f = MyForm(Application)'
' try:'
' print(f.ShowModal())'
' finally:'
' f.Free()'
''
' def testFormSubclass2(self):'
' f = TTestForm(Application)'
' try:'
' print(f.ShowModal())'
' finally:'
' f.Free()'
''
' def testPointConversions(self):'
' p1 = Point(10, 10)'
' p = MainForm.ClientToScreen(p1)'
' print(p)'
' p2 = MainForm.ScreenToClient(p)'
' self.assertEqual(p2.X, p1.X)'
' self.assertEqual(p2.Y, p1.Y)'
''
' def testObjectNotification(self):'
' DVar.IValue = 0'
' def ChangeHandler(Sender):'
' print(Sender)'
' Sender.IValue = 55'
' DVar.OnChange = ChangeHandler'
' if DelphiVersion >= 7:'
' DVar.TriggerChange()'
' self.assertEqual(DVar.IValue, 55)'
' DVar.OnChange = None'
' DVar.IValue = 0'
' DVar.TriggerChange()'
' self.assertEqual(DVar.IValue, 0)'
''
' def testActions(self):'
' self.assertEqual(MainForm.ActionList1.ActionCount, 1)'
' self.assertEqual(MainForm.ActionList1.Actions[0], MainForm.actTest)'
' self.assertEqual(MainForm.actTest in MainForm.ActionList1, True)'
' DVar.IValue = 0'
' MainForm.actTest.Execute()'
' self.assertEqual(DVar.IValue, 1)'
' def ActionHandler(Sender):'
' print("Action", Sender.Name, "executed from Python")'
' DVar.IValue = 2'
' self.assertEqual(MainForm.actTest.OnExecute, None)'
' MainForm.actTest.OnExecute = ActionHandler'
' self.assertEqual(MainForm.actTest.OnExecute, ActionHandler)'
' DVar.IValue = 0'
' MainForm.actTest.Execute()'
' self.assertEqual(DVar.IValue, 2)'
' MainForm.actTest.OnExecute = None'
' self.assertEqual(MainForm.actTest.OnExecute, None)'
''
' def testScreen(self):'
' self.assertEqual(Screen.DataModuleCount, 0)'
' self.assertEqual(Screen.FormCount > 0, True)'
' self.assertEqual(Screen.CustomFormCount > 0, True)'
' idx = -1'
' for i, f in enumerate(Screen.Forms):'
' if f == MainForm:'
' idx = i'
' break;'
' self.assertEqual(idx > -1, True)'
' self.assertEqual(Screen.Forms[idx], MainForm)'
' self.assertEqual(Screen.CustomForms[idx], MainForm)'
' self.assertEqual(Screen.Width > 0, True)'
' self.assertEqual(Screen.Height > 0, True)'
' MainForm.Button1.SetFocus()'
' self.assertEqual(Screen.ActiveControl, MainForm.Button1)'
' def ActiveControlChangeHandler(Sender):'
' print("ActiveControlChangeHandler fired")'
' print("New active constrol is", Sender.ActiveControl.Name)'
' DVar.IValue = 2'
' self.assertEqual(Screen.OnActiveControlChange, None)'
' Screen.OnActiveControlChange = ActiveControlChangeHandler'
' self.assertEqual(Screen.OnActiveControlChange, ActiveControlChangeHandler)'
' DVar.IValue = 0'
' self.assertEqual(DVar.IValue, 0)'
' MainForm.Memo2.SetFocus()'
' self.assertEqual(DVar.IValue, 2)'
' Screen.OnActiveControlChange = None'
' self.assertEqual(Screen.OnActiveControlChange, None)'
' DVar.IValue = 0'
' MainForm.Button1.SetFocus()'
' self.assertEqual(DVar.IValue, 0)'
' if DelphiVersion >= 6:'
' m = Screen.MonitorFromPoint(Point(10, 10), mdNearest)'
' self.assertEqual(isinstance(m, Monitor), True)'
''
' def testPublished(self):'
' L = MainForm.__published__'
' self.assertEqual(len(L) > 0, True)'
' self.assertEqual(''Caption'' in L, True)'
' self.assertEqual(''OnShow'' in L, True)'
''
'if __name__ == ''__main__'':'
' try:'
' unittest.main()'
' except SystemExit:'
' pass'
' MainForm.ActiveControl = MainForm.Memo2 # Class property!'
''
' '
' '
)
ScrollBars = ssVertical
TabOrder = 0
end
object Panel1: TPanel
Left = 0
Height = 41
Top = 606
Width = 668
Align = alBottom
BevelOuter = bvNone
ClientHeight = 41
ClientWidth = 668
TabOrder = 1
object Button1: TButton
Left = 8
Height = 25
Top = 8
Width = 75
Caption = 'Execute'
OnClick = Button1Click
TabOrder = 0
end
end
object Memo2: TMemo
Left = 0
Height = 169
Top = 0
Width = 668
Align = alTop
ScrollBars = ssBoth
TabOrder = 2
end
object PyEngine: TPythonEngine
IO = PythonGUIInputOutput1
left = 16
top = 16
end
object PythonModule: TPythonModule
Engine = PyEngine
Events = <
item
Name = 'TestFunction'
OnExecute = PythonModuleEvents0Execute
DocString.Strings = (
'doc for TestFunction'
)
end>
ModuleName = 'spam'
Errors = <>
left = 56
top = 16
end
object PythonGUIInputOutput1: TPythonGUIInputOutput
UnicodeIO = False
RawOutput = False
Output = Memo2
left = 168
top = 17
end
object ActionList1: TActionList
left = 96
top = 80
object actTest: TAction
Caption = 'Test'
OnExecute = actTestExecute
end
end
end