Advertisement
NosideedisoN

Install

Jul 15th, 2016
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.12 KB | None | 0 0
  1. I know you already are familiar with this function from my previous post.
  2. This is the function to render main window where headerLabelTxt and headerProgPercent.
  3. def renderMainWindow():
  4.     # Create Main window  
  5.     mainWindow = Tk()
  6.    
  7.      # display the menu
  8.     mainWindow.configure(menu=menuBar)
  9.  
  10.     # create App Menu
  11.     # need to update this control key for Windows
  12.     mainMenu = Menu(menuBar, tearoff=0, name='windows') # name creates system app menu
  13.     mainMenu.add_command(label="About " + appName, command=renderAboutDialog)
  14.     mainMenu.add_separator()
  15.     mainMenu.add_command(label="Quit " + appName, command=lambda: on_cancel_button('quit'), accelerator="Ctrl+Q")
  16.     mainMenu.bind_all("<Control-q>", on_cancel_button)
  17.     menuBar.add_cascade(label=appName, menu=mainMenu)
  18.    
  19.     # Create Menu Bar
  20.     menuBar = Menu(mainWindow)
  21.  
  22.     # Create Top Frame
  23.     topFrame = Frame(mainWindow)
  24.     topFrame.pack(side=TOP, fill=X)
  25.  
  26.     # Add Header to Top Frame
  27.     headerLabelTxt = StringVar()
  28.     headerLabel = Label(topFrame, textvariable=headerLabelTxt, justify=CENTER, anchor=CENTER)
  29.     headerLabelTxt.set('Select the software you would like to install')
  30.     headerLabel.pack(pady=pixelRetinaMod(10))
  31.  
  32.     headerProgPercent = IntVar()
  33.     headerProgress = Progressbar(topFrame, length=pixelRetinaMod(560), orient=HORIZONTAL, mode='determinate')
  34.     headerProgress['variable'] = headerProgPercent
  35.     headerProgress.pack()
  36.  
  37.     headerProgLabelTxt = StringVar()
  38.     headerProgressLabel = Label(topFrame, textvariable=headerProgLabelTxt, foreground='#777777', justify=CENTER)
  39.     headerProgLabelTxt.set('Click Install to Start')
  40.     headerProgressLabel.pack(pady=(0, pixelRetinaMod(10)))
  41.    
  42.     .......
  43.    
  44.     # Here, I follow your approach.
  45.     mainWindow.bind('<<InstallCompleteHeaderProgressBar>>', on_install_complete_header_progress_bar) # for header progress bar
  46.     mainWindow.bind('<<InstallCompleteHeaderProgressText>>', on_install_complete_header_progress_text) # for header progress text
  47.     mainWindow.bind('<<InstallComplete>>', on_install_complete) # this worked in updating the cancel and install button
  48.    
  49. Here are the virtual events that I removed from function on_install_button_active which involve Tkinter widgets.
  50. And I followed your approach.
  51.  
  52. # This worked
  53. def on_install_complete(event):
  54.     cancelButton.destroy()
  55.     installButton.configure(state=NORMAL)
  56.  
  57. # This did not worked
  58. def on_install_complete_header_progress_bar(event):
  59.     headerProgPercent.set(100)
  60.  
  61. # This did not worked
  62. def on_install_complete_header_progress_text(event):
  63.     headerProgLabelTxt.set('')
  64.     headerLabelTxt.set('Installation Complete')
  65.    
  66.    
  67. And this is the function on_install_button_active, whole code
  68. def on_install_button_active(button, model, selectcount):
  69.     # Main install Section
  70.     global pulseTimer
  71.     global installStatus
  72.     global itemIconImage
  73.     global view
  74.     global headerProgress
  75.  
  76.     # set busy flag
  77.     installStatus = 'busy'
  78.  
  79.     # Count items
  80.     itemCount = len(titleList)
  81.  
  82.     # Disable Checkboxes and header Checkbox
  83.     for listItem in range(itemCount):
  84.         itemCheckBox[listItem].configure(state=DISABLED)
  85.     headerCheckAll.configure(state=DISABLED)
  86.  
  87.     # START installing apps one by one
  88.  
  89.     # using itemSelectCount to do progress increments
  90.     progInc = float(100 / selectcount)
  91.     itemIncCount = 0
  92.  
  93.     headerProgPercent.set(0)
  94.  
  95.     for listItem in range(itemCount):
  96.         # Check which items are selected True in list column 0
  97.         itemSelected = checkItem[listItem].get()
  98.         if itemSelected == 1 and installStateList[listItem] != 'removed':
  99.             # set currentHeaderProgress for each process at start
  100.             currentHeaderProgress = headerProgPercent.get()
  101.  
  102.             # With selected items ...
  103.             headerLabelTxt.set('Installing Software ' + str(itemIncCount + 1) + ' of ' + str(selectcount))            
  104.  
  105.             # Start Install software
  106.             installError = ''
  107.  
  108.             if updateList[listItem]:
  109.                 updateText = 'Updating'
  110.             else:
  111.                 updateText = 'Installing'
  112.  
  113.             headerProgLabelTxt.set(updateText + " " + titleList[listItem])            
  114.  
  115.             # Set Focus on item
  116.             itemCheckBox[listItem].focus_set()
  117.             itemCheckBox[listItem].focus()
  118.  
  119.  
  120.             outFileName = urlList[listItem].split('\\')[-1]  # IP_ConfigServerMT64_8130027b1_ENU_windows.zip            
  121.             outFileExt = fileExtension(outFileName)  # .zip            
  122.             outFile = os.path.join(appsFolder, titleList[listItem])            
  123.  
  124.             # Extract, for zip files
  125.             if outFileName:
  126.                 if outFileExt.lower() == 'zip':
  127.                     try:
  128.                         headerProgLabelTxt.set("Extracting " + titleList[listItem] + " ...")                                                
  129.                         extract_files(outFileName, outFile, listItem, progInc)                                                
  130.                     except:                        
  131.                         installError = "[Error] Could not extract %s" % outFileName
  132.  
  133.  
  134.                     # If installation folder exists
  135.                     if os.path.exists(outFile):
  136.                         headerProgLabelTxt.set(updateText + " " + titleList[listItem] + " ...")
  137.                         # Applications Install folder path
  138.                         appFilePath = os.path.join(outFile, 'ip')
  139.                         # Change directory to execute setup.exe
  140.                         os.chdir(appFilePath)                        
  141.                         try:                            
  142.                             get_exitcode_stdout_stderr_zip_dvd(titleList[listItem])
  143.                         except:                            
  144.                             installError = '[Error] Installation of %s not successful.' %titleList[listItem]
  145.                 else:
  146.                     # for DVD
  147.                     headerProgLabelTxt.set(updateText + " " + titleList[listItem] + " ...")
  148.                     appDVDPath = urlList[listItem]
  149.                     # Change directory to execute setup.exe
  150.                     os.chdir(appDVDPath)
  151.                     get_exitcode_stdout_stderr_zip_dvd(titleList[listItem])                    
  152.             else:              
  153.                 installError = "[Error] No ZIP/DVD file for " + titleList[listItem]
  154.  
  155.  
  156.             itemProgressPercent[listItem].set(90)
  157.             headerProgPercent.set(setHeaderProgress(listItem, progInc, currentHeaderProgress))
  158.  
  159.             # Check if component if indeed installed
  160.             appInstallPath = os.path.join(installationDir, descriptionList[listItem], appFileList[listItem])
  161.             if os.path.exists(appInstallPath) and not installError:                
  162.             else:                
  163.                 installError = "[Error] Could not install %s" % titleList[listItem]
  164.  
  165.             # END of main item Install
  166.  
  167.             # De-select checkbox, I am now here
  168.             checkItem[listItem].set(0)
  169.  
  170.             # Check if install ok and set icon and progress bar
  171.             if installError == '':                
  172.                 installStateList[listItem] = 'installed'
  173.                 itemProgressPercent[listItem].set(100)
  174.                 headerProgPercent.set(setHeaderProgress(listItem, progInc, currentHeaderProgress))
  175.             else:                
  176.                 installStateList[listItem] = 'error'                
  177.                 itemProgressPercent[listItem].set(100)
  178.                 headerProgPercent.set(setHeaderProgress(listItem, progInc, currentHeaderProgress))
  179.                 # Set to 0 after main progress update
  180.                 itemProgressPercent[listItem].set(0)
  181.  
  182.             # If selected Inc for each item as we know not how many here
  183.             # Move progress incrementally depending on number of install items
  184.             itemIncCount = itemIncCount + 1
  185.             displayInc = progInc * itemIncCount
  186.  
  187.             # Update main progress bar at the end of each item install
  188.             headerProgPercent.set(displayInc)
  189.  
  190.     # These are the calls that involved Tkinter widget which I removed
  191.     # Software Install Done - The End -
  192.     # headerProgPercent.set(100)  # not working?!
  193.     # headerProgLabelTxt.set('')  # not working?!
  194.    
  195.     # Followed your approach to call virtual events, Have tried when parameter to head and mark but did not work and GUI hangs/freeze
  196.     mainWindow.event_generate('<<InstallCompleteHeaderProgressBar>>', when='tail')    
  197.  
  198.     # One of the call that involved Tkinter widget which I removed
  199.     # headerLabelTxt.set('Installation Complete')  # not working?!)
  200.    
  201.     # Followed your approach to call virtual events, Have tried when parameter to head and mark but did not work and GUI hangs/freeze
  202.     mainWindow.event_generate('<<InstallCompleteHeaderProgressText>>', when='tail')
  203.  
  204.     # Reset install status
  205.     installStatus = 'complete'
  206.    
  207.     # This is the only call to virtual events that worked
  208.     mainWindow.event_generate('<<InstallComplete>>', when='tail')
  209.    
  210.     refreshGui(mainWindow)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement