From d310b3ad9ffeeae447e44fe27447a52161ea355d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 12 Jul 2020 23:02:07 +0800 Subject: [PATCH] bugfix --- kivyblocks/boxViewer.py | 9 ++++++++- kivyblocks/newwidget.py | 2 +- kivyblocks/swipebehavior.py | 28 ++++++++++++++++++++++------ kivyblocks/tree.py | 2 +- kivyblocks/vplayer.py | 8 ++++---- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/kivyblocks/boxViewer.py b/kivyblocks/boxViewer.py index f50981e..807d350 100644 --- a/kivyblocks/boxViewer.py +++ b/kivyblocks/boxViewer.py @@ -32,7 +32,14 @@ class BoxViewer(BoxLayout): self.parenturl = None self.dataloader = None self.initflag = False - BoxLayout.__init__(self, orientation='vertical') + remind = ['toolbar', + 'dataloader', + 'orientation', + 'viewer', + 'boxwidth', + 'boxheight'] + kwargs = {k:v for k,v in options if k not in remind } + BoxLayout.__init__(self, orientation='vertical', **kwargs) self.selected_data = None self.options = options self.box_width = CSize(options['boxwidth']) diff --git a/kivyblocks/newwidget.py b/kivyblocks/newwidget.py index 778febf..34e8c8a 100644 --- a/kivyblocks/newwidget.py +++ b/kivyblocks/newwidget.py @@ -29,7 +29,7 @@ class NewWidget(Widget): def getParentColorLevel(self): if not self.parent: - self.fcolor, self.bgcolor = getColors(self.color_level): + self.fcolor, self.bgcolor = getColors(self.color_level) def on_color_level(self,o,v=None): if bgcolor != [] and fcolor != []: diff --git a/kivyblocks/swipebehavior.py b/kivyblocks/swipebehavior.py index 1ca0f95..82b9d7a 100644 --- a/kivyblocks/swipebehavior.py +++ b/kivyblocks/swipebehavior.py @@ -4,6 +4,7 @@ from kivy.logger import Logger class SwipeBehavior(object): def __init__(self, **kwargs): object.__init__(self) + self.swipeenable = True self.register_event_type('on_context_menu') self.register_event_type('on_swipe_left') self.register_event_type('on_swipe_right') @@ -14,11 +15,17 @@ class SwipeBehavior(object): self.sb_start_time = None self.sb_end_time = None self.threshold=20 - self.threshold_time = 1.5 + self.threshold_time = 0.6 self.bind(on_touch_down=self.on_touchdown) self.bind(on_touch_move=self.on_touchmove) self.bind(on_touch_up=self.on_touchup) + def disable_swipe(self): + self.swipeenable = False + + def enable_swipe(self): + self.swipeenable = True + def on_context_menu(self): Logger.info('SwipeBehavior:on_context_menu fired') @@ -34,15 +41,21 @@ class SwipeBehavior(object): def on_swipe_down(self): Logger.info('SwipeBehavior:on_swipe_down fired') - def on_touchdown(self,o,touch): + def on_touchdown(self,o, touch): + if touch.is_mouse_scrolling: + Logger.info('SwipeBehavior:is_mouse_scrolling') + return False + if not self.collide_point(touch.x, touch.y): + return False + Logger.info('SwipeBehavior:touch_down fired') - if self.collide_point(*touch.pos): + if self.swipeenable: Logger.info('SwipeBehavior:touch_down fired') self.sb_start_point = touch.pos self.sb_start_time = time.time() def on_touchmove(self,o,touch): - if self.collide_point(*touch.pos): + if self.collide_point(*touch.pos) and self.swipeenable: Logger.info('SwipeBehavior:touch_move fired') if self.sb_start_point is None: self.sb_start_point = touch.pos @@ -50,7 +63,7 @@ class SwipeBehavior(object): self.sb_end_point = touch.pos def on_touchup(self,o,touch): - if self.collide_point(*touch.pos): + if self.collide_point(*touch.pos) and self.swipeenable: Logger.info('SwipeBehavior:touch_up fired') self.sb_end_point = touch.pos self.sb_end_time = time.time() @@ -66,7 +79,10 @@ class SwipeBehavior(object): return if not self.sb_end_time: return - if self.sb_end_time - self.sb_start_time > self.threshold_time: + period_time = self.sb_end_time - self.sb_start_time + Logger.info('SwipeBehavior:period_time=%f,threshold_time=%f', + period_time, self.threshold_time) + if period_time >= self.threshold_time: self.dispatch('on_context_menu') def check_swipe(self): diff --git a/kivyblocks/tree.py b/kivyblocks/tree.py index 0ba621c..a19b9cd 100644 --- a/kivyblocks/tree.py +++ b/kivyblocks/tree.py @@ -431,7 +431,7 @@ class PopupMenu(BoxLayout): def __init__(self,target,menudesc,**opts): self.target = target self.menudesc = menudesc - BoxLayout.__init__(self, size_hint=(0.5,0.5)) + BoxLayout.__init__(self, size_hint=(0.5,0.5), **opts) self.menu_tree = TextTree(**menudesc) self.add_widget(self.menu_tree) self.menu_tree.bind(on_press=self.onMenuItemTouch) diff --git a/kivyblocks/vplayer.py b/kivyblocks/vplayer.py index b728364..7b5e45c 100644 --- a/kivyblocks/vplayer.py +++ b/kivyblocks/vplayer.py @@ -1,6 +1,8 @@ import os import sys import time + +from appPublic.sockPackage import get_free_local_addr from kivy.utils import platform from traceback import print_exc from kivy.core.window import Window @@ -22,7 +24,7 @@ from pythonosc import dispatcher, osc_server from ffpyplayer.tools import set_log_callback from .utils import * from .paging import PageLoader -from .baseWidget import PressableImage, get_local_addr +from .baseWidget import PressableImage from .swipebehavior import SwipeBehavior desktopOSs=[ @@ -235,11 +237,9 @@ class Swipe_VPlayer(BaseVPlayer, SwipeBehavior): class OSC_VPlayer(BaseVPlayer): def __init__(self,vfile=None, loop=False, mute=False): - self.ip = ip - self.port = port self.dispatcher = dispatcher.Dispatcher() addr = get_local_addr - self.ip,self.port = get_local_addr() + self.ip,self.port = get_free_local_addr() self.server = osc_server.ThreadingOSCUDPServer( (self.ip,self.port), self.dispatcher) BaseVPlayer.__init__(self,vfile=vfile, loop=loop, mute=mute)