fix rectangle bug

This commit is contained in:
yumoqing 2022-11-23 14:41:47 +08:00
parent b80987ce72
commit 0c616b2845
9 changed files with 64 additions and 42 deletions

View File

@ -147,11 +147,14 @@ class Blocks(EventDispatcher):
x = ClassX{klass_cnt}()
"""
# print(code)
exec(code, env, lenv)
w = lenv.get('x', None)
klass_cnt += 1
return w
try:
exec(code, env, lenv)
w = lenv.get('x', None)
klass_cnt += 1
return w
except Exception as e:
print(code)
raise e
def set(self, k:str, v):
self.env[k] = v
@ -501,8 +504,9 @@ x = ClassX{klass_cnt}()
target.add_widget(w)
def doerr(o,e):
Logger.info('Block: urlwidgetAction(): desc=%s widgetBuild error'
,str(desc))
Logger.info('Block: urlwidgetAction(): desc=%s widgetBuild error e=%s'
,str(desc), str(e))
print('d=', d)
b = Blocks()
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('Video',Video)
Factory.register('OrientationLayout', OrientationLayout)

View File

@ -1,6 +1,7 @@
import os
import sys
from kivyblocks import setconfig
from kivy.resources import resource_add_path
import signal
import codecs
@ -22,6 +23,7 @@ from kivy.app import App
import plyer
from .i18n import I18n
from .register import *
from .threadcall import HttpClient,Workers
from .utils import *
@ -74,6 +76,7 @@ class BlocksApp(App):
register_css(k,v)
def build(self):
i18n = I18n()
self.platform = platform
self.is_desktop = platform in ['win', 'linux', 'macosx']
config = getConfig()

View File

@ -35,6 +35,7 @@ vhks = ['v_src',
]
class FFVideo(WidgetReady, VideoBehavior, BoxLayout):
# class FFVideo(VideoBehavior, BoxLayout):
def __init__(self, **kw):
kw1 = {k:v for k,v in kw.items() if k in vhks}
kw1['renderto'] = 'background'
@ -43,9 +44,9 @@ class FFVideo(WidgetReady, VideoBehavior, BoxLayout):
BoxLayout.__init__(self, **kw2)
VideoBehavior.__init__(self, **kw1)
WidgetReady.__init__(self)
self.msg_w = Label(text='Hello')
self.add_widget(self.msg_w)
self.bind(on_frame=self.show_info)
# self.msg_w = Label(text='Hello')
# self.add_widget(self.msg_w)
# self.bind(on_frame=self.show_info)
def show_info(self, o, d):
txt = f"size={d['size']}, vpos={d['pos']}, vsize={d['texture_size']}"

View File

@ -1,4 +1,5 @@
from kivy.graphics import Color, Line
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivyblocks.bgcolorbehavior import BGColorBehavior
@ -16,6 +17,7 @@ class LandscopeHide(FloatLayout):
self.fix_widget = fix_desc
else:
self.fix_widget = widget_build(fix_desc)
self.add_widget(self.fix_widget)
if float_desc:
if isinstance(float_desc, Widget):
self.float_widget = float_desc
@ -44,23 +46,26 @@ class LandscopeHide(FloatLayout):
return self.width > self.height
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.clear_widgets()
self.show_fix()
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):
if self.is_landscope():
print('show_fix() landscope')
self.fix_widget.size_hint = (1, 1)
self.fix_widget.pos = (0,0)
self.fix_widget.pos_hint = {'x':0, 'y':0}
else:
print('show_fix() not landscope')
self.fix_widget.size_hint = (1, None)
self.fix_widget.height = self.width * self.rate
self.fix_widget.pos = (0, self.height - self.fix_widget.height)
self.add_widget(self.fix_widget)
hr = self.width * self.rate / self.height
self.fix_widget.size_hint = (1, hr)
self.fix_widget.pos_hint = {'x':0, 'y':(1-hr)}
def show_float(self):
if self.is_landscope():
@ -70,12 +75,16 @@ class LandscopeHide(FloatLayout):
self.float_widget.width = self.height * self.rate
self.float_widget.pos = (0, 0)
self.add_widget(self.float_widget)
else:
if self.float_widget in self.children:
self.remove_widget(self.float_widget)
else:
print('show_float() not landscope')
self.float_widget.size_hint = (1, None)
self.float_widget.height = self.height - self.fix_widget.height
self.float_widget.pos = (0, 0)
self.add_widget(self.float_widget)
if not self.float_widget in self.children:
self.add_widget(self.float_widget)
if __name__ == '__main__':
from kivy.app import App

View File

@ -9,7 +9,7 @@ class ModalBehavior(object):
auto_dismiss = BooleanProperty(True)
target = StringProperty(None)
show_time = NumericProperty(0)
position = OptionProperty('cc',options=['tl', 'tc', 'tr',
anchor = OptionProperty('cc',options=['tl', 'tc', 'tr',
'cl', 'cc', 'cr',
'bl', 'bc', 'br'])
def __init__(self, **kw):
@ -17,8 +17,8 @@ class ModalBehavior(object):
setattr(self, k,v)
self.time_task = None
self._target = None
self.set_size_position()
self._target.bind(size=self.set_size_position)
self.set_size_anchor()
self._target.bind(size=self.set_size_anchor)
self.register_event_type('on_open')
self.register_event_type('on_pre_open')
self.register_event_type('on_pre_dismiss')
@ -48,18 +48,18 @@ class ModalBehavior(object):
w = Window
self._target = w
def set_size_position(self, *args):
def set_size_anchor(self, *args):
self.set_target()
if self.size_hint_x:
self.width = self.size_hint_x * self._target.width
if self.size_hint_y:
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()
xn = self.position[1]
yn = self.position[0]
xn = self.anchor[1]
yn = self.anchor[0]
x, y = 0, 0
if xn == 'c':
x = (self._target.width - self.width) / 2
@ -77,7 +77,7 @@ class ModalBehavior(object):
self.pos = x, y
else:
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):
if self.time_task is not None:

View File

@ -30,6 +30,7 @@ from .markdown import Markdown
# from .custom_camera import CustomCamera, QrReader
from .defaultimage import *
from .price import *
from .blocks import Blocks
#if kivy.platform in ['win','linux', 'macosx']:
# from .camerawithmic import ScreenWithMic

View File

@ -1 +1 @@
__version__ = '0.4.6'
__version__ = '0.4.7'

View File

@ -48,7 +48,7 @@ class VideoBehavior(object):
}
self.lib_opts = {}
self.headers_pattern = {}
self.set_black()
# self.set_black()
self.start_task = None
self.block_task = None
self.register_event_type('on_frame')
@ -292,9 +292,9 @@ class VideoBehavior(object):
return
image_texture = Texture.create(
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')
self._draw_texture(image_texture, *self.size)
self._my_show_texture(image_texture, *self.size)
self.is_black = True
def show_yuv420(self, img):
@ -324,7 +324,7 @@ class VideoBehavior(object):
self._fbo.ask_update()
self._fbo.draw()
texture.flip_vertical()
self.draw_texture(texture, w, h)
self.my_show_texture(texture, w, h)
# self.texture = texture
def show_others(self, img):
@ -334,16 +334,18 @@ class VideoBehavior(object):
img.to_memoryview()[0], colorfmt='rgb',
bufferfmt='ubyte')
texture.flip_vertical()
self.draw_texture(texture, w, h)
self.my_show_texture(texture, w, h)
# self.texture = texture
# print('img_size=', w, h, 'window size=', self.size)
def draw_texture(self, texture, w, h):
d = self._draw_texture(texture, w, h)
def my_show_texture(self, texture, w, h):
d = self._my_show_texture(texture, w, h)
if 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:
self._set_video_size()
if w > self.width:
@ -365,7 +367,9 @@ class VideoBehavior(object):
Color(1,1,1,1)
Line(points=[0, 1, self.width, 1], width=2)
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 = {
'texture':texture,
'position':self.position,
@ -389,7 +393,7 @@ class VideoBehavior(object):
self.play()
return
self.status = 'stop'
self.set_black()
# self.set_black()
self.last_val = None
return
if val == 'pause':
@ -397,7 +401,7 @@ class VideoBehavior(object):
self.last_val = None
return
if frame is None:
self.set_black()
# self.set_black()
self.last_val = None
self.vh_task = Clock.schedule_once(self.video_handle, 0.1)
return

View File

@ -164,6 +164,8 @@ class WidgetCSS(object):
self.set_background_color()
def set_background_color(self, *args):
if self.width == 100 and self.height == 100:
return
if not self.bgcolor:
return
if not self.canvas:
@ -171,7 +173,7 @@ class WidgetCSS(object):
# self.__class__.__name__)
return
# self.canvas.before.clear()
self.canvas.before.clear()
with self.canvas.before:
Color(*self.bgcolor)
if self.radius: