Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I know you already are familiar with this function from my previous post.
- This is the function to render main window where headerLabelTxt and headerProgPercent.
- def renderMainWindow():
- # Create Main window
- mainWindow = Tk()
- # display the menu
- mainWindow.configure(menu=menuBar)
- # create App Menu
- # need to update this control key for Windows
- mainMenu = Menu(menuBar, tearoff=0, name='windows') # name creates system app menu
- mainMenu.add_command(label="About " + appName, command=renderAboutDialog)
- mainMenu.add_separator()
- mainMenu.add_command(label="Quit " + appName, command=lambda: on_cancel_button('quit'), accelerator="Ctrl+Q")
- mainMenu.bind_all("<Control-q>", on_cancel_button)
- menuBar.add_cascade(label=appName, menu=mainMenu)
- # Create Menu Bar
- menuBar = Menu(mainWindow)
- # Create Top Frame
- topFrame = Frame(mainWindow)
- topFrame.pack(side=TOP, fill=X)
- # Add Header to Top Frame
- headerLabelTxt = StringVar()
- headerLabel = Label(topFrame, textvariable=headerLabelTxt, justify=CENTER, anchor=CENTER)
- headerLabelTxt.set('Select the software you would like to install')
- headerLabel.pack(pady=pixelRetinaMod(10))
- headerProgPercent = IntVar()
- headerProgress = Progressbar(topFrame, length=pixelRetinaMod(560), orient=HORIZONTAL, mode='determinate')
- headerProgress['variable'] = headerProgPercent
- headerProgress.pack()
- headerProgLabelTxt = StringVar()
- headerProgressLabel = Label(topFrame, textvariable=headerProgLabelTxt, foreground='#777777', justify=CENTER)
- headerProgLabelTxt.set('Click Install to Start')
- headerProgressLabel.pack(pady=(0, pixelRetinaMod(10)))
- .......
- # Here, I follow your approach.
- mainWindow.bind('<<InstallCompleteHeaderProgressBar>>', on_install_complete_header_progress_bar) # for header progress bar
- mainWindow.bind('<<InstallCompleteHeaderProgressText>>', on_install_complete_header_progress_text) # for header progress text
- mainWindow.bind('<<InstallComplete>>', on_install_complete) # this worked in updating the cancel and install button
- Here are the virtual events that I removed from function on_install_button_active which involve Tkinter widgets.
- And I followed your approach.
- # This worked
- def on_install_complete(event):
- cancelButton.destroy()
- installButton.configure(state=NORMAL)
- # This did not worked
- def on_install_complete_header_progress_bar(event):
- headerProgPercent.set(100)
- # This did not worked
- def on_install_complete_header_progress_text(event):
- headerProgLabelTxt.set('')
- headerLabelTxt.set('Installation Complete')
- And this is the function on_install_button_active, whole code
- def on_install_button_active(button, model, selectcount):
- # Main install Section
- global pulseTimer
- global installStatus
- global itemIconImage
- global view
- global headerProgress
- # set busy flag
- installStatus = 'busy'
- # Count items
- itemCount = len(titleList)
- # Disable Checkboxes and header Checkbox
- for listItem in range(itemCount):
- itemCheckBox[listItem].configure(state=DISABLED)
- headerCheckAll.configure(state=DISABLED)
- # START installing apps one by one
- # using itemSelectCount to do progress increments
- progInc = float(100 / selectcount)
- itemIncCount = 0
- headerProgPercent.set(0)
- for listItem in range(itemCount):
- # Check which items are selected True in list column 0
- itemSelected = checkItem[listItem].get()
- if itemSelected == 1 and installStateList[listItem] != 'removed':
- # set currentHeaderProgress for each process at start
- currentHeaderProgress = headerProgPercent.get()
- # With selected items ...
- headerLabelTxt.set('Installing Software ' + str(itemIncCount + 1) + ' of ' + str(selectcount))
- # Start Install software
- installError = ''
- if updateList[listItem]:
- updateText = 'Updating'
- else:
- updateText = 'Installing'
- headerProgLabelTxt.set(updateText + " " + titleList[listItem])
- # Set Focus on item
- itemCheckBox[listItem].focus_set()
- itemCheckBox[listItem].focus()
- outFileName = urlList[listItem].split('\\')[-1] # IP_ConfigServerMT64_8130027b1_ENU_windows.zip
- outFileExt = fileExtension(outFileName) # .zip
- outFile = os.path.join(appsFolder, titleList[listItem])
- # Extract, for zip files
- if outFileName:
- if outFileExt.lower() == 'zip':
- try:
- headerProgLabelTxt.set("Extracting " + titleList[listItem] + " ...")
- extract_files(outFileName, outFile, listItem, progInc)
- except:
- installError = "[Error] Could not extract %s" % outFileName
- # If installation folder exists
- if os.path.exists(outFile):
- headerProgLabelTxt.set(updateText + " " + titleList[listItem] + " ...")
- # Applications Install folder path
- appFilePath = os.path.join(outFile, 'ip')
- # Change directory to execute setup.exe
- os.chdir(appFilePath)
- try:
- get_exitcode_stdout_stderr_zip_dvd(titleList[listItem])
- except:
- installError = '[Error] Installation of %s not successful.' %titleList[listItem]
- else:
- # for DVD
- headerProgLabelTxt.set(updateText + " " + titleList[listItem] + " ...")
- appDVDPath = urlList[listItem]
- # Change directory to execute setup.exe
- os.chdir(appDVDPath)
- get_exitcode_stdout_stderr_zip_dvd(titleList[listItem])
- else:
- installError = "[Error] No ZIP/DVD file for " + titleList[listItem]
- itemProgressPercent[listItem].set(90)
- headerProgPercent.set(setHeaderProgress(listItem, progInc, currentHeaderProgress))
- # Check if component if indeed installed
- appInstallPath = os.path.join(installationDir, descriptionList[listItem], appFileList[listItem])
- if os.path.exists(appInstallPath) and not installError:
- else:
- installError = "[Error] Could not install %s" % titleList[listItem]
- # END of main item Install
- # De-select checkbox, I am now here
- checkItem[listItem].set(0)
- # Check if install ok and set icon and progress bar
- if installError == '':
- installStateList[listItem] = 'installed'
- itemProgressPercent[listItem].set(100)
- headerProgPercent.set(setHeaderProgress(listItem, progInc, currentHeaderProgress))
- else:
- installStateList[listItem] = 'error'
- itemProgressPercent[listItem].set(100)
- headerProgPercent.set(setHeaderProgress(listItem, progInc, currentHeaderProgress))
- # Set to 0 after main progress update
- itemProgressPercent[listItem].set(0)
- # If selected Inc for each item as we know not how many here
- # Move progress incrementally depending on number of install items
- itemIncCount = itemIncCount + 1
- displayInc = progInc * itemIncCount
- # Update main progress bar at the end of each item install
- headerProgPercent.set(displayInc)
- # These are the calls that involved Tkinter widget which I removed
- # Software Install Done - The End -
- # headerProgPercent.set(100) # not working?!
- # headerProgLabelTxt.set('') # not working?!
- # Followed your approach to call virtual events, Have tried when parameter to head and mark but did not work and GUI hangs/freeze
- mainWindow.event_generate('<<InstallCompleteHeaderProgressBar>>', when='tail')
- # One of the call that involved Tkinter widget which I removed
- # headerLabelTxt.set('Installation Complete') # not working?!)
- # Followed your approach to call virtual events, Have tried when parameter to head and mark but did not work and GUI hangs/freeze
- mainWindow.event_generate('<<InstallCompleteHeaderProgressText>>', when='tail')
- # Reset install status
- installStatus = 'complete'
- # This is the only call to virtual events that worked
- mainWindow.event_generate('<<InstallComplete>>', when='tail')
- refreshGui(mainWindow)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement