123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- import hashlib
- import sys
- from tkinter import *
- import helpers
- root = Tk()
- titleLabel = StringVar()
- text = StringVar()
- filesInfo = None
- csvFiles = None
- state = None
- acceptedDataCSV = None
- rejectedDataCSV = None
- def findDuplicate (hashDict, title):
- if title in hashDict:
- return True
- else:
- return False
- def acceptPaper (file, csvRow, index):
- global state
- global acceptedDataCSV
- fileFilter = helpers.getFilter(file)
- data = fileFilter.getCSVData(csvRow)
- digest = hashlib.sha256(str.encode(fileFilter.getTitle(csvRow))).hexdigest()
- duplicate = findDuplicate(rejectedDataCSV, digest) or findDuplicate(acceptedDataCSV, digest)
- if duplicate:
- state['duplihttps://mail.google.com/mail/u/0/#inboxcate'] += 1
- else:
- data.append("{0} - {1}".format(file['path'],index))
- acceptedDataCSV[digest] = data
- state['accepted'] += 1
- return
- def rejectPaper (file, csvRow, index):
- global rejectedDataCSV
- global state
- fileFilter = helpers.getFilter(file)
- data = fileFilter.getCSVData(csvRow)
- digest = hashlib.sha256(str.encode(fileFilter.getTitle(csvRow))).hexdigest()
- duplicate = findDuplicate(rejectedDataCSV, digest) or findDuplicate(acceptedDataCSV, digest)
- if duplicate:
- state['duplicate'] += 1
- else:
- data.append("{0} - {1}".format(file['path'],index))
- rejectedDataCSV[digest] = data
- state['rejected'] += 1
- return
- def rejectButtonHandler (*arg):
- global state
- global csvFiles
- index = state['row_index']
- fileIndex = state['file_index']
- fileTuple = csvFiles[fileIndex]
- rejectPaper(fileTuple[1], fileTuple[0][index], index)
- nextPaper()
- return
- def acceptButtonHandler (*arg):
- global state
- global csvFiles
- index = state['row_index']
- fileIndex = state['file_index']
- fileTuple = csvFiles[fileIndex]
- acceptPaper(fileTuple[1], fileTuple[0][index], index)
- nextPaper()
- return
- def updateAndClear (textField, *args):
- textField.config(state=NORMAL)
- textField.delete('1.0', END)
- textField.insert(INSERT, text.get())
- textField.tag_add("center", '1.0', END)
- textField.config(state=DISABLED)
- def loadFiles ():
- global filesInfo
- global csvFiles
- global state
- global root
- global acceptedDataCSV
- global rejectedDataCSV
- filesInfo = helpers.loadConfigFile()
- if len(filesInfo) == 0:
- sys.exit("csvconfig.txt not found. You need this file to run the program")
- state = helpers.loadState(root)
- acceptedDataCSV = helpers.restoreAcceptedCSV() #load default file, if present append else create new one
- rejectedDataCSV = helpers.restoreRejectedCSV()
- if len(acceptedDataCSV) == 0:
- acceptedDataCSV['header'] = helpers.FINAL_CSV_HEADERS
- if len(rejectedDataCSV) == 0:
- rejectedDataCSV['header'] = helpers.FINAL_CSV_HEADERS
- csvFiles = [(list(f[0]), f[1]) for f in helpers.loadFiles(filesInfo)]
- setPaperFromState()
- def setPaperFromState ():
- global titleLabel
- global text
- fileIndex = state['file_index']
- if fileIndex >= len(filesInfo):
- return #finished processing
- fileList = csvFiles[fileIndex][0]
- index = state['row_index']
- if index >= len(fileList):
- state['file_index'] += 1
- state['row_index'] = 0
- setPaperFromState()
- else:
- file = fileList[index]
- fileFilter = helpers.getFilter(csvFiles[fileIndex][1])
- title = fileFilter.getTitle(file)
- abstract = fileFilter.getAbstract(file)
- titleLabel.set(title)
- text.set(abstract)
- def nextPaper ():
- global titleLabel
- global text
- global root
- fileIndex = state['file_index']
- if fileIndex >= len(filesInfo):
- helpers.removeStateFile()
- helpers.writeFinalLog(state)
- helpers.saveAcceptedCSV(acceptedDataCSV)
- helpers.saveRejectedCSV(rejectedDataCSV)
- root.destroy()#acabou, fecha essa porra
- return
- fileList = csvFiles[fileIndex][0]
- index = state['row_index'] = state['row_index'] + 1
- if index >= len(fileList):
- state['file_index'] += 1
- state['row_index'] = -1
- nextPaper()
- else:
- file = fileList[index]
- fileFilter = helpers.getFilter(csvFiles[fileIndex][1])
- title = fileFilter.getTitle(file)
- abstract = fileFilter.getAbstract(file)
- titleLabel.set(title)
- text.set(abstract)
- def onClosing ():
- global state
- global root
- global acceptedDataCSV
- global rejectedDataCSV
- helpers.saveState(state)
- helpers.saveAcceptedCSV(acceptedDataCSV)
- helpers.saveRejectedCSV(rejectedDataCSV)
- root.destroy()
- def main ():
- global root
- root.title('Reviewer')
- root.geometry('800x600')
- topFrame = Frame(root)
- bottomFrame = Frame(root)
- bottomFrame.pack(side=BOTTOM)
- topFrame.pack(side=TOP, fill=BOTH, expand=True)
- label = Label(root, textvariable=titleLabel, relief=RAISED)
- label.pack(in_=topFrame, fill=BOTH, side=TOP)
- textField = Text(root)
- textField.tag_configure("center", wrap=WORD)
- textField.pack(in_=topFrame, fill=BOTH, side=TOP)
- accept = Button(root, text ="Accept Paper", command = acceptButtonHandler)
- root.bind('<Right>', lambda e: acceptButtonHandler())
- accept.pack(in_=bottomFrame, side=LEFT)
- reject = Button(root, text ="Reject Paper", command = rejectButtonHandler)
- root.bind('<Down>', lambda e: rejectButtonHandler())
- reject.pack(in_=bottomFrame, side=LEFT)
- textField.insert(INSERT, text.get())
- text.trace('w', lambda *arg: updateAndClear(textField))
- textField.config(state=DISABLED)
- root.protocol("WM_DELETE_WINDOW", onClosing)
- root.mainloop()
- loadFiles()
- main()
|