This commit is contained in:
yumoqing 2021-03-15 08:24:26 +08:00
parent e85b2cfc4f
commit d2e9358624

View File

@ -2,15 +2,15 @@ from kivy.uix.popup import Popup
from kivy.clock import Clock from kivy.clock import Clock
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput from kivy.uix.textinput import TextInput
from appPublic.Singleton import SingletonDecorator
@SingletonDecorator
class Messager: class Messager:
def __init__(self, show_time=0): def __init__(self, show_time=0, title=None):
self.show_time = show_time self.show_time = show_time
self.title = title if title else 'Message'
self.time_task = None self.time_task = None
self.w = Popup(content=BoxLayout(orientation='vertical'), self.w = Popup(content=BoxLayout(orientation='vertical'),
title="Error info",size_hint=(0.8,0.8)) title=self.title,
size_hint=(0.8,0.8))
self.messager = TextInput(size=self.w.content.size, self.messager = TextInput(size=self.w.content.size,
multiline=True,readonly=True) multiline=True,readonly=True)
self.w.content.add_widget(self.messager) self.w.content.add_widget(self.messager)
@ -20,14 +20,15 @@ class Messager:
self.time_task = Clock.schedule_once(self.hide, self.time_task = Clock.schedule_once(self.hide,
self.show_time) self.show_time)
def show_error(self,e): def show_error(self,e):
self.w.title = "error" self.messager.text = '%s[error]%s\n' % (self.messager.text,str(e))
self.messager.text = str(e)
self.w.open() self.w.open()
self.set_time_task() self.set_time_task()
def clear_messages(self):
self.messager.text = ''
def show_info(self,info): def show_info(self,info):
self.w.title = "info" self.messager.text = '%s[info]%s\n' % (self.messager.text, info)
self.messager.text = str(info)
self.w.open() self.w.open()
self.set_time_task() self.set_time_task()