This commit is contained in:
yumoqing 2021-09-19 19:17:08 +08:00
parent d807cb11e3
commit 2831aa6175
2 changed files with 42 additions and 8 deletions

View File

@ -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)

View File

@ -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(