* distributed option * i18n, pause, etc * fixes galore * max buffer etc * test override config * maxgame * visit * contribute menu * restore vars * i18n * actually start * retry distr and errors * pw eye / move speed * cfg/no log * shutdown fix * shutdown fix * download fix * wut * stats and desc * esc fix * Omit terminate queries from KataGoEngine.queries. (#353) * press key h to clear current node analysis. (#352) * clear current node all analysis * add reset key binding * reset all analysis off. * code refactor * code change according to review. * remove useless variable * code review changes * clean up reset node * oops * Setup position feature (#354) * go for zebras * setup working! * uhh * tweak * img * fix i18n * AEEEEEEEEEE and stop * link in readme * new game options for edit/new/setup (#357) * new game options for edit/new/setup * feedback * fix * ai thoughts * no tristate cb * branch fixing (#358) * new game options for edit/new/setup * feedback * fix * ai thoughts * no tristate cb * fix comma etc * normal katago * kata * dll * save window pos/size * BAD comma * new linux binary + allow default engine * fix * unused icon, build mac * exe * player new game fix * fix i18n * test test * just print * 한국어 * 활성화 * Add new Traditional Chinese translation (#362) Improve some translations as well. * cn (#363) * cn * rm old * rm old * informal you * mo * jp (#364) * config and readme * mo * kgtraining * fix score * lower stddev a bit * tweak weights * 1.8 French Po (#365) * fr and getattr fix * -DBUILD_DISTRIBUTED=1 * openssl * openssl * openssl * openssl * config * jp (num undos) (#366) * clarify undo in en, po->mo * fix player name * new kata * new kata * Load game option save config (#367) * in the load dialog, "load fast analysis" and "rewind to the start" option ,save to config file * in the load dialog, "load fast analysis" and "rewind to the start" option ,save to config file * default option * remove useless override * save check state when file dialog's submit event , * save config in callback * readme * active games * de * log games as json always * black * Russian localization for 1.8.0 (#375) * ru Co-authored-by: pdeblanc <peter@spaceandgames.com> Co-authored-by: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Co-authored-by: Liou, Guan-Cheng <Tony-Liou@users.noreply.github.com> Co-authored-by: kaorahi <38910552+kaorahi@users.noreply.github.com> Co-authored-by: Dontbtme <66470440+Dontbtme@users.noreply.github.com> Co-authored-by: Alexander Kiselev <satoshi.yoda.register.264@gmail.com>
136 lines
4.2 KiB
Python
136 lines
4.2 KiB
Python
from kivy.lang import Builder
|
|
from kivy.properties import BooleanProperty, ListProperty, NumericProperty
|
|
from kivy.uix.widget import Widget
|
|
|
|
|
|
class SelectionSlider(Widget):
|
|
__events__ = ["on_select", "on_change"]
|
|
active = BooleanProperty(False)
|
|
hint = BooleanProperty(True)
|
|
|
|
index = NumericProperty(0) # selected index
|
|
values = ListProperty([(0, "")]) # (value:numeric,label:string) pairs
|
|
normalized_pos = NumericProperty(0) # slider relative pos from 0-1
|
|
px_pos = NumericProperty(0) # actual px pos
|
|
padding = NumericProperty("16sp")
|
|
|
|
track_color = ListProperty([1, 1, 1, 0.3])
|
|
thumb_color = ListProperty([0.5, 0.5, 0.5, 1])
|
|
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
self.bind(
|
|
size=self.set_index_and_positions,
|
|
pos=self.set_index_and_positions,
|
|
values=self.set_index_and_positions,
|
|
index=self.set_index_and_positions,
|
|
)
|
|
|
|
def set_index_and_positions(self, *_args):
|
|
self.index = max(0, min(self.index, len(self.values) - 1))
|
|
self.normalized_pos = self.index / (len(self.values) - 1)
|
|
self.px_pos = self.x + self.padding + self.normalized_pos * (self.width - 2 * self.padding)
|
|
|
|
@property
|
|
def value(self):
|
|
return self.values[self.index][0]
|
|
|
|
def set_value(self, set_value): # set to closest value
|
|
if isinstance(set_value, (float, int)):
|
|
eq_value = sorted([(abs(v - set_value), i) for i, (v, l) in enumerate(self.values)])
|
|
self.index = eq_value[0][1]
|
|
|
|
def set_from_pos(self, pos):
|
|
norm_value = (pos[0] - self.x - self.padding) / (self.width - 2 * self.padding)
|
|
self.index = round(norm_value * (len(self.values) - 1))
|
|
self.dispatch("on_change", self.value)
|
|
|
|
def on_touch_down(self, touch):
|
|
if self.disabled or not self.collide_point(*touch.pos):
|
|
return
|
|
if touch.is_mouse_scrolling:
|
|
if "down" in touch.button or "left" in touch.button:
|
|
self.index += 1
|
|
if "up" in touch.button or "right" in touch.button:
|
|
self.index -= 1
|
|
else:
|
|
touch.grab(self)
|
|
self.active = True
|
|
self.set_from_pos(touch.pos)
|
|
return True
|
|
|
|
def on_touch_move(self, touch):
|
|
if touch.grab_current == self:
|
|
self.set_from_pos(touch.pos)
|
|
return True
|
|
|
|
def on_touch_up(self, touch):
|
|
if touch.grab_current == self:
|
|
self.set_from_pos(touch.pos)
|
|
self.active = False
|
|
self.dispatch("on_select", self.value)
|
|
return True
|
|
|
|
def on_select(self, value):
|
|
pass
|
|
|
|
def on_change(self, value):
|
|
pass
|
|
|
|
|
|
KV = """
|
|
#:import i18n katrain.core.lang.i18n
|
|
<SelectionSlider>:
|
|
id: slider
|
|
canvas:
|
|
Clear
|
|
Color:
|
|
rgba:
|
|
self.track_color
|
|
Rectangle:
|
|
size:
|
|
(self.width - self.padding*2, dp(4))
|
|
pos:
|
|
(self.x + self.padding, self.center_y - dp(4))
|
|
Color:
|
|
rgba:
|
|
self.thumb_color
|
|
Rectangle:
|
|
size:
|
|
((self.width-self.padding*2)*self.normalized_pos, sp(4))
|
|
pos:
|
|
(self.x + self.padding, self.center_y - dp(4))
|
|
|
|
Thumb:
|
|
id: thumb
|
|
size_hint: None, None
|
|
size:
|
|
((dp(24), dp(24)) if root.active else (dp(16), dp(16)))
|
|
pos:
|
|
(slider.px_pos - dp(8), slider.center_y - thumb.height/2 - dp(2))
|
|
color:
|
|
root.thumb_color
|
|
elevation:
|
|
4 if root.active else 2
|
|
|
|
MDCard:
|
|
id: hint_box
|
|
size_hint: None, None
|
|
md_bg_color: [1, 1, 1, 1] if root.active else [0, 0, 0, 0]
|
|
elevation: 4 if root.active else 0
|
|
size:
|
|
(max(dp(28), label.texture_size[0]+4) , dp(28))
|
|
pos:
|
|
(slider.px_pos - dp(9), slider.center_y - hint_box.height / 2 + dp(30))
|
|
|
|
Label:
|
|
id: label
|
|
text: slider.values[slider.index][1]
|
|
font_size: sp(12)
|
|
lang_change_tracking: i18n._('') # for font
|
|
halign: "center"
|
|
color: root.thumb_color if root.active else [0, 0, 0, 0]
|
|
"""
|
|
|
|
Builder.load_string(KV)
|