-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_ui.py
153 lines (129 loc) · 5.17 KB
/
start_ui.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Start UI.
Start Crcordile with an UI.
"""
import sys
from dialog import Dialog
import crocrodile
from crocrodile.client import main as client_main
class StartUI(object):
"""Crocrodile Start UI."""
def __init__(self):
self.dialog: Dialog = Dialog()
self.dialog.set_background_title("Crocrodile Start Program")
def main_menu(self) -> int:
"""
Show main menu.
:return: Choice (1 client, 2 basics train)
:rtype: int
"""
code, tag = self.dialog.menu("Wich element do you want to start ?",
title="Main menu",
choices=[("1", "Client"),
("2", "Basics Training"),
("3", "Training file generator")])
if code == self.dialog.OK:
return int(tag)
def input_client_options(self) -> list:
"""
Input client options.
:return: List of selected arguments.
:rtype: list
"""
code, tags = self.dialog.checklist("Select options of client:",
choices=[("-d", "Use developpement account", False),
("-n", "Use neural network", False),
("-u", "Upgrade account to BOT", False),
("-v", "Show debug logs", False),
("-q", "Don't show any logs", False),
("-c", "Challenge user", False),
("-a", "Auto re-challenging", False)],
title="Configure client")
if code == self.dialog.OK:
return tags
def ask_challenge(self) -> list:
"""
Ask challenge configuration.
:return: List of options.
:rtype: list
"""
code, return_list = self.dialog.form("Select challenge configuration:",
[("User", 1, 1, "", 1, 1, 0, 0)])
def ask_challenge_user(self) -> str:
"""
Ask user to challenge.
:return: Username of user to challenge.
:rtype: str
"""
code, string = self.dialog.inputbox("User to challenge:", title="Configure client")
if code == self.dialog.OK:
return string
def ask_time_control(self) -> str:
"""
Ask time control for challenge.
:return: Time control (like 5+3).
:rtype: str
"""
code, string = self.dialog.inputbox("Time control for challenge:", title="Configure client")
if code == self.dialog.OK:
return string
def start(self) -> None:
"""
Start UI.
:return: Nothing.
:rtype: None
"""
choice: int = self.main_menu()
if choice == 1: # Start client
self.start_client()
elif choice == 2: # Start basics training
self.start_basics()
elif choice == 3:
self.start_generator()
def start_client(self) -> None:
"""
Start client.
:return: Nothing.
:rtype: None
"""
options: list = self.input_client_options()
if "-c" in options:
form_result: list = self.ask_challenge()
user: str = self.ask_challenge_user()
time_control: list = self.ask_time_control().split("+")
if len(time_control) != 2:
self.challenge_invalid()
try:
time: int = int(time_control[0])
increment: int = time_control[1]
except ValueError:
self.challenge_invalid()
return
args = f"{user} {time} {increment}"
options.append(args)
return client_main(options)
def challenge_invalid(self) -> str:
"""
Show invalid challenge configuration.
:return: Dialog exit code.
:rtype: str
"""
return self.dialog.msgbox("ERROR: Invalid challenge", title="Configure client")
def start_generator(self) -> None:
code, positions = self.dialog.inputbox("Maximum positions tested:", title="Configure generator")
if code == self.dialog.OK:
code, piece = self.dialog.inputbox("Piece added:",
title="Configure generator")
if code == self.dialog.OK:
code, dtm = self.dialog.inputbox("Maximum DTM:",
title="Configure generator")
if code == self.dialog.OK:
code, destination = self.dialog.inputbox("Destination file:",
title="Configure generator")
if code == self.dialog.OK:
return os.system("python3 training_files/training_from_tb.py {positions} {dtm} {piece} {destination}")
if __name__ == "__main__":
ui = StartUI()
sys.exit(ui.start())