problem in event handling on change of variable value.

sirjee hitechpundir at gmail.com
Mon Aug 3 07:12:15 EDT 2009


On Aug 1, 2:22 pm, sirjee <hitechpun... at gmail.com> wrote:
> hello;
>
> i m facing a problem in handling events on change of value of
> environment variable in a toolCANoe.
>
> class CANoeEvents:
>     def OnChange(self,value):
>         print "value of environment variable has changed"
>     def OnOpen(self,App):
>         print "opening Application"
>
> App_Event = DispatchWithEvents('CANoe.Application',CANoeEvents)
> time.sleep(2)
> App_Event.Open("C:\projectConfig.cfg")  # printd "opening Application"
> and event handled properly.
> .......(now a code file runs in thecanoein which value of
> environment variable called dummy is changed during execution. Just
> like OnOpen; OnChange is defined in specification which should be
> called on change of environment variable.But it is not happening.)
> while (<some condition>):
>                 myenvVar = App_Event.Environment.GetVariable("dummy")
>
> The VB does it very easily and defines a subroutine called :
> Sub myenvVar _OnChange(value)
>    print "value of environment variable has changed"
> End Sub
> //////////////////////////////////////////////////however the
> alternative for subroutine for OnOpen in VB (defined below) works fine
> as shown above in python.
> Sub AppEvent_OnOpen(App)
>         print "opening Application"
> End Sub
>
> for VB; all this stuff is cake work.... object_eventname subroutine
> and done.....what in python?

hi all;

strange !!!!
i got answer to the problem posted by me only.
now I have very good control of CANoe tool from python....
if anybody faces any problem wrt automation of CANoe tool using
python; do contact me.
here actual problem lied in analysing and implementing com heirarchy.
( which is really bit cumbersome)
onChange event is associated with App_Event.Environment.GetVariable
("dummy") object.
So we need to associate separate class with this object and then write
onChange function:


class evtClass:
    def __init__(self):
        print "initializing event class"
    def OnChange(self,value):
            print "value of environment variable changing"

            print "changed value of environment variable is"
            print value


see = App_Event.Environment.GetVariable("dummy")
see_temp=DispatchWithEvents(see,evtClass)

this will solve problem.
So we need to create separate classes for events associated with
separate objects.

regards
sirjee



More information about the Python-list mailing list