99from PySide6 .QtGui import QIcon
1010from PySide6 .QtWidgets import QComboBox , QWidget
1111
12- from ..Constants .python_env_constants import PyEnv , PyEnvType , get_pyenv_version
12+ from ..Constants import RUNTIME_INFO , PyEnv , PyEnvType , get_pyenv_version
13+ from ..Utilities import get_sys_python
1314
1415
1516class PyEnvComboBox (QComboBox ):
@@ -22,21 +23,27 @@ def __init__(self, parent: Optional[QWidget] = None):
2223
2324 self .setIconSize (QSize (18 , 18 ))
2425
26+ if not RUNTIME_INFO .is_bundled :
27+ # 在非 PyInstaller 捆绑环境中,第一项为当前用于运行 Py2exe-GUI 的 Python 环境
28+ current_pyenv = PyEnv (PyEnvType .poetry , executable_path = sys .executable )
29+ self .addItem (* self .gen_item (current_pyenv ))
30+ else :
31+ # 若已由 PyInstaller 捆绑成冻结应用程序,则第一项为系统 Python 环境
32+ sys_pyenv = PyEnv (PyEnvType .system , executable_path = get_sys_python ())
33+ self .addItem (* self .gen_item (sys_pyenv ))
34+
35+ # 测试项
2536 self .addItem (
2637 QIcon (":/Icons/Python_128px" ),
2738 f"Python { platform .python_version ()} " ,
2839 sys .executable ,
2940 )
3041
31- self .addItem (
32- * self .gen_item (PyEnv (PyEnvType .poetry , executable_path = sys .executable ))
33- )
34-
3542 @classmethod
3643 def gen_item (cls , pyenv : PyEnv ) -> tuple :
3744 """
38- 根据传入的Python环境 ,生成一个适用于 QComboBox.addItem() 参数的三元素元组 \n
39- :param pyenv: Python解释器环境
45+ 根据传入的 Python 环境 ,生成一个适用于 QComboBox.addItem() 参数的三元素元组 \n
46+ :param pyenv: Python 解释器环境
4047 :return: (icon, text, data)
4148 """
4249
@@ -45,13 +52,13 @@ def gen_item(cls, pyenv: PyEnv) -> tuple:
4552
4653 if pyenv .type == PyEnvType .system :
4754 icon = QIcon (":/Icons/Python_128px" )
48- text = f"Python { version } "
55+ text = f"Python { version } (System) "
4956 elif pyenv .type == PyEnvType .poetry :
5057 icon = QIcon (":/Icons/Poetry" )
51- text = f"Poetry[Python { version } ]"
58+ text = f"Poetry [Python { version } ]"
5259 elif pyenv .type == PyEnvType .conda :
5360 icon = QIcon (":/Icons/Conda" )
54- text = f"Conda[Python { version } ]"
61+ text = f"Conda [Python { version } ]"
5562 else :
5663 icon = QIcon (":/Icons/Python_128px" )
5764 text = f"Python { version } "
0 commit comments