Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14069

How to change the anchor value in MDFloatingActionButtonSpeedDial in KivyMD?

$
0
0

I have been working with kivymd to develop a mobile application. But I was having a problem regarding MDFloatingActionButtonSpeedDial. I wanted to set the anchor value in MDFloatingActionButtonSpeedDial to "left" for some buttons and "right" for some buttons. So I modified the class of MDFloatingActionButtonSpeedDial that is in the module "kivymd.uix.button" and added some more options in 'anchor' which assumes OptionProperty. Along with it I also added the methods required for the applied changes. The changes in acnhor are:-

anchor = OptionProperty('right',option=["right","left"])

And the changes in the methods are:-

def set_pos_labels(self, widget):"""Sets the position of the floating labels."""    if self.anchor == "right":        widget.x = Window.width - widget.width - dp(86)    elif self.anchor == "left":        widget.x = widget.width + dp(86)def set_pos_root_button(self, instance):"""Sets the position of the root button."""    if self.anchor == "right":        instance.y = dp(20)        instance.x = Window.width - (dp(56) + dp(20))    elif self.anchor == "left":        instance.y = dp(20)        instance.x = (dp(56) + dp(20))def set_pos_bottom_buttons(self, instance):"""Sets the position of the bottom buttons in a stack."""    if self.anchor == "right":        if self.state != "open":            instance.y = instance.height / 2        instance.x = Window.width - (instance.height + instance.width / 2)    elif self.anchor == "left":        if self.state != "open":            instance.y = instance.height / 2        instance.x = (instance.height + instance.width / 2)

I have added the left anchor property as the right anchor was present by default.

The Builder string that I have written is as follows:-

MDFloatingActionButtonSpeedDial:     data : app.data_download     rotation_root_button : True     id : download_button     icon: 'download'     anchor: 'left'MDFloatingActionButtonSpeedDial:      data : app.data_return      rotation_root_button: True      icon : 'arrow-left'      anchor: 'right'

Now whenever I tried to set the anchor property to 'left' other than the default option(right) in my builder string file the program returns an error. I want to inform if I set the default value of anchor to left then I get the error for setting the anchor to right and when I set the default value of anchor to right then I get the error for setting the anchor to left. The error that that I am getting is:-

 Traceback (most recent call last): File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 700, in _apply_rule setattr(widget_set, key, value) File "kivy\weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__ File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__ File "kivy\properties.pyx", line 541, in kivy.properties.Property.set File "kivy\properties.pyx", line 532, in kivy.properties.Property.set File "kivy\properties.pyx", line 1252, in kivy.properties.OptionProperty.check ValueError: MDFloatingActionButtonSpeedDial.anchor is set to an invalid option 'left'. Must be one  of: [] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "onlinecv2.py", line 500, in <module> ScanIt().run() File "C:\Users\user\Anaconda3\lib\site-packages\kivy\app.py", line 829, in run root = self.build() File "onlinecv2.py", line 435, in build camerascreen    = Builder.load_string(screen_helper) File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 405, in load_string rule_children=rule_children) File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 707, in _apply_rule e), cause=tb) kivy.lang.builder.BuilderException: Parser: File "<inline>", line 154: ...     152:                        id : download_button     153:                        icon: 'download'>>  154:                        anchor: 'left'     155:     156: ... ValueError: MDFloatingActionButtonSpeedDial.anchor is set to an invalid option 'left'. Must be one  of: [] File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 700, in _apply_rule setattr(widget_set, key, value) File "kivy\weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__ File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__ File "kivy\properties.pyx", line 541, in kivy.properties.Property.set File "kivy\properties.pyx", line 532, in kivy.properties.Property.set File "kivy\properties.pyx", line 1252, in kivy.properties.OptionProperty.check

The output that I am getting (which is undesirable) when i dont set any anchor value in my kivy file is as:-I only get the floating button in the right. But the output that I desire is I wanted two floating buttons to be present on both side of the screen i.e. left as well as right. But I am getting only on one side and so i started to change the module but ended up with an error.

So, I would be glad if you can provide me an solution to solve this error so that I can use both the anchor properties 'left' and 'right'.


Viewing all articles
Browse latest Browse all 14069

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>