Skip to content

Commit

Permalink
back and btn event
Browse files Browse the repository at this point in the history
  • Loading branch information
vanguardmaster01 committed Sep 11, 2023
1 parent 5a47d03 commit c64bdf1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
55 changes: 53 additions & 2 deletions item.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ def draw_bigo(self):

def on_back_press(self, instance, touch):
if instance.collide_point(*touch.pos):
print('back_pressed')
self.manager.current = 'List'
self.clear_widgets()
self.__init__()

def on_buy_press(self):
print(f'buy_pressed')

def on_money_button_press(self):
print('money_button_press')


class CountNumber(GridLayout):
Expand Down Expand Up @@ -157,4 +161,51 @@ def decrease_number(self, instance, touch):
self.update_number()

def update_number(self):
self.number_text.text = str(self.number)
self.number_text.text = str(self.number)


class RoundedBorderGrid(GridLayout):
def __init__(self, **kwargs):
super(RoundedBorderGrid, self).__init__(**kwargs)

self.bind(pos=self.update_canvas, size=self.update_canvas)

def update_canvas(self, *args):
self.canvas.before.clear()
with self.canvas.before:
Color(1, 0, 0, 1) # Set the color of the border

# Parameters for top left rounded corner
top_left_center = (self.x, self.top)
top_left_radius = 20

# Parameters for top right rounded corner
top_right_center = (self.right, self.top)
top_right_radius = 20

# Parameters for straight bottom corners
bottom_left = (self.x, self.y)
bottom_right = (self.right, self.y)

self.draw_rounded_border(top_left_center, top_left_radius, top_right_center, top_right_radius, bottom_left,
bottom_right, width=2)

def draw_rounded_border(self, top_left_center, top_left_radius, top_right_center, top_right_radius, bottom_left,
bottom_right, width=2):
diameter_top_left = top_left_radius * 2
diameter_top_right = top_right_radius * 2

# Draw the top-left rounded corner
with self.canvas.before:
Bezier(points=[bottom_left, bottom_left, top_left_center[0] - top_left_radius,
top_left_center[1] + top_left_radius, bottom_left], segment_length=20, width=width)

# Draw the top-right rounded corner
with self.canvas.before:
Bezier(points=[bottom_right, bottom_right, top_right_center[0] + top_right_radius,
top_right_center[1] + top_right_radius, bottom_right], segment_length=20, width=width)

# Draw the straight bottom sides
with self.canvas.before:
Color(1, 1, 1, 1) # Set the color for straight borders
Bezier(points=[bottom_left, bottom_right], width=width)
5 changes: 4 additions & 1 deletion kv/list.kv
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ WindowManager:
font_size: 30
background_normal: './img/bg-btn-1.png'
background_color: (1,1,1,0.5)
background_down: './img/price.png'
size_hint_x: None
size:(200, self.height)
on_press:root.on_money_button_press()
BoxLayout:
size_hint_x: 0.4
padding: [10, 0, 0, 0]
Expand Down Expand Up @@ -279,4 +281,5 @@ WindowManager:
size_hint_x: None
text_size: self.width, None

<CountNumber>:
<CountNumber>:
<RoundedBorderGrid>:
8 changes: 5 additions & 3 deletions list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.core.image import Image as CoreImage
from kivy.clock import Clock
from kivy.graphics import Color, Rectangle
from kivy.graphics import Color, Rectangle, Bezier
# from kivy.graphics.texture import Texture
from kivy.properties import StringProperty
from PIL import Image as PILImage
Expand Down Expand Up @@ -139,7 +139,7 @@ def on_draw_category_item(self):

return boxlayout


# product image
class ImageItem(Image):
def __init__(self, **kwargs):
super(ImageItem, self).__init__(**kwargs)
Expand All @@ -152,7 +152,9 @@ def on_touch_down(self, touch):
self.manager.current = 'Item'
self.manager.get_screen("Item").set_item_id(self.name)

# top bar image
class CategoryItem(Image):
def __init__(self, **kwargs):
super(CategoryItem, self).__init__(**kwargs)


0 comments on commit c64bdf1

Please sign in to comment.