问题
I'm working on a bus driver app. Once in a while, there are messages published on a MQTT topic which the app is subscribed to (by a server). When such message comes, a popup must appear. I customized the default Kivy popup: changed the background, added as the content a FloatLayout with a Lable and a Button.
The problem is that once in several cases (5-6) the texture elements of the popup jumps away, like the background, or the Label text, or the button's image.
Here is the Kivy definition of my Popup class:
<BktsPopup@Popup>:
title: 'Alert message'
title_align: 'center'
title_size: 25
size_hint: (0.6, 0.6)
# size: (400, 300)
auto_dismiss: False
separator_height: 0
message: popup_msg
border: (14, 14, 14, 14)
FloatLayout:
BktsLabel:
id: popup_msg
font_size: 20
size_hint_y: 0.7
pos_hint: {'center_x': 0.5, 'y': 0.5}
# size_hint_y: 60
BktsButton:
id: ok_btn
background_normal: 'res/btn_released_gray.png'
background_down: 'res/btn_pressed_gray.png'
size_hint_x: 0.4
size_hint_y: 0.3
pos_hint: {'center_x': 0.5, 'y': 0.1}
text: 'OK'
font_size: 25
on_press: root.dismiss()
Here is the python class:
class BktsPopup(Popup):
popup_back_color = ListProperty([])
message = ObjectProperty()
def __init__(self, text, title, level):
Popup.__init__(self)
self.title = title
self.message.text = text
if level is LEVEL_NORMAL:
self.background = 'res/popup_back_green.png'
elif level is LEVEL_URGENT:
self.background = 'res/popup_back_red.png'
Here's how the popup is being opened:
def on_dispatcher_message(self, level, text):
popup = BktsPopup(text, 'Dispatcher', level)
popup.bind(on_dismiss=self.send_message_ack)
popup.open()
self.store_event(text)
Here's the normal appearance of the popup:
Here's a texture-anomaly case:
Sometimes, the whole background jumps and appears in the left-bottom corner. Any ideas why?
来源:https://stackoverflow.com/questions/38183393/kivy-popup-rendering-issue