コード例 #1
0
ファイル: primaryGUI.py プロジェクト: tairabiteru/NDL-DVCL
 def refresh(self):
     self.currentTable = getAll('patrons')
     stype = None
     direct = 'up'
     for key, value in self.disptable.directions.iteritems():
         if value:
             stype = key
             direct = value
     self.disptable = DisplayTable(self, self.currentTable, sorttype=stype, direction=direct)
     self.currentTable = self.disptable.currentTable
     self.populate(self.currentTable)
     self.getInfoButton.configure(state=tk.DISABLED)
コード例 #2
0
ファイル: metrics.py プロジェクト: tairabiteru/NDL-DVCL2
    def __init__(self, primary):
        logTC("Creating MetricsWindow from metrics.py")
        self.primary = primary

        self.mwin = tk.Toplevel(primary)
        self.mwin.protocol("WM_DELETE_WINDOW", self.close)
        self.mwin.geometry("750x600")
        self.mwin.wm_title("Metrics Generator")
        self.mwin.focus_set()
        self.mwin.grab_set()

        self.data = getAll('patrons')

        self.outputLB = tk.Text(self.mwin, height=35, width=100)
        self.outputLB.grid(column=1, row=1)

        self.test()
コード例 #3
0
ファイル: primaryGUI.py プロジェクト: tairabiteru/NDL-DVCL2
 def refresh(self, new=False):
     if not new:
         try:
             rtnval = self.selected.curselection()
         except AttributeError:
             rtnval = False
         self.deleteButton.configure(state=tk.DISABLED)
         self.getInfoButton.configure(state=tk.DISABLED)
     self.currentTable = getAll('patrons')
     if new:
         rtnval = len(self.currentTable)
         rtnval = [rtnval]
     stype = None
     direct = 'up'
     for key, value in self.disptable.directions.iteritems():
         if value:
             stype = key
             direct = value
     self.disptable = DisplayTable(self, self.currentTable, sorttype=stype, direction=direct)
     self.currentTable = self.disptable.currentTable
     self.populate(self.currentTable)
     if rtnval:
         self.detectSelect(self.selected, rtn=rtnval)
コード例 #4
0
ファイル: advsearch.py プロジェクト: tairabiteru/NDL-DVCL2
    def __init__(self, AdvSearchWin):
        self.fulltable = getAll("patrons")
        self.searchedtable = []

        self.posdict = {
            "ID Number": 0,
            "First Name": 1,
            "Middle Name": 2,
            "Last Name": 3,
            "Any part of the Name": -1,
            "Municipality": 4,
            "State": 5,
            "Number of Visitor Cards": 6,
            "Status": 7,
        }
        for record in self.fulltable:

            if AdvSearchWin.numberSelectorVar.get() == "Is Equal To":
                if AdvSearchWin.numberOptionVar.get() == "Number of Visitor Cards":
                    if len(multiParse(record[self.posdict[AdvSearchWin.numberOptionVar.get()]])) == int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)
                else:
                    if record[self.posdict[AdvSearchWin.numberOptionVar.get()]] == int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)

            if AdvSearchWin.numberSelectorVar.get() == "Is Greater Than":
                if AdvSearchWin.numberOptionVar.get() == "Number of Visitor Cards":
                    if len(multiParse(record[self.posdict[AdvSearchWin.numberOptionVar.get()]])) > int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)
                else:
                    if record[self.posdict[AdvSearchWin.numberOptionVar.get()]] > int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)

            if AdvSearchWin.numberSelectorVar.get() == "Is Less Than":
                if AdvSearchWin.numberOptionVar.get() == "Number of Visitor Cards":
                    if len(multiParse(record[self.posdict[AdvSearchWin.numberOptionVar.get()]])) < int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)
                else:
                    if record[self.posdict[AdvSearchWin.numberOptionVar.get()]] < int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)

            if AdvSearchWin.numberSelectorVar.get() == "Is Greater Than Or Equal To":
                if AdvSearchWin.numberOptionVar.get() == "Number of Visitor Cards":
                    if len(multiParse(record[self.posdict[AdvSearchWin.numberOptionVar.get()]])) >= int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)
                else:
                    if record[self.posdict[AdvSearchWin.numberOptionVar.get()]] >= int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)

            if AdvSearchWin.numberSelectorVar.get() == "Is Less Than Or Equal To":
                if AdvSearchWin.numberOptionVar.get() == "Number of Visitor Cards":
                    if len(multiParse(record[self.posdict[AdvSearchWin.numberOptionVar.get()]])) <= int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)
                else:
                    if record[self.posdict[AdvSearchWin.numberOptionVar.get()]] <= int(
                        AdvSearchWin.numberEntryVar.get()
                    ):
                        self.searchedtable.append(record)

            if AdvSearchWin.nameOptionBoxVar.get():
                pass

            if AdvSearchWin.statusOptionBoxVar.get():
                pass

        print self.searchedtable
コード例 #5
0
ファイル: primaryGUI.py プロジェクト: tairabiteru/NDL-DVCL2
 def resetSearch(self):
     table = getAll('patrons')
     self.searchBox.delete(0, 'end')
     self.disptable = DisplayTable(self, table, sorttype='last', direction='up')
     self.currentTable = self.disptable.currentTable
     self.populate(self.currentTable)
コード例 #6
0
ファイル: primaryGUI.py プロジェクト: tairabiteru/NDL-DVCL2
    def __init__(self, parent, *args, **kwargs):
        logTC("Creating MainApp from primaryGUI.py")
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent

        self.selected = 0

        self.currentTable = []

        self.currentSort = "last"

        self.menuBar = tk.Menu(self.parent)
        self.parent.configure(menu=self.menuBar)

        self.fileMenu = tk.Menu(self.menuBar, tearoff=0)
        self.fileMenu.add_command(label='Advanced Search', command=self.execadvsearch)
        self.fileMenu.add_command(label='Exit', command=self.terminate)
        self.menuBar.add_cascade(label='File', menu=self.fileMenu)

        self.toolsMenu = tk.Menu(self.menuBar, tearoff=0)
        self.toolsMenu.add_command(label='Generate Metrics', command=self.genMetrics)
        self.toolsMenu.add_command(label='Reset Configuration File', command=self.resetConfig)
        self.menuBar.add_cascade(label='Tools', menu=self.toolsMenu)

        self.helpMenu = tk.Menu(self.menuBar, tearoff=0)
        self.helpMenu.add_command(label='About', command=self.aboutWindow)
        self.menuBar.add_cascade(label='Help', menu=self.helpMenu)

        self.searchBoxVar = tk.StringVar()
        self.searchBox = tk.Entry(self, textvariable=self.searchBoxVar)
        self.searchBox.grid(column=2, row=1, pady=(20, 0))
        self.searchBox.bind("<KeyRelease>", self.caps)
        self.searchBox.bind("<Return>", self.lookup)

        self.searchButton = tk.Button(self, text="Search", command=self.lookup)
        self.searchButton.grid(column=3, row=1, pady=(20, 0))

        self.exactSearch = tk.IntVar()
        self.exactSearchCheckbox = tk.Checkbutton(self, text="Exact Search", variable=self.exactSearch)
        self.exactSearchCheckbox.grid(column=3, row=2, pady=(0, 20))

        self.resetSearchButton = tk.Button(self, text="Reset Search", command=self.resetSearch)
        self.resetSearchButton.grid(column=4, row=1, pady=(20, 0))

        self.options = ("Last,First", "Municipality", "State")
        self.searchOptionVar = tk.StringVar()
        self.searchOptionVar.set(self.options[0])
        self.searchOption = tk.OptionMenu(self, self.searchOptionVar, *self.options)
        self.searchOption.grid(column=4, row=2, pady=(0, 20))

        self.refreshButton = tk.Button(self, text="Add Record", command=self.addRecord)
        self.refreshButton.grid(column=6, row=1, pady=PADY)

        self.deleteButton = tk.Button(self, text="Delete Record", command=self.deleteRecord)
        self.deleteButton.grid(column=7, row=1, pady=PADY)
        self.deleteButton.configure(state=tk.DISABLED)

        self.getInfoButton = tk.Button(self, text="Display Patron Info", command=self.getInfo)
        self.getInfoButton.grid(column=8, row=1, pady=PADY)
        self.getInfoButton.configure(state=tk.DISABLED)

        self.scrollbar = tk.Scrollbar(self, orient="vertical", command=self.onScroll)
        self.scrollbar.grid(column=9, row=4, sticky='ns')

        self.statusSortID = ''
        self.idLBLabel = tk.Button(self, text='ID ^', command=lambda: self.sort('id'))
        self.idLBLabel.grid(column=1, row=3, padx=(20,0), sticky='we')
        self.idLB = tk.Listbox(self, width=5, bd=0, highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.idLB.grid(column=1, row=4, padx=(20,0))
        self.idLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.idLB))
        self.idLB.bind("<MouseWheel>", self.onMouseWheel)
        self.idLB.bind("<Double-Button-1>", lambda _: self.getInfo())

        self.statusSortLast = 'up'
        self.lnameLBLabel = tk.Button(self, text='Last', command=lambda: self.sort('last'))
        self.lnameLBLabel.grid(column=2, row=3, sticky='we')
        self.lnameLB = tk.Listbox(self, bd=0, highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.lnameLB.grid(column=2, row=4)
        self.lnameLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.lnameLB))
        self.lnameLB.bind("<MouseWheel>", self.onMouseWheel)
        self.lnameLB.bind("<Double-Button-1>", lambda _: self.getInfo())

        self.statusSortFirst = ''
        self.fnameLBLabel = tk.Button(self, text='First', command=lambda: self.sort('first'))
        self.fnameLBLabel.grid(column=3, row=3, sticky='we')
        self.fnameLB = tk.Listbox(self, bd=0, highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.fnameLB.grid(column=3, row=4)
        self.fnameLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.fnameLB))
        self.fnameLB.bind("<MouseWheel>", self.onMouseWheel)
        self.fnameLB.bind("<Double-Button-1>", lambda _: self.getInfo())

        self.statusSortMiddle = ''
        self.mnameLBLabel = tk.Button(self, text='Middle', command=lambda: self.sort('middle'))
        self.mnameLBLabel.grid(column=4, row=3, sticky='we')                                                               
        self.mnameLB = tk.Listbox(self, bd=0, highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.mnameLB.grid(column=4, row=4)
        self.mnameLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.mnameLB))
        self.mnameLB.bind("<MouseWheel>", self.onMouseWheel)
        self.mnameLB.bind("<Double-Button-1>", lambda _: self.getInfo())

        self.statusSortMuni = ''
        self.muniLBLabel = tk.Button(self, text='Municipality', command=lambda: self.sort('muni'))
        self.muniLBLabel.grid(column=5, row=3, sticky='we') 
        self.muniLB = tk.Listbox(self, bd=0,highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.muniLB.grid(column=5, row=4)
        self.muniLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.muniLB))
        self.muniLB.bind("<MouseWheel>", self.onMouseWheel)
        self.muniLB.bind("<Double-Button-1>", lambda _: self.getInfo())

        self.statusSortState = ''
        self.stateLBLabel = tk.Button(self, text='State', command=lambda: self.sort('state'))
        self.stateLBLabel.grid(column=6, row=3, sticky='we')
        self.stateLB = tk.Listbox(self, bd=0,highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.stateLB.grid(column=6, row=4)
        self.stateLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.stateLB))
        self.stateLB.bind("<MouseWheel>", self.onMouseWheel)
        self.stateLB.bind("<Double-Button-1>", lambda _: self.getInfo())

        self.statusSortCards = ''
        self.cardTimesLBLabel = tk.Button(self, text='Cards Issued', command=lambda: self.sort('cards'))
        self.cardTimesLBLabel.grid(column=7, row=3, sticky='we')
        self.cardTimesLB = tk.Listbox(self, bd=0,highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.cardTimesLB.grid(column=7, row=4)
        self.cardTimesLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.cardTimesLB))
        self.cardTimesLB.bind("<MouseWheel>", self.onMouseWheel)
        self.cardTimesLB.bind("<Double-Button-1>", lambda _: self.getInfo())

        self.statusSortStatus = ''
        self.statusLBLabel = tk.Button(self, text='Status', command=lambda: self.sort('status'))
        self.statusLBLabel.grid(column=8, row=3, sticky='we')
        self.statusLB = tk.Listbox(self, bd=0,highlightthickness=0, exportselection=0, yscrollcommand=self.scrollbar.set, height=YSIZE)
        self.statusLB.grid(column=8, row=4)
        self.statusLB.bind('<<ListboxSelect>>', lambda _: self.detectSelect(self.statusLB))
        self.statusLB.bind("<MouseWheel>", self.onMouseWheel)
        self.statusLB.bind("<Double-Button-1>", lambda _: self.getInfo())
        
        table = getAll('patrons')
        if Config.defaultsort in ('id', 'last', 'first', 'middle', 'muni', 'state', 'cards', 'status'):
            st = Config.defaultsort
        else:
            logTC('Invalid option set in config for defaultsort: \'' + Config.defaultsort + '\'. Using default instead.', 'WARNING')
            st = 'id'
        if Config.defaultsortorder in ('up', 'down'):
            d = Config.defaultsortorder
        else:
            logTC('Invalid option set in config for defaultsortorder: \'' + Config.defaultsortorder + '\'. Using default instead.', 'WARNING')
            d = 'up'
        if not table:
            if not existsTable():
                self.searchButton.configure(state=tk.DISABLED)
                self.resetSearchButton.configure(state=tk.DISABLED)
                self.refreshButton.configure(state=tk.DISABLED)
                self.deleteButton.configure(state=tk.DISABLED)
                self.getInfoButton.configure(state=tk.DISABLED)
                self.idLBLabel.configure(state=tk.DISABLED)
                self.lnameLBLabel.configure(state=tk.DISABLED)
                self.fnameLBLabel.configure(state=tk.DISABLED)
                self.mnameLBLabel.configure(state=tk.DISABLED)
                self.muniLBLabel.configure(state=tk.DISABLED)
                self.stateLBLabel.configure(state=tk.DISABLED)
                self.cardTimesLBLabel.configure(state=tk.DISABLED)
                self.statusLBLabel.configure(state=tk.DISABLED)
                logTC('Table not initialized', 'ERROR')
                e = ErrorWindow(self, "Table not initialized")
            else:
                logTC("Table contains no data", "INFO")

        self.disptable = DisplayTable(self, table, sorttype=st, direction=d)
        self.populate(self.disptable.currentTable, True)
コード例 #7
0
ファイル: primaryGUI.py プロジェクト: tairabiteru/NDL-DVCL2
 def lookup(self, *args):
     self.getInfoButton.configure(state=tk.DISABLED)
     sterm = self.searchBoxVar.get()
     option = self.searchOptionVar.get()
     if not sterm:
         logTC("Nothing entered into search box.", "ERROR")
         e = ErrorWindow(self, "Nothing entered into search box.")
         return False
     else:
         if option == 'Last,First':
             sterm = nameVAndF(sterm)
             if not sterm:
                 logTC("Entered name not in correct format.", "ERROR")
                 e = ErrorWindow(self, "Entered name not in correct format.")
             else:
                 if self.exactSearch.get():
                     if not sterm[1]:
                         ln = sterm[0]
                         results = filt('patrons', lname=ln)
                     elif not sterm[0]:
                         fn = sterm[1]
                         results = filt('patrons', fname=fn)
                     else:
                         ln = sterm[0]
                         fn = sterm[1]
                         results = filt('patrons', fname=fn, lname=ln)
                 else:
                     results = getAll('patrons')
                     w_results = []
                     for result in results:
                         rl = 0
                         rf = 0
                         try:
                             rl = difflib.SequenceMatcher(None, result[3], sterm[0]).ratio()
                             rf = difflib.SequenceMatcher(None, result[1], sterm[1]).ratio()
                         except TypeError:
                             pass
                         w_results.append((result, rl + rf))
                     w_results = sorted(w_results, key=lambda x: x[1], reverse=True)
                     results= []
                     for res in w_results:
                         results.append(res[0])
         if option == 'Municipality':
             if self.exactSearch.get():
                 results = filt('patrons', muni=sterm)
             else:
                 results = getAll('patrons')
                 w_results = []
                 for result in results:
                     ratio = difflib.SequenceMatcher(None, result[4], sterm).ratio()
                     w_results.append((result, ratio))
                 w_results = sorted(w_results, key=lambda x: x[1], reverse=True)
                 results = []
                 for res in w_results:
                     results.append(res[0])
         if option == 'State':
             if self.exactSearch.get():
                 results = filt('patrons', state=sterm)
             else:
                 results = getAll('patrons')
                 w_results = []
                 for result in results:
                     ratio = difflib.SequenceMatcher(None, result[5], sterm).ratio()
                     w_results.append((result, ratio))
                 w_results = sorted(w_results, key=lambda x: x[1], reverse=True)
                 results = []
                 for res in w_results:
                     results.append(res[0])
             
         self.populate(results)
コード例 #8
0
ファイル: addrecord.py プロジェクト: tairabiteru/NDL-DVCL2
 def validate(self, issuePass=False):
     self.arr = []
     self.arr.append(self.idVar.get())
     if not self.fnameVar.get():
         logTC("First name field may not be empty", "ERROR")
         e = ErrorWindow(self.arwin, "First name field may not be empty.")
         return -1
     valid = validateName(self.fnameVar.get())
     if not valid[0]:
         logTC("Invalid character in first name field: '" + valid[1] + "'", "ERROR")
         e = ErrorWindow(self.arwin, "Invalid character in first name field: '" + valid[1] + "'")
         return -1
     self.arr.append(self.fnameVar.get().upper())
     if not self.mnameVar.get():
         logTC("Middle name field may not be empty", "ERROR")
         e = ErrorWindow(self.arwin, "Middle name field may not be empty.")
         return -1
     valid = validateName(self.mnameVar.get())
     if not valid[0]:
         logTC("Invalid character in middle name field: '" + valid[1] + "'", "ERROR")
         e = ErrorWindow(self.arwin, "Invalid character in middle name field: '" + valid[1] + "'")
         return -1
     self.arr.append(self.mnameVar.get().upper())
     if not self.lnameVar.get():
         logTC("Last name field may not be empty", "ERROR")
         e = ErrorWindow(self.arwin, "Last name field may not be empty.")
         return -1
     valid = validateName(self.lnameVar.get())
     if not valid[0]:
         logTC("Invalid character in last name field: '" + valid[1] + "'", "ERROR")
         e = ErrorWindow(self.arwin, "Invalid character in last name field: '" + valid[1] + "'")
         return -1
     self.arr.append(self.lnameVar.get().upper())
     if not self.muniVar.get():
         logTC("Location field may not be empty", "ERROR")
         e = ErrorWindow(self.arwin, "Location field may not be empty.")
         return -1
     valid = validateMuni(self.muniVar.get().upper())
     if not valid[0]:
         logTC("Invalid character in the location field: '" + valid[1] + "'", "ERROR")
         e = ErrorWindow(self.arwin, "Invalid character in the location field: '" + valid[1] + "'")
         return -1
     self.arr.append(self.muniVar.get().upper())
     self.arr.append(self.stateOptionsVar.get())
     self.arr.append(None)
     if self.statusOptionsVar.get() == 'OK':
         self.arr.append(None)
     elif self.statusOptionsVar.get() == 'BLOCKED':
         self.arr.append('BLOCKED')
     elif self.statusOptionsVar.get() == 'BARRED':
         self.arr.append('BARRED')
     else:
         e = ErrorWindow(self.arwin, "Invalid status setting. (If you see this, contact an administrator)", "425x100")
         logTC("Invalid status setting", "ERROR")
         return -1
     if self.bandateVar.get():
         if self.bandateVar.get() in ("NEVER", "CONDITIONAL"):
             logTC("Invalid argument in bandate field!", "ERROR")
             e = ErrorWindow(self.arwin, "You cannot use NEVER or CONDITIONAL in the ban date field.", "425x100")
             return -1
         try:
             sd = Date(self.bandateVar.get())
             self.arr.append(self.bandateVar.get())
         except Exception as e:
             logTC("Invalid ban date entered!", "ERROR")
             e = ErrorWindow(self.arwin, "Invalid ban date entered!")
             return -1
     else:
         self.arr.append(None)
     if self.expdateVar.get():
         try:
             sd = Date(self.expdateVar.get())
             self.arr.append(self.expdateVar.get())
         except Exception as e:
             logTC("Invalid expiration date entered!", "ERROR")
             e = ErrorWindow(self.arwin, "Invalid expiration date entered!")
             return -1
     else:
         self.arr.append(None)
     if self.barcodeVar.get():
         barcode = self.barcodeVar.get()
         if not validateBarcode(barcode):
             logTC("Invalid barcode!", "ERROR")
             e = ErrorWindow(self.arwin, "Invalid barcode entered!")
         else:
             self.arr.append(self.barcodeVar.get())
     else:
         self.arr.append(None)
     if any(letter.isalpha() for letter in self.reasonText.get("1.0", tk.END)):
         self.arr.append(self.reasonText.get("1.0", tk.END))
     else:
         self.arr.append(None)
     self.arr.append(self.aiText.get("1.0", tk.END))
     if self.arr[7] in ("BLOCKED", "BARRED"):
         if not self.arr[8]:
             logTC("Patron with isBanned == BLOCKED or BARRED cannot have NULL Ban Date field.", "ERROR")
             e = ErrorWindow(self.arwin, "A BLOCKED or BARRED patron may not have their Ban Date field be blank.", "425x100")
             return -1
         if not self.arr[11]:
             logTC("Patron with isBanned == BLOCKED or BARRED cannot have NULL reason field.", "ERROR")
             e = ErrorWindow(self.arwin, "A BLOCKED or BARRED patron may not have their reason field be blank.", "425x100")
             return -1
     table = getAll('patrons')
     flag = False
     if Config.EnforceNoDuplicates:
         duplicate = False
         for record in table:
             if self.arr[1] == record[1]:
                 if self.arr[3] == record[3]:
                     duplicate = True
                     break
         if duplicate:
             w = CDWindow(self, self.arwin, record, vp=issuePass)
         else:
             flag = True
     else:
         flag = True
                 
                         
     if flag:
         if issuePass:
             self.confirmVP()
         else:
             self.commitToDB()