This commit is contained in:
yumoqing 2021-07-13 16:14:31 +08:00
parent 86d2f0cd7a
commit 169e98469c
3 changed files with 99 additions and 12 deletions

View File

@ -33,10 +33,12 @@ if kivy.platform in ['win','linux', 'macosx']:
from .camerawithmic import ScreenWithMic from .camerawithmic import ScreenWithMic
from .camerawithmic import CameraWithMic from .camerawithmic import CameraWithMic
from .scrollpanel import ScrollPanel from .scrollpanel import ScrollPanel
from .udp_widget import UdpWidget
r = Factory.register r = Factory.register
if kivy.platform in ['win','linux', 'macosx']: if kivy.platform in ['win','linux', 'macosx']:
r('ScreenWithMic', ScreenWithMic) r('ScreenWithMic', ScreenWithMic)
r('UdpWidget', UdpWidget)
r('ScrollPanel', ScrollPanel) r('ScrollPanel', ScrollPanel)
r('TextInput', TextInput) r('TextInput', TextInput)
r('CameraWithMic', CameraWithMic) r('CameraWithMic', CameraWithMic)

View File

@ -64,9 +64,6 @@ class NodeTrigger(ButtonBehavior, EmptyBox):
self.showOpenStatus() self.showOpenStatus()
def on_press(self, *args): def on_press(self, *args):
Logger.info('NodeTrigger:on_press() called, open_status=%s',
self.open_status
)
self.open_status = False if self.open_status else True self.open_status = False if self.open_status else True
# self.showOpenStatus() # self.showOpenStatus()
@ -77,7 +74,6 @@ class NodeTrigger(ButtonBehavior, EmptyBox):
self.showOpenStatus() self.showOpenStatus()
def showOpenStatus(self): def showOpenStatus(self):
Logger.info('NodeTrigger:showOpenStatus() called')
points = self.close_points points = self.close_points
if self.open_status: if self.open_status:
points = self.open_points points = self.open_points
@ -181,14 +177,12 @@ class TreeNode(BoxLayout):
return return
if self.data.children is None: if self.data.children is None:
Logger.info('Tree : is a leaf node')
return return
if self.data.children == []: if self.data.children == []:
self.treeObj.getUrlData(self.addChildren,self.data) self.treeObj.getUrlData(self.addChildren,self.data)
return return
if len(self.nodes) == 0: if len(self.nodes) == 0:
Logger.info('Tree : add subnodes')
self.addChildren(self.data.children) self.addChildren(self.data.children)
else: else:
Logger.info('Tree : not need add subnodes') Logger.info('Tree : not need add subnodes')
@ -492,11 +486,6 @@ class TextTree(Tree):
class MenuTreeNode(TextTreeNode): class MenuTreeNode(TextTreeNode):
def on_size(self, *args): def on_size(self, *args):
Logger.info('%s:on_size(),bgcolor=%s, fgcolor=%s,css=%s',
self.__class__.__name__,
self.content.bgcolor,
self.content.fgcolor,
self.content.csscls)
self.node_box.width = self.width self.node_box.width = self.width
self.content.width = self.node_box.width - self.trigger.width self.content.width = self.node_box.width - self.trigger.width
self.text_widget.width = self.content.width - CSize(1) self.text_widget.width = self.content.width - CSize(1)
@ -632,7 +621,6 @@ class PopupMenu(BoxLayout):
Logger.info('PopupMenu: on_press fired') Logger.info('PopupMenu: on_press fired')
def onMenuItemTouch(self,o,d=None,v=None): def onMenuItemTouch(self,o,d=None,v=None):
Logger.info('MenuTree: on_press fired,o=%s,d=%s,v=%s',o,d,v)
data = { data = {
'target':self.treeObj.target, 'target':self.treeObj.target,
'menudata':d 'menudata':d

97
kivyblocks/udp_widget.py Normal file
View File

@ -0,0 +1,97 @@
import time
from kivy.event import EventDispatcher
from appPublic.udp_comm import UdpComm
from appPublic.dataencoder import DataEncoder
class UdpWidget(EventDispatcher):
def __init__(self, udp_port=55000, cert_file=None, commands=[],
**kw):
super(UdpWidget, self).__init__(**kw)
self.udp_port = udp_port
self.commands = commands
self.block_commands = []
self.udp_transport = UdpComm(udp_port, self.comm_callback)
host = self.upd_transport.host
self.dataencoder = DataEncoder(host, self.get_peer_pubkey)
self.inner_handlers = {
'get_pubkey':self.resp_pubkey
}
for cmd in self.commands:
evt_name = 'on_%s' % cmd
setattr(self, evt_name, self.event_handler)
self.register_event_type(evt_name)
def block_command(self, cmd):
if cmd not in self.command:
return
if cmd in self.block_command:
return
self.block_commands.append(cmd)
def unblock_command(self, cmd):
if cmd not in self.block_command:
return
self.block_commands = [ c for c in self.block_command if c!=cmd ]
def get_peer_pubkey(self, peer_id, timeout=2):
d = {
'c':'get_pubkey',
'd':{
'pubkey':self.dataencoder.my_text_publickey()
}
}
b = json.dumps(d).encode('utf-8')
self.udp_tranport.broadcast(b)
t1 = time.time()
t = t1
t1 += timeout
while t1 > t:
time.sleep(0.1)
t = time.time()
if self.dataencoder.exist_peer_publickeys():
return
raise Exception('timeout')
def comm_callback(self, data, addr):
d = None
if data[:18] == b'0x00' * 18:
data = data[18:]
try:
d = json.loads(data.decode('utf-8'))
except Exception as e:
print(e, addr, data)
print_exc()
return
else:
d = self.dataencoder.unpack(addr[0], data)
if d is None:
return
if not isinstance(d, dict):
return
cmd = d['c']
f = self.inner_handler(cmd)
if f:
f(d, addr)
return
if cmd in self.block_commands:
return
evt_name = 'on_%s' % cmd
evt_data = {
'data': d,
'addr': addr
}
self.dispatch(evt_name, evt_data)
def event_handler(self, o, d):
Logger.info('UdpWidget: received data=%s', d)
def resp_pubkey(self, data, addr):
pk = data['d']['pubkey']
id = addr[0]
self.dataencoder.set_peer_text_pubkey(id, pk)
def send(self, peer_id, data):
d = self.dataencoder.pack(peer_id, data)
addr = (peer_id, self.udp_port)
self.udp_transport.send(d, addr)