python_page.iss.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. { Copyright 2019-2021 Espressif Systems (Shanghai) CO LTD
  2. SPDX-License-Identifier: Apache-2.0 }
  3. { ------------------------------ Page to select Python interpreter ------------------------------ }
  4. #include "python_find_installed.iss.inc"
  5. var
  6. PythonPage: TInputOptionWizardPage;
  7. PythonVersion, PythonPath, PythonExecutablePath: String;
  8. function GetPythonPath(Unused: String): String;
  9. begin
  10. Result := PythonPath;
  11. end;
  12. function PythonVersionSupported(Version: String): Boolean;
  13. var
  14. Major, Minor: Integer;
  15. begin
  16. Result := False;
  17. if not VersionExtractMajorMinor(Version, Major, Minor) then
  18. begin
  19. Log('PythonVersionSupported: Could not parse version=' + Version);
  20. exit;
  21. end;
  22. if (Major = 2) and (Minor = 7) then Result := True;
  23. if (Major = 3) and (Minor >= 5) then Result := True;
  24. end;
  25. procedure OnPythonPagePrepare(Sender: TObject);
  26. var
  27. Page: TInputOptionWizardPage;
  28. FullName: String;
  29. i, Index, FirstEnabledIndex: Integer;
  30. OfferToInstall: Boolean;
  31. VersionToInstall: String;
  32. VersionSupported: Boolean;
  33. begin
  34. Page := TInputOptionWizardPage(Sender);
  35. Log('OnPythonPagePrepare');
  36. if Page.CheckListBox.Items.Count > 0 then
  37. exit;
  38. VersionToInstall := '{#PythonVersion}';
  39. OfferToInstall := True;
  40. FirstEnabledIndex := -1;
  41. for i := 0 to InstalledPythonVersions.Count - 1 do
  42. begin
  43. VersionSupported := PythonVersionSupported(InstalledPythonVersions[i]);
  44. FullName := InstalledPythonDisplayNames.Strings[i];
  45. if not VersionSupported then
  46. begin
  47. FullName := FullName + ' (unsupported)';
  48. end;
  49. FullName := FullName + #13#10 + InstalledPythonExecutables.Strings[i];
  50. Index := Page.Add(FullName);
  51. if not VersionSupported then
  52. begin
  53. Page.CheckListBox.ItemEnabled[Index] := False;
  54. end else begin
  55. if FirstEnabledIndex < 0 then FirstEnabledIndex := Index;
  56. end;
  57. if InstalledPythonVersions[i] = VersionToInstall then
  58. begin
  59. OfferToInstall := False;
  60. end;
  61. end;
  62. if OfferToInstall then
  63. begin
  64. Index := Page.Add('Install Python ' + VersionToInstall);
  65. if FirstEnabledIndex < 0 then FirstEnabledIndex := Index;
  66. end;
  67. Page.SelectedValueIndex := FirstEnabledIndex;
  68. end;
  69. procedure OnPythonSelectionChange(Sender: TObject);
  70. var
  71. Page: TInputOptionWizardPage;
  72. begin
  73. Page := TInputOptionWizardPage(Sender);
  74. Log('OnPythonSelectionChange index=' + IntToStr(Page.SelectedValueIndex));
  75. end;
  76. procedure ApplyPythonConfigurationByIndex(Index:Integer);
  77. begin
  78. Log('ApplyPythonConfigurationByIndex index=' + IntToStr(Index));
  79. PythonExecutablePath := InstalledPythonExecutables[Index];
  80. PythonPath := ExtractFilePath(PythonExecutablePath);
  81. PythonVersion := InstalledPythonVersions[Index];
  82. Log('ApplyPythonConfigurationByIndex: PythonPath='+PythonPath+' PythonExecutablePath='+PythonExecutablePath);
  83. end;
  84. function OnPythonPageValidate(Sender: TWizardPage): Boolean;
  85. var
  86. Page: TInputOptionWizardPage;
  87. begin
  88. Page := TInputOptionWizardPage(Sender);
  89. ApplyPythonConfigurationByIndex(Page.SelectedValueIndex);
  90. Result := True;
  91. end;
  92. procedure UpdatePythonVariables(ExecutablePath: String);
  93. begin
  94. PythonExecutablePath := ExecutablePath;
  95. PythonPath := ExtractFilePath(PythonExecutablePath);
  96. Log('PythonExecutablePathUpdateAfterInstall: PythonPath='+PythonPath+' PythonExecutablePath='+PythonExecutablePath);
  97. end;
  98. <event('InitializeWizard')>
  99. procedure CreatePythonPage();
  100. begin
  101. PythonPage := ChoicePageCreate(
  102. wpLicense,
  103. 'Python choice', 'Please choose Python version',
  104. 'Available Python versions',
  105. '',
  106. False,
  107. @OnPythonPagePrepare,
  108. @OnPythonSelectionChange,
  109. @OnPythonPageValidate);
  110. end;
  111. <event('ShouldSkipPage')>
  112. function ShouldSkipPythonPage(PageID: Integer): Boolean;
  113. var
  114. UseEmbeddedPythonParam: String;
  115. begin
  116. if (PageID = PythonPage.ID) then begin
  117. { Skip in case of embedded Python. }
  118. UseEmbeddedPythonParam := ExpandConstant('{param:USEEMBEDDEDPYTHON|yes}');
  119. if (UseEmbeddedPythonParam = 'yes') then begin
  120. ApplyPythonConfigurationByIndex(0);
  121. Result := True;
  122. end;
  123. end;
  124. end;