forked from pnprog/goreviewpartner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
160 lines (125 loc) · 3.89 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
# -*- 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 as e:
print ("Could not import the Tkinter librairy, please double check it is installed:")
print (str(e))
input()
sys.exit()
import dual_view
import settings
from toolbox import *
from toolbox import _
log("Checking availability of config file")
import configparser
Config = configparser.ConfigParser()
try:
Config.readfp(open(config_file))
except Exception as e:
show_error(_("Could not open the config file of Go Review Partner")+"\n"+str(e))
sys.exit()
app = Tk()
app.title('GoReviewPartner')
bg=app.cget("background")
logo = Canvas(app,bg=bg,width=5,height=5)
logo.pack(fill=BOTH,expand=1)
logo.bind("<Configure>",lambda e: draw_logo(logo,e))
label = Label(app, text=_("This is GoReviewPartner"), font="-weight bold")
label.pack(padx=5, pady=5)
popups=[]
from sys import exit
from time import sleep
def close_app():
global popups, app
for popup in popups:
popup.close_app()
log("closing")
app.destroy()
app.quit()
exit()
def launch_analysis():
global popups
filename = open_sgf_file(parent=app)
log(filename)
log("gamename:",filename[:-4])
if not filename:
return
log("filename:",filename)
top = Toplevel(app)
top.parent=app
new_popup=RangeSelector(top,filename,bots=get_available("AnalysisBot"))
new_popup.pack()
popups.append(new_popup)
#top.mainloop()
analysis_bouton=Button(app, text=_("Run a SGF file analysis"), command=launch_analysis)
analysis_bouton.pack(fill=X,padx=5, pady=5)
def download_sgf_for_review():
top = Toplevel(app)
new_popup=DownloadFromURL(top,bots=get_available("AnalysisBot"))
new_popup.pack()
popups.append(new_popup)
download_bouton=Button(app, text=_("Download a SGF file for analysis"), command=download_sgf_for_review)
download_bouton.pack(fill=X,padx=5, pady=5)
from live_analysis import LiveAnalysisLauncher
def launch_live_analysis():
global popups
top = Toplevel(app)
top.parent=app
new_popup=LiveAnalysisLauncher(top)
popups.append(new_popup)
#top.mainloop()
live_bouton=Button(app, text=_("Run a live analysis"), command=launch_live_analysis)
live_bouton.pack(fill=X,padx=5, pady=5)
def launch_review():
filename = open_rsgf_file(parent=app)
log(filename)
if not filename:
return
display_factor=.5
screen_width = app.winfo_screenwidth()
screen_height = app.winfo_screenheight()
width=int(display_factor*screen_width)
height=int(display_factor*screen_height)
top = Toplevel(app)
new_popup=dual_view.DualView(top,filename,min(width,height))
new_popup.pack(fill=BOTH,expand=1)
popups.append(new_popup)
review_bouton=Button(app, text=_("Open a RSGF file for review"), command=launch_review)
review_bouton.pack(fill=X,padx=5, pady=5)
def launch_settings():
settings.OpenSettings(app)
def refresh():
log("refreshing")
global review_bouton, analysis_bouton
Config = configparser.ConfigParser()
Config.read(config_file)
if len(get_available("AnalysisBot"))==0:
analysis_bouton.config(state='disabled')
download_bouton.config(state='disabled')
live_bouton.config(state='disabled')
else:
analysis_bouton.config(state='normal')
download_bouton.config(state='normal')
live_bouton.config(state='normal')
if len(get_available("LiveAnalysisBot"))==0:
live_bouton.config(state='disabled')
else:
live_bouton.config(state='normal')
bouton=Button(app, text=_("Settings"), command=launch_settings)
bouton.pack(fill=X,padx=5, pady=5)
app.protocol("WM_DELETE_WINDOW", close_app)
#app.wm_iconphoto(True, PhotoImage(file='../logo.png'))
try:
ico = Image("photo", file="icon.gif")
app.tk.call('wm', 'iconphoto', str(app), '-default', ico)
except:
log("(Could not load the application icon)")
refresh()
app.refresh=refresh
app.mainloop()
log("terminated")