forked from pnprog/goreviewpartner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
139 lines (104 loc) · 3.75 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
# -*- coding:Utf-8 -*-
import sys, os
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, e:
print "Could not import the Tkinter librairy, please double check it is installed:"
print str(e)
raw_input()
sys.exit()
import dual_view
import settings
from toolbox import *
from toolbox import _
from live_analysis import LiveAnalysisLauncher
log("Checking availability of config file")
import ConfigParser
Config = ConfigParser.ConfigParser()
try:
Config.readfp(open(config_file))
except Exception, e:
show_error(_("Could not open the config file of Go Review Partner")+"\n"+str(e))
sys.exit()
class Main(Toplevel):
def __init__(self,parent):
Toplevel.__init__(self,parent)
self.parent=parent
bg=self.cget("background")
logo = Canvas(self,bg=bg,width=5,height=5)
logo.pack(fill=BOTH,expand=1)
logo.bind("<Configure>",lambda e: draw_logo(logo,e))
label = Label(self, text=_("This is GoReviewPartner"), font="-weight bold")
label.pack(padx=5, pady=5)
self.popups=[]
self.analysis_bouton=Button(self, 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, 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, text=_("Run a live analysis"), command=self.launch_live_analysis)
self.live_bouton.pack(fill=X,padx=5, pady=5)
review_bouton=Button(self, text=_("Open a RSGF file for review"), command=self.launch_review)
review_bouton.pack(fill=X,padx=5, pady=5)
bouton=Button(self, text=_("Settings"), command=self.launch_settings)
bouton.pack(fill=X,padx=5, pady=5)
self.protocol("WM_DELETE_WINDOW", self.close)
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)
log(filename)
log("gamename:",filename[:-4])
if not filename:
return
log("filename:",filename)
new_popup=RangeSelector(self.parent,filename,bots=get_available("AnalysisBot"))
self.parent.add_popup(new_popup)
def download_sgf_for_review(self):
new_popup=DownloadFromURL(self.parent,bots=get_available("AnalysisBot"))
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)
log(filename)
if not filename:
return
display_factor=.5
screen_width = self.parent.winfo_screenwidth()
screen_height = self.parent.winfo_screenheight()
width=int(display_factor*screen_width)
height=int(display_factor*screen_height)
new_popup=dual_view.DualView(self.parent,filename,min(width,height))
self.parent.add_popup(new_popup)
def launch_settings(self):
settings.OpenSettings(self)
def refresh(self):
log("refreshing")
Config = ConfigParser.ConfigParser()
Config.read(config_file)
if len(get_available("AnalysisBot"))==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("LiveAnalysisBot"))==0:
self.live_bouton.config(state='disabled')
else:
self.live_bouton.config(state='normal')
app = Application()
popup=Main(app)
popup.refresh()
app.add_popup(popup)
app.mainloop()