Adding SleepMode Some error in eg.scheduler.CancelTask

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Adding SleepMode Some error in eg.scheduler.CancelTask

Post by Pako » Thu Jun 16, 2011 6:09 pm

altainta wrote:Sorry but still not working

The Main macro

Code: Select all

    import eg
    xyz = "SleepNow"
    def SleepMode(myArgument):
        eg.TriggerEvent(xyz, repr(myArgument))

    task = eg.scheduler.AddTask(10, SleepMode, xyz)
The cancel Sleep Mode Macro

Code: Select all

    <?xml version="1.0" encoding="UTF-8" ?>
    <EventGhost Version="1522">
        <Macro Name="Show OSD: Cancel Sleep Mode">
            <Action>
                EventGhost.ShowOSD(u'Cancel Sleep Mode', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 6, (0, 0), 0, 3.0, False)
            </Action>
            <Action>
                EventGhost.PythonCommand(u'eg.scheduler.CancelTask(task)')
            </Action>
            <Action>
                EventGhost.FlushEvents()
            </Action>
        </Macro>
    </EventGhost>
error

Code: Select all

       
    Traceback (most recent call last):
         Python script "12", line 2, in <module>
           eg.scheduler.CancelTask(task)
    NameError: name 'task' is not defined
altainta
Sorry.
I wanted to delete only a shadow copy.

The solution is simple. You must use:

eg.globals.myTask = eg.scheduler.AddTask(...)
and
eg.scheduler.CancelTask(eg.globals.myTask)

Pako

altainta
Posts: 29
Joined: Sun Nov 28, 2010 5:58 am

Re: Adding SleepMode Some error in eg.scheduler.CancelTask

Post by altainta » Fri Jun 17, 2011 7:38 am

Thank You it is working fien.
Can you tell me where can i learn more about python language (for eventghost) like variable,constant, etc?

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Adding SleepMode Some error in eg.scheduler.CancelTask

Post by Pako » Fri Jun 17, 2011 7:52 am

altainta wrote:Can you tell me where can i learn more about python language (for eventghost) like variable,constant, etc?
Specifically for the EG, here is only what is on this site in the Documentation and Wiki sections. I recommend to study carefully.
An ideal tool for debugging and learning is PyCrust 0.9.8 - The Flakiest Python Shell, which is (in EventGhost) accessible through the menu Help - Python Shell.

Pako

Post Reply