0

I'm learning Kivy and I'm on the MDExpansionPanel widget. Data source from a JSON I use the keys to assemble my panels and the values to compose my Contents.

It happens that I'm able to do it but an extra line always appears in my contents.

I would like your help to delete this line.

I will post my code below:

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


json_data = {'01001BA476': {'price': '74.73',
                            'product_code': '000003',
                            'quantity': '100'},
             '0100251633': {'price': '92.07',
                            'product_code': '000156',
                            'quantity': '1000'}}


KV = '''
<ClassDetails>
    orientation: 'vertical'
    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 InvoicePanel(MDExpansionPanel):
    pass

class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def fechar_pedido(self):
        print('You clicked on the information line')

    def on_start(self):
        for class_title, class_details in json_data.items():
            cd = ClassDetails()
            expansion_panel = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {class_title}'), content=cd)
            self.root.ids.box.add_widget(expansion_panel)

            for item in class_details.items():
                cd.add_widget(ClassDetails(
                    text=str(class_details.values()), action=self.fechar_pedido))

Test().run()

1 Answers1

1

I think the extra line is coming from setting your initial content to a ClassDetails instance, which has a OneLineIconListItem in its definition. Try replacing the content with a simple MDBoxLayout instead:

def on_start(self):
    for class_title, class_details in json_data.items():
        print(class_title, class_details)
        # cd = ClassDetails()
        cd = MDBoxLayout(orientation='vertical', adaptive_height=True)
        expansion_panel = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {class_title}'), content=cd)
        self.root.ids.box.add_widget(expansion_panel)

        for item in class_details.items():
            print('\titem:', item)
            cd.add_widget(ClassDetails(
                text=str(class_details.values()), action=self.fechar_pedido))
John Anderson
  • 35,991
  • 4
  • 13
  • 36