Skip to content

Commit f53692d

Browse files
committed
New samples
Former-commit-id: d3a0850
1 parent 3ca5ae7 commit f53692d

File tree

9 files changed

+3792
-1
lines changed

9 files changed

+3792
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
program AsyncEvents;
2+
3+
uses
4+
System.StartUpCopy,
5+
FMX.Forms,
6+
Unit1 in 'Unit1.pas' {Form1};
7+
8+
{$R *.res}
9+
10+
begin
11+
Application.Initialize;
12+
Application.CreateForm(TForm1, Form1);
13+
Application.Run;
14+
end.

samples/environments/deploy/AsyncEvents/AsyncEvents.dproj

Lines changed: 1629 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
object Form1: TForm1
2+
Left = 0
3+
Top = 0
4+
Caption = 'Asynchronous Events'
5+
ClientHeight = 189
6+
ClientWidth = 479
7+
Position = MainFormCenter
8+
FormFactor.Width = 320
9+
FormFactor.Height = 480
10+
FormFactor.Devices = [Desktop]
11+
OnCreate = FormCreate
12+
OnCloseQuery = FormCloseQuery
13+
DesignerMasterStyle = 0
14+
object Memo1: TMemo
15+
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
16+
DataDetectorTypes = []
17+
Lines.Strings = (
18+
'Set the PyEmbeddedEnvironment1 "AutoLoad" property to False. '
19+
20+
'Set the PyEmbeddedEnvironment1 "SynchronizeEvents" property to F' +
21+
'alse.'
22+
'Enqueue all events.'
23+
'Check out the Delphi code.'
24+
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
25+
Align = Client
26+
Size.Width = 479.000000000000000000
27+
Size.Height = 189.000000000000000000
28+
Size.PlatformDefault = False
29+
TabOrder = 2
30+
Viewport.Width = 475.000000000000000000
31+
Viewport.Height = 185.000000000000000000
32+
end
33+
object PythonEngine1: TPythonEngine
34+
AutoLoad = False
35+
DllName = 'python39.dll'
36+
DllPath = 'C:\Users\Public\Documents\Embarcadero\Studio\22.0\Bpl\3.9'
37+
APIVersion = 1013
38+
RegVersion = '3.9'
39+
UseLastKnownVersion = False
40+
Left = 224
41+
Top = 32
42+
end
43+
object PyEmbeddedEnvironment1: TPyEmbeddedEnvironment
44+
BeforeSetup = PyEmbeddedEnvironment1BeforeSetup
45+
AfterSetup = PyEmbeddedEnvironment1AfterSetup
46+
BeforeActivate = PyEmbeddedEnvironment1BeforeActivate
47+
AfterActivate = PyEmbeddedEnvironment1AfterActivate
48+
OnError = PyEmbeddedEnvironment1Error
49+
OnReady = PyEmbeddedEnvironment1Ready
50+
AutoLoad = False
51+
SynchronizeEvents = False
52+
PythonEngine = PythonEngine1
53+
Distributions = <>
54+
Scanner.AutoScan = True
55+
Scanner.ScanRule = srFileName
56+
Scanner.DeleteEmbeddable = True
57+
Left = 224
58+
Top = 96
59+
end
60+
end
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
unit Unit1;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7+
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types,
8+
FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, PythonEngine,
9+
PyEnvironment, PyEnvironment.Embeddable;
10+
11+
type
12+
TForm1 = class(TForm)
13+
PythonEngine1: TPythonEngine;
14+
Memo1: TMemo;
15+
PyEmbeddedEnvironment1: TPyEmbeddedEnvironment;
16+
procedure PyEmbeddedEnvironment1AfterActivate(Sender: TObject;
17+
const APythonVersion: string; const AActivated: Boolean);
18+
procedure PyEmbeddedEnvironment1AfterSetup(Sender: TObject;
19+
const APythonVersion: string);
20+
procedure PyEmbeddedEnvironment1BeforeActivate(Sender: TObject;
21+
const APythonVersion: string);
22+
procedure PyEmbeddedEnvironment1BeforeSetup(Sender: TObject;
23+
const APythonVersion: string);
24+
procedure PyEmbeddedEnvironment1Error(Sender: TObject;
25+
const AException: Exception);
26+
procedure PyEmbeddedEnvironment1Ready(Sender: TObject;
27+
const APythonVersion: string);
28+
procedure FormCreate(Sender: TObject);
29+
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
30+
private
31+
FAsyncActivate: IAsyncResult;
32+
{ Private declarations }
33+
public
34+
{ Public declarations }
35+
end;
36+
37+
var
38+
Form1: TForm1;
39+
40+
implementation
41+
42+
{$R *.fmx}
43+
44+
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
45+
begin
46+
CanClose := FAsyncActivate.IsCompleted;
47+
if not CanClose then
48+
ShowMessage('Waiting for background operation. Try again.');
49+
end;
50+
51+
procedure TForm1.FormCreate(Sender: TObject);
52+
var
53+
LAsyncSetup: IAsyncResult;
54+
begin
55+
LAsyncSetup := PyEmbeddedEnvironment1.SetupAsync();
56+
FAsyncActivate := PyEmbeddedEnvironment1.ActivateAsync(LAsyncSetup);
57+
Memo1.Lines.Add('Background task has started.');
58+
end;
59+
60+
procedure TForm1.PyEmbeddedEnvironment1AfterActivate(Sender: TObject;
61+
const APythonVersion: string; const AActivated: Boolean);
62+
begin
63+
TThread.Queue(TThread.Current, procedure() begin
64+
Memo1.Lines.Add(Format('Python %s has been activated.', [APythonVersion]));
65+
end);
66+
end;
67+
68+
procedure TForm1.PyEmbeddedEnvironment1AfterSetup(Sender: TObject;
69+
const APythonVersion: string);
70+
begin
71+
TThread.Queue(TThread.Current, procedure() begin
72+
Memo1.Lines.Add(Format('Python %s has been setup.', [APythonVersion]));
73+
end);
74+
end;
75+
76+
procedure TForm1.PyEmbeddedEnvironment1BeforeActivate(Sender: TObject;
77+
const APythonVersion: string);
78+
begin
79+
TThread.Queue(TThread.Current, procedure() begin
80+
Memo1.Lines.Add(Format('Activating Python %s.', [APythonVersion]));
81+
end);
82+
end;
83+
84+
procedure TForm1.PyEmbeddedEnvironment1BeforeSetup(Sender: TObject;
85+
const APythonVersion: string);
86+
begin
87+
TThread.Queue(TThread.Current, procedure() begin
88+
Memo1.Lines.Add(Format('Setting up Python %s.', [APythonVersion]));
89+
end);
90+
end;
91+
92+
procedure TForm1.PyEmbeddedEnvironment1Error(Sender: TObject;
93+
const AException: Exception);
94+
begin
95+
TThread.Queue(TThread.Current, procedure() begin
96+
Memo1.Lines.Add(Format(
97+
'An error occurred during the installation process: %s', [
98+
AException.ToString()]));
99+
end);
100+
end;
101+
102+
procedure TForm1.PyEmbeddedEnvironment1Ready(Sender: TObject;
103+
const APythonVersion: string);
104+
begin
105+
TThread.Queue(TThread.Current, procedure() begin
106+
Memo1.Lines.Add(Format('Python %s is ready.', [APythonVersion]));
107+
end);
108+
end;
109+
110+
end.

samples/environments/deploy/ExtractPython/Unit1.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ procedure TForm1.PyEmbeddedEnvironment1ZipProgress(Sender: TObject;
107107
ADistribution: TPyCustomEmbeddableDistribution; FileName: string;
108108
Header: TZipHeader; Position: Int64);
109109
begin
110-
//Zip progress is not sync
110+
//Zip progress is neer synchronized, even when
111+
//the SynchronizeEvents property is set to true
111112
TThread.Queue(nil, procedure() begin
112113
Label1.Text := FileName.Replace(
113114
TDirectory.GetParent(ADistribution.EnvironmentPath), String.Empty, []);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
program SimpleAndroid;
2+
3+
uses
4+
System.StartUpCopy,
5+
FMX.Forms,
6+
Unit1 in 'Unit1.pas' {Form1};
7+
8+
{$R *.res}
9+
10+
begin
11+
Application.Initialize;
12+
Application.CreateForm(TForm1, Form1);
13+
Application.Run;
14+
end.

0 commit comments

Comments
 (0)