Page tree


Search

  Wiki Navigation

    Loading...


 Recently Updated


 Latest Releases

 MediaPortal 1.22 
            Releasenews | Download
 MediaPortal 2 2.2.1 
            Releasenews | Download

Read Documentation & source code

Using an on-screen keyboard

VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
if (null == keyboard)
  return;

keyboard.Reset();
keyboard.Text = strLine;
keyboard.DoModal(GetID);
if (keyboard.IsConfirmed)
{
  // Do something here. The typed value is stored in "keyboard.Text"
}

Use the following code do display the web keyboard:

DialogWebKeyboard keyboard = (DialogWebKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_WEB_KEYBOARD);
...

Activating other window and returning back

//Activate new window
GUIWindowManager.ActivateWindow(YOUR_TO_BE_ACTIVATED_WINDOW_ID);

...

//Show the previous window (go back)
GUIWindowManager.ShowPreviousWindow();
  • FYI: still looking how to transfer data other than strings between the windows. If you know - shoot me a message..
  • See the "properties" or "configuration" tips if you want to transfer strings

Logging

Use class Log for logging. You can log Info, Error, Warn and Debug. There are a lot of different methods for additional formatting.

Log.Info("My plugin: started");

Configuration

Note: you can have as many as you need configuration files. Use common sence - do not create separate file for each setting. Example:

// Read configuration settings
using (Settings reader = new Settings(Config.GetFile(Config.Dir.Config, "mediaportal.xml")))
{
  setting = reader.GetValue("section_name", "setting_name");
}

Properties

You can store and read string properties.

// Save a property
GUIPropertyManager.SetProperty("#status", "Ready");

// Read a property value
string strUrl = GUIPropertyManager.GetProperty("#urltonavigate");

Creating a new element

  • You can dynamically create and render new elements and then access them as if they were in the XML-file.

 

public override void AllocResources()
{
  base.AllocResources();
  mylabel = new GUILabelControl(5678, 999, 300, 400, 200, 100, string.Empty, "This is a new string to render in a label", 0xFFFFFFFF, GUIControl.Alignment.Left, false);
  mylabel.AllocResources();
}

public override void Render(float timePassed)
{
  base.Render(timePassed);
  mylabel.Render(timePassed);
}

Dialogs

Message/Error Box

This is how to present an "OK" dialog (it can be used do display error messages as well":

/// <summary>
   /// Shows the Error Dialog
   /// </summary>
   private void ShowErrorDialog(string messsage)
   {
      GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
      if (dlgOK != null)
      {
         dlgOK.SetHeading("Error" /* or Message */);
         dlgOK.SetLine(1, messsage);
         dlgOK.SetLine(2, "");
         dlgOK.DoModal(PARENT_WINDOW_ID);
      }
   }

Context Menu

To show a context menu (in the middle of the screen):

private int ShowContextMenu()
   {
      GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
      if (dlgMenu != null)
      {
         dlgMenu.Reset();
         dlgMenu.SetHeading("Header");
         dlgMenu.Add("line 1");
         dlgMenu.Add("line 2");
         ...
         dlgMenu.DoModal(PARENT_WINDOW_ID);

         if (dlgMenu.SelectedLabel == -1) // Nothing was selected
            return EventAction.Nothing;

         return dlgMenu.SelectedLabel;
      }
   }

Enum Selection Dialog

To show a selection Dialog for values from a given Enum and returns the selected value. (using generics) T must be of Enum type...

public T ShowEnumSelectionDialog<T>() {
    GUIDialogSelect2 dlgSelect =
        (GUIDialogSelect2)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_SELECT2);
    dlgSelect.Reset();
    dlgSelect.SetHeading("Selection: " + typeof(T).ToString());
    Enum.GetNames(typeof(T)).ToList().ForEach(dlgSelect.Add);
    dlgSelect.DoModal(GUIWindowManager.ActiveWindow);
    try {
        return Enum<T>.Parse(dlgSelect.SelectedLabelText);
    } catch {
        return default (T);
    }
}

 

Helper class for parsing enum value:

public static class Enum<T> {
    public static T Parse(string value) {
        return (T)Enum.Parse(typeof(T), value);
    }
    public static IList<T> GetValues() {
        IList<T> list = new List<T>();
        foreach (object value in Enum.GetValues(typeof(T))) {
            list.Add((T)value);
        }
        return list;
    }
}

 

Usage:

MyEnum myEnumValue = ShowEnumSelectionDialog<MyEnum>();

Unconfirmed Tips & Tricks

Interface for NON-GUI plugins

namespace MediaPortal.GUI.Library
{
  public interface IPlugin
  {
    void Start();
    void Stop();
  }
}

The actual plugin is run from the plugin/process folder, but to get it to show up in the configuration window (and get to the plugins setup screens) you have to have a copy in the plugins/windows folder too.

   

 

This page has no comments.