status hiding

This commit is contained in:
Sander Land committed 2020-06-28 01:06:12 +02:00
1 parent 0e17a7ccf1
commit eb9aab5db8
7 files changed
+51 -30

No files matched your search

+11 -7
View File
@@ -59,6 +59,8 @@ from katrain.core.constants import (
MODE_ANALYZE,
HOMEPAGE,
VERSION,
STATUS_ERROR,
STATUS_INFO,
)
from katrain.gui.popups import ConfigTeacherPopup, ConfigTimerPopup, I18NPopup
from katrain.core.base_katrain import KaTrainBase
@@ -100,16 +102,18 @@ class KaTrainGui(Screen, KaTrainBase):
super().log(message, level)
if level == OUTPUT_KATAGO_STDERR and "ERROR" not in self.controls.status.text:
if "starting" in message.lower():
self.controls.set_status(f"KataGo engine starting...")
self.controls.set_status(f"KataGo engine starting...", STATUS_INFO)
if message.startswith("Tuning"):
self.controls.set_status(f"KataGo is tuning settings for first startup, please wait." + message)
self.controls.set_status(
f"KataGo is tuning settings for first startup, please wait." + message, STATUS_INFO
)
return
if "ready" in message.lower():
self.controls.set_status(f"KataGo engine ready.")
self.controls.set_status(f"KataGo engine ready.", STATUS_INFO)
if (level == OUTPUT_ERROR or (level == OUTPUT_KATAGO_STDERR and "error" in message.lower())) and getattr(
self, "controls", None
):
self.controls.set_status(f"ERROR: {message}")
self.controls.set_status(f"ERROR: {message}", STATUS_ERROR)
@property
def play_analyze_mode(self):
@@ -276,7 +280,7 @@ class KaTrainGui(Screen, KaTrainBase):
try:
self.game.play(Move(coords, player=self.next_player_info.player))
except IllegalMoveException as e:
self.controls.set_status(f"Illegal Move: {str(e)}")
self.controls.set_status(f"Illegal Move: {str(e)}",STATUS_ERROR)
def _do_analyze_extra(self, mode, **kwargs):
self.game.analyze_extra(mode, **kwargs)
@@ -367,7 +371,7 @@ class KaTrainGui(Screen, KaTrainBase):
def load_sgf_from_clipboard(self):
clipboard = Clipboard.paste()
if not clipboard:
self.controls.set_status(f"Ctrl-V pressed but clipboard is empty.")
self.controls.set_status(f"Ctrl-V pressed but clipboard is empty.",STATUS_ERROR)
return
try:
move_tree = KaTrainSGF.parse(clipboard)
@@ -459,7 +463,7 @@ class KaTrainGui(Screen, KaTrainBase):
self("output-sgf")
elif keycode[1] == "c" and "ctrl" in modifiers:
Clipboard.copy(self.game.root.sgf())
self.controls.set_status(i18n._("Copied SGF to clipboard."))
self.controls.set_status(i18n._("Copied SGF to clipboard."),STATUS_INFO)
elif keycode[1] == "v" and "ctrl" in modifiers:
self.load_sgf_from_clipboard()
elif keycode[1] in shortcuts.keys() and "ctrl" not in modifiers:
+5
View File
@@ -8,6 +8,11 @@ OUTPUT_INFO = 0
OUTPUT_DEBUG = 1
OUTPUT_EXTRA_DEBUG = 2
STATUS_ANALYSIS = 1.0 # same priority for analysis/info
STATUS_INFO = 1.1
STATUS_TEACHING = 2.0
STATUS_ERROR = 1000.0
PLAYER_HUMAN, PLAYER_AI = "player:human", "player:ai"
PLAYER_TYPES = [PLAYER_HUMAN, PLAYER_AI]
+11 -7
View File
@@ -5,7 +5,9 @@ import threading
from datetime import datetime
from typing import Dict, List, Optional, Union
from katrain.core.constants import HOMEPAGE, OUTPUT_DEBUG, OUTPUT_INFO
from kivy.clock import Clock
from katrain.core.constants import HOMEPAGE, OUTPUT_DEBUG, OUTPUT_INFO, STATUS_ANALYSIS, STATUS_INFO, STATUS_TEACHING
from katrain.core.engine import KataGoEngine
from katrain.core.game_node import GameNode
from katrain.core.lang import i18n
@@ -322,13 +324,15 @@ class Game:
cn = self.current_node
engine = self.engines[cn.next_player]
Clock.schedule_once(self.katrain.analysis_controls.hints.activate,0)
if mode == "extra":
if kwargs.get("continuous", False):
visits = max(engine.config["fast_visits"], math.ceil(cn.analysis_visits_requested * 1.25))
else:
visits = cn.analysis_visits_requested + engine.config["fast_visits"]
self.katrain.controls.set_status(i18n._("extra analysis").format(visits=visits))
self.katrain.controls.set_status(i18n._("extra analysis").format(visits=visits), STATUS_ANALYSIS)
cn.analyze(engine, visits=visits, priority=-1_000, time_limit=False)
return
if mode == "game":
@@ -337,7 +341,7 @@ class Game:
visits = min_visits + engine.config["max_visits"]
for node in nodes:
node.analyze(engine, visits=visits, priority=-1_000_000, time_limit=False)
self.katrain.controls.set_status(i18n._("game re-analysis").format(visits=visits))
self.katrain.controls.set_status(i18n._("game re-analysis").format(visits=visits), STATUS_ANALYSIS)
return
elif mode == "sweep":
@@ -365,16 +369,16 @@ class Game:
if (x, y) not in stones
]
visits = engine.config["fast_visits"]
self.katrain.controls.set_status(i18n._("sweep analysis").format(visits=visits))
self.katrain.controls.set_status(i18n._("sweep analysis").format(visits=visits), STATUS_ANALYSIS)
priority = -1_000_000_000
elif mode == "equalize":
if not cn.analysis_ready:
self.katrain.controls.set_status(i18n._("wait-before-equalize"), self.current_node)
self.katrain.controls.set_status(i18n._("wait-before-equalize"), STATUS_INFO, self.current_node)
return
analyze_moves = [Move.from_gtp(gtp, player=cn.next_player) for gtp, _ in cn.analysis["moves"].items()]
visits = max(d["visits"] for d in cn.analysis["moves"].values())
self.katrain.controls.set_status(i18n._("equalizing analysis").format(visits=visits))
self.katrain.controls.set_status(i18n._("equalizing analysis").format(visits=visits), STATUS_ANALYSIS)
priority = -1_000
else:
raise ValueError("Invalid analysis mode")
@@ -406,6 +410,6 @@ class Game:
if undo:
self.undo(1)
self.katrain.controls.set_status(
i18n._("teaching undo message").format(move=move.gtp(), points_lost=points_lost)
i18n._("teaching undo message").format(move=move.gtp(), points_lost=points_lost), STATUS_TEACHING
)
self.katrain.update_state()
+3 -1
View File
@@ -6,6 +6,8 @@
#:import PLAYER_AI katrain.core.constants.PLAYER_AI
#:import MODE_PLAY katrain.core.constants.MODE_PLAY
#:import MODE_ANALYZE katrain.core.constants.MODE_ANALYZE
#:import STATUS_INFO katrain.core.constants.STATUS_INFO
#:import WHITE katrain.gui.style.WHITE
#:import BLACK katrain.gui.style.BLACK
@@ -253,7 +255,7 @@
Line:
circle: self.pos[0] + self.width/2, self.pos[1] + self.height/2, self.width/6
width: 1
on_press: app.gui.controls.set_status(i18n._('ai-ponder'))
on_press: app.gui.controls.set_status(i18n._('ai-ponder'),STATUS_INFO)
<HamburgerButton@TransparentIconButton>:
+16 -13
View File
@@ -6,7 +6,7 @@ from kivy.properties import ObjectProperty, OptionProperty
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.floatlayout import MDFloatLayout
from katrain.core.constants import MODE_PLAY, MODE_ANALYZE
from katrain.core.constants import MODE_PLAY, MODE_ANALYZE, STATUS_ERROR, STATUS_ANALYSIS
from katrain.gui.kivyutils import AnalysisToggle, CollapsablePanel
@@ -66,8 +66,7 @@ class ControlsPanel(BoxLayout):
def __init__(self, **kwargs):
super(ControlsPanel, self).__init__(**kwargs)
self.status_msg = None
self.status_node = None
self.status_state = (None, -1e9, None)
self.active_comment_node = None
self.last_timer_update = (None, 0, False)
self.beep = SoundLoader.load("beep.wav")
@@ -81,24 +80,28 @@ class ControlsPanel(BoxLayout):
self.players[bw].player_type = player_info.player_type
self.players[bw].player_subtype = player_info.player_subtype
def set_status(self, msg, at_node=None):
self.status_msg = msg
self.status_node = at_node or self.katrain and self.katrain.game and self.katrain.game.current_node
self.status.text = msg
self.update_evaluation()
def set_status(self, msg, status_type, at_node=None):
at_node = at_node or self.katrain and self.katrain.game and self.katrain.game.current_node
if at_node != self.status_state[2] or int(status_type) >= int(self.status_state[1]):
self.status_state = (msg, status_type, at_node)
self.status.text = msg
Clock.schedule_once(self.update_evaluation,0)
# handles showing completed analysis and score graph
def update_evaluation(self):
def update_evaluation(self,*_args):
katrain = self.katrain
game = katrain and katrain.game
if not game:
return
current_node, move = game.current_node, game.current_node.move
if game.current_node is not self.status_node and not (
self.status is not None and self.status_node is None and game.current_node.is_root
): # startup errors on root
if (
game.current_node is not self.status_state[2]
and not (self.status_state[1] == STATUS_ERROR and self.status_state[2] is None)
) or (
len(game.engines["B"].queries)==0 and self.status_state[1] == STATUS_ANALYSIS
): # clear status if node changes, except startup errors on root. also clear analysis message when no queries
self.status.text = ""
self.status_node = None
self.status_state = (None, -1e9, None)
last_player_was_ai_playing_human = katrain.last_player_info.ai and katrain.next_player_info.human
both_players_are_robots = katrain.last_player_info.ai and katrain.next_player_info.ai
+3
View File
@@ -317,6 +317,9 @@ class AnalysisToggle(MDBoxLayout):
def trigger_action(self, *args, **kwargs):
return self.checkbox.trigger_action(*args, **kwargs)
def activate(self,*_args):
self.checkbox.active = True
@property
def active(self):
return self.checkbox.active
+2 -2
View File
@@ -22,7 +22,7 @@ from katrain.core.constants import (
OUTPUT_DEBUG,
OUTPUT_ERROR,
OUTPUT_INFO,
AI_OPTION_VALUES,
AI_OPTION_VALUES, STATUS_INFO,
)
from katrain.core.engine import KataGoEngine
from katrain.core.lang import i18n
@@ -432,7 +432,7 @@ class ConfigPopup(QuickConfigGui):
def restart_engine(_dt):
self.katrain.log(f"Restarting Engine after {detected_restart} settings change")
self.katrain.controls.set_status(i18n._("restarting engine"))
self.katrain.controls.set_status(i18n._("restarting engine"),STATUS_INFO)
old_engine = self.katrain.engine # type: KataGoEngine
old_proc = old_engine.katago_process