collapsable panel
This commit is contained in:
1 parent
448888f073
commit
ee14597314
4 files changed
+74
-30
No files matched your search
+18
-11
@@ -45,8 +45,7 @@
|
||||
pos: self.pos
|
||||
|
||||
|
||||
|
||||
<ToolTipLabel>:
|
||||
<ToolTipLabel>: # TODO
|
||||
size_hint: None, None
|
||||
size: self.texture_size
|
||||
tooltip_font_size: dp(14)
|
||||
@@ -67,19 +66,15 @@
|
||||
# new widgets
|
||||
|
||||
<SizedMDBaseButton>:
|
||||
size: (dp(100),dp(33))
|
||||
text_color: WHITE
|
||||
MDLabel:
|
||||
label: label
|
||||
Label:
|
||||
id: label
|
||||
text: root.text
|
||||
size_hint_x: None
|
||||
height: self.texture_size[1]
|
||||
text_size: (None, root.height)
|
||||
theme_text_color: 'Custom'
|
||||
text_color: root.text_color
|
||||
color: root.text_color
|
||||
font_size: root.font_size
|
||||
font_name: root.font_name or self.font_name
|
||||
valign: 'middle'
|
||||
halign: root.halign
|
||||
|
||||
<SizedMDFlatButton>:
|
||||
@@ -94,9 +89,15 @@
|
||||
text_color: root.color if self.state=='down' else self.inactive_color
|
||||
outline_color: root.color if self.state=='down' else self.inactive_color
|
||||
|
||||
<AutoSizedMDFlatRectangleToggleButton>: # only wants height
|
||||
width: self.label.texture_size[0] + self.hor_padding * 2
|
||||
font_size: self.height * 0.8
|
||||
|
||||
|
||||
<BGMDBoxLayout@MDBoxLayout+BackgroundColor>:
|
||||
background_color: BOX_BACKGROUND_COLOR
|
||||
|
||||
|
||||
# -- old widgets
|
||||
|
||||
|
||||
@@ -645,6 +646,7 @@
|
||||
status: status
|
||||
padding: CP_PADDING
|
||||
spacing: CP_SPACING
|
||||
tab_option_height: 20
|
||||
BoxLayout: # -- Players
|
||||
size_hint_y: PLAYER_BOX_HEIGHT
|
||||
PlayerInfo:
|
||||
@@ -663,9 +665,14 @@
|
||||
Timer:
|
||||
id: timer
|
||||
size_hint_x: 0.7
|
||||
ScoreGraph:
|
||||
CollapsablePanel:
|
||||
size_hint_y: GRAPH_BOX_HEIGHT
|
||||
id: graph
|
||||
options: ['Score','Win Rate','Points Lost']
|
||||
option_colors: [SCORE_COLOR,WINRATE_COLOR,POINTLOSS_COLOR]
|
||||
option_active: [True,False,False]
|
||||
options_height: root.tab_option_height
|
||||
ScoreGraph:
|
||||
id: graph
|
||||
BoxLayout:
|
||||
size_hint_y: STATS_BOX_HEIGHT
|
||||
StatsBox:
|
||||
|
||||
@@ -5,10 +5,10 @@ from kivymd.uix.gridlayout import MDGridLayout
|
||||
from kivymd.uix.label import MDLabel
|
||||
|
||||
from katrain.core.common import OUTPUT_DEBUG, OUTPUT_ERROR
|
||||
from katrain.gui.kivyutils import SizedMDFlatButton, LightHelpLabel, ScaledLightLabel
|
||||
from katrain.gui.kivyutils import SizedMDFlatButton, LightHelpLabel, ScaledLightLabel, StyledSpinner
|
||||
from katrain.gui.popups import QuickConfigGui, ConfigPopup, InputParseError
|
||||
|
||||
KV='''
|
||||
KV = """
|
||||
<ConfigAIPopupContents>:
|
||||
orientation: 'vertical'
|
||||
rules_spinner: rules_spinner
|
||||
@@ -96,14 +96,13 @@ KV='''
|
||||
font_size: 0.3 * self.size[1]
|
||||
on_left_press: if not self.last_touch or self.last_touch.button=="left": root.new_game()
|
||||
|
||||
'''
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class ConfigAIPopupContents(QuickConfigGui):
|
||||
def __init__(self, katrain, popup: Popup):
|
||||
self.settings = {'engine': katrain.config('engine')}
|
||||
super().__init__(katrain, popup, settings = self.settings)
|
||||
self.settings = {"engine": katrain.config("engine")}
|
||||
super().__init__(katrain, popup, settings=self.settings)
|
||||
Clock.schedule_once(self.build, 0)
|
||||
|
||||
def build(self, _):
|
||||
@@ -153,4 +152,3 @@ class ConfigAIPopupContents(QuickConfigGui):
|
||||
self.katrain.log(e, OUTPUT_ERROR)
|
||||
return
|
||||
self.popup.dismiss()
|
||||
|
||||
@@ -10,6 +10,7 @@ from katrain.core.common import PLAYER_HUMAN, PLAYER_AI, PLAYER_HUMAN_TEACHING
|
||||
from katrain.gui.popups import ConfigTeacherPopup, ConfigTimerPopup
|
||||
from katrain.gui.ai_settings import ConfigAIPopupContents
|
||||
|
||||
|
||||
class RightButtonControls(MDBoxLayout):
|
||||
button_size = ListProperty([100, 33])
|
||||
|
||||
|
||||
+50
-12
@@ -6,7 +6,7 @@ from kivy.clock import Clock
|
||||
from kivy.core.text import Label as CoreLabel
|
||||
from kivy.core.window import Window
|
||||
from kivy.graphics import *
|
||||
from kivy.properties import BooleanProperty, ListProperty, NumericProperty, StringProperty, OptionProperty
|
||||
from kivy.properties import BooleanProperty, ListProperty, NumericProperty, StringProperty, OptionProperty, ObjectProperty
|
||||
from kivy.uix.behaviors import ToggleButtonBehavior, ButtonBehavior
|
||||
from kivy.uix.button import Button
|
||||
from kivy.uix.checkbox import CheckBox
|
||||
@@ -43,17 +43,14 @@ class LeftButtonBehavior(ButtonBehavior): # stops buttons etc activating on rig
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
print('touch!',self.collide_point(touch.x, touch.y))
|
||||
return super().on_touch_down(touch)
|
||||
|
||||
def on_release(self):
|
||||
print("RElease!")
|
||||
if not self.last_touch or self.last_touch.button == "left":
|
||||
self.dispatch("on_left_release")
|
||||
return super().on_release()
|
||||
|
||||
def on_press(self):
|
||||
print("press!")
|
||||
if not self.last_touch or self.last_touch.button == "left":
|
||||
self.dispatch("on_left_press")
|
||||
return super().on_press()
|
||||
@@ -69,7 +66,8 @@ class LeftButtonBehavior(ButtonBehavior): # stops buttons etc activating on rig
|
||||
class SizedMDBaseButton(BasePressedButton, BaseFlatButton, LeftButtonBehavior): # avoid baserectangular for sizing
|
||||
text = StringProperty("")
|
||||
halign = OptionProperty("center", options=["left", "center", "right", "justify", "auto"])
|
||||
|
||||
label = ObjectProperty(None)
|
||||
height = NumericProperty(33)
|
||||
|
||||
class SizedMDFlatButton(RectangularRippleBehavior, SizedMDBaseButton):
|
||||
pass
|
||||
@@ -87,6 +85,10 @@ class SizedMDFlatRectangleToggleButton(SizedMDFlatRectangleButton, ToggleButtonB
|
||||
return self.state == "down"
|
||||
|
||||
|
||||
class AutoSizedMDFlatRectangleToggleButton(SizedMDFlatRectangleToggleButton):
|
||||
hor_padding = NumericProperty(3)
|
||||
|
||||
|
||||
# -- basic styles
|
||||
class LightLabel(MDLabel):
|
||||
pass
|
||||
@@ -104,9 +106,7 @@ class CensorableLabel(MDBoxLayout):
|
||||
|
||||
class MyNavigationDrawer(MDNavigationDrawer): # in PR
|
||||
def on_touch_down(self, touch):
|
||||
sup = super().on_touch_down(touch)
|
||||
print('touchhere?',sup)
|
||||
return sup
|
||||
return super().on_touch_down(touch)
|
||||
|
||||
def on_touch_up(self, touch):
|
||||
if self.status == "opened" and self.close_on_click and not self.collide_point(touch.ox, touch.oy):
|
||||
@@ -124,14 +124,14 @@ class CircleWithText(MDFloatLayout):
|
||||
# -- gui elements
|
||||
|
||||
|
||||
class MainMenuItem(RectangularRippleBehavior,LeftButtonBehavior,MDBoxLayout):
|
||||
class MainMenuItem(RectangularRippleBehavior, LeftButtonBehavior, MDBoxLayout):
|
||||
__events__ = ["on_action"]
|
||||
icon = StringProperty("")
|
||||
text = StringProperty("")
|
||||
shortcut = StringProperty("")
|
||||
|
||||
def on_left_release(self):
|
||||
self.anim_complete() # kill ripple
|
||||
self.anim_complete() # kill ripple
|
||||
MDApp.get_running_app().gui.nav_drawer.set_state("close")
|
||||
self.dispatch("on_action")
|
||||
|
||||
@@ -139,6 +139,44 @@ class MainMenuItem(RectangularRippleBehavior,LeftButtonBehavior,MDBoxLayout):
|
||||
pass
|
||||
|
||||
|
||||
class CollapsablePanel(MDBoxLayout):
|
||||
__events__ = ["on_option_select"]
|
||||
options = ListProperty([])
|
||||
options_height = NumericProperty(25)
|
||||
option_active = ListProperty([])
|
||||
option_colors = ListProperty([])
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.contents = None
|
||||
super().__init__(**kwargs)
|
||||
self.orientation = "vertical"
|
||||
self.bind(options=self.build, option_colors=self.build, options_height=self.build, option_active=self.build)
|
||||
|
||||
def build(self, *args, **kwargs):
|
||||
print(args, kwargs, "b")
|
||||
self.clear_widgets()
|
||||
header = MDBoxLayout(adaptive_height=True, padding=[4, 0, 0, 0],spacing=2)
|
||||
option_colors = self.option_colors
|
||||
for opt, opt_col, active in zip(self.options, option_colors, self.option_active):
|
||||
header.add_widget(AutoSizedMDFlatRectangleToggleButton(text=opt, color=opt_col,
|
||||
height=self.options_height,
|
||||
on_press=lambda _:print(self.size,_.size),
|
||||
state="down" if active else "normal"))
|
||||
header.add_widget(SizedMDFlatRectangleButton(text="x",height=self.options_height))
|
||||
super().add_widget(header)
|
||||
if self.contents:
|
||||
super().add_widget(self.contents)
|
||||
|
||||
def add_widget(self, widget, index=0, **_kwargs):
|
||||
if self.contents:
|
||||
raise ValueError("CollapsablePanel can only have one child")
|
||||
self.contents = widget
|
||||
self.build()
|
||||
|
||||
def on_option_select(self, states):
|
||||
pass
|
||||
|
||||
|
||||
# --- not checked
|
||||
|
||||
|
||||
@@ -184,9 +222,9 @@ class ToolTipBehavior(object): # TODO restyle
|
||||
class ScaledLightLabel(LightLabel, ToolTipBehavior):
|
||||
num_lines = NumericProperty(1)
|
||||
|
||||
class ClickableLabel(LightLabel,LeftButtonBehavior):
|
||||
pass
|
||||
|
||||
class ClickableLabel(LightLabel, LeftButtonBehavior):
|
||||
pass
|
||||
|
||||
|
||||
class LightHelpLabel(ScaledLightLabel):
|
||||
|
||||
Reference in new issue
Block a user