cxfreeze打包python程序的方法说明(生成安装包,实现桌面快捷方式、删除快捷方式)
2021-07-03 11:07
import os
__all__ = [ "bdist_msi" ]
# force the remove existing products action to happen first since Windows
for index, info in enumerate(sequence):
def add_config(self, fullname):
def add_cancel_dialog(self):
# installer appears to be braindead and doesn‘t handle files shared between
# different "products" very well
sequence = msilib.sequence.InstallExecuteSequence
if info[0] == ‘RemoveExistingProducts‘:
sequence[index] = (info[0], info[1], 1450)
class bdist_msi(distutils.command.bdist_msi.bdist_msi):
user_options = distutils.command.bdist_msi.bdist_msi.user_options + [
(‘add-to-path=‘, None, ‘add target dir to PATH environment variable‘),
(‘upgrade-code=‘, None, ‘upgrade code to use‘),
(‘initial-target-dir=‘, None, ‘initial target directory‘),
(‘target-name=‘, None, ‘name of the file to create‘),
(‘directories=‘, None, ‘list of 3-tuples of directories to create‘),
(‘data=‘, None, ‘dictionary of data indexed by table name‘),
# add by joshua zou 2016.07.23
(‘product-code=‘, None, ‘product code to use‘)
]
x = y = 50
width = 370
height = 300
title = "[ProductName] Setup"
modeless = 1
modal = 3
if self.add_to_path:
msilib.add_data(self.db, ‘Environment‘,
[("E_PATH", "Path", r"[~];[TARGETDIR]", "TARGETDIR")])
if self.directories:
msilib.add_data(self.db, "Directory", self.directories)
msilib.add_data(self.db, ‘CustomAction‘,
[("A_SET_TARGET_DIR", 256 + 51, "TARGETDIR",
self.initial_target_dir)])
msilib.add_data(self.db, ‘InstallExecuteSequence‘,
[("A_SET_TARGET_DIR", ‘TARGETDIR=""‘, 401)])
msilib.add_data(self.db, ‘InstallUISequence‘,
[("PrepareDlg", None, 140),
("A_SET_TARGET_DIR", ‘TARGETDIR=""‘, 401),
("SelectDirectoryDlg", "not Installed", 1230),
("MaintenanceTypeDlg",
"Installed and not Resume and not Preselected", 1250),
("ProgressDlg", None, 1280)
])
for index, executable in enumerate(self.distribution.executables):
if executable.shortcutName is not None \
and executable.shortcutDir is not None:
baseName = os.path.basename(executable.targetName)
msilib.add_data(self.db, "Shortcut",
[("S_APP_%s" % index, executable.shortcutDir,
executable.shortcutName, "TARGETDIR",
"[TARGETDIR]%s" % baseName, None, None, None,
None, None, None, None)])
for tableName, data in self.data.items():
msilib.add_data(self.db, tableName, data)
dialog = msilib.Dialog(self.db, "CancelDlg", 50, 10, 260, 85, 3,
self.title, "No", "No", "No")
dialog.text("Text", 48, 15, 194, 30, 3,
"Are you sure you want to cancel [ProductName] installation?")
button = dialog.pushbutton("Yes", 72, 57, 56, 17, 3, "Yes", "No")
button.event("EndDialog", "Exit")
button = dialog.pushbutton("No", 132, 57, 56, 17, 3, "No", "Yes")
button.event("EndDialog", "Return")
def add_error_dialog(self):
dialog = msilib.Dialog(self.db, "ErrorDlg", 50, 10, 330, 101, 65543,
self.title, "ErrorText", None, None)
dialog.text("ErrorText", 50, 9, 280, 48, 3, "")
for text, x in [("No", 120), ("Yes", 240), ("Abort", 0),
("Cancel", 42), ("Ignore", 81), ("Ok", 159), ("Retry", 198)]:
button = dialog.pushbutton(text[0], x, 72, 81, 21, 3, text, None)
button.event("EndDialog", "Error%s" % text)
def add_exit_dialog(self):
dialog = distutils.command.bdist_msi.PyDialog(self.db, "ExitDialog",
self.x, self.y, self.width, self.height, self.modal,
self.title, "Finish", "Finish", "Finish")
dialog.title("Completing the [ProductName] installer")
dialog.back(""Change"‘, 20)
button = dialog.cancel("Cancel", "RepairRadioGroup")
button.event("SpawnDialog", "CancelDlg")
def add_prepare_dialog(self):
dialog = distutils.command.bdist_msi.PyDialog(self.db, "PrepareDlg",
self.x, self.y, self.width, self.height, self.modeless,
self.title, "Cancel", "Cancel", "Cancel")
dialog.text("Description", 15, 70, 320, 40, 0x30003,
"Please wait while the installer prepares to guide you through"
"the installation.")
dialog.title("Welcome to the [ProductName] installer")
text = dialog.text("ActionText", 15, 110, 320, 20, 0x30003,
"Pondering...")
text.mapping("ActionText", "Text")
text = dialog.text("ActionData", 15, 135, 320, 30, 0x30003, None)
text.mapping("ActionData", "Text")
dialog.back("Back", None, active = False)
dialog.next("Next", None, active = False)
button = dialog.cancel("Cancel", None)
button.event("SpawnDialog", "CancelDlg")
def add_progress_dialog(self):
dialog = distutils.command.bdist_msi.PyDialog(self.db, "ProgressDlg",
self.x, self.y, self.width, self.height, self.modeless,
self.title, "Cancel", "Cancel", "Cancel", bitmap = False)
dialog.text("Title", 20, 15, 200, 15, 0x30003,
r"{\DlgFontBold8}[Progress1] [ProductName]")
dialog.text("Text", 35, 65, 300, 30, 3,
"Please wait while the installer [Progress2] [ProductName].")
dialog.text("StatusLabel", 35, 100 ,35, 20, 3, "Status:")
text = dialog.text("ActionText", 70, 100, self.width - 70, 20, 3,
"Pondering...")
text.mapping("ActionText", "Text")
control = dialog.control("ProgressBar", "ProgressBar", 35, 120, 300,
10, 65537, None, "Progress done", None, None)
control.mapping("SetProgress", "Progress")
dialog.back("", "Cancel", active = False)
button = dialog.cancel("Cancel", "Back")
button.event("SpawnDialog", "CancelDlg")
def add_properties(self):
metadata = self.distribution.metadata
props = [
(‘DistVersion‘, metadata.get_version()),
(‘DefaultUIFont‘, ‘DlgFont8‘),
(‘ErrorDialog‘, ‘ErrorDlg‘),
(‘Progress1‘, ‘Install‘),
(‘Progress2‘, ‘installs‘),
(‘MaintenanceForm_Action‘, ‘Repair‘),
(‘ALLUSERS‘, ‘1‘)
]
email = metadata.author_email or metadata.maintainer_email
if email:
props.append(("ARPCONTACT", email))
if metadata.url:
props.append(("ARPURLINFOABOUT", metadata.url))
if self.upgrade_code is not None:
props.append(("UpgradeCode", self.upgrade_code))
msilib.add_data(self.db, ‘Property‘, props)
def add_select_directory_dialog(self):
dialog = distutils.command.bdist_msi.PyDialog(self.db,
"SelectDirectoryDlg", self.x, self.y, self.width, self.height,
self.modal, self.title, "Next", "Next", "Cancel")
dialog.title("Select destination directory")
dialog.back("", "Cancel")
button.event("SetTargetPath", "TARGETDIR", ordering = 1)
button.event("SpawnWaitDialog", "WaitForCostingDlg", ordering = 2)
button.event("EndDialog", "Return", ordering = 3)
button = dialog.cancel("Cancel", "DirectoryCombo")
button.event("SpawnDialog", "CancelDlg")
dialog.control("DirectoryCombo", "DirectoryCombo", 15, 70, 272, 80,
393219, "TARGETDIR", None, "DirectoryList", None)
dialog.control("DirectoryList", "DirectoryList", 15, 90, 308, 136, 3,
"TARGETDIR", None, "PathEdit", None)
dialog.control("PathEdit", "PathEdit", 15, 230, 306, 16, 3,
"TARGETDIR", None, "Next", None)
button = dialog.pushbutton("Up", 306, 70, 18, 18, 3, "Up", None)
button.event("DirectoryListUp", "0")
button = dialog.pushbutton("NewDir", 324, 70, 30, 18, 3, "New", None)
button.event("DirectoryListNew", "0")
def add_text_styles(self):
msilib.add_data(self.db, ‘TextStyle‘,
[("DlgFont8", "Tahoma", 9, None, 0),
("DlgFontBold8", "Tahoma", 8, None, 1),
("VerdanaBold10", "Verdana", 10, None, 1),
("VerdanaRed9", "Verdana", 9, 255, 0)
])
def add_ui(self):
self.add_text_styles()
self.add_error_dialog()
self.add_fatal_error_dialog()
self.add_cancel_dialog()
self.add_exit_dialog()
self.add_user_exit_dialog()
self.add_files_in_use_dialog()
self.add_wait_for_costing_dialog()
self.add_prepare_dialog()
self.add_select_directory_dialog()
self.add_progress_dialog()
self.add_maintenance_type_dialog()
def add_upgrade_config(self, sversion):
if self.upgrade_code is not None:
msilib.add_data(self.db, ‘Upgrade‘,
[(self.upgrade_code, None, sversion, None, 513, None,
"REMOVEOLDVERSION"),
(self.upgrade_code, sversion, None, None, 257, None,
"REMOVENEWVERSION")
])
def add_user_exit_dialog(self):
dialog = distutils.command.bdist_msi.PyDialog(self.db, "UserExit",
self.x, self.y, self.width, self.height, self.modal,
self.title, "Finish", "Finish", "Finish")
dialog.title("[ProductName] installer was interrupted")
dialog.back("
上一篇:python的第五天
文章标题:cxfreeze打包python程序的方法说明(生成安装包,实现桌面快捷方式、删除快捷方式)
文章链接:http://soscw.com/essay/101241.html