bugfix
This commit is contained in:
parent
f886788bb3
commit
54119a475f
@ -1,4 +1,6 @@
|
|||||||
from kivy.uix.floatlayout import FloatLayout
|
from kivy.uix.floatlayout import FloatLayout
|
||||||
|
from kivy.event import EventDispatcher
|
||||||
|
from kivy.clock import Clock
|
||||||
from kivy.factory import Factory
|
from kivy.factory import Factory
|
||||||
from kivy.properties import ObjectProperty
|
from kivy.properties import ObjectProperty
|
||||||
from kivy.uix.popup import Popup
|
from kivy.uix.popup import Popup
|
||||||
@ -21,12 +23,15 @@ class FileLoaderBrowser(Popup):
|
|||||||
Popup.__init__(self, content = self.content,
|
Popup.__init__(self, content = self.content,
|
||||||
title=i18n(title),
|
title=i18n(title),
|
||||||
size_hint=(0.9,0.9))
|
size_hint=(0.9,0.9))
|
||||||
|
self.register_event_type('on_selected')
|
||||||
self.choose_dir = choose_dir
|
self.choose_dir = choose_dir
|
||||||
|
|
||||||
self.list_widget = FileChooserListView(rootpath=rootpath)
|
self.list_widget = FileChooserListView(rootpath=rootpath)
|
||||||
self.icon_widget = FileChooserIconView(rootpath=rootpath)
|
self.icon_widget = FileChooserIconView(rootpath=rootpath)
|
||||||
self.list_widget.bind(on_selection=self.set_txt_input)
|
self.list_widget.bind(on_touch_up=self.on_release)
|
||||||
self.icon_widget.bind(on_selection=self.set_txt_input)
|
self.icon_widget.bind(on_touch_up=self.on_release)
|
||||||
|
self.list_widget.bind(on_submit=self.do_submit)
|
||||||
|
self.icon_widget.bind(on_submit=self.do_submit)
|
||||||
self.btn_load = Button(text=i18n('load'),size_hint=(None,None),
|
self.btn_load = Button(text=i18n('load'),size_hint=(None,None),
|
||||||
size=CSize(8,2))
|
size=CSize(8,2))
|
||||||
self.btn_list_view = PressableImage( \
|
self.btn_list_view = PressableImage( \
|
||||||
@ -48,19 +53,44 @@ class FileLoaderBrowser(Popup):
|
|||||||
self.view_mode = 'list_view'
|
self.view_mode = 'list_view'
|
||||||
self.show_list_view()
|
self.show_list_view()
|
||||||
|
|
||||||
def set_txt_input(self,o,v=None):
|
def on_selected(self,fn):
|
||||||
print('on_selection fired',o.selection)
|
print(fn,'selected')
|
||||||
self.txt_input.text = o.path
|
|
||||||
|
def on_release(self,o,v=None):
|
||||||
|
Clock.schedule_once(self.set_txt_input,0.4)
|
||||||
|
|
||||||
|
def set_txt_input(self,t=None):
|
||||||
|
self.txt_input.text = self.cur_widget.path
|
||||||
|
|
||||||
|
def target_selected(self):
|
||||||
|
fn = self.txt_input.text
|
||||||
|
if not self.choose_dir and os.path.isdir(fn):
|
||||||
|
return
|
||||||
|
if self.choose_dir and os.path.isfile(fn):
|
||||||
|
fn = os.path.dirname(fn)
|
||||||
|
self.dispatch('on_selected',fn)
|
||||||
|
self.dismiss()
|
||||||
|
|
||||||
|
def do_submit(self,o,a,b):
|
||||||
|
if not self.cur_widget.selection:
|
||||||
|
return
|
||||||
|
self.txt_input.text = self.cur_widget.selection[0]
|
||||||
|
self.target_selected()
|
||||||
|
|
||||||
def do_load(self,o,d=None):
|
def do_load(self,o,d=None):
|
||||||
print(o,d)
|
if self.cur_widget.selection:
|
||||||
print(self.cur_widget.selection and self.cur_widget.selection[0] or '', 'selected ')
|
self.txt_input.text = self.cur_widget.selection[0]
|
||||||
|
if self.txt_input.text == '':
|
||||||
|
return
|
||||||
|
self.target_selected()
|
||||||
|
|
||||||
def change_view_mode(self,o,v=None):
|
def change_view_mode(self,o,v=None):
|
||||||
self.content.clear_widgets()
|
self.content.clear_widgets()
|
||||||
if self.view_mode == 'list_view':
|
if self.view_mode == 'list_view':
|
||||||
self.show_icon_view()
|
self.show_icon_view()
|
||||||
else:
|
else:
|
||||||
self.show_list_view()
|
self.show_list_view()
|
||||||
|
|
||||||
def show_list_view(self):
|
def show_list_view(self):
|
||||||
self.cur_widget = self.list_widget
|
self.cur_widget = self.list_widget
|
||||||
self.view_mode = 'list_view'
|
self.view_mode = 'list_view'
|
||||||
|
100
kivyblocks/player_osc.py
Normal file
100
kivyblocks/player_osc.py
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
|
||||||
|
import json
|
||||||
|
from pythonosc import dispatcher, osc_server, udp_client
|
||||||
|
from appPublic.sockPackage import get_free_local_addr
|
||||||
|
from background import Background
|
||||||
|
from kivy.event import EventDispatcher
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerOSCServer(EventDispatcher):
|
||||||
|
def __init__(self,playerid):
|
||||||
|
EventDispatcher.__init__(self)
|
||||||
|
self.playerid = playerid
|
||||||
|
dispatch = dispatcher.Dispatcher()
|
||||||
|
self.ip,self.port = get_free_local_addr()
|
||||||
|
# self.server = osc_server.ThreadingOSCUDPServer( (self.ip, self.port), dispatch)
|
||||||
|
self.server = osc_server.BlockingOSCUDPServer( (self.ip, self.port), dispatch)
|
||||||
|
self.osc_dispatch = dispatch
|
||||||
|
self.commands = []
|
||||||
|
self.register_event_type('on_osc_event')
|
||||||
|
self.map('/mute',self.mute)
|
||||||
|
self.map('/pause',self.pause)
|
||||||
|
self.map('/menu',self.menu)
|
||||||
|
self.map('/up',self.up)
|
||||||
|
self.map('/down',self.down)
|
||||||
|
self.map('/left',self.left)
|
||||||
|
self.map('/right',self.right)
|
||||||
|
self.map('/play',self.play)
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def on_osc_event(self,*args):
|
||||||
|
print('PlayerOSCServer():on_osc_event():args=',args)
|
||||||
|
|
||||||
|
def menu(self,*args):
|
||||||
|
self.dispatch('on_osc_event','menu',*args)
|
||||||
|
|
||||||
|
def mute(self,*args):
|
||||||
|
self.dispatch('on_osc_event','mute',*args)
|
||||||
|
|
||||||
|
def pause(self,*args):
|
||||||
|
self.dispatch('on_osc_event','pouse',*args)
|
||||||
|
|
||||||
|
def up(self,*args):
|
||||||
|
self.dispatch('on_osc_event','up',*args)
|
||||||
|
|
||||||
|
def down(self,*args):
|
||||||
|
self.dispatch('on_osc_event','down',*args)
|
||||||
|
|
||||||
|
def left(self,*args):
|
||||||
|
self.dispatch('on_osc_event','left',*args)
|
||||||
|
|
||||||
|
def right(self,*args):
|
||||||
|
self.dispatch('on_osc_event','right',*args)
|
||||||
|
|
||||||
|
def play(self,*args):
|
||||||
|
print('play():args=',args)
|
||||||
|
d = json.loads(args[1])
|
||||||
|
self.dispatch('on_osc_event','play',d)
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.thread = Background(self.server.serve_forever)
|
||||||
|
self.thread.daemon_threads = True
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
return {
|
||||||
|
"playerid":self.playerid,
|
||||||
|
"ip":self.ip,
|
||||||
|
"port":self.port,
|
||||||
|
"commands": self.commands
|
||||||
|
}
|
||||||
|
|
||||||
|
def map(self,cmd,func):
|
||||||
|
self.commands.append(cmd)
|
||||||
|
self.osc_dispatch.map(cmd,func)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.server.shutdown()
|
||||||
|
self.server.server_close()
|
||||||
|
self.thread.join(5)
|
||||||
|
|
||||||
|
class PlayerOSCClient:
|
||||||
|
def __init__(self, ip,port):
|
||||||
|
self.client = udp_client.SimpleUDPClient(ip, port) # Create client
|
||||||
|
|
||||||
|
def play(self, mrec):
|
||||||
|
t = json.dumps(mrec)
|
||||||
|
self.client.send_message("/play", t)
|
||||||
|
|
||||||
|
def mute(self):
|
||||||
|
self.client.send_message('/mute')
|
||||||
|
|
||||||
|
def menu(self):
|
||||||
|
self.client.send_message('/menu')
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
self.client.send_message('/pause')
|
||||||
|
|
||||||
|
def up(self):
|
||||||
|
self.client.send_message('/up')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user