Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

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 »

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 »

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 »

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