pause etc

This commit is contained in:
Sander Land committed 2020-05-27 19:07:49 +02:00
1 parent 01f0663ac1
commit 4ad46a201b
10 files changed
+271 -63

No files matched your search

-1
View File
@@ -36,7 +36,6 @@ class BackgroundMixin(Widget):
background_radius = NumericProperty(0)
outline_color = ListProperty([0, 0, 0, 0])
outline_width = NumericProperty(1)
background_radius = NumericProperty(0)
class LeftButtonBehavior(ButtonBehavior): # stops buttons etc activating on right click
+169
View File
@@ -0,0 +1,169 @@
import kivy
from kivy.app import App
from kivy.core.text import Label as CoreLabel
from kivy.lang import Builder
from kivy.properties import (
BooleanProperty,
ListProperty,
NumericProperty,
ObjectProperty,
OptionProperty,
StringProperty,
)
from kivy.uix.behaviors import ButtonBehavior, ToggleButtonBehavior
from kivy.uix.button import Button
from kivy.uix.checkbox import CheckBox
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.uix.spinner import Spinner
from kivy.uix.widget import Widget
from kivymd.app import MDApp
from kivymd.uix.behaviors import CircularRippleBehavior, RectangularRippleBehavior
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import BaseFlatButton, BasePressedButton
from kivymd.uix.navigationdrawer import MDNavigationDrawer
WHITE = [1, 1, 1, 1]
class TestBox(GridLayout):
pass
class BackgroundMixin(Widget):
background_color = ListProperty([0, 0, 0, 0])
background_radius = NumericProperty(0)
outline_color = ListProperty([0, 0, 0, 0])
outline_width = NumericProperty(1)
class LeftButtonBehavior(ButtonBehavior): # stops buttons etc activating on right click
def __init__(self, **kwargs):
self.register_event_type("on_left_release")
self.register_event_type("on_left_press")
super().__init__(**kwargs)
def on_touch_down(self, touch):
return super().on_touch_down(touch)
def on_release(self):
if not self.last_touch or self.last_touch.button == "left":
self.dispatch("on_left_release")
return super().on_release()
def on_press(self):
if not self.last_touch or self.last_touch.button == "left":
self.dispatch("on_left_press")
return super().on_press()
def on_left_release(self):
pass
def on_left_press(self):
pass
class PauseButton(LeftButtonBehavior,Widget):
active = BooleanProperty(True)
active_line_color = WHITE
inactive_line_color = WHITE
active_fill_color = ListProperty([0.5, 0.5, 0.5, 1])
inactive_fill_color = ListProperty([1, 1, 1, 0])
line_width = NumericProperty(5)
fill_color = ListProperty([0.5, 0.5, 0.5, 1])
line_color = ListProperty([0.5, 0.5, 0.5, 1])
min_size = NumericProperty(100)
def on_left_press(self):
self.active = not self.active
KV = """
#:set LIGHTGREY [0.7,0.7,0.7,1]
#:set WHITE [1,1,1,1]
#:set BACKGROUND_COLOR [16/255,18/255,32/255,1]
#:set BOX_BACKGROUND_COLOR [46/255,65/255,88/255,1]
<BackgroundMixin>:
canvas.before:
Color:
rgba: root.background_color
RoundedRectangle:
size: self.size
pos: self.pos
radius: [root.background_radius, ]
Color:
rgba: root.outline_color
Line:
rounded_rectangle: (*self.pos,self.width,self.height,root.background_radius)
width: root.outline_width
<PauseButton>:
min_size: min(self.height,self.width)
line_color: root.active_line_color if self.active else root.inactive_line_color
fill_color: root.active_fill_color if self.active else root.inactive_fill_color
canvas:
Color:
rgba: root.fill_color
Ellipse:
pos: root.x + root.width/2 - root.min_size/2, root.y + root.height/2 - root.min_size/2
size: root.min_size,root.min_size
Color:
rgba: root.line_color
Line:
circle: root.x + root.width/2, root.y + root.height/2, root.min_size/2 - root.line_width/2
width: root.line_width
Line:
points: root.x + root.width/2 - root.min_size/8, root.y + root.height/2 - root.min_size/6, root.x + root.width/2 - root.min_size/8, root.y + root.height/2 + root.min_size/6
width: root.line_width
Line:
points: root.x + root.width/2 + root.min_size/8, root.y + root.height/2 - root.min_size/6, root.x + root.width/2 + root.min_size/8, root.y + root.height/2 + root.min_size/6
width: root.line_width
<BGBoxLayout@BoxLayout+BackgroundMixin>
background_color: BACKGROUND_COLOR
padding: 100
<TestBox>:
canvas.before:
Color:
rgba: [0,1,0,1]
Line:
rectangle: (*self.pos,*self.size)
width: 1
cols: 2
rows: 2
BGBoxLayout:
PauseButton:
size_hint: None, None
width: 100
height: 200
active: False
BGBoxLayout:
PauseButton:
size_hint: None, None
width: 200
height: 100
BGBoxLayout:
PauseButton:
size_hint: 0.5,0.5
"""
Builder.load_string(KV)
class MyApp(MDApp):
def __init__(self):
super().__init__()
def build(self):
layout = TestBox()
return layout
MyApp().run()
+3 -3
View File
@@ -24,7 +24,7 @@ from kivy.uix.screenmanager import Screen
from kivymd.app import MDApp
from katrain.core.ai import ai_move
from katrain.core.utils import LANGUAGE, OUTPUT_DEBUG, OUTPUT_ERROR, OUTPUT_EXTRA_DEBUG, OUTPUT_INFO, OUTPUT_KATAGO_STDERR, find_package_resource, i18n, MODE_PLAY
from katrain.core.utils import DEFAULT_LANGUAGE, OUTPUT_DEBUG, OUTPUT_ERROR, OUTPUT_EXTRA_DEBUG, OUTPUT_INFO, OUTPUT_KATAGO_STDERR, find_package_resource, i18n, MODE_PLAY, switch_lang, i18n_font
from katrain.core.engine import KataGoEngine
from katrain.core.game import Game, IllegalMoveException, KaTrainSGF
from katrain.core.sgf_parser import Move, ParseError
@@ -356,7 +356,7 @@ class KaTrainGui(Screen):
class KaTrainApp(MDApp):
gui = ObjectProperty(None)
language = StringProperty(LANGUAGE)
language = StringProperty(DEFAULT_LANGUAGE)
def build(self):
self.icon = ICON # how you're supposed to set an icon
@@ -370,7 +370,7 @@ class KaTrainApp(MDApp):
def on_language(self, _instance, language):
self.gui.log(f"Switching language to {language}", OUTPUT_INFO)
i18n.switch_lang(language)
switch_lang(language)
def on_start(self):
self.gui.start()
+30 -18
View File
@@ -1,8 +1,12 @@
import os
import sys
from typing import Any, List, Tuple
from kivy.event import EventDispatcher
from kivy.lang import Observable
import gettext
from kivy.properties import StringProperty
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
@@ -50,19 +54,32 @@ def find_package_resource(path):
return path # absolute path
class LangFont(EventDispatcher):
font_name = StringProperty('')
DEFAULT_FONT = "fonts/NotoSans-Regular.ttf"
FONTS = {'ko': "fonts/NotoSansKR-Regular.otf"}
font_name = StringProperty('')
def __init__(self,lang,**kwargs):
super().__init__(**kwargs)
self.switch_lang(lang)
def switch_lang(self,lang):
self.lang = lang
self.font_name = self.FONTS.get(lang) or self.DEFAULT_FONT
class Lang(Observable):
observers = []
lang = None
def __init__(self, defaultlang):
def __init__(self, lang):
super(Lang, self).__init__()
self.ugettext = None
self.lang = defaultlang
self.switch_lang(self.lang)
self.font = None
self.switch_lang(lang)
def _(self, text):
str = self.ugettext(text)
return str
return self.ugettext(text)
def fbind(self, name, func, *args, **kwargs):
if name == "_":
@@ -81,6 +98,7 @@ class Lang(Observable):
def switch_lang(self, lang):
# get the right locales directory, and instantiate a gettext
self.lang = lang
i18n_dir, _ = os.path.split(find_package_resource("katrain/i18n/__init__.py"))
locale_dir = os.path.join(i18n_dir, "locales")
locales = gettext.translation("katrain", locale_dir, languages=[lang])
@@ -93,18 +111,12 @@ class Lang(Observable):
except ReferenceError:
pass # proxy no longer exists
@property
def font(self):
return self._("LANG_FONT")
LANGUAGE = "en"
i18n = Lang(LANGUAGE)
DEFAULT_LANGUAGE = "en"
i18n = Lang(DEFAULT_LANGUAGE)
i18n_font = LangFont(DEFAULT_LANGUAGE)
class I18NLabel(Label):
pass
class I18NTextInput(TextInput):
pass
def switch_lang(lang):
i18n.switch_lang(lang)
i18n_font.switch_lang(lang)
+48 -25
View File
@@ -1,5 +1,6 @@
#:kivy 1.11.0
#:import i18n __main__.i18n
#:import i18n_font __main__.i18n_font
#:import find_package_resource __main__.find_package_resource
#:set BUTTON_COLOR [0.23, 0.30, 0.35, 1]
@@ -32,13 +33,8 @@
#:set NOTES_FONT_SIZE dp(18)
#<DefaultLabel@Label>:
# font_name: 'Roboto'
#<Label>:
# font_name: i18n._('LANG_FONT')
<I18NLabel>:
font_name: i18n._('LANG_FONT')
<Label>:
font_name: i18n_font.font_name
canvas.before:
Color:
rgba: RED
@@ -46,8 +42,8 @@
rectangle: (*self.pos,*self.size)
width: 1
<I18NTextInput>:
font_name: i18n._('LANG_FONT')
<TextInput>:
font_name: i18n_font.font_name
# mixins
<BackgroundMixin>:
@@ -91,7 +87,7 @@
background_color: BOX_BACKGROUND_COLOR
label: label
text_size: root.size
I18NLabel:
Label:
id: label
padding: [root.padding_x,root.padding_y]
color: root.text_color
@@ -378,22 +374,49 @@
size_hint: 0.75, 1
orientation: 'vertical'
spacing: CP_SPACING
I18NLabel:
Label:
text: root.player_type
size_hint: 1,0.55
font_size: 0.8 * self.height
I18NLabel:
Label:
text: root.player_subtype
size_hint: 1,0.45
font_size: 0.7 * self.height
<PauseButton@MDFloatingActionButton+ToggleButtonBehavior>:
icon: 'img/flaticon/pause.png'
<PauseButton>:
height: self.width
size_hint: 1, None
min_size: min(self.height,self.width)
inactive_line_color: WHITE
inactive_fill_color: [1,1,1,0]
active_line_color: RED
active_fill_color: LIGHTGREY
line_width: max(1.1,self.min_size/20)
line_color: root.active_line_color if self.active else root.inactive_line_color
fill_color: root.active_fill_color if self.active else root.inactive_fill_color
canvas:
Color:
rgba: root.fill_color
Ellipse:
pos: root.x + root.width/2 - root.min_size/2, root.y + root.height/2 - root.min_size/2
size: root.min_size,root.min_size
Color:
rgba: root.line_color
Line:
circle: root.x + root.width/2, root.y + root.height/2, root.min_size/2 - root.line_width/2
width: root.line_width
Line:
points: root.x + root.width/2 - root.min_size/8, root.y + root.height/2 - root.min_size/6, root.x + root.width/2 - root.min_size/8, root.y + root.height/2 + root.min_size/6
width: root.line_width
Line:
points: root.x + root.width/2 + root.min_size/8, root.y + root.height/2 - root.min_size/6, root.x + root.width/2 + root.min_size/8, root.y + root.height/2 + root.min_size/6
width: root.line_width
<TimerLabel@I18NLabel>
<TimerLabel@Label>
color: GREEN
markup: True
multiline: False
@@ -442,7 +465,7 @@
#:set GRAPH_CENTER_COLOR GREY
<GraphMarkerLabel@I18NLabel>:
<GraphMarkerLabel@Label>:
valign: 'bottom'
halign: 'left'
text: '+0'
@@ -525,7 +548,7 @@
<StatsLabel>:
value : value
orientation: 'horizontal'
I18NLabel:
Label:
size_hint: 0.6,1
id: desc
text: root.label if not root.hidden else ''
@@ -533,7 +556,7 @@
text_size: self.size
valign: 'middle'
halign: 'center'
I18NLabel:
Label:
size_hint: 0.4,1
text: root.text if not root.hidden else ''
color: root.color
@@ -577,7 +600,7 @@
Line:
rectangle: (*self.pos,*self.size)
width: 1
I18NLabel:
Label:
id: label
markup: root.markup
padding: 5, 5
@@ -701,7 +724,7 @@
on_ref_press: root.katrain.board_gui.show_pv_from_comments(args[1])
size_hint: 1, 1
height: self.parent.height - status.height - note.height - 1
I18NTextInput:
TextInput:
id: note
font_size: NOTES_FONT_SIZE
size_hint: 1, 1
@@ -717,7 +740,7 @@
size_hint: None, 0.7
pos_hint: {'center_y':0.5}
checkbox: checkbox
I18NLabel:
Label:
id: label
text: root.text
halign: 'center'
@@ -742,7 +765,7 @@
<AnalysisDropdownMenuRightContent>:
width: 0
I18NLabel:
Label:
id: label
size: dp(30)
font_size: root.font_size
@@ -810,7 +833,7 @@
mipmap: True
size_hint: 0.7,0.7
pos_hint: {'center_y': 0.5,'center_x': 0.5}
I18NLabel:
Label:
text: root.text
text_size: self.size
size_hint_x: 1
@@ -818,7 +841,7 @@
valign: 'middle'
font_size: root.font_size
color: WHITE
I18NLabel:
Label:
text: root.shortcut
halign: 'left'
valign: 'middle'
@@ -831,7 +854,7 @@
size_hint: 1,1
icon_size: self.height * 0.9, self.height * 0.9
<MenuLabel@I18NLabel+BackgroundMixin>:
<MenuLabel@Label+BackgroundMixin>:
background_color: BACKGROUND_COLOR
font_size: self.height * 0.5
height: self.parent.item_height or 50
+21 -7
View File
@@ -14,6 +14,7 @@ from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.uix.spinner import Spinner
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
@@ -24,7 +25,7 @@ from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import BasePressedButton, BaseFlatButton
from kivymd.uix.navigationdrawer import MDNavigationDrawer
from kivy.core.text import Label as CoreLabel
from katrain.core.utils import i18n, I18NTextInput, I18NLabel
from katrain.core.utils import i18n
#
@@ -37,7 +38,6 @@ class BackgroundMixin(Widget):
background_radius = NumericProperty(0)
outline_color = ListProperty([0, 0, 0, 0])
outline_width = NumericProperty(1)
background_radius = NumericProperty(0)
class LeftButtonBehavior(ButtonBehavior): # stops buttons etc activating on right click
@@ -113,9 +113,23 @@ class TransparentIconButton(CircularRippleBehavior, Button):
icon_size = ListProperty([25, 25])
icon = StringProperty("")
class PauseButton(CircularRippleBehavior,LeftButtonBehavior,Widget):
active = BooleanProperty(True)
active_line_color = ListProperty([0.5, 0.5, 0.8, 1])
inactive_line_color = ListProperty([1, 1, 1, 1])
active_fill_color = ListProperty([0.5, 0.5, 0.5, 1])
inactive_fill_color = ListProperty([1, 1, 1, 0])
line_width = NumericProperty(5)
fill_color = ListProperty([0.5, 0.5, 0.5, 1])
line_color = ListProperty([0.5, 0.5, 0.5, 1])
min_size = NumericProperty(100)
def on_left_press(self):
self.active = not self.active
# -- basic styles
class LightLabel(I18NLabel):
class LightLabel(Label):
pass
@@ -247,7 +261,7 @@ class CollapsablePanel(MDBoxLayout):
self.header.add_widget(Label()) # spacer
self.trigger_select()
else:
self.header.add_widget(I18NLabel(text=i18n._(self.closed_label), halign="right", height=self.options_height))
self.header.add_widget(Label(text=i18n._(self.closed_label), halign="right", height=self.options_height))
self.header.add_widget(self.open_close_button)
super().clear_widgets()
@@ -297,7 +311,7 @@ class StatsBox(MDBoxLayout, BackgroundMixin):
# --- not checked
class ToolTipLabel(I18NLabel):
class ToolTipLabel(Label):
pass
@@ -340,7 +354,7 @@ class ScaledLightLabel(LightLabel, ToolTipBehavior):
num_lines = NumericProperty(1)
class ClickableLabel(LeftButtonBehavior, I18NLabel):
class ClickableLabel(LeftButtonBehavior, Label):
pass
@@ -449,7 +463,7 @@ class ToggleButtonContainer(GridLayout):
return self.options[0]
class LabelledTextInput(I18NTextInput):
class LabelledTextInput(TextInput):
input_property = StringProperty("")
multiline = BooleanProperty(False)
@@ -6,9 +6,6 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. This is the font used, files ONLY relative to 'katrain' directory
msgid "LANG_FONT"
msgstr "fonts/NotoSans-Regular.ttf"
#. main hamburger menu
msgid "menu:playersetup"
@@ -6,9 +6,6 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. This is the font used, files ONLY relative to 'katrain' directory
msgid "LANG_FONT"
msgstr "fonts/NotoSansKR-Regular.otf"
msgid "pass-button-text"
msgstr "패스"
@@ -6,9 +6,6 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. This is the font used, files ONLY relative to 'katrain' directory
msgid "LANG_FONT"
msgstr "fonts/NotoSans-Regular.ttf"
msgid "pass-button-text"
msgstr "Pas"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB