> Date: Sat, 1 Sep 2012 08:05:45 -0500
> From: bjt...@gmail.com
> To: emc-users@lists.sourceforge.net
> Subject: [Emc-users] Postgui
>
> I'm trying to decipher how to have a postgui hal file with my custom
> GUI. The following snippet I assume does the magic of loading the
> postgui file. Some I understand and some I don't.
>
> if __name__ == "__main__":
> if len(sys.argv) > 2 and sys.argv[1] == '-ini':
> print "ini", sys.argv[2]
> hwg = touchy(sys.argv[2])
> else:
> hwg = touchy()
> res = os.spawnvp(os.P_WAIT, "halcmd", ["halcmd", "-f",
> "touchy.hal"])
> if res: raise SystemExit, res
> # load a postgui file if one is present in the INI file
> postgui_halfile,inifile = touchy.postgui(hwg)
> print "TOUCHY postgui filename:",postgui_halfile
> if postgui_halfile:
> res = os.spawnvp(os.P_WAIT, "halcmd", ["halcmd",
> "-i",inifile,"-f", postgui_halfile])
> if res: raise SystemExit, res
> gtk.main()
>
> The line hwg = touchy(sys.argv[2]) what is that doing?
>
> Also what is postgui_halfile,inifile = touchy.postgui(hwg) doing?
> Somehow it seems that postgui_halfile is being set to > 0 if one is
> found in the ini file but I don't understand how that line does that?
>
> Thanks
> John
If you want to do substitution in the post gui hal file you must tell
halcmd where the ini file is.
Some of the weirdness of this code is because it is outside the touchy class
so you must call methods with the class name rather then using the usual self.
if __name__ == "__main__":
if len(sys.argv) > 2 and sys.argv[1] == '-ini':
print "ini", sys.argv[2]
hwg = touchy(sys.argv[2])
else:
hwg = touchy()
This looks for the a -ini switch that directly specifies an INI path.
else does not specify and INI path
Then it initializes an instance of the touchy class called hwg,
either with the specified INI path or without.
res = os.spawnvp(os.P_WAIT, "halcmd", ["halcmd", "-f",
"touchy.hal"])
if res: raise SystemExit, res
This loads touch.hal file by spawning an instance of halcmd
and letting it do it's thing. no ini substitution is possible.
if there is an error in the hal file touchy exits with error.
# load a postgui file if one is present in the INI file
postgui_halfile,inifile = touchy.postgui(hwg)
print "TOUCHY postgui filename:",postgui_halfile
This calls a method INSIDE the touchy class so instead of self
we use hwg (the instance name we gave it a couple lines ago)
the method postgui() looks for the postgui filename in the INI file
from the config that was started from and returns the postgui file name and
the INI path
if postgui_halfile:
res = os.spawnvp(os.P_WAIT, "halcmd", ["halcmd",
"-i",inifile,"-f", postgui_halfile])
if res: raise SystemExit, res
So here we check to see if there was a postgui file name and if so
we spawn another halcmd to load it. This time we allow INI substitution.
again if there is an error we exit the program with an error message.
gtk.main()
Of course gtk.main() starts monitoring signals from our program.
Hope that helps John!
Chris M
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users