fix rectangle bug
This commit is contained in:
parent
b80987ce72
commit
0c616b2845
@ -147,11 +147,14 @@ class Blocks(EventDispatcher):
|
|||||||
|
|
||||||
x = ClassX{klass_cnt}()
|
x = ClassX{klass_cnt}()
|
||||||
"""
|
"""
|
||||||
# print(code)
|
try:
|
||||||
exec(code, env, lenv)
|
exec(code, env, lenv)
|
||||||
w = lenv.get('x', None)
|
w = lenv.get('x', None)
|
||||||
klass_cnt += 1
|
klass_cnt += 1
|
||||||
return w
|
return w
|
||||||
|
except Exception as e:
|
||||||
|
print(code)
|
||||||
|
raise e
|
||||||
|
|
||||||
def set(self, k:str, v):
|
def set(self, k:str, v):
|
||||||
self.env[k] = v
|
self.env[k] = v
|
||||||
@ -501,8 +504,9 @@ x = ClassX{klass_cnt}()
|
|||||||
target.add_widget(w)
|
target.add_widget(w)
|
||||||
|
|
||||||
def doerr(o,e):
|
def doerr(o,e):
|
||||||
Logger.info('Block: urlwidgetAction(): desc=%s widgetBuild error'
|
Logger.info('Block: urlwidgetAction(): desc=%s widgetBuild error e=%s'
|
||||||
,str(desc))
|
,str(desc), str(e))
|
||||||
|
print('d=', d)
|
||||||
|
|
||||||
b = Blocks()
|
b = Blocks()
|
||||||
b.bind(on_built=partial(doit,target,add_mode))
|
b.bind(on_built=partial(doit,target,add_mode))
|
||||||
@ -858,5 +862,3 @@ class {{ classname }}({% for b in bases -%}{{b}}{% endfor %})
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
Factory.register('Blocks',Blocks)
|
Factory.register('Blocks',Blocks)
|
||||||
Factory.register('Video',Video)
|
|
||||||
Factory.register('OrientationLayout', OrientationLayout)
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from kivyblocks import setconfig
|
||||||
from kivy.resources import resource_add_path
|
from kivy.resources import resource_add_path
|
||||||
import signal
|
import signal
|
||||||
import codecs
|
import codecs
|
||||||
@ -22,6 +23,7 @@ from kivy.app import App
|
|||||||
|
|
||||||
import plyer
|
import plyer
|
||||||
|
|
||||||
|
from .i18n import I18n
|
||||||
from .register import *
|
from .register import *
|
||||||
from .threadcall import HttpClient,Workers
|
from .threadcall import HttpClient,Workers
|
||||||
from .utils import *
|
from .utils import *
|
||||||
@ -74,6 +76,7 @@ class BlocksApp(App):
|
|||||||
register_css(k,v)
|
register_css(k,v)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
|
i18n = I18n()
|
||||||
self.platform = platform
|
self.platform = platform
|
||||||
self.is_desktop = platform in ['win', 'linux', 'macosx']
|
self.is_desktop = platform in ['win', 'linux', 'macosx']
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
@ -35,6 +35,7 @@ vhks = ['v_src',
|
|||||||
]
|
]
|
||||||
|
|
||||||
class FFVideo(WidgetReady, VideoBehavior, BoxLayout):
|
class FFVideo(WidgetReady, VideoBehavior, BoxLayout):
|
||||||
|
# class FFVideo(VideoBehavior, BoxLayout):
|
||||||
def __init__(self, **kw):
|
def __init__(self, **kw):
|
||||||
kw1 = {k:v for k,v in kw.items() if k in vhks}
|
kw1 = {k:v for k,v in kw.items() if k in vhks}
|
||||||
kw1['renderto'] = 'background'
|
kw1['renderto'] = 'background'
|
||||||
@ -43,9 +44,9 @@ class FFVideo(WidgetReady, VideoBehavior, BoxLayout):
|
|||||||
BoxLayout.__init__(self, **kw2)
|
BoxLayout.__init__(self, **kw2)
|
||||||
VideoBehavior.__init__(self, **kw1)
|
VideoBehavior.__init__(self, **kw1)
|
||||||
WidgetReady.__init__(self)
|
WidgetReady.__init__(self)
|
||||||
self.msg_w = Label(text='Hello')
|
# self.msg_w = Label(text='Hello')
|
||||||
self.add_widget(self.msg_w)
|
# self.add_widget(self.msg_w)
|
||||||
self.bind(on_frame=self.show_info)
|
# self.bind(on_frame=self.show_info)
|
||||||
|
|
||||||
def show_info(self, o, d):
|
def show_info(self, o, d):
|
||||||
txt = f"size={d['size']}, vpos={d['pos']}, vsize={d['texture_size']}"
|
txt = f"size={d['size']}, vpos={d['pos']}, vsize={d['texture_size']}"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
from kivy.graphics import Color, Line
|
||||||
from kivy.uix.floatlayout import FloatLayout
|
from kivy.uix.floatlayout import FloatLayout
|
||||||
from kivy.uix.widget import Widget
|
from kivy.uix.widget import Widget
|
||||||
from kivyblocks.bgcolorbehavior import BGColorBehavior
|
from kivyblocks.bgcolorbehavior import BGColorBehavior
|
||||||
@ -16,6 +17,7 @@ class LandscopeHide(FloatLayout):
|
|||||||
self.fix_widget = fix_desc
|
self.fix_widget = fix_desc
|
||||||
else:
|
else:
|
||||||
self.fix_widget = widget_build(fix_desc)
|
self.fix_widget = widget_build(fix_desc)
|
||||||
|
self.add_widget(self.fix_widget)
|
||||||
if float_desc:
|
if float_desc:
|
||||||
if isinstance(float_desc, Widget):
|
if isinstance(float_desc, Widget):
|
||||||
self.float_widget = float_desc
|
self.float_widget = float_desc
|
||||||
@ -44,23 +46,26 @@ class LandscopeHide(FloatLayout):
|
|||||||
return self.width > self.height
|
return self.width > self.height
|
||||||
|
|
||||||
def size_changed(self, *args):
|
def size_changed(self, *args):
|
||||||
print(f'force={self.float_show_landscope}, landscope={self.is_landscope()}, w={self.width}, h={self.height}')
|
|
||||||
self.rate = min(*self.size) / max(*self.size)
|
self.rate = min(*self.size) / max(*self.size)
|
||||||
self.clear_widgets()
|
|
||||||
self.show_fix()
|
self.show_fix()
|
||||||
self.show_float()
|
self.show_float()
|
||||||
|
self._trigger_layout()
|
||||||
|
print(f'landscope={self.is_landscope()}, w={self.width}, h={self.height}, fix_pos={self.fix_widget.pos}, fix_size={self.fix_widget.size}')
|
||||||
|
self.canvas.before.clear()
|
||||||
|
with self.canvas.before:
|
||||||
|
Color(1,0,0,1)
|
||||||
|
Line(rectangle=(0,0, self.width, self.height), width=2)
|
||||||
|
|
||||||
def show_fix(self):
|
def show_fix(self):
|
||||||
if self.is_landscope():
|
if self.is_landscope():
|
||||||
print('show_fix() landscope')
|
print('show_fix() landscope')
|
||||||
self.fix_widget.size_hint = (1, 1)
|
self.fix_widget.size_hint = (1, 1)
|
||||||
self.fix_widget.pos = (0,0)
|
self.fix_widget.pos_hint = {'x':0, 'y':0}
|
||||||
else:
|
else:
|
||||||
print('show_fix() not landscope')
|
print('show_fix() not landscope')
|
||||||
self.fix_widget.size_hint = (1, None)
|
hr = self.width * self.rate / self.height
|
||||||
self.fix_widget.height = self.width * self.rate
|
self.fix_widget.size_hint = (1, hr)
|
||||||
self.fix_widget.pos = (0, self.height - self.fix_widget.height)
|
self.fix_widget.pos_hint = {'x':0, 'y':(1-hr)}
|
||||||
self.add_widget(self.fix_widget)
|
|
||||||
|
|
||||||
def show_float(self):
|
def show_float(self):
|
||||||
if self.is_landscope():
|
if self.is_landscope():
|
||||||
@ -70,11 +75,15 @@ class LandscopeHide(FloatLayout):
|
|||||||
self.float_widget.width = self.height * self.rate
|
self.float_widget.width = self.height * self.rate
|
||||||
self.float_widget.pos = (0, 0)
|
self.float_widget.pos = (0, 0)
|
||||||
self.add_widget(self.float_widget)
|
self.add_widget(self.float_widget)
|
||||||
|
else:
|
||||||
|
if self.float_widget in self.children:
|
||||||
|
self.remove_widget(self.float_widget)
|
||||||
else:
|
else:
|
||||||
print('show_float() not landscope')
|
print('show_float() not landscope')
|
||||||
self.float_widget.size_hint = (1, None)
|
self.float_widget.size_hint = (1, None)
|
||||||
self.float_widget.height = self.height - self.fix_widget.height
|
self.float_widget.height = self.height - self.fix_widget.height
|
||||||
self.float_widget.pos = (0, 0)
|
self.float_widget.pos = (0, 0)
|
||||||
|
if not self.float_widget in self.children:
|
||||||
self.add_widget(self.float_widget)
|
self.add_widget(self.float_widget)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -9,7 +9,7 @@ class ModalBehavior(object):
|
|||||||
auto_dismiss = BooleanProperty(True)
|
auto_dismiss = BooleanProperty(True)
|
||||||
target = StringProperty(None)
|
target = StringProperty(None)
|
||||||
show_time = NumericProperty(0)
|
show_time = NumericProperty(0)
|
||||||
position = OptionProperty('cc',options=['tl', 'tc', 'tr',
|
anchor = OptionProperty('cc',options=['tl', 'tc', 'tr',
|
||||||
'cl', 'cc', 'cr',
|
'cl', 'cc', 'cr',
|
||||||
'bl', 'bc', 'br'])
|
'bl', 'bc', 'br'])
|
||||||
def __init__(self, **kw):
|
def __init__(self, **kw):
|
||||||
@ -17,8 +17,8 @@ class ModalBehavior(object):
|
|||||||
setattr(self, k,v)
|
setattr(self, k,v)
|
||||||
self.time_task = None
|
self.time_task = None
|
||||||
self._target = None
|
self._target = None
|
||||||
self.set_size_position()
|
self.set_size_anchor()
|
||||||
self._target.bind(size=self.set_size_position)
|
self._target.bind(size=self.set_size_anchor)
|
||||||
self.register_event_type('on_open')
|
self.register_event_type('on_open')
|
||||||
self.register_event_type('on_pre_open')
|
self.register_event_type('on_pre_open')
|
||||||
self.register_event_type('on_pre_dismiss')
|
self.register_event_type('on_pre_dismiss')
|
||||||
@ -48,18 +48,18 @@ class ModalBehavior(object):
|
|||||||
w = Window
|
w = Window
|
||||||
self._target = w
|
self._target = w
|
||||||
|
|
||||||
def set_size_position(self, *args):
|
def set_size_anchor(self, *args):
|
||||||
self.set_target()
|
self.set_target()
|
||||||
if self.size_hint_x:
|
if self.size_hint_x:
|
||||||
self.width = self.size_hint_x * self._target.width
|
self.width = self.size_hint_x * self._target.width
|
||||||
if self.size_hint_y:
|
if self.size_hint_y:
|
||||||
self.height = self.size_hint_y * self._target.height
|
self.height = self.size_hint_y * self._target.height
|
||||||
self.set_modal_position()
|
self.set_modal_anchor()
|
||||||
|
|
||||||
def set_modal_position(self):
|
def set_modal_anchor(self):
|
||||||
self.set_target()
|
self.set_target()
|
||||||
xn = self.position[1]
|
xn = self.anchor[1]
|
||||||
yn = self.position[0]
|
yn = self.anchor[0]
|
||||||
x, y = 0, 0
|
x, y = 0, 0
|
||||||
if xn == 'c':
|
if xn == 'c':
|
||||||
x = (self._target.width - self.width) / 2
|
x = (self._target.width - self.width) / 2
|
||||||
@ -77,7 +77,7 @@ class ModalBehavior(object):
|
|||||||
self.pos = x, y
|
self.pos = x, y
|
||||||
else:
|
else:
|
||||||
self.pos = self._target.pos[0] + x, self._target.pos[1] + y
|
self.pos = self._target.pos[0] + x, self._target.pos[1] + y
|
||||||
print("modal",self._target.size, self.position, self.pos, self.size, self.size_hint)
|
print("modal",self._target.size, self.anchor, self.pos, self.size, self.size_hint)
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
if self.time_task is not None:
|
if self.time_task is not None:
|
||||||
|
@ -30,6 +30,7 @@ from .markdown import Markdown
|
|||||||
# from .custom_camera import CustomCamera, QrReader
|
# from .custom_camera import CustomCamera, QrReader
|
||||||
from .defaultimage import *
|
from .defaultimage import *
|
||||||
from .price import *
|
from .price import *
|
||||||
|
from .blocks import Blocks
|
||||||
|
|
||||||
#if kivy.platform in ['win','linux', 'macosx']:
|
#if kivy.platform in ['win','linux', 'macosx']:
|
||||||
# from .camerawithmic import ScreenWithMic
|
# from .camerawithmic import ScreenWithMic
|
||||||
|
@ -1 +1 @@
|
|||||||
__version__ = '0.4.6'
|
__version__ = '0.4.7'
|
||||||
|
@ -48,7 +48,7 @@ class VideoBehavior(object):
|
|||||||
}
|
}
|
||||||
self.lib_opts = {}
|
self.lib_opts = {}
|
||||||
self.headers_pattern = {}
|
self.headers_pattern = {}
|
||||||
self.set_black()
|
# self.set_black()
|
||||||
self.start_task = None
|
self.start_task = None
|
||||||
self.block_task = None
|
self.block_task = None
|
||||||
self.register_event_type('on_frame')
|
self.register_event_type('on_frame')
|
||||||
@ -292,9 +292,9 @@ class VideoBehavior(object):
|
|||||||
return
|
return
|
||||||
image_texture = Texture.create(
|
image_texture = Texture.create(
|
||||||
size=self.size, colorfmt='rgb')
|
size=self.size, colorfmt='rgb')
|
||||||
buf = b'\x00' * int(self.width * self.height * 3)
|
buf = b'\x33' * int(self.width * self.height * 3)
|
||||||
image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
|
image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
|
||||||
self._draw_texture(image_texture, *self.size)
|
self._my_show_texture(image_texture, *self.size)
|
||||||
self.is_black = True
|
self.is_black = True
|
||||||
|
|
||||||
def show_yuv420(self, img):
|
def show_yuv420(self, img):
|
||||||
@ -324,7 +324,7 @@ class VideoBehavior(object):
|
|||||||
self._fbo.ask_update()
|
self._fbo.ask_update()
|
||||||
self._fbo.draw()
|
self._fbo.draw()
|
||||||
texture.flip_vertical()
|
texture.flip_vertical()
|
||||||
self.draw_texture(texture, w, h)
|
self.my_show_texture(texture, w, h)
|
||||||
# self.texture = texture
|
# self.texture = texture
|
||||||
|
|
||||||
def show_others(self, img):
|
def show_others(self, img):
|
||||||
@ -334,16 +334,18 @@ class VideoBehavior(object):
|
|||||||
img.to_memoryview()[0], colorfmt='rgb',
|
img.to_memoryview()[0], colorfmt='rgb',
|
||||||
bufferfmt='ubyte')
|
bufferfmt='ubyte')
|
||||||
texture.flip_vertical()
|
texture.flip_vertical()
|
||||||
self.draw_texture(texture, w, h)
|
self.my_show_texture(texture, w, h)
|
||||||
# self.texture = texture
|
# self.texture = texture
|
||||||
# print('img_size=', w, h, 'window size=', self.size)
|
# print('img_size=', w, h, 'window size=', self.size)
|
||||||
|
|
||||||
def draw_texture(self, texture, w, h):
|
def my_show_texture(self, texture, w, h):
|
||||||
d = self._draw_texture(texture, w, h)
|
d = self._my_show_texture(texture, w, h)
|
||||||
if d:
|
if d:
|
||||||
self.dispatch('on_frame', d)
|
self.dispatch('on_frame', d)
|
||||||
|
|
||||||
def _draw_texture(self, texture, w, h):
|
def _my_show_texture(self, texture, w, h):
|
||||||
|
if self.width == 100 and self.height== 100:
|
||||||
|
return
|
||||||
if abs(self.width - w) > 1 and abs(self.height - h) > 1:
|
if abs(self.width - w) > 1 and abs(self.height - h) > 1:
|
||||||
self._set_video_size()
|
self._set_video_size()
|
||||||
if w > self.width:
|
if w > self.width:
|
||||||
@ -365,7 +367,9 @@ class VideoBehavior(object):
|
|||||||
Color(1,1,1,1)
|
Color(1,1,1,1)
|
||||||
Line(points=[0, 1, self.width, 1], width=2)
|
Line(points=[0, 1, self.width, 1], width=2)
|
||||||
Color(1,0,0,1)
|
Color(1,0,0,1)
|
||||||
Line(points=[0,1,p,1], width=2)
|
Line(points=[1,1,p,1], width=2)
|
||||||
|
# Color(1,1,0,1)
|
||||||
|
# Line(rectangle=[0,0, self.width, self.height], width=4)
|
||||||
d = {
|
d = {
|
||||||
'texture':texture,
|
'texture':texture,
|
||||||
'position':self.position,
|
'position':self.position,
|
||||||
@ -389,7 +393,7 @@ class VideoBehavior(object):
|
|||||||
self.play()
|
self.play()
|
||||||
return
|
return
|
||||||
self.status = 'stop'
|
self.status = 'stop'
|
||||||
self.set_black()
|
# self.set_black()
|
||||||
self.last_val = None
|
self.last_val = None
|
||||||
return
|
return
|
||||||
if val == 'pause':
|
if val == 'pause':
|
||||||
@ -397,7 +401,7 @@ class VideoBehavior(object):
|
|||||||
self.last_val = None
|
self.last_val = None
|
||||||
return
|
return
|
||||||
if frame is None:
|
if frame is None:
|
||||||
self.set_black()
|
# self.set_black()
|
||||||
self.last_val = None
|
self.last_val = None
|
||||||
self.vh_task = Clock.schedule_once(self.video_handle, 0.1)
|
self.vh_task = Clock.schedule_once(self.video_handle, 0.1)
|
||||||
return
|
return
|
||||||
|
@ -164,6 +164,8 @@ class WidgetCSS(object):
|
|||||||
self.set_background_color()
|
self.set_background_color()
|
||||||
|
|
||||||
def set_background_color(self, *args):
|
def set_background_color(self, *args):
|
||||||
|
if self.width == 100 and self.height == 100:
|
||||||
|
return
|
||||||
if not self.bgcolor:
|
if not self.bgcolor:
|
||||||
return
|
return
|
||||||
if not self.canvas:
|
if not self.canvas:
|
||||||
@ -171,7 +173,7 @@ class WidgetCSS(object):
|
|||||||
# self.__class__.__name__)
|
# self.__class__.__name__)
|
||||||
return
|
return
|
||||||
|
|
||||||
# self.canvas.before.clear()
|
self.canvas.before.clear()
|
||||||
with self.canvas.before:
|
with self.canvas.before:
|
||||||
Color(*self.bgcolor)
|
Color(*self.bgcolor)
|
||||||
if self.radius:
|
if self.radius:
|
||||||
|
Loading…
Reference in New Issue
Block a user