--
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/ed4df83b-eec0-45c0-9de2-c869383fe3e8n%40googlegroups.com.
The class only has one content attribute. If you want multiple items on the expansion panel, set a content item to be a layout, and add the items. Extending the example in the docs:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelThreeLine
from kivymd import images_path
KV = '''
<Content>
adaptive_height: True
orientation: 'vertical'
TwoLineIconListItem:
text: "(050)-123-45-67"
secondary_text: "Mobile"
IconLeftWidget:
icon: 'phone'
TwoLineIconListItem:
text: "Second Item Line One"
secondary_text: "Second Item Line Two"
ScrollView:
MDGridLayout:
id: box
cols: 1
adaptive_height: True
'''
class Content(MDBoxLayout):
'''Custom content.'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
for i in range(10):
self.root.ids.box.add_widget(
MDExpansionPanel(
icon=f"{images_path}kivymd.png",
content=Content(),
panel_cls=MDExpansionPanelThreeLine(
text="Text",
secondary_text="Secondary text",
tertiary_text="Tertiary text",
)
)
)
Test().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8pV8P4jH0AwE2E_HjMM11R_Lc%3DmK_FLZbBaMWffAv8tOQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/629ade34.1c69fb81.c8e2.e3bcSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Here you go… The for loop in content adds 3 TwoLine items to the exapansion panel, the initial item is defined in kv. You can move them all to the for loop.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelThreeLine
from kivymd.uix.list import TwoLineListItem
from kivymd import images_path
KV =
'''
<Content>
adaptive_height: True
orientation: 'vertical'
TwoLineIconListItem:
text: "(050)-123-45-67"
secondary_text: "Mobile"
IconLeftWidget:
icon: 'phone'
ScrollView:
MDGridLayout:
id: box
cols: 1
adaptive_height: True
'''
class Content(MDBoxLayout):
'''Custom content.'''
def on_kv_post(self, base_widget):
for i in range(1, 4):
w = TwoLineListItem(text=f"Item {i} Line One", secondary_text="Line Two")
self.add_widget(w)
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
for i in range(10):
self
.root.ids.box.add_widget(
MDExpansionPanel(
icon='pencil',
content=Content(),
panel_cls=MDExpansionPanelThreeLine(
text="Text",
secondary_text="Secondary text",
tertiary_text="Tertiary text",
)
)
)
Test().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8oZVOCbWKPRRWKVDqn8a9m7fnoUZmMqEsce_t6H4uEKGg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/629b74a5.1c69fb81.732c3.f017SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
*** Off topic question ***
How can you send hi light codes through the forum.
I have the messages from the forum set to my local email client. I use the highlighter capability in the default Windows Email client.
Did you have a question about getting the JSON into the expansion panel?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8rj%2B1VrvqQ7a6ZfifwQHd60ecjMW0JHNkOdyqKXswVWNg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/629cc0c0.1c69fb81.49ff4.edc4SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
I think this is what you are looking for…
As an FYI, when parsing JSON, I like to use pretty print to print the JSON, it makes it easier to understand when parsing.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivymd.uix.list import ThreeLineListItem
KV = '''
<Content>
adaptive_height: True
orientation: 'vertical'
<InvoicePanel>:
icon: 'pencil'
ScrollView:
MDGridLayout:
id: box
cols: 1
adaptive_height: True
'''
json_data = {'Card': {'Invoice': {'20220602184756182705': {'01001BA476': {'price': '74.73',
'product_code': '000003',
'quantity': '100'},
'0100251633': {'price': '92.07',
'product_code': '000156',
'quantity': '1000'}}}}}
class InvoicePanel(MDExpansionPanel):
pass
class Content(MDBoxLayout):
pass
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
# I am assuming you have multiple invoices per each card...
invoices = list(json_data['Card']['Invoice'].keys())
for invoice in invoices:
# add invoice as major item
cw = Content() # fill in content as the data is parsed
ep = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {invoice}'),
content=cw)
self.root.ids.box.add_widget(ep)
line_items = list(json_data['Card']['Invoice'][invoice].keys())
# self.root.ids.box.add_widget(ep)
for item in line_items:
lines = [(k, v) for k, v in json_data['Card']['Invoice'][invoice][item].items()]
# add content as 3 line item
cw.add_widget(ThreeLineListItem(text=f'Item: {item}, {lines[0][0]}: {lines[0][1]}',
secondary_text=f'{lines[1][0]}: {lines[1][1]}',
tertiary_text=f'{lines[2][0]}: {lines[2][1]}'))
Test().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8rtThF8m-yaxuoaYtPE07uoSJDnwoh%3Dth8-Qq2aB1DyuQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/629ceac4.1c69fb81.ae9df.4823SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/629ceac4.1c69fb81.ae9df.4823SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
The "Content Class” in the example below is an MDBoxLayout.
You would want the ThreeLineListItem to center the text. Looking at the source code for kicyMD, the look the ThreeLine list item is set by it’s parent class.
It think it would be easiest to replace the ThreeLineListItem with a new class that contains an MDList that centers the data.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8qCP4_qVPW6oANBfVg05gVnz-2tyUqSPjefNnZ1%2BmMBtw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a24e51.1c69fb81.232bf.9af1SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Yes you could use a Label on an MDLabel, or create a class that has multiple Labels. You would want to draw a line under the text to have a look consistent with the ListItem classes.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8qYsFaTDHo_G1hOAv5dydv7nQrsAQJYRyx-2F6TimGj0A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a25985.1c69fb81.dbcf0.de54SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Nice!
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8q%3DPpstYJfd_%3DWRXBLhDeHehbVebkHdCg42SB8kHpz4%2Bw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a3d3f5.1c69fb81.99213.0d62SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
The example below shows 3 ways to do it.
The on_release attribute needs to be assigned a callable. You can use a lambda to create an anonymous function; you can use a method; or you can define a new class and specify the on_release in kv.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
kv ="""
<ReleaseButton>:
on_release: print(f'{self.text} print from kv, instanced in python')
RootBoxLayout:
orientation: 'vertical'
Button:
text: 'Button 0'
on_release: print(f'{self.text} print from kv instanced in kv')
"""
class ReleaseButton(Button):
pass
class RootBoxLayout(BoxLayout):
def on_kv_post(self, base_widget):
self.add_widget(Button(text='Button 1', on_release=lambda x:print(f'{x.text} instanced in python, print from lambda')))
self.add_widget(Button(text='Button 2', on_release=self.call_method))
self.add_widget(ReleaseButton(text='Button 3'))
def call_method(self, button):
print(f'{button.text} instanced in python, print in method')
class OnReleaseExamples(App):
def build(self):
return Builder.load_string(kv)
OnReleaseExamples().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8pvNfK8ZVBHhTq48zdh4XUP5N4%2BfO-dvwKZGqDYyWEK0Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a7a532.1c69fb81.20df0.5be8SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
On Jun 13, 2022, at 3:26 PM, Elias Coutinho <coutinh...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8rg8x7_VSYLxDZ3adhKjACD29s0cAmvmKtt-oy3cHi_ng%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/38A8C58B-3D99-4DF8-A7D0-199FBADDB5BF%40cox.net.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/38A8C58B-3D99-4DF8-A7D0-199FBADDB5BF%40cox.net.
If you put the function in the constructor with on_press=self.fechar_pedido(); then at the time you are making the enclosing call creating the OneListItemAligned, you will make the call to self.fechar_pedido(), and set on_press to the value that is returned by self.fechar_pedido(). In this case, that would be None.
What is the error you are seeing?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8oYW3OSY6Cq-EnY%3DcOi4a5CKQNPfaV%3DSY%2BfYQkW_HP%2B0Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a7e179.1c69fb81.b141c.e2afSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Charles,
I’ll be happy to put an example together for you. I am assuming that you will get some data that you want to display. My example will be more useful for you if the example uses the data as it is structured. Do you have data that you want to display?
If you do not have data – let me know I’ll create an example.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAMsm4Mm05VNVOJ-FaL2JNTx0Ba5BNJDH%3D_4FZLNjf-we_B2Z5Q%40mail.gmail.com.
I’ve assumed the data is a list of tuples of the class name, and the details. I hope this helps.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty
class_data = [('Business 101', 'An introduction to key concepts'),
('Business 201', 'An intermediate class'),
('Business 301', 'A few focused an complex topics'),
('Business 401', 'A detailed look a complex problems'),
('Computer Science 101', 'An introduction to key concepts'),
('Computer Science 201', 'An intermediate class'),
('Computer Science 301', 'A few focused an complex topics'),
('Computer Science 401', 'A detailed look a complex problems'),
('Math 101', 'An introduction to key concepts'),
('Math 201', 'An intermediate class'),
('Math 301', 'A few focused an complex topics'),
('Math 401', 'A detailed look a complex problems'),
('Art 101', 'An introduction to key concepts'),
('Art 201', 'An intermediate class'),
('Art 301', 'A few focused an complex topics'),
('Art 401', 'A detailed look a complex problems')]
KV = '''
<ClassDetails>
adaptive_height: True
OneLineIconListItem:
text: root.text
IconLeftWidget:
icon: 'star'
ScrollView:
MDGridLayout:
id: box
cols: 1
adaptive_height: True
'''
class ClassDetails(MDBoxLayout):
text = StringProperty()
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self
):
for class_title, class_details in class_data:
self.root.ids.box.add_widget(
MDExpansionPanel(icon="pencil",
content=ClassDetails(text=class_details),
panel_cls=MDExpansionPanelOneLine(text=class_title)))
Test().run()
From: Elliot Garbus
Sent: Monday, June 13, 2022 7:02 PM
To: kivy-...@googlegroups.com
Subject: RE: [kivy-users] Expansion Panel
Charles,
I’ll be happy to put an example together for you. I am assuming that you will get some data that you want to display. My example will be more useful for you if the example uses the data as it is structured. Do you have data that you want to display?
If you do not have data – let me know I’ll create an example.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAMsm4Mm05VNVOJ-FaL2JNTx0Ba5BNJDH%3D_4FZLNjf-we_B2Z5Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a7ffec.1c69fb81.9e316.02beSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Changes highlighted:
Builder.load_string(KV)
def myprint(self, expansion_panel):
print(expansion_panel.text)
print('---------- ok ----------')
def on_start(self):
for class_title, class_details in class_data:
self.root.ids.box.add_widget(
MDExpansionPanel(icon="pencil",
content=ClassDetails(text
=class_details),
panel_cls=MDExpansionPanelOneLine(text=class_title, on_press=self.myprint)))
Test().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8ryObXRdmokBbv%3DVzM6xeXJn_xzk7K2GX_YA9PvqghBWQ%40mail.gmail.com.
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/_wyQpAhuwxw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a904e9.1c69fb81.26f90.699bSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
On Jun 14, 2022, at 3:27 PM, Elias Coutinho <coutinh...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8qjmVs3ZQge3CPwAT710ESKiMJ5hhGqu0vZw7bfM%3DLtbw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/F8BC2F70-6061-4797-936E-BDC66F986682%40cox.net.
The content, is the ClassDetails class. ClassDetails is derived from an MDBoxLayout. If we want to have a response to an on_press event, we can add ButtonBehavior.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty
from kivy.uix.behaviors import ButtonBehavior
class ClassDetails(ButtonBehavior, MDBoxLayout):
text = StringProperty()
class Test(MDApp):
def build(self):
return
Builder.load_string(KV)
def myprint(self, obj):
print('---------- ok ----------')
print(obj.text)
def on_start(self):
for class_title, class_details in class_data:
self.root.ids.box.add_widget(
MDExpansionPanel(icon="pencil",
content=ClassDetails(text=class_details, on_press=self.myprint),
panel_cls=MDExpansionPanelOneLine(text=class_title)))
Test().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8pPkYsA0Fu_Fkk7PRHPV3eWBL3Xg5GLsQbMaKsWkXfh_g%40mail.gmail.com.
Here are two other ways to add the on_press…
You could use the on_press event that is available in the components of ClassDetails, the OneLineIconListItem and the IconLeftWidet.
In the kv code definition of Class detail, action is called. If you had different callbacks you wanted to insert based on the data this might be a useful approach.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty, ObjectProperty
class_data = [('Business 101', 'An introduction to key concepts'),
('Business 201', 'An intermediate class'),
('Business 301', 'A few focused an complex topics'),
('Business 401', 'A detailed look a complex problems'),
('Computer Science 101', 'An introduction to key concepts'),
('Computer Science 201', 'An intermediate class'),
('Computer Science 301', 'A few focused an complex topics'),
('Computer Science 401', 'A detailed look a complex problems'),
('Math 101', 'An introduction to key concepts'),
('Math 201', 'An intermediate class'),
('Math 301', 'A few focused an complex topics'),
('Math 401', 'A detailed look a complex problems'),
('Art 101', 'An introduction to key concepts'),
('Art 201', 'An intermediate class'),
('Art 301', 'A few focused an complex topics'),
('Art 401', 'A detailed look a complex problems')]
KV = '''
<ClassDetails>
adaptive_height: True
OneLineIconListItem:
id: info_line
text: root.text
on_press: root.action()
IconLeftWidget:
icon: 'star'
on_press: print(f'star pressed on line: {info_line.text}')
ScrollView:
MDGridLayout:
id: box
cols: 1
adaptive_height: True
'''
class ClassDetails(MDBoxLayout):
text = StringProperty()
action = ObjectProperty()
class Test(MDApp):
def build(self):
return
Builder.load_string(KV)
def my_print(self):
print('You clicked on the information line')
def on_start(self):
for class_title, class_details in class_data:
self.root.ids.box.add_widget(
MDExpansionPanel(icon="pencil",
content=ClassDetails(text=class_details, action=self.my_print),
panel_cls=MDExpansionPanelOneLine(text=class_title)))
Test().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62aa613c.1c69fb81.3ac16.0c1eSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Perfect!
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62aa6540.1c69fb81.53b48.033bSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
--Elias Coutinho.
Aprender sobre alguns assuntos é fundamental.
Aprender sobre Deus é indiscutivelmente o melhor conteúdo.