-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
124 lines (104 loc) · 4.3 KB
/
main.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
import sys
from optparse import OptionParser
from tkinter import Tk, messagebox, ttk
from tkinter.ttk import Notebook
from alpino_page import AlpinoInputPage
from chat_page import CHATPage
from functions import process_input
from styles import apply_styles
class TredBridgeMain(Tk):
def print_state(self):
''' print state of different metadata fields for debugging purposes'''
print('Origutt:\t{}'.format(self.origutt))
print('Revisedutt:\t{}'.format(self.revised_utt))
print('Alpino input:\t{}'.format(self.alpino_input))
print('Sentence:\t{}'.format(self.sentence))
print('Origsent:\t{}\n'.format(self.origsent))
def on_click_tab(self, event):
clicked_tab = self.notebook.tk.call(
self.notebook._w, "identify", "tab", event.x, event.y)
if clicked_tab != '':
self.switch_to_tab(clicked_tab)
def switch_to_tab(self, target_tab):
if self.phase == 0 and target_tab == 1:
result = messagebox.askquestion(
"Continue to Alpino editor",
"Are you done editing the CHAT-utterance?")
if result == 'yes':
self.chat_app.clean_continue_to_alpino()
self.transist_phase(0, 1)
elif self.phase == 1 and target_tab == 0:
result = messagebox.askquestion(
"Return to CHAT editor",
"Do you wish to return to the CHAT-editor?" +
"\nWarning: all changes in the alpino editor are undone.",
icon='warning')
if result == 'yes':
self.alp_app.reset()
self.transist_phase(1, 0)
def transist_phase(self, old_phase, new_phase):
self.phase = new_phase
self.notebook.tab(old_phase, state='disabled')
self.notebook.tab(new_phase, state='normal')
self.notebook.select(new_phase)
if new_phase == 0:
self.chat_app.chat_edit.focus()
elif new_phase == 1:
self.alp_app.alpino_edit.focus()
def __init__(self, input_path, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.input_path = input_path
# input parse
input_info = process_input(self.input_path)
# all utterances and sentences
self.origutt = input_info['origutt']
self.revised_utt = input_info['revised_utt']
self.alpino_input = input_info['alpino_input']
self.sentence = input_info['sentence']
self.sentid = input_info['sent_id']
self.origsent = input_info['origsent']
# fields present at time of input parse
self.revised_exists = input_info['revised_exists']
self.origsent_exists = input_info['origsent_exists']
self.alpino_input_exists = input_info['alpino_input_exists']
# XML contents
self.xml_content = input_info['xml_content']
self.new_xml = ''
self.metadata = input_info['metadata']
# phase the editor is currently in. 0=utterance, 1=alpino.
self.phase = 0
# setup notebook
self.notebook = Notebook(self)
frame1 = ttk.Frame(self.notebook)
frame2 = ttk.Frame(self.notebook)
# add empty frames to notebook tabs
self.notebook.add(frame1, text="CHAT Editor")
self.notebook.add(frame2, text="Alpino Editor")
self.notebook.grid()
# fill the tab frames
self.chat_app = CHATPage(parent=frame1, utterance=self.revised_utt)
self.chat_app.grid()
self.alp_app = AlpinoInputPage(parent=frame2, sentence=self.sentence)
self.alp_app.grid()
# setup tabs
self.notebook.tab(1, state='disabled')
# focus on first screen
self.chat_app.chat_edit.focus()
# mouse binding
self.notebook.bind('<Button-1>', self.on_click_tab)
def main(args=None):
if args is None:
args = sys.argv[1:]
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
default=None, help="edit the given file (default: None)")
(options, args) = parser.parse_args(args)
app = None
if options.filename is None:
app = TredBridgeMain(input_path='test.xml')
else:
app = TredBridgeMain(input_path=options.filename)
apply_styles(app)
app.mainloop()
if __name__ == '__main__':
main()