From eedef483aa816f77aa419503c9e6c694d314ffd6 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 22 Mar 2021 00:37:42 +0800 Subject: [PATCH] bugfix --- docs/cn/intro.md | 14 ++++ kivyblocks/widgetExt/inputext.py | 11 ++- kivyblocks/widget_css.py | 122 +++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 kivyblocks/widget_css.py diff --git a/docs/cn/intro.md b/docs/cn/intro.md index 8bc4a9f..b931b1c 100644 --- a/docs/cn/intro.md +++ b/docs/cn/intro.md @@ -1,2 +1,16 @@ # kivyblocks简介 +kivyblocks是一个基于kivy的python GUI开发工具,得益于kivy的跨平台特性, kivyblocks可以支持Windows,Linux,macosx, iPhone,android, 以及X霉 + + +## kivyblocks的目标 +降低前端原生应用开发的复杂度,提高原生应用系统的开发和运维效率。 + +## kivyblocks的原理 +逻辑 + 数据 = 程序 + +相信程序员都了解上述等式,kviyblocks将复杂的业务逻辑封装在底层的构件库中,而将标准的数据接口提供给程序员,程序员不需要编写逻辑代码 + +程序要要创建一个显示构件,只需要按照[构件数据格式](./cdf.md)的要求填写字典数据即可 + + diff --git a/kivyblocks/widgetExt/inputext.py b/kivyblocks/widgetExt/inputext.py index 56f1c2a..777b614 100755 --- a/kivyblocks/widgetExt/inputext.py +++ b/kivyblocks/widgetExt/inputext.py @@ -9,7 +9,7 @@ from kivy.uix.dropdown import DropDown from kivy.uix.switch import Switch from kivy.metrics import sp,dp from kivy.app import App -from kivy.properties import BooleanProperty +from kivy.properties import BooleanProperty, ListProperty from ..threadcall import HttpClient from ..utils import CSize @@ -41,6 +41,15 @@ class BoolInput(Switch): self.active = v class StrInput(TextInput): + bgcolor = ListProperty(None) + fgcolor = ListProperty(None) + + def on_bgcolor(self, o, bgcolor): + self.background_color = bgcolor + + def on_fgcolor(self, o, fgcolor): + self.foreground_color = fgcolor + def __init__(self,**kv): if kv is None: kv = {} diff --git a/kivyblocks/widget_css.py b/kivyblocks/widget_css.py new file mode 100644 index 0000000..7773624 --- /dev/null +++ b/kivyblocks/widget_css.py @@ -0,0 +1,122 @@ +from kivy.properties import NumericProperty, ListProperty, StringProperty +from kivy.graphics import Color, Rectangle, RoundedRectangle +from kivy.uix.textinput import TextInput +from kivy.uix.button import Button +from kivy.uix.label import Label +from kivyblocks.utils import CSize + +kivyblocks_css_keys = [ + "height_nm", + "width_nm", + "height_cm", + "width_cm", + "bgcolor", + "fgcolor", + "radius", + "spacing", + "padding", + "border" +] + +kivyblocks_csses = { + "default":{ + }, +} + +class WidgetCSS(object): + height_nm = NumericProperty(None) + width_nm = NumericProperty(None) + height_cm = NumericProperty(None) + width_cm = NumericProperty(None) + bgcolor = ListProperty(None) + fgcolor = ListProperty(None) + csscls = StringProperty(None) + radius = ListProperty(None) + + def on_height_nm(self, o, v): + if not self.height_nm: + return + if self.height_nm <= 1: + self.size_hint_y = self.height_nm + else: + self.size_hint_y = None + self.height = height_nm + + def on_width_nm(self, o, v): + if not self.width_nm: + return + if self.width_nm <= 1: + self.size_hint_x = self.width_nm + else: + self.size_hint_x = None + self.width = self.width_nm + + def on_csscls(self, o, csscls): + if isinstance(self.csscls, str): + self.set_css(sef.csscls) + + def _get_css_dict_by_name(self, css_name): + dic = kivyblocks_csses.get(css_name,{}) + return dic + + def set_css(self, css_str): + css = {} + for css_name in css_str.split(' '): + css.update(self._get_css_dict_by_name(css_name)) + for k,v in css.items(): + setattr(self,k,v) + + def on_height_cm(self, o, c): + if not height_cm: + return + self.size_hint_y = None + self.height = CSize(self.height_cm) + + def on_width_cm(self, o, c): + if not width_cm: + return + self.size_hint_x = None + self.width = CSize(self.width_cm) + + def on_fgcolor(self, o, c): + if not self.fgcolor: + return + if isinstance(self, TextInput): + self.foreground_color = fgcolor + if isinstance(self, Label): + self.color = fgcolor + return + return + + def on_bgcolor(self, o, c): + if not self.bgcolor: + return + if isinstance(self, TextInput): + self.background_color = bgcolor + return + if isinstance(self, Button): + self.background_color = bgcolor + return + self.set_background_color() + + def on_radius(self, o, r): + if not radius: + return + self.set_background_color() + + def set_background_color(self, *args): + if not self.bgcolor: + return + if not self.canvas: + return + + with self.canvas.before: + Color(*self.bgcolor) + if self.radius and len(self.radius) == 4: + self.background_rect = RoundedRectangle(pos=self.pos, + size=self.size, + radius=self.radius) + else: + self.background_rect = Rectangle(pos=self.pos, + size=self.size) +