This commit is contained in:
yumoqing 2020-12-29 10:39:20 +08:00
parent 7304e546fa
commit 5ee7e534ff
4 changed files with 62 additions and 0 deletions

View File

@ -1,3 +1,6 @@
import os
import codecs
import locale
from kivy.app import App
from kivy.properties import StringProperty
@ -17,9 +20,28 @@ class I18n:
def addI18nWidget(self,w):
self.i18nWidgets.append(w)
def loadI18nFromI18nFolder(self, lang):
config = gtConfig()
fpath = os.path.join(config.i18n_folder,lang,'msg.txt')
with codecs.open(fpath,'r','utf-8') as f:
line = f.readline()
d = {}
while line:
if line.startswith('#'):
line = readline()
continue
k,v = line.split(':',1)
d.update({k:v})
line = readline()
return d
def loadI18n(self,lang):
app = App.get_running_app()
config = getConfig()
if config.i18n_folder:
self.kvlang[lang] = self.loadI18nFromFolder(lang)
return
url = '%s%s/%s' % (config.uihome, config.i18n_url, lang)
hc = HttpClient()
d = hc.get(url)

37
kivyblocks/osc_server.py Normal file
View File

@ -0,0 +1,37 @@
from functools import partial
from kivy.event import EventDispatcher
from kivy.clock import Clock
from oscpy.server import OSCThreadServer
from oscpy.client import OSCClient
class OSCServer(EventDispatcher):
def __init__(self,addr='0.0.0.0', port=60405,apis=[]):
self.port = port
self.addr = addr
self.osc_server = OSCThreadServer()
self.osc_server.listen(self.addr,port=self.port,default=True)
EventDispatcher.__init__(self)
for api in apis:
self.register_event_type(api)
f = partial(self.handle, api)
setattr(self, api, f)
api_f = partial(self.apihandle,api)
bstr = '/%s' % api
bstr.encode('utf-8')
self.osc_server.bind(bstr, api_f)
def handle(self,api,o,*args):
print(api, *args)
def apihandle(self, api, *args):
self.dispatch(api,*args)
def sendMessage(self,api='', addr=None, port=None, *args):
try:
bstr = '/%s' % api
bstr = bstr.encode('utf-8')
client = OSCClient(addr, port)
client.sendMessage(bstr, args)
except:
print('sendMessage error:',api, addr,port,args)

View File

@ -15,8 +15,10 @@ from .tab import TabsPanel
from .qrdata import QRCodeWidget
# from .kivycamera import KivyCamera
from .filebrowser import FileLoaderBrowser
from .osc_server import OSCServer
r = Factory.register
r('OSCServer',OSCServer)
r('DataGrid',DataGrid)
r('FileLoaderBrowser',FileLoaderBrowser)
# r('KivyCamera',KivyCamera)

View File

@ -6,3 +6,4 @@ pillow
requests
plyer
python-osc
oscpy