Skip to content

Commit

Permalink
Added QtIfwControlScript attribute onFinishedDetachedExecutions, incl…
Browse files Browse the repository at this point in the history
…uding its implementation, and a basic demo of using it from an uninstaller within the Dynamic Finish example.
  • Loading branch information
BuvinJ committed Jan 8, 2021
1 parent 5c8da89 commit 2140fb9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
1 change: 1 addition & 0 deletions distbuilder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
, QtIfwTargetDirPage \
, QtIfwSimpleTextPage \
, QtIfwWidget \
, QtIfwOnFinishedDetachedExec \
, QtIfwOnFinishedCheckbox \
, installQtIfw \
, unInstallQtIfw \
Expand Down
45 changes: 33 additions & 12 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,7 @@ def __init__( self,

self.onFinishedClickedCallbackBody = None
self.onFinishedClickedCallbackInjection = None
self.onFinishedDetachedExecutions = []
self.isAutoFinishedClickedCallbackBody = True

self.isIntroductionPageVisible = True
Expand Down Expand Up @@ -3306,7 +3307,7 @@ def __genFinishedClickedCallbackBody( self ):

prepend = _QtIfwScript.log( "finish clicked" )

# Execute custom on wizard finished/exited actions
# Execute ui bound (user controlled) finished actions
finshedCheckboxes = [ w for w in self.widgets
if isinstance( w, QtIfwOnFinishedCheckbox ) ]
if len(finshedCheckboxes) > 0:
Expand All @@ -3322,6 +3323,26 @@ def __genFinishedClickedCallbackBody( self ):
checkbox._action +
EBLK )
prepend += EBLK + EBLK

# Execute other finished actions
finshedDetachedExecs=[e for e in self.onFinishedDetachedExecutions
if isinstance( e, QtIfwOnFinishedDetachedExec )]
if len(finshedDetachedExecs) > 0:
prepend +=( TAB +
_QtIfwScript.ifBoolValue( _QtIfwScript.INTERUPTED_KEY,
isNegated=True, isMultiLine=True )
)
for ex in finshedDetachedExecs:
prepend += (
(2*TAB) +
(SBLK
if ex.event == QtIfwOnFinishedCheckbox.ON_BOTH
else _QtIfwScript.ifInstalling( isNegated =
ex.event==QtIfwOnFinishedCheckbox.ON_UNINSTALL,
isMultiLine=True ) ) +
ex._action +
(2*TAB) + EBLK )
prepend += EBLK

# Remove keep alive file
append =(
Expand Down Expand Up @@ -6698,7 +6719,7 @@ def fileName( self ):
self.name + QtIfwWidget.__FILE_ROOT_SUFFIX )

# -----------------------------------------------------------------------------
class QtIfwOnFinishedAction:
class QtIfwOnFinishedDetachedExec:

ON_INSTALL, ON_UNINSTALL, ON_BOTH = range(3)

Expand All @@ -6723,7 +6744,7 @@ class QtIfwOnFinishedAction:
__REBOOT_CMD =( "shutdown /r -t %d" if IS_WINDOWS else
"sleep %d; sudo reboot" )

# QtIfwOnFinishedAction
# QtIfwOnFinishedDetachedExec
def __init__( self, name, event=None,
ifwPackage=None,
runProgram=None, argList=None,
Expand All @@ -6732,7 +6753,7 @@ def __init__( self, name, event=None,
isReboot=False, rebootDelaySecs=2 ):

self.name = name
self.event =( QtIfwOnFinishedAction.ON_INSTALL if event is None
self.event =( QtIfwOnFinishedDetachedExec.ON_INSTALL if event is None
else event )
self.runProgram = None
self.argList = None
Expand All @@ -6753,7 +6774,7 @@ def __init__( self, name, event=None,
# or around entire commands.
# Escape quotes & backslashes for the QScript literal.
shellCmd = shellCmd.replace('\\','\\\\').replace('"','\\"')
self._action =( QtIfwOnFinishedAction.__EXEC_CMD_DETACHED_TMPLT
self._action =( QtIfwOnFinishedDetachedExec.__EXEC_CMD_DETACHED_TMPLT
% (shellCmd,) )
else :
self.runProgram = runProgram
Expand Down Expand Up @@ -6787,7 +6808,7 @@ def __setFromScript( self, script, argList ):
self.argList = argList
args =( '[%s]' % (",".join( ['"%s"' % (a,) for a in self.argList ] ),)
if self.argList else _QtIfwScript.NULL )
execTemplate = QtIfwOnFinishedAction.__SCRIPT_TMPLTS.get(
execTemplate = QtIfwOnFinishedDetachedExec.__SCRIPT_TMPLTS.get(
script.extension )
if execTemplate is None: raise Exception("Script type not supported")
self._action =(
Expand All @@ -6797,18 +6818,18 @@ def __setFromScript( self, script, argList ):

def __setAsReboot( self, rebootDelaySecs ):
self.isReboot = True
cmd = QtIfwOnFinishedAction.__REBOOT_CMD % (rebootDelaySecs,)
cmd = QtIfwOnFinishedDetachedExec.__REBOOT_CMD % (rebootDelaySecs,)
self._action =(
QtIfwOnFinishedAction.__EXEC_CMD_DETACHED_TMPLT % (cmd,) )
QtIfwOnFinishedDetachedExec.__EXEC_CMD_DETACHED_TMPLT % (cmd,) )

def __setSimpleExecDetachedAction( self ):
args = self.argList if self.argList else []
args = '[%s]' % (",".join( ['"%s"' % (a,) for a in args] ),)
self._action = QtIfwOnFinishedAction.__EXEC_DETACHED_TMPLT % (
self._action = QtIfwOnFinishedDetachedExec.__EXEC_DETACHED_TMPLT % (
self.runProgram, args )

# -----------------------------------------------------------------------------
class QtIfwOnFinishedCheckbox( QtIfwWidget, QtIfwOnFinishedAction ):
class QtIfwOnFinishedCheckbox( QtIfwWidget, QtIfwOnFinishedDetachedExec ):

__AUTO_POSITION = 0

Expand Down Expand Up @@ -6855,8 +6876,8 @@ def __init__( self, name, text=None, position=None,
position=( position if position else
QtIfwOnFinishedCheckbox.__AUTO_POSITION ),
sourcePath=QtIfwOnFinishedCheckbox.__SRC )
QtIfwOnFinishedAction.__init__( self, name,
event=QtIfwOnFinishedAction.ON_INSTALL,
QtIfwOnFinishedDetachedExec.__init__( self, name,
event=QtIfwOnFinishedDetachedExec.ON_INSTALL,
ifwPackage=ifwPackage,
runProgram=runProgram, argList=argList,
shellCmd=shellCmd, script=script,
Expand Down
13 changes: 12 additions & 1 deletion examples/hello_dynamic_finish/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from distbuilder import( RobustInstallerProcess, ConfigFactory,
QtIfwControlScript, QtIfwOnFinishedCheckbox, ExecutableScript,
QtIfwOnFinishedCheckbox, QtIfwOnFinishedDetachedExec, \
QtIfwControlScript, ExecutableScript, \
findQtIfwPackage, joinPathQtIfw,
IS_WINDOWS, IS_MACOS, QT_IFW_TARGET_DIR )

Expand Down Expand Up @@ -205,6 +206,16 @@ def showIfInstalled( checkbox, pkg, isChecked=True ):
rebootCheckbox.setChecked( False ) +
rebootCheckbox.setVisible( True )
)

# Add detached executions invoked unconditionally upon the
# completion of the uninstaller.
openPyPiPageViaOsExec = QtIfwOnFinishedDetachedExec(
"openPyPiPageViaOs", QtIfwOnFinishedDetachedExec.ON_UNINSTALL,
openViaOsPath="https://pypi.org/project/distbuilder/" )

cfg.controlScript.onFinishedDetachedExecutions = [
openPyPiPageViaOsExec
]

pkgs = cfg.packages
tkPkg = findQtIfwPackage( pkgs, TK_CONFIG_KEY )
Expand Down

0 comments on commit 2140fb9

Please sign in to comment.