On Raspberry with Raspbian GNU/Linux 10 (buster) I have Kivy setup the following way:
[INFO ] [Logger ] Record log in /home/pi/.kivy/logs/kivy_20-09-30_28.txt
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Kivy ] v2.0.0rc1, git-Unknown, 20191231
[INFO ] [Kivy ] Installed at "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/__init__.py"
[INFO ] [Python ] v3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0]
[INFO ] [Python ] Interpreter at "/home/pi/.virtualenvs/py3/bin/python"
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Window ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] Backend used <sdl2>
[INFO ] [GL ] OpenGL version <b'3.1 Mesa 19.3.2'>
[INFO ] [GL ] OpenGL vendor <b'VMware, Inc.'>
[INFO ] [GL ] OpenGL renderer <b'llvmpipe (LLVM 9.0.1, 128 bits)'>
[INFO ] [GL ] OpenGL parsed version: 3, 1
[INFO ] [GL ] Shading version <b'1.40'>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2(['text_pango'] ignored)
[INFO ] [GL ] NPOT texture support is available
[INFO ] [GL ] Unpack subimage support is available
[INFO ] [Base ] Start application main loop
Regardless if I use the original 7" TFT display or a LCD (both on HDMI) sometimes randomly happens the popups come up in a see-through version or without colors, they do not cover the main screen. See the pictures below.
Some of my code to get an idea. Unfortunately I can not provide a bare minimum working sample.
# to avoid "segmentation error" due to raspbian version
os.environ["KIVY_WINDOW"] = "sdl2"
# uncommnent he two lines below when using the TFT display
from kivy.core.window import Window
#Window.fullscreen = 'auto'
#Window.show_cursor = False
# kivy modules first, if not Kivy may cause problems
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.network.urlrequest import UrlRequest
from kivy.factory import Factory
kivy.require('2.0.0')
# main screen
class MainScreen(Screen):
def __init__(self, **kwargs):
self.name="MAIN SCREEN"
super(Screen, self).__init__(**kwargs)
# popup class
class RequestBox(Popup):
def __init__(self, obj, **kwargs):
super(RequestBox, self).__init__(**kwargs)
self.obj = obj
# main app class
class Touch(App):
pauseFlag = False # init set pause to OFF
MainScreenTitle = "MainScreenTitle"
MainScreenLabel = "MainScreenLabel"
MessageBoxTitle = "MessageBoxTitle"
MessageBoxLabel = "MessageBoxLabel"
MessageButtonConfirm = "CONFERMA"
MessageButtonCancel = "CANCELLA"
MessageButtonEnter = "ENTRA"
MessageButtonExit = "ESCI"
def build(self):
sm = Builder.load_string("""
ScreenManager
canvas:
Color:
rgb: 1, 1, 1
Rectangle:
size: self.size
MainScreen:
size_hint: 1, 1
auto_dismiss: True
# auto_dismiss: False # original line
title: app.MainScreenTitle
title_align: "center"
BoxLayout:
orientation: "vertical"
spacing: 10
#Label:
#text: app.MainScreenLabel
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .8
Image:
orientation: "vertical"
center: self.parent.center
source: "ChemoMakerMark.jpg"
size_hint: 1, 1
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .2
# Button: # uncomment to activate the nter button
# text: app.MessageButtonEnter # start app
# on_press:
# #app.enter()
Button:
font_size: 50
text: app.MessageButtonExit # exit app
on_press:
self.background_color = 0,255,0,1
app.exit()
<MessageBox>:
size_hint: 1, 1
auto_dismiss: False
title: app.MessageBoxTitle
title_align: "center"
title_size: 30
BoxLayout:
orientation: "vertical"
Label:
font_size: '30sp'
text: app.MessageBoxLabel
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .5
Button:
font_size: 50
background_color: 0,204,0,1
text: app.MessageButtonConfirm # "CONFIRM"
on_press:
# self.disabled = True
self.background_color = 0,255,0,1
app.do()
root.dismiss()
Button:
font_size: 50
background_color: 204,0,0,1
text: app.MessageButtonCancel # "CANCEL"
on_press:
self.background_color = 255,0,0,1
app.cancel()
root.dismiss()
<ActivityBox>:
size_hint: 1, 1
auto_dismiss: False
title: app.MessageBoxTitle
title_align: "center"
title_size: 30
BoxLayout:
orientation: "vertical"
Label:
font_size: '30sp'
text: app.MessageBoxLabel
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .5
<RequestBox>:
size_hint: 1, 1
auto_dismiss: False
title: app.MessageBoxTitle
title_align: "center"
title_size: 30
BoxLayout:
orientation: "vertical"
Label:
font_size: '30sp'
text: app.MessageBoxLabel
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .5
Button:
font_size: 50
background_color: 0,204,0,1
text: app.MessageButtonConfirm # "CONFIRM"
on_press:
self.disabled = True
self.background_color = 0,255,0,1
app.accept_request()
#root.dismiss()
Button:
font_size: 50
background_color: 204,0,0,1
text: app.MessageButtonCancel # "CANCEL"
on_press:
self.background_color = 255,0,0,1
app.reject_request() # for testing the data flow when 400 is not desired
root.dismiss()
<BarcodeBox>:
size_hint: 1, 1
auto_dismiss: False
title: app.MessageBoxTitle
title_align: "center"
title_size: 30
BoxLayout:
orientation: "vertical"
Label:
font_size: '30sp'
text: app.MessageBoxLabel
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .5
Button:
font_size: 50
background_color: 204,0,0,1
text: app.MessageButtonCancel # "CANCEL"
on_press:
self.background_color = 255,0,0,1
app.cancel_barcode()
root.dismiss()
<RfidBox>:
size_hint: 1, 1
auto_dismiss: False
title: app.MessageBoxTitle
title_align: "center"
title_size: 30
BoxLayout:
orientation: "vertical"
Label:
font_size: '30sp'
text: app.MessageBoxLabel
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .5
Button:
font_size: 50
background_color: 204,0,0,1
text: app.MessageButtonCancel # "CANCEL"
on_press:
self.background_color = 255,0,0,1
app.cancel_rfid()
root.dismiss()
<ErrorBox>:
size_hint: 1, 1
auto_dismiss: False
title: app.MessageBoxTitle
title_align: "center"
title_size: 30
BoxLayout:
orientation: "vertical"
Label:
font_size: '30sp'
text: app.MessageBoxLabel
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .5
Button:
font_size: 50
background_color: 204,0,0,1
text: app.MessageButtonCancel # "CANCEL"
on_press:
self.background_color = 255,0,0,1
app.annulla()
root.dismiss()
""")
return sm
What could be the problem?
------ 1. UPDATE --------------------------------------------------
The troubled popup is build and opens in the main thread. The problem remains in both cases: if the popup is run as a thread or directly.
def mainmethod():
# setup the messages for the MessageBox popup
self.messageTitle = "some title"
self.messageLabel = "some message"
# call popup2, the MessageBox popup
self.popup2(self.messageTitle, self.messageLabel)
def popup2(self, boxTitle, boxLabel): # popup for showing message
#set the messages of the popup
self.MessageButtonConfirm = "AVANTI"
self.MessageButtonCancel = "CANCELLA"
self.MessageBoxTitle = boxTitle
self.MessageBoxLabel = boxLabel
# set the popup structure
self.popupMessage = MessageBox(self)
# run the popup directly
self.popupMessage.open()
# run the popup in a thread
# tp2 = threading.Thread(target = self.popupMessage.open)
# tp2.start()
------ 2. UPDATE --------------------------------------------------
After retesting the code without applying any changes, the following error appeared. Any suggestions about the cause?
Exception in thread Thread-22:
Traceback (most recent call last):
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 242, in create_handler
return eval(value, idmap), bound_list
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/data/style.kv", line 10, in <module>
pos: int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 923, in _build_canvas
key, value, prule, idmap, True)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 247, in create_handler
cause=tb)
kivy.lang.builder.BuilderException: Parser: File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/data/style.kv", line 10:
...
8: texture: self.texture
9: size: self.texture_size
>> 10: pos: int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.)
11:
12:<-Button,-ToggleButton>:
...
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 242, in create_handler
return eval(value, idmap), bound_list
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/data/style.kv", line 10, in <module>
pos: int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "main.py", line 1490, in avanti
self.step3() # call the activity popup method
File "main.py", line 1169, in step3
self.popupActivity = ActivityBox(self)
File "main.py", line 580, in __init__
super(ActivityBox, self).__init__(**kwargs)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/uix/modalview.py", line 186, in __init__
super(ModalView, self).__init__(**kwargs)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/uix/anchorlayout.py", line 68, in __init__
super(AnchorLayout, self).__init__(**kwargs)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/uix/layout.py", line 76, in __init__
super(Layout, self).__init__(**kwargs)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/uix/widget.py", line 361, in __init__
rule_children=rule_children)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/uix/widget.py", line 465, in apply_class_lang_rules
rule_children=rule_children)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 541, in apply
rule_children=rule_children)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 662, in _apply_rule
child, crule, rootrule, rule_children=rule_children)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 660, in _apply_rule
root=rctx['ids']['root'], rule_children=rule_children)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/uix/widget.py", line 465, in apply_class_lang_rules
rule_children=rule_children)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 541, in apply
rule_children=rule_children)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 599, in _apply_rule
rule.canvas_root, rootrule)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 929, in _build_canvas
'{}: {}'.format(e.__class__.__name__, e), cause=tb)
kivy.lang.builder.BuilderException: Parser: File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/data/style.kv", line 10:
...
8: texture: self.texture
9: size: self.texture_size
>> 10: pos: int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.)
11:
12:<-Button,-ToggleButton>:
...
BuilderException: Parser: File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/data/style.kv", line 10:
...
8: texture: self.texture
9: size: self.texture_size
>> 10: pos: int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.)
11:
12:<-Button,-ToggleButton>:
...
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 242, in create_handler
return eval(value, idmap), bound_list
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/data/style.kv", line 10, in <module>
pos: int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 923, in _build_canvas
key, value, prule, idmap, True)
File "/home/pi/.virtualenvs/py3/lib/python3.7/site-packages/kivy/lang/builder.py", line 247, in create_handler
cause=tb)
------ 3. UPDATE --------------------------------------------------
Unfortunately by enabling the hardware video acceleration in raspi-config
the issue is still present.
Before:
[INFO ] [GL ] Backend used <sdl2>
[INFO ] [GL ] OpenGL version <b'3.1 Mesa 19.3.2'>
[INFO ] [GL ] OpenGL vendor <b'VMware, Inc.'>
[INFO ] [GL ] OpenGL renderer <b'llvmpipe (LLVM 9.0.1, 128 bits)'>
[INFO ] [GL ] OpenGL parsed version: 3, 1
[INFO ] [GL ] Shading version <b'1.40'>
Now:
[INFO ] [GL ] Backend used <sdl2>
[INFO ] [GL ] OpenGL version <b'2.1 Mesa 19.3.2'>
[INFO ] [GL ] OpenGL vendor <b'Broadcom'>
[INFO ] [GL ] OpenGL renderer <b'V3D 4.2'>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b'1.20'>
------ 4th update --------------------------------------------------
The graphical error seems to be related to a layout problem [WARNING] <kivy.uix.gridlayout.GridLayout object at 0xae191bf0> have no cols or rows set, layout is not triggered.
I checked the solutions below for the GridLayout but I can not see how they relate to my problem as I use FloatLayout. Any ideas?