Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import ttk
  3. import os
  4. import threading
  5. import queue
  6.  
  7.  
  8. the_queue = queue.Queue()
  9.  
  10. class ReportGUI:
  11.     def __init__(self, master):
  12.  
  13.         frame = Frame(master)
  14.         frame.grid()
  15.  
  16.  
  17.         self.B1 = Button(frame, text = 'Generate  Report', bg = 'blue', fg = 'white', bd = 5, command=self.PutVariablesIntoQ, font="Tahoma 9")
  18.         self.B1.grid(column = 8, row = 11, columnspan = 1, pady=(10,10), padx=7)
  19.  
  20.  
  21.  
  22.         #Loading Screen
  23.         self.pbar = ttk.Progressbar(frame)
  24.         self.pbar_label = Label(frame, text="Loading...", font="Helvetica 9 italic")
  25.  
  26.  
  27.     def PutVariablesIntoQ(self):
  28.         # Make progress bar visible and start it
  29.         self.pbar.grid(row=3, column=0, columnspan=3, padx=(4,0))
  30.         self.pbar_label.grid(row=3, column=3, columnspan=1)
  31.         self.pbar['mode'] = 'indeterminate'
  32.         self.pbar.start(20)
  33.  
  34.         self.a = self.E1.get() # get variables from GUI
  35.         self.b = self.E3.get()
  36.         self.c = self.E6.get()
  37.  
  38.         SQL_Class = ClientReportSQL(self.a, self.b) # long running blocking function that is run on another thread
  39.         the_queue.put(SQL_Class.openconnection())
  40.         the_queue.put(SQL_Class.executeSQL())
  41.  
  42.         # more functions
  43.  
  44.         if self.layer_report_var.get():
  45.             Layer_File_Class = LayerReportFile(self.clientname, SQL_Class.treaty_date)
  46.             the_queue.put(Layer_File_Class.copyfinaltemplate(self.path)) # more functions
  47.  
  48.         else:
  49.             pass
  50.  
  51.         #self.stop_program()
  52.  
  53.     def stop_program(self):
  54.         self.pbar.stop()
  55.         self.pbar['mode'] = 'determinate'
  56.         self.pbar.grid_forget()
  57.         self.pbar_label.config(text='Finished!')
  58.  
  59.  
  60. def thread_target():
  61.     while True:
  62.         task = the_queue.get()
  63.         if task is None:
  64.             return
  65.         func = task[0]
  66.         args = task[1:]
  67.         func(*args)
  68.  
  69. root = Tk()
  70. root.iconbitmap(icof)
  71. app = ReportGUI(root)
  72. root.lift()
  73.  
  74. threading.Thread(target=thread_target).start()
  75. root.mainloop()
  76.  
  77. the_queue.put(None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement