from tkinter import * from tkinter import ttk from functools import partial import pyOSC3 from pyOSC3 import OSCString import time from bs4 import BeautifulSoup import requests import json import threading toBeRemoved = "testDelay" #patchname to be removed tobeLoaded = "" # patchname to be loaded loadedList = [] # list of loaded patchers tijdF = "" # formatted time string tijdJ = "" # formatted string Y M D updateTimeSec = 1 # update time every x sec url = 'http://127.0.0.1:5678/rnbo/patchers'#*****Soup init (read from Cycling file) #******************************************** functions class RepeatTimer(threading.Timer):#********* regulary update time def run(self): while not self.finished.wait(self.interval): self.function(*self.args,**self.kwargs) def updateTime():#*************************** regulary update time timeInit() labelT.config(text=tijdF) def cb_Load(): global tobeLoaded osc_gotoPatch.append(tobeLoaded,typehint = 's') c.send(osc_gotoPatch) weg = osc_gotoPatch.pop(1)#****************************************de 0 laten staan nameS.config(text=tobeLoaded) osc_loadedPatch.append(tobeLoaded,typehint = 's') #***************stuur naarhw vertaling cl.send(osc_loadedPatch) weg = osc_loadedPatch.pop(0) def cb_Remove(): global loadedList osc_removePatch.setAddress("/rnbo/patchers/"+toBeRemoved+"/destroy") c.send(osc_removePatch) soupInit() # renew entries loaded patchers combobox patchnames.config(values=loadedList) def cb_patchnames(w): global tobeLoaded tobeLoaded = patchnames.get() def soupInit(): global loadedList response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') soupTxt = soup.prettify() my_dict = json.loads(soupTxt) keysList = list(my_dict.keys()) my_cont = my_dict.get(keysList[2]) loadedList = list(my_cont.keys()) def timeInit(): global tijdF,tijdJ tijd = time.localtime() jaar = time.strftime('%Y',tijd) maand = time.strftime('%h',tijd) dag = time.strftime('%d',tijd) uur = time.strftime('%H',tijd) minuut = time.strftime('%M',tijd) seconde = time.strftime('%S',tijd) tijdF = uur+":"+minuut+":"+seconde tijdJ = dag+" "+maand+" "+jaar #******************************************** init c = pyOSC3.OSCClient() c.connect(('127.0.0.1',1234))#***************port to reach Cycling RNBO to change loaded file and remove file osc_gotoPatch = pyOSC3.OSCMessage() osc_gotoPatch.setAddress("/rnbo/inst/control/load") osc_gotoPatch.append(0)#******************** extra 0 nodig voor pathernaam osc_removePatch = pyOSC3.OSCMessage() osc_removePatch.setAddress("/rnbo/patchers/"+toBeRemoved+"/destroy") cl = pyOSC3.OSCClient() cl.connect(('127.0.0.1',9876))#***************port to reach Cycling RNBO to change loaded file and remove file osc_loadedPatch = pyOSC3.OSCMessage() osc_loadedPatch.setAddress("/PL/rnbo/loadedPatch") soupInit() timeInit() t = RepeatTimer(updateTimeSec, updateTime) t.start() #******************************************** hui wdw = Tk() wdw.title("PL RNBO control") wdw.geometry ('220x250') pempty1 = Label(wdw,height=1) pempty1.pack() pFr = Frame(wdw) pFr.pack(fill = BOTH) bLoad = Button(pFr,text="load",command=cb_Load) bRemove = Button(pFr,text="remove",command=cb_Remove) bLoad.pack(side = LEFT) bRemove.pack(side = RIGHT) pempty2 = Label(wdw,height=1) pempty2.pack() CBvals = loadedList.copy() patchnames = ttk.Combobox(wdw,height=10,width=20,values=CBvals) patchnames.bind('<>',cb_patchnames) patchnames.pack() pempty3 = Label(wdw,height=1) pempty3.pack() nameL = Label(wdw,text="loaded patch:") nameS = Label(wdw,text="---",font=("Arial",14)) nameL.pack() nameS.pack() pempty4 = Label(wdw,height=1) pempty4.pack() labelD = Label(wdw,text=tijdJ) labelD.pack() labelT = Label(wdw,text=tijdF,font=("Arial",20)) labelT.pack() wdw.mainloop()