Browse Source

improve FixtureEditor ... EMPTY attr

micha 1 year ago
parent
commit
3a2eee6052

+ 101 - 24
_LibreLightDesk.py

@@ -122,7 +122,7 @@ import lib.motion as motion
 
 from collections import OrderedDict
 
-_FIX_FADE_ATTR = ["PAN","TILT","DIM","RED","GREEN","BLUE","CYAN","YELLOW","MAGENTA","FOCUS","ZOOM","FROST"]
+_FIX_FADE_ATTR = ["PAN","TILT","DIM","RED","GREEN","BLUE","WHITE","CYAN","YELLOW","MAGENTA","FOCUS","ZOOM","FROST"]
 
 
 _POS_LEFT = 0
@@ -3204,35 +3204,112 @@ def _fixture_load_import_list(path=None):
                 if os.path.isfile(fname):
                     ok = 1
             #fname_buffer = []
-            if ok:
-                f = open(fname)
-                lines = f.readlines()
-                f.close()
+            if not ok:
+                continue
+
+            f = open(fname)
+            lines = f.readlines()
+            f.close()
 
-                for line in lines:
-                    ok2 = 0
-                    _key = ""
-                    line = line.split("\t")
-                    jdata = json.loads(line[2])
-                    if "ATTRIBUT" in jdata:
-                        _len = len(jdata["ATTRIBUT"])
-                        _key = list(jdata["ATTRIBUT"].keys()) 
-                        _key.sort()
-                        _key = str(_key)
-                        if _key not in fname_buffer:
-                            fname_buffer.append(_key) # group same fixtures by ATTR
-                            ok2 = 1
-                    if ok2:
-                        name = jdata["NAME"]
-                        #row = [name,fname+":"+name,path])
-                        xfname = fname.replace(path,"")
-                        row = {"name":name,"xfname":xfname ,"ch":_len, "xpath":path,"d":_key} #,"b":jdata}
-                        blist.append(row)
+            for line in lines:
+                ok2 = 0
+                _key = ""
+                line = line.split("\t")
+                if len(line) < 2:
+                    continue
+                jdata = json.loads(line[2])
+
+                fixture = jdata
+                _len = str(fixture_get_ch_count(fixture))
+                if "ATTRIBUT" in jdata:
+                    #_len = len(jdata["ATTRIBUT"])
+                    #if "_ACTIVE" in jdata["ATTRIBUT"]:
+                    #    _len -= 1
+                    _key = list(jdata["ATTRIBUT"].keys()) 
+                    _key.sort()
+                    _key = str(_key)
+                    if _key not in fname_buffer:
+                        fname_buffer.append(_key) # group same fixtures by ATTR
+                        ok2 = 1
+                if ok2:
+                    name = jdata["NAME"]
+                    #row = [name,fname+":"+name,path])
+                    xfname = fname.replace(path,"")
+                    row = {"xfname":xfname ,"name":name,"ch":_len, "xpath":path,"d":_key} #,"b":jdata}
+                    blist.append(row)
         except Exception as e:
             print("exception",e)
+            raise e
     return blist
 
 
+def fixture_get_ch_count(fixture):
+    _len = [0,0]
+    if "ATTRIBUT" not in fixture:
+        return [-1,-1]
+
+    for at in fixture["ATTRIBUT"]:
+        #print(at,_len)
+        #print(" ",fixture["ATTRIBUT"][at])
+        if not at.startswith("_") and not at.startswith("EMPTY"):
+            _len[1] += 1
+
+        if "NR" in fixture["ATTRIBUT"][at]:
+            NR = fixture["ATTRIBUT"][at]["NR"]
+            if NR > _len[0]:
+                _len[0] = NR
+        #print("-",at,_len)
+
+    return _len
+
+def fixture_get_attr_data(fixture,attr):
+    if "ATTRIBUT" in fixture:
+        if attr in fixture["ATTRIBUT"]:
+            return fixture["ATTRIBUT"][attr]
+
+    if "NAME" in fixture:
+        print("  NO fixture_get_attr_data A",fixture["NAME"],attr)
+    else:
+        print("  NO fixture_get_attr_data B",fixture,attr)
+
+def fixture_order_attr_by_nr(fixture):
+    out1 = []
+    max_nr = 0
+    if "ATTRIBUT" not in fixture:
+        return []
+
+    nrs = {}
+    for at in fixture["ATTRIBUT"]:
+        #print("+   ",at)
+        atd = fixture_get_attr_data(fixture,at)
+        #print("+   ",atd)
+        if not atd:
+            continue
+
+        k = atd["NR"]
+        v = at
+        nrs[k] = v
+        if k > max_nr:
+            max_nr = k
+
+    for i in range(1,max_nr+1):
+        if i not in nrs:
+            v = "EMPTY" #-{}".format(i)
+            nrs[i] = v
+            #print("-: ",v)
+
+
+    nrs_key = list(nrs.keys())
+    nrs_key.sort()
+    #print(nrs_key)
+
+    for k in nrs_key:
+        v = nrs[k]
+        #print("-: ",k,v)
+        out1.append(v)
+
+    #print()
+    return out1 
 
 def _load_fixture_list(mode="None"):
     blist = []

+ 0 - 0
fixtures/LibreLight_VPU-COUNT-000_1ch.json → fixtures/LibreLight_VPU-COUNT.json


+ 0 - 0
fixtures/LibreLight_VPU-FUNC-000_9ch.json → fixtures/LibreLight_VPU-FUNC.json


+ 0 - 0
fixtures/LibreLight_VPU-PIX-000_4ch.json → fixtures/LibreLight_VPU-PIX.json


+ 0 - 0
fixtures/LibreLight_VPU-VPLAY-000_9ch.json → fixtures/LibreLight_VPU-VPLAY.json


+ 0 - 0
fixtures/Martin_RushMH3_19ch.sav → fixtures/Martin_RushMH3.sav


+ 0 - 0
fixtures/generic_dimmer_1ch.sav → fixtures/generic_dimmer.sav


+ 1 - 0
fixtures/generic_irgb.sav

@@ -0,0 +1 @@
+1001	1001	{"DMX": 401, "UNIVERS": 2, "NAME": "iRGB", "ATTRIBUT": {"DIM": {"NR": 1, "MASTER": "1", "MODE": "F", "VALUE": 0.0, "ACTIVE": 0}, "RED": {"NR": 2, "MASTER": "", "MODE": "F", "VALUE": 255.0, "ACTIVE": 0}, "GREEN": {"NR": 3, "MASTER": "", "MODE": "F", "VALUE": 255.0, "ACTIVE": 0}, "BLUE": {"NR": 4, "MASTER": "", "MODE": "F", "VALUE": 127.0, "ACTIVE": 0}}}

+ 0 - 1
fixtures/generic_irgb_4ch.sav

@@ -1 +0,0 @@
-1001	1001	{"DMX": 401, "UNIVERS": 2, "NAME": "RGB", "ATTRIBUT": {"VDIM": {"NR": -1, "MASTER": "1", "MODE": "F", "VALUE": 0.0, "ACTIVE": 0}, "RED": {"NR": 1, "MASTER": "", "MODE": "F", "VALUE": 255.0, "ACTIVE": 0}, "GREEN": {"NR": 2, "MASTER": "", "MODE": "F", "VALUE": 255.0, "ACTIVE": 0}, "BLUE": {"NR": 3, "MASTER": "", "MODE": "F", "VALUE": 127.0, "ACTIVE": 0}}}

+ 0 - 0
fixtures/generic_rgbv_3ch.sav → fixtures/generic_rgbv.sav


+ 102 - 30
tkgui/GUI.py

@@ -806,23 +806,27 @@ def GUI_LOAD_FIXTURE_LIST(frame,data={"EMPTY":"None"},cb=None,bg="black"):
 
         bg="lightgrey"
         #dbg="grey"
-        b = tk.Button(frame,text=r+1,anchor="w",bg=dbg,width=6,relief="sunken")
+        b = tk.Button(frame,text=r+1,anchor="w",bg=dbg,width=6,height=1,relief="sunken")
         b.grid(row=r+1, column=c, sticky=tk.W ) #+tk.E)
         c+=1
-        bg="grey"
-        dbg="grey"
+        bg="lightgrey"
+        dbg="lightgrey"
         for k,v in row.items():
             #if v > time.strftime("%Y-%m-%d %X",  time.localtime(time.time()-3600*4)):
             #    dbg = "lightgreen"
             #elif v > time.strftime("%Y-%m-%d %X",  time.localtime(time.time()-3600*24*7)):
             #    dbg = "green"
+            if "." in v:
+                #v = v.split(".",-1)
+                v = v[::1].split(".",1)[0]#[::-1]
 
-
-            if c == 2:
+            if c == 3:
+                bg="grey"
+                dbg="grey"
                 _cb2 = _M.BaseCallback(cb=cb,args={"key":k,"val":v,"data":row}).cb
                 b = tk.Button(frame,text=v,anchor="w",height=1,bg=bg,command=_cb2)
             else: 
-                b = tk.Button(frame,text=v,anchor="w",bg=dbg,relief="flat")
+                b = tk.Button(frame,text=v,anchor="w",bg=dbg,relief="flat",height=1)
                 b.config(activebackground=dbg)
             b.grid(row=r+1, column=c, sticky=tk.W+tk.E)
             c+=1
@@ -864,7 +868,7 @@ class GUI_FixtureEditor():
         self.frame.pack(fill="both", side=tk.RIGHT)#EFT)
 
         bg = "lightblue"
-        self.b = tk.Button(self.frame,bg=bg,text="IMPORT", width=5)#,command=self.event) #bv.change_dmx)
+        self.b = tk.Button(self.frame,bg=bg,text="IMPORT FROM SHOW", width=20)#,command=self.event) #bv.change_dmx)
         self.b["command"] = self.open_fixture_list_import
         self.b.pack( side=tk.LEFT)
 
@@ -1027,7 +1031,7 @@ class GUI_FixtureEditor():
                     frameS = tk.Frame(self.frame,bg="#a0aadd",width=width,border=2)
                 self.c=0
 
-            e= ELEM_FADER(frameS,nr=j+1,cb=self._cb,fader_cb=self._fader_cb)
+            e=  ELEM_FADER(frameS,nr=j+1,cb=self._cb,fader_cb=self._fader_cb)
             e.pack()
             #e.attr["bg"] = "red"
             self.fader_elem.append(e)
@@ -1044,13 +1048,21 @@ class GUI_FixtureEditor():
             a1 = arg #arg[2]
             nr = args["nr"] #.nr
             j=[]
+            e = self.fader_elem[args["nr"]-1]
+            nr = int(e.elem_nr["text"]) 
+            if not nr:
+                nr = args["nr"]
+            nr_start = ( int(self.entry_dmx["text"])-1 + int(self.entry_univ["text"])*512 )
+            nr += nr_start
+
             jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(nr)}
-            ##print("   ",jdata)
+            print("   ",jdata)
             j.append(jdata)
             jclient_send(j)
         except Exception as e:
-            print("exec",arg,args)
+            print("exec",arg,args,nr)
             print(e)
+            raise e
 
     def _cb(self,arg,name="<name>",**args):
         #print(" FixtureEditor._cb")
@@ -1070,8 +1082,12 @@ class GUI_FixtureEditor():
             txt = elem.attr["text"]
             if txt:
                 #print("count_ch:",i,txt)
-                elem.attr["bg"] = "#0f0"
-                elem.attr["activebackground"] = "#0fa"
+                if txt.startswith("EMPTY"):
+                    elem.attr["bg"] = "#fa0"
+                    elem.attr["activebackground"] = "#fa0"
+                else:
+                    elem.attr["bg"] = "#0f0"
+                    elem.attr["activebackground"] = "#0fa"
                 ch_s.append([i,txt])
                 j=i
             else:
@@ -1161,8 +1177,10 @@ class GUI_FixtureEditor():
             self.name["text"] = data["name"] #"load_MH2"
             xpath = data["xpath"] + "/" + data["xfname"]
             fdata = _M._read_sav_file(xpath)
+            n = []
             a = []
             m = []
+            NR = 0
             for row in fdata:
                 #print("row:  ",row.keys())
                 #print("a-")
@@ -1175,14 +1193,31 @@ class GUI_FixtureEditor():
 
                     print("a    :",k,str(fixture)[:220],"...")
                     #print("a    ::",type(k),":",type(fixture))
+
+
+                    attr_by_nr = _M.fixture_order_attr_by_nr(fixture)
+
                     if "ATTRIBUT" in fixture:
-                        for at in fixture["ATTRIBUT"]:
+                        for at in attr_by_nr: #fixture["ATTRIBUT"]:
+                            print("   ",at)
+                            if at.startswith("EMPTY"):
+                                NR += 1
+                                n.append(str(NR))
+                                a.append(at)
+                                m.append("-")
+                                continue
+                            print("       ",fixture["ATTRIBUT"][at])
+
                             if at.startswith("_"):
                                  continue
                             try:
-                                a.append(at +":"+ str(fixture["ATTRIBUT"][at]["NR"]))
+                                NR = fixture["ATTRIBUT"][at]["NR"]
+                                n.append(str(NR))
                             except:
-                                a.append(at ) 
+                                n.append("-") 
+                            
+                            a.append(at ) #+":"+ str(fixture["ATTRIBUT"][at]["NR"]))
+
                             if at.endswith("-FINE"):
                                 m.append("-")
                             elif at in _M._FIX_FADE_ATTR: #["PAN","TILT","DIM","RED","GREEN","BLUE","CYAN","YELLOW","MAGENTA","FOCUS","ZOOM","FROST"]:
@@ -1193,7 +1228,7 @@ class GUI_FixtureEditor():
 
                     break # only a single fixture #no sub fixture
 
-            self._load_fix(None,a,m)
+            self._load_fix(None,n,a,m)
             self.close_fixture_list()
 
         blist = _M._load_fixture_list(mode=mode)
@@ -1256,18 +1291,26 @@ class GUI_FixtureEditor():
         self._load_fix(None,attr,mode)
         self.close_fixture_list()
 
-    def _load_fix(self,_event=None,attr=[],mode=[]):
+    def _load_fix(self,_event=None,nrs=[],attr=[],mode=[]):
         print("load_fixture",[_event,self])
         #for i,e in enumerate(self.elem):
         for i,e in enumerate(self.elem):
             #print(self,"event",_event,e)
             #print("event",_event,e)
-            e._set_attr( "")
+            if len(attr) > i:
+                e._set_nr( nrs[i])
+            else:
+                e._set_nr( "")
+
             if len(attr) > i:
                 e._set_attr( attr[i])
-            e._set_mode( "---")
+            else:
+                e._set_attr( "")
+
             if len(mode) > i:
                 e._set_mode( mode[i]+"'")
+            else:
+                e._set_mode( "---")
         self.count_ch() 
 
     def event_univ(self,_event=None):
@@ -1320,8 +1363,8 @@ class GUI_FixtureEditor():
     def _event_redraw(self,_event=None):
         self.entry_dmx["text"] = "{}".format(self.dmx)
         self.entry_univ["text"] = "{}".format(self.univ)
-        nr = self.univ*(512)+self.dmx
-        self.b_xdmx["text"] = " {}  ".format(nr)
+        nr = 1 # self.univ*(512)+self.dmx # multiplay fader nr with dmx...
+        # self.b_xdmx["text"] = " {}  ".format(nr)
 
         print("change_dmx",[_event,self])
         for i,btn in enumerate(self.elem):
@@ -1389,6 +1432,19 @@ class ELEM_FADER():
         if self._cb:
             self._cb([self,"event",a1,a2])
 
+    def set_nr(self,_event=None):
+        txt= self.elem_nr["text"]
+        def _cb(data):
+            if not data:
+                print("err443",self,"_cb",data)
+                return None
+            txt = data["Value"]
+            self._set_nr(txt)
+            if self._cb:
+                self._cb([self,"set_nr",txt])
+        dialog._cb = _cb
+        dialog.askstring("ATTR","set NR:",initialvalue=txt)
+
     def set_attr(self,_event=None):
         txt= self.attr["text"]
         def _cb(data):
@@ -1403,13 +1459,6 @@ class ELEM_FADER():
         dialog._cb = _cb
         dialog.askstring("ATTR","set attr:",initialvalue=txt)
         
-    def _set_attr(self,txt=""):
-        if type(txt) is str:
-            self.attr["text"] = "{}".format(txt)
-            #print("_set_attr",[self])
-        if self._cb:
-            self._cb([self,"_set_attr",txt])
-
     def set_label(self,name=""):
         #print("set_label",self.b,name)
         self.label["text"] = name
@@ -1433,6 +1482,28 @@ class ELEM_FADER():
         dialog._cb = _cb
         dialog.askstring("MODE S/F:","SWITCH or FADE",initialvalue=txt)
 
+    def _set_nr(self,txt=""):
+        if type(txt) is str:
+            try: 
+                x = int(txt)
+                if x <= 0:
+                    txt = "off"
+                    self.attr["bg"] = "#fa0"
+                    self.elem_nr["bg"] = "#fa0"
+            except:pass
+            self.elem_nr["text"] = "{}".format(txt)
+        if self._cb:
+            self._cb([self,"_set_nr",txt])
+
+    def _set_attr(self,txt=""):
+        if type(txt) is str:
+            self.attr["text"] = "{}".format(txt)
+            if txt.startswith("EMPTY"):
+                self.attr["bg"] = "#fa0"
+        if self._cb:
+            self._cb([self,"_set_attr",txt])
+
+
     def _set_mode(self,txt=""):
         if type(txt) is str:
             txt = txt[0].upper()
@@ -1443,6 +1514,7 @@ class ELEM_FADER():
 
     def _refresh(self):
         pass
+
     def pack(self,init=None,from_=255,to=0,**args):
         width=11
         r=0
@@ -1462,8 +1534,8 @@ class ELEM_FADER():
             self.b.set(init)
         self.elem.append(self.b)
         
-        self.b = tk.Button(frameS,bg="lightblue",text="0", width=4,command=self.set_mode,font=self.font8 )
-        self.elem_fix_id=self.b
+        self.b = tk.Button(frameS,bg="lightblue",text="0", width=4,command=self.set_nr,font=self.font8 )
+        self.elem_nr=self.b
         self.b.pack(fill=tk.BOTH, side=tk.TOP)
         self.elem.append(self.b)