From f6b8c73fb2f0d1f958ccb1c280d618385526946e Mon Sep 17 00:00:00 2001 From: Sander Land Date: Wed, 10 Jun 2020 23:22:21 +0200 Subject: [PATCH] graph click and background --- i18n.py | 10 +-- katrain/gui.kv | 7 +- katrain/gui/popups.py | 64 ++++++++++++------ katrain/gui/widgets/graph.py | 14 ++-- .../i18n/locales/de/LC_MESSAGES/katrain.mo | Bin 12055 -> 12053 bytes .../i18n/locales/de/LC_MESSAGES/katrain.po | 9 ++- .../i18n/locales/es/LC_MESSAGES/katrain.mo | Bin 12339 -> 12338 bytes .../i18n/locales/es/LC_MESSAGES/katrain.po | 9 ++- .../i18n/locales/fr/LC_MESSAGES/katrain.mo | Bin 12398 -> 12390 bytes .../i18n/locales/fr/LC_MESSAGES/katrain.po | 9 ++- .../i18n/locales/ko/LC_MESSAGES/katrain.mo | Bin 12686 -> 12677 bytes .../i18n/locales/ko/LC_MESSAGES/katrain.po | 9 ++- katrain/img/graph_bg.png | Bin 835 -> 694 bytes katrain/popups.kv | 15 +--- 14 files changed, 78 insertions(+), 68 deletions(-) diff --git a/i18n.py b/i18n.py index 14520e7..a76def2 100644 --- a/i18n.py +++ b/i18n.py @@ -19,14 +19,14 @@ errors = False po = {} pofile = {} -num_todo = defaultdict(int) +todos = defaultdict(list) for lang in locales: pofile[lang] = os.path.join(localedir, lang, "LC_MESSAGES", "katrain.po") po[lang] = polib.pofile(pofile[lang]) for entry in po[lang].translated_entries(): if "TODO" in entry.comment: - num_todo[lang] += 1 + todos[lang].append(entry) else: strings_to_langs[entry.msgid][lang] = entry.msgstr strings_to_keys[entry.msgid][lang] = set(re.findall("{.*?}", entry.msgstr)) @@ -34,8 +34,10 @@ for lang in locales: print("duplicate", entry.msgid, "in", lang) errors = True lang_to_strings[lang].add(entry.msgid) - if num_todo[lang]: - print(f"{lang} has {num_todo[lang]} TODO entries") + if todos[lang]: + print(f"========== {lang} has {len(todos[lang])} TODO entries ========== ") + for item in todos[lang]: + print(item) for lang in locales: diff --git a/katrain/gui.kv b/katrain/gui.kv index 04c4527..e06bfe7 100644 --- a/katrain/gui.kv +++ b/katrain/gui.kv @@ -140,12 +140,13 @@ points: self.x,self.y,self.x+self.width,self.y width: 1 -: - font_size: self.height * 0.5 - sync_height_frac: 1.0 +: + -font_size: self.height * 0.5 background_color: [*[c*255/88 for c in BACKGROUND_COLOR[:3]], 1] # compensate for texture option_cls: 'I18NSpinnerOption' + + sync_height_frac: 1.0 : min_size: min(self.height,self.width) diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index 9621c66..991ca10 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -46,6 +46,10 @@ class LabelledTextInput(MDTextField): def input_value(self): return self.text + @property + def raw_input_value(self): + return self.text + class LabelledPathInput(LabelledTextInput): def __init__(self, **kwargs): @@ -77,6 +81,9 @@ class LabelledCheckBox(MDCheckbox): def input_value(self): return bool(self.active) + def raw_input_value(self): + return self.active + class LabelledSpinner(I18NSpinner): input_property = StringProperty("") @@ -85,6 +92,9 @@ class LabelledSpinner(I18NSpinner): def input_value(self): return self.selected[1] # ref value + def raw_input_value(self): + return self.text + class LabelledFloatInput(LabelledTextInput): signed = BooleanProperty(True) @@ -105,7 +115,7 @@ class LabelledFloatInput(LabelledTextInput): @property def input_value(self): - return float(self.text) + return float('0'+self.text) class LabelledIntInput(LabelledTextInput): @@ -116,7 +126,7 @@ class LabelledIntInput(LabelledTextInput): @property def input_value(self): - return int(self.text) + return int('0'+self.text) class InputParseError(Exception): @@ -128,7 +138,7 @@ class QuickConfigGui(MDBoxLayout): super().__init__() self.katrain = katrain self.popup = None - Clock.schedule_once(lambda _dt: self.set_properties(self)) + Clock.schedule_once(self.build_and_set_properties,0) def collect_properties(self, widget) -> Dict: if isinstance(widget, (LabelledTextInput, LabelledSpinner, LabelledCheckBox)) and getattr( @@ -137,7 +147,7 @@ class QuickConfigGui(MDBoxLayout): try: ret = {widget.input_property: widget.input_value} except Exception as e: # TODO : on widget? - raise InputParseError(f"Could not parse value for {widget.input_property} ({widget.__class__}): {e}") + raise InputParseError(f"Could not parse value '{widget.raw_input_value}' for {widget.input_property} ({widget.__class__.__name__}): {e}") else: ret = {} for c in widget.children: @@ -167,7 +177,10 @@ class QuickConfigGui(MDBoxLayout): ) return config[keys[-1]], config, keys[-1] - def set_properties(self, widget): + def build_and_set_properties(self,*_args): + return self._set_properties_subtree(self) + + def _set_properties_subtree(self, widget): if isinstance(widget, (LabelledTextInput, LabelledSpinner, LabelledCheckBox)) and getattr( widget, "input_property", None ): @@ -184,7 +197,7 @@ class QuickConfigGui(MDBoxLayout): else: widget.text = str(value) for c in widget.children: - self.set_properties(c) + self._set_properties_subtree(c) def update_config(self, save_to_file=True): updated = set() @@ -237,15 +250,11 @@ def wrap_anchor(widget): class ConfigTeacherPopup(QuickConfigGui): - def __init__(self, katrain): - super().__init__(katrain) - self.build() - def add_option_widgets(self, widgets): for widget in widgets: self.options_grid.add_widget(wrap_anchor(widget)) - def build(self): + def build_and_set_properties(self,*_args): undos = self.katrain.config("trainer/num_undo_prompts") thresholds = self.katrain.config("trainer/eval_thresholds") savesgfs = self.katrain.config("trainer/save_feedback") @@ -263,7 +272,7 @@ class ConfigTeacherPopup(QuickConfigGui): LabelledCheckBox(text=str(savesgf), input_property=f"trainer/save_feedback::{i}"), ] ) - self.set_properties(self) + super().build_and_set_properties() class DescriptionLabel(Label): @@ -297,24 +306,35 @@ class AIPopup(QuickConfigGui): class ConfigPopup(QuickConfigGui): - def __init__(self, katrain): - super().__init__(katrain) - def check_models(self): - model = self.collect_properties()['katago/model'] + def build_and_set_properties(self,*_args): + super().build_and_set_properties() + self.check_models() + + def check_models(self,*args): # WIP + try: + model = self.collect_properties(self)['engine/model'] + except InputParseError: + self.model_files.values = [] + return + if os.path.exists(model): if os.path.isdir(model): - path = model - file = None + path = model.rstrip('\\/') + file = None else: + if model.startswith('katrain'): + model = find_package_resource(model) path, file = os.path.split(model) - glob.glob(path+'*.bin.gz') - for file in f: - - self.model_files.values = [] + files = sorted([os.path.split(f)[1] for ftype in ['*.bin.gz','*.txt.gz'] for f in glob.glob(path+os.path.sep+ftype)]) + self.model_files.values =files + print(file,files,file in files) + if file in files: + self.model_files.text = file else: self.model_files.values = [] + def update_config(self, save_to_file=True): updated = super().update_config(save_to_file=save_to_file) self.katrain.debug_level = self.katrain.config("general/debug_level", OUTPUT_INFO) diff --git a/katrain/gui/widgets/graph.py b/katrain/gui/widgets/graph.py index 39a5185..52083a9 100644 --- a/katrain/gui/widgets/graph.py +++ b/katrain/gui/widgets/graph.py @@ -178,44 +178,44 @@ Builder.load_string( rgba: GRAPH_DOT_COLOR Ellipse: id: score_dot - pos: [c - self.highlight_size / 2 for c in (self.score_dot_pos if not self.navigate_move else [self.navigate_move[1],self.navigate_move[2]] ) ] + pos: [c - self.highlight_size / 2 for c in (self.score_dot_pos if not self.navigate_move[0] else [self.navigate_move[1],self.navigate_move[2]] ) ] size: (self.highlight_size,self.highlight_size) if root.show_score else (0.0001,0.0001) Color: rgba: GRAPH_DOT_COLOR Ellipse: id: winrate_dot - pos: [c - self.highlight_size / 2 for c in (self.winrate_dot_pos if not self.navigate_move else [self.navigate_move[1],self.navigate_move[3]] ) ] + pos: [c - self.highlight_size / 2 for c in (self.winrate_dot_pos if not self.navigate_move[0] else [self.navigate_move[1],self.navigate_move[3]] ) ] size: (self.highlight_size,self.highlight_size) if root.show_winrate else (0.0001,0.0001) # score ticks GraphMarkerLabel: font_size: root.marker_font_size color: SCORE_COLOR - pos: root.right_edge - root.width-1, root.y+root.height - self.font_size - 1 + pos: root.right_edge - self.width-1, root.pos[1]+root.height - self.font_size - 1 text: 'B+{}'.format(root.score_scale) opacity: int(root.show_score) GraphMarkerLabel: font_size: root.marker_font_size color: SCORE_COLOR - pos: root.right_edge - root.width-1, root.mid - root.height/2 + 2 + pos: root.right_edge - self.width-1, root.mid - self.height/2 + 2 text: i18n._('Jigo') opacity: int(root.show_score) GraphMarkerLabel: font_size: root.marker_font_size color: SCORE_COLOR - pos: root.right_edge - root.width-1, root.y + pos: root.right_edge - self.width-1, root.pos[1] text: 'W+' + str(int(root.score_scale)) opacity: int(root.show_score) # wr ticks GraphMarkerLabel: font_size: root.marker_font_size color: WINRATE_COLOR - pos: root.x+1, root.y+root.height - self.font_size - 1 + pos: root.pos[0]+1, root.pos[1]+root.height - self.font_size - 1 text: "{}%".format(50 + root.winrate_scale) opacity: int(root.show_winrate) GraphMarkerLabel: font_size: root.marker_font_size color: WINRATE_COLOR - pos:root.x+1, root.y + pos:root.pos[0]+1, root.pos[1] text: "{}%".format(50 - root.winrate_scale) opacity: int(root.show_winrate) """ diff --git a/katrain/i18n/locales/de/LC_MESSAGES/katrain.mo b/katrain/i18n/locales/de/LC_MESSAGES/katrain.mo index daf2a2f62f5f9bf78e92a1c3eba8bca1d406f645..8abd43a8815c128a3294596d433db1d04727710c 100644 GIT binary patch delta 699 zcmXZZPbh519;6mJQR;ZnfdeQ5j0H8OB$y{5lWe0IvsjNg zwBi+3;~iS?5oLl`lzpEl0~osgC-k5+4592FMyWS}QB0xi+t&z;1jks8XZrdaWwJ|b z#v=CPi~il!{a>IJL*ygKqo#OSa2>IK9cufrD^xl%yQA zxrp3QYDvmL4$6TXq?DZG`?R;--p}*A>3ybj=U1$l36rdaJSdChz0o~Y-IzTLBh>#dxYQs*{{9)93Q%YmENfqSSoa%=j8I>-mw(fB6FBlt7bYWmMCs8<+9 zJxBz#@Blh-6t&Oo-Gg(xZ67%`J_+05j&kn;Wk7L%Pz7M3K* zYePv`%|c;8l){b``3HO--g!jJK@uJ!+6QEWmHnP8q5EDutrdvK;l!Dp6ZF zh#F)VHE0;MQ&DSv0d=Dl^x``1;4x|^hxkM370jTvd=B-h6UgI~J>Ht=348I=>~Ji4 i%oBf4nyWh=o0^?onvYJ-UYjxRKy)$M8#nF2fbAEyDO0Ba delta 705 zcmXZaPbh6TjJED|>;v!s-Qcm7qo_cy--{0?Pzu)Kg{p~nqrH&5VX1$1Pghirwf-!u=2K0A` z^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F$5DPs5_>U?1Gt6KxP-&_gL2@ZPQx*jgG`|twKNNPsyWjIlz)~(8FYwtJTc=_ zl!h0kMU+Oj7{nJ`L1&lo0vjk7*+y zP}Xf>EAF8Wuh5Rq*n=e;!j5jeE{+4l+bH|qpc6mPfhwf5{|RSEPk7P8d=SGpg7uif zLCm2vJ~ezmGx4`!8AVmZRxC#kO1=dfuoIgwihi69YjOysR+y;89h4IuqZFQFBVMBo zpRf{Nu^K;(yp8L(5&O}BF_ir#(2nz1gGrpiRh0TWje(QFBTC^rO5-1th84X^xzUC4 z6@HZbEXtS6V-&L(!y}Z9OE`w6KK;OxhBGJ!Nuc!AvJB*@a)xUtf3}X&=nO4*X~efE zFK};IK-uU8oAC=bv94c#fnAh~oS@_{P}UcamvyT*267WKU6;|Dk5nG|EaUM^d^FXb VF9v+&)^sA1SxPRZ^R95#^auEzQKJ9= diff --git a/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po b/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po index bcf7d03..8add7bb 100644 --- a/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po +++ b/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po @@ -349,8 +349,11 @@ msgstr "존재하지 않는 경로입니다." msgid "general settings" msgstr "일반 설정" +msgid "katago settings" +msgstr "KataGo 설정" + msgid "engine settings" -msgstr "KataGo 엔진 설정" +msgstr "엔진 설정" msgid "config file path" msgstr "설정 파일 경로:" @@ -579,7 +582,3 @@ msgstr "Equalizing analysis of candidate moves to {visits} visits" #. TODO msgid "extra analysis" msgstr "Performing additional analysis to {visits} visits" - -#. TODO -msgid "katago settings" -msgstr "KataGo settings" diff --git a/katrain/img/graph_bg.png b/katrain/img/graph_bg.png index a1e2a8395d8f639c5f3ff052fd79a9340f6643da..d2012889670164969bdc61edc3d7d14ea0dc52fc 100644 GIT binary patch literal 694 zcmeAS@N?(olHy`uVBq!ia0y~yV5|eOk8`jANx2M*uRw~iILO_JVcj{Imp~3nx}&cn z1H;CC?mvmFKt5-IM`SSr1K(i~W;~w1B87p0$=lP#F{C2y?e)7^ha3dhF083|7@c05 zy^z)VC12}>u%5H=U*|~M+fAFx>2ib*Xb9z?Y{~oI$;T%0{tiAiQS{j@bsK~7{NFmZ z*XGzqh|1H0@{7TgNnY&M@KA!N^@%{_x+Qs?*vg=Rq99SLkQ2*GKd-2-} z7T?dBfB)IL-1$qN-%`J`qdsf@7rWxS|EK(>+=W0B4)9HhdTsjI44`SRwq zANM?aSCIEdX^v6fofrL*?rCqf&&rw*m$UVJ%y;{zc2x1shMntv YGuY_;73iq^dmdKI;Vst0OHioumAu6 literal 835 zcmeAS@N?(olHy`uVBq!ia0y~yV5|eOPjIjS$@g|$3P6gpz$3Dlfr0M`2s2LA=96Y% zVEXFm;uumf=j}B^uEPcbu8!;T7yOnlyUc#+R*O0Ft9=evoj32UW}HyC|1Sf>Jk>u8 zhKKkClt(G*1;O_-G54R(`TV(QFA)5#fB*LfV^UiA_qXm0A7t$78YCXFcL: configfile: configfile - model_files: model_files DescriptionLabel: text: i18n._('katago settings') font_size: DESC_FONT_SIZE * 1.5 @@ -99,17 +98,9 @@ DescriptionLabel: text: i18n._("engine:model") size_hint: 0.33, 1 - BoxLayout: - AnchorLayout: - size_hint: 0.66, 1 - LabelledPathInput: - input_property: "engine/model" - on_text: root.check_models(*args) - AnchorLayout: - size_hint: 0.33, 1 - Spinner: - id: model_files - on_text: root.set_model(*args) + AnchorLayout: + LabelledPathInput: + input_property: "engine/model" DescriptionLabel: text: i18n._("engine:config") size_hint: 0.33, 1