_LibreLightDesk.py 216 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This file is part of LibreLight.
  5. LibreLight is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, version 2 of the License.
  8. LibreLight is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with LibreLight. If not, see <http://www.gnu.org/licenses/>.
  14. (c) 2012 micha@uxsrv.de
  15. """
  16. import random
  17. rnd_id = str(random.randint(1000,9000))
  18. rnd_id += " beta 22.10 "
  19. import subprocess
  20. import string
  21. _gcmd=['git', 'rev-parse', '--short', 'HEAD']
  22. try:
  23. r = subprocess.check_output(_gcmd)
  24. rnd_id += r.decode('ascii').strip()
  25. except Exception as e:
  26. rnd_id += " no git"
  27. #rnd_id += " ".join(_gcmd) +str(e)
  28. try:
  29. xtitle = __file__
  30. except:
  31. xtitle = "__file__"
  32. if "/" in xtitle:
  33. xtitle = xtitle.split("/")[-1]
  34. import sys
  35. sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
  36. import json
  37. import time
  38. import sys
  39. import os
  40. import _thread as thread
  41. import traceback
  42. import tkinter
  43. import tkinter as tk
  44. from tkinter import font
  45. space_font = None
  46. import tkinter.simpledialog
  47. from idlelib.tooltip import Hovertip
  48. _global_short_key = 1
  49. class DialogEvent():
  50. def __init__(self):
  51. self.el = None
  52. self.e_txt = None
  53. self.master = None
  54. def _event(self,event,**args):
  55. print(self,"_event",event)
  56. if 10:#else:
  57. input_event_blocker.set( self.e , self.e_txt)
  58. input_event_blocker.event(event) #,args)
  59. if "keysym" in dir(event):
  60. if event.keysym == "Return":# or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  61. self.master.ok()
  62. elif event.keysym == "Escape":
  63. self.master.close()
  64. else:
  65. self.el.focus()
  66. class Dialog():
  67. def __init__(self):
  68. self.d = tkinter.simpledialog
  69. self._exit = None
  70. self._cb = self.dummy_cb
  71. self.data = {"Value:",None}
  72. #self.tk = tkinter.Toplevel()
  73. def dummy_cb(self,_return):
  74. print("dialog.dummy_cb()",self,_return)
  75. pass
  76. def askstring(self,title="title",prompt="prompt:",initialvalue=""):
  77. old = 0
  78. if old:
  79. title = "*"+title
  80. txt = self.askstring_old(title=title,prompt=prompt,initialvalue=initialvalue)
  81. self._exit = {"Value":txt}
  82. self.data = {"Value":txt}
  83. self._cb(self._exit)
  84. else:
  85. title = "#"+title
  86. self.askstring_new(title=title,prompt=prompt,initialvalue=initialvalue)
  87. def askstring_old(self,title="title",prompt="prompt:",initialvalue=""):
  88. print(self.d)
  89. print(dir(self.d))
  90. txt = self.d.askstring(title=title,prompt=prompt,initialvalue=initialvalue)
  91. return txt
  92. def _close(self):
  93. print("dialog._close()",self._exit)
  94. self.tk.destroy()
  95. def close(self):
  96. self._close()
  97. time.sleep(0.1)
  98. input_event_blocker.unlock()
  99. self._cb(None)
  100. return {} #self._exit
  101. def ok(self):
  102. _data = {}
  103. for k,e in self.data.items():
  104. #print(k,dir(e))
  105. if e is not None:
  106. _data[k] = e.get()
  107. if "Value" not in _data:
  108. _data["Value"] = None
  109. #t=self.e_txt.get()#[:-1]
  110. #if "=" in t:
  111. # t = t.split("=")[0]
  112. #self._exit = t
  113. self._exit = _data
  114. self._close()
  115. time.sleep(0.1)
  116. input_event_blocker.unlock()
  117. print(self,"ok()",self._exit)
  118. self._cb(self._exit)
  119. def _event(self,event,**args):
  120. print(self,"_event",event)
  121. if 0:#else:
  122. input_event_blocker.set( self.e , self.e_txt)
  123. input_event_blocker.event(event) #,args)
  124. if "keysym" in dir(event):
  125. if event.keysym == "Return":# or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  126. self.ok()
  127. if 1:# _global_short_key == 0:
  128. if event.keysym == "Escape":
  129. self.close()
  130. def event(self,event,**args):
  131. print(self,"event",event)
  132. if 1:#else:
  133. input_event_blocker.set( self.e , self.e_txt)
  134. input_event_blocker.event(event) #,args)
  135. if "keysym" in dir(event):
  136. if event.keysym == "Return":# or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  137. self.ok()
  138. if _global_short_key == 0:
  139. if event.keysym == "Escape":
  140. self.close()
  141. def ask_exec_config(self,prompt="",_cb=None,**args):
  142. print(self,"ask_exec_config()")
  143. print([prompt,args])
  144. self.data = {"Value:":None}
  145. self._exit = None
  146. try:
  147. self.close()
  148. except Exception as e:print(e)
  149. #self.tk = tkinter.Tk()
  150. self.tk = tkinter.Toplevel()
  151. #self.tk.withdraw() # do not draw
  152. self.tk.iconify()
  153. self.tk.geometry("450x200") #.format(120+c))
  154. self.tk.title("{} EXEC-CONFIG".format(prompt) )#+" "+":"+str(rnd_id))
  155. self.tk.attributes('-topmost',True)
  156. self.tk.protocol("WM_DELETE_WINDOW", self.close)
  157. self.tk.resizable(0,0)
  158. bg = "#e0e"
  159. bg = "#cd5"
  160. bg = "lightgrey"
  161. self.tk["bg"] = bg
  162. #self.tk.overrideredirect(1)
  163. #self.tk.attributes('-toolwindow', True)
  164. #self.tk.state(newstate='iconic')
  165. self.fo = tk.Frame(self.tk,bd=1) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  166. self.fo["bg"] = "red"
  167. self.fo["bg"] = "#eee"#lightgrey"
  168. self.fo.pack(side="top")
  169. self.fl = tk.Frame(self.fo,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  170. self.fl["bg"] = "green"
  171. self.fl["bg"] = "#eee"#lightgrey"
  172. self.fl.pack(side="left")
  173. self.fm = tk.Frame(self.fo,width=20,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  174. self.fm["bg"] = "#eee"#lightgrey"
  175. self.fm.pack(side="left",expand=1,fill="y")
  176. self.fr = tk.Frame(self.fo,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  177. self.fr["bg"] = "blue"
  178. self.fr["bg"] = "#eee"#lightgrey"
  179. self.fr.pack(side="left")
  180. # ------------------------- frame right
  181. from_= 255
  182. to = 0
  183. self.ff = tk.Frame(self.fr,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  184. self.ff["bg"] = "#99a"
  185. self.ff.pack(side="left")
  186. self.b = tk.Scale(self.ff,bg="lightblue", width=28,from_=from_,to=to,command=self._event)
  187. self.data["Master"] = self.b
  188. self.data["Master"].set(100)
  189. k = "HTP-MASTER"
  190. if "cfg" in args and k in args["cfg"]:
  191. #self.data["Master"].config(state="active")
  192. self.data["Master"].set(int(args["cfg"][k]))
  193. self.data["Master"].config(state="disable")
  194. self.b.pack(side="top") #fill=tk.Y, side=tk.TOP)
  195. self.el = tk.Button(self.ff,text="Master",bg="lightblue",width=4)
  196. myTip = Hovertip(self.el,'HTP-MASTER')
  197. self.el.pack(side="top")
  198. from_= 200
  199. self.ff = tk.Frame(self.fr,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  200. self.ff["bg"] = "#99a"
  201. self.ff.pack(side="left")
  202. self.b = tk.Scale(self.ff,bg="lightblue",width=28,from_=from_,to=to,command=self._event)
  203. self.data["Size"] = self.b
  204. k = "SIZE-MASTER"
  205. if "cfg" in args and k in args["cfg"]:
  206. #self.data["Size"].config(state="active")
  207. self.data["Size"].set(int(args["cfg"][k]))
  208. self.data["Size"].config(state="disable")
  209. self.b.pack(side="top") #fill=tk.Y, side=tk.TOP)
  210. self.el = tk.Button(self.ff,text="Size",bg="lightblue",width=4)
  211. myTip = Hovertip(self.el,'SIZE-MASTER')
  212. self.el.pack(side="top")
  213. from_= 400
  214. self.ff = tk.Frame(self.fr,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  215. self.ff["bg"] = "#99a"
  216. self.ff.pack(side="left")
  217. self.b = tk.Scale(self.ff,bg="lightblue", width=28,from_=from_,to=to,command=self._event)
  218. self.data["Speed"] = self.b
  219. k = "SPEED-MASTER"
  220. if "cfg" in args and k in args["cfg"]:
  221. self.data["Speed"].set(int(args["cfg"][k]))
  222. self.data["Speed"].config(state="disable")
  223. self.b.pack(side="top") #fill=tk.Y, side=tk.TOP)
  224. self.el = tk.Button(self.ff,text="Speed",bg="lightblue",width=4)
  225. myTip = Hovertip(self.el,'SPEED-MASTER')
  226. self.el.pack(side="top")
  227. from_= 400
  228. self.ff = tk.Frame(self.fr,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  229. self.ff["bg"] = "#99a"
  230. self.ff.pack(side="left")
  231. self.b = tk.Scale(self.ff,bg="lightblue", width=28,from_=from_,to=to,command=self._event)
  232. self.data["Offset"] = self.b
  233. k = "OFFSET-MASTER"
  234. if "cfg" in args and k in args["cfg"]:
  235. #self.data["Offset"].config(state="active")
  236. self.data["Offset"].set(int(args["cfg"][k]))
  237. self.data["Offset"].config(state="disable")
  238. self.b.pack(side="top") #fill=tk.Y, side=tk.TOP)
  239. self.el = tk.Button(self.ff,text="Offset",bg="lightblue",width=4)
  240. myTip = Hovertip(self.el,'OFFSET-MASTER')
  241. self.el.pack(side="top")
  242. #self.f = tk.Frame(self.fl) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  243. #self.f.pack(side="top")
  244. #self.elx = tk.Label(self.f,text="")
  245. #self.elx["bg"] = bg
  246. #self.elx.pack(side="left")
  247. # ----------------------------------- frame left
  248. self.f = tk.Frame(self.fl) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  249. self.f.pack(side="top")
  250. self.el = tk.Label(self.f,text=str("NR:"),anchor="w",width=8)
  251. self.el["bg"] = bg
  252. self.el.pack(side="left",expand=1,fill="y")
  253. self.el = tk.Label(self.f,text=str(prompt),anchor="w",width=12)
  254. self.el["bg"] = bg
  255. self.el.pack(side="left",expand=1,fill="y")
  256. self.f2 = tk.Frame(self.fl)
  257. self.f2.pack(side="top",expand=1,fill="y")
  258. self.data["Fade"] = tk.StringVar()
  259. self.el = tk.Label(self.f2,text="Fade",anchor="w",width=8)
  260. self.el.pack(side="left")
  261. self.e = tk.Entry(self.f2,state="disable",textvariable=self.data["Fade"],width=12)
  262. print("---",self.data["Fade"].get())
  263. if "cfg" in args and "FADE" in args["cfg"]:
  264. self.data["Fade"].set(str(args["cfg"]["FADE"]))
  265. print("---",self.data["Fade"].get())
  266. #self.e["bg"] = "#eee"
  267. self.e.config(highlightthickness=2)
  268. self.e.config(highlightcolor= "red")
  269. #self.e.icursor(999)
  270. #self.e.selection_range(0, 999)#"end")
  271. self.e.bind("<Key>",self._event)
  272. self.e.bind("<Button>",self._event)
  273. self.e.pack(side="left")
  274. self.e1 = self.e
  275. self.f2 = tk.Frame(self.fl)
  276. self.f2.pack(side="top",expand=1,fill="y")
  277. self.data["Delay"] = tk.StringVar()
  278. self.el = tk.Label(self.f2,text="Delay",anchor="w",width=8)
  279. self.el.pack(side="left")
  280. self.e = tk.Entry(self.f2,state="disable",textvariable=self.data["Delay"],width=12)
  281. if "cfg" in args and "DELAY" in args["cfg"]:
  282. self.data["Delay"].set(str(args["cfg"]["DELAY"]))
  283. #self.e["bg"] = "#eee"
  284. self.e.config(highlightthickness=2)
  285. self.e.config(highlightcolor= "red")
  286. #self.e.icursor(999)
  287. #self.e.selection_range(0, 999)#"end")
  288. self.e.bind("<Key>",self._event)
  289. self.e.bind("<Button>",self._event)
  290. self.e.pack(side="left")
  291. self.e2 = self.e
  292. self.f2 = tk.Frame(self.fl)
  293. self.f2.pack(side="top",expand=1,fill="y")
  294. self.el = tk.Label(self.f2,text="Button",anchor="w",width=8)
  295. self.el.pack(side="left")
  296. self.e_txt = tk.StringVar()
  297. #self.e = tk.Entry(self.f2,textvariable=self.e_txt,width=6)
  298. #dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  299. self.e = tk.OptionMenu(self.f2,self.e_txt,"FL", "SEL", "GO","ON") #,width=6)
  300. self.data["Button"] = self.e_txt
  301. self.e["width"] = 9
  302. #self.e["bg"] = "#eee"
  303. self.e.config(highlightthickness=2)
  304. self.e.config(highlightcolor= "red")
  305. #self.e_txt.set(str(initialvalue)+"<")
  306. self.e_txt.set(str(""))
  307. #self.e.icursor(999)
  308. #self.e.selection_range(0, 999)#"end")
  309. ev1 = DialogEvent()
  310. ev1.e = self.e
  311. ev1.master = self
  312. ev1.e_txt = self.data["Button"]
  313. self.e.bind("<Key>",ev1._event)
  314. self.e.bind("<Button>",ev1._event)
  315. self.e.pack(side="left")
  316. if "button" in args and type(args["button"]) is str:
  317. self.e_txt.set(args["button"]) # default value
  318. self.e3 = self.e
  319. del self.e_txt
  320. del ev1
  321. self.f = tk.Frame(self.fl) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  322. self.f.pack(side="top")
  323. self.f2 = tk.Frame(self.f)
  324. self.f2.pack(side="top",expand=1,fill="y")
  325. self.data["Label"] = tk.StringVar()
  326. self.el = tk.Label(self.f2,text="Label",anchor="w",width=8)
  327. self.el.pack(side="left")
  328. self.e = tk.Entry(self.f2,textvariable=self.data["Label"],width=12) #,command=ev._event)
  329. if "label" in args and type(args["label"]) is str:
  330. self.data["Label"].set(args["label"])
  331. #self.e["bg"] = "#eee"
  332. self.e.config(highlightthickness=2)
  333. self.e.config(highlightcolor= "red")
  334. self.e.icursor(999)
  335. #self.e.selection_range(0, 999)#"end")
  336. ev = DialogEvent()
  337. ev.e = self.e
  338. ev.master = self
  339. ev.e_txt = self.data["Label"]
  340. self.e.bind("<Key>",ev._event)
  341. self.e.bind("<Button>",ev._event)
  342. self.e.pack(side="left")
  343. self.e1 = self.e
  344. del ev
  345. # ---------------------- frame bottom [ok,cancel]
  346. self.fu = tk.Frame(self.tk,bd=2) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  347. self.fu.pack(side="top")
  348. self.fu["bg"] = "lightgrey"##eee"
  349. # --- Spacer ---- OK,Cancle
  350. self.f = tk.Frame(self.fu) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  351. self.f.pack(side="top")
  352. self.elx = tk.Label(self.f,text="")
  353. self.elx["bg"] = bg
  354. self.elx.pack(side="left")
  355. self.f = tk.Frame(self.fu) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  356. self.f.pack(side="top")
  357. self.b = tk.Button(self.f,bg="lightgrey", text="OK",width=10,command=self.ok)
  358. self.b.config(padx=1)
  359. #self.b.bind("<Button>",Xevent(fix=fix,mode="D-SELECT",elem=b).cb)
  360. self.b.pack(side="left")
  361. self.fxx = tk.Frame(self.f,width=20) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  362. self.fxx.pack(side="left")
  363. self.b = tk.Button(self.f,bg="lightgrey", text="Cancel",width=10,command=self.close)
  364. self.b.config(padx=1)
  365. self.b.pack(side="left")
  366. self.f = tk.Frame(self.fu) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  367. self.f.pack(side="top")
  368. self.elx = tk.Label(self.f,text="")
  369. self.elx["bg"] = bg
  370. self.elx.pack(side="left")
  371. self.e.focus()
  372. #time.sleep(3)
  373. self.tk.deiconify()
  374. def askstring_new(self,title="title",prompt="prompt:",initialvalue=""):
  375. self.data = {}
  376. self._exit = None
  377. try:
  378. self.close()
  379. except Exception as e:print(e)
  380. #try:
  381. # #self.tk.quit()
  382. # print(dir(self.tk))
  383. # self.close()
  384. #except Exception as e:print(e)
  385. #self.tk = tkinter.Tk()
  386. self.tk = tkinter.Toplevel()
  387. #self.tk.withdraw() # do not draw
  388. self.tk.iconify()
  389. c = prompt.count("\n") * 15
  390. self.tk.geometry("200x{}".format(120+c))
  391. self.tk.title(""+str(title) )#+" "+":"+str(rnd_id))
  392. self.tk.attributes('-topmost',True)
  393. self.tk.protocol("WM_DELETE_WINDOW", self.close)
  394. self.tk.resizable(0,0)
  395. bg = "#e0e"
  396. bg = "#aaa"
  397. self.tk["bg"] = bg
  398. #self.tk.overrideredirect(1)
  399. #self.tk.attributes('-toolwindow', True)
  400. #self.tk.state(newstate='iconic')
  401. self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  402. self.f.pack(side="top")
  403. self.elx = tk.Label(self.f,text="")
  404. self.elx["bg"] = bg
  405. self.elx.pack(side="left")
  406. self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  407. self.f.pack(side="top")
  408. self.el = tk.Label(self.f,text=prompt,anchor="w")
  409. self.el["bg"] = bg
  410. self.el.pack(side="left")
  411. self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  412. self.f.pack(side="top")
  413. self.e_txt = tk.StringVar()
  414. self.data["Value"] = self.e_txt
  415. #self.e = tk.Entry(self.f,state="readonly",textvariable=self.e_txt)
  416. self.e = tk.Entry(self.f,textvariable=self.e_txt)
  417. #self.e = tk.Button(self.f,textvariable=self.e_txt,relief="sunken",width=20)
  418. self.e["bg"] = "#fff"
  419. self.e.config(highlightthickness=2)
  420. self.e.config(highlightcolor= "red")
  421. #self.e_txt.set(str(initialvalue)+"<")
  422. self.e_txt.set(str(initialvalue))
  423. self.e.icursor(999)
  424. self.e.selection_range(0, 999)#"end")
  425. self.e.bind("<Key>",self.event)
  426. self.e.bind("<Button>",self.event)
  427. self.e.pack(side="top")
  428. self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  429. self.f.pack(side="top")
  430. self.elx = tk.Label(self.f,text="")
  431. self.elx["bg"] = bg
  432. self.elx.pack(side="left")
  433. self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  434. self.f.pack(side="top")
  435. self.b = tk.Button(self.f,bg="lightgrey", text="OK",width=10,command=self.ok)
  436. self.b.config(padx=1)
  437. #self.b.bind("<Button>",Xevent(fix=fix,mode="D-SELECT",elem=b).cb)
  438. self.b.pack(side="left")
  439. self.b = tk.Button(self.f,bg="lightgrey", text="Cancel",width=10,command=self.close)
  440. self.b.config(padx=1)
  441. self.b.pack(side="left")
  442. self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  443. self.f.pack(side="top")
  444. self.elx = tk.Label(self.f,text="")
  445. self.elx["bg"] = bg
  446. self.elx.pack(side="left")
  447. self.e.focus()
  448. #time.sleep(3)
  449. self.tk.deiconify()
  450. dialog = Dialog()
  451. import lib.zchat as chat
  452. import lib.motion as motion
  453. from collections import OrderedDict
  454. _POS_LEFT = 0
  455. _POS_TOP = 15
  456. _config = []
  457. try:
  458. h = os.environ["HOME"]
  459. lines = [{}]
  460. try:
  461. f = open(h +"/LibreLight/config.json")
  462. lines = f.readlines()
  463. except FileNotFoundError as e: #Exception as e:
  464. f = open(h +"/LibreLight/config.json","w")
  465. f.write('{"POS_TOP":0}\n{"POS_LEFT":0}')
  466. f.close()
  467. print("Exception:",e)
  468. for line in lines:
  469. line=line.strip()
  470. print("config read",line)
  471. row = json.loads(line)
  472. _config.append(row)
  473. except Exception as e:
  474. print("Exception:",e)
  475. try:
  476. for row in _config:
  477. print("config:",row)
  478. if "POS_LEFT" in row:
  479. _POS_LEFT = int(row["POS_LEFT"])
  480. if "POS_TOP" in row:
  481. _POS_TOP = int(row["POS_TOP"])
  482. except Exception as e:
  483. print("Exception:",e)
  484. def showwarning(msg="<ERROR>",title="<TITLE>"):
  485. _main = tkinter.Tk()
  486. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  487. print("showwarning",defaultFont)
  488. defaultFont.configure(family="FreeSans",
  489. size=10,
  490. weight="normal")
  491. geo ="{}x{}".format(20,20)
  492. _main.geometry(geo)
  493. def _quit():
  494. time.sleep(.02)
  495. _main.quit()
  496. thread.start_new_thread(_main.mainloop,())
  497. #_main.quit()
  498. #msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  499. #msg += "please check\n"
  500. #msg += "-{}init.txt\n".format(self.show_path0)
  501. #msg += "-{}".format(self.show_path1)
  502. r=tkinter.messagebox.showwarning(message=msg,title=title,parent=None)
  503. CUES = OrderedDict()
  504. groups = OrderedDict()
  505. class Modes():
  506. def __init__(self):
  507. self.modes = {}
  508. self.__cfg = {}
  509. self.__cb = None
  510. def val(self,mode,value=None): #like jquery
  511. if value is not None:
  512. return self.set(mode,value)
  513. elif mode in self.modes:
  514. return self.modes[mode]
  515. def get(self,mode,value=None):
  516. return self.val(mode,value)
  517. def __check(self,mode):
  518. if mode not in self.modes:
  519. self.modes[mode] = 0
  520. self.__cfg[mode] = 0
  521. def cfg(self,mode,data={}):
  522. self.__check(mode)
  523. if type(data) is dict:
  524. for k in data:
  525. v = data[k]
  526. if v not in self.__cfg:
  527. self.__cfg[k] = v
  528. return 1
  529. elif type(data) is str:
  530. if data in self.__cfg:
  531. return self.__cfg[data]
  532. def set(self,mode,value):
  533. protected = ["BLIND","CLEAR","REC-FX"]
  534. self.__check(mode)
  535. if mode == "CLEAR":
  536. return 1
  537. elif mode == "ESC":
  538. for m in self.modes:
  539. print("ESC",m)
  540. if m == "COPY":
  541. PRESETS.clear_copy()
  542. if m == "MOVE":
  543. PRESETS.clear_move()
  544. if m != "BLIND":
  545. self.modes[m] = 0
  546. self.callback(m)
  547. return 1
  548. if value:
  549. for m in self.modes:
  550. if m not in protected and mode not in protected and m != mode:
  551. #cprint("-#-# clear mode",mode,m,value,color="red")
  552. if self.modes[m]:
  553. self.modes[m]= 0
  554. self.callback(m)
  555. if self.modes[mode] and value == 1:
  556. if modes == "MOVE":
  557. PRESETS.clear_move()
  558. if modes == "COPY":
  559. PRESETS.clear_copy()
  560. self.modes[mode] = 0 # value
  561. else:
  562. self.modes[mode] = value #1 #value
  563. else:
  564. self.modes[mode] = 0 #value
  565. if modes == "COPY":
  566. PRESETS.clear_copy()
  567. if modes == "MOVE":
  568. PRESETS.clear_move()
  569. self.callback(mode)
  570. return value
  571. def set_cb(self,cb):
  572. if cb:
  573. self.__cb = cb
  574. def callback(self,mode):
  575. if self.__cb is not None and mode in self.modes:
  576. value = self.modes[mode]
  577. self.__cb(mode=mode,value=value)
  578. modes = Modes()
  579. #modes.val("BLIND", 0)
  580. #modes.modes["BLIND"] = 0
  581. modes.modes["ESC"] = 0
  582. modes.modes["REC"] = 0
  583. modes.modes["EDIT"] = 0
  584. modes.modes["MOVE"] = 0
  585. modes.modes["FLASH"] = 0
  586. modes.modes["GO"] = 0
  587. modes.modes["DEL"] = 0
  588. modes.modes["REC-FX"] = 0
  589. modes.modes["SELECT"] = 0
  590. modes.modes["CFG-BTN"] = 0
  591. modes.modes["LABEL"] = 0
  592. def xcb(mode,value=None):
  593. print("xcb","MODE CALLBACK",mode,value)
  594. if mode == "REC-FX":
  595. print("xcb",modes.val("REC-FX"))
  596. #modes.set_cb(xcb)
  597. POS = ["PAN","TILT","MOTION"]
  598. COLOR = ["RED","GREEN","BLUE","COLOR"]
  599. BEAM = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
  600. INT = ["DIM","SHUTTER","STROBE","FUNC"]
  601. #client = chat.tcp_sender(port=50001)
  602. def set_exec_fader(nr,val,color=""):
  603. exec_wing = window_manager.get_obj(name="EXEC-WING") #= WindowManager()
  604. if not exec_wing:
  605. return
  606. #print(exec_wing)
  607. try:
  608. exec_wing.set_fader(nr,val,color=color)
  609. except Exception as e:
  610. print("exception",e)
  611. #print("remote in:",round(time.time(),0),"x",i,v)
  612. # remote input - start (memcached)
  613. def JCB(x):
  614. for i in x:
  615. jv = x[i]
  616. try:
  617. jv = json.loads(jv)
  618. jv = jv[0]
  619. #print(jv)
  620. v = jv["iVAL"]
  621. #exec_wing.set_fader(0,v)
  622. set_exec_fader(0,v)
  623. set_exec_fader(1,200-v)
  624. set_exec_fader(2,int(v/2+10))
  625. except Exception as e:
  626. print("exception",e)
  627. #print("remote in:",round(time.time(),0),"x",i,v)
  628. #chat.cmd(JCB,port=30002) # SERVER
  629. thread.start_new_thread(chat.cmd,(JCB,30002)) # SERVER
  630. # remote input - end
  631. # read memcachd
  632. memcache = None
  633. try:
  634. import memcache
  635. except Exception as e:
  636. print("Exception IMPORT ERROR",e)
  637. class MC():
  638. def __init__(self,server="127.0.0.1",port=11211):
  639. print("----------- MC")
  640. try:
  641. self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  642. #self.init()
  643. except Exception as e:
  644. print("Exception",e)
  645. # def init(self):
  646. data = {}
  647. start = time.time()
  648. delta = start
  649. index = self.mc.get("index")
  650. if index:
  651. for i in index:
  652. print("key",i)
  653. self.fader_map = []
  654. for i in range(30+1):
  655. self.fader_map.append({"UNIV":0,"DMX":0})
  656. try:
  657. f = open("/home/user/LibreLight/fader.json")
  658. lines = f.readlines()
  659. for i,line in enumerate(lines):
  660. jdata = json.loads(line)
  661. print("fader_map ->>",i,jdata)
  662. self.fader_map[i] = jdata
  663. except Exception as e:
  664. print("Except Fader_map",e)
  665. #exit()
  666. def ok(self):
  667. if self.mc:
  668. return 1
  669. return 0
  670. def test(self):
  671. if not self.ok():
  672. return
  673. self.mc.set("some_key", "Some value")
  674. self.value = mc.get("some_key")
  675. self.mc.set("another_key", 3)
  676. self.mc.delete("another_key")
  677. def loop(self):
  678. thread.start_new_thread(self._loop,())
  679. if not self.ok():
  680. return
  681. def _loop(self):
  682. print("++++++++++ start.memcachd read loop",self )
  683. while 1:
  684. send = 0
  685. #print("+")
  686. try:
  687. ip="10.10.10.13:0"
  688. #ip="ltp-out:0"
  689. #print(ip)
  690. x=self.mc.get(ip)
  691. if x:
  692. #print(ip,x)
  693. #val = x[501-1]
  694. #val = x[141-1]
  695. for i, line in enumerate(self.fader_map):
  696. try:
  697. #print(i,line)
  698. dmx = int(line["DMX"])
  699. if dmx > 0:
  700. val = x[dmx-1]
  701. #print("mc val",val)
  702. set_exec_fader(i,val,color="#aaa")
  703. except:pass
  704. time.sleep(0.01)
  705. except Exception as e:
  706. print("exc", e)
  707. time.sleep(1)
  708. _mc=MC()
  709. _mc.loop()
  710. #time.sleep(1)
  711. #exit()
  712. jclient = chat.tcp_sender()#port=50001)
  713. import zlib
  714. def jclient_send(data):
  715. t_start = time.time()
  716. jtxt = data
  717. jdatas = []
  718. for jdata in data:
  719. if "CMD" in jdata:
  720. try:
  721. jdatas.append(jdata)
  722. except Exception as e:
  723. cprint("jclient_send, Exception DMX ",color="red")
  724. cprint("",jdata,color="red")
  725. cprint("-----",color="red")
  726. elif "DMX" in jdata:
  727. try:
  728. dmx = int(jdata["DMX"])
  729. if int(dmx) >= 1: # ignore DMX lower one
  730. if "FIX" in jdata and "ATTR" in jdata:
  731. fix = jdata["FIX"]
  732. attr = jdata["ATTR"]
  733. # find dmx-fine channel
  734. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  735. jdatas.append(jdata)
  736. else:
  737. cprint("jclient_send, ignore DMX ",jdata["DMX"],color="red")
  738. except Exception as e:
  739. cprint("jclient_send, Exception DMX ",color="red")
  740. cprint("",jdata,color="red")
  741. cprint(e,color="red")
  742. cprint("-----",color="red")
  743. jtxt = jdatas
  744. jtxt = json.dumps(jtxt)
  745. jtxt = jtxt.encode()
  746. #jtxt = zlib.compress(jtxt)
  747. jclient.send( jtxt ) #b"\00 ")
  748. #print(round((time.time()-t_start)*1000,4),"milis")
  749. cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")
  750. cprint("{:0.04} tick".format(time.time()),color="yellow")
  751. def _highlight(fix,_attr="DIM"):
  752. " patch test button "
  753. print("highlight",fix,"1")
  754. if fix not in FIXTURES.fixtures:
  755. return None
  756. d = FIXTURES.fixtures[fix]
  757. #for k,v in d.items():
  758. # print("-",k,v)
  759. DMX = d["DMX"] + d["UNIVERS"]*512
  760. if "ATTRIBUT" in d:
  761. ATTR= d["ATTRIBUT"]
  762. data = {"VALUE":200,"DMX":1}
  763. attr = ""
  764. if _attr in ATTR:
  765. attr = _attr
  766. else:
  767. return #stop
  768. print(attr,ATTR[attr])
  769. old_val = ATTR[attr]["VALUE"]
  770. data["DMX"] = DMX + ATTR[attr]["NR"]-1
  771. print(attr,ATTR[attr])
  772. print(data)
  773. for i in range(3):
  774. print("highlight",fix,"0")
  775. data["VALUE"] = 100
  776. jclient_send([data])
  777. time.sleep(0.1)
  778. print("highlight",fix,"1")
  779. data["VALUE"] = 234
  780. jclient_send([data])
  781. time.sleep(0.3)
  782. print("highlight",fix,"0")
  783. data["VALUE"] = old_val
  784. jclient_send([data])
  785. def highlight2(fix,attr="DIM"):
  786. def x():
  787. highlight(fix,attr=attr)
  788. return x
  789. def highlight(fix):
  790. print("highlight",fix)
  791. thread.start_new_thread(_highlight,(fix,"DIM"))
  792. thread.start_new_thread(_highlight,(fix,"RED"))
  793. thread.start_new_thread(_highlight,(fix,"GREEN"))
  794. thread.start_new_thread(_highlight,(fix,"BLUE"))
  795. class ValueBuffer():
  796. def __init__(self,_min=0,_max=255):
  797. self._value = 2
  798. self._on = 1
  799. self._min=_min
  800. self._max=_max
  801. def check(self):
  802. if self._value < self._min:
  803. self._value = self._min
  804. elif self._value > self._max:
  805. self._value = self._max
  806. def inc(self,value=None):
  807. if value is not None:
  808. if type(value) is float:
  809. self._value += round(value,4)
  810. else:
  811. self._value += value
  812. self.check()
  813. return self._value
  814. def val(self,value=None):
  815. if value is not None:
  816. if type(value) is float:
  817. self._value = round(value,4)
  818. else:
  819. self._value = value
  820. self.check()
  821. return self._value
  822. def on(self):
  823. self._on = 1
  824. def off(self):
  825. self._on = 0
  826. def _is(self):
  827. if self._on:
  828. return 1
  829. return 0
  830. FADE = ValueBuffer() #2 #0.1 #1.13
  831. FADE.val(2.0)
  832. FADE_move = ValueBuffer() #2 #0.1 #1.13
  833. FADE_move.val(4.0)
  834. DELAY = ValueBuffer() #2 #0.1 #1.13
  835. DELAY.off()
  836. DELAY.val(0.2)
  837. fx_prm_move = {"SIZE":40,"SPEED":8,"OFFSET":100,"BASE":"0","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":0,"WING":2,"WIDTH":100}
  838. fx_prm = {"SIZE":255,"SPEED":10,"OFFSET":100,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":1,"SHUFFLE":0,"WING":2,"WIDTH":25,"FX-X":1,"FX:MODE":0}
  839. fx_x_modes = ["spiral","left","right","up","down","left_right","up_down"]
  840. fx_modes = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
  841. fx_mo = ["fade","on","rnd","ramp","ramp2","cosinus","sinus"]
  842. class FX_handler():
  843. def __init__():
  844. pass
  845. def reshape_preset(data ,value=None,xfade=0,flash=0,ptfade=0):
  846. f=0 #fade
  847. out = []
  848. delay=0
  849. for row in data:
  850. #cprint("reshape_preset in:",row)
  851. line = {}
  852. line["DELAY"]=delay
  853. if type(value) is float:
  854. line["VALUE"] = value #round(value,3)
  855. else:
  856. line["VALUE"] = value
  857. if value is not None:
  858. line["FX"] = row["FX"].split(":",1)[-1]
  859. else:
  860. line["FX"] = row["FX"]
  861. if row["FX2"]:
  862. line["FX2"] = row["FX2"]
  863. if row["FIX"]:
  864. line["FIX"] = row["FIX"]
  865. if row["ATTR"]:
  866. line["ATTR"] = row["ATTR"]
  867. if row["VALUE"] is not None:
  868. if value is None:
  869. v=row["VALUE"]
  870. if type(v) is float:
  871. line["VALUE"] = v #round(v,3)
  872. else:
  873. line["VALUE"] = v
  874. if row["ATTR"] in ["PAN","TILT"]:
  875. f = ptfade
  876. for a in ["DIM","ZOOM","FOCUS","RED","GREEN","BLUE","WHITE","AMBER","IRIS","BLADE"]:
  877. #FADE ATTRIBUTES
  878. if a in row["ATTR"]:
  879. f = xfade
  880. break
  881. if flash:
  882. xfade = 0
  883. if type( f ) is float:
  884. line["FADE"] = round(f,4)
  885. else:
  886. line["FADE"] = f
  887. if 0:
  888. cprint("reshape_preset j",line,color="red")
  889. #cprint("reshape_preset out:",line)
  890. out.append(line)
  891. if DELAY._is():
  892. delay+=DELAY.val()/100 #0.02
  893. return out
  894. class dummy_event():
  895. def __init__(self):
  896. self.num =0
  897. self.type = 4 #press 5 release
  898. self.set_value=-1
  899. gcolor = 1
  900. def cprint(*text,color="blue",space=" ",end="\n"):
  901. #return 0 #disable print dbg
  902. if not gcolor:
  903. print(text)
  904. return 0
  905. if color == "green":
  906. txt = '\033[92m'
  907. elif color == "red":
  908. txt = '\033[0;31m\033[1m'
  909. elif color == "yellow":
  910. txt = '\033[93m\033[1m'
  911. elif color == "cyan":
  912. txt = '\033[96m'
  913. else:
  914. txt = '\033[94m'
  915. for t in text:
  916. txt += str(t ) +" "
  917. #HEADER = '\033[95m'
  918. #OKBLUE = '\033[94m'
  919. #OKCYAN = '\033[96m'
  920. #OKGREEN = '\033[92m'
  921. #WARNING = '\033[93m'
  922. #FAIL = '\033[91m'
  923. #ENDC = '\033[0m'
  924. #BOLD = '\033[1m'
  925. #UNDERLINE = '\033[4m'
  926. txt += '\033[0m'
  927. print(txt,end=end)
  928. #return txt
  929. cprint("________________________________")
  930. def process_wings(xfixtures):
  931. """process the wing's of selected fixtures
  932. input: [1,2,3,4,10,12,13,14]
  933. if WING = 2 return: [[1,2,3,4][14,13,12,10]]
  934. """
  935. wing_buffer = []
  936. fix_count = len(xfixtures)
  937. prm = fx_prm # ToDo: global WING for PAN/TILE !? ATTRIBUT is not availible in this moment
  938. if prm["WING"] > 1 and fix_count > 1:
  939. wing_count = fix_count // prm["WING"]
  940. number_of_fix_in_wing = fix_count // wing_count
  941. if number_of_fix_in_wing < 2:
  942. number_of_fix_in_wing = 2
  943. for i in range(number_of_fix_in_wing):
  944. j = i*wing_count
  945. wing = xfixtures[j:j+wing_count]
  946. if i%2!=0:
  947. wing = wing[::-1]
  948. print("wing",i,"j",j,"wing_count:",wing_count,"wing",wing)
  949. wing_buffer.append(wing)
  950. if fix_count > j+wing_count: # append Fixtures Left over
  951. wing = xfixtures[j+wing_count:]
  952. wing_buffer.append(wing)
  953. else:
  954. wing_buffer.append(xfixtures)
  955. if prm["SHUFFLE"]:
  956. _wing_buffer = []
  957. for wing in wing_buffer:
  958. wing = wing[:]
  959. random.shuffle(wing)
  960. _wing_buffer.append(wing)
  961. wing_buffer = _wing_buffer
  962. return wing_buffer
  963. def process_effect(wing_buffer,fx_name=""):
  964. jdatas = []
  965. offset = 0
  966. offset_move = 0
  967. start = fx_prm["START"]
  968. base = fx_prm["BASE"]
  969. for wing in wing_buffer:
  970. count_of_fix_in_wing = len(wing)
  971. coffset= 0 # 1024/count_of_fix_in_wing * (offset/255)
  972. coffset_move=0
  973. for fix in wing:
  974. if fix not in FIXTURES.fixtures:
  975. continue
  976. data = FIXTURES.fixtures[fix]
  977. for attr in data["ATTRIBUT"]:
  978. jdata = {"MODE":"FX"}
  979. jdata["VALUE"] = None
  980. jdata["FIX"] = fix
  981. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  982. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  983. jdata["ATTR"] =attr
  984. if attr.endswith("-FINE"):
  985. continue
  986. if attr in ["PAN","TILT"]:
  987. csize = fx_prm_move["SIZE"]
  988. cspeed = fx_prm_move["SPEED"]
  989. cstart = fx_prm_move["START"]
  990. cbase = fx_prm_move["BASE"]
  991. width = fx_prm_move["WIDTH"]
  992. invert = fx_prm_move["INVERT"]
  993. coffset_move= round(offset_move,1)
  994. else:
  995. csize = fx_prm["SIZE"]
  996. cspeed = fx_prm["SPEED"]
  997. cstart = fx_prm["START"]
  998. cbase = fx_prm["BASE"]
  999. width = fx_prm["WIDTH"]
  1000. invert = fx_prm["INVERT"]
  1001. coffset= round(offset,1)
  1002. fx=""
  1003. if "SIN" in fx_name:
  1004. fx = "sinus"
  1005. elif "FD" in fx_name:
  1006. fx = "fade"
  1007. elif "RND" in fx_name:
  1008. fx = "rnd"
  1009. elif "ON" in fx_name:
  1010. fx = "on"
  1011. elif "RAMP2" in fx_name:
  1012. fx = "bump2"
  1013. fx = "ramp2"
  1014. elif "RAMP" in fx_name:
  1015. fx = "ramp"
  1016. elif "COS" in fx_name:
  1017. fx = "cosinus"
  1018. if fx:
  1019. if attr in ["PAN","TILT"]:
  1020. cprint("SKIP FX attr:{} fix:{} " .format(attr,fix) )
  1021. continue
  1022. if fx:
  1023. if fx_prm["SPEED"] < 0:
  1024. fx = "off"
  1025. else:
  1026. if ":DIM" in fx_name:
  1027. base=""
  1028. ffxb=fx_mo[fx_prm["MO"]]
  1029. #ffxb= "cosinus"
  1030. if attr == "DIM":
  1031. if fx_prm["SPEED"] < 0:
  1032. fx = "off"
  1033. else:
  1034. fx = ffxb #"fade"
  1035. elif ":TILT" in fx_name:
  1036. base=""
  1037. if attr == "PAN":
  1038. fx = "off"
  1039. if attr == "TILT":
  1040. if fx_prm["SPEED"] < 0:
  1041. fx = "off"
  1042. else:
  1043. fx = "sinus"
  1044. elif ":PAN" in fx_name:
  1045. base=""
  1046. if attr == "PAN":
  1047. if fx_prm_move["SPEED"] < 0:
  1048. fx = "off"
  1049. else:
  1050. fx = "cosinus"
  1051. if attr == "TILT":
  1052. fx = "off"
  1053. elif ":CIR" in fx_name:
  1054. base=""
  1055. if attr == "PAN":
  1056. if fx_prm_move["SPEED"] < 0:
  1057. fx = "off"
  1058. else:
  1059. fx = "cosinus"
  1060. if attr == "TILT":
  1061. if fx_prm["SPEED"] < 0:
  1062. fx = "off"
  1063. else:
  1064. fx = "sinus"
  1065. elif ":RED" in fx_name:
  1066. ffxb= fx_mo[fx_prm["MO"]]
  1067. ffx= "off" #fx_mo[fx_prm["MO"]]
  1068. if "RED" in fx_modes[fx_prm["MODE"]]:#
  1069. base="-"
  1070. if attr == "RED":
  1071. fx=ffx
  1072. if attr == "GREEN":
  1073. fx = ffxb# "off"
  1074. if attr == "BLUE":
  1075. fx = ffxb#"off"
  1076. elif "GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in fx_name:
  1077. base="-"
  1078. if attr == "RED":
  1079. fx = ffxb#"off"
  1080. elif "GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in fx_name:
  1081. if attr == "GREEN":
  1082. fx = ffxb# "off"
  1083. fx=ffx
  1084. if attr == "BLUE":
  1085. fx = ffxb#"off"
  1086. elif "BLUE" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  1087. base="-"
  1088. if attr == "RED":
  1089. fx = ffxb# "off"
  1090. if attr == "GREEN":
  1091. fx = ffxb# "off"
  1092. if attr == "BLUE":
  1093. fx = ffxb# "off"
  1094. fx=ffx
  1095. elif "YELLOW" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  1096. base="-"
  1097. if attr == "RED":
  1098. fx = ffxb# "off"
  1099. fx=ffx
  1100. if attr == "GREEN":
  1101. fx = ffxb# "off"
  1102. fx=ffx
  1103. if attr == "BLUE":
  1104. fx = "off"
  1105. elif "CYAN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  1106. base="-"
  1107. if attr == "RED":
  1108. fx = ffxb# "off"
  1109. if attr == "GREEN":
  1110. fx = ffxb# "off"
  1111. fx=ffx
  1112. if attr == "BLUE":
  1113. fx = ffxb# "off"
  1114. fx=ffx
  1115. elif "MAG" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  1116. base="-"
  1117. if attr == "RED":
  1118. fx = ffxb# "off"
  1119. fx=ffx
  1120. if attr == "GREEN":
  1121. fx = ffxb# "off"
  1122. if attr == "BLUE":
  1123. fx = ffxb# "off"
  1124. fx=ffx
  1125. else:
  1126. cprint("FX: unbekant",fx_modes[fx_prm["MODE"]],color="red")
  1127. fxtype = fx
  1128. fxtype = fx
  1129. if "FX" not in data["ATTRIBUT"][attr]:
  1130. data["ATTRIBUT"][attr]["FX"] =""
  1131. if "FX2" not in data["ATTRIBUT"][attr]:
  1132. data["ATTRIBUT"][attr]["FX2"] ={}
  1133. if data["ATTRIBUT"][attr]["ACTIVE"] and fxtype:
  1134. #print("++ADD FX",fix,attr,fx)
  1135. #data["ATTRIBUT"][attr]["FX"] = fx #"sinus:40:100:10"
  1136. fjdata = {}
  1137. if cspeed < 0.1:
  1138. fjdata["TYPE"] = "off"
  1139. else:
  1140. fjdata["TYPE"] = fxtype
  1141. fjdata["SIZE"] = round(csize,2)
  1142. fjdata["SPEED"] = round(cspeed,2)
  1143. fjdata["WIDTH"] = int(width)
  1144. fjdata["START"] = cstart
  1145. if attr in ["PAN","TILT"]:
  1146. fjdata["OFFSET"]= round(coffset_move,2)
  1147. else:
  1148. fjdata["OFFSET"]= round(coffset,2)
  1149. fjdata["INVERT"]= int(invert)
  1150. fjdata["BASE"] = cbase
  1151. jdata["FX2"] = fjdata
  1152. data["ATTRIBUT"][attr]["FX2"] = fjdata
  1153. jdatas.append(jdata)
  1154. if fx_prm_move["OFFSET"] > 0.5: # and
  1155. aoffset_move = (100/count_of_fix_in_wing) * (fx_prm_move["OFFSET"]/100)
  1156. if fx_prm_move["DIR"] <= 0:
  1157. offset_move -= aoffset_move
  1158. else:
  1159. offset_move += aoffset_move
  1160. offset_move = round(offset_move,2)
  1161. if fx_prm["OFFSET"] > 0.5: # and
  1162. aoffset = (100/count_of_fix_in_wing) * (fx_prm["OFFSET"]/100)
  1163. if fx_prm["DIR"] <= 0:
  1164. offset -= aoffset
  1165. else:
  1166. offset += aoffset
  1167. offset = round(offset,2)
  1168. if jdatas and not modes.val("BLIND"):
  1169. jclient_send(jdatas)
  1170. master.refresh_fix()
  1171. return jdatas
  1172. def process_matrix(xfixtures):
  1173. fix_count = len(xfixtures)
  1174. fx_x = fx_prm["FX-X"]
  1175. fx_mod = fx_x_modes[fx_prm["FX:MODE"]]
  1176. print("----",fx_x,fx_mod)
  1177. if fx_x > 1 and fix_count > fx_x:
  1178. try:
  1179. from lib import matrix
  1180. w=fx_x
  1181. h=int(fix_count/fx_x)
  1182. if fx_mod == "spiral":
  1183. _map = matrix.spiral(w,h)
  1184. elif fx_mod == "up_down":
  1185. _map = matrix.up_down(w,h)
  1186. elif fx_mod == "left_right":
  1187. _map = matrix.left_right(w,h)
  1188. elif fx_mod == "left":
  1189. _map = matrix.left(w,h)
  1190. elif fx_mod == "right":
  1191. _map = matrix.right(w,h)
  1192. elif fx_mod == "up":
  1193. _map = matrix.up(w,h)
  1194. elif fx_mod == "down":
  1195. _map = matrix.down(w,h)
  1196. else:
  1197. return xfixtures # do nothing
  1198. matrix.mprint(xfixtures,w,h)
  1199. out = ["0"]*(w*h)
  1200. for i,f in enumerate(xfixtures):
  1201. if i < w*h:
  1202. j = int(_map[i])
  1203. print([i,f,j])
  1204. out[j] = f
  1205. matrix.mprint(out,w,h)
  1206. xfixtures = out
  1207. except Exception as e:
  1208. print("matrix exception",e)
  1209. return xfixtures
  1210. class Xevent_fx():
  1211. """ global input event Handeler for short cut's ... etc
  1212. """
  1213. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  1214. self.fix = fix
  1215. self.data = data
  1216. self.attr = attr
  1217. self.elem = elem
  1218. self.mode = mode
  1219. def fx(self,event):
  1220. cprint("Xevent.fx",self.attr,self.fix,event)
  1221. fx2 = {}
  1222. if event.num == 4:
  1223. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  1224. txt = "FX:RED"
  1225. fx_prm["MODE"] += 1
  1226. if fx_prm["MODE"] >= len(fx_modes):
  1227. fx_prm["MODE"]=0
  1228. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  1229. master.fx.elem["FX:RED"]["text"] = txt
  1230. elif event.num == 5:
  1231. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  1232. txt = "FX:RED"
  1233. fx_prm["MODE"] -= 1
  1234. if fx_prm["MODE"] < 0:
  1235. fx_prm["MODE"]= len(fx_modes)-1
  1236. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  1237. master.fx.elem["FX:RED"]["text"] = txt
  1238. if event.num == 4:
  1239. cprint("FX-X: CHANGE",fx_prm,color="red")
  1240. txt = "FX-X:"
  1241. fx_prm["FX:MODE"] += 1
  1242. if fx_prm["FX:MODE"] >= len(fx_x_modes):
  1243. fx_prm["FX:MODE"]=0
  1244. txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
  1245. master.fx.elem["FX:MODE"]["text"] = txt
  1246. elif event.num == 5:
  1247. cprint("FX-X: CHANGE",fx_prm,color="red")
  1248. txt = "FX-X:"
  1249. fx_prm["FX:MODE"] -= 1
  1250. if fx_prm["FX:MODE"] < 0:
  1251. fx_prm["FX:MODE"]= len(fx_x_modes)-1
  1252. txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
  1253. master.fx.elem["FX:MODE"]["text"] = txt
  1254. elif event.num == 1:
  1255. xfixtures = []
  1256. fix_active =FIXTURES.get_active()
  1257. for fix in fix_active:
  1258. if fix == "CFG":
  1259. continue
  1260. xfixtures.append(fix)
  1261. if not xfixtures:
  1262. cprint("470 fx() ... init no fixture selected",color="red")
  1263. return 0
  1264. xfixtures = process_matrix(xfixtures)
  1265. wing_buffer = process_wings(xfixtures)
  1266. process_effect(wing_buffer,fx_name=self.attr)
  1267. def command(self,event,mode=""):
  1268. cprint("fx_command",self.mode)
  1269. if self.mode == "FX":
  1270. prm = fx_prm
  1271. ct = self.data.fx
  1272. if self.mode == "FX-MOVE":
  1273. prm = fx_prm_move
  1274. ct = self.data.fx_moves
  1275. if 1:
  1276. if self.attr.startswith("SIZE:"):#SIN":
  1277. #global fx_prm
  1278. k = "SIZE"
  1279. if event.num == 1:
  1280. prm[k] =30
  1281. elif event.num == 3:
  1282. prm[k] =100
  1283. elif event.num == 4:
  1284. if prm[k] <= 0:
  1285. prm[k] = 1
  1286. prm[k] +=5
  1287. elif event.num == 5:
  1288. prm[k] -=5
  1289. #prm[k] =int(prm[k])
  1290. if prm[k] > 4000:
  1291. prm[k] = 4000
  1292. if prm[k] < 0:
  1293. prm[k] =0
  1294. if prm[k] == 6: #bug
  1295. prm[k] =5
  1296. ct.elem[self.attr]["text"] = "SIZE:\n{:0.0f}".format(prm[k])
  1297. cprint(prm)
  1298. elif self.attr.startswith("SPEED:"):#SIN":
  1299. #global prm
  1300. k = "SPEED"
  1301. if event.num == 1:
  1302. prm[k] = 6
  1303. elif event.num == 3:
  1304. prm[k] = 60
  1305. elif event.num == 4:
  1306. if prm[k] <= 0:
  1307. prm[k] = 0.06
  1308. elif prm[k] < 5:
  1309. prm[k] *=1.2
  1310. else:
  1311. prm[k] +=5 #1.1
  1312. elif event.num == 5:
  1313. if prm[k] <= 5:
  1314. prm[k] *=0.8
  1315. else:
  1316. prm[k] -= 5 #1.1
  1317. #prm[k] =int(prm[k])
  1318. if prm[k] > 4000:
  1319. prm[k] = 4000
  1320. if prm[k] < 0.05:
  1321. prm[k] =0
  1322. if prm[k] > 5 and prm[k] < 10: #bug
  1323. prm[k] =5
  1324. if prm[k] < 0:
  1325. ct.elem[self.attr]["text"] = "SPEED:\noff".format(prm[k])
  1326. else:
  1327. ct.elem[self.attr]["text"] = "SPEED:\n{:0.02f}".format(prm[k])
  1328. cprint(prm)
  1329. elif self.attr.startswith("START:"):#SIN":
  1330. #global prm
  1331. k = "START"
  1332. if event.num == 1:
  1333. pass
  1334. elif event.num == 2:
  1335. pass
  1336. elif event.num == 4:
  1337. if prm[k] <= 0:
  1338. prm[k] = 1
  1339. prm[k] += 5 #1.1
  1340. elif event.num == 5:
  1341. prm[k] -= 5 #1.1
  1342. #prm[k] =int(prm[k])
  1343. if prm[k] > 4000:
  1344. prm[k] = 4000
  1345. if prm[k] < 5:
  1346. prm[k] =0
  1347. if prm[k] == 6: #bug
  1348. prm[k] =5
  1349. ct.elem[self.attr]["text"] = "START:\n{:0.0f}".format(prm[k])
  1350. cprint(prm)
  1351. elif self.attr.startswith("WIDTH:"):#SIN":
  1352. #global prm
  1353. k = "WIDTH"
  1354. if event.num == 1:
  1355. prm[k] = 25
  1356. elif event.num == 2:
  1357. prm[k] = 50
  1358. elif event.num == 3:
  1359. prm[k] = 100
  1360. elif event.num == 4:
  1361. if prm[k] <= 0:
  1362. prm[k] = 1
  1363. elif prm[k] == 50:
  1364. prm[k] = 100
  1365. elif prm[k] == 5:
  1366. prm[k] = 25
  1367. elif prm[k] == 25:
  1368. prm[k] = 50
  1369. else:
  1370. prm[k] += 5 #*=1.1
  1371. elif event.num == 5:
  1372. if prm[k] == 10:
  1373. prm[k] = 5
  1374. elif prm[k] == 25:
  1375. prm[k] = 10
  1376. elif prm[k] == 50:
  1377. prm[k] = 25
  1378. elif prm[k] == 100:
  1379. prm[k] = 50
  1380. #else:
  1381. # prm[k] -=5 #/=1.1
  1382. #prm[k] =int(prm[k])
  1383. if prm[k] < 0:
  1384. prm[k] = 0
  1385. if prm[k] > 100:
  1386. prm[k] = 100
  1387. if prm[k] == 6: #bug
  1388. prm[k] =5
  1389. if prm[k] > 25 and prm[k] < 50: #bug
  1390. prm[k] =50
  1391. if prm[k] > 50 and prm[k] < 100: #bug
  1392. prm[k] =100
  1393. ct.elem[self.attr]["text"] = "WIDTH:\n{:0.0f}".format(prm[k])
  1394. cprint(prm)
  1395. elif self.attr.startswith("DIR:"):#SIN":
  1396. #global prm
  1397. k = "DIR"
  1398. if event.num == 1:
  1399. prm[k] = 1
  1400. elif event.num == 3:
  1401. prm[k] = -1
  1402. elif event.num == 4:
  1403. prm[k] = 1
  1404. elif event.num == 5:
  1405. prm[k] =-1
  1406. txt = prm[k]
  1407. ct.elem[self.attr]["text"] = "DIR:\n{}".format(prm[k])
  1408. cprint(prm)
  1409. elif self.attr.startswith("SHUFFLE:"):#SIN":
  1410. #global prm
  1411. k = "SHUFFLE"
  1412. if event.num == 1:
  1413. prm[k] = 0
  1414. elif event.num == 3:
  1415. prm[k] = 1
  1416. elif event.num == 4:
  1417. prm[k] = 1
  1418. elif event.num == 5:
  1419. prm[k] =0
  1420. if prm[k] == 6: #bug ?
  1421. prm[k] =5
  1422. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  1423. cprint(prm)
  1424. elif self.attr.startswith("INVERT:"):#SIN":
  1425. #global prm
  1426. k = "INVERT"
  1427. if event.num == 1:
  1428. prm[k] = 0
  1429. elif event.num == 3:
  1430. prm[k] = 1
  1431. elif event.num == 4:
  1432. prm[k] = 1
  1433. elif event.num == 5:
  1434. prm[k] =0
  1435. if prm[k] == 6: #bug ?
  1436. prm[k] =5
  1437. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  1438. cprint(prm)
  1439. elif self.attr.startswith("FX-X:"):#SIN":
  1440. #global prm
  1441. k = "FX-X"
  1442. if event.num == 1:
  1443. prm[k] = 1
  1444. elif event.num == 3:
  1445. prm[k] = 2
  1446. elif event.num == 4:
  1447. prm[k] += 1
  1448. elif event.num == 5:
  1449. prm[k] -=1
  1450. if prm[k] > 100:
  1451. prm[k] = 100
  1452. if prm[k] < 1:
  1453. prm[k] =1
  1454. txt = prm[k]
  1455. ct.elem[self.attr]["text"] = "FX-X:\n{}".format(prm[k])
  1456. cprint(prm)
  1457. elif self.attr.startswith("WING:"):#SIN":
  1458. #global prm
  1459. k = "WING"
  1460. if event.num == 1:
  1461. prm[k] = 1
  1462. elif event.num == 3:
  1463. prm[k] = 2
  1464. elif event.num == 4:
  1465. prm[k] += 1
  1466. elif event.num == 5:
  1467. prm[k] -=1
  1468. if prm[k] > 100:
  1469. prm[k] = 100
  1470. if prm[k] < 1:
  1471. prm[k] =1
  1472. txt = prm[k]
  1473. ct.elem[self.attr]["text"] = "WING:\n{}".format(prm[k])
  1474. cprint(prm)
  1475. elif self.attr.startswith("OFFSET:"):#SIN":
  1476. #global prm
  1477. k = "OFFSET"
  1478. if event.num == 1:
  1479. prm[k] = 50
  1480. elif event.num == 2:
  1481. prm[k] *= 2
  1482. elif event.num == 3:
  1483. prm[k] = 100
  1484. elif event.num == 4:
  1485. if prm[k] <= 0:
  1486. prm[k] = 1
  1487. prm[k] +=5 #*=1.1
  1488. elif event.num == 5:
  1489. prm[k] -=5 #/=1.1
  1490. #prm[k] =int(prm[k])
  1491. #if prm[k] > 512:
  1492. # prm[k] = 512
  1493. if prm[k] < 5:
  1494. prm[k] =0
  1495. if prm[k] == 6: #bug
  1496. prm[k] =5
  1497. ct.elem[self.attr]["text"] = "OFFSET:\n{:0.0f}".format(prm[k])
  1498. cprint(prm)
  1499. elif self.attr.startswith("BASE:"):
  1500. k = "BASE"
  1501. if event.num == 1:
  1502. prm[k] = "-"
  1503. elif event.num == 3:
  1504. prm[k] = "0"
  1505. elif event.num == 4:
  1506. prm[k] = "+"
  1507. elif event.num == 5:
  1508. prm[k] = "0"
  1509. ct.elem[self.attr]["text"] = "BASE:\n{}".format(prm[k])
  1510. elif self.attr.startswith("FX:"):#SIN":
  1511. self.fx(event)
  1512. elif self.attr == "FX OFF":
  1513. if event.num == 1:
  1514. FIXTURES.fx_off("all")
  1515. CONSOLE.fx_off("all")
  1516. CONSOLE.flash_off("all")
  1517. master.refresh_fix()
  1518. return 0
  1519. #if event.num == 1:
  1520. elif self.attr == "REC-FX":
  1521. print("ELSE",self.attr)
  1522. modes.val(self.attr,1)
  1523. return 0
  1524. def cb(self,event):
  1525. cprint("EVENT_fx cb",self.attr,self.mode,event,color='yellow')
  1526. print(["type",event.type,"num",event.num])
  1527. try:
  1528. change = 0
  1529. if self.mode.startswith("FX"):
  1530. self.command(event)
  1531. return 0
  1532. except Exception as e:
  1533. cprint("== cb EXCEPT",e,color="red")
  1534. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1535. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1536. return 1
  1537. def save_window_position(save_as=""):
  1538. try:
  1539. base = Base()
  1540. fname = "/home/user/LibreLight"
  1541. fname = base.show_path1 +base.show_name
  1542. if save_as:
  1543. fname = save_as
  1544. fname += "/gui.txt"
  1545. print("save_window_position",fname)
  1546. f = open(fname,"w")
  1547. for k,win in window_manager.windows.items():
  1548. print("save:win:pos",win,k)
  1549. if not win:
  1550. continue
  1551. #print("d",dir(win))
  1552. #print("winfo",k,win.tk.geometry())
  1553. line="{} {}\n".format(k,win.tk.geometry())
  1554. #print("> ",[line])
  1555. f.write( line )
  1556. f.flush()
  1557. f.close()
  1558. except Exception as e:
  1559. cprint("save_window_position Exception:",e,color="red")
  1560. return
  1561. def save_window_position_loop(): # like autosave
  1562. def loop():
  1563. time.sleep(20)
  1564. try:
  1565. while 1:
  1566. save_window_position()
  1567. time.sleep(60)
  1568. except Exception as e:
  1569. print("save_loop",e)
  1570. thread.start_new_thread(loop,())
  1571. def load_window_position():
  1572. try:
  1573. base = Base()
  1574. fname = "/home/user/LibreLight"
  1575. fname = base.show_path1 +base.show_name
  1576. fname += "/gui.txt"
  1577. print("load_window_position",fname)
  1578. f = open(fname,"r")
  1579. data = {}
  1580. for line in f.readlines():
  1581. line = line.strip()
  1582. if " " in line:
  1583. k,geo = line.split(" ",1)
  1584. data[k] = geo
  1585. for k,win in window_manager.windows.items():
  1586. if not win:
  1587. continue
  1588. if k in data:
  1589. try:
  1590. #print("> ",[k,data[k]])
  1591. win.tk.geometry(data[k])
  1592. except Exception as e:
  1593. cprint("load_window_position Exception:",e,color="red")
  1594. #print("winfo",k,win.tk.geometry())
  1595. f.close()
  1596. except Exception as e:
  1597. cprint("load_window_position Exception:",e,color="red")
  1598. return
  1599. class Xevent():
  1600. """ global input event Handeler for short cut's ... etc
  1601. """
  1602. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  1603. self.fix = fix
  1604. self.data=data
  1605. self.attr = attr
  1606. self.elem = elem
  1607. self.mode = mode
  1608. def setup(self,event):
  1609. cprint("xevent.SETUP",[self.mode,self.attr],color="red")
  1610. if self.mode == "SETUP":
  1611. if self.attr == "SAVE\nSHOW":
  1612. self.elem["bg"] = "orange"
  1613. self.elem["text"] = "SAVING..."
  1614. self.elem["bg"] = "red"
  1615. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1616. #self.elem["fg"] = "orange"
  1617. self.elem.config(activebackground="orange")
  1618. modes.val(self.attr,1)
  1619. PRESETS.backup_presets()
  1620. FIXTURES.backup_patch()
  1621. save_window_position()
  1622. #time.sleep(1)
  1623. #modes.val(self.attr,0)
  1624. self.elem["bg"] = "lightgrey"
  1625. #self.elem["fg"] = "lightgrey"
  1626. self.elem.config(activebackground="lightgrey")
  1627. elif self.attr == "LOAD\nSHOW":
  1628. name = "LOAD-SHOW"
  1629. base = Base()
  1630. line1 = "PATH: "+base.show_path1 +base.show_name
  1631. line2 = "DATE: "+ time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
  1632. class cb():
  1633. def __init__(self,name=""):
  1634. self.name=name
  1635. print("cb",name)
  1636. def cb(self,event=None,**args):
  1637. print("cdb",self.name,event,args)
  1638. if self.name != "<exit>":
  1639. print("-----------------------:")
  1640. LOAD_SHOW_AND_RESTAT(self.name).cb()
  1641. #self.elem["bg"] = "lightgrey"
  1642. #self.elem.config(activebackground="lightgrey")
  1643. pw = PopupList(name,cb=cb)
  1644. frame = pw.sframe(line1=line1,line2=line2)
  1645. r = _load_show_list(frame,cb=cb)
  1646. #self.elem["bg"] = "red"# "lightgrey"
  1647. #self.elem.config(activebackground="red")
  1648. #self.elem.config(activebackground="lightgrey")
  1649. #w.tk.attributes('-topmost',False)
  1650. elif self.attr == "SAVE\nSHOW AS":
  1651. base = Base()
  1652. #def _cb(fname):
  1653. def _cb(data):
  1654. fname = data["Value"]
  1655. print(self,"save_show._cb()",fname)
  1656. fpath,fname = base.build_path(fname)
  1657. cprint("SAVE AS",fpath,fname)
  1658. if base._create_path(fpath):
  1659. a=PRESETS.backup_presets(save_as=fpath)
  1660. b=FIXTURES.backup_patch(save_as=fpath)
  1661. #base._set(fname)
  1662. save_window_position(save_as=fpath)
  1663. LOAD_SHOW_AND_RESTAT(fname).cb()
  1664. dialog._cb = _cb
  1665. dialog.askstring("SAVE SHOW AS","SAVE SHOW AS:")
  1666. elif self.attr == "SAVE &\nRESTART":
  1667. self.elem["bg"] = "orange"
  1668. self.elem["text"] = "SAVING..."
  1669. self.elem["bg"] = "red"
  1670. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1671. #self.elem["fg"] = "orange"
  1672. self.elem.config(activebackground="orange")
  1673. modes.val(self.attr,1)
  1674. PRESETS.backup_presets()
  1675. FIXTURES.backup_patch()
  1676. save_window_position()
  1677. self.elem["text"] = "RESTARTING..."
  1678. #time.sleep(1)
  1679. #modes.val(self.attr,0)
  1680. self.elem["bg"] = "lightgrey"
  1681. #self.elem["fg"] = "lightgrey"
  1682. self.elem.config(activebackground="lightgrey")
  1683. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  1684. elif self.attr == "DRAW\nGUI":
  1685. #self.elem["bg"] = "orange"
  1686. old_text = self.elem["text"]
  1687. self.elem["text"] = "DRAWING..."
  1688. #self.elem["bg"] = "red"
  1689. #time.sleep(0.05)
  1690. #print("redraw",name)
  1691. #if name == "PATCH":
  1692. # gui_patch.draw()
  1693. #if name == "DIMMER":
  1694. # gui_fix.draw()
  1695. self.elem["text"] = "PATCH..."
  1696. window_manager.top("PATCH")
  1697. gui_patch.draw()
  1698. self.elem["text"] = "FIX..."
  1699. gui_fix.draw()
  1700. window_manager.top("FIXTURES")
  1701. master._refresh_exec()
  1702. self.elem["text"] = old_text
  1703. else:
  1704. r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
  1705. return 1
  1706. def live(self,event):
  1707. if self.mode == "LIVE":
  1708. if "FADE" in self.attr or "DELAY" in self.attr:
  1709. if self.attr == "FADE":
  1710. ct = FADE
  1711. if self.attr == "DELAY":
  1712. ct = DELAY
  1713. if "PAN/TILT\nFADE" in self.attr:
  1714. ct = FADE_move
  1715. value = ct.val()
  1716. #print("EVENT CHANGE ",[self.attr])
  1717. print("EVENT CHANGE:",self.mode,value,self.attr)
  1718. if value < 0.01:
  1719. ct.val(0.01)
  1720. elif value > 100.0:
  1721. pass #value = 100
  1722. if event.num == 4:
  1723. value *= 1.1
  1724. elif event.num == 5:
  1725. value /= 1.1
  1726. elif event.num == 1:
  1727. if ct._is():
  1728. ct.off()# = 0
  1729. self.data.commands.elem[self.attr]["bg"] = "grey"
  1730. self.elem.config(activebackground="grey")
  1731. else:
  1732. ct.on()# = 1
  1733. self.data.commands.elem[self.attr]["bg"] = "green"
  1734. self.elem.config(activebackground="lightgreen")
  1735. elif event.num == 2:
  1736. if value > 1 and value < 4:
  1737. value = 4
  1738. elif value > 3 and value < 6:
  1739. value = 6
  1740. elif value > 5 and value < 7:
  1741. value = 8
  1742. elif value > 7 and value < 9:
  1743. value = 10
  1744. elif value > 9:
  1745. value = 0.01
  1746. elif value < 1:
  1747. value = 1.1
  1748. value = round(value,3)
  1749. value = ct.val(value)
  1750. if self.attr == "FADE":
  1751. self.data.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
  1752. if self.attr == "DELAY":
  1753. self.data.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
  1754. if "PAN/TILT\nFADE" in self.attr:
  1755. self.data.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
  1756. def command(self,event):
  1757. if self.mode == "COMMAND":
  1758. if self.attr == "CLEAR":
  1759. if event.num == 1:
  1760. ok = FIXTURES.clear()
  1761. if ok:
  1762. master.refresh_fix()
  1763. modes.val(self.attr,0)
  1764. elif self.attr == "SAVE":
  1765. modes.val(self.attr,1)
  1766. PRESETS.backup_presets()
  1767. FIXTURES.backup_patch()
  1768. #time.sleep(1)
  1769. modes.val(self.attr,0)
  1770. elif self.attr == "S-KEY":
  1771. global _global_short_key
  1772. if _global_short_key:
  1773. _global_short_key = 0
  1774. master.commands.elem["S-KEY"]["bg"] = "red"
  1775. master.commands.elem["S-KEY"]["activebackground"] = "red"
  1776. else:
  1777. _global_short_key = 1
  1778. master.commands.elem["S-KEY"]["bg"] = "green"
  1779. master.commands.elem["S-KEY"]["activebackground"] = "green"
  1780. print("s-key",_global_short_key)
  1781. else:
  1782. if event.num == 1:
  1783. print("ELSE",self.attr)
  1784. modes.val(self.attr,1)
  1785. return 0
  1786. def encoder(self,event):
  1787. global _shift_key
  1788. if self.mode == "ENCODER" or self.mode == "ENCODER2":
  1789. cprint("Xevent","ENC",self.fix,self.attr,self.mode)
  1790. cprint("SHIFT_KEY",_shift_key,"??????????")
  1791. #cprint(self.data)
  1792. val=""
  1793. if event.num == 1:
  1794. val ="click"
  1795. elif event.num == 4:
  1796. val ="++"
  1797. if _shift_key:
  1798. val = "+"
  1799. elif event.num == 5:
  1800. val ="--"
  1801. if _shift_key:
  1802. val = "-"
  1803. print("SHIFT",val,_shift_key)
  1804. if val:
  1805. #if self.attr == "DIM" and self.fix == 0 and val == "click":
  1806. #if self.fix == 0 and val == "click":
  1807. #if self.attr == "DIM" and self.fix == 0 and val == "click":
  1808. #if self.attr == "DIM" and self.fix == 0 and val == "click":
  1809. # pass
  1810. #else:
  1811. if 1:
  1812. FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
  1813. if self.mode == "ENCODER": # fast refresh
  1814. master._refresh_fix()
  1815. else: #"ENCODER2" slow refresh
  1816. master.refresh_fix()
  1817. #master._refresh_fix()
  1818. def cb(self,event):
  1819. cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
  1820. print(["type",event.type,"num",event.num])
  1821. try:
  1822. change = 0
  1823. if "keysym" in dir(event):
  1824. if "Escape" == event.keysym:
  1825. ok = FIXTURES.clear()
  1826. master.refresh_fix()
  1827. return 0
  1828. if self.mode == "SETUP":
  1829. self.setup(event)
  1830. elif self.mode == "COMMAND":
  1831. self.command(event)
  1832. elif self.mode == "LIVE":
  1833. self.live(event)
  1834. elif self.mode == "ENCODER":
  1835. self.encoder(event)
  1836. elif self.mode == "ENCODER2":
  1837. self.encoder(event)
  1838. elif self.mode == "FX":
  1839. cprint("Xevent CALLING FX WRONG EVENT OBJECT !!",color="red")
  1840. elif self.mode == "ROOT":
  1841. if event.keysym=="Escape":
  1842. pass
  1843. elif self.mode == "INPUT":
  1844. print("INP",self.data.entry.get())
  1845. if event.keycode == 36:
  1846. x=self.data.entry.get()
  1847. #client.send(x)
  1848. elif self.mode == "INPUT2":
  1849. print("INP2",self.data.entry2.get())
  1850. if event.keycode == 36:
  1851. x=self.data.entry2.get()
  1852. #client.send(x)
  1853. elif self.mode == "INPUT3":
  1854. print("INP3",self.data.entry3.get())
  1855. if event.keycode == 36:
  1856. x=self.data.entry3.get()
  1857. #client.send(x)
  1858. elif self.mode == "PRESET":
  1859. nr = self.attr #int(self.attr.split(":")[1])-1
  1860. if event.num == 3: # right click for testing
  1861. if str(event.type) == '4': #4 ButtonPress
  1862. if modes.val("CFG-BTN"):
  1863. master.btn_cfg(nr,testing=1)
  1864. if event.num == 1:
  1865. if str(event.type) == '4': #4 ButtonPress
  1866. if modes.val("REC"):
  1867. self.data.preset_rec(nr)
  1868. modes.val("REC",0)
  1869. elif modes.val("DEL"):
  1870. ok=PRESETS.delete(nr)
  1871. if ok:
  1872. modes.val("DEL",0)
  1873. master.refresh_exec()
  1874. elif modes.val("COPY"):
  1875. ok=PRESETS.copy(nr)
  1876. if ok:
  1877. modes.val("COPY",0)
  1878. master.refresh_exec()
  1879. elif modes.val("MOVE"):
  1880. ok=PRESETS.move(nr)
  1881. if ok:
  1882. #modes.val("MOVE",0) # keep MOVE on
  1883. master.refresh_exec()
  1884. elif modes.val("CFG-BTN"):
  1885. master.btn_cfg(nr)
  1886. elif modes.val("LABEL"):#else:
  1887. master.label(nr)
  1888. elif modes.val("EDIT"):
  1889. FIXTURES.clear()
  1890. self.data.preset_select(nr)
  1891. self.data.preset_go(nr,xfade=0,event=event,val=255,button="go")
  1892. modes.val("EDIT", 0)
  1893. master.refresh_fix()
  1894. elif modes.val("SELECT"):
  1895. self.data.preset_select(nr)
  1896. else:
  1897. self.data.preset_go(nr,event=event,val=255)
  1898. else:
  1899. self.data.preset_go(nr,xfade=0,event=event,val=0)
  1900. if event.num == 3:
  1901. if not modes.val("REC"):
  1902. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=255)
  1903. return 0
  1904. elif self.mode == "INPUT":
  1905. return 0
  1906. except Exception as e:
  1907. cprint("== cb EXCEPT",e,color="red")
  1908. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1909. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1910. return 1
  1911. def wheel(event,d=None):
  1912. print("wheel",event,d)
  1913. import copy
  1914. class Element():
  1915. def __init__(self):
  1916. self.__data = {}
  1917. def set(self,key,val):
  1918. self.__data[key] = val
  1919. class Base():
  1920. def __init__(self):
  1921. cprint("Base.init()",color="red")
  1922. self._init()
  1923. def _init(self):
  1924. show_name = "DemoShow"
  1925. self.home = os.environ['HOME']
  1926. self.show_path0 = self.home +"/LibreLight/"
  1927. self.show_path = self.show_path0
  1928. self.show_path1 = self.show_path0 + "show/"
  1929. try:
  1930. f = open(self.show_path+"init.txt","r")
  1931. for line in f.readlines():
  1932. #cprint(line)
  1933. if not line.startswith("#"):
  1934. show_name = line.strip()
  1935. show_name = show_name.replace(".","")
  1936. show_name = show_name.replace("\\","")
  1937. show_name = show_name.replace("/","")
  1938. self.show_name = show_name
  1939. except Exception as e:
  1940. cprint("show name exception",color="red")
  1941. msg="Error Exception:{}".format(e)
  1942. r=tkinter.messagebox.showwarning(message=msg,parent=None)
  1943. finally:
  1944. f.close()
  1945. fpath = self.show_path1 +show_name
  1946. if not os.path.isdir(fpath):
  1947. cprint(fpath)
  1948. print( os.path.isdir(fpath))
  1949. msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  1950. msg += "please check\n"
  1951. msg += "-{}init.txt\n".format(self.show_path0)
  1952. msg += "-{}".format(self.show_path1)
  1953. showwarning(msg=msg,title="Show Error")
  1954. exit()
  1955. self._check()
  1956. def _set(self,fname):
  1957. ok= os.path.isdir(self.show_path1+"/"+fname)
  1958. ini = self.show_path0+"init.txt"
  1959. print("SET SHOW NAME",fname,ok,ini)
  1960. try:
  1961. f = open( ini ,"r")
  1962. lines = f.readlines()
  1963. f.close()
  1964. if len(lines) >= 10: # cut show history
  1965. print("_set",ini,len(lines))
  1966. lines = lines[-10:]
  1967. f = open( ini ,"w")
  1968. f.writelines(lines)
  1969. f.close()
  1970. exit()
  1971. except:pass
  1972. if ok:
  1973. #self.show_name = fname
  1974. f = open( ini ,"a")
  1975. f.write(fname+"\n")
  1976. f.close()
  1977. return 1
  1978. def _check(self):
  1979. if not os.path.isdir(self.show_path):
  1980. os.mkdir(self.show_path)
  1981. self.show_path += "/show/"
  1982. if not os.path.isdir(self.show_path):
  1983. os.mkdir(self.show_path)
  1984. self.show_path += "/" +self.show_name +"/"
  1985. if not os.path.isdir(self.show_path):
  1986. os.mkdir(self.show_path)
  1987. pass
  1988. def _list(self):
  1989. #self._check()
  1990. show_list = list(os.listdir( self.show_path1 ))
  1991. out = []
  1992. for fname in show_list:
  1993. #print(fname)
  1994. ctime = os.path.getmtime(self.show_path1+fname)
  1995. ctime = time.strftime("%Y-%m-%d %X", time.localtime(ctime)) #1650748726.6604707))
  1996. try:
  1997. mtime = os.path.getmtime(self.show_path1+fname+"/patch.sav")
  1998. mtime = time.strftime("%Y-%m-%d %X", time.localtime(mtime)) #1650748726.6604707))
  1999. except:
  2000. mtime = 0
  2001. if mtime:
  2002. out.append([fname,mtime])#,ctime])
  2003. from operator import itemgetter
  2004. out=sorted(out, key=itemgetter(1))
  2005. out.reverse()
  2006. return out
  2007. def _load(self,filename):
  2008. xfname = self.show_path+"/"+str(filename)+".sav"
  2009. print("load",xfname)
  2010. try:
  2011. f = open(xfname,"r")
  2012. lines = f.readlines()
  2013. f.close()
  2014. except Exception as e:
  2015. msg = "Exception: {}".format(e)
  2016. msg += "\n\ncheck\n-init.txt"
  2017. cprint(msg,color="red")
  2018. showwarning(msg=msg,title="load Error")
  2019. data = OrderedDict()
  2020. labels = OrderedDict()
  2021. i=0
  2022. for line in lines:
  2023. if line.count("\t") < 2:
  2024. cprint("Error line.count('\\t') < 2 (is:{})".format(line.count("\t")),color="red",end=" ")
  2025. cprint("file:{}".format(xfname),color="red")
  2026. continue
  2027. key,label,rdata = line.split("\t",2)
  2028. key = int(key)
  2029. jdata = json.loads(rdata,object_pairs_hook=OrderedDict)
  2030. nrnull = 0
  2031. if "ATTRIBUT" in jdata: # translate old FIXTURES.fixtures start with 0 to 1
  2032. if nrnull:
  2033. print("DMX NR IS NULL",attr,"CHANGE +1")
  2034. for attr in jdata["ATTRIBUT"]:
  2035. if "NR" in jdata["ATTRIBUT"][attr]:
  2036. nr = jdata["ATTRIBUT"][attr]["NR"]
  2037. if nr >= 0:
  2038. jdata["ATTRIBUT"][attr]["NR"] +=1
  2039. data[key] = jdata
  2040. labels[key] = label
  2041. return data,labels
  2042. def _clean_path(self,fpath):
  2043. _path=[]
  2044. for i in fpath:
  2045. fpath = fpath.replace(" ","_")
  2046. if i in string.ascii_letters+string.digits+"äöüßÖÄÜ_-":
  2047. _path.append(i)
  2048. path = "".join(_path)
  2049. return path
  2050. def build_path(self,save_as):
  2051. save_as = self._clean_path(save_as)
  2052. path = self.show_path.split("/")
  2053. path = "/".join(path[:-2])
  2054. fpath = path+"/"+save_as
  2055. return fpath,save_as
  2056. def _create_path(self,fpath):
  2057. if os.path.isdir(fpath):
  2058. cprint("STOP SHOW EXIST !",color="red")
  2059. return 0
  2060. else:
  2061. cprint("CREATE DIR ",fpath,color="green")
  2062. os.mkdir(fpath)
  2063. #self._set(save_as)
  2064. return fpath
  2065. def _backup(self,filename,data,labels,save_as):
  2066. if save_as:
  2067. xfname = save_as +"/"+str(filename)+".sav"
  2068. else:
  2069. xfname = self.show_path+"/"+str(filename)+".sav"
  2070. print("backup",xfname)
  2071. f = open(xfname,"w")
  2072. for key in data:
  2073. line = data[key]
  2074. #print(line)
  2075. label = "label"
  2076. if key in labels:
  2077. label = labels[key]
  2078. if label == "Name-"+str(key):
  2079. label = ""
  2080. #print(xfname,"load",key,label,len(line))
  2081. f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
  2082. f.close()
  2083. return 1
  2084. class Event():
  2085. def __init__(self,name):
  2086. self.name=name
  2087. #print("init",self)
  2088. def event(self,event):
  2089. print(self.name,event)
  2090. class scroll():
  2091. def __init__(self,canvas):
  2092. self.canvas=canvas
  2093. def config(self,event):
  2094. canvas = self.canvas
  2095. canvas.configure(scrollregion=canvas.bbox("all"))#,width=400,height=200)
  2096. def hex_to_rgb(hex):
  2097. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  2098. class cb():
  2099. def __init__(self,win):
  2100. self.win = win
  2101. def _callback(self,event):
  2102. clobj=event.widget
  2103. ## undermouse=find_withtag(master.CURRENT)
  2104. undermouse=self.win.find_closest(self.win.CURRENT)
  2105. print( repr(undermouse))
  2106. def callback(self,event):
  2107. print(__file__,self,"callback",event)
  2108. cnv = self.win
  2109. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  2110. tags = cnv.gettags(item)
  2111. #cnv.itemconfigure(self.tag, text=tags[0])
  2112. print(tags,item)
  2113. color = cnv.itemcget(item, "fill")
  2114. cnv.itemconfig("all", width=1)#filla="green")
  2115. cnv.itemconfig(item, width=3)#filla="green")
  2116. print(color)
  2117. print( hex_to_rgb(color[1:]))
  2118. class MiniButton:
  2119. def __init__(self,root,width=72,height=38,text="button"):
  2120. self.text=text
  2121. self.rb = tk.Frame(root, highlightbackground = "lightgrey", highlightthickness = 1, bd=0)
  2122. self.bb = tk.Canvas(self.rb, highlightbackground = "black", highlightthickness = 1, bd=1,relief=tk.RAISED)
  2123. self.bb.configure(width=width, height=height)
  2124. self.fg = "#002"
  2125. self.label = []
  2126. self.bind("<Enter>", self.on_enter)
  2127. self.bind("<Leave>", self.on_leave)
  2128. # !! BLOCK's other bindings like GO
  2129. #self.bind("<Button-1>", self.on_b1)
  2130. #self.bind("<ButtonPress>", self.on_press)
  2131. #self.bind("<ButtonRelease>", self.on_release)
  2132. #self.bind("<ButtonRelease-1>", self.on_release)
  2133. self.activebackground="lightgrey"
  2134. self.defaultBackground="grey"
  2135. def on_b1(self, e):
  2136. print("on_b1",e)
  2137. #self.bb.config(background=self.activebackground)
  2138. self.bb.config(relief=tk.SUNKEN)#abackground=self.activebackground)
  2139. return 1
  2140. def on_press(self, e):
  2141. print("on_press",e)
  2142. #self.bb.config(background=self.activebackground)
  2143. self.bb.config(relief=tk.SUNKEN)#abackground=self.activebackground)
  2144. return 1
  2145. def on_release(self, e):
  2146. print("on_release",e)
  2147. #self.bb.config(background=self.activebackground)
  2148. self.bb.config(relief=tk.RAISED)#abackground=self.activebackground)
  2149. return 1
  2150. def on_enter(self, e):
  2151. #print("on_enter",e)
  2152. #self.bb.config(background=self.activebackground)
  2153. self.bb.config(relief=tk.FLAT)#abackground=self.activebackground)
  2154. return 1
  2155. def on_leave(self, e):
  2156. #print("on_leave",e)
  2157. self.bb.config(background=self.defaultBackground)
  2158. self.bb.config(relief=tk.RAISED)#abackground=self.activebackground)
  2159. return 1
  2160. def _label(self,text="1\n2\n3\n"):
  2161. z = 0
  2162. self.bb.delete("label")
  2163. self.label = []
  2164. for t in text.split("\n"):
  2165. self.l = self.bb.create_text(37,z*10+9,text=t,anchor="c",tag="label")
  2166. #self.l["color"] = self.fg
  2167. self.label.append(self.l)
  2168. z+=1
  2169. def _configure(self,**args):
  2170. if "text" in args:
  2171. self.text = args["text"]
  2172. self._label(self.text)
  2173. if "bg" in args:
  2174. #print(dir(self.bb))
  2175. self.bb.configure(bg=args["bg"])
  2176. self.defaultBackground=args["bg"]
  2177. if "fg" in args:
  2178. #print(dir(self.bb))
  2179. self.fg=args["fg"]
  2180. #if len(self.label):
  2181. # self.label[0].configure(color="red") #args["fg"])
  2182. #self.defaultBackground=args["fg"]
  2183. def configure(self,**args):
  2184. self._configure(**args)
  2185. def config(self,**args):
  2186. self._configure(**args)
  2187. def bind(self,etype="<Button>",cb=None):
  2188. #bb.bind("<ButtonRelease>",Xevent(fix=0,elem=b,attr=k,data=self,mode="PRESET").cb)
  2189. if cb:
  2190. self.bb.bind(etype,cb)
  2191. def grid(self,row=0, column=0, sticky=""):
  2192. self.bb.pack() #(row=row, column=column, sticky=sticky)
  2193. self.rb.grid(row=row, column=column, sticky=sticky)
  2194. class ExecButton(MiniButton):
  2195. def __init__(self,root,width=72,height=38,text="button"):
  2196. super().__init__(root,width,height,text)
  2197. self.text = "1\n2\n3\n"
  2198. self.x9font = tk.font.Font(family="FreeSans", size=9, weight="bold")
  2199. self.x8font = tk.font.Font(family="FreeSans", size=8, weight="bold")
  2200. self.x7font = tk.font.Font(family="FreeSans", size=7, weight="bold")
  2201. self.x6font = tk.font.Font(family="FreeSans", size=6, weight="bold")
  2202. self.x5font = tk.font.Font(family="FreeSans", size=5, weight="bold")
  2203. def config(self,**args):
  2204. self._configure(**args)
  2205. self._label()
  2206. def configure(self,**args):
  2207. self._configure(**args)
  2208. self._label()
  2209. def _label(self,text=None):
  2210. if type(text) is str:
  2211. self.text = text
  2212. else:
  2213. text = self.text
  2214. self.bb.delete("label")
  2215. txt2 = text
  2216. try:
  2217. text = text.split("\n")[1]
  2218. except:pass
  2219. if "grün" in text.lower() or "green" in text.lower():
  2220. self.l = self.bb.create_rectangle(10,27,20,37,fill="green",tag="label")
  2221. elif "blau" in text.lower() or "blue" in text.lower():
  2222. self.l = self.bb.create_rectangle(10,27,20,37,fill="blue",tag="label")
  2223. elif "rot" in text.lower() or "red" in text.lower():
  2224. self.l = self.bb.create_rectangle(10,27,20,37,fill="red",tag="label")
  2225. elif "orange" in text.lower():# or "yellow" in text.lower():
  2226. self.l = self.bb.create_rectangle(10,27,20,37,fill="orange",tag="label")
  2227. elif "weiß" in text.lower() or "white" in text.lower():
  2228. self.l = self.bb.create_rectangle(10,27,20,37,fill="white",tag="label")
  2229. elif "cyan" in text.lower():# or "yellow" in text.lower():
  2230. self.l = self.bb.create_rectangle(10,27,20,37,fill="cyan",tag="label")
  2231. elif "gelb" in text.lower() or "yellow" in text.lower():
  2232. self.l = self.bb.create_rectangle(10,27,20,37,fill="yellow",tag="label")
  2233. elif "mage" in text.lower() or "mage" in text.lower():
  2234. self.l = self.bb.create_rectangle(10,27,20,37,fill="magenta",tag="label")
  2235. if "nebel" in text.lower() or "smoke" in text.lower() or "haze" in text.lower():
  2236. self.l = self.bb.create_rectangle(10,27,60,37,fill="white",tag="label")
  2237. if "mh " in text.lower() or " mh" in text.lower() :
  2238. self.l = self.bb.create_rectangle(30,27,35,32,fill="black",tag="label")
  2239. self.l = self.bb.create_rectangle(28,34,37,37,fill="black",tag="label")
  2240. if "off" in text.lower():
  2241. self.l = self.bb.create_rectangle(50,30,55,35,fill="black",tag="label")
  2242. if "dim" in text.lower() or "front" in text.lower() or "on" in text.lower():
  2243. #self.l = self.bb.create_line(56,30,60,28,fill="black",tag="label")
  2244. self.l = self.bb.create_rectangle(50,30,55,35,fill="white",tag="label")
  2245. #self.l = self.bb.create_line(56,36,58,36,fill="black",tag="label")
  2246. if "circle" in text.lower():
  2247. self.l = self.bb.create_oval(30,27,40,37,fill="",tag="label")
  2248. if "pan" in text.lower():
  2249. self.l = self.bb.create_line(20,34 ,45,34,fill="black",arrow=tk.BOTH,tag="label")
  2250. if "tilt" in text.lower():
  2251. self.l = self.bb.create_line(30,25 ,30,43,fill="black",arrow=tk.BOTH,tag="label")
  2252. text = txt2
  2253. z = 0
  2254. for t in text.split("\n"):
  2255. ts = 10
  2256. _max = 7
  2257. if z==1 and len(t) >= _max:
  2258. ts = int(10 - (len(t)-_max)/1.5)
  2259. if ts < 5:
  2260. ts = 5
  2261. xfont = self.x9font
  2262. if 1:
  2263. if ts == 9:
  2264. xfont = self.x9font
  2265. elif ts == 8:
  2266. xfont = self.x8font
  2267. elif ts == 7:
  2268. xfont = self.x7font
  2269. elif ts == 6:
  2270. xfont = self.x7font
  2271. elif ts == 5:
  2272. xfont = self.x7font
  2273. #self.l = self.bb.create_text(37,z*10+9,text=t,anchor="c",tag="label",fill=self.fg,font=xfont)
  2274. self.l = self.bb.create_text(37,z*10+9,text=t,anchor="c",tag="label",fill=self.fg)
  2275. else:
  2276. self.l = self.bb.create_text(37,z*10+9,text=t,anchor="c",tag="label",fill=self.fg)
  2277. z+=1
  2278. class Elem_Container():
  2279. def __init__(self):
  2280. self.commands = []
  2281. self.val = {}
  2282. self.elem = {}
  2283. class GUI():
  2284. def __init__(self):
  2285. #super().__init__()
  2286. self.base = Base ()
  2287. self.load()
  2288. self._XX = 0
  2289. self.all_attr =["DIM","PAN","TILT"]
  2290. self.elem_attr = {}
  2291. self.fx_moves = Elem_Container()
  2292. self.fx_moves.commands =["REC-FX","FX OFF","\n"
  2293. ,"FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  2294. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  2295. ]
  2296. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  2297. self.fx = Elem_Container()
  2298. self.fx.commands =[
  2299. "FX:DIM","FX:RED", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  2300. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","FX-X:\n-","FX:MODE"
  2301. ]
  2302. self.fx_generic = Elem_Container()
  2303. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON"]
  2304. self.commands = Elem_Container()
  2305. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  2306. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  2307. ,"BLIND","CLEAR","REC","EDIT","COPY","-","\n"
  2308. ]
  2309. self.elem_presets = {}
  2310. for i in range(8*8*8):
  2311. if i not in PRESETS.val_presets:
  2312. name = "Preset:"+str(i+1)+":\nXYZ"
  2313. #self.presets[i] = [i]
  2314. PRESETS.val_presets[i] = OrderedDict() # FIX
  2315. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  2316. PRESETS.label_presets[i] = "-"
  2317. modes.set_cb(self.xcb)
  2318. def button_refresh(self,name,color,color2=None,text="",fg=None):
  2319. cprint("button_refresh",name,color)
  2320. #if color == "gold":
  2321. # color2 = "yellow"
  2322. if color2 is None:
  2323. color2 = color
  2324. if text:
  2325. text = "\n"+str(text)
  2326. if name in self.commands.elem:
  2327. self.commands.elem[name]["bg"] = color
  2328. self.commands.elem[name]["text"] = name+ text
  2329. self.commands.elem[name].config(activebackground=color2)
  2330. if fg:
  2331. self.commands.elem[name]["fg"] = fg
  2332. elif name in self.fx.elem:
  2333. #todo
  2334. self.fx.elem[name]["bg"] = color
  2335. self.fx.elem[name].config(activebackground=color2)
  2336. if fg:
  2337. self.fx.elem[name]["fg"] = fg
  2338. # new version
  2339. for elems in [self.fx_moves]:
  2340. if name in elems.elem:
  2341. elem = elems.elem[name]
  2342. cprint("elem",elem)
  2343. elem.config(bg = color)
  2344. elem.config(text = name+text)
  2345. elem.config(activebackground=color2)
  2346. if fg and "fg" in elem:
  2347. elem["fg"] = fg
  2348. def btn_cfg(self,nr,testing=0):
  2349. cfg = PRESETS._btn_cfg(nr)
  2350. button = PRESETS.btn_cfg(nr)
  2351. label = PRESETS.label(nr)
  2352. def _cb(data):
  2353. print(self,"btn_cfg._cb()",data)
  2354. if data:
  2355. if "Button" in data and type(data["Button"]) is str:
  2356. txt = data["Button"]
  2357. PRESETS.btn_cfg(nr,txt)
  2358. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  2359. if "Label" in data and type(data["Label"]) is str:
  2360. txt = data["Label"]
  2361. PRESETS.label(nr,txt)
  2362. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  2363. modes.val("CFG-BTN",0)
  2364. master._refresh_exec()
  2365. dialog._cb = _cb
  2366. if 1: # testing:
  2367. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  2368. else:
  2369. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  2370. def label(self,nr):
  2371. txt = PRESETS.label(nr)
  2372. def _cb(data):
  2373. txt = data["Value"]
  2374. print(self,"label._cb()",nr,txt)
  2375. if txt:
  2376. PRESETS.label(nr,txt)
  2377. self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
  2378. modes.val("LABEL", 0)
  2379. master._refresh_exec()
  2380. dialog._cb= _cb #_x(nr)
  2381. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  2382. def xcb(self,mode,value=None):
  2383. cprint("MODE CALLBACK",mode,value,color="green",end="")
  2384. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  2385. if value:
  2386. cprint("===== ON ======",color="red")
  2387. txt = ""
  2388. if mode == "REC-FX":
  2389. modes.val("REC",0)
  2390. modes.val("REC",1)
  2391. if value == 2:
  2392. if mode in ["MOVE","COPY"]:
  2393. txt="to"
  2394. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  2395. else:
  2396. if mode in ["MOVE","COPY"]:
  2397. txt="from"
  2398. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  2399. else:
  2400. cprint("===== OFF ======",color="red")
  2401. if mode == "REC-FX":
  2402. modes.val("REC",0)
  2403. self.button_refresh(mode,color="lightgrey")#,fg="black")
  2404. def load(self,fname=""):
  2405. pass
  2406. def exit(self):
  2407. print("__del__",self)
  2408. PRESETS.backup_presets()
  2409. #print("********************************************************")
  2410. FIXTURES.backup_patch()
  2411. #print("*********del",self,"***********************************************")
  2412. def refresh_exec(self):
  2413. refresher.reset() # = Refresher()
  2414. def _refresh_exec(self):
  2415. cprint("PRESET.refresh_exec()")
  2416. self._XX +=1
  2417. for k in PRESETS.val_presets:
  2418. label = ""
  2419. if k not in self.elem_presets:
  2420. cprint("ERROR",k ,"not in elem_presets continue")
  2421. continue
  2422. if k in PRESETS.label_presets:
  2423. label = PRESETS.label_presets[k]
  2424. #print([label])
  2425. b = self.elem_presets[k]
  2426. ifval = 0
  2427. fx_only = 0
  2428. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  2429. sdata = PRESETS.val_presets[k]
  2430. #print("sdata7654",sdata)
  2431. BTN="go"
  2432. if "CFG" in sdata:#["BUTTON"] = "GO"
  2433. if "BUTTON" in sdata["CFG"]:
  2434. BTN = sdata["CFG"]["BUTTON"]
  2435. #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
  2436. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  2437. #txt+=str(self._XX)
  2438. b.configure(text= txt)
  2439. b.configure(bg="yellow")
  2440. b.config(activebackground="yellow")
  2441. if len(sdata) > 1:
  2442. ifval = 1
  2443. fx_color = 0
  2444. val_color = 0
  2445. for fix in sdata:
  2446. if fix == "CFG":
  2447. continue
  2448. #print( "$$$$",fix,sdata[fix])
  2449. for attr in sdata[fix]:
  2450. if "FX2" in sdata[fix][attr]:
  2451. if sdata[fix][attr]["FX2"]:
  2452. fx_color = 1
  2453. if "FX" in sdata[fix][attr]:
  2454. if sdata[fix][attr]["FX"]:
  2455. fx_color = 1
  2456. if "VALUE" in sdata[fix][attr]:
  2457. if sdata[fix][attr]["VALUE"] is not None:
  2458. val_color = 1
  2459. b.configure(fg= "black")
  2460. if val_color:
  2461. b.configure(bg="gold")
  2462. b.config(activebackground="#ffaa55")
  2463. if fx_color:
  2464. b.configure(fg = "blue")
  2465. else:
  2466. if fx_color:
  2467. fx_only = 1
  2468. else:
  2469. b.configure(bg="grey")
  2470. b.config(activebackground="#aaa")
  2471. if "\n" in txt:
  2472. txt1 = txt.split("\n")[0]
  2473. b.configure(fg="black")
  2474. if ifval:
  2475. if fx_only:
  2476. b.configure(bg = "cyan")
  2477. b.config(activebackground="#55d4ff")
  2478. if "SEL" in txt1:
  2479. b.configure(bg="#77f")
  2480. else:
  2481. b.configure(bg="grey")
  2482. b.configure(fg="darkgrey") #black")
  2483. if "SEL" in txt1:
  2484. b.configure(fg="blue")
  2485. elif "ON" in txt1:
  2486. b.configure(fg="#040")
  2487. elif "GO" in txt1:
  2488. b.configure(fg="#555")
  2489. if "FL" in txt1:
  2490. b.configure(fg="#00e")
  2491. def refresh_fix(self):
  2492. refresher.reset() # = Refresher()
  2493. def _refresh_fix(self):
  2494. c_d =0
  2495. c_f =0
  2496. c_a =0
  2497. for fix in FIXTURES.fixtures:
  2498. sdata = FIXTURES.fixtures[fix]
  2499. _c_a = 0
  2500. for attr in sdata["ATTRIBUT"]:
  2501. if "FINE" in attr:
  2502. continue
  2503. v2 = sdata["ATTRIBUT"][attr]["VALUE"]
  2504. if fix in self.elem_attr:
  2505. elem = self.elem_attr[fix][attr]
  2506. #print( attr,v2)
  2507. elem["text"] = "{} {:0.2f}".format(attr,v2)
  2508. if sdata["ATTRIBUT"][attr]["ACTIVE"]:
  2509. elem["bg"] = "yellow"
  2510. elem.config(activebackground="yellow")
  2511. if "DIM" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 1:
  2512. c_d+=1
  2513. else:
  2514. _c_a += 1
  2515. else:
  2516. elem["bg"] = "grey"
  2517. elem.config(activebackground="grey")
  2518. if "FX2" not in sdata["ATTRIBUT"][attr]: # insert FX2 excetption
  2519. sdata["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  2520. if sdata["ATTRIBUT"][attr]["FX"]:
  2521. elem["fg"] = "blue"
  2522. elif sdata["ATTRIBUT"][attr]["FX2"]:
  2523. elem["fg"] = "red"
  2524. else:
  2525. elem["fg"] = "black"
  2526. c_a += _c_a
  2527. if _c_a>0:
  2528. c_f +=1
  2529. c_a2=0
  2530. if c_f > 0:
  2531. c_a2 = round(c_a/c_f,2)
  2532. if c_a2 % 1 > 0:
  2533. gui_menu.config("FIXTURES","bg","orange")
  2534. gui_menu.config("FIXTURES","activebackground","orange")
  2535. else:
  2536. gui_menu.config("FIXTURES","bg","yellow")
  2537. gui_menu.config("FIXTURES","activebackground","yellow")
  2538. else:
  2539. gui_menu.config("FIXTURES","bg","")
  2540. gui_menu.config("FIXTURES","activebackground","")
  2541. gui_menu.update("FIXTURES","{} : {}".format(c_f,c_a2))
  2542. if c_d > 0:
  2543. gui_menu.config("DIMMER","bg","yellow")
  2544. gui_menu.config("DIMMER","activebackground","yellow")
  2545. else:
  2546. gui_menu.config("DIMMER","bg","")
  2547. gui_menu.config("DIMMER","activebackground","")
  2548. gui_menu.update("DIMMER","{}".format(c_d))
  2549. def preset_rec(self,nr):
  2550. print("------- STORE PRESET")
  2551. data = FIXTURES.get_active()
  2552. if modes.val("REC-FX"):
  2553. PRESETS.rec(nr,data,"REC-FX")
  2554. modes.val("REC-FX",0)
  2555. else:
  2556. PRESETS.rec(nr,data)
  2557. sdata=data
  2558. PRESETS.val_presets[nr] = sdata
  2559. master._refresh_exec()
  2560. return 1
  2561. def preset_select(self,nr):
  2562. print("SELECT PRESET")
  2563. sdata = PRESETS.val_presets[nr]
  2564. cmd = ""
  2565. for fix in sdata:
  2566. if fix == "CFG":
  2567. continue
  2568. for attr in sdata[fix]:
  2569. v2 = sdata[fix][attr]["VALUE"]
  2570. v2_fx = sdata[fix][attr]["FX"]
  2571. #print( self.data.elem_attr)
  2572. if fix in self.elem_attr:
  2573. if attr in self.elem_attr[fix]:
  2574. elem = self.elem_attr[fix][attr]
  2575. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  2576. elem["bg"] = "yellow"
  2577. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  2578. t_start = time.time()
  2579. if xfade is None and FADE._is():
  2580. xfade = FADE.val()
  2581. if ptfade is None and FADE_move._is():
  2582. ptfade = FADE_move.val()
  2583. print("GO PRESET FADE",nr,val)
  2584. rdata = PRESETS.get_raw_map(nr)
  2585. if not rdata:
  2586. return 0
  2587. print("???????")
  2588. cfg = PRESETS.get_cfg(nr)
  2589. print("''''''''")
  2590. #virtcmd = FIXTURES.get_virtual(rdata)
  2591. if not cfg:
  2592. cprint("NO CFG",cfg,nr)
  2593. return 0
  2594. xFLASH = 0
  2595. value=None
  2596. cprint("preset_go",nr,cfg)
  2597. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  2598. self.preset_select(nr)
  2599. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  2600. xFLASH = 1
  2601. xfade = 0
  2602. if type(val) is not type(None) and val == 0 :
  2603. value = "off"
  2604. if event:
  2605. if str(event.type) == "ButtonRelease" or event.type == '5' :
  2606. value = "off"
  2607. cprint("preset_go() FLUSH",value,color="red")
  2608. fcmd = FIXTURES.update_raw(rdata,update=0)
  2609. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  2610. elif not val:
  2611. cprint("preset_go() STOP",value,color="red")
  2612. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  2613. fcmd = FIXTURES.update_raw(rdata)
  2614. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  2615. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  2616. fcmd = FIXTURES.update_raw(rdata)
  2617. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  2618. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  2619. self.refresh_exec()
  2620. self.refresh_fix()
  2621. cprint("preset_go",time.time()-t_start)
  2622. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  2623. if xfade is None and FADE._is():
  2624. xfade = FADE.val()
  2625. if ptfade is None and FADE_move._is():
  2626. ptfade = FADE_move.val()
  2627. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  2628. if xfade is None:
  2629. xfade = cfg["FADE"]
  2630. if ptfade is None:
  2631. ptfade = cfg["FADE"]
  2632. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  2633. #cprint(rdata,color="red")
  2634. vcmd = reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  2635. cmd = []
  2636. delay=0
  2637. for i,v in enumerate(fcmd):
  2638. #print("go",i,v)
  2639. if xFLASH:
  2640. vcmd[i]["FLASH"] = 1
  2641. DMX = fcmd[i]["DMX"]
  2642. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  2643. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  2644. if value is not None:
  2645. vcmd[i]["VALUE"] = value
  2646. if value == "off":
  2647. if "FX2" in vcmd:
  2648. vcmd[i]["FX2"]["TYPE"] = value
  2649. if "FIX" in fcmd:
  2650. vcmd[i]["FIX"] = fcmd["FIX"]
  2651. if DMX and vcmd[i]:
  2652. vcmd[i]["DMX"] = DMX
  2653. if "VIRTUAL" in fcmd[i]:
  2654. for a in fcmd[i]["VIRTUAL"]:
  2655. DMX = fcmd[i]["VIRTUAL"][a]
  2656. if DMX and vcmd[i]:
  2657. vcmd[i]["DMX"] = DMX
  2658. if type(nr) is not type(None):
  2659. vcmd[i]["EXEC"] = str(int(nr)+1)
  2660. #cprint(vcmd[i],color="red")
  2661. cmd.append(vcmd[i])
  2662. if cmd and not modes.val("BLIND"):
  2663. jclient_send(cmd)
  2664. def render(self):
  2665. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  2666. #self.draw_input()
  2667. pass
  2668. def draw_sub_dim(gui,fix,data,c=0,r=0,frame=None):
  2669. i=0
  2670. if frame is None:
  2671. frame = tk.Frame(root,bg="black")
  2672. frame.pack(fill=tk.X, side=tk.TOP)
  2673. if fix not in gui.elem_attr:
  2674. gui.elem_attr[fix] = {}
  2675. for attr in data["ATTRIBUT"]:
  2676. if attr not in gui.all_attr:
  2677. gui.all_attr.append(attr)
  2678. if attr not in gui.elem_attr[fix]:
  2679. gui.elem_attr[fix][attr] = []
  2680. if attr.endswith("-FINE"):
  2681. continue
  2682. v= data["ATTRIBUT"][attr]["VALUE"]
  2683. b = tk.Button(frame,bg="lightblue", text=""+str(fix),width=3,anchor="w")
  2684. b.config(padx=1)
  2685. b.bind("<Button>",Xevent(fix=fix,mode="D-SELECT",elem=b).cb)
  2686. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2687. c+=1
  2688. b = tk.Button(frame,bg="lightblue", text=data["NAME"],width=10,anchor="w")
  2689. b.config(padx=1)
  2690. b.bind("<Button>",Xevent(fix=fix,mode="D-SELECT",elem=b).cb)
  2691. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2692. c+=1
  2693. b = tk.Button(frame,bg="grey", text=str(round(v,2)),width=10,anchor="w")
  2694. b.config(padx=1)
  2695. gui.elem_attr[fix][attr] = b
  2696. b.bind("<Button>",Xevent(fix=fix,elem=b,attr=attr,mode="ENCODER",data=data).cb)
  2697. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2698. c+=1
  2699. if c >=12:
  2700. c=0
  2701. r+=1
  2702. return c,r
  2703. class _SET_PATCH():
  2704. def __init__(self,k,v,fix,data,_cb=None):
  2705. self._cb = _cb
  2706. self.v = v
  2707. self.button = None
  2708. self.k = k
  2709. self.fix = fix
  2710. self.data = data
  2711. def attr(self,_event=None):
  2712. k = self.k
  2713. data = self.data
  2714. fix = self.fix
  2715. txt = "k={} v={}".format(self.k,self.v)
  2716. print(txt)
  2717. print( "fix", self.fix )
  2718. print( "row data",self.data)
  2719. val = ""
  2720. if k in self.data:
  2721. val = self.data[k]
  2722. #txt = dialog.askstring("SET","SET: {}={}".format(self.k,self.v),initialvalue=val)
  2723. def _cb(data):
  2724. txt = data["Value"]
  2725. print("_SET.attr",txt)
  2726. v = txt
  2727. if v is not None:
  2728. err = 1
  2729. if k in self.data:
  2730. if k == "NAME":
  2731. self.data[k] = v
  2732. err = 0
  2733. if k == "DMX":
  2734. v = int(v)
  2735. if v <= 512 and v >= 0:
  2736. self.data[k] = v
  2737. err = 0
  2738. if k == "UNIVERS":
  2739. v = int(v)
  2740. if v > 15:
  2741. v=15
  2742. if v < 0:
  2743. v=0
  2744. self.data[k] = v
  2745. err = 0
  2746. if self.button:
  2747. if err:
  2748. self.button["bg"] = "red"
  2749. else:
  2750. self.button["bg"] = "#fff"
  2751. self.button["text"] = "{}".format(v)
  2752. if self._cb:
  2753. self._cb()
  2754. print( "row data",self.data)
  2755. dialog._cb = _cb
  2756. dialog.askstring("SET","SET: {}={}".format(self.k,self.v),initialvalue=val)
  2757. def set_button(self,button):
  2758. self.button = button
  2759. class GUI_PATCH():
  2760. def __init__(self,gui,yframe):
  2761. self.gui = gui
  2762. self.yframe = yframe
  2763. def draw(self): #,gui,yframe):
  2764. gui = self.gui
  2765. yframe = self.yframe
  2766. #print(dir(yframe))
  2767. #yframe.clear()
  2768. for widget in yframe.winfo_children():
  2769. widget.destroy()
  2770. xframe = tk.Frame(yframe,bg="black")
  2771. xframe.pack()
  2772. def yview(event):
  2773. print("yevent",event)
  2774. yyy=20.1
  2775. xframe.yview_moveto(yyy)
  2776. i=0
  2777. c=0
  2778. r=0
  2779. def head(i,c,r):
  2780. b = tk.Button(xframe,bg="grey", text="Z:{} ID".format(z+1),width=6,anchor="e")
  2781. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  2782. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2783. c+=1
  2784. b = tk.Button(xframe,bg="grey", text="NAME",width=14,anchor="w")
  2785. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  2786. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2787. c+=1
  2788. rgb = "#aaa"
  2789. b = tk.Button(xframe,bg=rgb, text="TYPE",width=3)
  2790. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2791. c+=1
  2792. b = tk.Button(xframe,bg=rgb, text="Uni",width=1)
  2793. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2794. c+=1
  2795. b = tk.Button(xframe,bg=rgb, text="DMX",width=1)
  2796. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2797. c+=1
  2798. b = tk.Button(xframe,bg=rgb, text="CH's",width=1)
  2799. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2800. c+=1
  2801. b = tk.Button(xframe,bg=rgb, text="from - to",width=1)
  2802. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2803. c+=1
  2804. b = tk.Button(xframe,bg=rgb, text="DMX-SUM",width=1)
  2805. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2806. c+=1
  2807. b = tk.Button(xframe,bg=rgb, text="TEST",width=1)
  2808. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2809. c+=1
  2810. b = tk.Button(xframe,bg=rgb, text="DMX Collision!",width=12)
  2811. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2812. c+=1
  2813. c=0
  2814. r+=1
  2815. return i,c,r
  2816. #i,c,r = head(i,c,r)
  2817. dmx_ch_sum = 0
  2818. dmx_collision = {}
  2819. for fix in FIXTURES.fixtures:
  2820. data = FIXTURES.fixtures[fix]
  2821. max_dmx = FIXTURES.get_max_dmx_nr(fix)
  2822. for i in range(data["DMX"],data["DMX"]+max_dmx[1]):
  2823. k = "{}.{}".format(data["UNIVERS"],i)
  2824. if k in dmx_collision:
  2825. dmx_collision[k] += 1
  2826. else:
  2827. dmx_collision[k] = 0
  2828. z=0
  2829. for fix in FIXTURES.fixtures:
  2830. if z % 20 == 0:
  2831. i,c,r = head(i,c,r)
  2832. z+=1
  2833. collision = []
  2834. i+=1
  2835. data = FIXTURES.fixtures[fix]
  2836. b = tk.Button(xframe,bg="lightblue", text=""+str(fix),width=6,anchor="e")
  2837. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  2838. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2839. c+=1
  2840. command = _SET_PATCH("NAME",data["NAME"],fix,data)
  2841. b = tk.Button(xframe,bg="lightblue", text=data["NAME"],width=14,anchor="w",command=command.attr)
  2842. command.set_button(b)
  2843. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  2844. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2845. c+=1
  2846. if len(data["ATTRIBUT"]) == 1:
  2847. b = tk.Button(xframe,bg="#ddd", text="DIMMER",width=8,anchor="w")
  2848. elif "PAN" in data["ATTRIBUT"] or "TILT" in data["ATTRIBUT"] :
  2849. b = tk.Button(xframe,bg="#ddd", text="MOVER",width=8,anchor="w")
  2850. else:
  2851. b = tk.Button(xframe,bg="#ddd", text="",width=8,anchor="w")
  2852. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  2853. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2854. c+=1
  2855. b = tk.Button(xframe,bg="#ddd", text="EDIT",width=3)
  2856. b.bind("<Button>",Xevent(fix=fix,mode="SELECT",elem=b).cb)
  2857. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2858. c+=1
  2859. b = tk.Button(xframe,bg="#ddd", text="[ ][x]",width=1)
  2860. b.bind("<Button>",Xevent(fix=fix,mode="SELECT",elem=b).cb)
  2861. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2862. c+=1
  2863. #r+=1
  2864. start_c=3
  2865. c=start_c
  2866. if fix not in gui.elem_attr:
  2867. gui.elem_attr[fix] = {}
  2868. patch = ["UNIVERS","DMX"]
  2869. for k in patch:
  2870. v=data[k]
  2871. #b = tk.Button(xframe,bg="grey", text=str(k)+' '+str(v),width=8)
  2872. command = _SET_PATCH(k,v,fix,data) #,_cb=highlight2(fix) ) #,_cb=self.draw)
  2873. b = tk.Button(xframe,bg="grey", text=str(v),width=2,command=command.attr)
  2874. command.set_button(b)
  2875. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2876. c+=1
  2877. if c >=8:
  2878. c=start_c
  2879. r+=1
  2880. max_dmx = FIXTURES.get_max_dmx_nr(fix)
  2881. dmx_ch_sum += max_dmx[1]
  2882. for i in range(data["DMX"],data["DMX"]+max_dmx[1]):
  2883. k = "{}.{}".format(data["UNIVERS"],i)
  2884. if k in dmx_collision:
  2885. if dmx_collision[k]:
  2886. collision.append(k)
  2887. b = tk.Button(xframe,bg="grey", text="{:3} ({})".format(max_dmx[1] , max_dmx[0]),width=4) #a,anchor="w")
  2888. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2889. c+=1
  2890. #b = tk.Button(xframe,bg="#aaa", text="{:03}-{:03}".format(data["DMX"],len(data["ATTRIBUT"])+(data["DMX"])-1),width=6,anchor="w")
  2891. b = tk.Button(xframe,bg="#aaa", text="{:03} - {:03}".format(data["DMX"],max_dmx[1]+(data["DMX"]-1)),width=8,anchor="w")
  2892. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2893. c+=1
  2894. b = tk.Button(xframe,bg="#aaa",fg="#225", text="{} : {:03}".format(z,dmx_ch_sum),width=6,anchor="w")
  2895. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2896. c+=1
  2897. def x(fix):
  2898. def xx():
  2899. print("TEST",fix)
  2900. if fix in FIXTURES.fixtures:
  2901. data = FIXTURES.fixtures[fix]
  2902. # print(data)
  2903. highlight(fix)
  2904. return xx
  2905. #print(fix)
  2906. b = tk.Button(xframe,bg="#aaa",fg="#225", text="TEST",width=4,anchor="w",command=x(fix))
  2907. myTip = Hovertip(b,'BLINK DIMMER')
  2908. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2909. #b.command = x
  2910. #exit()
  2911. c+=1
  2912. bg = "#252"
  2913. if collision:
  2914. bg = "#f22"
  2915. else:
  2916. collision = ""
  2917. b = tk.Button(xframe,bg=bg, text="{}".format(",".join(collision)),width=14,anchor="w")
  2918. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2919. c=0
  2920. r+=1
  2921. class GUI_FIX():
  2922. def __init__(self,gui,xframe,yframe=None):
  2923. self.gui = gui
  2924. self.xframe = xframe
  2925. self.yframe = yframe
  2926. def draw(self):
  2927. gui=self.gui
  2928. xframe=self.xframe
  2929. yframe=self.yframe
  2930. r=0
  2931. c=0
  2932. frame_dim=xframe
  2933. if yframe:
  2934. frame_dim=yframe
  2935. for widget in yframe.winfo_children():
  2936. widget.destroy()
  2937. frame_fix=xframe
  2938. for widget in xframe.winfo_children():
  2939. widget.destroy()
  2940. root = frame_dim
  2941. dim_frame = tk.Frame(root,bg="black")
  2942. dim_frame.pack(fill=tk.X, side=tk.TOP)
  2943. root = frame_fix
  2944. fix_frame = tk.Frame(root,bg="black")
  2945. fix_frame.pack(fill=tk.X, side=tk.TOP)
  2946. i=0
  2947. c=0
  2948. r=0
  2949. dim_end=0
  2950. for fix in FIXTURES.fixtures:
  2951. i+=1
  2952. data = FIXTURES.fixtures[fix]
  2953. #print("draw_fix", fix ,data )
  2954. if(len(data["ATTRIBUT"].keys()) <= 1):
  2955. c,r=draw_sub_dim(gui,fix,data,c=c,r=r,frame=dim_frame)
  2956. else:
  2957. if not dim_end:
  2958. dim_end=1
  2959. c=0
  2960. r=0
  2961. #gui._draw_fix(fix,data,root=fix_frame)
  2962. frame = fix_frame
  2963. b = tk.Button(frame,bg="lightblue", text="ID:"+str(fix),width=6,anchor="w")
  2964. b.bind("<Button>",Xevent(fix=fix,mode="SELECT",elem=b).cb)
  2965. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2966. c+=1
  2967. b = tk.Button(frame,bg="#55f", text=data["NAME"],width=10,anchor="w")
  2968. b.bind("<Button>",Xevent(fix=fix,attr="ALL",mode="ENCODER",elem=b).cb)
  2969. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2970. c+=1
  2971. #r+=1
  2972. start_c=3
  2973. c=start_c
  2974. if fix not in gui.elem_attr:
  2975. gui.elem_attr[fix] = {}
  2976. for attr in data["ATTRIBUT"]:
  2977. if attr.endswith("-FINE"):
  2978. continue
  2979. if attr not in gui.all_attr:
  2980. gui.all_attr.append(attr)
  2981. if attr not in gui.elem_attr[fix]:
  2982. gui.elem_attr[fix][attr] = ["line1348",fix,attr]
  2983. v= data["ATTRIBUT"][attr]["VALUE"]
  2984. b = tk.Button(frame,bg="grey", text=str(attr)+' '+str(round(v,2)),width=12, anchor="w")
  2985. gui.elem_attr[fix][attr] = b
  2986. b.bind("<Button>",Xevent(fix=fix,elem=b,attr=attr,mode="ENCODER",data=data).cb)
  2987. b.grid(row=r, column=c, sticky=tk.W+tk.E,ipadx=0,ipady=0,padx=0,pady=0)
  2988. c+=1
  2989. if c >=8:
  2990. c=start_c
  2991. r+=1
  2992. c=0
  2993. r+=1
  2994. #master._refresh_exec()
  2995. #master.refresh_exec()
  2996. def draw_enc(gui,xframe):
  2997. for widget in xframe.winfo_children():
  2998. widget.destroy()
  2999. root2 = xframe
  3000. i=0
  3001. c=0
  3002. r=0
  3003. frame = tk.Frame(xframe,bg="black")
  3004. frame.pack( side=tk.LEFT,expand=0,fill="both")
  3005. b = tk.Button(frame,bg="lightblue", text="ENCODER",width=6)
  3006. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3007. c+=1
  3008. #for attr in ["xx"]*23: # gui.all_attr:
  3009. eat = gui.all_attr
  3010. if len(eat) < 23:
  3011. for i in range(23-len(eat)):
  3012. eat.append("")
  3013. for attr in eat:
  3014. if attr.endswith("-FINE"):
  3015. continue
  3016. v=0
  3017. b = tk.Button(frame,bg="#6e6e6e", text=str(attr)+'',width=7)#, anchor="w")
  3018. if attr == "DIM":
  3019. b = tk.Button(frame,bg="#ff7f00", text=str(attr)+'',width=7)#, anchor="w")
  3020. b.bind("<Button>",Xevent(fix=0,elem=b,attr=attr,data=gui,mode="ENCODER2").cb)
  3021. b.grid(row=r, column=c, sticky=tk.W+tk.E ,ipadx=0,ipady=0,padx=0,pady=0)#,expand=True)
  3022. c+=1
  3023. if c >=8:
  3024. c=0
  3025. r+=1
  3026. def _draw_fx(frame,c,r,gui,mode="FX"):
  3027. ct = gui.fx
  3028. prm = fx_prm
  3029. if mode=="FX-MOVE":
  3030. ct = gui.fx_moves
  3031. prm = fx_prm_move
  3032. elif mode=="FX-GENERIC":
  3033. ct = gui.fx_generic
  3034. prm = fx_prm #_generic
  3035. for comm in ct.commands:
  3036. if comm == "\n\n":
  3037. b = tk.Label(frame,bg="black", text="-",font=space_font)
  3038. b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
  3039. c=0
  3040. r+=1
  3041. continue
  3042. if comm == "\n":
  3043. c=0
  3044. r+=1
  3045. continue
  3046. v=0
  3047. if "PAN/TILT" in comm:
  3048. b = tk.Button(frame,bg="grey", text=str(comm),width=6,height=2)
  3049. else:
  3050. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  3051. if comm not in ct.elem:
  3052. #comm = comm.replace("\n","")
  3053. ct.elem[comm] = b
  3054. ct.val[comm] = 0
  3055. b.bind("<Button>",Xevent_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
  3056. if comm == "REC-FX":
  3057. b["bg"] = "grey"
  3058. elif comm == "FX OFF":
  3059. b["bg"] = "magenta"
  3060. elif comm[:3] == "FX:":
  3061. b["text"] = comm
  3062. b["bg"] = "#ffbf00"
  3063. elif comm[:3] == "MO:":
  3064. b["text"] = comm
  3065. b["bg"] = "lightgreen"
  3066. elif comm.startswith( "SIZE:"):
  3067. b["text"] = "SIZE:\n{:0.0f}".format(prm["SIZE"])
  3068. b["bg"] = "lightgreen"
  3069. elif comm.startswith( "SPEED:"):
  3070. b["text"] = "SPEED:\n{:0.0f}".format(prm["SPEED"])
  3071. b["bg"] = "lightgreen"
  3072. elif comm.startswith("START:"):
  3073. b["bg"] = "lightgreen"
  3074. b["text"] = "START:\n{:0.0f}".format(prm["START"])
  3075. elif comm.startswith( "OFFSET:"):
  3076. b["bg"] = "lightgreen"
  3077. b["text"] = "OFFSET:\n{:0.0f}".format(prm["OFFSET"])
  3078. elif comm[:3] == "BASE:":
  3079. b["bg"] = "lightgreen"
  3080. b["text"] = "BASE:\n{}".format(prm["BASE"])
  3081. elif comm[0] == "M":
  3082. b["text"] = comm
  3083. b["bg"] = "lightgrey"
  3084. if comm:
  3085. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3086. c+=1
  3087. if c >=6:
  3088. c=0
  3089. r+=1
  3090. return c,r
  3091. def draw_fx(gui,xframe):
  3092. frame_fx=xframe
  3093. i=0
  3094. c=0
  3095. r=0
  3096. frame = tk.Frame(frame_fx,bg="black")
  3097. frame.pack(fill=tk.X, side=tk.TOP)
  3098. b = tk.Button(frame,bg="lightblue", text="FX.",width=6)
  3099. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3100. c+=1
  3101. c,r = _draw_fx(frame,c,r,gui,mode="FX-MOVE")
  3102. r+=1
  3103. b = tk.Canvas(frame,bg="black", height=4,bd=0,width=6,highlightthickness=0) #,bd="black")
  3104. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3105. r+=1
  3106. c=0
  3107. c,r = _draw_fx(frame,c,r,gui,mode="FX")
  3108. b = tk.Canvas(frame,bg="black", height=4,bd=0,width=6,highlightthickness=0) #,bd="black")
  3109. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3110. r+=1
  3111. c=0
  3112. c,r = _draw_fx(frame,c,r,gui,mode="FX-GENERIC")
  3113. def draw_setup(gui,xframe):
  3114. frame_cmd=xframe
  3115. i=0
  3116. c=0
  3117. r=0
  3118. frame = tk.Frame(frame_cmd,bg="black")
  3119. frame.pack(fill=tk.X, side=tk.TOP)
  3120. #b = tk.Button(frame,bg="lightblue", text="SETUP",width=6)
  3121. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  3122. #b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3123. #r+=1
  3124. c+=1
  3125. for comm in ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI"]:
  3126. if comm == "\n":
  3127. c=0
  3128. r+=1
  3129. continue
  3130. v=0
  3131. if comm == "SAVE\nSHOW":
  3132. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=5,height=2)
  3133. elif comm == "LOAD\nSHOW":
  3134. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=5,height=2)
  3135. elif comm == "SAVE\nSHOW AS":
  3136. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  3137. elif comm == "SAVE &\nRESTART":
  3138. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  3139. elif comm == "DRAW\nGUI":
  3140. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  3141. else:
  3142. b = tk.Button(frame,bg="grey", text=str(comm),width=5,height=2)
  3143. if comm not in gui.commands.elem:
  3144. gui.commands.elem[comm] = b
  3145. gui.commands.val[comm] = 0
  3146. b.bind("<Button>",Xevent(fix=0,elem=b,attr=comm,data=gui,mode="SETUP").cb)
  3147. if comm == "BASE:":
  3148. b["text"] = "BASE:{}".format(prm["BASE"])
  3149. if comm:
  3150. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3151. c+=1
  3152. if c >=7:
  3153. c=0
  3154. r+=1
  3155. def _loop_clock(b):
  3156. xfont = tk.font.Font(family="FreeSans", size=65, weight="bold")
  3157. xfont1 = tk.font.Font(family="FreeSans", size=25, weight="bold")
  3158. while 1:
  3159. #b["text"] =
  3160. d = time.strftime("%Y-%m-%d")
  3161. s = time.strftime("%X")
  3162. b.delete("all")
  3163. b.create_text(170,41,text=s,fill="#aa0" ,font=xfont)
  3164. b.create_text(160,91,text=d,fill="#aa0" ,font=xfont1)
  3165. time.sleep(1)
  3166. #exit()
  3167. def draw_clock(gui,xframe):
  3168. frame_cmd=xframe
  3169. frame = tk.Frame(frame_cmd,bg="black")
  3170. frame.pack(fill=tk.X, side=tk.TOP)
  3171. comm = "xx"
  3172. xfont = tk.font.Font(family="FreeSans", size=25, weight="bold")
  3173. b = tk.Canvas(frame,bg="black", height=105,bd=0,width=6,highlightthickness=0) #,bd="black")
  3174. #b = tk.Button(frame,bg="lightgrey", text=str(comm),width=26,height=2,font=xfont)
  3175. #b.config(activebackground="lightgreen")
  3176. #b.config(background="lightgreen")
  3177. b.pack(fill="both",expand=1) #row=0, column=0, sticky=tk.W+tk.E)
  3178. #b["text"] = time.strftime("%Y-%m-%d %X")
  3179. thread.start_new_thread(_loop_clock,(b,))
  3180. def draw_live(gui,xframe):
  3181. frame_cmd=xframe
  3182. i=0
  3183. c=0
  3184. r=0
  3185. frame = tk.Frame(frame_cmd,bg="black")
  3186. frame.pack(fill=tk.X, side=tk.TOP)
  3187. c+=1
  3188. for comm in ["FADE","DELAY","PAN/TILT\nFADE","PAN/TILT\nDELAY"]:
  3189. if comm == "\n":
  3190. c=0
  3191. r+=1
  3192. continue
  3193. v=0
  3194. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  3195. if comm not in gui.commands.elem:
  3196. gui.commands.elem[comm] = b
  3197. gui.commands.val[comm] = 0
  3198. b.bind("<Button>",Xevent(fix=0,elem=b,attr=comm,data=gui,mode="LIVE").cb)
  3199. if "FADE" == comm:
  3200. b["text"] = "FADE:\n{:0.2}".format(FADE.val())
  3201. if "DELAY" == comm:
  3202. b["text"] = "DELAY:\n{:0.2}".format(DELAY.val())
  3203. if "PAN/TILT\nFADE" == comm:
  3204. b["text"] = "PAN/TILT\nFADE:{:0.2}".format(FADE_move.val())
  3205. if "FADE" in comm:
  3206. b["bg"] = "green"
  3207. b.config(activebackground="lightgreen")
  3208. if comm:
  3209. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3210. c+=1
  3211. if c >=5:
  3212. c=0
  3213. r+=1
  3214. class LOAD_FIXTURE():
  3215. def __init__(self,name="",master=None):
  3216. self.name=name
  3217. self.master=master
  3218. def cb(self,event=None):
  3219. print("LOAD_FIXTURE",self.name,event)
  3220. if self.master is not None:
  3221. #for i in dir(self.master): #.load_MH2()
  3222. # print(i)
  3223. if "SPARX" in self.name:
  3224. self.master.load_MH2()
  3225. else:
  3226. self.master.load_DIM()
  3227. print(dir(self.master))
  3228. class LOAD_SHOW_AND_RESTAT():
  3229. def __init__(self,fname=""):
  3230. self.fname=fname
  3231. self.base = Base()
  3232. def cb(self,event=None,force=0):
  3233. print("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  3234. if not self.fname and not force:
  3235. return 0
  3236. if self.base.show_name == self.fname and not force:
  3237. cprint("filename is the same",self.fname)
  3238. return 0
  3239. if not force:
  3240. self.base._set(self.fname)
  3241. print("LOAD SHOW:",event,self.fname)
  3242. print(sys.executable, os.path.abspath(__file__), *sys.argv)
  3243. os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
  3244. sys.exit()
  3245. class PopupList():
  3246. def __init__(self,name="<NAME>",master=0,width=400,height=450,exit=1,left=_POS_LEFT+400,top=_POS_TOP+100,cb=None,bg="black"):
  3247. self.name = name
  3248. self.frame = None
  3249. self.bg=bg
  3250. self.cb = cb
  3251. if cb is None:
  3252. cb = DummyCallback #("load_show_list.cb")
  3253. w = GUIWindow(self.name,master=master,width=width,height=height,exit=exit,left=left,top=top,cb=cb)
  3254. self.w = w
  3255. w.show()
  3256. def sframe(self,line1="<line1>",line2="<line2>",data=[]):
  3257. xframe=self.w.tk
  3258. if self.bg:
  3259. xframe.configure(bg=self.bg)
  3260. self.w.tk.configure(bg=self.bg)
  3261. c=0
  3262. r=0
  3263. b = tk.Label(xframe,bg="grey",text=line1,anchor="w")
  3264. b.pack(side="top",expand=0,fill="x" )
  3265. b = tk.Label(xframe,bg="grey",text=line2,anchor="w")
  3266. b.pack(side="top",expand=0,fill="x" )
  3267. b = tk.Label(xframe,bg="black",fg="black",text="")
  3268. if self.bg:
  3269. b.configure(fg=self.bg)
  3270. b.configure(bg=self.bg)
  3271. b.pack(side="top")
  3272. b = tk.Entry(xframe,width=10,text="")#,anchor="w")
  3273. b.pack(side="top",expand=0,fill="x")
  3274. b.focus()
  3275. #frame = tk.Frame(xframe,heigh=2800)
  3276. #frame.pack(fill=tk.BOTH,expand=1, side=tk.TOP)
  3277. frame = ScrollFrame(xframe,width=300,height=500,bd=1,bg=self.bg)
  3278. #frame.pack(side="left") #fill=tk.BOTH,expand=1, side=tk.TOP)
  3279. #self.frame = frame
  3280. self.w.tk.state(newstate='normal')
  3281. self.w.tk.attributes('-topmost',True)
  3282. return frame
  3283. class DummyCallback():
  3284. def __init__(self,name="name"):
  3285. self.name = name
  3286. def cb(self,event=None):
  3287. print("DummyCallback.cb",[self.name,event])
  3288. def _load_show_list(frame,cb=None):
  3289. c=0
  3290. r=0
  3291. base = Base()
  3292. for i in ["name","stamp"]: #,"create"]:
  3293. b = tk.Label(frame,bg="grey",text=i)
  3294. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3295. c+=1
  3296. r+=1
  3297. blist = base._list()
  3298. for i in range(10):
  3299. blist.append(["",""])
  3300. if cb is None:
  3301. cb = DummyCallback #("load_show_list.cb")
  3302. for i in blist:
  3303. #print(i)
  3304. c=0
  3305. for j in i:
  3306. bg="lightgrey"
  3307. dbg="lightgrey"
  3308. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  3309. dbg = "lightgreen"
  3310. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  3311. dbg = "green"
  3312. if c > 0:
  3313. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  3314. b.config(activebackground=dbg)
  3315. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3316. else:
  3317. if base.show_name == i[0]:
  3318. bg="green"
  3319. _cb = cb(j)
  3320. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  3321. if base.show_name == i[0]:
  3322. b.config(activebackground=bg)
  3323. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3324. c+=1
  3325. r+=1
  3326. def _load_fixture_list(frame,cb=None,master=None,bg="black"):
  3327. frame.configure(bg=bg)
  3328. c=0
  3329. r=0
  3330. base = Base()
  3331. for i in ["name","stamp"]: #,"create"]:
  3332. b = tk.Label(frame,bg="grey",text=i)
  3333. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3334. c+=1
  3335. r+=1
  3336. blist = [] #base._list()
  3337. blist.append(["MAC-500","martin","z"])
  3338. blist.append(["MAC-2000","martin","z"])
  3339. blist.append(["MAC-VIPER","martin","z"])
  3340. blist.append(["SPARX-7","JB","z"])
  3341. blist.append(["SPARX-11","JB","z"])
  3342. blist.append(["JB-P6","JB","z"])
  3343. blist.append(["JB-P7","JB","z"])
  3344. blist.append(["JB-A7","JB","z"])
  3345. blist.append(["TMH-12","Eurolight","z"])
  3346. for i in range(10):
  3347. blist.append(["",""])
  3348. if cb is None:
  3349. cb = DummyCallback #("load_show_list.cb")
  3350. for i in blist:
  3351. #print(i)
  3352. c=0
  3353. for j in i:
  3354. bg="lightgrey"
  3355. dbg="lightgrey"
  3356. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  3357. dbg = "lightgreen"
  3358. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  3359. dbg = "green"
  3360. if c > 0:
  3361. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  3362. b.config(activebackground=dbg)
  3363. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3364. else:
  3365. if base.show_name == i[0]:
  3366. bg="green"
  3367. _cb=cb(j)
  3368. _cb.master=master
  3369. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  3370. if base.show_name == i[0]:
  3371. b.config(activebackground=bg)
  3372. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3373. c+=1
  3374. r+=1
  3375. def draw_command(gui,xframe):
  3376. frame_cmd=xframe
  3377. i=0
  3378. c=0
  3379. r=0
  3380. frame = tk.Frame(frame_cmd,bg="black")
  3381. frame.pack(fill=tk.X, side=tk.TOP)
  3382. # b = tk.Button(frame,bg="lightblue", text="COMM.",width=6)
  3383. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  3384. #b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3385. #r+=1
  3386. c+=1
  3387. for comm in gui.commands.commands:
  3388. if comm == "\n":
  3389. c=0
  3390. r+=1
  3391. continue
  3392. v=0
  3393. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  3394. if comm not in gui.commands.elem:
  3395. gui.commands.elem[comm] = b
  3396. gui.commands.val[comm] = 0
  3397. if comm == "BLIND":
  3398. b["bg"] = "grey"
  3399. myTip = Hovertip(b,'BLIND MODE\nNO CHANGE on DMX-OUTPUT')
  3400. if comm == "CLEAR":
  3401. b["bg"] = "grey"
  3402. myTip = Hovertip(b,'CLEAR ALL SELECTED\nFIXTURES ATTRIBUTES')
  3403. if comm == "REC-FX":
  3404. b["bg"] = "grey"
  3405. myTip = Hovertip(b,'RECORD ONLY FX\nINTO EXEC')
  3406. if comm == "FADE":
  3407. b["bg"] = "green"
  3408. myTip = Hovertip(b,'adjust fade time')
  3409. if comm == "S-KEY":
  3410. b["bg"] = "green"
  3411. myTip = Hovertip(b,'keyboard short-key\non or off')
  3412. if comm == "FX OFF":
  3413. b["bg"] = "magenta"
  3414. if comm == "SIZE:":
  3415. b["text"] = "SIZE:{:0.0f}".format(fx_prm["SIZE"])
  3416. if comm == "SPEED:":
  3417. b["text"] = "SPEED:{:0.0f}".format(fx_prm["SPEED"])
  3418. if comm == "DELAY":
  3419. b["text"] = "FADE:\n{:0.02f}".format(DELAY.val())
  3420. if comm == "FADE":
  3421. b["text"] = "FADE:\n{:0.02f}".format(FADE.val())
  3422. if comm == "START:":
  3423. b["text"] = "START:{:0.0f}".format(fx_prm["START"])
  3424. if comm == "OFFSET:":
  3425. b["text"] = "OFFSET:{:0.0f}".format(fx_prm["OFFSET"])
  3426. if comm == "FX-X:":
  3427. b["text"] = "FX-X:{}".format(fx_prm["FX-X"])
  3428. if comm == "BASE:":
  3429. b["text"] = "BASE:{}".format(fx_prm["BASE"])
  3430. b.bind("<Button>",Xevent(fix=0,elem=b,attr=comm,data=gui,mode="COMMAND").cb)
  3431. if comm:
  3432. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3433. c+=1
  3434. if c >=8:
  3435. c=0
  3436. r+=1
  3437. def draw_preset(gui,xframe):
  3438. i=0
  3439. c=0
  3440. r=0
  3441. root = xframe
  3442. frame = tk.Frame(root,bg="black")
  3443. frame.pack(fill=tk.X, side=tk.TOP)
  3444. i=0
  3445. for k in PRESETS.val_presets:
  3446. if i%(10*8)==0 or i ==0:
  3447. c=0
  3448. #b = tk.Label(frame,bg="black", text="" )
  3449. b = tk.Canvas(frame,bg="black", height=4,bd=0,width=6,highlightthickness=0) #,bd="black")
  3450. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3451. r+=1
  3452. c=0
  3453. b = tk.Button(frame,bg="lightblue", text="EXEC " )
  3454. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3455. c+=1
  3456. b = tk.Button(frame,bg="lightblue", text="BANK " + str(int(i/(8*8))+1) )
  3457. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3458. c+=1
  3459. b = tk.Button(frame,bg="lightblue", text="NAME" )
  3460. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3461. r+=1
  3462. c=0
  3463. i+=1
  3464. v=0
  3465. label = ""
  3466. #if k in PRESETS.label_presets:
  3467. # label = PRESETS.label_presets[k]
  3468. # #print([label])
  3469. sdata=PRESETS.val_presets[k]
  3470. BTN="go"
  3471. if "CFG" in sdata:#["BUTTON"] = "GO"
  3472. if "BUTTON" in sdata["CFG"]:
  3473. BTN = sdata["CFG"]["BUTTON"]
  3474. #bb = tk.Frame(frame, highlightbackground = "red", highlightthickness = 1, bd=0)
  3475. #bb = tk.Canvas(frame, highlightbackground = "black", highlightthickness = 1, bd=1)
  3476. #bb.configure(width=70, height=38)
  3477. txt=str(k+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+label
  3478. b = ExecButton(frame,text=txt)
  3479. #b = tk.Button(bb,bg="grey", text=txt,width=7,height=2)
  3480. b.bind("<Button>",Xevent(fix=0,elem=b,attr=k,data=gui,mode="PRESET").cb)
  3481. b.bind("<ButtonRelease>",Xevent(fix=0,elem=b,attr=k,data=gui,mode="PRESET").cb)
  3482. if k not in gui.elem_presets:
  3483. gui.elem_presets[k] = b
  3484. #b.pack(expand=1)
  3485. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3486. c+=1
  3487. if c >=10:
  3488. c=0
  3489. r+=1
  3490. time.sleep(0.1)
  3491. gui._refresh_exec()
  3492. gui.refresh_exec()
  3493. gui.refresh_exec()
  3494. def draw_input(gui):
  3495. i=0
  3496. c=0
  3497. r=0
  3498. frame = tk.Frame(root2,bg="black")
  3499. frame.pack(fill=tk.X, side=tk.TOP)
  3500. b = tk.Label(frame,bg="black", text="------------------------ ---------------------------------------")
  3501. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3502. r=0
  3503. frame = tk.Frame(root2,bg="black")
  3504. frame.pack(fill=tk.X, side=tk.TOP)
  3505. b = tk.Label(frame, text="send:")
  3506. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3507. c+=1
  3508. b = tk.Entry(frame,bg="grey", text="",width=50)
  3509. gui.entry = b
  3510. b.bind("<Button>",Xevent(fix=0,elem=b,attr="INPUT",data=gui,mode="INPUT").cb)
  3511. b.bind("<Key>",Xevent(fix=0,elem=b,attr="INPUT",data=gui,mode="INPUT").cb)
  3512. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3513. b.insert("end","d0:127,fx241:sinus:50:50:10,fx243:cosinus:50:50:10,d201:127,fx201:sinus:50:300:10")
  3514. r+=1
  3515. b = tk.Entry(frame,bg="grey", text="",width=20)
  3516. gui.entry2 = b
  3517. b.bind("<Button>",Xevent(fix=0,elem=b,attr="INPUT",data=gui,mode="INPUT2").cb)
  3518. b.bind("<Key>",Xevent(fix=0,elem=b,attr="INPUT",data=gui,mode="INPUT2").cb)
  3519. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3520. b.insert("end","d1:0:4")
  3521. r+=1
  3522. b = tk.Entry(frame,bg="grey", text="",width=20)
  3523. gui.entry3 = b
  3524. b.bind("<Button>",Xevent(fix=0,elem=b,attr="INPUT",data=gui,mode="INPUT3").cb)
  3525. #b.bind("<B1-Motion>",Xevent(fix=0,elem=b,attr="INPUT",data=gui,mode="INPUT3").cb)
  3526. b.bind("<Key>",Xevent(fix=0,elem=b,attr="INPUT",data=gui,mode="INPUT3").cb)
  3527. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3528. b.insert("end","fx:alloff:::")
  3529. def draw_colorpicker(gui,xframe):
  3530. import lib.colorpicker as colp
  3531. class _CB():
  3532. def __init__(gui):
  3533. gui.old_color = (0,0,0)
  3534. def cb(gui,event,data):
  3535. print("CB.cb",gui,event,data)
  3536. cprint("colorpicker CB")
  3537. if "color" not in data:
  3538. return 0
  3539. if gui.old_color == data["color"]:
  3540. pass #return 0
  3541. #gui.old_color = data["color"]
  3542. color = data["color"]
  3543. print("e",event,data)
  3544. print("e",dir(event))#.keys())
  3545. try:
  3546. print("e.state",event.state)
  3547. except:pass
  3548. set_fade = FADE.val() #fade
  3549. event_ok = 0
  3550. event_num = 0
  3551. event_state = 0
  3552. if event is None:
  3553. event_ok = 1
  3554. event_num = 3
  3555. elif event.num == 1:
  3556. event_ok = 1
  3557. event_num = event.num
  3558. elif event.num == 3:
  3559. event_ok = 1
  3560. event_num = event.num
  3561. elif event.num==2:
  3562. event_ok = 1
  3563. event_num = event.num
  3564. elif event.state in [256,1024]:
  3565. event_ok = 1
  3566. event_state = event.state
  3567. if "color" in data and event_ok:
  3568. cr=None
  3569. cg=None
  3570. cb=None
  3571. cw=0
  3572. ca=0
  3573. set_fade=0
  3574. if event_num == 1:
  3575. if FADE._is():
  3576. set_fade=FADE.val() #fade
  3577. cr = color[0]
  3578. cg = color[1]
  3579. cb = color[2]
  3580. elif event_num == 3:
  3581. cr = color[0]
  3582. cg = color[1]
  3583. cb = color[2]
  3584. elif event_num == 2:
  3585. cr= "click"
  3586. cg= "click"
  3587. cb= "click"
  3588. cw= "click"
  3589. ca= "click"
  3590. elif event_state == 256:
  3591. cr = color[0]
  3592. cg = color[1]
  3593. cb = color[2]
  3594. if cr is not None:
  3595. FIXTURES.encoder(fix=0,attr="RED",xval=cr,xfade=set_fade)
  3596. if cg is not None:
  3597. FIXTURES.encoder(fix=0,attr="GREEN",xval=cg,xfade=set_fade)
  3598. if cb is not None:
  3599. FIXTURES.encoder(fix=0,attr="BLUE",xval=cb,xfade=set_fade)
  3600. FIXTURES.encoder(fix=0,attr="WHITE",xval=cw,xfade=set_fade)
  3601. FIXTURES.encoder(fix=0,attr="AMBER",xval=ca,xfade=set_fade)
  3602. master.refresh_fix()
  3603. print("PICK COLOR:",data["color"])
  3604. _cb=_CB()
  3605. colp.colorpicker(xframe,width=580,height=113, xcb=_cb.cb)
  3606. return 0
  3607. canvas=tk.Canvas(xframe,width=600,height=113)
  3608. canvas["bg"] = "yellow" #"green"
  3609. canvas.pack()
  3610. # RGB
  3611. x=0
  3612. y=0
  3613. j=0
  3614. d = 20
  3615. for i in range(0,d+1):
  3616. fi = int(i*255/d)
  3617. f = 255-fi
  3618. if i > d/2:
  3619. pass#break
  3620. color = '#%02x%02x%02x' % (f, fi, fi)
  3621. print( "farbe", i*10, j, f,fi,fi,color)
  3622. r = canvas.create_rectangle(x, y, x+20, y+20, fill=color)
  3623. x+=20
  3624. class InputEventBlocker():
  3625. def __init__(self):
  3626. self.__init = 0
  3627. self.cursor = "88888"
  3628. def set(self,el,txt):
  3629. self.e = el
  3630. self.e_txt = txt
  3631. self.cursor = "88888"
  3632. def init(self):
  3633. if self.__init == 0:
  3634. try:
  3635. self.el = tk.Button()
  3636. self.e_txt = tk.StringVar()
  3637. self.__init = 1
  3638. except Exception as e:
  3639. pirnt("init() exception",e)
  3640. def _lock(self):
  3641. global _global_short_key
  3642. _global_short_key = 0
  3643. master.commands.elem["S-KEY"]["bg"] = "red"
  3644. def _unlock(self):
  3645. global _global_short_key
  3646. _global_short_key = 1
  3647. master.commands.elem["S-KEY"]["bg"] = "green"
  3648. def lock(self):
  3649. self._lock()
  3650. #self.e["bg"] = "red"
  3651. #self.el.config({"background": "grey"})
  3652. #self.e.focus()
  3653. def unlock(self):
  3654. self._unlock()
  3655. #self.e["bg"] = "blue"
  3656. #self.el.config({"background": "yellow"})
  3657. #self.el.focus_set()
  3658. def event(self,event,**args):
  3659. self.init()
  3660. #print()
  3661. print(self,event,args)
  3662. #print("###-",self.e_txt,dir(self.e_txt))
  3663. if "S-KEY" not in master.commands.elem:
  3664. return
  3665. if "num" in dir(event):
  3666. self.lock()
  3667. if "keysym" in dir(event):
  3668. t=self.e_txt.get()
  3669. if t and t[-1] == "<":
  3670. t = t[:-1]
  3671. if event.keysym == "Return" or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  3672. self.unlock()
  3673. #self.e_txt.set(t)
  3674. print("filter: get()",_global_short_key,t)
  3675. t2 = t
  3676. if _global_short_key == 0:
  3677. if event.keysym == "BackSpace":
  3678. if len(t) > 1:
  3679. t2 = t[:-1]
  3680. else:
  3681. t2=""
  3682. elif event.keysym == "Escape":
  3683. t2=""
  3684. elif event.keysym == "space":
  3685. t2=t+" "
  3686. elif event.char in "äöüÄÖÜ-_,.;:#'*+~":
  3687. t2=t+event.char
  3688. elif len(event.keysym) == 1:
  3689. t2=t+event.keysym
  3690. #self.e_txt.set(t2+"<")
  3691. #time.sleep(0.2)
  3692. #_global_short_key = 1
  3693. input_event_blocker = InputEventBlocker()
  3694. class TableFrame():
  3695. def __init__(self,root, width=50,height=100,bd=1):
  3696. self.root=root
  3697. self.a = _TableFrame(self.root)
  3698. f=self.a.HFrame()
  3699. f=self.a.Sframe(f, width=width,height=height,bd=bd)
  3700. self.a.draw([["A","11"],["B",4],["E",""],["R","R"],["Z","Z"],["U","U"]])
  3701. self.b = _TableFrame(self.root) #äself.root)
  3702. b=self.b.HFrame()
  3703. b=self.b.Sframe(b, width=width,height=height,bd=bd)
  3704. self.b.draw([["AA","1a1"],["BBB",114],["EE","22"],["RRR","RRR"],["TTZ","TTZ"],["ZZU","ZZU"]])
  3705. self.c = _TableFrame(self.root)
  3706. c=self.c.HFrame()
  3707. c=self.c.Sframe(c, width=width,height=height,bd=bd)
  3708. self.c.draw([["A","11"],["B",4],["E",""],["R","R"],["Z","Z"],["U","U"]][::-1])
  3709. self.bframe=None
  3710. def draw(self,data=[1,2],head=[],config=[]):
  3711. pass
  3712. class _TableFrame():
  3713. def __init__(self,main):
  3714. self.main = main
  3715. self.frame=tk.Frame(self.main,relief=tk.GROOVE,bg="yellow")#,width=width,height=height,bd=bd)
  3716. self.frame.pack(side="top",fill="x",expand=1) #x=0,y=0)
  3717. self.hframe=tk.Frame(self.frame,relief=tk.GROOVE,bg="yellow")#,width=width,height=height,bd=bd)
  3718. self.hframe.pack(side="top",fill="x",expand=0) #x=0,y=0)
  3719. self.aframe=tk.Frame(self.main,relief=tk.GROOVE)#,width=width,height=height,bd=bd)
  3720. #aframe.place(x=0,y=0)
  3721. self.aframe.pack(side="top",fill="both",expand=1) #x=0,y=0)
  3722. self.canvas=tk.Canvas(self.aframe,width=100-24,height=150)
  3723. self.canvas["bg"] = "blue" #black" #"green"
  3724. self.bframe=tk.Frame(self.canvas)#,width=width,height=height)
  3725. self.bframe["bg"] = "blue"
  3726. self.scrollbar=tk.Scrollbar(self.aframe,orient="vertical",command=self.canvas.yview,width=20)
  3727. self.canvas.configure(yscrollcommand=self.scrollbar.set)
  3728. self.scrollbar.pack(side="right",fill="y")
  3729. self.canvas.pack(side="left",expand=1,fill="both")
  3730. self.canvas.create_window((0,0),window=self.bframe,anchor='nw')
  3731. self.bframe.bind("<Configure>",scroll(self.canvas).config)
  3732. self.canvas.bind("<Button>",Event("XXX").event)
  3733. self.canvas.bind("<Key>",Event("XXX").event)
  3734. self.canvas.bind("<KeyRelease>",Event("XXX").event)
  3735. #self.bframe=tk.Frame(self.frame,relief=tk.GROOVE,bg="magenta")#,width=width,height=height,bd=bd)
  3736. #self.bframe.pack(side="top",fill="both",expand=1) #x=0,y=0)
  3737. #self.HFrame()
  3738. def event(self,event,**args):
  3739. input_event_blocker.set( self.e , self.e_txt)
  3740. input_event_blocker.event(event) #,args)
  3741. def HFrame(self,main=None):
  3742. self.el = tk.Label(self.hframe,text="Filter:")
  3743. self.el.pack(side="left")
  3744. self.e_txt = tk.StringVar()
  3745. #self.e = tk.Entry(self.hframe,state="readonly",textvariable=self.e_txt)
  3746. self.e = tk.Entry(self.hframe,textvariable=self.e_txt)
  3747. #self.e = tk.Button(self.hframe,textvariable=self.e_txt,relief="sunken",width=20)
  3748. self.e["bg"] = "#fff"
  3749. self.e.config(highlightthickness=2)
  3750. self.e.config(highlightcolor= "red")
  3751. #self.e_txt.set(self.e_txt.get()+"<")
  3752. self.e.bind("<Key>",self.event)
  3753. self.e.bind("<Button>",self.event)
  3754. self.e.pack(side="left")
  3755. def Sframe(self,main=None, **args):
  3756. pass
  3757. def draw(self,data=[1,2],head=[],config=[]):
  3758. yframe = self.bframe
  3759. if 1:
  3760. xframe = tk.Frame(yframe,bg="black")
  3761. xframe.pack(side="top", expand=1,fill="both")
  3762. def yview(event):
  3763. print("yevent",event)
  3764. yyy=20.1
  3765. xframe.yview_moveto(yyy)
  3766. i=0
  3767. c=0
  3768. r=0
  3769. b = tk.Button(xframe,bg="lightblue", text="ID",width=6,anchor="e")
  3770. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  3771. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3772. c+=1
  3773. b = tk.Button(xframe,bg="lightblue", text="NAME",width=14,anchor="w")
  3774. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  3775. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3776. c+=1
  3777. b = tk.Button(xframe,bg="#ddd", text="TYPE",width=3)
  3778. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3779. c+=1
  3780. b = tk.Button(xframe,bg="#ddd", text="Uni",width=1)
  3781. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3782. c+=1
  3783. b = tk.Button(xframe,bg="#ddd", text="DMX",width=1)
  3784. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3785. c+=1
  3786. b = tk.Button(xframe,bg="#ddd", text="CH's",width=1)
  3787. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3788. c+=1
  3789. c=0
  3790. r+=1
  3791. for i,p in enumerate(data):
  3792. for j in data[i]:
  3793. b = tk.Button(xframe,bg="lightblue", text=""+str(j),width=6,anchor="e")
  3794. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  3795. c+=1
  3796. c=0
  3797. r+=1
  3798. return self.bframe
  3799. def ScrollFrame(root,width=50,height=100,bd=1,bg="black"):
  3800. #print("ScrollFrame init",width,height)
  3801. aframe=tk.Frame(root,relief=tk.GROOVE)#,width=width,height=height,bd=bd)
  3802. #aframe.place(x=0,y=0)
  3803. aframe.pack(side="left",fill="both",expand=1) #x=0,y=0)
  3804. canvas=tk.Canvas(aframe,width=width-24,height=height)
  3805. if bg == "":
  3806. bg="orange"
  3807. canvas["bg"] = bg # "black" #"green"
  3808. bframe=tk.Frame(canvas,width=width,height=height)
  3809. bframe["bg"] = "blue"
  3810. scrollbar=tk.Scrollbar(aframe,orient="vertical",command=canvas.yview,width=20)
  3811. canvas.configure(yscrollcommand=scrollbar.set)
  3812. scrollbar.pack(side="right",fill="y")
  3813. canvas.pack(side="left",expand=1,fill="both")
  3814. canvas.create_window((0,0),window=bframe,anchor='nw')
  3815. bframe.bind("<Configure>",scroll(canvas).config)
  3816. canvas.bind("<Button>",Event("XXX").event)
  3817. canvas.bind("<Key>",Event("XXX").event)
  3818. canvas.bind("<KeyRelease>",Event("XXX").event)
  3819. return bframe
  3820. #frame = ScrollFrame(root)
  3821. class GUIHandler():
  3822. def __init__(self):
  3823. pass
  3824. def update(self,fix,attr,args={}):
  3825. print("GUIHandler.update()",fix,attr,args)
  3826. for i,k in enumerate(args):
  3827. v = args[k]
  3828. #print("GUI-H", i,k,v)
  3829. class Fixtures():
  3830. def __init__(self):
  3831. #super().__init__()
  3832. self.base=Base()
  3833. #self.load()
  3834. self.fixtures = OrderedDict()
  3835. self.gui = GUIHandler()
  3836. def load_patch(self):
  3837. filename="patch"
  3838. #self.base._init()
  3839. d,l = self.base._load(filename)
  3840. self.fixtures = OrderedDict()
  3841. for i in l:
  3842. sdata = d[i]
  3843. new_f = OrderedDict()
  3844. #print("++++")
  3845. for k,j in sdata.items():
  3846. overide=0 # only for repair
  3847. if overide:
  3848. if k in ["TYPE","VENDOR"]: #ignor
  3849. continue
  3850. new_f[k] = j
  3851. if k =="NAME":
  3852. #print("AAAADDDDDD")
  3853. if "TYPE" not in sdata and not overide:
  3854. if len( sdata["ATTRIBUT"]) == 1:
  3855. new_f["TYPE"] = "DIMMER"
  3856. elif "PAN" in sdata["ATTRIBUT"]:
  3857. new_f["TYPE"] = "MOVER"
  3858. elif "RED" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 3:
  3859. new_f["TYPE"] = "RGB"
  3860. elif "RED" in sdata["ATTRIBUT"]:
  3861. new_f["TYPE"] = "LED"
  3862. elif "CYAN" in sdata["ATTRIBUT"]:
  3863. new_f["TYPE"] = "COLOR"
  3864. else:
  3865. new_f["TYPE"] = ""
  3866. if "VENDOR" not in sdata and not overide:
  3867. new_f["VENDOR"] = ""
  3868. #print(k,j)#,sdata)
  3869. sdata = new_f
  3870. if "ACTIVE" not in sdata:
  3871. sdata["ACTIVE"] = 0
  3872. for attr in sdata["ATTRIBUT"]:
  3873. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  3874. #print("load",filename,sdata)
  3875. #if "CFG" not in sdata:
  3876. # sdata["CFG"] = OrderedDict()
  3877. self.fixtures[str(i)] = sdata
  3878. #PRESETS.label_presets = l
  3879. self.fx_off("all")
  3880. def backup_patch(self,save_as=""):
  3881. filename = "patch"
  3882. #self.fx_off("all")
  3883. data = self.fixtures
  3884. labels = {}
  3885. for k in data:
  3886. labels[k] = k
  3887. #self.base._init()
  3888. self.base._backup(filename,data,labels,save_as)
  3889. def fx_get(self,fix=None):
  3890. out={}
  3891. if not fix or fix == "all":
  3892. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  3893. for fix in self.fixtures:
  3894. data = self.fixtures[fix]
  3895. for attr in data["ATTRIBUT"]:
  3896. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX"]
  3897. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX2"]
  3898. return out
  3899. def fx_off(self,fix=None):
  3900. if not fix or fix == "all":
  3901. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  3902. for fix in self.fixtures:
  3903. data = self.fixtures[fix]
  3904. for attr in data["ATTRIBUT"]:
  3905. data["ATTRIBUT"][attr]["FX"] = ""
  3906. data["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  3907. def get_attr(self,fix,attr):
  3908. if fix in self.fixtures:
  3909. data = self.fixtures[fix]
  3910. if "ATTRIBUT" in data:
  3911. if attr in data["ATTRIBUT"]:
  3912. return data["ATTRIBUT"][attr]
  3913. def get_max_dmx_nr(self,fix):
  3914. max_dmx = 0
  3915. used_dmx = 0
  3916. if fix not in self.fixtures:
  3917. return (used_dmx,max_dmx)
  3918. data = self.fixtures[fix]
  3919. used_dmx = len(data["ATTRIBUT"])
  3920. for a in data["ATTRIBUT"]:
  3921. attr = data["ATTRIBUT"][a]
  3922. if "NR" in attr:
  3923. try:
  3924. _n = int(attr["NR"])
  3925. if _n > max_dmx:
  3926. max_dmx=_n
  3927. except ValueError:pass
  3928. return (used_dmx,max_dmx)
  3929. def get_dmx(self,fix,attr):
  3930. #cprint("get_dmx",[fix,attr])
  3931. if fix in self.fixtures:
  3932. data = self.fixtures[fix]
  3933. DMX = -99
  3934. if "DMX" in data:
  3935. DMX = int(data["DMX"])
  3936. if DMX < 1: # ignore attribute with DMX lower 1
  3937. return -22
  3938. else:
  3939. return -1
  3940. if "UNIVERS" in data:
  3941. if int(data["UNIVERS"]) >= 0:
  3942. DMX += (int(data["UNIVERS"])*512)
  3943. else:
  3944. return -33
  3945. adata = self.get_attr(fix,attr)
  3946. #-hier ende 8.2.22
  3947. #cprint("adata",adata,DMX)
  3948. if adata:
  3949. if "NR" in adata:
  3950. NR = adata["NR"]
  3951. if NR >= 1:
  3952. DMX+=NR-1
  3953. else:
  3954. return -44
  3955. return DMX
  3956. return -4
  3957. return -3
  3958. def update_raw(self,rdata,update=1):
  3959. cprint("update_raw",len(rdata))
  3960. cmd = []
  3961. for i,d in enumerate(rdata):
  3962. xcmd = {"DMX":""}
  3963. #print("fix:",i,d)
  3964. fix = d["FIX"]
  3965. attr = d["ATTR"]
  3966. v2 = d["VALUE"]
  3967. v2_fx = d["FX"]
  3968. if fix not in self.fixtures:
  3969. continue
  3970. sdata = self.fixtures[fix] #shortcat
  3971. ATTR = sdata["ATTRIBUT"]
  3972. sDMX = 0
  3973. if sdata["DMX"] > 0:
  3974. #print( sdata)
  3975. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  3976. #sDMX =sdata["DMX"]
  3977. #else:
  3978. # continue
  3979. if attr not in ATTR:
  3980. continue
  3981. #DMX = FIXTURES.get_dmx(fix)
  3982. if ATTR[attr]["NR"] >= 0:
  3983. DMX = sDMX+ATTR[attr]["NR"]-1
  3984. xcmd["DMX"] = str(DMX)
  3985. else:
  3986. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  3987. xcmd["VIRTUAL"] = {}
  3988. for a in ATTR:
  3989. if ATTR[a]["MASTER"]:
  3990. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  3991. #print( "VIRTUAL",xcmd)
  3992. cmd.append(xcmd)
  3993. v=ATTR[attr]["VALUE"]
  3994. if v2 is not None and update:
  3995. ATTR[attr]["VALUE"] = v2
  3996. if d["FX2"] and update:
  3997. ATTR[attr]["FX2"] = d["FX2"]
  3998. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  3999. text = str(attr)+' '+str(round(v,2))
  4000. #self.gui.update(fix,attr,args={"text":text})
  4001. #print("END 5454 _=_=_=_=_==_")
  4002. #cprint("update_raw",cmd,color="red")
  4003. return cmd
  4004. def encoder(self,fix,attr,xval="",xfade=0,xdelay=0):
  4005. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  4006. if attr == "CLEAR":
  4007. self.clear()
  4008. return 0
  4009. if attr == "ALL":
  4010. x=self.select(fix,attr,mode="toggle")
  4011. return x
  4012. out = []
  4013. if fix not in self.fixtures:
  4014. print(" activate Fixture in fixture list on encoder click ")
  4015. #jdata=[{"MODE":"---"}]
  4016. ii =0
  4017. #jclient_send(jdata)
  4018. delay=0
  4019. print("-->A HIER <--")
  4020. for fix in self.fixtures:
  4021. ii+=1
  4022. #cprint(fix,attr,xval)
  4023. data = self.fixtures[fix]
  4024. if "-FINE" in attr.upper():
  4025. continue
  4026. elif (attr in data["ATTRIBUT"] ) and "-FINE" not in attr.upper() :
  4027. if xval == "click":
  4028. self.select(fix,attr,mode="on")
  4029. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  4030. if fix: # prevent endless recursion
  4031. self.encoder(fix,attr,xval,xfade,delay)
  4032. if DELAY._is():
  4033. delay += DELAY.val()/100
  4034. jdata=[{"MODE":ii}]
  4035. print("-->B HIER <--")
  4036. jclient_send(jdata)
  4037. return 0
  4038. data = self.fixtures[fix]
  4039. if xval == "click":
  4040. #cprint(data)
  4041. return self.select(fix,attr,mode="toggle")
  4042. v2=data["ATTRIBUT"][attr]["VALUE"]
  4043. change=0
  4044. increment = 4.11
  4045. jdata = {"MODE":"ENC"}
  4046. if xval == "++":
  4047. v2+= increment
  4048. jdata["INC"] = increment
  4049. change=1
  4050. elif xval == "--":
  4051. jdata["INC"] = increment*-1
  4052. v2-= increment
  4053. change=1
  4054. elif xval == "+":
  4055. increment = 0.5
  4056. v2+= increment
  4057. jdata["INC"] = increment
  4058. change=1
  4059. elif xval == "-":
  4060. increment = 0.5
  4061. jdata["INC"] = increment*-1
  4062. v2-= increment
  4063. change=1
  4064. elif type(xval) is int or type(xval) is float:
  4065. v2 = xval
  4066. change=1
  4067. if v2 < 0:
  4068. v2=0
  4069. elif v2 > 256:
  4070. v2=256
  4071. jdata["VALUE"] = round(v2,4)
  4072. jdata["FIX"] = fix
  4073. jdata["ATTR"] = attr
  4074. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  4075. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  4076. out = {}
  4077. if change:
  4078. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  4079. data["ATTRIBUT"][attr]["VALUE"] = round(v2,4)
  4080. jdata["FADE"] = 0
  4081. if xfade:
  4082. jdata["FADE"] = xfade
  4083. if xdelay:
  4084. #if attr not in ["PAN","TILT"] and 1:
  4085. jdata["DELAY"] = xdelay
  4086. if not modes.val("BLIND"):
  4087. jdata = [jdata]
  4088. #print("ENC",jdata)
  4089. jclient_send(jdata)
  4090. time.sleep(0.001)
  4091. return v2
  4092. def get_active(self):
  4093. cprint("get_active",self)
  4094. CFG = OrderedDict()
  4095. sdata = OrderedDict()
  4096. sdata["CFG"] = CFG # OrderedDict()
  4097. sdata["CFG"]["FADE"] = FADE.val()
  4098. sdata["CFG"]["DEALY"] = 0
  4099. #sdata["CFG"]["BUTTON"] = "GO"
  4100. for fix in self.fixtures:
  4101. data = self.fixtures[fix]
  4102. for attr in data["ATTRIBUT"]:
  4103. if data["ATTRIBUT"][attr]["ACTIVE"]:
  4104. if fix not in sdata:
  4105. sdata[fix] = {}
  4106. if attr not in sdata[fix]:
  4107. sdata[fix][attr] = OrderedDict()
  4108. if not modes.val("REC-FX"):
  4109. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  4110. #sdata[fix][attr]["FADE"] = FADE.val() #fade
  4111. else:
  4112. sdata[fix][attr]["VALUE"] = None #data["ATTRIBUT"][attr]["VALUE"]
  4113. if "FX" not in data["ATTRIBUT"][attr]:
  4114. data["ATTRIBUT"][attr]["FX"] =""
  4115. if "FX2" not in data["ATTRIBUT"][attr]:
  4116. data["ATTRIBUT"][attr]["FX2"] ={}
  4117. sdata[fix][attr]["FX"] = data["ATTRIBUT"][attr]["FX"]
  4118. sdata[fix][attr]["FX2"] = data["ATTRIBUT"][attr]["FX2"]
  4119. return sdata
  4120. def _deselect_all(self,fix=None):
  4121. cprint("FIXTURES._deselect_all()",fix,"ALL",color="yellow")
  4122. c=0
  4123. if fix in self.fixtures:
  4124. data = self.fixtures[fix]
  4125. for attr in data["ATTRIBUT"]:
  4126. #print("SELECT ALL",fix,attr)
  4127. if "-FINE" in attr.upper():
  4128. pass
  4129. else:
  4130. c+=self.select(fix,attr,mode="off",mute=1)
  4131. return c
  4132. def _select_all(self,fix=None,mode="toggle"):
  4133. cprint("FIXTURES._select_all()",fix,"ALL",mode,color="yellow")
  4134. c=0
  4135. if fix in self.fixtures:
  4136. data = self.fixtures[fix]
  4137. for attr in data["ATTRIBUT"]:
  4138. #print("SELECT ALL",fix,attr)
  4139. if "-FINE" in attr.upper():
  4140. pass
  4141. else:
  4142. c+=self.select(fix,attr,mode="on",mute=1)
  4143. if not c and mode == "toggle": # unselect all
  4144. c= self._deselect_all(fix=fix)
  4145. return c
  4146. def select(self,fix=None,attr=None,mode="on",mute=0):
  4147. if not mute:
  4148. cprint("FIXTURES.select()",fix,attr,mode,color="yellow")
  4149. out = 0
  4150. if fix in self.fixtures:
  4151. data = self.fixtures[fix]
  4152. if attr.upper() == "ALL":
  4153. x=self._select_all(fix=fix,mode=mode)
  4154. return x
  4155. elif attr in data["ATTRIBUT"]:
  4156. if mode == "on":
  4157. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  4158. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  4159. out = 1
  4160. elif mode == "off":
  4161. if data["ATTRIBUT"][attr]["ACTIVE"]:
  4162. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  4163. out = 1
  4164. elif mode == "toggle":
  4165. if data["ATTRIBUT"][attr]["ACTIVE"]:
  4166. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  4167. else:
  4168. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  4169. out = 1
  4170. return out
  4171. def clear(self):
  4172. out = 0
  4173. for fix in self.fixtures:
  4174. data = self.fixtures[fix]
  4175. for attr in data["ATTRIBUT"]:
  4176. #if attr.endswith("-FINE"):
  4177. # continue
  4178. if data["ATTRIBUT"][attr]["ACTIVE"]:
  4179. out +=1
  4180. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  4181. return out
  4182. def CFG_CHECKER(sdata):
  4183. "repair CFG "
  4184. ok = 0
  4185. if "CFG" not in sdata:
  4186. sdata["CFG"] = OrderedDict()
  4187. ok += 1
  4188. if "FADE" not in sdata["CFG"]:
  4189. sdata["CFG"]["FADE"] = 4
  4190. ok += 1
  4191. if "DELAY" not in sdata["CFG"]:
  4192. sdata["CFG"]["DELAY"] = 0
  4193. ok += 1
  4194. if "BUTTON" not in sdata["CFG"]:
  4195. sdata["CFG"]["BUTTON"] = "GO"
  4196. ok += 1
  4197. if "HTP-MASTER" not in sdata["CFG"]:
  4198. sdata["CFG"]["HTP-MASTER"] = 100 #%
  4199. ok += 1
  4200. if "SIZE-MASTER" not in sdata["CFG"]:
  4201. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  4202. ok += 1
  4203. if "SPEED-MASTER" not in sdata["CFG"]:
  4204. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  4205. ok += 1
  4206. if "OFFSET-MASTER" not in sdata["CFG"]:
  4207. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  4208. ok += 1
  4209. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  4210. #except:pass
  4211. return ok
  4212. class Presets():
  4213. def __init__(self):
  4214. #super().__init__()
  4215. self.base = Base()
  4216. #self.load()
  4217. self._last_copy = None
  4218. self._last_move = None
  4219. self.fx_buffer = {}
  4220. def load_presets(self):
  4221. #self._load()
  4222. filename="presets"
  4223. #self.base._init()
  4224. d,l = self.base._load(filename)
  4225. for i in d:
  4226. sdata = d[i]
  4227. ok = CFG_CHECKER(sdata)
  4228. self.val_presets = d
  4229. self.label_presets = l
  4230. def check_cfg(self,nr=None):
  4231. cprint("PRESETS.check_cfg()",nr)#,color="red")
  4232. ok = 0
  4233. if nr is not None:
  4234. if nr in self.val_presets:
  4235. sdata = self.val_presets[nr]
  4236. ok += self._check_cfg(sdata)
  4237. else:
  4238. cprint("nr not in data ",nr,color="red")
  4239. else:
  4240. for nr in self.val_presets:
  4241. sdata = self.val_presets[nr]
  4242. ok += self._check_cfg(sdata)
  4243. return ok
  4244. def _check_cfg(self,sdata):
  4245. cprint("PRESETS._check_cfg()")#,color="red")
  4246. ok = CFG_CHECKER(sdata)
  4247. if ok:
  4248. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  4249. return ok
  4250. def backup_presets(self,save_as=""):
  4251. filename = "presets"
  4252. data = self.val_presets
  4253. labels = self.label_presets
  4254. #self.base._init()
  4255. self.base._backup(filename,data,labels,save_as)
  4256. def get_cfg(self,nr):
  4257. cprint("PRESETS.get_cfg()",nr)
  4258. self.check_cfg(nr)
  4259. if nr not in self.val_presets:
  4260. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  4261. return {}
  4262. if "CFG" in self.val_presets[nr]:
  4263. return self.val_presets[nr]["CFG"]
  4264. def clean(self,nr):
  4265. if nr not in self.val_presets:
  4266. self.val_presets[nr] = OrderedDict()
  4267. #self.val_presets[nr]["VALUE"] = 0
  4268. #self.val_presets[nr]["FX"] = ""
  4269. sdata = self.val_presets[nr]
  4270. for fix in sdata:
  4271. #print("exec.clear()",nr,fix,sdata[fix])
  4272. for attr in sdata[fix]:
  4273. row = sdata[fix][attr]
  4274. if fix == "CFG":
  4275. continue
  4276. if "VALUE" not in row:
  4277. row["VALUE"] = None
  4278. if "FX" not in row:
  4279. row["FX"] = ""
  4280. if "FX2" not in row:
  4281. row["FX2"] = OrderedDict()
  4282. elif row["FX2"]:
  4283. for k in ["SIZE","SPEED","START","OFFSET"]:
  4284. row["FX2"][k] = int( row["FX2"][k] )
  4285. row["FX"] = ""
  4286. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  4287. #"off:0:0:0:16909:-:"
  4288. x = row["FX"].split(":")
  4289. print("-fx",x,len(x))
  4290. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  4291. if len(x) >= 6:
  4292. row["FX2"]["TYPE"] = x[0]
  4293. row["FX2"]["SIZE"] = int(x[1])
  4294. row["FX2"]["SPEED"] = int(x[2])
  4295. row["FX2"]["START"] = int(x[3])
  4296. row["FX2"]["OFFSET"] = int(x[4])
  4297. row["FX2"]["BASE"] = x[5]
  4298. row["FXOLD"] = row["FX"]
  4299. row["FX"] = ""
  4300. #cprint("exec.clear()",nr,fix,row)
  4301. def get_raw_map(self,nr):
  4302. self.clean(nr)
  4303. print("get_raw_map",nr)
  4304. sdata = self.val_presets[nr]
  4305. cmd = ""
  4306. out = []
  4307. dmx=-1
  4308. for fix in sdata:
  4309. if fix == "CFG":
  4310. #print("CFG",nr,sdata[fix])
  4311. continue
  4312. for attr in sdata[fix]:
  4313. x = {}
  4314. #print("RAW",attr)
  4315. x["FIX"] = fix
  4316. x["ATTR"] = attr
  4317. x["VALUE"] = sdata[fix][attr]["VALUE"]
  4318. x["FX"] = sdata[fix][attr]["FX"]
  4319. x["FX2"] = sdata[fix][attr]["FX2"]
  4320. #x["DMX"] = sdata[fix][attr]["NR"]
  4321. out.append(x)
  4322. return out
  4323. def get_btn_txt(self,nr):
  4324. sdata=self.val_presets[nr]
  4325. BTN="go"
  4326. if "CFG" in sdata:
  4327. if "BUTTON" in sdata["CFG"]:
  4328. BTN = sdata["CFG"]["BUTTON"]
  4329. _label = self.label_presets[nr] # = label
  4330. txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  4331. print("get_btn_txt",nr,[txt])
  4332. return txt
  4333. def _btn_cfg(self,nr,txt=None):
  4334. if nr not in self.val_presets:
  4335. return ""
  4336. if "CFG" not in self.val_presets[nr]:
  4337. self.val_presets[nr]["CFG"] = OrderedDict()
  4338. return self.val_presets[nr]["CFG"]
  4339. def btn_cfg(self,nr,txt=None):
  4340. if nr not in self.val_presets:
  4341. return ""
  4342. if "CFG" not in self.val_presets[nr]:
  4343. self.val_presets[nr]["CFG"] = OrderedDict()
  4344. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  4345. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  4346. if type(txt) is str:
  4347. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  4348. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  4349. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  4350. print("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  4351. return self.val_presets[nr]["CFG"]["BUTTON"]
  4352. def label(self,nr,txt=None):
  4353. if nr not in self.label_presets:
  4354. return ""
  4355. if type(txt) is str:
  4356. self.label_presets[nr] = txt
  4357. print("set label",nr,[txt])
  4358. print("??? ?? set label",nr,[txt])
  4359. return self.label_presets[nr]
  4360. def clear_move(self):
  4361. cprint("PRESETS.clear_move()",end=" ")
  4362. self.clear_copy()
  4363. def clear_copy(self):
  4364. cprint("PRESETS.clear_copy()",end=" ")
  4365. if self._last_copy is not None:
  4366. cprint("=OK=",color="red")
  4367. self._last_copy = None
  4368. else:
  4369. cprint("=NONE=",color="green")
  4370. def copy(self,nr,overwrite=1):
  4371. cprint("PRESETS._copy",nr,"last",self._last_copy)
  4372. if nr >= 0:
  4373. if self._last_copy is not None:
  4374. if modes.val("COPY"):
  4375. modes.val("COPY",3)
  4376. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  4377. return ok #ok
  4378. else:
  4379. if modes.val("COPY"):
  4380. modes.val("COPY",2)
  4381. self._last_copy = nr
  4382. cprint("PRESETS.copy START ",color="red")
  4383. return 0
  4384. return 1 # on error reset move
  4385. def _copy(self,nr_from,nr_to,overwrite=1):
  4386. cprint("PRESETS._copy",nr_from,"to",nr_to)
  4387. self.check_cfg(nr_from)
  4388. if type(self._last_copy) is None:
  4389. cprint("PRESETS._copy last nr is None",color="red")
  4390. return 0
  4391. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  4392. if nr_from in self.val_presets and nr_to in self.val_presets:
  4393. fdata = self.val_presets[nr_from]
  4394. tdata = self.val_presets[nr_to]
  4395. #cprint(fdata)
  4396. flabel = self.label_presets[nr_from]
  4397. tlabel = self.label_presets[nr_to]
  4398. self.val_presets[nr_to] = copy.deepcopy(fdata)
  4399. self.label_presets[nr_to] = flabel
  4400. if not overwrite: #default
  4401. cprint("overwrite",overwrite)
  4402. self.val_presets[nr_from] = copy.deepcopy(tdata)
  4403. self.label_presets[nr_from] = tlabel
  4404. #self.label_presets[nr_from] = "MOVE"
  4405. self.clear_copy()
  4406. cprint("PRESETS.copy OK",color="green")
  4407. return 1
  4408. def move(self,nr):
  4409. cprint("PRESETS.move",self._last_copy,"to",nr)
  4410. if nr >= 0:
  4411. last = self._last_copy
  4412. if modes.val("MOVE"):
  4413. modes.val("MOVE",2)
  4414. ok= self.copy(nr,overwrite=0)
  4415. if ok and last:
  4416. if modes.val("MOVE"):
  4417. modes.val("MOVE",3)
  4418. cprint("PRESETS.move OK",color="red")
  4419. #self.delete(last)
  4420. return ok #ok
  4421. return 0 # on error reset move
  4422. def delete(self,nr):
  4423. cprint("PRESETS.delete",nr)
  4424. ok=0
  4425. if nr in self.val_presets:
  4426. self.val_presets[nr] = OrderedDict()
  4427. self.label_presets[nr] = ""
  4428. ok = 1
  4429. self.check_cfg(nr)
  4430. return ok
  4431. def rec(self,nr,data,arg=""):
  4432. cprint("rec",self,"rec()",len(data),arg)
  4433. self.check_cfg(nr)
  4434. self._check_cfg(data) #by ref
  4435. odata=self.val_presets[nr]
  4436. #print("odata",odata)
  4437. if "CFG" in odata:
  4438. if "BUTTON" in odata["CFG"]:
  4439. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  4440. self.val_presets[nr] = data
  4441. return 1
  4442. def test(a1="",a2=""):
  4443. print([a1,a2])
  4444. class FixtureEditor():
  4445. def __init__(self,dmx=1):
  4446. pass
  4447. self.elem=[]
  4448. self.dmx=dmx
  4449. print("init FixtureEditor",dmx)
  4450. def event(self,a1="",a2=""):
  4451. print([self.dmx,a1,a2])
  4452. j=[]
  4453. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  4454. j.append(jdata)
  4455. jclient_send(j)
  4456. class MasterWing():
  4457. def __init__(self,dmx=1):
  4458. pass
  4459. self.elem=[]
  4460. self.dmx=dmx
  4461. print("init MasterWing",dmx)
  4462. def event(self,a1="",a2=""):
  4463. print([self.dmx,a1,a2])
  4464. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  4465. j=[]
  4466. j.append(jdata)
  4467. jclient_send(j)
  4468. class BufferVar():
  4469. def __init__(self,elem):
  4470. self.elem = elem
  4471. def change_dmx(self,event=""):
  4472. nr=1
  4473. txt=""
  4474. def cb(data):
  4475. txt = data["Value"]
  4476. dialog._cb = _cb
  4477. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  4478. print("change_dmx",[event,self])
  4479. class EXEC_FADER():
  4480. def __init__(self,frame,nr,cb=None,**args):
  4481. self.frame = frame
  4482. self.nr= nr
  4483. self.id=nr
  4484. self.elem = []
  4485. self._cb = cb
  4486. width=11
  4487. frameS = tk.Frame(self.frame,bg="#005",width=width)
  4488. frameS.pack(fill=tk.Y, side=tk.LEFT)
  4489. self.frame=frameS
  4490. def event(self,a1="",a2=""):
  4491. if self._cb is not None:
  4492. self._cb(a1,a2,nr=self.nr)
  4493. else:
  4494. print(self,"event",[self.nr,a1,a2])
  4495. j=[]
  4496. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.nr)}
  4497. j.append(jdata)
  4498. jclient_send(j)
  4499. def set_attr(self,_event=None):
  4500. txt= self.attr["text"]
  4501. def _cb(data):
  4502. print(self,"set_attr._cb()",data)
  4503. if "Value" in data and type( data["Value"]) is str:
  4504. txt = data["Value"]
  4505. self._set_attr(txt)
  4506. dialog._cb = _cb
  4507. dialog.askstring("ATTR","set attr:",initialvalue=txt)
  4508. def _set_attr(self,txt=""):
  4509. if type(txt) is str:
  4510. self.attr["text"] = "{}".format(txt)
  4511. print("_set_attr",[self])
  4512. def set_label(self,name=""):
  4513. #print("set_label",self.b,name)
  4514. self.label["text"] = name
  4515. def set_mode(self,_event=None):
  4516. txt= self.mode["text"]
  4517. def _cb(data):
  4518. txt = data["Value"]
  4519. print(self,"set_mode._cb()",txt)
  4520. w = GUIWindow("config",master=1,width=200,height=140,left=L1,top=TOP)
  4521. #w.pack()
  4522. self._set_mode(txt)
  4523. w.show()
  4524. dialog._cb = _cb
  4525. dialog.askstring("MODE S/F:","SWITCH or FADE",initialvalue=txt)
  4526. def _set_mode(self,txt=""):
  4527. if type(txt) is str:
  4528. self.mode["text"] = "{}".format(txt[0].upper())
  4529. print("_set_attr",[self])
  4530. def _refresh(self):
  4531. pass
  4532. def pack(self,init=None,from_=255,to=0,**args):
  4533. width=11
  4534. r=0
  4535. c=0
  4536. j=0
  4537. font8 = ("FreeSans",8)
  4538. frameS=self.frame
  4539. self.b = tk.Scale(frameS,bg="lightblue", width=28,from_=from_,to=to,command=self.event)
  4540. self.b.pack(fill=tk.Y, side=tk.TOP)
  4541. if init is not None:
  4542. self.b.set(init)
  4543. self.elem.append(self.b)
  4544. self.b = tk.Button(frameS,bg="lightblue",text="{}".format(self.nr), width=5,command=test,font=font8 )
  4545. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4546. self.label = self.b
  4547. if 1: #self.nr <= 10:
  4548. self.elem.append(self.b)
  4549. self.b = tk.Button(frameS,bg="lightblue",text="", width=5,command=self.set_attr,font=font8 )
  4550. self.attr=self.b
  4551. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4552. self.elem.append(self.b)
  4553. f = tk.Frame(frameS)
  4554. ##f.pack()
  4555. #self.b = tk.Button(f,bg="lightblue",text="<+", width=1,command=self.set_mode,font=font8 )
  4556. #self.mode=self.b
  4557. ##self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4558. #self.elem.append(self.b)
  4559. #self.b = tk.Button(frameS,bg="lightblue",text="F", width=4,command=self.set_mode,font=font8 )
  4560. #self.mode=self.b
  4561. #self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4562. ##self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4563. #self.elem.append(self.b)
  4564. #self.b = tk.Button(f,bg="lightblue",text="+>", width=1,command=self.set_mode,font=font8 )
  4565. #self.mode=self.b
  4566. ##self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4567. #self.elem.append(self.b)
  4568. self.b = tk.Label(frameS,bg="black",text="", width=4,font=font8 )
  4569. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4570. self.elem.append(self.b)
  4571. class ELEM_FADER():
  4572. def __init__(self,frame,nr,cb=None,**args):
  4573. self.frame = frame
  4574. self.nr= nr
  4575. self.id=nr
  4576. self.elem = []
  4577. self._cb = cb
  4578. width=11
  4579. frameS = tk.Frame(self.frame,bg="#005",width=width)
  4580. frameS.pack(fill=tk.Y, side=tk.LEFT)
  4581. self.frame=frameS
  4582. def event(self,a1="",a2=""):
  4583. if self._cb is not None:
  4584. self._cb(a1,a2,nr=self.nr)
  4585. else:
  4586. print(self,"event",[self.nr,a1,a2])
  4587. j=[]
  4588. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.nr)}
  4589. j.append(jdata)
  4590. jclient_send(j)
  4591. def set_attr(self,_event=None):
  4592. txt= self.attr["text"]
  4593. def _cb(data):
  4594. txt = data["Value"]
  4595. print(self,"set_attr._cb()",txt)
  4596. self._set_attr(txt)
  4597. dialog._cb = _cb
  4598. dialog.askstring("ATTR","set attr:",initialvalue=txt)
  4599. def _set_attr(self,txt=""):
  4600. if type(txt) is str:
  4601. self.attr["text"] = "{}".format(txt)
  4602. print("_set_attr",[self])
  4603. def set_label(self,name=""):
  4604. #print("set_label",self.b,name)
  4605. self.label["text"] = name
  4606. def set_mode(self,_event=None):
  4607. txt= self.mode["text"]
  4608. def _cb(data):
  4609. txt = data["Value"]
  4610. print(self,"set_mode._cb()",txt)
  4611. w = GUIWindow("config",master=1,width=200,height=140,left=L1,top=TOP)
  4612. #w.pack()
  4613. self._set_mode(txt)
  4614. w.show()
  4615. dialog._cb = _cb
  4616. dialog.askstring("MODE S/F:","SWITCH or FADE",initialvalue=txt)
  4617. def _set_mode(self,txt=""):
  4618. if type(txt) is str:
  4619. self.mode["text"] = "{}".format(txt[0].upper())
  4620. print("_set_attr",[self])
  4621. def _refresh(self):
  4622. pass
  4623. def pack(self,init=None,from_=255,to=0,**args):
  4624. width=11
  4625. r=0
  4626. c=0
  4627. j=0
  4628. font8 = ("FreeSans",8)
  4629. frameS=self.frame
  4630. self.b = tk.Scale(frameS,bg="lightblue", width=28,from_=from_,to=to,command=self.event)
  4631. self.b.pack(fill=tk.Y, side=tk.TOP)
  4632. if init is not None:
  4633. self.b.set(init)
  4634. self.elem.append(self.b)
  4635. self.b = tk.Button(frameS,bg="lightblue",text="{}".format(self.nr), width=4,command=test,font=font8 )
  4636. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4637. self.label = self.b
  4638. self.elem.append(self.b)
  4639. self.b = tk.Button(frameS,bg="lightblue",text="", width=5,command=self.set_attr,font=font8 )
  4640. self.attr=self.b
  4641. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4642. self.elem.append(self.b)
  4643. f = tk.Frame(frameS)
  4644. #f.pack()
  4645. self.b = tk.Button(f,bg="lightblue",text="<+", width=1,command=self.set_mode,font=font8 )
  4646. self.mode=self.b
  4647. #self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4648. self.elem.append(self.b)
  4649. self.b = tk.Button(frameS,bg="lightblue",text="F", width=4,command=self.set_mode,font=font8 )
  4650. self.mode=self.b
  4651. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4652. #self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4653. self.elem.append(self.b)
  4654. self.b = tk.Button(f,bg="lightblue",text="+>", width=1,command=self.set_mode,font=font8 )
  4655. self.mode=self.b
  4656. #self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4657. self.elem.append(self.b)
  4658. self.b = tk.Label(frameS,bg="black",text="", width=4,font=font8 )
  4659. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  4660. self.elem.append(self.b)
  4661. class GUI_ExecWingLayout():
  4662. def __init__(self,root,data,title="tilte",width=800,start=81):
  4663. #xfont = tk.font.Font(family="FreeSans", size=5, weight="bold")
  4664. font8 = ("FreeSans",8)
  4665. self.dmx=1
  4666. self.univ=0
  4667. self.start=start-1
  4668. r=0
  4669. c=0
  4670. i=1
  4671. self.elem=[]
  4672. self.header=[]
  4673. self.data = data
  4674. #self.frame = tk.Frame(root,bg="black",width=width)
  4675. #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4676. #self.b = tk.Label(self.frame,bg="#fff",text="Master Wing") #,font=font8 )
  4677. #self.b.pack(fill=None, side=tk.LEFT)
  4678. #self.frame = tk.Frame(root,bg="black",width=width)
  4679. #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4680. #self.b = tk.Label(self.frame,bg="black",text="") # spacer
  4681. #self.b.pack(fill=tk.Y, side=tk.LEFT)
  4682. self.frame = tk.Frame(root,bg="magenta",width=width,border=2) # fader frame
  4683. self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4684. r=0
  4685. c=0
  4686. pb=10
  4687. self.pb=pb
  4688. for j,row in enumerate(data):
  4689. if c % pb == 0 or c==0:
  4690. h=hex(j*10)[2:].rjust(2,"0")
  4691. frameS = tk.Frame(self.frame,bg="#000",width=width,border=2)
  4692. frameS.pack(fill=tk.BOTH, side=tk.TOP)
  4693. p=j//pb+1
  4694. if j < 10:
  4695. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4696. else:
  4697. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4698. self.b = tk.Label(frameS,bg="lightblue",text=txt,width=25,font=font8 )
  4699. self.header.append(self.b)
  4700. self.b.pack(fill=None, side=tk.LEFT)
  4701. self.b = tk.Label(frameS,bg="black",text="" ,width=11,font=font8 )
  4702. self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4703. try:
  4704. frameS = tk.Frame(self.frame,bg="#a000{}".format(h),width=width,border=2)
  4705. except:
  4706. frameS = tk.Frame(self.frame,bg="#a0aadd",width=width,border=2)
  4707. c=0
  4708. #print(frameS)
  4709. #e= ELEM_FADER(frameS,nr=j+1,cb=self.event_cb)
  4710. e= EXEC_FADER(frameS,nr=j+1,cb=self.event_cb)
  4711. if j >= 10:
  4712. e.pack(from_=400,to=0,init=100)
  4713. else:
  4714. e.pack(from_=200,to=0,init=100)
  4715. self.elem.append(e)
  4716. frameS.pack(fill=tk.X, side=tk.TOP)
  4717. c+=1
  4718. i+=1
  4719. self.frame.pack()
  4720. self._event_redraw()
  4721. def set_fader(self,nr,val,color=""):
  4722. #print("set_fader",nr,val)
  4723. if nr < len(self.elem):
  4724. ee = self.elem[nr].elem[0]
  4725. ee.set(val)
  4726. if color:
  4727. ee["bg"] = color
  4728. return # STOP
  4729. for i in self.elem:
  4730. e = i #self.elem[i] #.append(e)
  4731. #print("e",e)
  4732. ee = e.elem[0]
  4733. #print(dir(ee))
  4734. ee.set(val)# = val
  4735. #for ee in e.elem: #.append(self.b)
  4736. # print("ee",ee)
  4737. def event_cb(self,a1="",a2="",nr=None,**args):
  4738. print("event_cb:",nr,a1,a2,args)
  4739. nr += 1
  4740. jdata= {"CMD":"X-MASTER","NR":nr,"VALUE":int(a1)}
  4741. if nr >= 1 and nr <= 10:
  4742. jdata["CMD"] = "EXEC-SIZE-MASTER"
  4743. jdata["NR"] = nr +self.start
  4744. if nr >= 11 and nr <= 20:
  4745. jdata["CMD"] = "EXEC-SPEED-MASTER"
  4746. jdata["NR"] = nr-10 +self.start
  4747. if nr >= 21 and nr <= 30:
  4748. jdata["CMD"] = "EXEC-OFFSET-MASTER"
  4749. jdata["NR"] = nr-20 +self.start
  4750. print("event_cb",jdata)
  4751. j = [jdata]
  4752. jclient_send(j)
  4753. def set_name(self,_event=None):
  4754. txt = self.name["text"]
  4755. def _cb(data):
  4756. txt = data["Value"]
  4757. print(self,"._cb()",txt)
  4758. self.name["text"] = "{}".format(txt)
  4759. print("change_dmx",[_event,self])
  4760. dialog._cb = _cb
  4761. dialog.askstring("FIXTURE NAME:","NAME:",initialvalue=txt)
  4762. def event_value(self,_event=None):
  4763. nr=self.dmx
  4764. txt= self.entry_dmx["text"]
  4765. def _event_redraw(self,_event=None):
  4766. nr = 0
  4767. print("change_dmx",[_event,self])
  4768. for i,btn in enumerate(self.elem):
  4769. btn.set_label("{} D:{}".format(i+1,nr))
  4770. btn.nr = nr+i
  4771. pb=self.pb
  4772. for j,e in enumerate(self.header):
  4773. p=j+1
  4774. #p=nr/pb
  4775. if p == 1:
  4776. txt="SIZE-MASTER:{} {}-{}".format(p,1+self.start,10+self.start)#p*pb-pb+1,p*pb)
  4777. elif p == 2:
  4778. txt="SPEED-MASTER:{} {}-{}".format(p,1+self.start,10+self.start)#p*pb-pb+1,p*pb)
  4779. elif p == 3:
  4780. txt="OFFSET-MASTER:{} {}-{}".format(p,1+self.start,10+self.start)#p*pb-pb+1,p*pb)
  4781. else:
  4782. txt="X-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4783. #txt="BANK:{} {}-{}".format(p,p*pb-pb+nr,p*pb+nr)
  4784. print("---",j,txt,e)
  4785. e["text"] = txt
  4786. class GUI_MasterWingLayout():
  4787. def __init__(self,root,data,title="tilte",width=800):
  4788. #xfont = tk.font.Font(family="FreeSans", size=5, weight="bold")
  4789. font8 = ("FreeSans",8)
  4790. self.dmx=1
  4791. self.univ=0
  4792. r=0
  4793. c=0
  4794. i=1
  4795. self.elem=[]
  4796. self.header=[]
  4797. self.data = data
  4798. #self.frame = tk.Frame(root,bg="black",width=width)
  4799. #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4800. #self.b = tk.Label(self.frame,bg="#fff",text="Master Wing") #,font=font8 )
  4801. #self.b.pack(fill=None, side=tk.LEFT)
  4802. #self.frame = tk.Frame(root,bg="black",width=width)
  4803. #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4804. #self.b = tk.Label(self.frame,bg="black",text="") # spacer
  4805. #self.b.pack(fill=tk.Y, side=tk.LEFT)
  4806. self.frame = tk.Frame(root,bg="magenta",width=width,border=2) # fader frame
  4807. self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4808. r=0
  4809. c=0
  4810. pb=1
  4811. self.pb=pb
  4812. for j,row in enumerate(data):
  4813. if c % pb == 0 or c==0:
  4814. h=hex(j*10)[2:].rjust(2,"0")
  4815. frameS = tk.Frame(self.frame,bg="#000",width=width,border=2)
  4816. frameS.pack(fill=tk.BOTH, side=tk.TOP)
  4817. p=j//pb+1
  4818. if j < 1:
  4819. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4820. else:
  4821. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4822. self.b = tk.Label(frameS,bg="lightblue",text=txt,width=25,font=font8 )
  4823. self.header.append(self.b)
  4824. self.b.pack(fill=None, side=tk.LEFT)
  4825. self.b = tk.Label(frameS,bg="black",text="" ,width=11,font=font8 )
  4826. self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4827. try:
  4828. frameS = tk.Frame(self.frame,bg="#a000{}".format(h),width=width,border=2)
  4829. except:
  4830. frameS = tk.Frame(self.frame,bg="#a0aadd",width=width,border=2)
  4831. c=0
  4832. #print(frameS)
  4833. e= ELEM_FADER(frameS,nr=j+1,cb=self.event_cb)
  4834. if j >= 2:
  4835. e.pack(from_=400,to=0,init=100)
  4836. else:
  4837. e.pack(from_=200,to=0,init=100)
  4838. self.elem.append(e)
  4839. frameS.pack(fill=tk.X, side=tk.TOP)
  4840. c+=1
  4841. i+=1
  4842. self.frame.pack()
  4843. self._event_redraw()
  4844. def event_cb(self,a1="",a2="",nr=None,**args):
  4845. print("event_cb:",nr,a1,a2,args)
  4846. nr += 1
  4847. jdata= {"CMD":"X-MASTER","NR":nr,"VALUE":int(a1)}
  4848. if nr == 1:
  4849. jdata["CMD"] = "SIZE-MASTER"
  4850. jdata["NR"] = 1 #nr
  4851. if nr == 2:
  4852. jdata["CMD"] = "SPEED-MASTER"
  4853. jdata["NR"] = 1 #nr
  4854. print("event_cb",jdata)
  4855. j = [jdata]
  4856. jclient_send(j)
  4857. def set_name(self,_event=None):
  4858. txt = self.name["text"]
  4859. def _cb(data):
  4860. txt = data["Value"]
  4861. print(self,"._cb()",txt)
  4862. self.name["text"] = "{}".format(txt)
  4863. print("change_dmx",[_event,self])
  4864. dialog._cb = _cb
  4865. dialog.askstring("FIXTURE NAME:","NAME:",initialvalue=txt)
  4866. def event_value(self,_event=None):
  4867. nr=self.dmx
  4868. txt= self.entry_dmx["text"]
  4869. def _event_redraw(self,_event=None):
  4870. nr = 0
  4871. print("change_dmx",[_event,self])
  4872. for i,btn in enumerate(self.elem):
  4873. btn.set_label("{} D:{}".format(i+1,nr))
  4874. btn.nr = nr+i
  4875. pb=self.pb
  4876. for j,e in enumerate(self.header):
  4877. p=j+1
  4878. #p=nr/pb
  4879. if p == 1:
  4880. txt="SIZE-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4881. else:
  4882. txt="SPEED-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4883. #txt="BANK:{} {}-{}".format(p,p*pb-pb+nr,p*pb+nr)
  4884. print("---",j,txt,e)
  4885. e["text"] = txt
  4886. class GUI_FaderLayout():
  4887. def __init__(self,root,data,title="tilte",width=800):
  4888. #xfont = tk.font.Font(family="FreeSans", size=5, weight="bold")
  4889. font8 = ("FreeSans",8)
  4890. self.dmx=1
  4891. self.univ=0
  4892. r=0
  4893. c=0
  4894. i=1
  4895. self.elem=[]
  4896. self.header=[]
  4897. self.data = data
  4898. self.frame = tk.Frame(root,bg="black",width=width)
  4899. self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4900. self.b = tk.Label(self.frame,bg="#fff",text="Fixture Editor") #,font=font8 )
  4901. self.b.pack(fill=None, side=tk.LEFT)
  4902. self.frame = tk.Frame(root,bg="black",width=width)
  4903. self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4904. self.b = tk.Label(self.frame,bg="#ddd",text="NAME:")
  4905. self.b.pack(fill=None, side=tk.LEFT)
  4906. self.b = tk.Button(self.frame,bg="lightblue",text="MAC-500", width=11)
  4907. self.name=self.b
  4908. self.b["command"] = self.set_name
  4909. self.b.pack( side=tk.LEFT)
  4910. self.b = tk.Label(self.frame,bg="lightblue",text="UNIV:")
  4911. self.b.pack(fill=None, side=tk.LEFT)
  4912. self.b_univ = tk.Button(self.frame,bg="lightblue",text="1", width=4)#,command=self.event) #bv.change_dmx)
  4913. self.entry_univ=self.b_univ
  4914. self.b_univ["command"] = self.event_univ
  4915. self.b_univ.pack( side=tk.LEFT)
  4916. self.b = tk.Label(self.frame,bg="lightblue",text="DMX:")
  4917. self.b.pack(fill=None, side=tk.LEFT)
  4918. self.b = tk.Button(self.frame,bg="lightblue",text="1", width=4)#,command=self.event) #bv.change_dmx)
  4919. self.entry_dmx=self.b
  4920. self.b["command"] = self.event_dmx
  4921. self.b.pack( side=tk.LEFT)
  4922. self.b_xdmx = tk.Label(self.frame,bg="lightgreen",text="5")
  4923. self.b_xdmx.pack(fill=None, side=tk.LEFT)
  4924. self.b = tk.Label(self.frame,bg="#ddd",text="TYPE:")
  4925. self.b.pack(fill=None, side=tk.LEFT)
  4926. self.b = tk.Button(self.frame,bg="lightblue",text="LIST", width=5)#,command=self.event) #bv.change_dmx)
  4927. self.b["command"] = self.open_fixture_list
  4928. self.b.pack( side=tk.LEFT)
  4929. self.b = tk.Label(self.frame,bg="black",text="") # spacer
  4930. self.b.pack(fill=tk.Y, side=tk.LEFT)
  4931. self.frame = tk.Frame(root,bg="magenta",width=width,border=2) # fader frame
  4932. self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  4933. r=0
  4934. c=0
  4935. pb=12
  4936. self.pb=pb
  4937. for j,row in enumerate(data):
  4938. if c % pb == 0 or c==0:
  4939. h=hex(j*10)[2:].rjust(2,"0")
  4940. frameS = tk.Frame(self.frame,bg="#000",width=width,border=2)
  4941. frameS.pack(fill=tk.BOTH, side=tk.TOP)
  4942. p=j//pb+1
  4943. txt="BANK:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  4944. self.b = tk.Label(frameS,bg="lightblue",text=txt,width=15,font=font8 )
  4945. self.header.append(self.b)
  4946. self.b.pack(fill=None, side=tk.LEFT)
  4947. self.b = tk.Label(frameS,bg="black",text="" ,width=11,font=font8 )
  4948. self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  4949. try:
  4950. frameS = tk.Frame(self.frame,bg="#a000{}".format(h),width=width,border=2)
  4951. except:
  4952. frameS = tk.Frame(self.frame,bg="#a0aadd",width=width,border=2)
  4953. c=0
  4954. #print(frameS)
  4955. e= ELEM_FADER(frameS,nr=j+1)
  4956. e.pack()
  4957. self.elem.append(e)
  4958. frameS.pack(fill=tk.X, side=tk.TOP)
  4959. c+=1
  4960. i+=1
  4961. self.frame.pack()
  4962. self._event_redraw()
  4963. def set_name(self,_event=None):
  4964. txt = self.name["text"]
  4965. def _cb(data):
  4966. txt = data["Value"]
  4967. print(self,"._cb()",txt)
  4968. self.name["text"] = "{}".format(txt)
  4969. print("change_dmx",[_event,self])
  4970. dialog._cb = _cb
  4971. dialog.askstring("FIXTURE NAME:","NAME:",initialvalue=txt)
  4972. def open_fixture_list(self):
  4973. name = "FIXTURE-LIB"
  4974. line1="Fixture Library"
  4975. line2="CHOOS to EDIT >> DEMO MODUS"
  4976. cb = LOAD_FIXTURE
  4977. #cb.master=self
  4978. pw = PopupList(name,cb=cb,left=_POS_LEFT+820,bg="red")
  4979. frame = pw.sframe(line1=line1,line2=line2)
  4980. r=_load_fixture_list(frame,cb=cb,master=self,bg="red")
  4981. #self.elem["bg"] = "red"
  4982. #self.elem.config(activebackground="red")
  4983. #w.tk.attributes('-topmost',False)
  4984. def load_EMPTY(self,_event=None,attr=[]):
  4985. #attr = [,"RED","GREEN","BLUE"]
  4986. #mode = ["F","F","F","F"]
  4987. self._load_mh(None)#,attr,mode)
  4988. def load_DIM(self,_event=None,attr=[]):
  4989. attr = ["DIM"]
  4990. mode = ["F"]
  4991. self._load_fix(None,attr,mode)
  4992. def load_LED(self,_event=None,attr=[]):
  4993. attr = ["DIM","RED","GREEN","BLUE"]
  4994. mode = ["F","F","F","F"]
  4995. self._load_fix(None,attr,mode)
  4996. def load_MH(self,_event=None,attr=[]):
  4997. attr = ["PAN","PAN-FINE","TILT","TILT-FINE","SHUTTER","DIM","RED","GREEN","BLUE","GOBO"]
  4998. mode = ["F","F","F","F","S","F","F","F","F","S"]
  4999. self._load_fix(None,attr,mode)
  5000. def load_MH2(self,_event=None,attr=[]):
  5001. attr = ["PAN","PAN-FINE","TILT","TILT-FINE","SHUTTER","DIM","RED","GREEN","BLUE","GOBO","G-ROT","PRISM","P-ROT","ZOOM","CONTR"]
  5002. mode = ["F","F","F","F","S","F","F","F","F","S","S","S","S","F","S"]
  5003. self._load_fix(None,attr,mode)
  5004. def _load_fix(self,_event=None,attr=[],mode=[]):
  5005. print("load_fixture",[_event,self])
  5006. #for i,e in enumerate(self.elem):
  5007. for i,e in enumerate(self.elem):
  5008. #print(self,"event",_event,e)
  5009. print("event",_event,e)
  5010. e._set_attr( "---")
  5011. if len(attr) > i:
  5012. e._set_attr( attr[i])
  5013. e._set_mode( "---")
  5014. if len(mode) > i:
  5015. e._set_mode( mode[i])
  5016. def event_univ(self,_event=None):
  5017. nr=self.univ
  5018. txt= self.entry_univ["text"]
  5019. #def _cb(txt):
  5020. def _cb(data):
  5021. txt = data["Value"]
  5022. print(self,"event_univ._cb()",txt)
  5023. try:
  5024. nr = int(txt)
  5025. except TypeError:
  5026. print("--- abort ---")
  5027. return 0
  5028. self.univ = nr
  5029. self._event_redraw(_event)
  5030. dialog._cb = _cb
  5031. dialog.askstring("Universe","Univ 0-15",initialvalue=txt)
  5032. def event_dmx(self,_event=None):
  5033. nr=self.dmx
  5034. txt= self.entry_dmx["text"]
  5035. #txt = dialog.askstring("DMX","ArtNet 1-512 (7680 max)",initialvalue=txt)
  5036. #def _cb(txt):
  5037. def _cb(data):
  5038. txt = data["Value"]
  5039. print(self,"event_dmx._cb()",txt)
  5040. try:
  5041. nr = int(txt)
  5042. except TypeError:
  5043. print("--- abort ---")
  5044. return 0
  5045. self.dmx = nr
  5046. if self.dmx <= 0:
  5047. self.dmx = 1
  5048. if self.dmx > 512:
  5049. self.univ = (self.dmx-1)//512
  5050. self.dmx = (self.dmx-1)%512+1
  5051. self._event_redraw(_event)
  5052. dialog._cb = _cb
  5053. dialog.askstring("DMX","ArtNet 1-512 (7680 max)",initialvalue=txt)
  5054. def _event_redraw(self,_event=None):
  5055. self.entry_dmx["text"] = "{}".format(self.dmx)
  5056. self.entry_univ["text"] = "{}".format(self.univ)
  5057. nr = self.univ*(512)+self.dmx
  5058. self.b_xdmx["text"] = " {} ".format(nr)
  5059. print("change_dmx",[_event,self])
  5060. for i,btn in enumerate(self.elem):
  5061. #print("event",_event,btn)
  5062. #print("btn",btn)
  5063. dmx=nr+i
  5064. nr2 = dmx%512
  5065. btn.set_label("{} D:{}\n{}.{}".format(i+1,dmx,self.univ,nr2))
  5066. btn.nr = nr+i
  5067. pb=self.pb
  5068. for j,e in enumerate(self.header):
  5069. p=j+1
  5070. #p=nr/pb
  5071. txt="BANK:{} {}-{}".format(p,p*pb-pb+nr,p*pb+nr)
  5072. print("---",j,txt,e)
  5073. e["text"] = txt
  5074. class GUI_grid():
  5075. def __init__(self,root,data,title="tilte",width=800):
  5076. self.data = data
  5077. self.frame = tk.Frame(root,bg="black",width=width)
  5078. self.frame.pack(fill=tk.BOTH, side=tk.LEFT)
  5079. r=0
  5080. c=0
  5081. i=1
  5082. for row in data:
  5083. self.b = tk.Button(self.frame,bg="lightblue", text=row["text"],width=11,height=4)
  5084. #self.b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  5085. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  5086. c+=1
  5087. if c % 8 == 0:
  5088. r+=1
  5089. c=0
  5090. i+=1
  5091. self.frame.pack()
  5092. class BEvent():
  5093. def __init__(self,data,cb):
  5094. self._data = data
  5095. self._cb = cb
  5096. def cb(self,event):
  5097. #print(self,event)
  5098. self._cb(event,self._data)
  5099. class GUI_menu():
  5100. def __init__(self,root,data,title="tilte",width=800):
  5101. global tk
  5102. self.data = data
  5103. self.data2 = {}
  5104. self.frame = tk.Frame(root,bg="black",width=width)
  5105. self.frame.pack(fill=tk.BOTH, side=tk.LEFT)
  5106. r=0
  5107. c=0
  5108. i=1
  5109. self.b = tk.Label(self.frame,bg="lightblue", text="MAIN:MENU",width=8,height=1)
  5110. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  5111. r+=1
  5112. for row in data:
  5113. #print(i)
  5114. #row = data[i]
  5115. self.b = tk.Button(self.frame,bg="lightgrey", text=row["text"],width=8,height=2)
  5116. self.b.bind("<Button>",BEvent({"NR":i,"text":row["text"]},self.callback).cb)
  5117. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  5118. row["elem"] = self.b
  5119. self.data2[row["text"]] = row
  5120. r+=1
  5121. i+=1
  5122. self.frame.pack()
  5123. def callback(self,event,data={}):
  5124. print("callback543",self,event,data)
  5125. window_manager.top(data["text"])# = WindowManager()
  5126. def update(self,button,text):
  5127. #print(self,button,text)
  5128. for k in self.data2:
  5129. v=self.data2[k]
  5130. #print(self,k,v)
  5131. if button == k:
  5132. v["elem"]["text"] = k+"\n"+text
  5133. def config(self,button,attr,value):
  5134. #print("config",self,button,attr,value)
  5135. for k in self.data2:
  5136. v=self.data2[k]
  5137. #print(self,k,v)
  5138. if button == k:
  5139. #print(dir(v["elem"]))
  5140. if attr == "bg":
  5141. if value == "":
  5142. value = "lightgrey"
  5143. v["elem"][attr] = str(value)
  5144. if attr == "activebackground":
  5145. if value == "":
  5146. value = "lightgrey"
  5147. v["elem"][attr] = str(value)
  5148. lf_nr = 0
  5149. from tkinter import PhotoImage
  5150. _shift_key = 0
  5151. class GUIWindow():
  5152. def __init__(self,title="tilte",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1):
  5153. global lf_nr
  5154. #ico_path="/opt/LibreLight/Xdesk/icon/"
  5155. ico_path="./icon/"
  5156. self.cb = cb
  5157. if master:
  5158. self.tk = tkinter.Tk()
  5159. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  5160. self.tk.withdraw() # do not draw
  5161. self.tk.resizable(resize,resize)
  5162. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  5163. print(defaultFont)
  5164. defaultFont.configure(family="FreeSans",
  5165. size=10,
  5166. weight="bold")
  5167. #self.tk.option_add("*Font", FontBold)
  5168. # MAIN MENUE
  5169. try:
  5170. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png"))
  5171. except Exception as e:
  5172. print("Exception GUIWindow.__init__",e)
  5173. else:
  5174. # addtional WINDOW
  5175. self.tk = tkinter.Toplevel()
  5176. self.tk.iconify()
  5177. #self.tk.withdraw() # do not draw
  5178. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  5179. self.tk.resizable(resize,resize)
  5180. try:
  5181. if "COLORPICKER" in title:
  5182. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png"))
  5183. elif "ENCODER" in title:
  5184. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png"))
  5185. elif "EXEC" in title:
  5186. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  5187. elif "FX" in title:
  5188. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png"))
  5189. else:
  5190. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  5191. except Exception as e:
  5192. print("Exception on load window icon",title)
  5193. print("Exception:",e)
  5194. #time.sleep(3)
  5195. self.tk.deiconify()
  5196. self.tk["bg"] = "black"
  5197. self.tk.bind("<Button>",self.callback)
  5198. self.tk.bind("<Key>",self.callback)
  5199. self.tk.bind("<KeyRelease>",self.callback)
  5200. self.tk.title(""+str(title)+" "+str(lf_nr)+":"+str(rnd_id))
  5201. lf_nr+=1
  5202. #self.tk.geometry("270x600+0+65")
  5203. geo ="{}x{}".format(width,height)
  5204. if left is not None:
  5205. geo += "+{}".format(left)
  5206. if top is not None:
  5207. geo += "+{}".format(top)
  5208. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  5209. self.tk.geometry(geo)
  5210. self.show()
  5211. def update_idle_task(self):
  5212. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  5213. pass
  5214. def close_app_win(self,event=None):
  5215. print("close_app_win",self,event)
  5216. if exit:
  5217. save_window_position()
  5218. self.tk.destroy()
  5219. try:
  5220. self.cb("<exit>").cb()
  5221. except Exception as e:
  5222. print("EXCETPION close_app",e)
  5223. def title(self,title=None):
  5224. if title is None:
  5225. return self.tk.title()
  5226. else:
  5227. #return self.tk.title(title)
  5228. return self.tk.title(""+str(title)+" "+str(lf_nr)+":"+str(rnd_id))
  5229. def show(self):
  5230. self.tk.deiconify()
  5231. pass
  5232. def mainloop(self):
  5233. #save_window_position_loop() #like autosave
  5234. try:
  5235. self.tk.mainloop()
  5236. finally:
  5237. self.tk.quit()
  5238. def callback(self,event,data={}):#value=255):
  5239. global _global_short_key
  5240. #time.sleep(0.1)
  5241. if not _global_short_key:
  5242. #cprint("<GLOBAL-GUI-EVENT-DISABLED>",event,color="red")
  5243. return 1
  5244. global _shift_key
  5245. #cprint("<GUI>",event,color="yellow")
  5246. #cprint("<GUI>",event.state,data,[event.type],color="yellow")
  5247. value = 255
  5248. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  5249. value = 0
  5250. if "keysym" in dir(event):
  5251. if "Escape" == event.keysym:
  5252. FIXTURES.clear()
  5253. modes.val("ESC",1)
  5254. master.refresh_fix()
  5255. elif event.keysym in ["Shift_L","Shift_R"]:
  5256. #cprint(event.type)
  5257. if "KeyRelease" in str(event.type) or str(event.type) in ["3"]:
  5258. _shift_key = 0
  5259. else:
  5260. _shift_key = 1
  5261. #cprint("SHIFT_KEY",_shift_key,"??????????")
  5262. #cprint("SHIFT_KEY",_shift_key,"??????????")
  5263. global _ENCODER_WINDOW
  5264. if _shift_key:
  5265. _ENCODER_WINDOW.title("SHIFT/FINE ")
  5266. else:
  5267. _ENCODER_WINDOW.title("ENCODER")
  5268. elif event.keysym in "ebfclrms" and value:
  5269. if "e" == event.keysym:
  5270. modes.val("EDIT",1)
  5271. elif "b" == event.keysym:
  5272. modes.val("BLIND",1)
  5273. elif "f" == event.keysym:
  5274. modes.val("FLASH",1)
  5275. elif "c" == event.keysym:
  5276. modes.val("CFG-BTN",1)
  5277. elif "l" == event.keysym:
  5278. modes.val("LABEL",1)
  5279. elif "r" == event.keysym:
  5280. modes.val("REC",1)
  5281. elif "m" == event.keysym:
  5282. x=modes.val("MOVE",1)
  5283. if not x:
  5284. PRESETS.clear_move()
  5285. elif "s" == event.keysym:
  5286. modes.val("SELECT",1)
  5287. elif event.keysym in ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]:
  5288. nr = int( event.keysym[1:]) # F:1-12
  5289. nr = nr-1+81
  5290. cprint("F-KEY",value,nr,event.keysym)
  5291. #print(event)
  5292. master.preset_go(nr-1,xfade=None,val=value)
  5293. elif event.keysym in ["1","2","3","4","5","6","7","8","9","0"]:
  5294. nr = int( event.keysym)
  5295. if nr == 0:
  5296. nr = 10
  5297. nr = nr-1+161
  5298. cprint("NUM-KEY",value,nr)
  5299. master.preset_go(nr-1,xfade=None,val=value)
  5300. elif "End" == event.keysym:
  5301. FIXTURES.fx_off("all")
  5302. CONSOLE.fx_off("all")
  5303. CONSOLE.flash_off("all")
  5304. elif "Delete" == event.keysym:
  5305. #PRESETS.delete(nr)
  5306. if value:
  5307. modes.val("DEL",1)
  5308. class WindowManager():
  5309. def __init__(self):
  5310. self.windows = {}
  5311. self.obj = {}
  5312. self.nr= 0
  5313. self.first=""
  5314. def new(self,w,name="",obj=None):
  5315. if not self.first:
  5316. if name:
  5317. self.first = name
  5318. else:
  5319. self.first = str(self.nr)
  5320. w.tk.state(newstate='normal')
  5321. w.tk.attributes('-topmost',True)
  5322. if name:
  5323. self.windows[str(name)] = w
  5324. self.obj[str(name)] = obj
  5325. else:
  5326. self.windows[str(self.nr)] = w
  5327. self.obj[str(self.nr)] = obj
  5328. self.nr+=1
  5329. #w.show()
  5330. def mainloop(self):
  5331. self.windows[self.first].mainloop()
  5332. def get(self,name):
  5333. print(self,".get(name) =",name)
  5334. name = str(name)
  5335. if name in self.windows:
  5336. out = self.windows[name]
  5337. print(out)
  5338. return out
  5339. def get_obj(self,name):
  5340. #print(self,".get(name) =",name)
  5341. name = str(name)
  5342. if name in self.windows:
  5343. out = self.obj[name]
  5344. #print(out)
  5345. return out
  5346. def top(self,name):
  5347. name = str(name)
  5348. if name in self.windows:
  5349. self.windows[name].tk.state(newstate='normal')
  5350. self.windows[name].tk.attributes('-topmost',True)
  5351. self.windows[name].tk.attributes('-topmost',False)
  5352. self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  5353. #print("redraw",name)
  5354. #if name == "PATCH":
  5355. # gui_patch.draw()
  5356. #if name == "DIMMER":
  5357. # gui_fix.draw()
  5358. if name == "EXEC":
  5359. master._refresh_exec()
  5360. self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  5361. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  5362. else:
  5363. print(name,"not in self.windows",self.windows.keys())
  5364. class Console():
  5365. def __init__(self):
  5366. pass
  5367. def flash_off(self,fix):
  5368. pass#client.send("df0:alloff:::,")
  5369. def fx_off(self,fix):
  5370. cprint("Console.fx_off()",fix)
  5371. if not fix or fix == "all":
  5372. #client.send("fx0:alloff:,fxf:alloff:,")
  5373. #client.send("df0:alloff:::,")
  5374. j = []
  5375. if 0:
  5376. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  5377. j.append(jdata)
  5378. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  5379. j.append(jdata)
  5380. else:
  5381. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  5382. j.append(jdata)
  5383. jclient_send(j)
  5384. return 0
  5385. def test_1():
  5386. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  5387. pass
  5388. window_manager = WindowManager()
  5389. CONSOLE = Console()
  5390. PRESETS = Presets()
  5391. FIXTURES = Fixtures()
  5392. def LOAD_SHOW():
  5393. PRESETS.load_presets()
  5394. FIXTURES.load_patch()
  5395. #draw_enc(gui,root2)
  5396. #master._refresh_fix()
  5397. #master._refresh_exec()
  5398. LOAD_SHOW()
  5399. master = GUI()
  5400. class Refresher():
  5401. def __init__(self):
  5402. self.time = time.time()+1
  5403. def reset(self):
  5404. self.time = time.time()+.1
  5405. def refresh(self):
  5406. if time.time() > self.time:
  5407. if time.time() < self.time+2:
  5408. #self.time = time.time()+1
  5409. self._refresh()
  5410. def _refresh(self):
  5411. master._refresh_fix()
  5412. master._refresh_exec()
  5413. def loop(self,args={}):
  5414. while 1:
  5415. try:
  5416. self.refresh()
  5417. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  5418. except Exception as e:print("loop exc",e)
  5419. time.sleep(0.2)
  5420. print("main",__name__)
  5421. __run_main = 0
  5422. if __name__ == "__main__":
  5423. __run_main = 1
  5424. else:
  5425. import __main__
  5426. if "unittest" not in dir(__main__):
  5427. __run_main = 1
  5428. refresher = Refresher()
  5429. if __run_main:
  5430. print("main")
  5431. thread.start_new_thread(refresher.loop,())
  5432. TOP = _POS_TOP + 15
  5433. L0 = _POS_LEFT
  5434. L1 = _POS_LEFT + 95
  5435. L2 = _POS_LEFT + 920
  5436. W1 = 810
  5437. H1 = 550
  5438. HTB = 23 # hight of the titlebar from window manager
  5439. w = GUIWindow("MAIN",master=1,width=85,height=H1//2,left=L0,top=TOP,resize=0)
  5440. gui_menu_gui = w
  5441. data = []
  5442. #data.append({"text":"COMMAND"})
  5443. #data.append({"text":"CONFIG"})
  5444. data.append({"text":"PATCH"})
  5445. data.append({"text":"DIMMER"})
  5446. data.append({"text":"FIXTURES"})
  5447. data.append({"text":"EXEC"})
  5448. data.append({"text":"EXEC-WING"})
  5449. gui_menu = GUI_menu(w.tk,data)
  5450. window_manager.new(w)
  5451. name="EXEC"
  5452. w = GUIWindow(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  5453. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  5454. #frame_exe = w.tk
  5455. draw_preset(master,w1)#w.tk)
  5456. window_manager.new(w,name)
  5457. name="CONFIG"
  5458. w = GUIWindow(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  5459. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  5460. #frame_exe = w.tk
  5461. #draw_preset(master,w1)#w.tk)
  5462. window_manager.new(w,name)
  5463. name="DIMMER"
  5464. w = GUIWindow(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  5465. w2 = ScrollFrame(w.tk,width=W1,height=H1)
  5466. #frame_dim = w1 # w.tk
  5467. #master.draw_dim(w1.tk)
  5468. window_manager.new(w,name)
  5469. name="FIXTURES"
  5470. w = GUIWindow(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  5471. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  5472. #frame_fix = w1 #w.tk
  5473. #draw_fix(master,w1,w2)#.tk)
  5474. gui_fix = GUI_FIX(master,w1,w2)
  5475. gui_fix.draw()
  5476. window_manager.new(w,name)
  5477. name="FIXTURE-EDITOR"
  5478. w = GUIWindow(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  5479. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  5480. data=[]
  5481. for i in range((24+12)*15):
  5482. data.append({"text"+str(i):"test"})
  5483. GUI_FaderLayout(w1,data)
  5484. window_manager.new(w,name)
  5485. name="MASTER-WING"
  5486. #w = GUIWindow(name,master=0,width=730,height=205,left=L1-80,top=TOP+H1-200)
  5487. w = GUIWindow(name,master=0,width=75,height=405,left=L0,top=TOP+H1-220)
  5488. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  5489. w1 = tk.Frame(w.tk,width=W1,height=H1)
  5490. w1.pack()
  5491. data=[]
  5492. for i in range(2):
  5493. data.append({"MASTER"+str(i):"MASTER"})
  5494. GUI_MasterWingLayout(w1,data)
  5495. window_manager.new(w,name)
  5496. name="EXEC-WING"
  5497. #w = GUIWindow(name,master=0,width=730,height=205,left=L1-80,top=TOP+H1-200)
  5498. w = GUIWindow(name,master=0,width=600,height=415,left=L1,top=TOP+H1+HTB*2)
  5499. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  5500. w1 = tk.Frame(w.tk,width=W1,height=H1)
  5501. w1.pack()
  5502. data=[]
  5503. for i in range(10*3):
  5504. data.append({"EXEC"+str(i):"EXEC"})
  5505. obj=GUI_ExecWingLayout(w1,data)
  5506. window_manager.new(w,name,obj)
  5507. name="ENCODER"
  5508. w = GUIWindow(name,master=0,width=620,height=113,left=L0+710,top=TOP+H1+15+HTB*2)
  5509. _ENCODER_WINDOW = w
  5510. draw_enc(master,w.tk)#Xroot)
  5511. window_manager.new(w,name)
  5512. #name="REMOTE-CONTROL"
  5513. #w = GUIWindow(name,master=0,width=220,height=113,left=L0+710,top=TOP+H1+HTB*2+123)
  5514. #_ENCODER_WINDOW = w
  5515. #draw_enc(master,w.tk)#Xroot)
  5516. name = "SETUP"
  5517. w = GUIWindow(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP,resize=0)
  5518. w.tk.title("SETUP SHOW:"+master.base.show_name)
  5519. draw_setup(master,w.tk)
  5520. window_manager.new(w,name)
  5521. name = "COMMAND"
  5522. w = GUIWindow(name,master=0,width=415,height=130,left=L1+10+W1,top=TOP+81,resize=0)#+96)
  5523. draw_command(master,w.tk)
  5524. window_manager.new(w,name)
  5525. name = "LIVE"
  5526. w = GUIWindow(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP+235,resize=0)#250)
  5527. draw_live(master,w.tk)
  5528. window_manager.new(w,name)
  5529. name = "CLOCK"
  5530. w = GUIWindow(name,master=0,width=335,height=102,left=L1+10+W1+80,top=TOP+H1+HTB+160,resize=0)#250)
  5531. draw_clock(master,w.tk)
  5532. window_manager.new(w,name)
  5533. name="FX"
  5534. w = GUIWindow(name,master=0,width=415,height=297,left=L1+10+W1,top=TOP+302,resize=0)#317)
  5535. #frame_fx = w.tk
  5536. draw_fx(master,w.tk)
  5537. window_manager.new(w,name)
  5538. name="PATCH"
  5539. w = GUIWindow(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  5540. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  5541. main_preset_frame = w1
  5542. gui_patch = GUI_PATCH(master,main_preset_frame)
  5543. gui_patch.draw()
  5544. window_manager.new(w,name)
  5545. #LibreLightDesk
  5546. name="COLORPICKER"
  5547. w = GUIWindow(name,master=0,width=600,height=113,left=L1+5,top=TOP+5+HTB*2+H1)
  5548. draw_colorpicker(master,w.tk)
  5549. window_manager.new(w,name)
  5550. name="TableA"
  5551. w = GUIWindow(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  5552. space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  5553. x=TableFrame(root=w.tk)#,left=80,top=620)
  5554. w.show()
  5555. data =[]
  5556. for a in range(40):
  5557. data.append(["E","E{}".format(a+1)])
  5558. x.draw(data=data,head=["E","C"],config=[12,5,5])
  5559. w=x.bframe
  5560. #window_manager.new(w,name)
  5561. #Xroot = tk.Tk()
  5562. #Xroot["bg"] = "black" #white
  5563. #Xroot.title( xtitle+" "+str(rnd_id) )
  5564. #Xroot.geometry("1024x800+130+65")
  5565. master.render()
  5566. window_manager.top("Table")
  5567. #w = frame_fix #GUIWindow("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  5568. window_manager.new(w,name)
  5569. #Set EXEC-FADER SIZE TO 0 on Startup
  5570. for nr in range(10):
  5571. set_exec_fader(nr,0) #,color="#fff")
  5572. load_window_position()
  5573. try:
  5574. #root.mainloop()
  5575. #tk.mainloop()
  5576. window_manager.mainloop()
  5577. finally:
  5578. master.exit()