summaryrefslogtreecommitdiff
path: root/docs/examples/vl_isa.py
diff options
context:
space:
mode:
authorpavet2004-09-09 15:33:37 +0000
committerpavet2004-09-09 15:33:37 +0000
commita5803c3a3e49d5d10e017a70c9e94d0545d59a09 (patch)
tree62fb7a35ca46bbefa2eb1a9e4266315ed1ba76de /docs/examples/vl_isa.py
parent23abb4b87c7e40ed259dd02f653516f60e55ade4 (diff)
downloadivycpy-vinit-a5803c3a3e49d5d10e017a70c9e94d0545d59a09.zip
ivycpy-vinit-a5803c3a3e49d5d10e017a70c9e94d0545d59a09.tar.gz
ivycpy-vinit-a5803c3a3e49d5d10e017a70c9e94d0545d59a09.tar.bz2
ivycpy-vinit-a5803c3a3e49d5d10e017a70c9e94d0545d59a09.tar.xz
Initial revision
Diffstat (limited to 'docs/examples/vl_isa.py')
-rwxr-xr-xdocs/examples/vl_isa.py140
1 files changed, 140 insertions, 0 deletions
diff --git a/docs/examples/vl_isa.py b/docs/examples/vl_isa.py
new file mode 100755
index 0000000..89c70fa
--- /dev/null
+++ b/docs/examples/vl_isa.py
@@ -0,0 +1,140 @@
+#!/usr/bin/env python
+""" very light isa hmi mockup
+prog de test infrastructure ivy + mini ihm type isa """
+
+import traceback, time, os, sys, string, getopt
+from Tkinter import *
+from ivycpy import *
+
+APPNAME = "vl_isa"
+
+def lprint(fmt,*arg):
+ print APPNAME + ": " + fmt % arg
+
+def usage(scmd):
+ lpathitem = string.split(scmd,'/')
+ fmt = '''Usage: %s [-h] [-b IVYBUS | --ivybus=IVYBUS] [-n APPNAME | --name=APPNAME]
+where
+\t-h provides the usage message;
+\t-n APPNAME | --name=APPNAME
+\t-b IVYBUS | --ivybus=IVYBUS allow to provide the IVYBUS string in the form
+\t adresse:port eg. 127.255.255.255:2010
+'''
+ print fmt % lpathitem[-1]
+
+def oncxproc(connected):
+ if connected == IvyApplicationDisconnected :
+ lprint("an IvyApplication was Disconnected")
+ else:
+ lprint("an IvyApplication was Connected")
+
+def ondieproc(id):
+ lprint("we ask me to die with id [%d]", id )
+
+class TopLevel(Tk) :
+ __single = 0
+ def __init__(self,appname = "TopLevel"):
+ if TopLevel.__single != 0 :
+ lprint("TopLevel is singleton")
+ sys.exit(1)
+ __single = 1
+ # the object is tk_root
+ Tk.__init__(self)
+ self.appname = appname
+ self.title(self.appname)
+ # Frame contenant heure et bouton quit
+ self.tkFheadpanel = Frame(self)
+ # Label hour
+ self.tkLhour = Label(self.tkFheadpanel,text="hh:mm:ss")
+ self.tkLhour.pack(padx=4 , pady=4 , side = LEFT)
+ # dummy button
+## self.tkBdummy = Button(self.tkFheadpanel,
+## text="dummy", bg='pink')
+## self.tkBdummy.pack(padx=4 , pady=4, side = RIGHT)
+
+ # button quit
+ self.tkBquit = Button(self.tkFheadpanel,
+ text="QUIT", bg='pink', command=self.quit)
+ self.tkBquit.pack(padx=4 , pady=4, side = RIGHT)
+ self.tkFheadpanel.pack(side=TOP)
+
+ # Frame contenant un Label, un Text et un Scroller
+ self.tkFreceive_msg = Frame(self)
+ # label
+ self.tkLreceive_msg = Label(self.tkFreceive_msg, text="flyingonthebus")
+ self.tkLreceive_msg.pack(padx=4 , pady=4,
+ side=TOP, fill = BOTH, expand = YES)
+ # Text
+ self.tkTreceive_msg = Text(self.tkFreceive_msg, height=26, width=50)
+ # Scrollbar
+ self.tkSBreceive_scroller = Scrollbar(
+ self.tkFreceive_msg,
+ command = self.tkTreceive_msg.yview)
+ self.tkTreceive_msg.configure(
+ yscrollcommand = self.tkSBreceive_scroller.set)
+
+ self.tkTreceive_msg.pack(padx=4 , pady=4,
+ side=LEFT, fill = BOTH, expand = YES)
+ self.tkSBreceive_scroller.pack(side=RIGHT, fill = Y)
+ self.tkFreceive_msg.pack(side=BOTTOM, fill = BOTH, expand = YES)
+
+ def add_one_msg(self, smsg) :
+ self.tkTreceive_msg.insert(END, "%s\n" % smsg )
+
+ def onmsgproc(self,*arg) :
+ self.add_one_msg(string.join(arg,""))
+
+ def quit(self):
+ # cleanup action before detroying tk_root
+ lprint("doing IvyStop")
+ IvyStop()
+ lprint("doing destroy" )
+ self.destroy()
+ lprint("after destroy")
+ lprint("done.")
+
+## def ontick(self):
+## lprint("on tick method")
+## IvySendMsg("testtk_tick")
+## self.after(1000,self.ontick)
+
+# main prog
+if __name__ == '__main__':
+ # setting some main variable
+ sivybus = ""
+
+ # getting option
+ try:
+ optlist, left_args = getopt.getopt(sys.argv[1:],'hb:n:', ['ivybus=','name'])
+ except getopt.GetoptError:
+ # print help information and exit:
+ usage(sys.argv[0])
+ sys.exit(2)
+ for o, a in optlist:
+ if o in ("-h", "--help"):
+ usage(sys.argv[0])
+ sys.exit()
+ elif o in ("-b", "--ivybus"):
+ sivybus = a
+ elif o in ("-n","--name"):
+ APPNAME = a
+ if sivybus != "" :
+ sechoivybus = sivybus
+ elif os.environ.has_key("IVYBUS"):
+ sechoivybus = os.environ["IVYBUS"]
+ else:
+ sechoivybus = "ivydefault"
+ lprint("Ivy will broadcast on %s " , sechoivybus)
+
+ # initializing ivy : isreadymsg
+ sisreadymsg = "[%s is ready]" % APPNAME
+ IvyInit(APPNAME, sisreadymsg, 1 , oncxproc, ondieproc )
+ IvyStart(sivybus)
+
+ # initializing top hmi part
+ mytoplevel = TopLevel("%s top window" % APPNAME)
+
+ # doing suited binding
+ IvyBindMsg(mytoplevel.onmsgproc , "(.*)")
+
+ mytoplevel.mainloop()