Drag and delete item from the list.

120 views
Skip to first unread message

coutinh...@gmail.com

unread,
May 16, 2021, 10:40:17 AM5/16/21
to Kivy users support
Save guys, do you know when you are deleting emails in the gmail app?

Do you drag the list item to the right and left and it deletes the email?

Do we have this in kivy or KivyMD?

Elliot Garbus

unread,
May 16, 2021, 10:53:52 AM5/16/21
to kivy-...@googlegroups.com

There is a drag behavior in behaviors, or you can create your own drag and drop behavior using the on_touch_ methods.

 

I started to experiment with drag behaviors: https://github.com/ElliotGarbus/KivyDragExperiments

But I have never built an app using drag behavior.  I have previously just created my own.

--
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/e48a736c-7eeb-4d47-966a-454dfe740dd8n%40googlegroups.com.

 

purushottam yadav

unread,
May 16, 2021, 10:57:51 AM5/16/21
to Kivy users support

Elias Coutinho

unread,
May 16, 2021, 2:02:54 PM5/16/21
to kivy-...@googlegroups.com
That was it.



--
Elias Coutinho.
Aprender sobre alguns assuntos é fundamental.
Aprender sobre Deus é indiscutivelmente o melhor conteúdo.

Elias Coutinho

unread,
May 16, 2021, 2:03:25 PM5/16/21
to kivy-...@googlegroups.com
I will test it, thank you!

Elias Coutinho

unread,
May 16, 2021, 4:32:12 PM5/16/21
to kivy-...@googlegroups.com
Good night people,

I am evolving but there are some things that should be easier.

Now I need to create a data list and be able to delete it by dragging it to the side.

I found this resource on KivyMD with your help:
https://kivymd.readthedocs.io/en/latest/components/card/#mdcardswipe

As you can see it works exactly as shown on the page.
My problem:

Does the demonstrated application work on a main screen, if I need this feature on another screen? I managed to list on another screen, however the remove_item () function will not work, so I changed my kv from app.remove_item (root) to root.remove_item (root) and it returned the following:

AttributeError: 'SwipeToDeleteItem' object has no attribute 'remove_item'

The basic question is: How can I call a function from another class in kivy?

Or if the question was not clear I would like this example in the first link to work on a screen other than the main one.

Elliot Garbus

unread,
May 16, 2021, 10:13:07 PM5/16/21
to kivy-...@googlegroups.com

How you access one class instance from another is a function of where each instance sits in the kivy tree relative to each other.

Screens make this even a little more complicated.  Lets assume the following:

 

BoxLayout:  # root widget

    ScreenManager:

        id: sm

        ScreenOne:

            name: ‘one’

        ScreenTwo:

            name: ‘two’

 

<ScreenOne>:

    BoxLayout:

        ClassOne:

            id:s1c1

        Button:

           text: ‘print a property from the Class2 instance from screen two’

           on_release: print(app.root.ids.sm.get_screen(‘two’).ids.s2c2.prop)

 

<ScreenTwo>:

    BoxLayout:

        ClassTwo:

            id: s2c2

            prop: ‘The value’

 

Lets say we want to access a property in the ClassTwo instance from ScreenOne… see the on_release statement in ScreenOne Button.

Looking at the ‘kivy string’

app – The app instance

app.root- The root widget

app.root.ids – All the id’s of the root

app.root.ids.sm – The screenmanager

app.root.ids.sm.get_screen(‘two) – The ScreenTwo instance

app.root.ids.sm.get_screen(‘two’).ids – all the id’s of ScreenTwo

app.root.ids.sm.get_screen(‘two’).ids.s2c2 – The ClassTwo instance in ScreenTwo

app.root.ids.sm.get_screen(‘two’).ids.s2c2.prop – The property (‘The Value’).

 

You can print these out to see them.

How you actually access items across the kivy tree is dependent on how you have constructed the tree.

Elliot Garbus

unread,
May 17, 2021, 9:30:36 AM5/17/21
to kivy-...@googlegroups.com

Ooops… While the code below will work, because these are Screens you can use their manager property to simplify:

You can change:

app.root.ids.sm.get_screen(‘two’).ids.s2c2.prop

to:

self.manager.get_screen(‘two’).ids.s2c2.prop

Elias Coutinho

unread,
May 17, 2021, 9:30:45 AM5/17/21
to kivy-...@googlegroups.com
The text commented on line 328 I can print the ids, but when I pass to call the function according to line 329 it presents the error below:

https://gist.github.com/CoutinhoElias/e4231906f65de4493ebca02db3ff45e6#file-multi_screen-py-L315-L359

      on_release: print (app.root.ids.screen_manager.get_screen ('tela_contagem'). ids.tela_contagem.remove_item (root))
    File "kivy / properties.pyx", line 864, in kivy.properties.ObservableDict .__ getattr__
  AttributeError: 'super' object has no attribute '__getattr__'

Elliot Garbus

unread,
May 17, 2021, 10:14:25 AM5/17/21
to kivy-...@googlegroups.com

There is a problem that you have the id’s in your screens as strings.  They need to be identifiers.

 

<ScreenContagem>

    name: 'tela_contagem'

    id:  tela_contagem   #   'tela_contagem'

 

Additionally,

The get_screen() returns the screen widget, using the ids to get the screen is redundant.  You do not need the id.

app.root.ids.screen_manager.get_screen ('tela_contagem').remove_item (root)

Elias Coutinho

unread,
May 17, 2021, 1:20:52 PM5/17/21
to kivy-...@googlegroups.com
Thank you very much.

Can I ask you something off topic?
Really curious.

Elliot Garbus

unread,
May 17, 2021, 1:38:33 PM5/17/21
to kivy-...@googlegroups.com

Elias Coutinho

unread,
May 17, 2021, 2:34:13 PM5/17/21
to kivy-...@googlegroups.com
My curiosity is to know how this group works, I see that you work hard to answer us.

I would like to know if this is paid or is it for the pleasure of helping.

Elliot Garbus

unread,
May 17, 2021, 2:40:49 PM5/17/21
to kivy-...@googlegroups.com

I help for the pleasure of helping.  As a grateful user of an open-source project my contributions here are part of how I give back, and help support the community.

Reply all
Reply to author
Forward
0 new messages