import base64 import tkinter import threading from tkinter import * from tkinter import ttk import os import logging
classQnect_Quoter(object): def__init__(self): # the main window self.root = tkinter.Tk() # Title of the tool self.root.title("Qnect Quoter") # add ico from the icon.py file and delete the file after picture = open("picture.ico", "wb+") picture.write(base64.b64decode(img)) picture.close() self.root.iconbitmap("picture.ico") os.remove("picture.ico") # mainwindow size self.root.geometry("725x605") self.root.resizable(False, False)
# Create input cells for Qnect acount and passwords self.account_label = ttk.Label(self.input_frame, text="Qnect Account: ") self.account_input = ttk.Entry(self.input_frame, width=20) self.password_label = ttk.Label(self.input_frame, text="Password: ") self.password_input = ttk.Entry(self.input_frame, width=20) # The button to start quoting self.start_button = tkinter.Button(self.input_frame, command=self.start_quote, text="Start Quoting")
# Create radio buttons for selection of quoting coverages self.alignment_var = StringVar() self.alignments = ["Private Car"]
# Display textbox and scrollbar for information self.info_text = tkinter.Text(self.textbox_frame, width=85, height=28) self.scrollbar = ttk.Scrollbar(self.textbox_frame, orient="vertical", command=self.info_text.yview)
# add a process bar to the window self.pb = ttk.Progressbar(self.pb_frame, orient="horizontal", mode="determinate", length=700) self.pb_label = ttk.Label(self.pb_frame)
defstart_quote(self): global completed, listening login_thread = threading.Thread(target=LoginValidate) login_thread.start() completed = False # make sure there is only one Waiting_for_login() loop going on, otherwise will create several loops each click. ifnot listening: Waiting_for_login() listening = True defmain(): global main_window main_window = Qnect_Quoter() main_window.gui_arrang() logging.basicConfig(filename="Run.log", format='%(asctime)s %(message)s', filemode='w') logger = logging.getLogger() logger.setLevel(logging.ERROR) tkinter.mainloop() pass
defLoginValidate(): # initiate the process bar main_window.pb["value"] = 0 main_window.pb_label["text"] = "" global completed # get the inputs from the UI username = str(main_window.account_input.get()) password = str(main_window.password_input.get()) covername = str(main_window.alignment_var.get()) ifany([not username, not password, not covername]): update_info_text("Please input QNECT username, password and select a cover you wish to quote.\n") return0
global data_record, driver # validating the input file update_info_text("Loading File...\n") load_file = PrivateCarQuoting.load_data(Filename) if load_file[0] != 0: update_info_text(load_file[0]) return0 else: update_info_text("File loaded!\n") data_record = load_file[1]
# Login to Qnect update_info_text("Connecting to Qnect...\n") login_qnect = PrivateCarQuoting.Login(username, password) if login_qnect[0] != 0: update_info_text(login_qnect[0]) try: driver = login_qnect[1] driver.quit() except: pass return0 else: update_info_text("Log in Success!\n") driver = login_qnect[1] completed = True defupdate_info_text(text): main_window.info_text.insert(END, text) main_window.info_text.see(END)
# add ico from the icon.py file and delete the file after picture = open("picture.ico", "wb+") picture.write(base64.b64decode(img)) picture.close() self.root.iconbitmap("picture.ico") os.remove("picture.ico")