-
Notifications
You must be signed in to change notification settings - Fork 297
/
YEDDA_Admin.py
148 lines (124 loc) · 5.33 KB
/
YEDDA_Admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'''
# @ Author: Jie Yang
# @ Create Time: 2018
# @ Last Modified by: Jie Yang Contact: jieynlp@gmail.com
# @ Last Modified time: 2022-04-20 12:51:14
'''
# -*- coding: utf-8 -*-
import platform
import tkinter.filedialog as tkFileDialog
import tkinter.messagebox as tkMessageBox
from tkinter import *
from tkinter.ttk import * # Frame, Button, Label, Style, Scrollbar
from utils.compareAnn import *
from utils.metric4ann import *
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.Version = "YEDDA-V1.0 Administrator"
self.OS = platform.system().lower()
self.parent = parent
self.fileName = ""
# default GUI display parameter
self.textColumn = 3
self.initUI()
def initUI(self):
self.parent.title(self.Version)
self.pack(fill=BOTH, expand=True)
for idx in range(0, self.textColumn):
if idx == 1:
self.columnconfigure(idx, weight=10)
else:
self.columnconfigure(idx, weight=1)
# for idx in range(0,2):
# self.rowconfigure(idx, weight =1)
the_font = ('TkDefaultFont', 18,)
style0 = Style()
style0.configure(".", font=the_font, )
width_size = 30
abtn = Button(self, text="Multi-Annotator Analysis", command=self.multiFiles, width=width_size)
abtn.grid(row=0, column=1)
recButton = Button(self, text="Pairwise Comparison", command=self.compareTwoFiles, width=width_size)
recButton.grid(row=1, column=1)
cbtn = Button(self, text="Quit", command=self.quit, width=width_size)
cbtn.grid(row=2, column=1)
def ChildWindow(self, input_list, result_matrix):
file_list = []
for dir_name in input_list:
if ".ann" in dir_name:
dir_name = dir_name[:-4]
if "/" in dir_name:
file_list.append(dir_name.split('/')[-1])
else:
file_list.append(dir_name)
# Create menu
self.popup = Menu(self.parent, tearoff=0)
self.popup.add_command(label="Next", command=self.selection)
self.popup.add_separator()
def do_popup(event):
# display the popup menu
try:
self.popup.selection = self.tree.set(self.tree.identify_row(event.y))
self.popup.post(event.x_root, event.y_root)
finally:
# make sure to release the grab (Tk 8.0a1 only)
self.popup.grab_release()
# Create Treeview
win2 = Toplevel(self.parent)
new_element_header = file_list
treeScroll = Scrollbar(win2)
treeScroll.pack(side=RIGHT, fill=Y)
title_string = "F:Entity/Chunk"
self.tree = Treeview(win2, columns=[title_string] + file_list, show="headings")
self.tree.heading(title_string, text=title_string, anchor=CENTER)
self.tree.column(title_string, stretch=YES, minwidth=50, width=100, anchor=CENTER)
for each_file in file_list:
self.tree.heading(each_file, text=each_file, anchor=CENTER)
self.tree.column(each_file, stretch=YES, minwidth=50, width=100, anchor=CENTER)
for idx in range(len(file_list)):
self.tree.insert("", 'end', text=file_list[idx], values=[file_list[idx]] + result_matrix[idx],
tags=('chart',))
the_font = ('TkDefaultFont', 18,)
self.tree.tag_configure('chart', font=the_font)
style = Style()
style.configure(".", font=the_font, )
style.configure("Treeview", )
style.configure("Treeview.Heading", font=the_font, ) # <----
self.tree.pack(side=TOP, fill=BOTH)
# self.tree.grid()
self.tree.bind("<Button-3>", do_popup)
win2.minsize(30, 30)
def selection(self):
print(self.popup.selection)
def multiFiles(self):
ftypes = [('ann files', '.ann')]
filez = tkFileDialog.askopenfilenames(parent=self.parent, filetypes=ftypes, title='Choose a file')
if len(filez) < 2:
tkMessageBox.showinfo("Monitor Error", "Selected less than two files!\n\nPlease select at least two files!")
else:
result_matrix = generate_report_from_list(filez)
self.ChildWindow(filez, result_matrix)
def compareTwoFiles(self):
ftypes = [('ann files', '.ann')]
filez = tkFileDialog.askopenfilenames(parent=self.parent, filetypes=ftypes, title='Choose a file')
if len(filez) != 2:
tkMessageBox.showinfo("Compare Error", "Please select exactly two files!")
else:
outfile = tkFileDialog.asksaveasfilename(defaultextension=".tex")
write_result = compareBoundary(filez[0], filez[1], outfile)
if write_result:
tkMessageBox.showinfo("Latex Generate", "Latex file generated successfully!\n\nSaved to " + outfile)
# import os
# os.system("pdflatex "+ f.name)
else:
tkMessageBox.showinfo("Latex Error",
"Latex generated Error, two files don't have same sentence number!")
def main():
print("SUTDAnnotator launched!")
print(("OS:%s") % (platform.system()))
root = Tk()
root.geometry("400x100")
app = Example(root)
root.mainloop()
if __name__ == '__main__':
main()