2020-12-16 11:40:13 -05:00
|
|
|
{ Copyright 2019-2021 Espressif Systems (Shanghai) CO LTD
|
2019-04-28 22:36:03 -04:00
|
|
|
SPDX-License-Identifier: Apache-2.0 }
|
|
|
|
|
|
|
|
{ ------------------------------ Page to select Python interpreter ------------------------------ }
|
|
|
|
|
|
|
|
#include "python_find_installed.iss.inc"
|
|
|
|
|
|
|
|
var
|
|
|
|
PythonPage: TInputOptionWizardPage;
|
|
|
|
PythonVersion, PythonPath, PythonExecutablePath: String;
|
|
|
|
|
|
|
|
|
|
|
|
function GetPythonPath(Unused: String): String;
|
|
|
|
begin
|
|
|
|
Result := PythonPath;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function PythonVersionSupported(Version: String): Boolean;
|
|
|
|
var
|
|
|
|
Major, Minor: Integer;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if not VersionExtractMajorMinor(Version, Major, Minor) then
|
|
|
|
begin
|
|
|
|
Log('PythonVersionSupported: Could not parse version=' + Version);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (Major = 2) and (Minor = 7) then Result := True;
|
|
|
|
if (Major = 3) and (Minor >= 5) then Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure OnPythonPagePrepare(Sender: TObject);
|
|
|
|
var
|
|
|
|
Page: TInputOptionWizardPage;
|
|
|
|
FullName: String;
|
|
|
|
i, Index, FirstEnabledIndex: Integer;
|
|
|
|
OfferToInstall: Boolean;
|
|
|
|
VersionToInstall: String;
|
|
|
|
VersionSupported: Boolean;
|
|
|
|
begin
|
|
|
|
Page := TInputOptionWizardPage(Sender);
|
|
|
|
Log('OnPythonPagePrepare');
|
|
|
|
if Page.CheckListBox.Items.Count > 0 then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
VersionToInstall := '{#PythonVersion}';
|
|
|
|
OfferToInstall := True;
|
|
|
|
FirstEnabledIndex := -1;
|
|
|
|
|
|
|
|
for i := 0 to InstalledPythonVersions.Count - 1 do
|
|
|
|
begin
|
|
|
|
VersionSupported := PythonVersionSupported(InstalledPythonVersions[i]);
|
|
|
|
FullName := InstalledPythonDisplayNames.Strings[i];
|
|
|
|
if not VersionSupported then
|
|
|
|
begin
|
|
|
|
FullName := FullName + ' (unsupported)';
|
|
|
|
end;
|
|
|
|
FullName := FullName + #13#10 + InstalledPythonExecutables.Strings[i];
|
|
|
|
Index := Page.Add(FullName);
|
|
|
|
if not VersionSupported then
|
|
|
|
begin
|
|
|
|
Page.CheckListBox.ItemEnabled[Index] := False;
|
|
|
|
end else begin
|
|
|
|
if FirstEnabledIndex < 0 then FirstEnabledIndex := Index;
|
|
|
|
end;
|
|
|
|
if InstalledPythonVersions[i] = VersionToInstall then
|
|
|
|
begin
|
|
|
|
OfferToInstall := False;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if OfferToInstall then
|
|
|
|
begin
|
|
|
|
Index := Page.Add('Install Python ' + VersionToInstall);
|
|
|
|
if FirstEnabledIndex < 0 then FirstEnabledIndex := Index;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Page.SelectedValueIndex := FirstEnabledIndex;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure OnPythonSelectionChange(Sender: TObject);
|
|
|
|
var
|
|
|
|
Page: TInputOptionWizardPage;
|
|
|
|
begin
|
|
|
|
Page := TInputOptionWizardPage(Sender);
|
|
|
|
Log('OnPythonSelectionChange index=' + IntToStr(Page.SelectedValueIndex));
|
|
|
|
end;
|
|
|
|
|
2020-12-16 11:40:13 -05:00
|
|
|
procedure ApplyPythonConfigurationByIndex(Index:Integer);
|
|
|
|
begin
|
|
|
|
Log('ApplyPythonConfigurationByIndex index=' + IntToStr(Index));
|
|
|
|
PythonExecutablePath := InstalledPythonExecutables[Index];
|
|
|
|
PythonPath := ExtractFilePath(PythonExecutablePath);
|
|
|
|
PythonVersion := InstalledPythonVersions[Index];
|
|
|
|
Log('ApplyPythonConfigurationByIndex: PythonPath='+PythonPath+' PythonExecutablePath='+PythonExecutablePath);
|
|
|
|
end;
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
function OnPythonPageValidate(Sender: TWizardPage): Boolean;
|
|
|
|
var
|
|
|
|
Page: TInputOptionWizardPage;
|
|
|
|
begin
|
|
|
|
Page := TInputOptionWizardPage(Sender);
|
2020-12-16 11:40:13 -05:00
|
|
|
ApplyPythonConfigurationByIndex(Page.SelectedValueIndex);
|
2019-04-28 22:36:03 -04:00
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
2020-12-16 11:40:13 -05:00
|
|
|
procedure UpdatePythonVariables(ExecutablePath: String);
|
2019-04-28 22:36:03 -04:00
|
|
|
begin
|
|
|
|
PythonExecutablePath := ExecutablePath;
|
|
|
|
PythonPath := ExtractFilePath(PythonExecutablePath);
|
|
|
|
Log('PythonExecutablePathUpdateAfterInstall: PythonPath='+PythonPath+' PythonExecutablePath='+PythonExecutablePath);
|
|
|
|
end;
|
|
|
|
|
|
|
|
<event('InitializeWizard')>
|
|
|
|
procedure CreatePythonPage();
|
|
|
|
begin
|
|
|
|
PythonPage := ChoicePageCreate(
|
|
|
|
wpLicense,
|
|
|
|
'Python choice', 'Please choose Python version',
|
|
|
|
'Available Python versions',
|
|
|
|
'',
|
|
|
|
False,
|
|
|
|
@OnPythonPagePrepare,
|
|
|
|
@OnPythonSelectionChange,
|
|
|
|
@OnPythonPageValidate);
|
|
|
|
end;
|
2020-12-16 11:40:13 -05:00
|
|
|
|
|
|
|
<event('ShouldSkipPage')>
|
|
|
|
function ShouldSkipPythonPage(PageID: Integer): Boolean;
|
|
|
|
begin
|
|
|
|
if (PageID = PythonPage.ID) then begin
|
|
|
|
{ Skip in case of embedded Python. }
|
2020-08-28 06:33:48 -04:00
|
|
|
if (UseEmbeddedPython) then begin
|
2020-12-16 11:40:13 -05:00
|
|
|
ApplyPythonConfigurationByIndex(0);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|