Skip to content

Commit

Permalink
Patched the use of scripts by QtIfwOnFinishedDetachedExec (not attach…
Browse files Browse the repository at this point in the history
…ed to QtIfwOnFinishedCheckbox).
  • Loading branch information
BuvinJ committed Jan 10, 2021
1 parent fc7186d commit 2742f6c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
6 changes: 5 additions & 1 deletion distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,11 @@ def _generate( self ) :
for w in self.widgets:
if( isinstance( w, QtIfwOnFinishedCheckbox ) and
isinstance( w.script, ExecutableScript ) ):
controlScripts.append( w.script )
controlScripts.append( w.script )
for ex in self.onFinishedDetachedExecutions:
if( isinstance( ex, QtIfwOnFinishedDetachedExec ) and
isinstance( ex.script, ExecutableScript ) ):
controlScripts.append( ex.script )
self.script += _QtIfwScript.embedResources( controlScripts )

if self.isAutoGlobals: self.__genGlobals()
Expand Down
73 changes: 54 additions & 19 deletions examples/hello_dynamic_finish/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from distbuilder import( RobustInstallerProcess, ConfigFactory,
QtIfwOnFinishedCheckbox, QtIfwOnFinishedDetachedExec, \
QtIfwControlScript, ExecutableScript, \
findQtIfwPackage, joinPathQtIfw,
IS_WINDOWS, IS_MACOS, QT_IFW_TARGET_DIR )
findQtIfwPackage, joinPathQtIfw, joinPath,
IS_WINDOWS, IS_MACOS, QT_IFW_TARGET_DIR, QT_IFW_DESKTOP_DIR )

f = masterConfigFactory = ConfigFactory()
f.productName = "Hello Dynamic Finish Example"
Expand Down Expand Up @@ -51,6 +51,23 @@ def onConfigFactory( self, key, f ):
f.distResources = [licenseName]

def onQtIfwConfig( self, cfg ):

IS_CLI_APP_INSTALLED_KEY = "isCliAppInstalled"
IS_TK_APP_INSTALLED_KEY = "isTkAppInstalled"

def customizeReadyForInstallPage( cfg, tkPkg, cliPkg ):
# Unfortunately, there is no built-in QtIFW means to determine
# which components were installed via QtScript from an uninstaller.
# To work around that: Set an installer variable(s) indicating
# component (i.e. package) selection just prior to the installation
# process, so that such will be persisted, and thus available, in
# the uninstaller.
cfg.controlScript.readyForInstallationPageOnInstall =(
QtIfwControlScript.setBoolValue( IS_TK_APP_INSTALLED_KEY,
QtIfwControlScript.isComponentSelected( tkPkg ) ) +
QtIfwControlScript.setBoolValue( IS_CLI_APP_INSTALLED_KEY,
QtIfwControlScript.isComponentSelected( cliPkg ) )
)

def customizeFinishedPage( cfg, tkPkg, cliPkg ):

Expand Down Expand Up @@ -101,14 +118,16 @@ def customizeFinishedPage( cfg, tkPkg, cliPkg ):
elif IS_MACOS :
textViewer = "TextEdit"
openLicCommand=(
'open -a {textViewer} "@TargetDir@/{licenseName}"' )
'open -a {textViewer} "@TargetDir@/{licenseName}"' )
# TODO: Add self-destruction
openLicShellScript = ExecutableScript( "openLic", script=(
'open -a {textViewer} "@TargetDir@/{licenseName}"' ) )
scripts.update( { SHELL: openLicShellScript } )
else: # IS_LINUX
textViewer = "gedit" # distro specific...
openLicCommand=(
'screen -d -m {textViewer} "@TargetDir@/{licenseName}"' )
# TODO: Add self-destruction
openLicShellScript = ExecutableScript( "openLic", script=(
'screen -d -m {textViewer} "@TargetDir@/{licenseName}"' ) )
scripts.update( { SHELL: openLicShellScript } )
Expand Down Expand Up @@ -174,7 +193,6 @@ def customizeFinishedPage( cfg, tkPkg, cliPkg ):
'<br /><br />Thank you installing the <b>Tk Example</b>!' )
CLI_INSTALLED_MSG = Script.quote(
'<br /><br />Thank you installing the <b>CLI Example</b>!' )
IS_TK_APP_INSTALLED_KEY = "isTkAppInstalled"

# helper function
def showIfInstalled( checkbox, pkg, isChecked=True ):
Expand Down Expand Up @@ -208,18 +226,33 @@ def showIfInstalled( checkbox, pkg, isChecked=True ):
rebootCheckbox.setChecked( False ) +
rebootCheckbox.setVisible( True )
)

# Unfortunately, there is no built-in QtIFW means to determine
# which components were installed via QtScript from an uninstaller.
# To work around that: Set an installer variable indicating
# component (i.e. package) selection just prior to the installation
# process, so that such will be persisted, and thus available, in
# the uninstaller.
cfg.controlScript.readyForInstallationPageOnInstall =(
Script.setBoolValue( IS_TK_APP_INSTALLED_KEY,
Script.isComponentSelected( tkPkg ) )
)


# Add onFinishedDetachedExecutions (not directly bound to gui)
# -----------------------------------------------------------------
# Define a detached execution scripts, to be invoked post
# installation and uninstallation, unconditionally.
EXAMPLE_FILE_PATH = joinPath( QT_IFW_DESKTOP_DIR, "detached" )
createExampleFileExec = QtIfwOnFinishedDetachedExec(
"createExampleFile", QtIfwOnFinishedDetachedExec.ON_INSTALL,
script = ExecutableScript( "createFile", script=(
['echo. > "%s"' % (EXAMPLE_FILE_PATH,)
,'(goto) 2>nul & del "%~f0"']
if IS_WINDOWS else
['touch "%s"' % (EXAMPLE_FILE_PATH,)
,'']) # TODO: Add self-destruction
)
)
removeExampleFileExec = QtIfwOnFinishedDetachedExec(
"removeExampleFile", QtIfwOnFinishedDetachedExec.ON_UNINSTALL,
script = ExecutableScript( "removeFile", script=(
['del /q "%s"' % (EXAMPLE_FILE_PATH,)
,'(goto) 2>nul & del "%~f0"']
if IS_WINDOWS else
['rm "%s"' % (EXAMPLE_FILE_PATH,)
,'']) # TODO: Add self-destruction
)
)

# Define a detached execution action, to be invoked post
# uninstallation, conditionally controlled by the persisted
# variable stored during installation.
Expand All @@ -228,14 +261,16 @@ def showIfInstalled( checkbox, pkg, isChecked=True ):
openViaOsPath="https://pypi.org/project/distbuilder/",
ifCondition=Script.lookupBoolValue( IS_TK_APP_INSTALLED_KEY ) )

# Add on finished detached executions (not bound to gui controls)
cfg.controlScript.onFinishedDetachedExecutions = [
openPyPiPageViaOsExec
createExampleFileExec
, removeExampleFileExec
, openPyPiPageViaOsExec
]

pkgs = cfg.packages
tkPkg = findQtIfwPackage( pkgs, TK_CONFIG_KEY )
cliPkg = findQtIfwPackage( pkgs, CLI_CONFIG_KEY )
cliPkg = findQtIfwPackage( pkgs, CLI_CONFIG_KEY )
customizeReadyForInstallPage( cfg, tkPkg, cliPkg )
customizeFinishedPage( cfg, tkPkg, cliPkg )

p = BuildProcess( masterConfigFactory, pyPkgConfigFactoryDict=pkgFactories,
Expand Down

0 comments on commit 2742f6c

Please sign in to comment.