bugfix
This commit is contained in:
parent
b87cd5af45
commit
13fdea6429
@ -298,7 +298,7 @@ class Blocks(EventDispatcher):
|
|||||||
raise Exception(desc)
|
raise Exception(desc)
|
||||||
|
|
||||||
widgetClass = desc['widgettype']
|
widgetClass = desc['widgettype']
|
||||||
opts = desc.get('options',{}).copy()
|
opts = self.valueExpr(desc.get('options',{}).copy())
|
||||||
widget = None
|
widget = None
|
||||||
try:
|
try:
|
||||||
klass = wrap_ready(widgetClass)
|
klass = wrap_ready(widgetClass)
|
||||||
@ -329,26 +329,23 @@ class Blocks(EventDispatcher):
|
|||||||
continue
|
continue
|
||||||
setattr(widget,k,w)
|
setattr(widget,k,w)
|
||||||
continue
|
continue
|
||||||
setattr(widget,k,v)
|
setattr(widget,k,self.valueExpr(v,\
|
||||||
|
localnamespace={'self':widget}))
|
||||||
|
|
||||||
def build_rest(self, widget,desc,t=None):
|
def build_rest(self, widget,desc,t=None):
|
||||||
self.subwidget_total = len(desc.get('subwidgets',[]))
|
self.subwidget_total = len(desc.get('subwidgets',[]))
|
||||||
self.subwidgets = [ None for i in range(self.subwidget_total)]
|
self.subwidgets = [ None for i in range(self.subwidget_total)]
|
||||||
pos = 0
|
pos = 0
|
||||||
for pos,sw in enumerate(desc.get('subwidgets',[])):
|
for pos,sw in enumerate(desc.get('subwidgets',[])):
|
||||||
params={
|
|
||||||
'desc':desc,
|
|
||||||
'widget':widget,
|
|
||||||
'pos':pos
|
|
||||||
}
|
|
||||||
b = Blocks()
|
b = Blocks()
|
||||||
kw = sw.copy()
|
kw = sw.copy()
|
||||||
w = b.widgetBuild(kw)
|
w = b.widgetBuild(kw)
|
||||||
widget.add_widget(w)
|
widget.add_widget(w)
|
||||||
|
|
||||||
for b in desc.get('binds',[]):
|
for b in desc.get('binds',[]):
|
||||||
kw = b.copy()
|
kw = self.valueExpr(b.copy(), \
|
||||||
self.buildBind(widget,b)
|
localnamespace={'self':widget})
|
||||||
|
self.buildBind(widget,kw)
|
||||||
|
|
||||||
def buildBind(self,widget,desc):
|
def buildBind(self,widget,desc):
|
||||||
wid = desc.get('wid','self')
|
wid = desc.get('wid','self')
|
||||||
@ -545,7 +542,7 @@ class Blocks(EventDispatcher):
|
|||||||
desc,type(desc))
|
desc,type(desc))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
desc = self.valueExpr(desc)
|
# desc = self.valueExpr(desc)
|
||||||
widget = self.w_build(desc)
|
widget = self.w_build(desc)
|
||||||
self.dispatch('on_built',widget)
|
self.dispatch('on_built',widget)
|
||||||
if hasattr(widget,'ready'):
|
if hasattr(widget,'ready'):
|
||||||
|
@ -5,33 +5,58 @@ from oscpy.server import OSCThreadServer
|
|||||||
from oscpy.client import OSCClient
|
from oscpy.client import OSCClient
|
||||||
|
|
||||||
class OSCServer(EventDispatcher):
|
class OSCServer(EventDispatcher):
|
||||||
def __init__(self,addr='0.0.0.0', port=60405,apis=[]):
|
def __init__(self,addr='0.0.0.0',
|
||||||
|
port=60405,
|
||||||
|
apis=[]):
|
||||||
self.port = port
|
self.port = port
|
||||||
self.addr = addr
|
self.addr = addr
|
||||||
|
self.clients = []
|
||||||
self.osc_server = OSCThreadServer()
|
self.osc_server = OSCThreadServer()
|
||||||
self.osc_server.listen(self.addr,port=self.port,default=True)
|
self.osc_server.listen(self.addr,port=self.port,default=True)
|
||||||
EventDispatcher.__init__(self)
|
EventDispatcher.__init__(self)
|
||||||
|
apis.append('broadcast')
|
||||||
for api in apis:
|
for api in apis:
|
||||||
self.register_event_type(api)
|
event_name = 'on_%s' % api
|
||||||
f = partial(self.handle, api)
|
f = partial(self.handle, api)
|
||||||
setattr(self, api, f)
|
setattr(self, event_name, f)
|
||||||
|
self.register_event_type(event_name)
|
||||||
api_f = partial(self.apihandle,api)
|
api_f = partial(self.apihandle,api)
|
||||||
bstr = '/%s' % api
|
bstr = '/%s' % api
|
||||||
bstr.encode('utf-8')
|
bstr.encode('utf-8')
|
||||||
self.osc_server.bind(bstr, api_f)
|
self.osc_server.bind(bstr, api_f)
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
return {
|
||||||
|
"address":self.osc_server.getaddress()
|
||||||
|
}
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.osc_server.stop_all()
|
||||||
|
self.osc_server.terminate_server()
|
||||||
|
self.osc_server.join_server()
|
||||||
|
|
||||||
def handle(self,api,o,*args):
|
def handle(self,api,o,*args):
|
||||||
print(api, *args)
|
print(api, *args)
|
||||||
|
|
||||||
def apihandle(self, api, *args):
|
def apihandle(self, api, *args):
|
||||||
self.dispatch(api,*args)
|
data = json.loads(args[0])
|
||||||
|
sock, ip_address, response_port = self.osc_server.get_sender()
|
||||||
|
self.dispatch(api,
|
||||||
|
{'address':address,
|
||||||
|
'data':data
|
||||||
|
})
|
||||||
|
if api == 'broadcast':
|
||||||
|
return
|
||||||
|
if not address in self.clients:
|
||||||
|
self.clients.append([ip_address, response_port])
|
||||||
|
|
||||||
def sendMessage(self,api='', addr=None, port=None, *args):
|
def send_message(self,api, data, addr, port):
|
||||||
try:
|
data = json.dumps(data)
|
||||||
bstr = '/%s' % api
|
bstr = '/%s' % api
|
||||||
bstr = bstr.encode('utf-8')
|
bstr = bstr.encode('utf-8')
|
||||||
client = OSCClient(addr, port)
|
self.osc_server.send_message(b'/broadcast', [data], addr, port)
|
||||||
client.sendMessage(bstr, args)
|
|
||||||
except:
|
|
||||||
print('sendMessage error:',api, addr,port,args)
|
|
||||||
|
|
||||||
|
def broadcast(self, data):
|
||||||
|
for address in self.clients:
|
||||||
|
self.osc_server.send_message('broadcast', data, *address)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user