tri state checkboxes are probably a terrible idea

This commit is contained in:
Sander Land committed 2020-11-20 18:21:09 +01:00
1 parent 195ade962d
commit 507a3d333f
3 files changed
+36 -4

No files matched your search

+7 -2
View File
@@ -682,6 +682,7 @@
color: LIGHTGREY
<AnalysisToggle>:
adaptive_width: True
spacing: CP_SPACING
@@ -697,15 +698,18 @@
color: checkbox.disabled_color if root.disabled else (checkbox.selected_color if checkbox.active else checkbox.unselected_color)
size_hint_x: None
width: self.texture_size[0] + 4
on_left_press: checkbox.active = not checkbox.active
MDCheckbox:
on_left_press: checkbox.trigger_action()
TriStateMDCheckbox:
id: checkbox
disabled: root.disabled
tri_state: root.tri_state
size_hint: None,0.5
pos_hint: {'center_y': 0.5}
width: self.height
active: root.default_active
on_active: if app.gui: app.gui.update_state()
on_slashed: if app.gui: app.gui.update_state()
<AnalysisMenuItem@MenuItem>:
on_close: app.gui.analysis_controls.close_dropdown()
@@ -794,6 +798,7 @@
AnalysisToggle:
id: eval
text: i18n._("analysis:dots")
tri_state: True
AnalysisToggle:
id: hints
text: i18n._("analysis:topmoves")
+5 -1
View File
@@ -272,6 +272,7 @@ class BadukPanWidget(Widget):
current_node = katrain.game.current_node
game_ended = katrain.game.end_result
full_eval_on = katrain.analysis_controls.eval.active
all_dots_off = katrain.analysis_controls.eval.checkbox.slashed
has_stone = {}
drawn_stone = {}
for m in katrain.game.stones:
@@ -295,7 +296,10 @@ class BadukPanWidget(Widget):
placements = node.placements
for m in node.moves + placements:
if has_stone.get(m.coords) and not drawn_stone.get(m.coords): # skip captures, last only for
move_eval_on = show_dots_for.get(m.player) and (i < show_n_eval or full_eval_on)
move_eval_on = (
not all_dots_off and show_dots_for.get(m.player) and (i < show_n_eval or full_eval_on)
)
print(move_eval_on, all_dots_off, show_dots_for.get(m.player), i < show_n_eval, full_eval_on)
if move_eval_on and points_lost is not None:
evalcol = self.eval_color(points_lost, show_dots_for_class)
else:
+24 -1
View File
@@ -23,6 +23,7 @@ from kivymd.uix.behaviors import CircularRippleBehavior, RectangularRippleBehavi
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import BaseFlatButton, BasePressedButton
from kivymd.uix.navigationdrawer import MDNavigationDrawer
from kivymd.uix.selectioncontrol import MDCheckbox
from kivymd.uix.textfield import MDTextField
from katrain.core.constants import AI_STRATEGIES_RECOMMENDED_ORDER, GAME_TYPES, MODE_PLAY, PLAYER_AI
@@ -372,14 +373,36 @@ class Timer(BGBoxLayout):
timeout = BooleanProperty(False)
class TriStateMDCheckbox(MDCheckbox):
tri_state = BooleanProperty(False)
slashed = BooleanProperty(False)
def _do_press(self):
if not self.tri_state:
return super()._do_press()
if self.slashed:
self.state = "normal"
self.slashed = False
self.icon = "checkbox-blank-outline"
elif self.state == "down":
self.state = "normal"
self.slashed = True
self.icon = "checkbox-blank-off-outline"
else:
self.state = "down"
self.slashed = False
self.icon = "checkbox-marked-outline"
class AnalysisToggle(MDBoxLayout):
text = StringProperty("")
default_active = BooleanProperty(False)
font_name = StringProperty(DEFAULT_FONT)
disabled = BooleanProperty(False)
tri_state = BooleanProperty(False)
def trigger_action(self, *args, **kwargs):
return self.checkbox.trigger_action(*args, **kwargs)
return self.checkbox._do_press()
def activate(self, *_args):
self.checkbox.active = True