-
Notifications
You must be signed in to change notification settings - Fork 65
/
main.py
184 lines (138 loc) · 5.1 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys, os
if (sys.version_info > (3, 0)):
print("GoReviewPartner needs Python version 2 (e.g. 2.7.9) to run.")
print("GoReviewPartner cannot work with verions 3 of Python at the moment.")
print("Sorry about that :/")
input()
exit()
print("STDIN encoding:",sys.stdin.encoding)
print("STDOUT encoding:",sys.stdout.encoding)
print("STDERR encoding:",sys.stderr.encoding)
print("File system encoding:",sys.getfilesystemencoding())
try:
from Tkinter import *
except Exception:
print("Could not import the Tkinter librairy, please double check it is installed.")
raw_input()
sys.exit()
import dual_view
import settings
from toolbox import *
from toolbox import _
from live_analysis import LiveAnalysisLauncher
from r2sgf import rsgf2sgf
from r2csv import rsgf2csv
class Main(Toplevel):
def __init__(self,parent):
Toplevel.__init__(self,parent)
self.parent=parent
bg=self.cget("background")
self.popups=[]
self.control_frame = Frame(self)
label = Label(self.control_frame, text=_("This is GoReviewPartner"), font="-weight bold")
label.pack(padx=5, pady=5)
self.analysis_bouton=Button(self.control_frame, text=_("Run a SGF file analysis"), command=self.launch_analysis)
self.analysis_bouton.pack(fill=X,padx=5, pady=5)
self.download_bouton=Button(self.control_frame, text=_("Download a SGF file for analysis"), command=self.download_sgf_for_review)
self.download_bouton.pack(fill=X,padx=5, pady=5)
self.live_bouton=Button(self.control_frame, text=_("Run a live analysis"), command=self.launch_live_analysis)
self.live_bouton.pack(fill=X,padx=5, pady=5)
review_bouton=Button(self.control_frame, text=_("Open a RSGF file for review"), command=self.launch_review)
review_bouton.pack(fill=X,padx=5, pady=5)
r2sgf_bouton=Button(self.control_frame, text=_("Convert RSGF file to SGF file"), command=self.r2sgf)
r2sgf_bouton.pack(fill=X,padx=5, pady=5)
r2csv_bouton=Button(self.control_frame, text=_("Convert RSGF file to CSV file"), command=self.r2csv)
r2csv_bouton.pack(fill=X,padx=5, pady=5)
bouton=Button(self.control_frame, text=_("Settings"), command=self.launch_settings)
bouton.pack(fill=X,padx=5, pady=5)
self.control_frame.pack(fill=X, side=BOTTOM)
self.logo_frame = Frame(self)
logo = Canvas(self.logo_frame,bg=bg,width=5,height=5)
logo.pack(fill=BOTH, expand=1)
logo.bind("<Configure>",lambda e: draw_logo(logo,e))
self.logo_frame.pack(fill=BOTH, side=BOTTOM, expand=1)
self.protocol("WM_DELETE_WINDOW", self.close)
def r2sgf(self):
filename = open_rsgf_file(parent=self.parent)
if not filename:
return
rsgf2sgf(filename)
show_info(_("The file %s has been converted to %s")%(os.path.basename(filename),os.path.basename(filename)+".sgf"),parent=self.parent)
def r2csv(self):
filename = open_rsgf_file(parent=self.parent)
if not filename:
return
rsgf2csv(filename)
show_info(_("The file %s has been converted to %s")%(os.path.basename(filename),os.path.basename(filename)+".csv"),parent=self.parent)
def close(self):
for popup in self.popups[:]:
popup.close()
log("closing Main")
self.destroy()
self.parent.remove_popup(self)
def launch_analysis(self):
filename = open_sgf_file(parent=self)
if not filename:
return
log("filename:",filename)
new_popup=RangeSelector(self.parent,filename,bots=get_available())
self.parent.add_popup(new_popup)
def download_sgf_for_review(self):
new_popup=DownloadFromURL(self.parent,bots=get_available())
self.parent.add_popup(new_popup)
def launch_live_analysis(self):
new_popup=LiveAnalysisLauncher(self.parent)
self.parent.add_popup(new_popup)
def launch_review(self):
filename = open_rsgf_file(parent=self.parent)
if not filename:
return
new_popup=dual_view.DualView(self.parent,filename)
self.parent.add_popup(new_popup)
def launch_settings(self):
new_popup=settings.OpenSettings(self.parent,refresh=self.refresh)
self.parent.add_popup(new_popup)
def refresh(self):
log("refreshing")
if len(get_available())==0:
self.analysis_bouton.config(state='disabled')
self.download_bouton.config(state='disabled')
self.live_bouton.config(state='disabled')
else:
self.analysis_bouton.config(state='normal')
self.download_bouton.config(state='normal')
self.live_bouton.config(state='normal')
if len(get_available())==0:
self.live_bouton.config(state='disabled')
else:
self.live_bouton.config(state='normal')
if __name__ == "__main__":
app = Application()
if len(sys.argv)==1:
popup=Main(app)
popup.refresh()
app.add_popup(popup)
app.mainloop()
else:
opened=0
for filename in argv[1:]:
log(filename,"???")
extension=filename[-4:].lower()
log("extension",extension)
if extension=="rsgf":
opened+=1
log("Opening",filename)
popup=dual_view.DualView(app,filename)
app.add_popup(popup)
elif extension==".sgf":
log("Opening",filename)
popup=RangeSelector(app,filename,bots=get_available())
app.add_popup(popup)
opened+=1
if not opened:
popup=Main(app)
popup.refresh()
app.add_popup(popup)
app.mainloop()