AndreMiras / KivyMD

Set of widgets for Kivy inspired by Google's Material Design.
MIT License
56 stars 22 forks source link

Add self.thumb_color_disabled for MDSwitch non-Dark theme #4

Closed gbm001 closed 6 years ago

gbm001 commented 6 years ago

Added, in _set_colors, setting self.thumb_color_disabled for MDSwitch when a non-Dark theme is being used. Fixes old issue https://gitlab.com/kivymd/KivyMD/issues/99 Otherwise, code crashes when an MDSwitch is set to 'disabled'.

AndreMiras commented 6 years ago

Thanks, I could reproduce the issue setting disabled: True in the MDSwitch of demos/kitchen_sink/main.py. Error log:

$ PYTHONPATH=. python demos/kitchen_sink/main.py
[INFO   ] [Logger      ] Record log in /home/andre/.kivy/logs/kivy_18-11-06_7.txt
[INFO   ] [Kivy        ] v1.10.1
[INFO   ] [Python      ] v3.6.6 (default, Sep 12 2018, 18:26:19)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] [KivyMD      ] KivyMD version: 0.1.2
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <b'3.0 Mesa 18.0.5'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel Open Source Technology Center'>
[INFO   ] [GL          ] OpenGL renderer <b'Mesa DRI Intel(R) HD Graphics 620 (Kaby Lake GT2) '>
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <b'1.30'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Loader      ] using a thread pool of 2 workers
xclip version 0.12
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL
[INFO   ] [Clipboard   ] Provider: xclip
[INFO   ] [CutBuffer   ] cut buffer support enabled
[WARNING] [MDBottomNavigation] 50.0dp is less than the minimum size of 80dp for a MDBottomNavigationItem. We must now expand to 168dp.
[WARNING] [MDBottomNavigation] 33.333333333333336dp is less than the minimum size of 80dp for a MDBottomNavigationItem. We must now expand to 168dp.
[WARNING] [MDBottomNavigation] 25.0dp is less than the minimum size of 80dp for a MDBottomNavigationItem. We must now expand to 168dp.
 Traceback (most recent call last):
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/lang/builder.py", line 619, in _apply_rule
     setattr(widget_set, key, value)
   File "kivy/weakproxy.pyx", line 33, in kivy.weakproxy.WeakProxy.__setattr__
   File "kivy/properties.pyx", line 483, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 1470, in kivy.properties.AliasProperty.set
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/uix/widget.py", line 1318, in set_disabled
     self.inc_disabled()
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/uix/widget.py", line 1325, in inc_disabled
     self.property('disabled').dispatch(self)
   File "kivy/properties.pyx", line 562, in kivy.properties.Property.dispatch
   File "kivy/properties.pyx", line 579, in kivy.properties.Property.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1096, in kivy._event.EventObservers._dispatch
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/lang/builder.py", line 73, in call_fn
     e_value = eval(value, idmap)
   File "<string>", line 52, in <module>
   File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__
 AttributeError: 'MDSwitch' object has no attribute 'thumb_color_disabled'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "demos/kitchen_sink/main.py", line 1088, in <module>
     KitchenSink().run()
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/app.py", line 800, in run
     root = self.build()
   File "demos/kitchen_sink/main.py", line 942, in build
     main_widget = Builder.load_string(main_widget_kv)
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/lang/builder.py", line 400, in load_string
     self._apply_rule(widget, parser.root, parser.root)
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/lang/builder.py", line 630, in _apply_rule
     e), cause=tb)
 kivy.lang.builder.BuilderException: Parser: File "<inline>", line 543:
 ...
     541:                    pos_hint:    {'center_x': 0.75, 'center_y': 0.5}
     542:                    _active:        False
 >>  543:                    disabled: True
     544:
     545:            Screen:
 ...
 AttributeError: 'MDSwitch' object has no attribute 'thumb_color_disabled'
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/lang/builder.py", line 619, in _apply_rule
     setattr(widget_set, key, value)
   File "kivy/weakproxy.pyx", line 33, in kivy.weakproxy.WeakProxy.__setattr__
   File "kivy/properties.pyx", line 483, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 1470, in kivy.properties.AliasProperty.set
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/uix/widget.py", line 1318, in set_disabled
     self.inc_disabled()
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/uix/widget.py", line 1325, in inc_disabled
     self.property('disabled').dispatch(self)
   File "kivy/properties.pyx", line 562, in kivy.properties.Property.dispatch
   File "kivy/properties.pyx", line 579, in kivy.properties.Property.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1096, in kivy._event.EventObservers._dispatch
   File "/home/andre/workspace/KivyMD/venv/lib/python3.6/site-packages/kivy/lang/builder.py", line 73, in call_fn
     e_value = eval(value, idmap)
   File "<string>", line 52, in <module>
   File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__
$

Will give the pull request a try very soon :+1: