我正在开发一个公交车司机应用程序。偶尔,应用程序(通过服务器)订阅的 MQTT 主题上会发布消息。当出现此类消息时,必须出现弹出窗口。我定制了默认的 Kivy 弹出窗口:更改了背景,添加了带有标签和按钮的 FloatLayout 作为内容。
问题是,在某些情况下 (5-6),弹出窗口的纹理元素会跳开,例如背景、标签文本或按钮的图像。
这是我的 Popup 类的 Kivy 定义:
<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()
这是 python 类:
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'
弹出窗口的打开方式如下:
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:
有时,整个背景会跳跃并出现在左下角。
有什么想法吗?