This commit is contained in:
yumoqing 2020-04-02 13:18:10 +08:00
parent ab79735f7f
commit 211fee42ec
12 changed files with 327 additions and 397 deletions

View File

@ -55,6 +55,7 @@ from .widgetExt.inputext import FloatInput,IntegerInput, \
StrInput,SelectInput, BoolInput, AmountInput
from .widgetExt.messager import Messager
from .charts.bar import Bar
from .bgcolorbehavior import BGColorBehavior
if platform == 'android':
from .widgetExt.phonebutton import PhoneButton
@ -64,28 +65,17 @@ class PressableImage(ButtonBehavior,AsyncImage):
def on_press(self):
pass
class PressableLabel(ButtonBehavior, Label):
def on_press(self):
pass
class Text(Label):
bgColor = ListProperty([0.5,0.5,0.5,1])
def __init__(self,**kw):
class Text(BGColorBehavior, Label):
def __init__(self,bgcolor=[0,0,0,1],**kw):
self.options = DictObject(**kw)
kwargs = kw.copy()
self.bind(pos=self._update,size=self._update)
if kwargs.get('bgColor'):
self.bgColor = kwargs['bgColor']
del kwargs['bgColor']
super().__init__(**kwargs)
self.bind(pos=self.sizeChange,size=self.sizeChange)
Label.__init__(self,**kwargs)
BGColorBehavior.__init__(self,bgcolor=bgcolor)
def _update(self,t,v):
self.pos = t.pos
self.size = t.size
class PressableLabel(ButtonBehavior, Text):
def on_press(self):
pass
def sizeChange(self,o,t=None):
self.canvas.before.clear()
with self.canvas.before:
Color(*self.bgColor)
Rectangle(pos=self.pos,size=self.size)

View File

@ -0,0 +1,27 @@
from kivy.logger import Logger
from kivy.graphics import Color, Rectangle
from kivy.properties import ListProperty
_logcnt = 0
class BGColorBehavior(object):
bgcolor = ListProperty([])
def __init__(self, bgcolor=[1,0,0,1],**kwargs):
self.bgcolor = bgcolor
self.bind(size=self.on_bgcolor,pos=self.on_bgcolor)
def on_bgcolor(self,o=None,v=None):
global _logcnt
Logger.info('bgcolorBehavior: on_bgcolor(),o=%s,v=%s,logcnt=%d',\
o.text if hasattr(o,'text') else o,v,_logcnt)
_logcnt += 1
x = abs(self.size[0] - 100.0)
y = abs(self.size[1] - 100.0)
if self.size[0] < 0.0001 or self.size[1] < 0.0001:
return
if x < 0.0001 and y < 0.0001:
return
if self.canvas:
with self.canvas.before:
Color(*self.bgcolor)
Rectangle(pos=self.pos, size=self.size)

View File

@ -93,7 +93,7 @@ def closeWorkers():
def appBlocksHack(app):
config = getConfig()
app.on_close = on_close
# app.on_close = on_close
app.getAuthHeader = getAuthHeader
app.__del__ = closeWorkers
Window.bind(on_request_close=app.on_close)

View File

@ -1,4 +1,6 @@
from kivy.logger import logging
from kivy.logger import Logger
from .colorcalc import *
from appPublic.jsonConfig import getConfig
colors = {
'Red': {
@ -343,337 +345,64 @@ light_colors = {
'Light': ['White', 'MainBackground', 'DialogBackground']
}
text_colors = {
'Red': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': 'ffffff',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': 'ffffff',
'A400': 'ffffff',
'A700': 'ffffff',
},
'Pink': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': 'ffffff',
'400': 'ffffff',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': 'ffffff',
'A400': 'ffffff',
'A700': 'ffffff',
},
'Purple': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': 'ffffff',
'400': 'ffffff',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': 'ffffff',
'A400': 'ffffff',
'A700': 'ffffff',
},
'DeepPurple': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': 'ffffff',
'400': 'ffffff',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': 'ffffff',
'A400': 'ffffff',
'A700': 'ffffff',
},
'Indigo': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': 'ffffff',
'400': 'ffffff',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': 'ffffff',
'A400': 'ffffff',
'A700': 'ffffff',
},
'Blue': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': 'ffffff',
'A400': 'ffffff',
'A700': 'ffffff',
},
'LightBlue': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': 'ffffff',
},
'Cyan': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': '000000',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'Teal': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'Green': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'LightGreen': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': '000000',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'Lime': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': '000000',
'700': '000000',
'800': '000000',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'Yellow': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': '000000',
'700': '000000',
'800': '000000',
'900': '000000',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'Amber': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': '000000',
'700': '000000',
'800': '000000',
'900': '000000',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'Orange': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': '000000',
'700': '000000',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': '000000',
'A700': '000000',
},
'DeepOrange': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
'A100': '000000',
'A200': '000000',
'A400': 'ffffff',
'A700': 'ffffff',
},
'Brown': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': 'ffffff',
'400': 'ffffff',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
},
'Grey': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': '000000',
'500': '000000',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
},
'BlueGrey': {
'50': '000000',
'100': '000000',
'200': '000000',
'300': '000000',
'400': 'ffffff',
'500': 'ffffff',
'600': 'ffffff',
'700': 'ffffff',
'800': 'ffffff',
'900': 'ffffff',
},
}
level_bg_colors = [
'900',
'800',
'700',
'600',
]
level_selected_bg_colors = [
'500',
'400',
'300',
'200'
'200',
'100',
'50'
]
def getColors(style,level=0):
i = level % len(level_bg_colors)
logging.info('TEST : style=%s,level=%d', style, level)
text_color = text_colors[style][ level_bg_colors[i]]
bg_color = colors[style][ level_bg_colors[i]]
return text_color,bg_color
text_colors = {
'normal':['eeeeee','111111'],
'highlight':['ffffff','000000']
}
def getSelectedColors(style,level=0):
i = level % len(level_selected_bg_colors)
text_color = text_colors[style][ level_selected_bg_colors[i]]
bg_color = colors[style][ level_selected_bg_colors[i]]
return text_color, bg_color
def getConfigStyle():
config = getConfig()
stype = config.color_style or 'Blue'
return stype
def getTextColor(bgcolor,type='normal'):
colors = text_colors.get(type,text_colors.get('normal'))
d = 0
tcolor = None
for c in colors:
d1 = distance(bgcolor,c)
if d1>d:
d = d1
tcolor = c
return tcolor
def getColors(level=0,selected=False):
style = getConfigStyle()
i = level % 8
Logger.info('TEST : style=%s,level=%d', style, level)
bg_color = colors[style][ level_bg_colors[i]]
if selected:
k = level_bg_colors[i]
k1 = level_bg_colors[i+1]
colors1 = divideColor(colors[style][k],colors[style][k1],2)
bg_color = colors1[1]
text_color = getTextColor(bg_color)
return toArrayColor(text_color),toArrayColor(bg_color)
error_color_id = '100',
info_color_id = '50'
def getErrorColors(style):
text_color = text_colors[style][ error_color_id ]
def getErrorColors():
style = getConfigStyle()
bg_color = colors[style][ error_color_id ]
return text_color, bg_color
text_color = getTextColor(bg_color,type='highlight')
return toArrayColor(text_color),toArrayColor(bg_color)
def getInfoColors(style):
text_color = text_colors[style][ info_color_id ]
def getInfoColors():
style = getConfigStyle()
bg_color = colors[style][ info_color_id ]
return text_color, bg_color
text_color = getTextColor(bg_color)
return toArrayColor(text_color),toArrayColor(bg_color)

View File

@ -1,8 +1,8 @@
from kivy.utils import get_color_from_hex
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Rectangle, Ellipse
from kivy.uix.boxlayout import BoxLayout
#from kivy.app import App
#from kivy.uix.widget import Widget
#from kivy.graphics import Color, Rectangle, Ellipse
#from kivy.uix.boxlayout import BoxLayout
import math
def toArrayColor(color):

View File

@ -1,3 +1,4 @@
from kivy.logger import Logger
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
@ -10,6 +11,9 @@ from .baseWidget import *
from .utils import *
from .i18n import I18nText, I18n
from .toolbar import Toolbar
from .color_definitions import getColors
from .bgcolorbehavior import BGColorBehavior
"""
form options
{
@ -120,16 +124,17 @@ class InputBox(BoxLayout):
self.bind(on_size=self.setSize,
pos=self.setSize)
self.register_event_type("on_datainput")
self.register_event_type("on_ready")
def on_datainput(self,o,v=None):
print('on_datainput fired ...',o,v)
def init(self):
i18n = I18n()
if self.initflag:
return
i18n = I18n()
opts = {
"orientation":"vertical",
"orientation":"horizontal",
"size_hint_y":None,
"height":CSize(3)
}
@ -139,6 +144,8 @@ class InputBox(BoxLayout):
opts['size_hint_x'] = None
opts['width'] = self.labelwidth
bl = BoxLayout(**opts)
Logger.info('kivyblock:labelwidth=%f,opts=%s', self.labelwidth,str(opts))
Logger.info('kivyblock:bl.widht=%f,bl.height=%f',bl.width,bl.height)
self.add_widget(bl)
label = self.options.get('label',self.options.get('name'))
kwargs = {
@ -151,6 +158,8 @@ class InputBox(BoxLayout):
}
self.labeltext = I18nText(**kwargs)
bl.add_widget(self.labeltext)
Logger.info('kivyblock:label.widht=%f,label.height=%f',
self.labeltext.width,self.labeltext.height)
if self.options.get('required',False):
star = Label(text='*',
color=(1,0,0,1),
@ -173,6 +182,21 @@ class InputBox(BoxLayout):
self.initflag = True
self.input_widget.bind(on_focus=self.on_focus)
self.input_widget.setValue(self.options.get('default',''))
self.dispatch('on_ready', self)
def check(self):
d = self.getValue()
v = d.get(self.options.get('name'))
Logger.info('InputWidget() getValue=%s, name=%s',
v,self.options.get('name'))
if self.options.get('required',False) and \
(v == '' or v is None):
return False
return True
def on_ready(self, obj):
Logger.info('kivyblocks: Form input ready')
def clear(self):
self.input_widget.setValue('')
@ -195,8 +219,8 @@ class InputBox(BoxLayout):
def defaultToolbar():
return {
"img_size":1.5,
"text_size":0.7,
"img_size":2,
"text_size":1,
"tools":[
{
"name":"__submit",
@ -212,11 +236,15 @@ def defaultToolbar():
}
class Form(BoxLayout):
class Form(BGColorBehavior, BoxLayout):
def __init__(self, **options):
self.options = options
BoxLayout.__init__(self, orientation='vertical')
self.color_level = self.options.get('color_level', 0)
textcolor, bgcolor = getColors(self.color_level)
BGColorBehavior.__init__(self,bgcolor=bgcolor)
self.widget_ids = {}
self.readiedInput = 0
self.cols = self.options_cols = self.options.get('cols',1)
if isHandHold() and Window.width < Window.height:
self.cols = 1
@ -239,11 +267,11 @@ class Form(BoxLayout):
self.add_widget(self.toolbar)
self.add_widget(self.fsc)
self.fieldWidgets=[]
previous_w = None
for f in self.options['fields']:
w = InputBox(self, **f)
self.fsc.add_widget(w)
self.fieldWidgets.append(w)
w.bind(on_ready=self.makeInputLink)
blocks = App.get_running_app().blocks
# wid = self.widget_ids['__submit']
wid = blocks.getWidgetByIdPath(self,'__submit')
@ -253,6 +281,15 @@ class Form(BoxLayout):
wid.bind(on_press=self.on_clear_button)
self.initflag = True
def makeInputLink(self,o,v=None):
self.readiedInput += 1
if self.readiedInput >= len(self.options['fields']):
p = self.fieldWidgets[0]
for w in self.fieldWidgets[1:]:
p.input_widget.focus_next = w.input_widget
w.input_widget.focus_previous = p.input_widget
p = w
def getData(self):
d = {}
for f in self.fieldWidgets:
@ -260,12 +297,26 @@ class Form(BoxLayout):
d.update(v)
return d
def checkData(self):
for w in self.fieldWidgets:
if not w.check():
w.input_widget.focus = True
Logger.info('kivyblcks: input check false')
return False
Logger.info('kivyblcks: input check success')
return True
def on_submit(self,v=None):
print('Form():on_submit fired ...',v)
return False
def on_submit_button(self,o,v=None):
Logger.info('kivyblcks: submit button press')
if not self.checkData():
Logger.info('kivyblocks: CheckData False')
return
d = self.getData()
Logger.info('kivyblocks: fire on_submit')
self.dispatch('on_submit',d)
def on_clear_button(self,o,v=None):
@ -274,19 +325,20 @@ class Form(BoxLayout):
def on_size(self,o, v=None):
self.init()
textcolor, self.bgcolor = getColors(self.color_level)
class StrSearchForm(BoxLayout):
def __init__(self,img_url=None,**options):
self.name = options.get('name','search_string')
BoxLayout.__init__(self,orientation='horizontal',size_hint_y=None,height=CSize(3))
self.inputwidget = TextInput(
self.input_widget = TextInput(
text='',
multiline=False,
allow_copy=True,
font_size=CSize(1),
size_hint_y=None,
height=CSize(3))
self.add_widget(self.inputwidget)
self.add_widget(self.input_widget)
imgsrc = img_url if img_url else blockImage('search.png')
self.search = PressableImage(source=imgsrc,
size_hint=(None,None),
@ -295,16 +347,16 @@ class StrSearchForm(BoxLayout):
self.add_widget(self.search)
self.register_event_type('on_submit')
self.search.bind(on_press=self.submit_input)
self.inputwidget.bind(on_text_validate=self.submit_input)
self.input_widget.bind(on_text_validate=self.submit_input)
def getData(self):
d = {
self.name:self.inputwidget.text
self.name:self.input_widget.text
}
return d
def submit_input(self,o,v=None):
text = self.inputwidget.text
text = self.input_widget.text
if text != '':
d = {
self.name:text

BIN
kivyblocks/imgs/menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,78 @@
from kivymd.bottomsheet import MDListBottomSheet, MDGridBottomSheet
from kivymd.button import MDIconButton
from kivymd.date_picker import MDDatePicker
from kivymd.dialog import MDDialog
from kivymd.label import MDLabel
from kivymd.list import ILeftBody, ILeftBodyTouch, \
IRightBodyTouch, BaseListItem
from kivymd.material_resources import DEVICE_TYPE
from kivymd.navigationdrawer import MDNavigationDrawer, NavigationDrawerHeaderBase
from kivymd.navigationdrawer import NavigationLayout
from kivymd.navigationdrawer import NavigationDrawerDivider
from kivymd.navigationdrawer import NavigationDrawerToolbar
from kivymd.navigationdrawer import NavigationDrawerSubheader
from kivymd.selectioncontrols import MDSwitch
from kivymd.selectioncontrols import MDCheckbox
from kivymd.snackbar import Snackbar
from kivymd.theming import ThemeManager
from kivymd.time_picker import MDTimePicker
from kivymd.toolbar import Toolbar
from kivymd.list import MDList
from kivymd.textfields import MDTextField
from kivymd.spinner import MDSpinner
from kivymd.card import MDCard
from kivymd.card import MDSeparator
from kivymd.menu import MDDropdownMenu
from kivymd.grid import SmartTile
from kivymd.slider import MDSlider
from kivymd.tabs import MDTabbedPanel, MDTab, MDBottomNavigation, \
MDBottomNavigationItem
from kivymd.progressbar import MDProgressBar
from kivymd.accordion import MDAccordion, MDAccordionItem
from kivymd.theme_picker import MDThemePicker
from kivyblocks.blocks import registerWidget
class TabbedPannel(MDTabbedPanel):
def __init__(self,**options):
def kivyMDPlugin():
registerWidget('MDSlider',MDSlider)
registerWidget('MDTabbedPanel',MDTabbedPanel)
registerWidget('MDTab',MDTab)
registerWidget('MDBottomNavigation',MDBottomNavigation)
registerWidget('MDBottomNavigationItem',MDBottomNavigationItem)
registerWidget('MDProgressBar',MDProgressBar)
registerWidget('MDAccordion',MDAccordion)
registerWidget('MDAccordionItem',MDAccordionItem)
registerWidget('MDThemePicker',MDThemePicker)
registerWidget('MDListBottomSheet',MDListBottomSheet)
registerWidget('MDGridBottomSheet',MDGridBottomSheet)
registerWidget('MDIconButton', MDIconButton)
registerWidget('MDDatePicker', MDDatePicker)
registerWidget('MDDialog', MDDialog)
registerWidget('MDLabel', MDLabel)
registerWidget('ILeftBody',ILeftBody)
registerWidget('ILeftBodyTouch',ILeftBodyTouch)
registerWidget('IRightBodyTouch',IRightBodyTouch)
registerWidget('BaseListItem',BaseListItem)
registerWidget('MDNavigationDrawer',MDNavigationDrawer)
registerWidget('NavigationDrawerHeaderBase',NavigationDrawerHeaderBase)
registerWidget('MDCheckbox',MDCheckbox)
registerWidget('Snackbar',Snackbar)
registerWidget('ThemeManager',ThemeManager)
registerWidget('MDTimePicker',MDTimePicker)
registerWidget('Toolbar',Toolbar)
registerWidget('NavigationLayout',NavigationLayout)
registerWidget('NavigationDrawerDivider',NavigationDrawerDivider)
registerWidget('NavigationDrawerToolbar',NavigationDrawerToolbar)
registerWidget('NavigationDrawerSubheader',NavigationDrawerSubheader)
registerWidget('MDSwitch',MDSwitch)
registerWidget('MDList',MDList)
registerWidget('MDTextField',MDTextField)
registerWidget('MDSpinner',MDSpinner)
registerWidget('MDCard',MDCard)
registerWidget('MDSeparator',MDSeparator)
registerWidget('SmartTile',SmartTile)

View File

@ -1,3 +1,4 @@
from kivy.logger import Logger
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.popup import Popup
@ -45,7 +46,10 @@ class LoginForm(Popup):
print('build Content ....... ....')
self.initflag = True
app = App.get_running_app()
self.content = app.blocks.widgetBuild(logformdesc)
try:
self.content = app.blocks.widgetBuild(logformdesc)
except Exception as e:
Logger.info('login: Error %s', e)
self.content.bind(on_submit=self.on_submit)
def on_submit(self,o,userinfo):

View File

@ -1,3 +1,4 @@
from kivy.logger import Logger
from kivy.graphics import Color, Rectangle
from kivy.uix.button import ButtonBehavior
from kivy.uix.image import AsyncImage
@ -11,14 +12,16 @@ from appPublic.dictObject import DictObject
from .widgetExt.scrollwidget import ScrollWidget
from .utils import *
from .kivysize import KivySizes
from .ready import WidgetReady
from .i18n import I18nText
from .color_definitions import getColors
from .bgcolorbehavior import BGColorBehavior
"""
toobar={
"mode":"icon", "icontext","text"
img_size=1.5,
text_size=0.7,
img_size=2,
text_size=1,
"tools":[
]
}
@ -30,49 +33,62 @@ tool options
img=''
}
"""
class Tool(ButtonBehavior, WidgetReady,BoxLayout):
normal_bgColor=[0.1,0,0,1]
active_bgColor=[0.4,0.4,0.4,1]
class Tool(ButtonBehavior, BGColorBehavior, BoxLayout):
def __init__(self,ancestor=None,**opts):
if ancestor is None:
ancestor = App.get_running_app().root
ancestor.widget_ids[opts['name']] = self
self.ancestor = ancestor
ButtonBehavior.__init__(self)
bc = opts.get('bg_color',self.normal_bgColor)
WidgetReady.__init__(self,bg_color=self.normal_bgColor)
BoxLayout.__init__(self,
orientation='vertical',size_hint=(None,None))
size_hint_y=None)
BGColorBehavior.__init__(self)
self.bl = BoxLayout(orientation='vertical',
size_hint_y=None)
self.add_widget(self.bl)
self.opts = DictObject(**opts)
if not self.opts.img_size:
self.opts.img_size = 2
if not self.opts.text_size:
self.opts.text_size = 0.7
self.opts.text_size = 1
app = App.get_running_app()
ks = KivySizes()
size = ks.unitedSize(self.opts.img_size or 2)
img = AsyncImage(source=self.opts.img_src,size_hint=(None,None),
size=(size,size))
tsize = ks.unitedSize(self.opts.text_size)
size = 0
if self.opts.img_src:
size = CSize(self.opts.img_size or 2)
img = AsyncImage(source=self.opts.img_src,
size_hint=(None,None),
size=(size,size))
self.bl.add_widget(img)
tsize = CSize(self.opts.text_size)
label = self.opts.label or self.opts.name
lbl = I18nText(otext=label,font_size=int(tsize))
lbl.text_size = (size, 1.3 * tsize)
self.add_widget(img)
self.add_widget(lbl)
self.size = (size * 1.1, (size + 2 * tsize)*1.1)
self.lbl = I18nText(otext=label,
font_size=int(tsize),
text_size=(CSize(len(label)), tsize),
height=tsize,
width=CSize(len(label)),
size_hint=(None,None),
)
self.bl.add_widget(self.lbl)
self.height = (size + tsize)*1.1
self.lbl.color, self.bgcolor = getColors(self.ancestor.color_level,
selected=False)
self.lbl.bgcolor = self.bgcolor
def on_size(self,obj,size):
if self.parent:
print('********center*dd**********')
self.center = self.parent.center
Logger.info('toolbar: Tool() on_size fired')
self.lbl.color, self.bgcolor = getColors(self.ancestor.color_level,
selected=False)
self.lbl.bgcolor = self.bgcolor
def on_press(self):
print('Tool(). pressed ...............')
def setActive(self,flag):
if flag:
self.setBackgroundColor(self.active_bgColor)
else:
self.setBackgroundColor(self.normal_bgColor)
text_color, self.bgcolor = getColors(self.ancestor.color_level,
selected=flag)
self.lbl.bgcolor = self.bgcolor
self.lbl.color = text_color
"""
@ -100,10 +116,11 @@ class Toolbar(GridLayout):
for opt in self.opts.tools:
opt.img_size = self.opts.img_size
opt.text_size = self.opts.text_size
purl = None
if ancestor and hasattr(ancestor, 'parenturl'):
purl = ancestor.parenturl
opt.img_src = absurl(opt.img_src,purl)
if opt.img_src:
purl = None
if ancestor and hasattr(ancestor, 'parenturl'):
purl = ancestor.parenturl
opt.img_src = absurl(opt.img_src,purl)
tool = Tool(ancestor=ancestor, **opt)
if first:
first = False
@ -119,12 +136,12 @@ class Toolbar(GridLayout):
self.height = tool.height * 1.1
def on_size(self,obj,size):
return
with self.canvas.before:
Color(0.3,0.3,0.3,1)
Rectangle(pos=self.pos,size=self.size)
def tool_press(self,o,v=None):
o.background_color = [0.3,1,1,0.5]
for n,w in self.tool_widgets.items():
active = False
if w == o:
@ -137,6 +154,7 @@ Toolpage options
img_size=1.5,
text_size=0.7,
tool_at:"left","right","top","bottom",
color_level=0,
tools:[
{
"name":"myid",
@ -148,7 +166,7 @@ Toolpage options
]
"""
class ToolPage(BoxLayout):
class ToolPage(BGColorBehavior, BoxLayout):
def __init__(self,**opts):
self.opts = DictObject(**opts)
self.parenturl = opts.get('parenturl',None)
@ -158,7 +176,8 @@ class ToolPage(BoxLayout):
else:
orient = 'horizontal'
super().__init__(orientation=orient)
BoxLayout.__init__(self,orientation=orient)
BGColorBehavior.__init__(self)
self.content = None
self.toolbar = None
self.init()
@ -171,6 +190,7 @@ class ToolPage(BoxLayout):
self.toolbar.width = x
self.content.width = x
self.content.height = y - self.toolbar.height
self.color, self.bgcolor = getColors(self.color_level)
def showPage(self,obj):
self._show_page(obj.opts)
@ -191,6 +211,8 @@ class ToolPage(BoxLayout):
t.img_src = absurl(t.img_src,parenturl)
opts = self.opts
self.color_level = self.opts.color_level or 0
self.color, self.bgcolor = getColors(self.color_level)
self.toolbar = Toolbar(ancestor=self, **self.opts)
if self.opts.tool_at in ['top','left']:
self.add_widget(self.toolbar)
@ -198,7 +220,7 @@ class ToolPage(BoxLayout):
else:
self.add_widget(self.content)
self.add_widget(self.toolbar)
Clock.schedule_once(self.show_firstpage,0.5)
# Clock.schedule_once(self.show_firstpage,0.5)
if __name__ == '__main__':
from blocksapp import BlocksApp

View File

@ -9,7 +9,8 @@ from kivyblocks.widgetExt import ScrollWidget
from kivyblocks.utils import CSize
from appPublic.dictObject import DictObject
from .baseWidget import PressableLabel
from .stylebehavior import StyleBehavior
from .color_definitions import getColors
from .bgcolorbehavior import BGColorBehavior
class EmptyBox(Label):
def __init__(self,size_cnt=1):
@ -202,6 +203,7 @@ tree options
"url":
"params",
"bg_color",
"color_level",
"color",
"checkbox",
"multplecheck",
@ -210,12 +212,11 @@ tree options
"data" # array of {children:{},...}
}
"""
# class Tree(StyleBehavior,ScrollWidget):
class Tree(ScrollWidget):
class Tree(BGColorBehavior, ScrollWidget):
def __init__(self,**options):
self.color_level = options.get('color_level',0)
ScrollWidget.__init__(self)
level = options.get('level',0)
# StyleBehavior.__init__(self,level=level)
BGColorBehavior.__init__(self)
self.options = DictObject(**options)
self.nodes = []
self.initflag = False
@ -262,7 +263,7 @@ class Tree(ScrollWidget):
data = self.options.data
logging.info("Tree : buildTree,data=%s",data)
self.dataLoaded(data)
self.color, self.bgcolor = getColors(self.color_level)
def dataLoaded(self,d):
self.data = d
@ -283,6 +284,13 @@ class TextContent(PressableLabel):
def __init__(self,level=0,**options):
PressableLabel.__init__(self,**options)
def selected(self):
pass
def unselected(self):
pass
class TextTreeNode(TreeNode):
def buildContent(self):
txt = self.data.get(self.treeObj.options.textField,
@ -294,7 +302,8 @@ class TextTreeNode(TreeNode):
halign='left',
height=CSize(2),
width=CSize(len(txt)))
self.content.text_color = [0,0,0,1] #self.treeObj.text_color
self.content.color, self.content.bgcolor = getColors(self.treeObj.color_level,
selected=False)
self.content.bind(on_press=self.onPress)
return
@ -309,11 +318,17 @@ class TextTreeNode(TreeNode):
def selected(self):
logging.info('content selected ........')
self.content.selected()
color, bgcolor = getColors(self.treeObj.color_level,
selected=True)
self.content.bgcolor = bgcolor
self.content.color = color
def unselected(self):
logging.info('content unselected ........')
self.content.unselected()
color, bgcolor = getColors(self.treeObj.color_level,
selected=False)
self.content.bgcolor = bgcolor
self.content.color = color
class TextTree(Tree):
def __init__(self,**options):

View File

@ -70,6 +70,19 @@ class BaseVPlayer(FloatLayout):
if hasattr(self._video._video, '_ffplayer'):
self.ffplayer = self._video._video._ffplayer
def setSource(self,s):
self.stop()
self.curplay = 0
self.playlist = [s]
Logger.info('kivyblocks: Vplayer().setSource,s=%s',s)
self.play()
def setPlaylist(self,pl):
self.stop()
self.curplay = 0
self.playlist = pl
self.play()
def on_source_error(self,o,v):
Logger.info('safecorner: {} error'.format(v))