Skip to content

Commit

Permalink
imgea scroll view - up and down button
Browse files Browse the repository at this point in the history
  • Loading branch information
vanguardmaster01 committed Sep 11, 2023
1 parent c64bdf1 commit ba0b702
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 24 deletions.
23 changes: 23 additions & 0 deletions DbFuncs/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,26 @@ def get_product(id):
print('connection is closed')

return record

def get_product_count():
try:
conn = sqlite3.connect(utils.dbPath)
cursor = conn.cursor()

print(f'id: {id}')
select_query = '''select count(id) from products '''
cursor.execute(select_query)
record = cursor.fetchone()

conn.commit()
cursor.close()

except sqlite3.Error as error:
print('fail', error)
record = None
finally:
if conn:
conn.close()
print('connection is closed')

return record[0]
4 changes: 2 additions & 2 deletions item.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from kivy.uix.gridlayout import GridLayout
from kivy.core.image import Image as CoreImage
from kivy.clock import Clock
from kivy.graphics import Color, Rectangle, Triangle
from kivy.graphics import Color, Rectangle, Triangle, Bezier
import io
import math

Expand Down Expand Up @@ -58,7 +58,7 @@ def draw_product_info(self, product):
image_stream = io.BytesIO(product[2])
img = CoreImage(image_stream, ext='png')
image.texture = img.texture
self.ids.image_layout.add_widget(image)
self.ids.item_image_layout.add_widget(image)

self.draw_label('Abc1234')
self.draw_label('600')
Expand Down
14 changes: 9 additions & 5 deletions kv/list.kv
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@ WindowManager:
rows: 3
padding:6, 10, 6, 10

BoxLayout:
BoxLayout: # up button layout
id: up_image_layout
canvas.before:
Color:
rgb: 192 ,0 ,0
Rectangle:
pos: self.pos[0], self.pos[1] + self.height / 2
size: self.width, self.height / 2
size_hint_y: 0.15
padding: [root.WIDTH / 6, 0, 0, 0]
Image:
id: up_image
source: './img/up.png'
size: self.texture_size

ScrollView:
ImageScrollView: # product images view
id: image_scroll_view
size: root.width, root.height
pos: 0, 0
Expand All @@ -78,14 +80,15 @@ WindowManager:
size_hint_y: None
spacing: 20
padding: 10, 30, 10, 20
BoxLayout:
BoxLayout: # down button layout
canvas.before:
Color:
rgb: 192 ,0 ,0
Rectangle:
pos: self.pos
size: self.width, self.height / 2
size_hint_y: 0.15
padding: [root.WIDTH / 6, 0, 0, 0]
Image:
id: down_image
source: './img/down.png'
Expand Down Expand Up @@ -127,7 +130,7 @@ WindowManager:
padding: 10
size_hint_x: .6
RelativeLayout:
id: image_layout
id: item_image_layout

GridLayout:
rows: 3
Expand Down Expand Up @@ -282,4 +285,5 @@ WindowManager:
text_size: self.width, None

<CountNumber>:
<RoundedBorderGrid>:
<RoundedBorderGrid>:
<ImageScrollView>:
65 changes: 48 additions & 17 deletions list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivy.core.image import Image as CoreImage
from kivy.clock import Clock
from kivy.graphics import Color, Rectangle, Bezier
Expand All @@ -26,6 +27,7 @@


class ListScreen(Screen):
WIDTH = utils.screenX
def __init__(self, **kwargs):
super(ListScreen, self).__init__(**kwargs)
Clock.schedule_once(self.retrieve_image_layout)
Expand All @@ -36,6 +38,7 @@ def __init__(self, **kwargs):
self.scroll_position = 0
self.scroll_move_dis = utils.itemLength
self.scroll_y_dis = 0
self.scroll_y_offset = 0

# prevent to delay, so we can get image_layou and draw dynamically
def retrieve_image_layout(self, dt):
Expand Down Expand Up @@ -70,14 +73,6 @@ def get_products(self):
products = db.get_products()
return products

# click image, then navigate to itemscreen with item id
# def on_image_click(self, instance, touch):
# for image in self.imageList:
# if image.collide_point(*touch.pos):
# # self.manager.current = 'Item'
# self.manager.get_screen("Item").set_item_id(image.name)


# draw one image
def on_draw_item(self, product):
image = ImageItem()
Expand All @@ -92,25 +87,42 @@ def on_draw_item(self, product):
###################################################################
def retrieve_up_and_down_image(self, dt):
up_image = self.ids.up_image
up_image.size_hint_x = None
up_image.width = utils.screenX * 2 / 3
up_image.bind(on_touch_down = self.on_up_img_click)
down_image = self.ids.down_image
down_image.size_hint_x = None
down_image.width = utils.screenX * 2 / 3
down_image.bind(on_touch_down = self.on_down_img_click)

def on_up_img_click(self, instance, touch):
if instance.collide_point(*touch.pos):
# image_scroll_view.scroll_y = 1
if(self.scroll_position > 0):
self.ids.image_scroll_view.scroll_y += self.scroll_y_dis
self.scroll_position -= self.scroll_move_dis
# image_scroll_view = self.ids.image_scroll_view
# image_scroll_view.scroll_to(self.ids.image_layout)
# if(self.scroll_position > 0):
# self.ids.image_scroll_view.scroll_y += self.scroll_y_dis
# self.scroll_position -= self.scroll_move_dis

imageScrollView = self.ids.image_scroll_view
imageLayout = self.ids.image_layout
if imageLayout.children:
firstChild = imageLayout.children[-1]
imageScrollView.scroll_to(firstChild)



def on_down_img_click(self, instance, touch):
if instance.collide_point(*touch.pos):
# image_scroll_view.scroll_y = 1
if(self.ids.image_scroll_view.scroll_y > 0.01):
self.ids.image_scroll_view.scroll_y -= self.scroll_y_dis
self.scroll_position += self.scroll_move_dis
# if(self.ids.image_scroll_view.scroll_y > 0.01):
# self.ids.image_scroll_view.scroll_y -= self.scroll_y_dis
# self.scroll_position += self.scroll_move_dis

imageScrollView = self.ids.image_scroll_view
imageLayout = self.ids.image_layout
if imageLayout.children:
lastChild = imageLayout.children[0]
imageScrollView.scroll_to(lastChild)


########################################################################

Expand Down Expand Up @@ -139,7 +151,7 @@ def on_draw_category_item(self):

return boxlayout

# product image
# product image item
class ImageItem(Image):
def __init__(self, **kwargs):
super(ImageItem, self).__init__(**kwargs)
Expand All @@ -158,3 +170,22 @@ def __init__(self, **kwargs):
super(CategoryItem, self).__init__(**kwargs)


# image scroll view
class ImageScrollView(ScrollView):
def __init__(self, **kwargs):
super(ImageScrollView, self).__init__(**kwargs)

# self.imageLayout = self.ids.image_layout

# def on_touch_move(self, touch):
# if self.collide_point(*touch.pos):
# if touch.dy > 0 and self.scroll_y < 1: # Scrolling up
# print(f'scroll----{self.scroll_y}')
# self.scroll_y -= self.scroll_y_dis # Adjust the scroll_y value to modify the scrolling speed
# elif self.scroll_y > 0.01: # Scrolling down
# print(f'scroll+++++{self.scroll_y}')
# self.scroll_y += self.scroll_y_dis
# else:
# print('out')

# return super(ImageScrollView, self).on_touch_move(touch)

0 comments on commit ba0b702

Please sign in to comment.