class TestBox(BoxLayout):
data_items = ListProperty()
images = ListProperty()
def __init__(self, **kwargs):
super(TestBox, self).__init__(**kwargs)
self.get_users()
def get_users(self):
connection = mysql.connector.connect(user="*****", password="******", database="*****")
cursor = connection.cursor()
query =("SELECT servicename_ku FROM service_cat ORDER BY service_id ASC")
cursor.execute(query)
rows = cursor.fetchall()
# create data_items like a list to read each title
for row in rows:
for col in row:
self.data_items.append(col)
print(self.data_items)
def write_file(data, filename):
with open(filename, 'wb') as f:
f.write(data)
def get_img(self):
query1 =("SELECT service_img FROM service_cat ORDER BY service_id ASC")
cursor.execute(query1)
images = cursor.fetchall()
weite_file(images, filename)
print(images)
###my Kv file attached here:
<TestBox>:
#set and Arrange the Recycleview features
RecycleView:
id: rv
viewclass:'ImageAndTitle'
bar_width: 2
effect_cls: ScrollEffect
# n is each one of words in data_image list
# root is look at TestBox in this code
data: [{'source': root.images, 'title': get_display(arabic_reshaper.reshape(n))} for n in root.data_items]
RecycleBoxLayout:
default_size: dp(170), dp(153)
default_size_hint: None, None
size_hint: None, None
width: self.minimum_width
height: self.minimum_height
orientation: 'horizontal'
padding: 9
spacing: 20
how i should add images from DB to the recycleview ???
Here is at least one issue:
data: [{'source': root.images, 'title': get_display(arabic_reshaper.reshape(n))} for n in root.data_items]
You are setting source to the entire list root.images. I assume the images list is a list of filenames.
If so you want something like:
data: [{'source': root.images[i], 'title': get_display(arabic_reshaper.reshape(n))} for i, n in enumerate(root.data_items)]
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7c45aecd-9489-48dc-8d75-c798f7f4f67fo%40googlegroups.com.
class TestBox(BoxLayout):
data_items = ListProperty()
images = ListProperty()
titles_eng = ListProperty()
def __init__(self, **kwargs):
super(TestBox, self).__init__(**kwargs)
self.get_users()
def write_file(data, filename):
with open(filename, 'wb') as f:
f.write(data)
def get_users(self):
connection = pymysql.connect(user='****', password= '******', database='****')
cursor = connection.cursor()
cursor.execute("SELECT servicename_ku, service_img, servicename FROM service_cat ORDER BY service_id ASC")
rows = cursor.fetchall()
# create data_items
for row in rows:
title = row[0]
image = row[1]
t_eng = row[2]
self.data_items.append(title)
self.images.append(image)
self.titles_eng.append(t_eng)
<TestBox>:
#set and Arrange the Recycleview features
RecycleView:
#data: [{'source': [n]} for n in root.images]
data : [{'source': [i], 'title': get_display(arabic_reshaper.reshape(n))} for i,n in enumerate(root.images,root.data_items)]
id: rv
viewclass:'ImageAndTitle'
bar_width: 2
effect_cls: ScrollEffect
RecycleBoxLayout:
default_size: dp(170), dp(153)
default_size_hint: None, None
size_hint: None, None
width: self.minimum_width
height: self.minimum_height
orientation: 'horizontal'
padding: 9
spacing: 20
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
[{'source': [i], 'title': get_display(arabic_reshaper.reshape(n))} for i,n in enumerate(root.images,root.data_items)]
The line above a valid Python statement. Example:
>>> a
['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9']
>>> b
['B0', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9']
>>> for i, d in enumerate(b):
print(f'i: {i}, a[i]: {a[i]}, d: {d}')
i: 0, a[i]: A0, d: B0
i: 1, a[i]: A1, d: B1
i: 2, a[i]: A2, d: B2
i: 3, a[i]: A3, d: B3
i: 4, a[i]: A4, d: B4
i: 5, a[i]: A5, d: B5
i: 6, a[i]: A6, d: B6
i: 7, a[i]: A7, d: B7
i: 8, a[i]: A8, d: B8
i: 9, a[i]: A9, d: B9
>>>
You could say:
[{'source': root.images[i], 'title': get_display(arabic_reshaper.reshape(data_item))} for i, data_item in enumerate(root.data_items)]
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4adc96e7-8725-42c5-90b9-b90047c6d70do%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4adc96e7-8725-42c5-90b9-b90047c6d70do%40googlegroups.com.
I see 2 errors below:
IndexError: list index out of range
It appears there are not the same number of items in root.data_items and root.images. Is this correct?
ValueError: ImageAndTitle.source accept only str
What is the content of root.images[i] ?
If you print(type(root.images[0]) what is printed?
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c8dea2e3-2de3-4c3b-93ad-c124999aa8f8o%40googlegroups.com.
def get_users(self):
connection = pymysql.connect(user='****', password= '******', database='****')
cursor = connection.cursor()
cursor.execute("SELECT servicename_ku, service_img, servicename FROM service_cat ORDER BY service_id ASC")for row in rows:
rows = cursor.fetchall()
# create data_items
title = row[0]
image = row[1]
t_eng = row[2]
self.data_items.append(title)
self.images.append(image)
self.titles_eng.append(t_eng)
I see 2 errors below:
IndexError: list index out of range
It appears there are not the same number of items in root.data_items and root.images. Is this correct?
ValueError: ImageAndTitle.source accept only str
What is the content of root.images[i] ?
If you print(type(root.images[0]) what is printed?
if i print root.images in kv file will give me again the : IndexError: list index out of range
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c8dea2e3-2de3-4c3b-93ad-c124999aa8f8o%40googlegroups.com.
import mysql.connector
import pymysql
from kivy.app import App
class TextBox():
def __init__(self, **kwargs):
super(TestBox, self).__init__(**kwargs)
self.write_file()
def write_file(data, filename):
with open(filename, 'wb') as file:
file.write(data)
def get_img(service_id, filename):
connection = pymysql.connect(user="****", password="******", database="*****")
cursor = connection.cursor()
query1 =("SELECT service_img, servicename_ku, servicename FROM service_cat WHERE service_id = %s")
cursor.execute(query1, (service_id,))
records = cursor.fetchall()
for field in records:
image = field[0]
title = field[1]
english_title = field[2]
TextBox.write_file(image, filename)
print(title)
class MainApp(App):
TextBox.get_img(4, "D:\Python\spana\example.png")
MainApp().run()
Please attach a more complete section of code.
As I understand it. You are pulling images from the database, and writing them to files. The filenames are being stored in a list, images.
Print the len(root.images) and print(len(root.data_items)) are they the same?
Print root.images is it the expected list of filenames?
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ccf65b25-c728-454c-baa0-f13797d2e7e0o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ccf65b25-c728-454c-baa0-f13797d2e7e0o%40googlegroups.com.
class ImageAndTitle(MDBoxLayout, ButtonBehavior):
source = StringProperty()
title = StringProperty()
class TestBox(BoxLayout):
txt = ListProperty()
images2 = ListProperty()
records = ListProperty()
def __init__(self, **kwargs):
super(TestBox, self).__init__(**kwargs)
self.get_cat()
def get_cat(self):
connection = pymysql.connect(user="*****", password="*******", database="******")
cursor = connection.cursor()
query1 =("SELECT service_img,servicename_ku,servicename FROM service_cat ORDER BY service_id")
cursor.execute(query1)
records = cursor.fetchall()
file1 = BytesIO(records[0][0])
img1 = PIL.Image.open(file1)
self.images2.append(img1)
print(type(records[0]))
for field in records:
tex = field[1]
img = field[0]
print(type(img))
print(tex)
self.txt.append(tex)
#:import utils kivy.utils
#:import SmartTileWithLabel kivymd.uix.imagelist.SmartTileWithLabel
#:import ScrollEffect kivy.effects.scroll.ScrollEffect
#:import ScrollEffect kivy.effects.scroll.ScrollEffect
#:import get_display bidi.algorithm.get_display
#:import arabic_reshaper arabic_reshaper
<ImageAndTitle>:
#produce the MDCard Material Icons
MDCard:
orientation: "vertical"
border_radius : "20dp"
radius : [10]
focus_behavior: False
elevation: 1
spacing: 10
padding: [0,20,0,20]
md_bg_color: utils.get_color_from_hex("#fcfcfc")
Image:
source: root.source
size_hint_y: self.size_hint_min_y
MDLabel:
text: root.title
halign: "center"
theme_text_color: "Primary"
font_style: "Subtitle1"
<TestBox>:
#set and Arrange the Recycleview features
RecycleView:
#data: [{'source': [n]} for n in root.images]
#data : [{'source': [i], 'title': root.data_items(get_display(arabic_reshaper.reshape(n)))} for i,n in enumerate(root.images)]
#[
'title': (get_display(arabic_reshaper.reshape(n)))} for n in root.txt ]
above for loop is working for title and i can get text from DB my problem is with Blob Data
data : [ {'source': root.images2[i]} for i in range(7)]
id: rv
viewclass:'ImageAndTitle'
bar_width: 2
effect_cls: ScrollEffect
RecycleBoxLayout:
default_size: dp(170), dp(153)
default_size_hint: None, None
size_hint: None, None
width: self.minimum_width
height: self.minimum_height
orientation: 'horizontal'
padding: 9
spacing: 20
You can directly load images as described here: https://kivy.org/doc/stable/api-kivy.core.image.html?highlight=image#in-memory-image-loading
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bb618036-fc0d-41f9-9862-a1fc2d10e245o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bb618036-fc0d-41f9-9862-a1fc2d10e245o%40googlegroups.com.