Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### Welcome to the Samples section of Python Environments for Delphi applicaitons.

Each one of the samples showcase the various use-cases that we can achieve using **PythonEnvironments**.

- [Sample 00](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_00_SimpleDeployable)
- [Sample 01](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_01_ManuallyLoad)
- [Sample 02](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_02_AutoLoad)
- [Sample 03](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_03_ExtractPython)
- [Sample 04](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_04_AsyncLoad)
- [Sample 05](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_05_AsyncEvents)
- [Sample 06](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_00_SimpleDeployable)
- [Sample 07](https://github.com/Embarcadero/PythonEnviroments/tree/Update_Samples/samples/environments/deploy/sample_06_SimpleAndroid)
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ TForm1 = class(TForm)
TabControl1: TTabControl;
TabItem1: TTabItem;
TabItem2: TTabItem;
TabItem3: TTabItem;
Image1: TImage;
Image2: TImage;
TabItem4: TTabItem;
TabItem3: TTabItem;
Memo1: TMemo;
Image3: TImage;
procedure PyEmbeddedEnvironment1PluginInstall(const APlugin: TObject;
Expand Down Expand Up @@ -50,47 +48,62 @@ implementation

{$R *.fmx}

// Set the default view tab to "Run"
procedure TForm1.FormShow(Sender: TObject);
begin
TabControl1.ActiveTab := TabItem4;
TabControl1.ActiveTab := TabItem3;
end;

// "AfterActivate" Event of PyEmbeddedEnvironment1 is assigned
// to the below procedure
procedure TForm1.PyEmbeddedEnvironment1AfterActivate(Sender: TObject;
const APythonVersion: string; const AActivated: Boolean);
begin
Memo1.Lines.Add(Format('Python %s is active.', [APythonVersion]));
end;

// "AfterSetUp" Event of PyEmbeddedEnvironment1 is assigned
// to the below procedure
procedure TForm1.PyEmbeddedEnvironment1AfterSetup(Sender: TObject;
const APythonVersion: string);
begin
Memo1.Lines.Add(Format('Python %s setup done.', [APythonVersion]));
end;

// "BeforeActivate" Event of PyEmbeddedEnvironment1 is assigned
// to the below procedure
procedure TForm1.PyEmbeddedEnvironment1BeforeActivate(Sender: TObject;
const APythonVersion: string);
begin
Memo1.Lines.Add(Format('Activating Python %s.', [APythonVersion]));
end;

// "BeforeSetUp" Event of PyEmbeddedEnvironment1 is assigned
// to the below procedure
procedure TForm1.PyEmbeddedEnvironment1BeforeSetup(Sender: TObject;
const APythonVersion: string);
begin
Memo1.Lines.Add(Format('Setting up Python %s.', [APythonVersion]));
end;

// "OnError" Event of PyEmbeddedEnvironment1 is assigned
// to the below procedure
procedure TForm1.PyEmbeddedEnvironment1Error(Sender: TObject;
const AException: Exception);
begin
Memo1.Lines.Add(Format('An error has occurred: %s', [AException.Message]));
end;

// "OnPluginInstall" Event of PyEmbeddedEnvironment1 is assigned
// to the below procedure
procedure TForm1.PyEmbeddedEnvironment1PluginInstall(const APlugin: TObject;
const AInfo: TPyPluginInfo);
begin
Memo1.Lines.Add(Format('Installing %s...', [AInfo.Name]));
end;

// "OnReady" Event of PyEmbeddedEnvironment1 is assigned
// to the below procedure
procedure TForm1.PyEmbeddedEnvironment1Ready(Sender: TObject;
const APythonVersion: string);
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object Form1: TForm1
Left = 0
Top = 0
Caption = 'ManuallyLoad'
ClientHeight = 189
ClientWidth = 479
ClientHeight = 201
ClientWidth = 432
Position = MainFormCenter
FormFactor.Width = 320
FormFactor.Height = 480
Expand All @@ -15,14 +15,17 @@ object Form1: TForm1
DataDetectorTypes = []
Lines.Strings = (
'Set the PyEmbeddedEnvironment1 "AutoLoad" property to False. '
'Check out the Delphi code.')
'Check out the Delphi code.'
''
'Loading Python from user code level:'
'-----------------------------------------')
Align = Client
Size.Width = 479.000000000000000000
Size.Height = 189.000000000000000000
Size.Width = 432.000000000000000000
Size.Height = 201.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
Viewport.Width = 475.000000000000000000
Viewport.Height = 185.000000000000000000
Viewport.Width = 428.000000000000000000
Viewport.Height = 197.000000000000000000
end
object PythonEngine1: TPythonEngine
AutoLoad = False
Expand All @@ -31,8 +34,8 @@ object Form1: TForm1
APIVersion = 1013
RegVersion = '3.9'
UseLastKnownVersion = False
Left = 224
Top = 32
Left = 288
Top = 56
end
object PyEmbeddedEnvironment1: TPyEmbeddedEnvironment
BeforeSetup = PyEmbeddedEnvironment1BeforeSetup
Expand All @@ -48,7 +51,7 @@ object Form1: TForm1
Scanner.AutoScan = True
Scanner.ScanRule = srFileName
Scanner.DeleteEmbeddable = True
Left = 224
Top = 96
Left = 288
Top = 112
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ implementation

{$R *.fmx}

// We're loading Python manually on creation of the Form
procedure TForm1.FormCreate(Sender: TObject);
begin
// Manually setup by the application developer with the "Setup()" method
PyEmbeddedEnvironment1.Setup();
// Manually activated by the application developer with the "Activate()" method
PyEmbeddedEnvironment1.Activate();
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object Form1: TForm1
Left = 0
Top = 0
Caption = 'Automatically Load'
ClientHeight = 189
ClientWidth = 479
ClientHeight = 212
ClientWidth = 452
Position = MainFormCenter
FormFactor.Width = 320
FormFactor.Height = 480
Expand All @@ -16,14 +16,17 @@ object Form1: TForm1
'Set the PyEmbeddedEnvironment1 "AutoLoad" property to True. '

'It will load the Python environment automatically as you run the' +
' application.')
' application.'
''
'Loading Python automatically:'
'---------------------------------')
Align = Client
Size.Width = 479.000000000000000000
Size.Height = 189.000000000000000000
Size.Width = 452.000000000000000000
Size.Height = 212.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
Viewport.Width = 475.000000000000000000
Viewport.Height = 185.000000000000000000
Viewport.Width = 448.000000000000000000
Viewport.Height = 208.000000000000000000
end
object PythonEngine1: TPythonEngine
AutoLoad = False
Expand All @@ -32,8 +35,8 @@ object Form1: TForm1
APIVersion = 1013
RegVersion = '3.9'
UseLastKnownVersion = False
Left = 224
Top = 32
Left = 296
Top = 48
end
object PyEmbeddedEnvironment1: TPyEmbeddedEnvironment
BeforeSetup = PyEmbeddedEnvironment1BeforeSetup
Expand All @@ -49,7 +52,7 @@ object Form1: TForm1
Scanner.AutoScan = True
Scanner.ScanRule = srFileName
Scanner.DeleteEmbeddable = True
Left = 224
Top = 96
Left = 296
Top = 104
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ procedure TForm1.PyEmbeddedEnvironment1BeforeActivate(Sender: TObject;
Memo1.Lines.Add(Format('Activating Python %s.', [APythonVersion]));
end;

// PyEmbeddedEnvironmet1 will load Python automatically before setting it up.
procedure TForm1.PyEmbeddedEnvironment1BeforeSetup(Sender: TObject;
const APythonVersion: string);
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object Form1: TForm1
Left = 0
Top = 0
Caption = 'Extract Python Zip File'
ClientHeight = 189
ClientWidth = 543
ClientHeight = 232
ClientWidth = 452
Position = MainFormCenter
FormFactor.Width = 320
FormFactor.Height = 480
Expand All @@ -16,25 +16,28 @@ object Form1: TForm1
DataDetectorTypes = []
Lines.Strings = (
'Set the PyEmbeddedEnvironment1 "AutoLoad" property to False. '
'Check out the Delphi code.')
'Check out the Delphi code.'
''
'Extracting Zipped Python Embeddable:'
'------------------------------------------')
Align = Client
Size.Width = 543.000000000000000000
Size.Height = 167.000000000000000000
Size.Width = 452.000000000000000000
Size.Height = 210.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
Viewport.Width = 539.000000000000000000
Viewport.Height = 163.000000000000000000
Viewport.Width = 448.000000000000000000
Viewport.Height = 206.000000000000000000
end
object StatusBar1: TStatusBar
Position.Y = 167.000000000000000000
Position.Y = 210.000000000000000000
ShowSizeGrip = True
Size.Width = 543.000000000000000000
Size.Width = 452.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 5
object Label1: TLabel
Align = Client
Size.Width = 543.000000000000000000
Size.Width = 452.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TextSettings.WordWrap = False
Expand All @@ -48,8 +51,8 @@ object Form1: TForm1
APIVersion = 1013
RegVersion = '3.9'
UseLastKnownVersion = False
Left = 224
Top = 32
Left = 296
Top = 40
end
object PyEmbeddedEnvironment1: TPyEmbeddedEnvironment
BeforeSetup = PyEmbeddedEnvironment1BeforeSetup
Expand All @@ -66,7 +69,7 @@ object Form1: TForm1
Scanner.AutoScan = True
Scanner.ScanRule = srFileName
Scanner.DeleteEmbeddable = True
Left = 224
Top = 96
Left = 296
Top = 104
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ procedure TForm1.PyEmbeddedEnvironment1Ready(Sender: TObject;
Memo1.Lines.Add(Format('Python %s is ready.', [APythonVersion]));
end;

// Assigning the below procedure to the "OnZipProgress" event of
// TPyEmbeddedEnvironment1 component
procedure TForm1.PyEmbeddedEnvironment1ZipProgress(Sender: TObject;
ADistribution: TPyCustomEmbeddableDistribution; FileName: string;
Header: TZipHeader; Position: Int64);
begin
//Zip progress is neer synchronized, even when
//Zip progress is near synchronized, even when
//the SynchronizeEvents property is set to true
TThread.Queue(nil, procedure() begin
Label1.Text := FileName.Replace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object Form1: TForm1
Left = 0
Top = 0
Caption = 'Asynchronous Load'
ClientHeight = 189
ClientWidth = 479
ClientHeight = 204
ClientWidth = 427
Position = MainFormCenter
FormFactor.Width = 320
FormFactor.Height = 480
Expand All @@ -16,14 +16,17 @@ object Form1: TForm1
DataDetectorTypes = []
Lines.Strings = (
'Set the PyEmbeddedEnvironment1 "AutoLoad" property to False. '
'Check out the Delphi code.')
'Check out the Delphi code.'
''
'Loading Python Asynchronously:'
'------------------------------------')
Align = Client
Size.Width = 479.000000000000000000
Size.Height = 189.000000000000000000
Size.Width = 427.000000000000000000
Size.Height = 204.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
Viewport.Width = 475.000000000000000000
Viewport.Height = 185.000000000000000000
Viewport.Width = 423.000000000000000000
Viewport.Height = 200.000000000000000000
end
object PythonEngine1: TPythonEngine
AutoLoad = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
ShowMessage('Waiting for background operation. Try again.');
end;

// Loading the Python Asynchronously
procedure TForm1.FormCreate(Sender: TObject);
var
LAsyncSetup: IAsyncResult;
Expand Down
Loading