From 2831aa6175a2e495efd14a3be63d381766ecda5a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 19 Sep 2021 19:17:08 +0800 Subject: [PATCH] bugfix --- kivyblocks/qrdata.py | 25 ++++++++++++++++++++----- kivyblocks/scrollpanel.py | 25 ++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/kivyblocks/qrdata.py b/kivyblocks/qrdata.py index be1195b..b005618 100644 --- a/kivyblocks/qrdata.py +++ b/kivyblocks/qrdata.py @@ -10,7 +10,7 @@ from kivy.uix.image import Image from kivy.graphics.texture import Texture from kivy.properties import StringProperty from kivy.properties import ObjectProperty, StringProperty, ListProperty,\ - BooleanProperty + BooleanProperty, NumericProperty from kivy.lang import Builder from kivy.clock import Clock @@ -32,6 +32,16 @@ class QRCodeWidget(VBox): defaulting to `'data/images/image-loading.gif'`. ''' + version = NumericProperty(40) + box_size = NumericProperty(20) + err_level = StringProperty('L') + border = NumericProperty(1) + error_correct_values = { + 'L':qrcode.constants.ERROR_CORRECT_L, + 'M':qrcode.constants.ERROR_CORRECT_M, + 'Q':qrcode.constants.ERROR_CORRECT_Q, + 'H':qrcode.constants.ERROR_CORRECT_H + } def __init__(self, **kwargs): self.qrimage = Image(allow_stretch=True, keep_ratio=True) self.addr = None @@ -72,12 +82,17 @@ class QRCodeWidget(VBox): QRCode = qrcode.QRCode L = qrcode.constants.ERROR_CORRECT_L addr = self.addr + print('self.box_size=', self.box_size) + errv = self.error_correct_values.get(self.err_level) + if not errv: + errv=self.error_corrent_values.get('L') + try: self.qr = qr = QRCode( - version=None, - error_correction=L, - box_size=10, - border=4, + version=self.version, + error_correction=errv, + box_size=self.box_size, + border=self.border, ) qr.add_data(addr) qr.make(fit=True) diff --git a/kivyblocks/scrollpanel.py b/kivyblocks/scrollpanel.py index 3c7a72c..a751734 100644 --- a/kivyblocks/scrollpanel.py +++ b/kivyblocks/scrollpanel.py @@ -1,26 +1,45 @@ - +from kivy.properties import NumericProperty, StringProperty from kivy.uix.scrollview import ScrollView from kivy.effects.scroll import ScrollEffect from kivy.uix.widget import Widget from kivy.uix.boxlayout import BoxLayout from kivy.factory import Factory +from kivyblocks.utils import * + class ScrollPanel(ScrollView): + x_padding_c = NumericProperty(0) + y_padding_c = NumericProperty(0) + bg_color = ListProperty(0.2, 0.2, 0.2, 1) + orient = StringProperty('H') + def __init__(self,inner=None, **kw): - print('ScrollPanel(): kw=', kw) super(ScrollPanel,self).__init__() self.effect_cls = ScrollEffect if not inner: kw.update({ 'size_hint':(None,None), + 'bg_color':self.bg_color, 'orientation':'vertical' }) - self._inner = BoxLayout(**kw) + desc = { + "widgettype":"Box", + "options":kw + } + self._inner = Factory.Blocks().widgetBuild(desc) elif isinstance(inner, Widget): self._inner = inner else: self._inner = Factory.Blocks().widgetBuild(inner) + if isinstance(self._inner, BoxLayout): + if self.orient.upper() == 'H': + self._inner.orientation = 'horizontal' + else: + self._inner.orientation = 'vertical' + self.padding = self.spacing = \ + [CSize(self.x_padding_c), CSize(self.y_padding_c)] + self._inner.bind( minimum_height=self._inner.setter('height')) self._inner.bind(