From 78ae037d9c9f74078d2d2d6573235c6bcef879df Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 23 Jan 2021 17:27:47 +0800 Subject: [PATCH] bugfix --- kivyblocks/message.py | 114 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 kivyblocks/message.py diff --git a/kivyblocks/message.py b/kivyblocks/message.py new file mode 100644 index 0000000..6ba52ce --- /dev/null +++ b/kivyblocks/message.py @@ -0,0 +1,114 @@ + +from kivy.factory import Factory +from kivy.uix.image import AsyncImage +from .utils import * +from .baseWidget import Modal, Text, HBox,VBox +from .toggleitems import PressableBox + +class Conform(Modal): + def __init__(self, title_icon=None, + title = None, + message = None, + conform_icon=None, + cancel_icon=None, + **kw): + Modal.__init__(self, **kw) + self.register_event_type('on_cancel') + self.register_event_type('on_conform') + self.auto_dismiss = False + b = VBox() + b1 = HBox(size_hint_y=None, height=CSize(1.4)) + b1.add_widget(AsyncImage(source=title_icon or \ + blockImage('question.png'), + size_hint=[None,None], + height=CSize(1.2), + width=CSize(1.2))) + b1.add_widget(Text(text=title or 'Conform', + font_size=CSize(1.2), + i18n=True, + wrap=True, + halign='left', + valign='center', + )) + b.add_widget(b1) + b.add_widget(Text(text=message or 'Please conform', + wrap=True, + halign='left', + font_size=CSize(1))) + b1 = HBox(size_hint_y=None, height=CSize(1.2)) + w_cancel = PressableBox() + blocks = Factory.Blocks() + w_cancel.add_widget(blocks.widgetBuild({ + "widgettype":"HBox", + "options":{}, + "subwidgets":[ + { + "widgettype":"AsyncImage", + "options":{ + "source":cancel_icon or blockImage('cancel.png'), + "size_hint":[None,None], + "height":CSize(1), + "width":CSize(1) + } + }, + { + "widgettype":"Text", + "options":{ + "text":'Cancel', + "wrap":True, + "font_size":CSize(1), + "halign":'left', + "i18n":True + } + } + ] + })) + w_conform = PressableBox() + blocks = Factory.Blocks() + w_conform.add_widget(blocks.widgetBuild({ + "widgettype":"HBox", + "options":{}, + "subwidgets":[ + { + "widgettype":"AsyncImage", + "options":{ + "source":cancel_icon or blockImage('conform.png'), + "size_hint":[None,None], + "height":CSize(1), + "width":CSize(1) + } + }, + { + "widgettype":"Text", + "options":{ + "text":'Conform', + "wrap":True, + "font_size":CSize(1), + "halign":'left', + "i18n":True + } + } + ] + })) + + w_cancel.bind(on_press=self.cancel_press) + w_conform.bind(on_press=self.conform_press) + + b1.add_widget(w_cancel) + b1.add_widget(w_conform) + b.add_widget(b1) + self.add_widget(b) + + def cancel_press(self,o, v=None): + self.dispatch('on_cancel') + + def conform_press(self, o, v=None): + self.dispatch('on_conform') + + def on_cancel(self): + self.dismiss() + + def on_conform(self): + self.dismiss() + +