예제 #1
0
    def select_db(self,table,column,value,entry):

        Connect_Brisco_DB = Connect_DB('postgres','postgres',self.ip_add,self.psswd)
        cur1 = Connect_Brisco_DB.crsr()

        sql = 'SELECT %s FROM %s WHERE %s' % (entry,table,column) + ' = %s'
        cur1.execute(sql, (value, ))

        row = cur1.fetchall()
        cur1.close()
        return row
예제 #2
0
    def initializeLists(self,table):
        Connect_Brisco_DB = Connect_DB('postgres','postgres',self.ip_add,self.psswd)
        cur1 = Connect_Brisco_DB.crsr()

        query = 'SELECT * from "{}"'.format(table)
        cur1.execute(query)
        rows = cur1.fetchall()
        rows=sorted(rows)
        sorted_list = map(list, itertools.izip_longest(*rows))
        if table == 'owner_db':
            table1 = 'barkies2018_db'
            query = 'select loggingco from "{}"'.format(table1)
            cur1.execute(query)
            rows = cur1.fetchall()
            t_list  =[str(x[0]) for x in rows]
            self.loggingco_list =list(set(t_list))
        cur1.close()
        return sorted_list
from Connect_Brisco_DB import Connect_DB

Connect_Brisco_DB = Connect_DB('postgres', 'postgres', '192.168.0.200',
                               'coffeegood')
cur1 = Connect_Brisco_DB.crsr()
cur1.execute("DELETE FROM testscale")
예제 #4
0
    def __init__(self, master):

        cwd = os.getcwd()
        self.userDir = 'Cindy'

        self.master = master
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Values for all in layout~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        buttoncol = 'light slate gray'
        TitleFont = ("Courier", 20, "bold")
        paddyTitle = (0, 10)
        self.ip_add = '192.168.0.200'
        self.psswd = 'coffeegood'
        self.table = 'barkies2018_db'
        self.TopDir = 'Cindys Awesome Folder'
        self.Connect_Brisco_DB = Connect_DB('postgres', 'postgres',
                                            self.ip_add, self.psswd)

        #Create frames
        self.frame1 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame1.pack(side=LEFT, fill=Y)
        self.frame2 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame2.pack(side=TOP, fill=BOTH, ipady=20)
        self.frame3 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame3.pack(side=TOP, fill=BOTH, ipady=10)
        self.frame4 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame4.pack(side=TOP, fill=BOTH, expand=Y)

        # Frame 1 Widgets
        self.img = Image.open("Brisco_logo.png")
        self.tk_img = ImageTk.PhotoImage(self.img)
        self.label_image = Label(self.frame1,
                                 image=self.tk_img,
                                 borderwidth=2,
                                 relief='raised')
        # self.Comment_box = Text(self.frame1,width = 50)

        #Layout Widgets frame 1
        self.label_image.grid(row=0, column=0, padx=40)
        # self.Comment_box.grid(row=1,column=0,pady = )

        # Label Widgets
        self.label_CSV = Label(self.frame2, text='Export SpreadSheets')
        self.label_CSV.config(font=TitleFont, relief='sunken')
        self.label_year = Label(self.frame2, text="Year")
        self.label_month = Label(self.frame2, text="Month")
        self.label_day = Label(self.frame2, text="Day")
        self.label_folder = Label(self.frame2, text="Folder")
        self.label_Fname = Label(self.frame2, text="Filename")

        # Button widgets

        self.button_printGov = Button(self.frame2,
                                      text="Gov CSV",
                                      command=self.Create_GovCSV)
        self.button_printGov.config(bg=buttoncol, padx=5, width=20)
        self.button_barkies = Button(self.frame2,
                                     text="Full Barkies",
                                     command=self.Create_barkiesCSV)
        self.button_barkies.config(bg=buttoncol, padx=5, width=20)
        self.button_VbyS = Button(self.frame2,
                                  text="Volume by Supplier",
                                  command=self.Create_VbySCSV)
        self.button_VbyS.config(bg=buttoncol, padx=5, width=20)

        self.Dir_to_Save = Button(self.frame2,
                                  text="Browse",
                                  command=self.Browse_dir)

        # text entry Widgets
        self.Dir_entry = Entry(self.frame2)
        self.Year_entry = Entry(self.frame2)
        self.Fname_entry = Entry(self.frame2)

        #Drop down menu Widgets
        self.DD_L_month = [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
            'Oct', 'Nov', 'Dec'
        ]

        # self.DD_month = self.Create_DropDown()
        self.var1 = StringVar(self.frame2)
        self.test_dd = self.Create_DropDown(self.var1, self.DD_L_month,
                                            self.frame2)

        #initial values in entry boxes
        self.Dir_entry.insert(0, cwd)
        self.Year_entry.insert(0, "2017")

        self.Dir_entry_row = 1
        self.Fname_entry_row = 2

        #Radio Button Widgets Frame 2
        self.radiovar = IntVar(self.frame2)

        self.RadioAuto = Radiobutton(self.frame2,
                                     text="Automatic Folder Creation",
                                     variable=self.radiovar,
                                     value=1)
        self.RadioManual = Radiobutton(self.frame2,
                                       text="Manually Choose Folder",
                                       variable=self.radiovar,
                                       value=2)
        self.radiovar.set(1)

        #Layout Widgets frame 2
        self.label_CSV.grid(row=0,
                            column=0,
                            columnspan=3,
                            pady=paddyTitle,
                            sticky=W)

        self.label_folder.grid(row=1, column=0, sticky=W)
        self.Dir_entry.grid(row=1, column=1, sticky='ew')

        self.label_Fname.grid(row=2, column=0, sticky=W)
        self.Fname_entry.grid(row=2, column=1, sticky='ew')
        self.label_year.grid(row=3, column=0, sticky=W)
        self.Year_entry.grid(row=3, column=1, sticky='ew')
        self.label_month.grid(row=4, column=0, sticky=W)
        self.test_dd.grid(row=4, column=1, sticky='ew')

        self.button_printGov.grid(row=5, column=0, sticky='ew', pady=(10, 0))
        self.button_barkies.grid(row=5, column=1, sticky='ew', pady=(10, 0))
        self.button_VbyS.grid(row=5, column=2, sticky='ew', pady=(10, 0))

        self.Dir_to_Save.grid(row=1, column=2)

        self.RadioAuto.grid(row=1, column=3, sticky=W)
        self.RadioManual.grid(row=2, column=3, sticky=W)
        #Start Frame 3
        self.label_frame3 = Label(self.frame3,
                                  text='Edit Database',
                                  relief='sunken')
        self.label_frame3.config(font=TitleFont)

        self.Edit_DD_lst = [
            'Block #', 'Date', 'Population', 'Load Slip #', 'Sample Load',
            'TM9 Ticket', 'Owner', 'Disposition/FMA #', 'Working Circle',
            'Logging Co.', 'Hauling Contractor', 'Truck License Plate #',
            'Truck #', 'Truck Axle', 'Gross Weight', 'Tare Weight',
            'Net Weight'
        ]

        #Labels for frame 3
        self.label_searchBy = Label(self.frame3, text='TM9 to Search for')
        self.label_Colchange = Label(self.frame3, text='Value to Edit')
        self.label_valtoEnter = Label(self.frame3, text='New Value')

        #Widgets for menus for frame 3
        self.confirmEdit = Button(self.frame3,
                                  text='Confirm Edit',
                                  command=self.EditDB,
                                  bg=buttoncol,
                                  width=21)
        self.DeleteEntry = Button(self.frame3,
                                  text='Delete Entry',
                                  command=self.Del_entry,
                                  bg=buttoncol,
                                  width=21)
        self.var_for_edit = StringVar(self.frame3)
        self.dd_edit_db = self.Create_DropDown(self.var_for_edit,
                                               self.Edit_DD_lst, self.frame3)
        self.enterTM9_forEdit = Entry(self.frame3, width=26)
        self.replace_val = Entry(self.frame3, width=26)

        #Layout for frame 3
        rown = 0
        coln = 0
        self.label_frame3.grid(row=0, column=0, pady=paddyTitle, ipadx=50)
        # coln = coln + 1
        self.label_searchBy.grid(row=1, column=coln, sticky=W)
        self.enterTM9_forEdit.grid(row=1, column=coln, sticky=E)
        self.label_valtoEnter.grid(row=2, column=coln, sticky=W)
        self.replace_val.grid(row=2, column=coln, sticky=E)
        self.label_Colchange.grid(row=3, column=coln, sticky=W)
        self.dd_edit_db.grid(row=3, column=coln, sticky=E)

        self.confirmEdit.grid(row=4, column=0, sticky=W)
        self.DeleteEntry.grid(row=4, column=0, sticky=E)

        #Labels for Frame 4
        labellist = [
            'TM9', 'Total Volume Barkies', 'Avg pc Barkies', 'Net Wgt',
            '# of Pcs', 'conversions', 'Total Volume SawLogs',
            'Avg pc Sawlogs', 'Sawlogs/Returns', 'Pole Material', 'rejects'
        ]

        self.label_frame4 = Label(self.frame4,
                                  text='Scaler Information',
                                  relief='sunken')
        self.label_frame4.config(font=TitleFont)

        indx = 0
        self.inputTM9_label = Label(self.frame4,
                                    text=str(labellist[indx]),
                                    padx=10)
        indx = indx + 1
        self.TotalVol_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.AvgpcBark_label = Label(self.frame4,
                                     text=labellist[indx],
                                     padx=10)
        indx = indx + 1
        self.NetWgt_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.numPcs_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.Conversion_label = Label(self.frame4,
                                      text=labellist[indx],
                                      padx=10)
        indx = indx + 1
        self.TotV_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.AvgpcSaw_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.returns_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.poleMat_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.rejects_label = Label(self.frame4, text=labellist[indx], padx=10)

        #Widgets for Frame 4
        self.confirmEntry = Button(self.frame4,
                                   text='Confirm Entry',
                                   command=self.EnterScaler,
                                   bg=buttoncol)
        self.enterTM9_enter = Entry(self.frame4)
        self.enterTM9_enter.config(bd=5, relief='sunken')
        self.inputTM9_enter = Entry(self.frame4)
        self.TotalVol_enter = Entry(self.frame4)
        self.AvgpcBark_enter = Entry(self.frame4)
        self.NetWgt_enter = Entry(self.frame4)
        self.numPcs_enter = Entry(self.frame4)
        self.Conversion_enter = Entry(self.frame4)
        self.TotV_enter = Entry(self.frame4)
        self.AvgpcSaw_enter = Entry(self.frame4)
        self.returns_enter = Entry(self.frame4)
        self.poleMat_enter = Entry(self.frame4)
        self.rejects_enter = Entry(self.frame4)

        #Layout for frame 4
        rownum = 4
        padX = 10
        self.label_frame4.grid(row=0, column=0, pady=20, columnspan=2)
        self.confirmEntry.grid(row=7, column=0, sticky='ew')

        self.inputTM9_enter.grid(row=1, column=0, padx=padX, pady=(0, 20))
        self.TotalVol_enter.grid(row=rownum, column=0, padx=padX)
        self.AvgpcBark_enter.grid(row=rownum, column=1, padx=padX)
        self.NetWgt_enter.grid(row=rownum, column=2, padx=padX)
        self.numPcs_enter.grid(row=rownum, column=3, padx=padX)
        self.Conversion_enter.grid(row=rownum, column=4, padx=padX)
        self.TotV_enter.grid(row=(rownum + 2), column=0, padx=padX, pady=10)
        self.AvgpcSaw_enter.grid(row=(rownum + 2),
                                 column=1,
                                 padx=padX,
                                 pady=10)
        self.returns_enter.grid(row=(rownum + 2), column=2, padx=padX, pady=10)
        self.poleMat_enter.grid(row=(rownum + 2), column=3, padx=padX, pady=10)
        self.rejects_enter.grid(row=(rownum + 2), column=4, padx=padX, pady=10)

        #Label layout for frame 4
        rownum = 3
        self.inputTM9_label.grid(row=0, column=0, sticky=S)
        self.TotalVol_label.grid(row=rownum, column=0)
        self.AvgpcBark_label.grid(row=rownum, column=1)
        self.NetWgt_label.grid(row=rownum, column=2)
        self.numPcs_label.grid(row=rownum, column=3)
        self.Conversion_label.grid(row=(rownum), column=4)
        self.TotV_label.grid(row=(rownum + 2), column=0)
        self.AvgpcSaw_label.grid(row=(rownum + 2), column=1)
        self.returns_label.grid(row=(rownum + 2), column=2)
        self.poleMat_label.grid(row=(rownum + 2), column=3)
        self.rejects_label.grid(row=(rownum + 2), column=4)

        self.master.bind('<Escape>', lambda e: self.master.destroy())
예제 #5
0
class CindyProgram:
    def __init__(self, master):

        cwd = os.getcwd()
        self.userDir = 'Cindy'

        self.master = master
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Values for all in layout~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        buttoncol = 'light slate gray'
        TitleFont = ("Courier", 20, "bold")
        paddyTitle = (0, 10)
        self.ip_add = '192.168.0.200'
        self.psswd = 'coffeegood'
        self.table = 'barkies2018_db'
        self.TopDir = 'Cindys Awesome Folder'
        self.Connect_Brisco_DB = Connect_DB('postgres', 'postgres',
                                            self.ip_add, self.psswd)

        #Create frames
        self.frame1 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame1.pack(side=LEFT, fill=Y)
        self.frame2 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame2.pack(side=TOP, fill=BOTH, ipady=20)
        self.frame3 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame3.pack(side=TOP, fill=BOTH, ipady=10)
        self.frame4 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame4.pack(side=TOP, fill=BOTH, expand=Y)

        # Frame 1 Widgets
        self.img = Image.open("Brisco_logo.png")
        self.tk_img = ImageTk.PhotoImage(self.img)
        self.label_image = Label(self.frame1,
                                 image=self.tk_img,
                                 borderwidth=2,
                                 relief='raised')
        # self.Comment_box = Text(self.frame1,width = 50)

        #Layout Widgets frame 1
        self.label_image.grid(row=0, column=0, padx=40)
        # self.Comment_box.grid(row=1,column=0,pady = )

        # Label Widgets
        self.label_CSV = Label(self.frame2, text='Export SpreadSheets')
        self.label_CSV.config(font=TitleFont, relief='sunken')
        self.label_year = Label(self.frame2, text="Year")
        self.label_month = Label(self.frame2, text="Month")
        self.label_day = Label(self.frame2, text="Day")
        self.label_folder = Label(self.frame2, text="Folder")
        self.label_Fname = Label(self.frame2, text="Filename")

        # Button widgets

        self.button_printGov = Button(self.frame2,
                                      text="Gov CSV",
                                      command=self.Create_GovCSV)
        self.button_printGov.config(bg=buttoncol, padx=5, width=20)
        self.button_barkies = Button(self.frame2,
                                     text="Full Barkies",
                                     command=self.Create_barkiesCSV)
        self.button_barkies.config(bg=buttoncol, padx=5, width=20)
        self.button_VbyS = Button(self.frame2,
                                  text="Volume by Supplier",
                                  command=self.Create_VbySCSV)
        self.button_VbyS.config(bg=buttoncol, padx=5, width=20)

        self.Dir_to_Save = Button(self.frame2,
                                  text="Browse",
                                  command=self.Browse_dir)

        # text entry Widgets
        self.Dir_entry = Entry(self.frame2)
        self.Year_entry = Entry(self.frame2)
        self.Fname_entry = Entry(self.frame2)

        #Drop down menu Widgets
        self.DD_L_month = [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
            'Oct', 'Nov', 'Dec'
        ]

        # self.DD_month = self.Create_DropDown()
        self.var1 = StringVar(self.frame2)
        self.test_dd = self.Create_DropDown(self.var1, self.DD_L_month,
                                            self.frame2)

        #initial values in entry boxes
        self.Dir_entry.insert(0, cwd)
        self.Year_entry.insert(0, "2017")

        self.Dir_entry_row = 1
        self.Fname_entry_row = 2

        #Radio Button Widgets Frame 2
        self.radiovar = IntVar(self.frame2)

        self.RadioAuto = Radiobutton(self.frame2,
                                     text="Automatic Folder Creation",
                                     variable=self.radiovar,
                                     value=1)
        self.RadioManual = Radiobutton(self.frame2,
                                       text="Manually Choose Folder",
                                       variable=self.radiovar,
                                       value=2)
        self.radiovar.set(1)

        #Layout Widgets frame 2
        self.label_CSV.grid(row=0,
                            column=0,
                            columnspan=3,
                            pady=paddyTitle,
                            sticky=W)

        self.label_folder.grid(row=1, column=0, sticky=W)
        self.Dir_entry.grid(row=1, column=1, sticky='ew')

        self.label_Fname.grid(row=2, column=0, sticky=W)
        self.Fname_entry.grid(row=2, column=1, sticky='ew')
        self.label_year.grid(row=3, column=0, sticky=W)
        self.Year_entry.grid(row=3, column=1, sticky='ew')
        self.label_month.grid(row=4, column=0, sticky=W)
        self.test_dd.grid(row=4, column=1, sticky='ew')

        self.button_printGov.grid(row=5, column=0, sticky='ew', pady=(10, 0))
        self.button_barkies.grid(row=5, column=1, sticky='ew', pady=(10, 0))
        self.button_VbyS.grid(row=5, column=2, sticky='ew', pady=(10, 0))

        self.Dir_to_Save.grid(row=1, column=2)

        self.RadioAuto.grid(row=1, column=3, sticky=W)
        self.RadioManual.grid(row=2, column=3, sticky=W)
        #Start Frame 3
        self.label_frame3 = Label(self.frame3,
                                  text='Edit Database',
                                  relief='sunken')
        self.label_frame3.config(font=TitleFont)

        self.Edit_DD_lst = [
            'Block #', 'Date', 'Population', 'Load Slip #', 'Sample Load',
            'TM9 Ticket', 'Owner', 'Disposition/FMA #', 'Working Circle',
            'Logging Co.', 'Hauling Contractor', 'Truck License Plate #',
            'Truck #', 'Truck Axle', 'Gross Weight', 'Tare Weight',
            'Net Weight'
        ]

        #Labels for frame 3
        self.label_searchBy = Label(self.frame3, text='TM9 to Search for')
        self.label_Colchange = Label(self.frame3, text='Value to Edit')
        self.label_valtoEnter = Label(self.frame3, text='New Value')

        #Widgets for menus for frame 3
        self.confirmEdit = Button(self.frame3,
                                  text='Confirm Edit',
                                  command=self.EditDB,
                                  bg=buttoncol,
                                  width=21)
        self.DeleteEntry = Button(self.frame3,
                                  text='Delete Entry',
                                  command=self.Del_entry,
                                  bg=buttoncol,
                                  width=21)
        self.var_for_edit = StringVar(self.frame3)
        self.dd_edit_db = self.Create_DropDown(self.var_for_edit,
                                               self.Edit_DD_lst, self.frame3)
        self.enterTM9_forEdit = Entry(self.frame3, width=26)
        self.replace_val = Entry(self.frame3, width=26)

        #Layout for frame 3
        rown = 0
        coln = 0
        self.label_frame3.grid(row=0, column=0, pady=paddyTitle, ipadx=50)
        # coln = coln + 1
        self.label_searchBy.grid(row=1, column=coln, sticky=W)
        self.enterTM9_forEdit.grid(row=1, column=coln, sticky=E)
        self.label_valtoEnter.grid(row=2, column=coln, sticky=W)
        self.replace_val.grid(row=2, column=coln, sticky=E)
        self.label_Colchange.grid(row=3, column=coln, sticky=W)
        self.dd_edit_db.grid(row=3, column=coln, sticky=E)

        self.confirmEdit.grid(row=4, column=0, sticky=W)
        self.DeleteEntry.grid(row=4, column=0, sticky=E)

        #Labels for Frame 4
        labellist = [
            'TM9', 'Total Volume Barkies', 'Avg pc Barkies', 'Net Wgt',
            '# of Pcs', 'conversions', 'Total Volume SawLogs',
            'Avg pc Sawlogs', 'Sawlogs/Returns', 'Pole Material', 'rejects'
        ]

        self.label_frame4 = Label(self.frame4,
                                  text='Scaler Information',
                                  relief='sunken')
        self.label_frame4.config(font=TitleFont)

        indx = 0
        self.inputTM9_label = Label(self.frame4,
                                    text=str(labellist[indx]),
                                    padx=10)
        indx = indx + 1
        self.TotalVol_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.AvgpcBark_label = Label(self.frame4,
                                     text=labellist[indx],
                                     padx=10)
        indx = indx + 1
        self.NetWgt_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.numPcs_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.Conversion_label = Label(self.frame4,
                                      text=labellist[indx],
                                      padx=10)
        indx = indx + 1
        self.TotV_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.AvgpcSaw_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.returns_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.poleMat_label = Label(self.frame4, text=labellist[indx], padx=10)
        indx = indx + 1
        self.rejects_label = Label(self.frame4, text=labellist[indx], padx=10)

        #Widgets for Frame 4
        self.confirmEntry = Button(self.frame4,
                                   text='Confirm Entry',
                                   command=self.EnterScaler,
                                   bg=buttoncol)
        self.enterTM9_enter = Entry(self.frame4)
        self.enterTM9_enter.config(bd=5, relief='sunken')
        self.inputTM9_enter = Entry(self.frame4)
        self.TotalVol_enter = Entry(self.frame4)
        self.AvgpcBark_enter = Entry(self.frame4)
        self.NetWgt_enter = Entry(self.frame4)
        self.numPcs_enter = Entry(self.frame4)
        self.Conversion_enter = Entry(self.frame4)
        self.TotV_enter = Entry(self.frame4)
        self.AvgpcSaw_enter = Entry(self.frame4)
        self.returns_enter = Entry(self.frame4)
        self.poleMat_enter = Entry(self.frame4)
        self.rejects_enter = Entry(self.frame4)

        #Layout for frame 4
        rownum = 4
        padX = 10
        self.label_frame4.grid(row=0, column=0, pady=20, columnspan=2)
        self.confirmEntry.grid(row=7, column=0, sticky='ew')

        self.inputTM9_enter.grid(row=1, column=0, padx=padX, pady=(0, 20))
        self.TotalVol_enter.grid(row=rownum, column=0, padx=padX)
        self.AvgpcBark_enter.grid(row=rownum, column=1, padx=padX)
        self.NetWgt_enter.grid(row=rownum, column=2, padx=padX)
        self.numPcs_enter.grid(row=rownum, column=3, padx=padX)
        self.Conversion_enter.grid(row=rownum, column=4, padx=padX)
        self.TotV_enter.grid(row=(rownum + 2), column=0, padx=padX, pady=10)
        self.AvgpcSaw_enter.grid(row=(rownum + 2),
                                 column=1,
                                 padx=padX,
                                 pady=10)
        self.returns_enter.grid(row=(rownum + 2), column=2, padx=padX, pady=10)
        self.poleMat_enter.grid(row=(rownum + 2), column=3, padx=padX, pady=10)
        self.rejects_enter.grid(row=(rownum + 2), column=4, padx=padX, pady=10)

        #Label layout for frame 4
        rownum = 3
        self.inputTM9_label.grid(row=0, column=0, sticky=S)
        self.TotalVol_label.grid(row=rownum, column=0)
        self.AvgpcBark_label.grid(row=rownum, column=1)
        self.NetWgt_label.grid(row=rownum, column=2)
        self.numPcs_label.grid(row=rownum, column=3)
        self.Conversion_label.grid(row=(rownum), column=4)
        self.TotV_label.grid(row=(rownum + 2), column=0)
        self.AvgpcSaw_label.grid(row=(rownum + 2), column=1)
        self.returns_label.grid(row=(rownum + 2), column=2)
        self.poleMat_label.grid(row=(rownum + 2), column=3)
        self.rejects_label.grid(row=(rownum + 2), column=4)

        self.master.bind('<Escape>', lambda e: self.master.destroy())

    '''
    ~~~~~~~~~~~~~~~~~~~~~~~~~ GUI METHODS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '''

    def Del_entry(self):
        from psycopg2 import sql
        import tkMessageBox

        cur = self.Connect_Brisco_DB.crsr()

        if self.enterTM9_forEdit.get():
            tm9_str = self.enterTM9_forEdit.get()
            sql_statement = sql.SQL(
                "DELETE FROM {0} WHERE tm9_ticket = %s").format(
                    sql.Identifier(self.table))
            self.cur.execute(sql_statement, (tm9_str, ))
        else:
            sql_statement = sql.SQL(
                "DELETE FROM {0} WHERE tm9_ticket IS NULL").format(
                    sql.Identifier(self.table))
            self.cur.execute(sql_statement)

        cur.close()

    def Create_GovCSV(self):
        B = self.setup_extract('Load', 'Summary')
        B.WriteGovCSV()

    def Create_barkiesCSV(self):

        B = self.setup_extract('Barkies', 'Hauling')
        B.WriteHaulSummaryCSV()

    def Create_VbySCSV(self):
        B = self.setup_extract('Volume', 'by', 'Supplier')
        B.WriteVbySCSV()

    def MakeFolderforSave(self, EntryDir, year):

        import errno

        directory = os.path.join(r'C:\Users', self.userDir, 'Documents',
                                 self.TopDir, EntryDir, year)

        try:
            os.makedirs(directory)
            return directory

        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        return directory

    def setup_extract(self, *args):

        t_month = self.var1.get()
        month_num = self.DD_L_month.index(t_month) + 1
        year_num = int(self.Year_entry.get())
        self.Fname_entry.delete(0, 'end')
        s = "_"
        t_year = self.Year_entry.get()

        lst = []
        if args:
            for arg in args:
                lst.append(arg)
            lst_new = [t_month, t_year] + lst

            seq = tuple(lst_new)
        else:
            seq = (t_month, t_year)

        t_fname1 = s.join(seq)
        t_fname2 = ".csv"
        t_fname = t_fname1 + t_fname2

        #Folder Creation
        if self.radiovar.get() == 1:
            dirPrint = self.MakeFolderforSave(s.join(tuple(lst)),
                                              self.Year_entry.get())
        else:
            dirPrint = self.Dir_entry.get()

        self.Fname_entry.insert(0, t_fname)
        full_file = os.path.join(dirPrint, t_fname)

        DB_instance = self.Connect_Brisco_DB
        A = ExtractCSV(DB_instance, full_file, month_num, year_num)
        return A

    def Browse_dir(self):

        directory = tkFileDialog.askdirectory()
        self.Dir_entry.delete(0, 'end')
        self.Dir_entry.insert(0, directory)

    def Create_DropDown(self, DDvar, DDLst, frameName):

        DDvar.set(DDLst[0])
        DDmenu = OptionMenu(frameName, DDvar, *DDLst)
        return DDmenu

    def EditDB(self):

        cur = self.Connect_Brisco_DB.crsr()

        DB_list = [
            'blocknum',
            'daterecieved',
            'poploadslip',
            'count',
            'sampleloads',
            'tm9_ticket',
            'owner',
            'disposition_fmanum',
            'workingcircle',
            'loggingco',
            'haulingcontractor',
            'truckplate',
            'trucknum',
            'truckaxle',
            'grossweight',
            'tareweight',
            'netweight',
        ]

        list_for_int = [
            'poploadslip',
            'count',
            'truckaxle',
            'grossweight',
            'tareweight',
            'netweight',
        ]

        get_val = self.replace_val.get()
        dict_for_Edit = dict(zip(self.Edit_DD_lst, DB_list))
        val_to_chng = dict_for_Edit[self.var_for_edit.get()]

        TM9_strng = self.enterTM9_forEdit.get()

        is_int = [int(get_val) for x in list_for_int if val_to_chng in x]

        if not is_int:
            final_replace = get_val

        else:
            final_replace = is_int[0]

        sql_statement = 'UPDATE barkies2018_db SET (%s) = %s WHERE tm9_ticket = %s;'

        cur.execute(sql_statement, (AsIs(val_to_chng), (get_val, ), TM9_strng))

        cur.close()

    def EnterScaler(self):

        cur = self.Connect_Brisco_DB.crsr()
        Update_Scaler_keys = [
            'numpcsreceived', 'logsreject', 'totalvol', 'avgpc', 'conversion',
            'totalvolsaw', 'avgpcsaw', 'returnssaw', 'polemat'
        ]
        Update_Scaler_values = [
            self.numPcs_enter.get(),
            self.rejects_enter.get(),
            self.TotalVol_enter.get(),
            self.AvgpcBark_enter.get(),
            self.Conversion_enter.get(),
            self.TotV_enter.get(),
            self.AvgpcSaw_enter.get(),
            self.returns_enter.get(),
            self.poleMat_enter.get()
        ]
        Update_Scaler_values = [
            x if x != '' else None for x in Update_Scaler_values
        ]
        dictionary = dict(zip(Update_Scaler_keys, Update_Scaler_values))
        columns = dictionary.keys()
        values = [dictionary[column] for column in columns]
        insert_statement = 'UPDATE barkies2018_db SET (%s) = %s WHERE tm9_ticket = %s;'
        strng = self.inputTM9_enter.get()
        cur.execute(insert_statement,
                    (AsIs(','.join(columns)), tuple(values), strng))

        cur.close()
예제 #6
0
    def __init__(self, master):

        from PIL import Image, ImageTk
        self.master = master
        '''
        ~~~~~~~~~~~~~~~ Connect to Database and initialize Listst ~~~~~~~~~~~~~~
        '''
        self.Connect_Brisco_DB = Connect_DB('postgres', 'postgres',
                                            '192.168.0.200', 'coffeegood')
        self.cur1 = self.Connect_Brisco_DB.crsr()

        # self.loggingco_list =[]
        self.init_list_truck = self.initializeLists('truckers_db')
        self.init_list_owner = self.initializeLists('owner_db')
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~ Initialize Frames ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        self.frame1 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame1.grid(row=0, column=0, sticky='ew')

        self.frame2 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame2.grid(row=1, column=0, sticky='ew', ipady=20)

        self.frame3 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame3.grid(row=2, column=0, sticky='ew', ipady=20)

        self.frame4 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame4.grid(row=3, column=0, sticky='ew', ipady=20)

        self.frame5 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame5.grid(row=0, column=1, sticky='nsew')

        self.frame6 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame6.grid(row=1, column=1, sticky='nsew', rowspan=3)

        self.frame7 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame7.grid(row=0, column=2, rowspan=4, sticky='nwes')

        #list of dictionaries for trucks in the yard and info attached to them
        self.Lst_truckInfo = []
        '''
        ~~~~~~~~~~~~~~~ Create initial vals for comboboxes ~~~~~~~~~~~~~~~
        '''
        self.owner_combo_val = StringVar()
        self.FMA_combo_val = StringVar()
        self.wCircle_combo_val = StringVar()
        self.block_combo_val = StringVar()
        self.logCo_combo_val = StringVar()
        self.truckLicense_combo_val = StringVar()
        self.truckNum_combo_val = StringVar()
        self.axle_combo_val = StringVar()
        self.hauledBy_combo_val = StringVar()
        self.popDD_val = StringVar()
        self.sampleDD_val = StringVar()
        self.loggingCo_combo_val = StringVar()
        self.date_entry_var = StringVar()
        self.timeIn_entry_var = StringVar()
        self.timeOut_entry_var = StringVar()
        self.gross_weight_entry_var = StringVar()
        self.tare_weight_entry_var = StringVar()
        self.net_weight_entry_var = StringVar()
        self.loadNum_entry_var = StringVar()
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 1  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = 1

        framenum = self.frame1
        colm = 0
        rown = 0
        f1_lst_labels = ["TM9 Ticket", "Block #", "Pieces"]

        for strng in f1_lst_labels:
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", 20, "bold"), W)
            rown = rown + 1

        colm = 1
        rown = 0
        pddx = (90, 0)
        self.TM9_entry_var = StringVar()
        self.numPieces_entry_var = StringVar()
        self.blockNum_entry_var = StringVar()

        self.TM9_entry = self.create_place_entry(framenum, self.TM9_entry_var,
                                                 rown, colm,
                                                 ("Courier", 16, "bold"), 20,
                                                 E, pddx)
        rown = rown + 1
        self.blockNum_entry = self.create_place_entry(framenum,
                                                      self.blockNum_entry_var,
                                                      rown, colm,
                                                      ("Courier", 16, "bold"),
                                                      40, E, pddx)
        rown = rown + 1
        self.numPieces_entry = self.create_place_entry(
            framenum, self.numPieces_entry_var, rown, colm,
            ("Courier", 16, "bold"), None, E, pddx)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 2  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        framenum = self.frame2
        #labels
        colm = 0
        rown = 0
        f2_lst_labels = [
            "Truck #", "License Plate ", "Hauling Contractor", "Truck Axle"
        ]

        for strng in f2_lst_labels:
            if rown == 0:
                fnt_size = 20
            else:
                fnt_size = 16
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", fnt_size, "bold"), W)
            rown = rown + 1

        List_frame2 = self.initializeLists('truckers_db')

        #Menus
        rown = 0
        colm = 1
        pddx = None
        self.truckNum_combo = self.create_place_combo(
            framenum, self.init_list_truck[0], self.truckNum_combo_val, rown,
            colm, ("Courier", 20, "bold"), "truck", W, pddx)
        rown = rown + 1
        self.truckLicense_combo = self.create_place_combo(
            framenum, self.init_list_truck[1], self.truckLicense_combo_val,
            rown, colm, ("Courier", 16, "bold"), "truck", W, pddx)
        rown = rown + 1
        self.hauledBy_combo = self.create_place_combo(
            framenum, self.init_list_truck[2], self.hauledBy_combo_val, rown,
            colm, ("Courier", 16, "bold"), "truck", W, pddx)
        rown = rown + 1
        self.axle_combo = self.create_place_combo(
            framenum, self.init_list_truck[3], self.axle_combo_val, rown, colm,
            ("Courier", 16, "bold"), "truck", W, pddx)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 3  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        framenum = self.frame3
        colm = 0
        rown = 0
        f3_lst_labels = [
            "Owner", "FMA #", "Working Circle", "Logging Contractor"
        ]
        for strng in f3_lst_labels:
            if rown == 0:
                fnt_size = 20
            else:
                fnt_size = 16
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", fnt_size, "bold"), W)
            rown = rown + 1

        rown = 0
        colm = 1
        pddx = None
        self.owner_combo = self.create_place_combo(
            framenum, self.init_list_owner[0], self.owner_combo_val, rown,
            colm, ("Courier", 20, "bold"), "owner", W, pddx)
        rown = rown + 1
        self.FMA_combo = self.create_place_combo(framenum,
                                                 self.init_list_owner[1],
                                                 self.FMA_combo_val, rown,
                                                 colm, ("Courier", 16, "bold"),
                                                 "owner", W, pddx)
        rown = rown + 1
        self.wCircle_combo = self.create_place_combo(
            framenum, self.init_list_owner[2], self.wCircle_combo_val, rown,
            colm, ("Courier", 16, "bold"), "owner", W, pddx)
        rown = rown + 1
        self.loggingCo_combo = self.create_place_combo(
            framenum, self.loggingco_list, self.loggingCo_combo_val, rown,
            colm, ("Courier", 16, "bold"), "owner", W, pddx)
        rown = rown + 1
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 4  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = self.frame4
        colm = 0
        rown = 0
        f4_lst_labels = ["Population", "Sample Load"]

        for strng in f4_lst_labels:
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", 20, "bold"), W)
            rown = rown + 1
        lst_pop = ['726', '720', '730', '740', '750', '760', '780', '785']
        lst_sample = ['No', 'Yes']

        colm = 1
        rown = 0
        paddx = (180, 0)
        self.popDD = self.create_place_dropdown(framenum, lst_pop,
                                                self.popDD_val, rown, colm,
                                                ("Courier", 20, "bold"), 'ew',
                                                paddx)
        rown = rown + 1
        self.sampleDD = self.create_place_dropdown(framenum, lst_sample,
                                                   self.sampleDD_val, rown,
                                                   colm,
                                                   ("Courier", 20, "bold"),
                                                   'ew', paddx)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 5  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = self.frame5
        colm = 0
        rown = 0
        pddx = 0
        f6_lst_labels = [
            "Date: ", "Gross Weight: ", "Tare Weight: ", "Net Weight: ",
            "Load Slip #: "
        ]

        self.dict_labels = {}
        for strng in f6_lst_labels:
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", 16), E)
            rown = rown + 1

        colm = 0
        rown = 0
        pddx = 0
        paddy = 0
        self.date_entry = self.create_place_entry(framenum,
                                                  self.date_entry_var, rown,
                                                  colm + 1, ("Courier", 16),
                                                  paddy, E, pddx)
        rown = rown + 1
        # self.timeIn_entry = self.create_place_entry(framenum,self.timeIn_entry_var,rown,colm+1,("Courier", 16),paddy,E,pddx)
        # rown = rown + 1
        # self.timeOut_entry = self.create_place_entry(framenum,self.timeOut_entry_var,rown,colm+1,("Courier", 16),paddy,E,pddx)
        # rown = rown + 1
        self.gross_weight_entry = self.create_place_entry(
            framenum, self.gross_weight_entry_var, rown, colm + 1,
            ("Courier", 16), paddy, E, pddx)
        rown = rown + 1
        self.tare_weight_entry = self.create_place_entry(
            framenum, self.tare_weight_entry_var, rown, colm + 1,
            ("Courier", 16), paddy, E, pddx)
        rown = rown + 1
        self.net_weight_entry = self.create_place_entry(
            framenum, self.net_weight_entry_var, rown, colm + 1,
            ("Courier", 16), paddy, E, pddx)
        rown = rown + 1
        self.loadNum_entry = self.create_place_entry(framenum,
                                                     self.loadNum_entry_var,
                                                     rown, colm + 1,
                                                     ("Courier", 16), paddy, E,
                                                     pddx)
        rown = rown + 1
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 6  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        framenum = self.frame6

        self.orig_colour = 'light grey'
        self.truckin_colour = 'orange'

        self.label_lstbox = Label(framenum,
                                  text="Trucks to Weigh Out",
                                  borderwidth=2,
                                  relief='ridge')
        self.label_lstbox.config(font=("Courier", 20, "bold"),
                                 bg=self.orig_colour)
        self.label_lstbox.pack(side=TOP, expand=Y)
        self.TrucksInYard = Listbox(framenum)
        self.TrucksInYard.config(font=("Courier", 20, "bold"),
                                 bg=self.orig_colour)
        self.TrucksInYard.pack(side=TOP, expand=Y)
        self.TrucksInYard.bind("<<ListboxSelect>>", self.enable_weighOut)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 7  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = self.frame7

        self.img = Image.open("Brisco_logo.png")
        self.tk_img = ImageTk.PhotoImage(self.img)

        self.label_image = Label(framenum, image=self.tk_img, relief='groove')
        self.label_image.config(height=250, width=250)
        self.label_image.grid(row=0, column=0, columnspan=2)

        pddx = 20
        pddy = (150, 0)
        dimh = 8
        dimw = 10
        rown = 1
        colm = 0
        self.WeighIN = self.create_place_button(framenum, 'Enter\nValues',
                                                rown, colm,
                                                ("Courier", 22, "bold"), pddy,
                                                pddx, dimh, dimw, W,
                                                self.weighIN)
        self.WeighOUT = self.create_place_button(framenum, 'Weigh\nOut', rown,
                                                 colm + 1,
                                                 ("Courier", 22, "bold"), pddy,
                                                 pddx, dimh, dimw, E,
                                                 self.weighOUT)
        # self.WeighIN.config(state='Disabled')
        self.WeighOUT.config(state='disabled', bg='grey')
        '''
        ~~~~~~~~~~~~~~~  close program with escape key  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        self.master.bind('<Escape>', lambda e: self.master.destroy())
예제 #7
0
class GUIatFrontDesk:
    def __init__(self, master):

        from PIL import Image, ImageTk
        self.master = master
        '''
        ~~~~~~~~~~~~~~~ Connect to Database and initialize Listst ~~~~~~~~~~~~~~
        '''
        self.Connect_Brisco_DB = Connect_DB('postgres', 'postgres',
                                            '192.168.0.200', 'coffeegood')
        self.cur1 = self.Connect_Brisco_DB.crsr()

        # self.loggingco_list =[]
        self.init_list_truck = self.initializeLists('truckers_db')
        self.init_list_owner = self.initializeLists('owner_db')
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~ Initialize Frames ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        self.frame1 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame1.grid(row=0, column=0, sticky='ew')

        self.frame2 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame2.grid(row=1, column=0, sticky='ew', ipady=20)

        self.frame3 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame3.grid(row=2, column=0, sticky='ew', ipady=20)

        self.frame4 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame4.grid(row=3, column=0, sticky='ew', ipady=20)

        self.frame5 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame5.grid(row=0, column=1, sticky='nsew')

        self.frame6 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame6.grid(row=1, column=1, sticky='nsew', rowspan=3)

        self.frame7 = Frame(self.master, borderwidth=5, relief='raised')
        self.frame7.grid(row=0, column=2, rowspan=4, sticky='nwes')

        #list of dictionaries for trucks in the yard and info attached to them
        self.Lst_truckInfo = []
        '''
        ~~~~~~~~~~~~~~~ Create initial vals for comboboxes ~~~~~~~~~~~~~~~
        '''
        self.owner_combo_val = StringVar()
        self.FMA_combo_val = StringVar()
        self.wCircle_combo_val = StringVar()
        self.block_combo_val = StringVar()
        self.logCo_combo_val = StringVar()
        self.truckLicense_combo_val = StringVar()
        self.truckNum_combo_val = StringVar()
        self.axle_combo_val = StringVar()
        self.hauledBy_combo_val = StringVar()
        self.popDD_val = StringVar()
        self.sampleDD_val = StringVar()
        self.loggingCo_combo_val = StringVar()
        self.date_entry_var = StringVar()
        self.timeIn_entry_var = StringVar()
        self.timeOut_entry_var = StringVar()
        self.gross_weight_entry_var = StringVar()
        self.tare_weight_entry_var = StringVar()
        self.net_weight_entry_var = StringVar()
        self.loadNum_entry_var = StringVar()
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 1  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = 1

        framenum = self.frame1
        colm = 0
        rown = 0
        f1_lst_labels = ["TM9 Ticket", "Block #", "Pieces"]

        for strng in f1_lst_labels:
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", 20, "bold"), W)
            rown = rown + 1

        colm = 1
        rown = 0
        pddx = (90, 0)
        self.TM9_entry_var = StringVar()
        self.numPieces_entry_var = StringVar()
        self.blockNum_entry_var = StringVar()

        self.TM9_entry = self.create_place_entry(framenum, self.TM9_entry_var,
                                                 rown, colm,
                                                 ("Courier", 16, "bold"), 20,
                                                 E, pddx)
        rown = rown + 1
        self.blockNum_entry = self.create_place_entry(framenum,
                                                      self.blockNum_entry_var,
                                                      rown, colm,
                                                      ("Courier", 16, "bold"),
                                                      40, E, pddx)
        rown = rown + 1
        self.numPieces_entry = self.create_place_entry(
            framenum, self.numPieces_entry_var, rown, colm,
            ("Courier", 16, "bold"), None, E, pddx)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 2  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        framenum = self.frame2
        #labels
        colm = 0
        rown = 0
        f2_lst_labels = [
            "Truck #", "License Plate ", "Hauling Contractor", "Truck Axle"
        ]

        for strng in f2_lst_labels:
            if rown == 0:
                fnt_size = 20
            else:
                fnt_size = 16
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", fnt_size, "bold"), W)
            rown = rown + 1

        List_frame2 = self.initializeLists('truckers_db')

        #Menus
        rown = 0
        colm = 1
        pddx = None
        self.truckNum_combo = self.create_place_combo(
            framenum, self.init_list_truck[0], self.truckNum_combo_val, rown,
            colm, ("Courier", 20, "bold"), "truck", W, pddx)
        rown = rown + 1
        self.truckLicense_combo = self.create_place_combo(
            framenum, self.init_list_truck[1], self.truckLicense_combo_val,
            rown, colm, ("Courier", 16, "bold"), "truck", W, pddx)
        rown = rown + 1
        self.hauledBy_combo = self.create_place_combo(
            framenum, self.init_list_truck[2], self.hauledBy_combo_val, rown,
            colm, ("Courier", 16, "bold"), "truck", W, pddx)
        rown = rown + 1
        self.axle_combo = self.create_place_combo(
            framenum, self.init_list_truck[3], self.axle_combo_val, rown, colm,
            ("Courier", 16, "bold"), "truck", W, pddx)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 3  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        framenum = self.frame3
        colm = 0
        rown = 0
        f3_lst_labels = [
            "Owner", "FMA #", "Working Circle", "Logging Contractor"
        ]
        for strng in f3_lst_labels:
            if rown == 0:
                fnt_size = 20
            else:
                fnt_size = 16
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", fnt_size, "bold"), W)
            rown = rown + 1

        rown = 0
        colm = 1
        pddx = None
        self.owner_combo = self.create_place_combo(
            framenum, self.init_list_owner[0], self.owner_combo_val, rown,
            colm, ("Courier", 20, "bold"), "owner", W, pddx)
        rown = rown + 1
        self.FMA_combo = self.create_place_combo(framenum,
                                                 self.init_list_owner[1],
                                                 self.FMA_combo_val, rown,
                                                 colm, ("Courier", 16, "bold"),
                                                 "owner", W, pddx)
        rown = rown + 1
        self.wCircle_combo = self.create_place_combo(
            framenum, self.init_list_owner[2], self.wCircle_combo_val, rown,
            colm, ("Courier", 16, "bold"), "owner", W, pddx)
        rown = rown + 1
        self.loggingCo_combo = self.create_place_combo(
            framenum, self.loggingco_list, self.loggingCo_combo_val, rown,
            colm, ("Courier", 16, "bold"), "owner", W, pddx)
        rown = rown + 1
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 4  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = self.frame4
        colm = 0
        rown = 0
        f4_lst_labels = ["Population", "Sample Load"]

        for strng in f4_lst_labels:
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", 20, "bold"), W)
            rown = rown + 1
        lst_pop = ['726', '720', '730', '740', '750', '760', '780', '785']
        lst_sample = ['No', 'Yes']

        colm = 1
        rown = 0
        paddx = (180, 0)
        self.popDD = self.create_place_dropdown(framenum, lst_pop,
                                                self.popDD_val, rown, colm,
                                                ("Courier", 20, "bold"), 'ew',
                                                paddx)
        rown = rown + 1
        self.sampleDD = self.create_place_dropdown(framenum, lst_sample,
                                                   self.sampleDD_val, rown,
                                                   colm,
                                                   ("Courier", 20, "bold"),
                                                   'ew', paddx)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 5  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = self.frame5
        colm = 0
        rown = 0
        pddx = 0
        f6_lst_labels = [
            "Date: ", "Gross Weight: ", "Tare Weight: ", "Net Weight: ",
            "Load Slip #: "
        ]

        self.dict_labels = {}
        for strng in f6_lst_labels:
            self.create_place_label(framenum, strng, rown, colm,
                                    ("Courier", 16), E)
            rown = rown + 1

        colm = 0
        rown = 0
        pddx = 0
        paddy = 0
        self.date_entry = self.create_place_entry(framenum,
                                                  self.date_entry_var, rown,
                                                  colm + 1, ("Courier", 16),
                                                  paddy, E, pddx)
        rown = rown + 1
        # self.timeIn_entry = self.create_place_entry(framenum,self.timeIn_entry_var,rown,colm+1,("Courier", 16),paddy,E,pddx)
        # rown = rown + 1
        # self.timeOut_entry = self.create_place_entry(framenum,self.timeOut_entry_var,rown,colm+1,("Courier", 16),paddy,E,pddx)
        # rown = rown + 1
        self.gross_weight_entry = self.create_place_entry(
            framenum, self.gross_weight_entry_var, rown, colm + 1,
            ("Courier", 16), paddy, E, pddx)
        rown = rown + 1
        self.tare_weight_entry = self.create_place_entry(
            framenum, self.tare_weight_entry_var, rown, colm + 1,
            ("Courier", 16), paddy, E, pddx)
        rown = rown + 1
        self.net_weight_entry = self.create_place_entry(
            framenum, self.net_weight_entry_var, rown, colm + 1,
            ("Courier", 16), paddy, E, pddx)
        rown = rown + 1
        self.loadNum_entry = self.create_place_entry(framenum,
                                                     self.loadNum_entry_var,
                                                     rown, colm + 1,
                                                     ("Courier", 16), paddy, E,
                                                     pddx)
        rown = rown + 1
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 6  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        framenum = self.frame6

        self.orig_colour = 'light grey'
        self.truckin_colour = 'orange'

        self.label_lstbox = Label(framenum,
                                  text="Trucks to Weigh Out",
                                  borderwidth=2,
                                  relief='ridge')
        self.label_lstbox.config(font=("Courier", 20, "bold"),
                                 bg=self.orig_colour)
        self.label_lstbox.pack(side=TOP, expand=Y)
        self.TrucksInYard = Listbox(framenum)
        self.TrucksInYard.config(font=("Courier", 20, "bold"),
                                 bg=self.orig_colour)
        self.TrucksInYard.pack(side=TOP, expand=Y)
        self.TrucksInYard.bind("<<ListboxSelect>>", self.enable_weighOut)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~  Frame 7  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        framenum = self.frame7

        self.img = Image.open("Brisco_logo.png")
        self.tk_img = ImageTk.PhotoImage(self.img)

        self.label_image = Label(framenum, image=self.tk_img, relief='groove')
        self.label_image.config(height=250, width=250)
        self.label_image.grid(row=0, column=0, columnspan=2)

        pddx = 20
        pddy = (150, 0)
        dimh = 8
        dimw = 10
        rown = 1
        colm = 0
        self.WeighIN = self.create_place_button(framenum, 'Enter\nValues',
                                                rown, colm,
                                                ("Courier", 22, "bold"), pddy,
                                                pddx, dimh, dimw, W,
                                                self.weighIN)
        self.WeighOUT = self.create_place_button(framenum, 'Weigh\nOut', rown,
                                                 colm + 1,
                                                 ("Courier", 22, "bold"), pddy,
                                                 pddx, dimh, dimw, E,
                                                 self.weighOUT)
        # self.WeighIN.config(state='Disabled')
        self.WeighOUT.config(state='disabled', bg='grey')
        '''
        ~~~~~~~~~~~~~~~  close program with escape key  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''
        self.master.bind('<Escape>', lambda e: self.master.destroy())

    '''
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GUI Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '''

    def enable_weighOut(self, event):
        self.WeighIN.config(state='disabled', bg='grey')
        self.WeighOUT.config(state='normal', bg='green')

    def weighIN(self):
        if self.sampleDD_val.get() == 'No':
            binary_sample = 0
        else:
            binary_sample = 1

        Weighin_dict = {
            'daterecieved': self.date_entry.get(),
            'poploadslip': int(self.popDD_val.get()),
            'count': self.loadNum_entry.get(),
            'sampleloads': binary_sample,
            'tm9_ticket': self.TM9_entry.get(),
            'owner': self.owner_combo_val.get(),
            'disposition_fmanum': self.FMA_combo_val.get(),
            'workingcircle': self.wCircle_combo_val.get(),
            'blocknum': self.blockNum_entry.get(),
            'loggingco': self.loggingCo_combo_val.get(),
            'haulingcontractor': self.hauledBy_combo_val.get(),
            'truckplate': self.truckLicense_combo_val.get(),
            'trucknum': self.truckNum_combo_val.get(),
            'truckaxle': int(self.axle_combo_val.get()),
            'grossweight': self.gross_weight_entry.get(),
            # 'timeIn'  :     self.timeIn_entry.get(),
            'numpcsreceived': self.numPieces_entry.get(),
            'tareweight': self.tare_weight_entry.get(),
            'netweight': self.net_weight_entry.get(),
            # 'timeOut'   : self.timeOut_entry.get()
        }

        columns = Weighin_dict.keys()
        values = [Weighin_dict[column] for column in columns]

        insert_statement = 'INSERT INTO barkies_db (%s) VALUES %s'

        try:
            self.cur1.execute(insert_statement,
                              (AsIs(','.join(columns)), tuple(values)))

        except:
            tkMessageBox.showinfo("WHOOPS!",
                                  "Make sure all values are filled in!")
            print self.cur1.mogrify(insert_statement,
                                    (AsIs(','.join(columns)), tuple(values)))

    def weighOUT(self):

        trucknum_indx = next(index
                             for (index, d) in enumerate(self.Lst_truckInfo)
                             if d['trucknum'] == self.TrucksInYard.get(
                                 self.TrucksInYard.curselection()))

        dict_to_fill = self.Lst_truckInfo[trucknum_indx]

        del self.Lst_truckInfo[trucknum_indx]

        self.owner_combo.set(dict_to_fill['owner'])
        self.FMA_combo.set(dict_to_fill['disposition_fmanum'])
        self.wCircle_combo.set(dict_to_fill['workingcircle'])
        self.truckNum_combo.set(dict_to_fill['trucknum'])
        self.truckLicense_combo.set(dict_to_fill['truckplate'])
        self.hauledBy_combo.set(dict_to_fill['haulingcontractor'])
        self.axle_combo.set(dict_to_fill['truckaxle'])
        self.TM9_entry_var.set(dict_to_fill['tm9_ticket'])
        self.blockNum_entry_var.set(dict_to_fill['blocknum'])
        self.numPieces_entry_var.set(dict_to_fill['numpcsreceived'])

        try:
            ser = serial.Serial('/dev/ttyUSB0', 9600)
            str_weight = ser.readline()
            self.tare_weight = str_weight.split()[1]
            self.net_weight = int(dict_to_fill['grossweight']) - int(
                self.tare_weight)
        except:
            self.tare_weight = 50
            self.net_weight = int(
                dict_to_fill['grossweight']) - self.tare_weight

        self.timeOut_now = str(datetime.datetime.now().strftime("%H:%M:%S"))

        label_list = []

        #Set labels after weign in

        label_list = [
            dict_to_fill['daterecieved'], dict_to_fill['timeIn'],
            self.timeOut_now,
            str(dict_to_fill['grossweight']),
            str(self.tare_weight),
            str(self.net_weight), dict_to_fill['count']
        ]
        rown = 0
        for labl in label_list:

            self.create_place_label(self.frame5, labl, rown, 1,
                                    ("Courier", 16), E)
            rown = rown + 1

        self.TrucksInYard.delete(trucknum_indx)

        self.TrucksInYard.config(bg='bisque')
        self.label_lstbox.config(bg='bisque')

        WeighOut_dict = {
            'tareweight': self.tare_weight,
            'netweight': self.net_weight,
            'timeOut': self.timeOut_now
        }

        columns = WeighOut_dict.keys()
        values = [WeighOut_dict[column] for column in columns]

        insert_statement = 'UPDATE barkies_db SET (%s) = %s WHERE tm9_ticket = %s;'
        strng = self.TM9_entry.get()

        self.cur1.execute(insert_statement,
                          (AsIs(','.join(columns)), tuple(values), strng))

        self.WeighOUT.config(state='disabled', bg='grey')
        self.WeighIN.config(state='normal', bg='green')
        self.update_colors_truck()

    def update_colors_truck(self):
        if self.Lst_truckInfo:

            self.TrucksInYard.config(bg=self.truckin_colour)
            self.label_lstbox.config(bg=self.truckin_colour)
        else:
            self.TrucksInYard.config(bg=self.orig_colour)
            self.label_lstbox.config(bg=self.orig_colour)

    def update_lists(self, event, strng, name_combo, Lst):

        var_Selected = name_combo.current()

        if strng == 'owner':
            self.owner_combo.set(self.init_list_owner[0][var_Selected])
            self.FMA_combo.set(self.init_list_owner[1][var_Selected])
            self.wCircle_combo.set(self.init_list_owner[2][var_Selected])
            # self.loggingCo_combo.set(self.init_list_owner[3][var_Selected])

        elif strng == 'truck':
            self.truckNum_combo.set(self.init_list_truck[0][var_Selected])
            self.truckLicense_combo.set(self.init_list_truck[1][var_Selected])
            self.hauledBy_combo.set(self.init_list_truck[2][var_Selected])
            self.axle_combo.set(self.init_list_truck[3][var_Selected])
            # self.loggingCo_combo.set(self.init_list_owner[3][var_Selected])

    def initializeLists(self, table):

        query = 'select * from "{}"'.format(table)
        self.cur1.execute(query)
        rows = self.cur1.fetchall()
        rows = sorted(rows)
        sorted_list = map(list, itertools.izip_longest(*rows))
        if table == 'owner_db':
            table1 = 'barkies_db'
            query = 'select loggingco from "{}"'.format(table1)
            self.cur1.execute(query)
            rows = self.cur1.fetchall()
            t_list = [str(x[0]) for x in rows]
            self.loggingco_list = list(set(t_list))
        return sorted_list

    def create_place_label(self, frme, strng, rownum, columnum, fnt, stcky):

        labl_name = Label(frme, text='        ')
        labl_name.grid(row=rownum, column=columnum, sticky=stcky)
        labl_name.config(font=fnt, text=strng)
        return labl_name

    def create_place_combo(self, frme, Lst, cmboVal, rownum, columnum, fnt,
                           strng, stcky, pdx):

        bigfont = tkFont.Font(root=frme,
                              family="Courier",
                              size=30,
                              weight='bold')
        frme.option_add("*TCombobox*Listbox*Font", bigfont)

        name_combo = ttk.Combobox(frme, textvariable=cmboVal)
        name_combo.grid(row=rownum, column=columnum, sticky=stcky, padx=pdx)
        name_combo.config(font=fnt)
        name_combo['values'] = Lst
        name_combo.set(Lst[1])
        # self.owner_combo.bind("<<ComboboxSelected>>",lambda event: self.DB_Search_n_Fill(event,"owner",self.Connect_Brisco_DB))
        name_combo.bind(
            "<<ComboboxSelected>>",
            lambda event: self.update_lists(event, strng, name_combo, Lst))
        return name_combo

    def create_place_dropdown(self, frme, DD_lst, ddVal, rownum, columnum, fnt,
                              stcky, pdx):

        ddVal.set(DD_lst[0])
        name_DD = OptionMenu(frme, ddVal, *DD_lst)
        name_DD.config(font=fnt, bg='tan')
        name_DD.grid(row=rownum, column=columnum, sticky=stcky, padx=pdx)
        return name_DD

    def create_place_entry(self, frme, txt, rownum, columnum, fnt, pdy, stcky,
                           pdx):

        name_entry = Entry(frme, text=txt)
        name_entry.config(font=fnt)
        name_entry.grid(row=rownum,
                        column=columnum,
                        pady=pdy,
                        sticky=stcky,
                        padx=pdx)
        return name_entry

    def create_place_button(self, frme, txt_name, rownum, columnum, fnt, pdy,
                            pdx, dimmh, dimmw, stcky, cmmd):

        name_button = Button(frme, text=txt_name, command=cmmd)
        name_button.config(height=dimmh,
                           width=dimmw,
                           bg='green',
                           activebackground='red',
                           font=fnt)
        name_button.grid(row=rownum,
                         column=columnum,
                         pady=pdy,
                         padx=pdx,
                         sticky=stcky)
        return name_button

    def print_test(self, event, strng, name_combo, Lst):
        var_Selected = name_combo.current()
        selection_val = str(Lst[var_Selected])
        print(strng)
        print(selection_val)
    def __init__(self,master):

        from PIL import Image, ImageTk
        self.master = master


        '''
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~            Connect to Database              ~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        self.Connect_Brisco_DB = Connect_DB('postgres','postgres','192.168.0.200','coffeegood')


        self.cur1 = self.Connect_Brisco_DB.crsr()

        #create initial lists to populate dropdown and combobox
        init_list_Licensee = []
        init_list_FMA = []
        init_list_wCircle = []

        init_list_hauledBy = []
        init_list_truckLicense = []
        init_list_truckNum = []
        init_list_loggingco = []

        self.cur1.execute("SELECT * FROM owner_DB")
        rows = self.cur1.fetchall()
        for row in rows:
            if row[0] is not None:
                init_list_Licensee.append(row[0])
            if row[1] is not None:
                init_list_FMA.append(row[1])
            if row[2] is not None:
                init_list_wCircle.append(row[2])

        self.init_list_Licensee = list(set(init_list_Licensee))
        self.init_list_FMA = list(set(init_list_FMA))
        self.init_list_wCircle = list(set(init_list_wCircle))

        self.cur1.execute("SELECT haulingcontractor,truckplate,trucknum,loggingco FROM barkies_DB")
        rows = self.cur1.fetchall()
        for row in rows:
            if row[0] is not None:
                init_list_hauledBy.append(row[0])
            if row[1] is not None:
                init_list_truckLicense.append(row[1])
            if row[2] is not None:
                init_list_truckNum.append(row[2])
            if row[3] is not None:
                init_list_loggingco.append(row[3])

        self.init_list_hauledBy = list(set(init_list_hauledBy))
        self.init_list_truckLicense = list(set(init_list_truckLicense))
        self.init_list_truckNum = list(set(init_list_truckNum))
        self.init_list_loggingco = list(set(init_list_loggingco))

        self.img = Image.open("Brisco_logo.png")
        self.tk_img = ImageTk.PhotoImage(self.img)

        # Label Widgets
        self.label_image = Label(master,image=self.tk_img,borderwidth=2,relief='groove')
        self.label_timeIn_tag = Label(master, text = "Time in: ")
        self.label_timeOut_tag = Label(master, text = "Time out: ")
        self.label_date = Label(master,text ="Date")
        self.label_popNum = Label(master,text ="Population")
        self.label_popNumCount = Label(master,text ="Load Slip #")
        self.label_SampleLoad = Label(master,text ="Sample Load")
        self.label_TM9 = Label(master, text="TM9/Ticket #")
        self.label_owner = Label(master, text="Owner")
        self.label_hauledBy = Label(master, text = "Hauling Contractor")
        self.label_workingCircle= Label(master, text="Working Circle")
        self.label_BlockNum = Label(master, text="Block #")
        self.label_loggingCo = Label(master, text="Logging Co.")
        self.label_TruckPlate = Label(master, text="Truck License Plate #")
        self.label_TruckNum= Label(master, text="Truck #")
        self.label_TruckAxle = Label(master, text="Truck Axle")
        self.label_gross = Label(master, text="Gross Weight")
        self.label_tare = Label(master, text="Tare Weight")
        self.label_net = Label(master, text="Net Weight")
        self.label_pcs = Label(master, text="Pieces")
        self.label_FMA = Label(master, text="Disposition/FMA #")

        # labels that change with weight entered
        self.textVarGross = "----kg"
        self.textVarTare = "----kg"
        self.textVarNet = "----kgr"
        self.textpopCount = "-------"

        self.label_scaleGross = Label(master,text=self.textVarGross)
        self.label_scaleTare = Label(master,text=self.textVarTare )
        self.label_scaleNet = Label(master,text=self.textVarNet)
        self.label_popCount = Label(master,text=self.textpopCount)

        #Radio button for determining Weigh in or Weigh Out
        self.v_radio = IntVar()
        self.v_radio.set(1)
        self.In = Radiobutton(master, text="Weigh In", variable=self.v_radio , value=1, command=self.changetext)
        self.Out = Radiobutton(master, text="Weigh Out", variable=self.v_radio , value=2, command=self.changetext)

        # Buttons
        self.ButtonText = "Weigh\nIn"
        self.Bigbutton = Button(master, text=self.ButtonText,bg='green',command=self.buttonPress)
        # self.button_weighOut = Button(master, text="Weigh Out",bg='green',command=self.WeighOUT)
        # self.button_reset = Button(master, text ='Reset',command=self.Reset_button)
        # self.button_reset.config(width='10',height='8',activebackground='red')
        self.Bigbutton.config(width='20',height='8',activebackground='red')
        # self.button_weighOut.config(width='20',height='8',activebackground='red')

        # Drop Down Menus
        # Generate Time and Date

        self.gen_date = Label(master, text = "-------------")
        self.gen_timeIn = Label(master, text = "-------------")
        self.gen_timeOut = Label(master, text = "-------------")

        #population load slip
        self.DD_lst_popLoad = ['720','726','730','740','750','760','780','785']
        self.popLoad_DD_val = StringVar()
        self.popLoad_DD_val.set(self.DD_lst_popLoad[0])
        self.popLoad_DD_menu = OptionMenu(master, self.popLoad_DD_val, *self.DD_lst_popLoad)

        # Sample Load drop down menu
        self.DD_lst_sample = ['No','Yes']
        self.sample_DD_Val = StringVar()
        self.sample_DD_Val.set(self.DD_lst_sample[0])
        self.sample_DD_menu = OptionMenu(master, self.sample_DD_Val, *self.DD_lst_sample)

        self.DD_lst_axle = ['5','6','7','8','9','10']
        self.axle_DD_Val = StringVar()
        self.axle_DD_Val.set(self.DD_lst_axle[2])
        self.axle_DD_menu = OptionMenu(master, self.axle_DD_Val, *self.DD_lst_axle)

        # textEntry
        self.TM9_entry =Entry(master)
        self.timeIn_entry = Entry(master)
        self.timeOut_entry = Entry(master)
        self.pcs_entry = Entry(master)
        self.block_entry = Entry(master)

        # combobox initial val
        self.owner_combo_val = StringVar()
        self.FMA_combo_val = StringVar()
        self.wCircle_combo_val = StringVar()
        self.block_combo_val = StringVar()
        self.logCo_combo_val = StringVar()
        self.truckLicense_combo_val = StringVar()
        self.truckNum_combo_val = StringVar()
        self.axle_combo_val = StringVar()
        self.hauledBy_combo_val = StringVar()

        # 1st row combobox inisialize with bind to mouseclick
        self.owner_combo = ttk.Combobox(master,textvariable = self.owner_combo_val)
        self.owner_combo['values'] = self.init_list_Licensee
        self.owner_combo.set(self.init_list_Licensee[0])
        self.owner_combo.bind("<<ComboboxSelected>>",lambda event: self.DB_Search_n_Fill(event,"owner",self.Connect_Brisco_DB))

        #hauling Contractor Combobox
        self.FMA_combo = ttk.Combobox(master,textvariable = self.FMA_combo_val)
        self.FMA_combo['values'] = self.init_list_FMA
        self.FMA_combo.set(self.init_list_FMA[0])

        self.wCircle_combo = ttk.Combobox(master,textvariable = self.wCircle_combo_val)
        self.wCircle_combo['values'] = self.init_list_wCircle
        self.wCircle_combo.set(self.init_list_wCircle[0])

        # 2nd Row combobox initialize

        self.logCo_combo = ttk.Combobox(master,textvariable = self.logCo_combo_val)
        self.logCo_combo['values'] = self.init_list_loggingco
        self.logCo_combo.set(self.init_list_loggingco[0])

        self.truckLicense_combo = ttk.Combobox(master,textvariable = self.truckLicense_combo_val)
        self.truckLicense_combo['values'] = self.init_list_truckLicense
        self.truckLicense_combo.set(self.init_list_truckLicense[0])

        self.truckNum_combo = ttk.Combobox(master,textvariable = self.truckNum_combo_val)
        self.truckNum_combo['values'] = self.init_list_truckNum
        self.truckNum_combo.set(self.init_list_truckNum[0])

        self.hauledBy_combo = ttk.Combobox(master, textvariable = self.hauledBy_combo_val)
        self.hauledBy_combo['values'] = self.init_list_hauledBy
        self.hauledBy_combo.set(self.init_list_hauledBy[0])

        #Drop down menu Widgets
        pady_val = 100
        columnum = 0
        rownum = 2
        self.popLoad_DD_menu.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.label_popCount.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.sample_DD_menu.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.TM9_entry.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.owner_combo.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.hauledBy_combo.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.FMA_combo.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
                # 4th Row
        columnum = 0
        self.wCircle_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.block_entry.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.logCo_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.truckLicense_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.truckNum_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.axle_DD_menu.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.pcs_entry.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        #enlarge Text boxes

        #1st row labels
        self.label_image.grid(row=0,column=0,pady=(0,30),sticky=E)
        self.label_date.grid(row=0, column = 5,pady = (10,0),sticky='nw')
        self.label_timeIn_tag.grid(row=0, column = 5,sticky=W)
        self.label_timeOut_tag.grid(row=0, column = 5, pady = (60,0),sticky=W)

        #insert date and times
        self.gen_date.grid(row=0, column = 6,pady = (10,0),sticky=N)
        self.gen_timeIn.grid(row=0, column = 6)
        self.gen_timeOut.grid(row=0, column = 6, pady = (60,0))

        #2nd Row Layout Widgets
        columnum = 0
        self.label_popNum.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_popNumCount.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_SampleLoad.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_TM9.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_owner.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_hauledBy.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_FMA.grid(row=1,column=columnum )
        columnum = columnum+1

        #1st row Emtry and Combobox


        #2nd row layout Widgets
        columnum = 0
        self.label_workingCircle.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_BlockNum.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_loggingCo.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_TruckPlate.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_TruckNum.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_TruckAxle.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_pcs.grid(row=3,column=columnum)
        columnum = columnum+1

        #3rd row labels
        self.label_gross.grid(row=5,column=0)
        self.label_tare.grid(row=5,column=1)
        self.label_net.grid(row=5,column=2)


        #3rd row values
        columnum = 0
        self.label_scaleGross.grid(row=6,column=columnum)
        columnum = columnum+1
        self.label_scaleTare.grid(row=6,column=columnum)
        columnum = columnum+1
        self.label_scaleNet.grid(row=6,column=columnum)
        columnum = columnum+1

        # Buttons
        columnum = 0
        self.Bigbutton.grid(row=7,column=columnum,pady=100)
        columnum = columnum+1
        # self.button_weighOut.grid(row=7,column=columnum,pady=100)
        # columnum = columnum+1
        # self.button_reset.grid(row=7,column=7,pady=100)
        self.In.grid(row=7,column=columnum)
        columnum = columnum+1
        self.Out.grid(row=7,column=columnum)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Destroy Process ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        self.master.bind('<Escape>', lambda e: root.destroy())
class GUIatFrontDesk:

    def __init__(self,master):

        from PIL import Image, ImageTk
        self.master = master


        '''
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~            Connect to Database              ~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        self.Connect_Brisco_DB = Connect_DB('postgres','postgres','192.168.0.200','coffeegood')


        self.cur1 = self.Connect_Brisco_DB.crsr()

        #create initial lists to populate dropdown and combobox
        init_list_Licensee = []
        init_list_FMA = []
        init_list_wCircle = []

        init_list_hauledBy = []
        init_list_truckLicense = []
        init_list_truckNum = []
        init_list_loggingco = []

        self.cur1.execute("SELECT * FROM owner_DB")
        rows = self.cur1.fetchall()
        for row in rows:
            if row[0] is not None:
                init_list_Licensee.append(row[0])
            if row[1] is not None:
                init_list_FMA.append(row[1])
            if row[2] is not None:
                init_list_wCircle.append(row[2])

        self.init_list_Licensee = list(set(init_list_Licensee))
        self.init_list_FMA = list(set(init_list_FMA))
        self.init_list_wCircle = list(set(init_list_wCircle))

        self.cur1.execute("SELECT haulingcontractor,truckplate,trucknum,loggingco FROM barkies_DB")
        rows = self.cur1.fetchall()
        for row in rows:
            if row[0] is not None:
                init_list_hauledBy.append(row[0])
            if row[1] is not None:
                init_list_truckLicense.append(row[1])
            if row[2] is not None:
                init_list_truckNum.append(row[2])
            if row[3] is not None:
                init_list_loggingco.append(row[3])

        self.init_list_hauledBy = list(set(init_list_hauledBy))
        self.init_list_truckLicense = list(set(init_list_truckLicense))
        self.init_list_truckNum = list(set(init_list_truckNum))
        self.init_list_loggingco = list(set(init_list_loggingco))

        self.img = Image.open("Brisco_logo.png")
        self.tk_img = ImageTk.PhotoImage(self.img)

        # Label Widgets
        self.label_image = Label(master,image=self.tk_img,borderwidth=2,relief='groove')
        self.label_timeIn_tag = Label(master, text = "Time in: ")
        self.label_timeOut_tag = Label(master, text = "Time out: ")
        self.label_date = Label(master,text ="Date")
        self.label_popNum = Label(master,text ="Population")
        self.label_popNumCount = Label(master,text ="Load Slip #")
        self.label_SampleLoad = Label(master,text ="Sample Load")
        self.label_TM9 = Label(master, text="TM9/Ticket #")
        self.label_owner = Label(master, text="Owner")
        self.label_hauledBy = Label(master, text = "Hauling Contractor")
        self.label_workingCircle= Label(master, text="Working Circle")
        self.label_BlockNum = Label(master, text="Block #")
        self.label_loggingCo = Label(master, text="Logging Co.")
        self.label_TruckPlate = Label(master, text="Truck License Plate #")
        self.label_TruckNum= Label(master, text="Truck #")
        self.label_TruckAxle = Label(master, text="Truck Axle")
        self.label_gross = Label(master, text="Gross Weight")
        self.label_tare = Label(master, text="Tare Weight")
        self.label_net = Label(master, text="Net Weight")
        self.label_pcs = Label(master, text="Pieces")
        self.label_FMA = Label(master, text="Disposition/FMA #")

        # labels that change with weight entered
        self.textVarGross = "----kg"
        self.textVarTare = "----kg"
        self.textVarNet = "----kgr"
        self.textpopCount = "-------"

        self.label_scaleGross = Label(master,text=self.textVarGross)
        self.label_scaleTare = Label(master,text=self.textVarTare )
        self.label_scaleNet = Label(master,text=self.textVarNet)
        self.label_popCount = Label(master,text=self.textpopCount)

        #Radio button for determining Weigh in or Weigh Out
        self.v_radio = IntVar()
        self.v_radio.set(1)
        self.In = Radiobutton(master, text="Weigh In", variable=self.v_radio , value=1, command=self.changetext)
        self.Out = Radiobutton(master, text="Weigh Out", variable=self.v_radio , value=2, command=self.changetext)

        # Buttons
        self.ButtonText = "Weigh\nIn"
        self.Bigbutton = Button(master, text=self.ButtonText,bg='green',command=self.buttonPress)
        # self.button_weighOut = Button(master, text="Weigh Out",bg='green',command=self.WeighOUT)
        # self.button_reset = Button(master, text ='Reset',command=self.Reset_button)
        # self.button_reset.config(width='10',height='8',activebackground='red')
        self.Bigbutton.config(width='20',height='8',activebackground='red')
        # self.button_weighOut.config(width='20',height='8',activebackground='red')

        # Drop Down Menus
        # Generate Time and Date

        self.gen_date = Label(master, text = "-------------")
        self.gen_timeIn = Label(master, text = "-------------")
        self.gen_timeOut = Label(master, text = "-------------")

        #population load slip
        self.DD_lst_popLoad = ['720','726','730','740','750','760','780','785']
        self.popLoad_DD_val = StringVar()
        self.popLoad_DD_val.set(self.DD_lst_popLoad[0])
        self.popLoad_DD_menu = OptionMenu(master, self.popLoad_DD_val, *self.DD_lst_popLoad)

        # Sample Load drop down menu
        self.DD_lst_sample = ['No','Yes']
        self.sample_DD_Val = StringVar()
        self.sample_DD_Val.set(self.DD_lst_sample[0])
        self.sample_DD_menu = OptionMenu(master, self.sample_DD_Val, *self.DD_lst_sample)

        self.DD_lst_axle = ['5','6','7','8','9','10']
        self.axle_DD_Val = StringVar()
        self.axle_DD_Val.set(self.DD_lst_axle[2])
        self.axle_DD_menu = OptionMenu(master, self.axle_DD_Val, *self.DD_lst_axle)

        # textEntry
        self.TM9_entry =Entry(master)
        self.timeIn_entry = Entry(master)
        self.timeOut_entry = Entry(master)
        self.pcs_entry = Entry(master)
        self.block_entry = Entry(master)

        # combobox initial val
        self.owner_combo_val = StringVar()
        self.FMA_combo_val = StringVar()
        self.wCircle_combo_val = StringVar()
        self.block_combo_val = StringVar()
        self.logCo_combo_val = StringVar()
        self.truckLicense_combo_val = StringVar()
        self.truckNum_combo_val = StringVar()
        self.axle_combo_val = StringVar()
        self.hauledBy_combo_val = StringVar()

        # 1st row combobox inisialize with bind to mouseclick
        self.owner_combo = ttk.Combobox(master,textvariable = self.owner_combo_val)
        self.owner_combo['values'] = self.init_list_Licensee
        self.owner_combo.set(self.init_list_Licensee[0])
        self.owner_combo.bind("<<ComboboxSelected>>",lambda event: self.DB_Search_n_Fill(event,"owner",self.Connect_Brisco_DB))

        #hauling Contractor Combobox
        self.FMA_combo = ttk.Combobox(master,textvariable = self.FMA_combo_val)
        self.FMA_combo['values'] = self.init_list_FMA
        self.FMA_combo.set(self.init_list_FMA[0])

        self.wCircle_combo = ttk.Combobox(master,textvariable = self.wCircle_combo_val)
        self.wCircle_combo['values'] = self.init_list_wCircle
        self.wCircle_combo.set(self.init_list_wCircle[0])

        # 2nd Row combobox initialize

        self.logCo_combo = ttk.Combobox(master,textvariable = self.logCo_combo_val)
        self.logCo_combo['values'] = self.init_list_loggingco
        self.logCo_combo.set(self.init_list_loggingco[0])

        self.truckLicense_combo = ttk.Combobox(master,textvariable = self.truckLicense_combo_val)
        self.truckLicense_combo['values'] = self.init_list_truckLicense
        self.truckLicense_combo.set(self.init_list_truckLicense[0])

        self.truckNum_combo = ttk.Combobox(master,textvariable = self.truckNum_combo_val)
        self.truckNum_combo['values'] = self.init_list_truckNum
        self.truckNum_combo.set(self.init_list_truckNum[0])

        self.hauledBy_combo = ttk.Combobox(master, textvariable = self.hauledBy_combo_val)
        self.hauledBy_combo['values'] = self.init_list_hauledBy
        self.hauledBy_combo.set(self.init_list_hauledBy[0])

        #Drop down menu Widgets
        pady_val = 100
        columnum = 0
        rownum = 2
        self.popLoad_DD_menu.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.label_popCount.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.sample_DD_menu.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.TM9_entry.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.owner_combo.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.hauledBy_combo.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.FMA_combo.grid(row = 2, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
                # 4th Row
        columnum = 0
        self.wCircle_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.block_entry.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.logCo_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.truckLicense_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.truckNum_combo.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.axle_DD_menu.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        self.pcs_entry.grid(row = 4, column = columnum,sticky='nwe',pady=(0,pady_val))
        columnum = columnum+1
        #enlarge Text boxes

        #1st row labels
        self.label_image.grid(row=0,column=0,pady=(0,30),sticky=E)
        self.label_date.grid(row=0, column = 5,pady = (10,0),sticky='nw')
        self.label_timeIn_tag.grid(row=0, column = 5,sticky=W)
        self.label_timeOut_tag.grid(row=0, column = 5, pady = (60,0),sticky=W)

        #insert date and times
        self.gen_date.grid(row=0, column = 6,pady = (10,0),sticky=N)
        self.gen_timeIn.grid(row=0, column = 6)
        self.gen_timeOut.grid(row=0, column = 6, pady = (60,0))

        #2nd Row Layout Widgets
        columnum = 0
        self.label_popNum.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_popNumCount.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_SampleLoad.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_TM9.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_owner.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_hauledBy.grid(row=1,column=columnum )
        columnum = columnum+1
        self.label_FMA.grid(row=1,column=columnum )
        columnum = columnum+1

        #1st row Emtry and Combobox


        #2nd row layout Widgets
        columnum = 0
        self.label_workingCircle.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_BlockNum.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_loggingCo.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_TruckPlate.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_TruckNum.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_TruckAxle.grid(row=3,column=columnum)
        columnum = columnum+1
        self.label_pcs.grid(row=3,column=columnum)
        columnum = columnum+1

        #3rd row labels
        self.label_gross.grid(row=5,column=0)
        self.label_tare.grid(row=5,column=1)
        self.label_net.grid(row=5,column=2)


        #3rd row values
        columnum = 0
        self.label_scaleGross.grid(row=6,column=columnum)
        columnum = columnum+1
        self.label_scaleTare.grid(row=6,column=columnum)
        columnum = columnum+1
        self.label_scaleNet.grid(row=6,column=columnum)
        columnum = columnum+1

        # Buttons
        columnum = 0
        self.Bigbutton.grid(row=7,column=columnum,pady=100)
        columnum = columnum+1
        # self.button_weighOut.grid(row=7,column=columnum,pady=100)
        # columnum = columnum+1
        # self.button_reset.grid(row=7,column=7,pady=100)
        self.In.grid(row=7,column=columnum)
        columnum = columnum+1
        self.Out.grid(row=7,column=columnum)
        '''
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Destroy Process ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        '''

        self.master.bind('<Escape>', lambda e: root.destroy())

    def buttonPress(self):

        if self.v_radio.get()==1:
            self.WeighIN()

        else:
            self.WeighOUT()


    def changetext(self):
        if self.v_radio.get()==1:

            self.ButtonText ="Weigh\nIn"
        else:
            self.ButtonText = "Weigh\nOut"
            self.WeighOUTfill()

        self.Bigbutton.config(text=self.ButtonText )

    def DB_Search_n_Fill(self, event, strg, DB_instance):
        t_list_FMA = []
        t_list_workingCirc = []


        self.var_Selected = self.owner_combo.current()
        selection_val = str(self.init_list_Licensee[self.var_Selected])
        self.cur1.execute(sql.SQL("SELECT * FROM owner_db WHERE {} = %s;").format(sql.Identifier(strg)), (selection_val, ))
        rows=self.cur1.fetchall()

        for row in rows:
            t_list_FMA.append(row[1])
            t_list_workingCirc.append(row[2])

        wCircle_combo_list = [x for x in list(set(t_list_workingCirc)) if x is not None]
        FMA_combo_list = list(set(t_list_FMA))

        #Populate the rest of the fields
        self.FMA_combo['values'] = [x for x in FMA_combo_list if x is not None]
        self.wCircle_combo['values'] = [x for x in wCircle_combo_list if x is not None]

        #Populate the combo box with the initial value
        try:
            self.wCircle_combo.set(str(wCircle_combo_list[0]))
        except:
            self.wCircle_combo.set('')
        try:
            self.FMA_combo.set(str(FMA_combo_list[0]))
        except:
            self.FMA_combo.set('')

    def Reset_button(self):

        init_list_Licensee =[]
        init_list_haulingcontractor=[]
        self.cur1.execute("SELECT * FROM trucker_DB")
        rows = self.cur1.fetchall()
        for row in rows:
            if row[0] is not None:
                init_list_Licensee.append(row[0])
            if row[5] is not None:
                init_list_haulingcontractor.append(row[5])

        self.init_list_Licensee = list(set(init_list_Licensee))
        self.init_list_haulingcontractor = list(set(init_list_haulingcontractor))

        self.owner_combo['values'] = self.init_list_Licensee
        self.owner_combo.set(self.init_list_Licensee[0])
        self.hauledBy_combo['values'] =self.init_list_haulingcontractor
        self.hauledBy_combo.set(self.init_list_haulingcontractor[0])

        self.block_entry.delete(0,'end')
        self.block_entry.insert(0,'')

        self.wCircle_combo.set('')

        self.logCo_combo.set('')
        self.truckLicense_combo.set('')
        self.truckNum_combo.set('')
        self.TM9_entry.delete(0,'end')

        self.gen_timeIn.config(text = '----')
        self.gen_timeOut.config(text = '----')
        self.label_scaleTare.config(text = '----')
        self.label_scaleNet.config(text = '----')
        self.label_scaleGross.config(text = '----')
        self.gen_date.config(text = '----')


    def WeighIN(self):

        try:
            ser = serial.Serial('/dev/ttyUSB0',9600)
            str_weight = ser.readline()
            self.gross_weight =  str_weight.split()[1]
            self.gross_weight =int(self.gross_weight)
        except:
            self.gross_weight =  100

        self.date_now = str(datetime.datetime.now().date())
        self.timeIn_now = str(datetime.datetime.now().strftime("%H:%M:%S"))
        self.gen_date.config(text = self.date_now)
        self.gen_timeIn.config(text = self.timeIn_now)
        self.label_scaleGross.config(text = str(self.gross_weight))

        self.cur1.execute(sql.SQL("SELECT poploadslip,count FROM testscale WHERE {} = %s;").format(sql.Identifier('poploadslip')), (self.popLoad_DD_val.get(),))
        a = self.cur1.fetchall()

        try:
            self.new_popCount = int(a[-1][1])+1
        except:
            self.new_popCount = 1
        self.label_popCount.config(text = str(self.new_popCount) )

        if self.sample_DD_Val.get()=='No':
            binary_sample = 0
        else:
            binary_sample = 1

        #update Data base
        Weighin_dict = {
                    'daterecieved': self.date_now,
                    'poploadslip' : int(self.popLoad_DD_val.get()),
                    'count' : self.new_popCount,
                    'sampleloads' : binary_sample,
                    'tm9_ticket' : self.TM9_entry.get(),
                    'owner' : self.owner_combo_val.get(),
                    'disposition_fmanum' : self.FMA_combo_val.get(),
                    'workingcircle' : self.wCircle_combo_val.get(),
                    'blocknum' : self.block_entry.get(),
                    'loggingco' : self.logCo_combo_val.get(),
                    'haulingcontractor' : self.hauledBy_combo_val.get(),
                    'truckplate' : self.truckLicense_combo_val.get(),
                    'trucknum' : self.truckNum_combo_val.get(),
                    'truckaxle' : int(self.axle_DD_Val.get()),
                    'grossweight' : self.gross_weight,
                    'timeIn'  :     self.timeIn_now,
                    'numpcsreceived' : self.numPieces_entry.get()
                   }

        columns = Weighin_dict.keys()
        values = [Weighin_dict[column] for column in columns]

        insert_statement = 'INSERT INTO testscale (%s) VALUES %s'

        self.cur1.execute(insert_statement, (AsIs(','.join(columns)), tuple(values)))

    def WeighOUT(self):
        try:
            ser = serial.Serial('/dev/ttyUSB0',9600)
            str_weight = ser.readline()
            self.tare_weight =  str_weight.split()[1]
            self.net_weight = int(self.gross_weight)-int(self.tare_weight)
        except:
            self.tare_weight = 50
            self.net_weight = self.gross_weight-self.tare_weight

        timeOut_now = str(datetime.datetime.now().strftime("%H:%M:%S"))
        self.gen_timeOut.config(text = timeOut_now)
        self.label_scaleTare.config(text = str(self.tare_weight))
        self.label_scaleNet.config(text = str(self.net_weight))

        WeighOut_dict = {
                    'tareweight': self.tare_weight,
                    'netweight' : self.net_weight,
                    'timeOut'   : timeOut_now
                   }

        columns = WeighOut_dict.keys()
        values = [WeighOut_dict[column] for column in columns]

        insert_statement = 'UPDATE testscale SET (%s) = %s WHERE tm9_ticket = %s;'
        strng = self.TM9_entry.get()

        self.cur1.execute(insert_statement, (AsIs(','.join(columns)), tuple(values), strng))


    def WritetoDB(self):

        self.cur1.execute(sql.SQL("SELECT * FROM trucker_db WHERE {} = %s;").format(sql.Identifier(strg)), (selection_val,))
예제 #10
0
    def weighOUT(self):

        Connect_Brisco_DB = Connect_DB('postgres','postgres',self.ip_add,self.psswd)
        cur1 = Connect_Brisco_DB.crsr()
        trucknum_indx = next(index for (index, d) in enumerate(self.Lst_truckInfo) if d['trucknum'] == self.TrucksInYard.get(self.TrucksInYard.curselection()))

        dict_to_fill = self.Lst_truckInfo[trucknum_indx]

        del self.Lst_truckInfo[trucknum_indx]


        self.owner_combo.set(dict_to_fill['owner'])
        self.FMA_combo.set(dict_to_fill['disposition_fmanum'])
        self.wCircle_combo.set(dict_to_fill['workingcircle'])
        self.truckNum_combo.set(dict_to_fill['trucknum'])
        self.truckLicense_combo.set(dict_to_fill['truckplate'])
        self.hauledBy_combo.set(dict_to_fill['haulingcontractor'])
        self.axle_combo.set(dict_to_fill['truckaxle'])
        self.TM9_entry_var.set(dict_to_fill['tm9_ticket'])
        self.blockNum_entry_var.set(dict_to_fill['blocknum'])
        self.numPieces_entry_var.set(dict_to_fill['numpcsreceived'])

        try:
            ser = serial.Serial('/dev/ttyUSB0',9600)
            str_weight = ser.readline()
            self.tare_weight =  str_weight.split()[1]
            self.net_weight = int(dict_to_fill['grossweight'])-int(self.tare_weight)
            ser.close()

        except:
            self.tare_weight = 50
            self.net_weight = int(dict_to_fill['grossweight'])-self.tare_weight

        self.timeOut_now = str(datetime.datetime.now().strftime("%H:%M:%S"))

        label_list = []

        #Set labels after weign in

        label_list = [dict_to_fill['daterecieved'],dict_to_fill['timeIn'],self.timeOut_now,str(dict_to_fill['grossweight']),str(self.tare_weight),str(self.net_weight),dict_to_fill['count'] ]
        rown = 0
        for labl in label_list:

            self.create_place_label(self.frame5, labl, rown, 1, ("Courier", 16), E)
            rown = rown + 1

        self.TrucksInYard.delete(trucknum_indx)

        self.TrucksInYard.config(bg='bisque')
        self.label_lstbox.config(bg='bisque')

        WeighOut_dict = {
                    'tareweight': self.tare_weight,
                    'netweight' : self.net_weight,
                    'timeOut'   : self.timeOut_now
                   }

        columns = WeighOut_dict.keys()
        values = [WeighOut_dict[column] for column in columns]

        insert_statement = 'UPDATE barkies2018_db SET (%s) = %s WHERE tm9_ticket = %s;'
        strng = self.TM9_entry.get()

        cur1.execute(insert_statement, (AsIs(','.join(columns)), tuple(values), strng))

        self.WeighOUT.config(state='disabled',bg='grey')
        self.WeighIN.config(state='disabled',bg='grey')
        self.update_colors_truck()
        cur1.close()
예제 #11
0
    def weighIN(self):
        Connect_Brisco_DB = Connect_DB('postgres','postgres',self.ip_add,self.psswd)
        cur1 = Connect_Brisco_DB.crsr()

        try:
            ser = serial.Serial('/dev/ttyUSB0',9600)
            str_weight = ser.readline()
            self.gross_weight =  str_weight.split()[1]
            self.gross_weight =int(self.gross_weight)
            ser.close()
        except:
            self.gross_weight =  100

        self.date_now = str(datetime.datetime.now().date())
        self.timeIn_now = str(datetime.datetime.now().strftime("%H:%M:%S"))

        cur1.execute(sql.SQL("SELECT poploadslip,count FROM barkies2018_db WHERE {} = %s;").format(sql.Identifier('poploadslip')), (self.popDD_val.get(),))
        a = cur1.fetchall()

        try:
            self.new_popCount = int(a[-1][1])+1
        except:
            self.new_popCount = 1

        if self.sampleDD_val.get()=='No':
            binary_sample = 0
        else:
            binary_sample = 1

        #Set labels after weign in
        label_list = [self.date_now,self.timeIn_now,'',str(self.gross_weight),'','',str(self.new_popCount) ]
        rown = 0
        for labl in label_list:

            self.create_place_label(self.frame5, labl, rown, 1, ("Courier", 16), E)
            rown = rown + 1

        self.TrucksInYard.insert(END,self.truckNum_combo_val.get())
        self.TrucksInYard.config(bg=self.truckin_colour)
        self.label_lstbox.config(bg=self.truckin_colour)


        #update Data base
        Weighin_dict = {
                    'daterecieved': self.date_now,
                    'poploadslip' : int(self.popDD_val.get()),
                    'count' : self.new_popCount,
                    'sampleloads' : binary_sample,
                    'tm9_ticket' : self.TM9_entry.get(),
                    'owner' : self.owner_combo_val.get(),
                    'disposition_fmanum' : self.FMA_combo_val.get(),
                    'workingcircle' : self.wCircle_combo_val.get(),
                    'blocknum' : self.blockNum_entry.get(),
                    'loggingco' : self.logCo_combo_val.get(),
                    'haulingcontractor' : self.hauledBy_combo_val.get(),
                    'truckplate' : self.truckLicense_combo_val.get(),
                    'trucknum' : self.truckNum_combo_val.get(),
                    'truckaxle' : int(self.axle_combo_val.get()),
                    'grossweight' : self.gross_weight,
                    'timeIn'  :     self.timeIn_now,
                    'numpcsreceived' : self.numPieces_entry.get()
                   }

        self.Lst_truckInfo.append(Weighin_dict)
        trucknum_indx = len(self.Lst_truckInfo)-1

        columns = Weighin_dict.keys()
        # values = [Weighin_dict[column] for column in columns]
        values = [None if Weighin_dict[key] == '' else Weighin_dict[key] for key in columns]

        insert_statement = 'INSERT INTO barkies2018_db (%s) VALUES %s'

        #check if previous TM9 same was entered
        check_statement = 'SELECT tm9_ticket FROM barkies2018_db'

        cur1.execute('SELECT tm9_ticket FROM barkies2018_db')
        check_tm9 = cur1.fetchall()

        keys = ['tm9_ticket','blocknum','numpcsreceived']

        if [item for item in check_tm9 if Weighin_dict['tm9_ticket'] in item]:
            tkMessageBox.showinfo("WHOOPS!","That TM9 already Exists!")
            del self.Lst_truckInfo[trucknum_indx]
            self.TrucksInYard.delete(trucknum_indx)

        elif not any(Weighin_dict[key] for key in keys):
            tkMessageBox.showinfo("WHOOPS!","I think you forgot to enter something!")
            del self.Lst_truckInfo[trucknum_indx]
            self.TrucksInYard.delete(trucknum_indx)
        else:

            try:
                cur1.execute(insert_statement, (AsIs(','.join(columns)), tuple(values)))
                self.change_state(self.truckLicense_combo)
                self.change_state(self.hauledBy_combo)
                self.change_state(self.axle_combo)
                self.change_state(self.FMA_combo)
                self.change_state(self.wCircle_combo)

            except:
                tkMessageBox.showinfo("WHOOPS!","Make sure all values are filled in!")
                # trucknum_indx = next(index for (index, d) in enumerate(self.Lst_truckInfo) if d['trucknum'] == self.TrucksInYard.get(self.TrucksInYard.curselection()))
                del self.Lst_truckInfo[trucknum_indx]
                self.TrucksInYard.delete(trucknum_indx)

	self.WeighOUT.config(state='disabled',bg='grey')
        self.WeighIN.config(state='disabled',bg='grey')
        self.update_colors_truck()
        cur1.close()