Skip to content

Commit

Permalink
fix: add formats setup page with color picker for digits
Browse files Browse the repository at this point in the history
fix: extend functionality of saving dispatcher
  • Loading branch information
bartei81 committed May 27, 2024
1 parent c9be67c commit 7c4f28e
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 25 deletions.
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions rotary_controller_python/components/coordbar.kv
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
font_name: "fonts/iosevka-regular.ttf"
font_size: self.height / 1.5
font_style: "bold"
color: app.display_color
color: app.formats.display_color
text: app.formats.position_format.format(root.position / app.formats.factor) if root.mode == 0 else app.formats.speed_format.format(root.speed / app.formats.factor)
text_size: self.size
halign: 'right'
Expand All @@ -35,7 +35,7 @@
font_name: "fonts/iosevka-regular.ttf"
font_size: self.height / 1.5
font_style: "bold"
color: app.display_color
color: app.formats.display_color
text: app.formats.speed_format.format(root.speed / app.formats.factor)
text_size: self.size
halign: 'right'
Expand All @@ -49,7 +49,7 @@
text: "Num"
font_size: self.height / 1.5
size_hint_y: 0.3
color: app.display_color
color: app.formats.display_color
halign: 'center'
valign: 'top'
Button:
Expand All @@ -58,7 +58,7 @@
font_size: self.height / 2
font_style: "bold"
background_color: [0.3, 0.3, 0.3, 1]
color: app.display_color
color: app.formats.display_color
text: str(int(root.syncRatioNum))
text_size: self.size
halign: 'center'
Expand All @@ -74,7 +74,7 @@
text: "Den"
font_size: self.height / 1.5
size_hint_y: 0.3
color: app.display_color
color: app.formats.display_color
halign: 'center'
valign: 'top'
Button:
Expand All @@ -83,7 +83,7 @@
font_size: self.height / 2
font_style: "bold"
background_color: [0.3, 0.3, 0.3, 1]
color: app.display_color
color: app.formats.display_color
text: str(int(root.syncRatioDen))
text_size: self.size
halign: 'center'
Expand Down
42 changes: 42 additions & 0 deletions rotary_controller_python/components/setup/formats_panel.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#: import StringItem components.forms.string_item

<FormatsPanel>:
orientation: "vertical"
ScrollView:
do_scroll_x: False
do_scroll_y: True
GridLayout:
id: grid_layout
cols: 1
spacing: 1
size_hint_y: None
StringItem:
name: "Metric Position"
value: root.formats.metric_position
on_value: root.formats.metric_position = self.value
StringItem:
name: "Metric Speed"
value: root.formats.metric_speed
on_value: root.formats.metric_speed = self.value
StringItem:
name: "Imperial Position"
value: root.formats.imperial_position
on_value: root.formats.imperial_position = self.value
StringItem:
name: "Imperial Speed"
value: root.formats.imperial_speed
on_value: root.formats.imperial_speed = self.value
StringItem:
name: "Angle Format"
value: root.formats.angle_format
on_value: root.formats.angle_format = self.value
Label:
size_hint_y: None
height: 32
text: "Digits Color"
ColorPicker:
padding: 10
size_hint_y: None
height: 320
color: root.formats.display_color
on_color: root.formats.display_color = self.color
22 changes: 22 additions & 0 deletions rotary_controller_python/components/setup/formats_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from kivy.lang import Builder
from kivy.logger import Logger
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout


log = Logger.getChild(__name__)
kv_file = os.path.join(os.path.dirname(__file__), __file__.replace(".py", ".kv"))
if os.path.exists(kv_file):
log.info(f"Loading KV file: {kv_file}")
Builder.load_file(kv_file)


class FormatsPanel(BoxLayout):
formats = ObjectProperty()

def __init__(self, formats, **kv):
self.formats = formats
super().__init__(**kv)
self.ids['grid_layout'].bind(minimum_height=self.ids['grid_layout'].setter('height'))
7 changes: 3 additions & 4 deletions rotary_controller_python/components/setup/setup_popup.kv
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
Button:
text: "Network"
on_release: root.screen_manager.current = "network"

# Button:
# text: "Logs"
# on_release: root.screen_manager.current = "logs"
Button:
text: "Formats"
on_release: root.screen_manager.current = "formats"
Button:
text: "Exit"
on_release: root.dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition, NoTransition

from rotary_controller_python.components.setup.network_panel import NetworkPanel
from rotary_controller_python.components.setup.logs_panel import LogsPanel
# from rotary_controller_python.components.setup.logs_panel import LogsPanel
from rotary_controller_python.components.setup.scale_panel import ScalePanel
from rotary_controller_python.components.setup.servo_panel import ServoPanel
from rotary_controller_python.components.setup.formats_panel import FormatsPanel

log = Logger.getChild(__name__)
kv_file = os.path.join(os.path.dirname(__file__), __file__.replace(".py", ".kv"))
Expand Down Expand Up @@ -37,8 +38,13 @@ def __init__(self, **kv):
screen.add_widget(ServoPanel(servo=app.home.servo))
self.add_widget(screen)

screen = Screen(name="network")
screen.add_widget(NetworkPanel())
# TODO: Disable network for now, need to finish working on this
# screen = Screen(name="network")
# screen.add_widget(NetworkPanel())
# self.add_widget(screen)

screen = Screen(name="formats")
screen.add_widget(FormatsPanel(formats=app.formats))
self.add_widget(screen)

# Add Tab to allow reviewing the application logs
Expand Down
8 changes: 7 additions & 1 deletion rotary_controller_python/dispatchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import yaml
from kivy.logger import Logger
from kivy.event import EventDispatcher
from kivy.properties import StringProperty, NumericProperty, BooleanProperty
from kivy.properties import StringProperty, NumericProperty, BooleanProperty, ListProperty, ObservableList

log = Logger.getChild(__name__)


class SavingDispatcher(EventDispatcher):
_skip_save = []
_force_save = []
id_override = StringProperty("")

def __init__(self, *args, **kwargs):
Expand All @@ -34,6 +35,9 @@ def get_our_properties(self):
if type(item) in [NumericProperty, StringProperty, BooleanProperty]
]
properties = [item for item in properties if item.name not in self._skip_save]

force_properties = [getattr(type(self), item) for item in self._force_save]
properties.extend(force_properties)
return properties

@property
Expand Down Expand Up @@ -74,6 +78,8 @@ def save_settings(self, *args, **kv):
data = dict()
for item in prop_names:
data[item] = self.__getattribute__(item)
if type(data[item]) == ObservableList:
data[item] = list(data[item])

write_settings(self.filename, data)

Expand Down
5 changes: 4 additions & 1 deletion rotary_controller_python/dispatchers/formats.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from kivy.logger import Logger
from kivy.properties import (
NumericProperty,
StringProperty,
StringProperty, ListProperty,
)

from rotary_controller_python.dispatchers import SavingDispatcher
Expand All @@ -10,6 +10,7 @@


class FormatsDispatcher(SavingDispatcher):
_force_save = ['display_color']
metric_position = StringProperty("{:+0.3f}")
metric_speed = StringProperty("{:+0.3f}")

Expand All @@ -22,6 +23,8 @@ class FormatsDispatcher(SavingDispatcher):
position_format = StringProperty()
factor = NumericProperty(1)

display_color = ListProperty([1, 1, 1, 1])

def __init__(self, **kv):
super().__init__(**kv)
self.update_format()
Expand Down

0 comments on commit 7c4f28e

Please sign in to comment.