Skip to content

Commit

Permalink
add a widget for the three stars
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Dec 15, 2023
1 parent bd2aef3 commit dd78112
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 11 deletions.
7 changes: 6 additions & 1 deletion screens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
### Imports ###
###############

# Import the custom widgets
from screens.custom_widgets import (
BottomBar,
CustomButton
CustomButton,
ThreeStars
)

# Import the screens
from screens.home import HomeScreen
from screens.profile import ProfileScreen
from screens.customization import CustomizationScreen
from screens.settings import SettingsScreen
from screens.free_mode import FreeModeScreen
1 change: 1 addition & 0 deletions screens/custom_widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

from screens.custom_widgets.bottom_bar import BottomBar
from screens.custom_widgets.custom_buttons import CustomButton
from screens.custom_widgets.three_stars import ThreeStars
12 changes: 4 additions & 8 deletions screens/custom_widgets/bottom_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,22 @@ def open_home(self):
"""
Open the home screen.
"""
if self.selected != "home":
self.parent.manager.current = "home"
self.parent.manager.current = "home"

def open_settings(self):
"""
Open the settings screen.
"""
if self.selected != "settings":
self.parent.manager.current = "settings"
self.parent.manager.current = "settings"

def open_customization(self):
"""
Open the customization screen.
"""
if self.selected != "customization":
self.parent.manager.current = "customization"
self.parent.manager.current = "customization"

def open_profile(self):
"""
Open the profile screen.
"""
if self.selected != "profile":
self.parent.manager.current = "profile"
self.parent.manager.current = "profile"
49 changes: 49 additions & 0 deletions screens/custom_widgets/three_stars.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#:kivy 2.2.1
#:import PATH_IMAGES tools.path.PATH_IMAGES

<ThreeStars>:

# Star one
Image:
id: star_one_contour
pos_hint: {"center_x":0.125,"center_y":0.5}
size_hint: (0.25,1)
source: PATH_IMAGES + "star.png"
fit_mode: "contain"
Image:
id: star_one
pos_hint: {"center_x":0.125,"center_y":0.5}
size_hint: (0.25,1)
source: PATH_IMAGES + "star_full.png"
fit_mode: "contain"
color: root.star_one_color

# Star two
Image:
id: star_two_contour
pos_hint: {"center_x":0.5,"center_y":0.5}
size_hint: (0.25,1)
source: PATH_IMAGES + "star.png"
fit_mode: "contain"
Image:
id: star_two
pos_hint: {"center_x":0.5,"center_y":0.5}
size_hint: (0.25,1)
source: PATH_IMAGES + "star_full.png"
fit_mode: "contain"
color: root.star_two_color

# Star three
Image:
id: star_three_contour
pos_hint: {"center_x":0.875,"center_y":0.5}
size_hint: (0.25,1)
source: PATH_IMAGES + "star.png"
fit_mode: "contain"
Image:
id: star_three_contour
pos_hint: {"center_x":0.875,"center_y":0.5}
size_hint: (0.25,1)
source: PATH_IMAGES + "star_full.png"
fit_mode: "contain"
color: root.star_three_color
63 changes: 63 additions & 0 deletions screens/custom_widgets/three_stars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
Module to create three stars with a certain filling ratio
"""

###############
### Imports ###
###############

### Kivy imports ###
from kivy.uix.widget import Widget
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import (
NumericProperty,
ListProperty
)

#############
### Class ###
#############


class ThreeStars(RelativeLayout):

star_one_color = ListProperty([0.5, 0.5, 0.5, 1.])
star_two_color = ListProperty([0.5, 0.5, 0.5, 1.])
star_three_color = ListProperty([0.5, 0.5, 0.5, 1.])
star_color_dict = {1: star_one_color,
2: star_two_color,
3: star_three_color}
stars_number = NumericProperty()
primary_color = ListProperty([0.5, 0.5, 0.5, 1.])
secondary_color = ListProperty([1., 1., 1., 1.])

def __init__(
self,
primary_color=[1., 1., 1., 1.],
secondary_color=[0.5, 0.5, 0.5, 1.],
**kwargs):

self.primary_color = primary_color
self.secondary_color = secondary_color

self.bind(stars_number=self.change_stars_number)
super().__init__(**kwargs)

def change_stars_number(self, base_widget, value):
"""
Change the number of stars displayed.
"""

# self.stars_number = stars_number
if self.stars_number > 0:
self.star_one_color = self.primary_color
else:
self.star_one_color = self.secondary_color
if self.stars_number > 1:
self.star_two_color = self.primary_color
else:
self.star_two_color = self.secondary_color
if self.stars_number > 2:
self.star_three_color = self.primary_color
else:
self.star_three_color = self.secondary_color
4 changes: 4 additions & 0 deletions screens/free_mode.kv
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
pos_hint: {"bottom":0,"left":0}
selected: "home"

ThreeStars:
size_hint: (0.7,0.15)
pos_hint:{"center_x":0.5,"center_y":0.5}
stars_number: 2
1 change: 0 additions & 1 deletion screens/free_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)
from tools.kivy_tools import (
ImprovedScreen,
ImageButton
)


Expand Down
1 change: 1 addition & 0 deletions screens/home.kv
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
size_hint: (0.5,0.1)
pos_hint: {"center_x":0.5, "center_y":0.6}
text:"Free Mode"
release_function: root.open_free_mode

CustomButton:
size_hint: (0.5,0.1)
Expand Down
6 changes: 6 additions & 0 deletions screens/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ def __init__(self, **kwargs) -> None:
back_image_path=PATH_BACKGROUNDS +
THEMES_DICT[current_background_theme]["image"],
**kwargs)

def open_free_mode(self):
"""
Open the free mode screen.
"""
self.manager.current = "free_mode"
6 changes: 5 additions & 1 deletion screens/opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def load_kv_files(self, *_):
HomeScreen,
SettingsScreen,
ProfileScreen,
CustomizationScreen
CustomizationScreen,
FreeModeScreen
)

screen_files = [file for file in os.listdir(
Expand All @@ -76,6 +77,7 @@ def load_kv_files(self, *_):
self.SettingsScreen = SettingsScreen
self.ProfileScreen = ProfileScreen
self.CustomizationScreen = CustomizationScreen
self.FreeModeScreen = FreeModeScreen

Clock.schedule_once(self.load_other_screens)

Expand All @@ -93,4 +95,6 @@ def load_other_screens(self, *args):
self.manager.add_widget(profile_screen)
customization_screen = self.CustomizationScreen(name="customization")
self.manager.add_widget(customization_screen)
free_mode_screen = self.FreeModeScreen(name="free_mode")
self.manager.add_widget(free_mode_screen)
Clock.schedule_once(self.switch_to_menu)

0 comments on commit dd78112

Please sign in to comment.