This commit is contained in:
yumoqing 2020-10-31 11:13:59 +08:00
parent 2e976967ea
commit 89bdf6608b
3 changed files with 103 additions and 12 deletions

View File

@ -131,9 +131,7 @@ class Header(WidgetReady, ScrollWidget):
[ f.update({'value':self.part.fields[i]['label']}) for i,f in enumerate(rd) ]
self.header = Row(self.part,rd,header=True)
self.add_widget(self.header)
self.addChild(self.header)
self.height = self.header.height
self.built()
class Body(ScrollWidget):
def __init__(self,part,**kw):
@ -209,14 +207,11 @@ class DataGridPart(WidgetReady, BoxLayout):
if not self.datagrid.noheader:
self.header = Header(self,**kw)
self.add_widget(self.header)
self.addChild(self.header)
self.body = Body(self)
self.add_widget(self.body)
self.addChild(self.body)
if not self.freeze_flag:
self.body.bind(pos=self.datagrid.bodyOnSize,
size=self.datagrid.bodyOnSize)
self.built()
def clearRows(self):
return self.body.clearRows()
@ -258,15 +253,12 @@ class DataGrid(WidgetReady, BoxLayout):
self.createToolbar()
if self.toolbar:
self.add_widget(self.toolbar)
self.addChild(self.toolbar)
b = BoxLayout(orientation='horizontal')
if self.freeze_part:
b.add_widget(self.freeze_part)
self.addChild(self.freeze_part)
if self.normal_part:
b.add_widget(self.normal_part)
self.addChild(self.normal_part)
self.add_widget(b)
if self.options.get('paging',False):
self.loader = Paging(adder=self.addRow,
@ -290,7 +282,6 @@ class DataGrid(WidgetReady, BoxLayout):
self.on_sizeTask = None
self.register_event_type('on_selected')
self.register_event_type('on_scrollstop')
self.built()
def setScrollPosition(self,pos):
self.normal_part.body.scroll_y = pos

View File

@ -19,8 +19,6 @@ class NewVideo(BGColorBehavior, Video):
BGColorBehavior.__init__(self)
Window.allow_screensaver = False
set_log_callback(self.ffplayerLog)
if hasattr(self._video, '_ffplayer'):
self.ffplayer = self._video._ffplayer
def on_state(self,*args):
print('new state = ',self.state)
@ -35,5 +33,8 @@ class NewVideo(BGColorBehavior, Video):
logger_func[level]('yffpyplayer: {}'.format(msg))
def audioswitch(self,btn=None):
x = self._ffplayer.request_channel('audio')
if hasattr(self._video,'_ffplayer'):
x = self._video._ffplayer.request_channel('audio')
else:
print('NewVideo _video has not _ffplayer, do nothong')

99
kivyblocks/toggleitems.py Normal file
View File

@ -0,0 +1,99 @@
from functools import partial
from kivy.uix.button import Button, ButtonBehavior
from kivy.graphics import Color, Rectangle
from kivy.uix.boxlayout import BoxLayout
from kivy.factory import Factory
from kivyblocks.ready import WidgetReady
class PressableBox(ButtonBehavior, BoxLayout):
def __init__(self,border_width=1,
bgcolor=[0,1,0,1],
selected_color=[1,0,0,1],
**kw):
BoxLayout.__init__(self, padding=[border_width,
border_width,
border_width,
border_width],
**kw)
ButtonBehavior.__init__(self)
self.b_bgcolor = bgcolor
self.border_width = border_width
self.b_selected_color = selected_color
self.user_data = None
self.unselected()
def on_size(self,o,s):
if self._selected:
self.selected()
else:
self.unselected()
def on_press(self,o=None):
self.selected()
def set_data(self,d):
self.user_data = d
def get_data(self):
return self.user_data
def is_selected(self):
return self._selected
def selected(self):
self._selected = True
with self.canvas.before:
Color(*self.b_selected_color)
Rectangle(pos=self.pos,size=self.size)
Color(*self.b_bgcolor)
Rectangle(size=(self.width - 2*self.border_width, self.height - 2*self.border_width),
pos=(int(self.center_x - (self.width - 2*self.border_width)/2.0), int(self.center_y - (self.height - 2*self.border_width)/2.0)))
def unselected(self):
self._selected = False
with self.canvas.before:
Color(*self.b_bgcolor)
Rectangle(pos=self.pos,size=self.size)
class ToggleItems(BoxLayout):
def __init__(self,
items_desc=[],
border_width=1,
bgcolor=[1,0,0,1],
selected_color=[1,0,0,1],
**kw):
BoxLayout.__init__(self, **kw)
self.item_widgets = []
for desc in items_desc:
c = PressableBox(border_width=border_width,
bgcolor=bgcolor,
selected_color=selected_color
)
self.item_widgets.append(c)
self.add_widget(c)
c.bind(on_press=self.select_item)
b = Factory.Blocks()
def cb(c,o,w):
c.add_widget(w)
def eb(desc,o,e):
print(desc,'error',e)
b.bind(on_built=partial(cb,c))
b.bind(on_failed=partial(eb,desc))
b.widgetBuild(desc,ancestor=self)
if desc.get('data'):
c.set_data(desc.get('data'))
self.selected = None
def select_item(self,o=None):
[i.unselected() for i in self.item_widgets if i != o]
def getValue(self):
for i in self.item_widgets:
if i.is_selected():
return i.getValue()
return None
Factory.register('PressableBox',PressableBox)
Factory.register('ToggleItems',ToggleItems)