Page tree


Search

  Wiki Navigation

    Loading...


 Recently Updated


 Latest Releases

 MediaPortal 1.23 
            Releasenews | Download
 MediaPortal 2.2.2
            Releasenews | Download

Purpose

For plugin developers that would like a timed delay between the selection of an action and the execution of the action, this capability offers a visual countdown for the user by displaying the usual wait cursor with a decrementing integer value displayed in the center of the wait cursor.

Description of change

New public methods added to GUIWaitCursor:

public static void ElapsedEvent(int countDownMs, OnWaitCursorElapsed target, object paramObj);
public static void ElapsedEvent(int countDownMs, GUIMessage msg);
public static bool ElapsedEventRunning();

New delegate (used for callback handling):

public delegate void OnWaitCursorElapsed(object paramObj);

Use:

Choose one of:

  1. Select a method that should execute after some time delay. The method you select should have a method signature that matches the delegate method.
  2. Define a GUI message that should be sent after some time delay.

To display the wait cursor with the countdown and have either the delegate method called or the GUI message sent when the count down value reaches zero simply call the appropriate

ElapsedEvent()

method.

ElapsedEvent()

is a non-blocking method (wait cursor spawns a new thread to handle its work). You can test to see if an elapsed event is pending by calling

ElapsedEventRunning()

. Calling

Hide()

hides the wait cursor and prevents (cancels) the event from executing.

The font used by the wait cursor to display the count down values must be defined in the fonts.xml skin file; the font name must be "waitcursor".

The image below shows the wait cursor displayed with a pending event (which will execute in 3 seconds).

Example 1: Call a method

private void OnSomeAction()
    {
      // Stop the wait cursor (kill its thread) in anticipation of a need to restart it.
      if (GUIWaitCursor.ElapsedEventRunning())
      {
        GUIWaitCursor.Hide();
      }

      // Do something

      if (condition)
      {
        // Setup a wait cursor to execute DoAction() after 5 seconds.
        GUIWaitCursor.ElapsedEvent(5000, DoAction, null);
      }
    }

    public void DoAction(object data)
    {
      // Do something
    }

Example 2: Send a message

private void OnSomeAction()
    {
      // Stop the wait cursor (kill its thread) in anticipation of a need to restart it.
      if (GUIWaitCursor.ElapsedEventRunning())
      {
        GUIWaitCursor.Hide();
      }

      // Do something

      if (condition)
      {
        // Setup a wait cursor to send a message after 5 seconds.
        int msgId = 1234;
        GUIMessage msg;
        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_USER, GetID, 0, 0, msgId, 0, null);
        GUIWaitCursor.ElapsedEvent(5000, msg);
      }
    }

    public override bool OnMessage(GUIMessage message)
    {
      if (message.TargetWindowId == GetID)
      {
        // Handle a user message to change some settings.
        if (message.Message == GUIMessage.MessageType.GUI_MSG_USER)
        {
          switch (message.Param1)
          {
            case 1234:
              DoSomething();
              break;
          }
        }
      }
      if (base.OnMessage(message))
      {
        return true;
      }
      return false;
    }

   

 

This page has no comments.