Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot convert kivy.properties.BoundedNumericPropertyStorage to kivy.properties.NumericPropertyStorage #7398

Closed
hladkky opened this issue Mar 3, 2021 · 8 comments

Comments

@hladkky
Copy link

hladkky commented Mar 3, 2021

Software Versions

  • Python: 3.8
  • OS: WSL
  • Kivy: master
  • Kivy installation method: with buildozer requirements: ..., kivy==master, ...

Describe the bug
I have been compiled my application with WSL many times before, but the last one went wrong.
I have debugged the application on my mobile device through the ADB and got such traceback.

What the reason could it be and how can I fix it?

Expected behaviour
Expect application to run properly.

To Reproduce
Here is a branch from which I built https://github.com/hladkky/alias-kivy-application/tree/temp.

Code and Logs and screenshots

...
2021-03-03 13:20:34.826 20263-20305/org.alias_uk.alias_uk I/python: [INFO   ] [Base        ] Start application main loop
2021-03-03 13:20:34.884 20263-20305/org.alias_uk.alias_uk I/python: [INFO   ] [Base        ] Leaving application in progress...
2021-03-03 13:20:34.884 20263-20305/org.alias_uk.alias_uk I/python:  Traceback (most recent call last):
2021-03-03 13:20:34.885 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/app/main.py", line 268, in <module>
2021-03-03 13:20:34.885 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/alias_uk/kivy/app.py", line 955, in run
2021-03-03 13:20:34.885 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/alias_uk/kivy/base.py", line 580, in runTouchApp
2021-03-03 13:20:34.885 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/alias_uk/kivy/base.py", line 345, in mainloop
2021-03-03 13:20:34.885 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/alias_uk/kivy/base.py", line 385, in idle
2021-03-03 13:20:34.885 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/alias_uk/kivy/clock.py", line 733, in tick
2021-03-03 13:20:34.886 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/alias_uk/kivy/clock.py", line 776, in post_idle
2021-03-03 13:20:34.886 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/_clock.pyx", line 616, in kivy._clock.CyClockBase._process_events
2021-03-03 13:20:34.886 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/_clock.pyx", line 649, in kivy._clock.CyClockBase._process_events
2021-03-03 13:20:34.886 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/_clock.pyx", line 645, in kivy._clock.CyClockBase._process_events
2021-03-03 13:20:34.886 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/_clock.pyx", line 218, in kivy._clock.ClockEvent.tick
2021-03-03 13:20:34.886 20263-20305/org.alias_uk.alias_uk I/python:    File "/home/hladkko/aliasapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/alias_uk/kivy/uix/floatlayout.py", line 97, in do_layout
2021-03-03 13:20:34.886 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/properties.pyx", line 478, in kivy.properties.Property.__set__
2021-03-03 13:20:34.887 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/properties.pyx", line 1408, in kivy.properties.ReferenceListProperty.set
2021-03-03 13:20:34.887 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/properties.pyx", line 503, in kivy.properties.Property.set
2021-03-03 13:20:34.887 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/properties.pyx", line 507, in kivy.properties.Property.set
2021-03-03 13:20:34.887 20263-20305/org.alias_uk.alias_uk I/python:    File "kivy/properties.pyx", line 661, in kivy.properties.NumericProperty.convert
2021-03-03 13:20:34.887 20263-20305/org.alias_uk.alias_uk I/python:  TypeError: Cannot convert kivy.properties.BoundedNumericPropertyStorage to kivy.properties.NumericPropertyStorage
2021-03-03 13:20:34.887 20263-20305/org.alias_uk.alias_uk I/python: Python for android ended.
@moonpyx
Copy link

moonpyx commented Mar 12, 2021

Hi, I was checking the change history and this problem appears in this commit dbd9aec

@matham
Copy link
Member

matham commented Mar 14, 2021

I believe #7424 should fix it. Can you check?

@moonpyx
Copy link

moonpyx commented Mar 16, 2021

Hello, I checked and the error still persists and apparently it is due to the implementation of kivymd == 0.104.2.dev0 I put the code with which the revision is made, otherwise MDFlatButton works correctly

from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.app import MDApp     
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton 
  
class CardFloat(MDDialog):
    def __init__(self, **k):
        self.type = "custom"
        self.content_cls=MDBoxLayout()  
        self.buttons=[
                        MDFlatButton(
                            on_release=self.dismiss,
                            text="cerrar", text_color=MDApp.get_running_app().theme_cls.primary_color
                        )
                    ]  
        super().__init__(**k)
      
        
        
        
      
class test(MDApp):
    def build(self):
        m=CardFloat(size=[300,700])
        m.open()
        return MDBoxLayout()
    
if __name__ == "__main__":
    test().run()```

@matham
Copy link
Member

matham commented Mar 16, 2021

I just tried the code above with kivy master and kivymd master and could not trigger the issue. Do you have to do something to trigger the issue?

@moonpyx
Copy link

moonpyx commented Mar 16, 2021

you're right @matham, try following these steps:

install kivy:
python -m pip install git + https: //github.com/kivy/kivy.git

install kivymd:
python -m pip install git + https: //github.com/kivymd/KivyMD.git

The previous code worked, but I managed to replicate the failure by modifying the code like this:


from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.app import MDApp     
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton 
  
class CardFloat(MDDialog):
    def __init__(self, **k):
        self.type = "custom"
        self.content_cls=MDBoxLayout()  
        mdButton = MDFlatButton(
                            on_release=self.dismiss,
                            text="cerrar", text_color=MDApp.get_running_app().theme_cls.primary_color
                        )
        mdButton.size_hint=1,1
        self.buttons=[
                        mdButton
                    ]  
        super().__init__(**k)
      
        
        
        
      
class test(MDApp):
    def build(self):
        m=CardFloat(size=[300,700])
        m.open()
        return MDBoxLayout()
    
if __name__ == "__main__":
    test().run()

@hladkky
Copy link
Author

hladkky commented Mar 16, 2021

Yeah. I was managed to debug the application and found out that the reason for the error is the size_hint of widgets like the button. You can not set size_hint: 1, 1 or any other number from 0 to 1 for x and y both. Setting up only one of them does not cause exception, like size_hint: None, 0.7 or size_hint_x: 1

@hladkky
Copy link
Author

hladkky commented Mar 16, 2021

I have refactored some pieces of my code to avoid this exception so it does not appear.

@matham
Copy link
Member

matham commented Mar 16, 2021

Ok, I was able to reproduce it. This is actually a bug in KivyMD, which just wasn't visible before, but now it is because of the linked changes.

In widget.py Widget we have:

    width = NumericProperty(100)
    height = NumericProperty(100)
    size = ReferenceListProperty(width, height)

Then in KivyMD in BaseRectangularButton we have:

class BaseRectangularButton(...):
    width = BoundedNumericProperty(
        88, min=88, max=None, errorhandler=lambda x: 88
    )

But, the size property of Widget still refers to the original NumericProperty and not BoundedNumericProperty. You can see it in the error message:

File "G:\Python\libs\kivy\kivy\uix\boxlayout.py", line 323, in do_layout
     c.size = (w, h)
   File "kivy\properties.pyx", line 478, in kivy.properties.Property.__set__
   File "kivy\properties.pyx", line 1408, in kivy.properties.ReferenceListProperty.set
   File "kivy\properties.pyx", line 503, in kivy.properties.Property.set
   File "kivy\properties.pyx", line 507, in kivy.properties.Property.set
   File "kivy\properties.pyx", line 661, in kivy.properties.NumericProperty.convert
 TypeError: Cannot convert kivy.properties.BoundedNumericPropertyStorage to kivy.properties.NumericPropertyStorage

In the second before last line, it's actually using NumericProperty.convert and not BoundedNumericProperty.convert as KivyMD expects. So if you set button.width = x then it goes through the BoundedNumericProperty, but if you set button.size = x, y then it goes through the original NumericProperty.

Previously this would cause an explicit exception because BoundedNumericProperty and NumericProperty happened to share some internal storage details. But with my changes they don't anymore and so it crashes. But the bug is because of the width redefinition without also redefining size.

The solution is for KivyMD to do:

class BaseRectangularButton(...):
    width = BoundedNumericProperty(
        88, min=88, max=None, errorhandler=lambda x: 88
    )
    height = NumericProperty(100)
    size = ReferenceListProperty(width, height)

However, this leads to [CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute And that's because the minimum value 88 conflicts with AnchorLayout.do_layout and BoxLayout.do_layout, one of which somehow sets size = 0, ... which is below the minimum. I'm not sure why, but again this is a bug in KivyMD. Setting min=0 "fixes" that issue.

So ultimately I think this is something KivyMD needs to fix so I'll close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants