Update Namespace unavailable in PyCrust

Do you have questions about writing plugins or scripts in Python? Meet the coders here.

Update Namespace unavailable in PyCrust

Postby kkl » Sat Dec 03, 2016 6:31 pm

I use the included PyCrust to see the current value of variables in EG (Is there a better tool?). Many of the menu items are grayed out, including Update Namespace. So, when EG changes, I have to exit PyCrust and start a new session to see the changed variables. Am I missing something about how to do this efficiently?
kkl
Experienced User
 
Posts: 297
Joined: Wed May 04, 2011 9:32 pm

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Sun Dec 04, 2016 1:59 am

something could be made up quite easily. because all of the global variables are stored in eg.Bunch all we would have to do is to make a simple dialog to display all the variable names and their attributes and this can be populated by reading the eg.globals.__dict__ and all of the variables would be updated if create a __setattr__ method for eg.globals.

would you also like to see what the last function called for the variable is??? I can do that as well.

this would actually be a really good addition to any future releases of EG. and make it so that a global variable can be created and deleted as well from the dialog. this would be a good means to manage them.
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kkl » Sun Dec 04, 2016 5:13 pm

I'll leave that proposal to the programmers here who would know much better than me.
kkl
Experienced User
 
Posts: 297
Joined: Wed May 04, 2011 9:32 pm

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Mon Dec 05, 2016 6:08 am

I have most of it done. working on the gui for it now. maybe i will finish up tonight,
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Tue Dec 06, 2016 5:28 pm

OK. this is very much a prototype. There are a couple of issues that i am aware of.

One if you have to double right click the variable to bring up the popup menu for a variable.

I have set a mean in place to "nest" a global for organization. so if you had a global like this.

eg.globals.bedroomLightsCeiling
eg.globals.bedroomLightsWall


you could do this instead. grouping globals together

eg.globals.Bedroom.Lights.ceiling
eg.globals.Bedroom.Lights.wall

the 2 big uses
1: organizaton
2: i set up the class to be an iterator. meaning it can be used in a for loop to get the variable name and value. fo if you wanted to read all of the variables for a given group. or set all the values for a given group.
Example:

say you have a global that points to an action for set a light level, and you name the variable the same as what you would use in an action to set the lights.

set the globals
Code: Select all
eg.globals.Bedroom.Lights.ActionCall = eg.plugins.SomeLightingController.SetLightLevel
eg.globals.Bedroom.Lights.ceiling = ['BedroomCeiling', 40]
eg.globals.Bedroom.Lights.wall = ['BedroomWall', 10]


later on you call this python script to change the levels of the lights in the room
Code: Select all
actionCall = eg.globals.Bedroom.Lights.ActionCall
for key, value in eg.globals.Bedroom.Lights:
    if key != 'ActionCall':
        deviceName, level = value
        actionCall(deviceName, level)
        # or you could just use actionCall(*value) for simplified code, but as an example i wanted to key it out


and this would set the levels to 40 and 10 for the respected device. now doing this for one or 2 things wouldn't make sense but if you had 40 items. this would reduce code greatly.


but the 2nd problem is. and i hope someone can help me on this.

is that when the plugin goes and looks at all the variables in eg.globals. if the variable is one of these nested classes it is supposed to add it as a tree Item. but it doesn't.. maybe someone could take a look see and figure out why. i have been messing with it for 2 days now. and i cannot get it to add the tree item.

the plugin is attached. and i will post it in the plugins section as soon as i get the thing operating at 100%
Attachments
GlobalMonitor.egplugin
(6.57 KiB) Downloaded 12 times
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kkl » Tue Dec 06, 2016 7:31 pm

I'd love to give it a try, but GlobalMonitor.egplugin is hieroglyphics. What do I do with it?

Will this also check non-eg.globals variables? Thanks.
kkl
Experienced User
 
Posts: 297
Joined: Wed May 04, 2011 9:32 pm

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Tue Dec 06, 2016 8:43 pm

I did not design it to check anything other then eg.global variables because the way EG was designed that's the only variables a "normal" user should be setting. if you want it to do more i can have it do that but what i would do is make a hidden action you can enter the module or class name into and it will launch another thread to scan those. but I will not be able to have it show what the last class was that did something with the variable. the eg.Bunch (eg.globals) was easy to do this with because all that was coded in was it updating __dict__. so for me to move everything to a new class that had all the monitoring code in place was easy.


.egplugin

just double click the file and away it goes. no need to restart eg. it will make the folders and files and install the plugin where it needs to be.

it will place the plugin into the c:\programdata\eventghost\plugins folder. not in the install directory folder
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Tue Dec 06, 2016 8:53 pm

here is another example of using the iterator feature. in this one if you make the variable name the same as the actual device on the controller that can be used instead of setting a list


set the globals
Code: Select all
eg.globals.Bedroom.Lights.Bedroom_Ceiling = 40
eg.globals.Bedroom.Lights.Bedroom_Wall = 10


later on you call this python script to change the levels of the lights in the room
Code: Select all
for deviceName, level in eg.globals.Bedroom.Lights:
         eg.plugins.SomeLightingController.SetLightLevel(deviceName, level)


and this would set the levels to 40 and 10 for the respected device.

and if you wanted to set the values of the variables and you know what variable names are stored. the iterator sorts them alphabetically so if you do this


set the globals
Code: Select all
eg.globals.Bedroom.Lights.Bedroom_Ceiling = 40
eg.globals.Bedroom.Lights.Bedroom_Wall = 10


Code: Select all
lightLevel = [100, 50]
for deviceName, level in eg.globals.Bedroom.Lights:
         setattr(deviceName, lightLevel.pop(0))


the above code will change the Bedroom_Ceiling to 100 and the Bedroom_Wall to 50
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kkl » Wed Dec 07, 2016 1:11 am

kgschlosser wrote:I did not design it to check anything other then eg.global variables because the way EG was designed that's the only variables a "normal" user should be setting. if you want it to do more i can have it do that but what i would do is make a hidden action you can enter the module or class name into and it will launch another thread to scan those. but I will not be able to have it show what the last class was that did something with the variable. the eg.Bunch (eg.globals) was easy to do this with because all that was coded in was it updating __dict__. so for me to move everything to a new class that had all the monitoring code in place was easy.


I didn't get the memo when I started using EG, so I just used regular variable names when I didn't need to pass values into a script. Sounds like it will be much easier for me to change my variable names than for you to program it.

kgschlosser wrote:.egplugin

just double click the file and away it goes. no need to restart eg. it will make the folders and files and install the plugin where it needs to be.

it will place the plugin into the c:\programdata\eventghost\plugins folder. not in the install directory folder


Wait...what? That's some kind of voodoo magic you're doing there. Everyone needs to make it that easy. :D There is a problem though when I try to add the plug-in. It crashes EG:
Capture6.JPG


I thought maybe there was a permissions issue, so I tried "Take Ownership" of the relevant directory and also tried moving the plug-in to C:\Program Files (x86)\EventGhost\plugins. Neither of those worked. The error appears right after __init.pyc__ is created and the add to configuration screen opens.
kkl
Experienced User
 
Posts: 297
Joined: Wed May 04, 2011 9:32 pm

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Wed Dec 07, 2016 4:29 am

yep voodoo.. it worked so well it crashed EG

LOL

i will see if it does the same on my end. it might. who knows.
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Wed Dec 07, 2016 4:32 am

now it installed correctly. you just can't add it????
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Wed Dec 07, 2016 4:33 am

it installed and added properly on mine. what version of EG are you running????


***edit***
Never mind.

it works with .5 but not .4 and it is not throwing any errors either. and i really can't think of anything that has changed in how a plugin loads or possibly how the config dialog loads that would crash it..


but at any rate. it works with EG .5 beta 4.
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Wed Dec 07, 2016 11:52 am

ok i have it sorted. it now runs in EG .4 and eg .5 still the original 2 problems. the menu click thing i am not concerned about. the issue with the nested globals is annoying.


what a pain it was getting this thing to play nice nice with the 2 different versions of eg. the biggest issue was getting it to close properly without hanging. and because the wx versions were different that produced it's own complications.

and just when i thought i get it all done. pow! the menu's don't work. oye!

everything but the double right click and it now showing nested variables. the only 2 issues i could find. there are probably more i am sure. but i didn't stumble across them

here it is tho
Attachments
GlobalMonitor.egplugin
(7.26 KiB) Downloaded 14 times
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Update Namespace unavailable in PyCrust

Postby kkl » Wed Dec 07, 2016 8:34 pm

Hmmm. Well, the prior error is resolved, but there is no longer the option to add actions to the configuration tree when adding the plug-in. There also doesn't appear to be any option to add actions manually; nothing shows up in the list of choices:
Capture7.JPG

EG also hangs when trying to exit if the GlobalMonitor plugin is loaded. Isn't it axiomatic in programming that if you think something is going to be easy, well...maybe not. :P
kkl
Experienced User
 
Posts: 297
Joined: Wed May 04, 2011 9:32 pm

Re: Update Namespace unavailable in PyCrust

Postby kgschlosser » Wed Dec 07, 2016 10:52 pm

open yer eyeballs f00

funny.png


just because it's a plugin doesn't mean it has to have any actions to do something.

all the fun stuff is in the menus. but it's just like using eg.globals as usual. just some niceties and convenience things added


and the hanging on close.. if you could do me a favor and run EG from a command line with -debug after it..


then close EG

and navigate to you Users\SOMEUSER\appdata\roaming\eventghost folder and attach the log.txt to a forum post. or send it to me in a pm if you think it may have personal stuff in it (it shouldn't but who knows)
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1254
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Next

Return to Coding Corner

Who is online

Users browsing this forum: No registered users and 1 guest