Advanced Plug-in Development Tips & Tricks
Contents
Read Documentation & source code
Use the MediaPortal source code
Read documentation - ?MediaPortalDevelopment
?ClassLibrary
- Utils Project
Using an on-screen keyboard
1 VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
2 if (null == keyboard)
3 return;
4
5 keyboard.Reset();
6 keyboard.Text = strLine;
7 keyboard.DoModal(GetID);
8 if (keyboard.IsConfirmed)
9 {
10 // Do something here. The typed value is stored in "keyboard.Text"
11 }
- Use the following code do display the web keyboard:
1 DialogWebKeyboard keyboard = (DialogWebKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_WEB_KEYBOARD);
2 ...
Activating other window and returning back
1 //Activate new window
2 GUIWindowManager.ActivateWindow(YOUR_TO_BE_ACTIVATED_WINDOW_ID);
3
4 ...
5
6 //Show the previous window (go back)
7 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.
1 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:
1 // Read configuration settings
2 using (Settings reader = new Settings(Config.GetFile(Config.Dir.Config, "mediaportal.xml")))
3 {
4 setting = reader.GetValue("section_name", "setting_name");
5 }
Properties
- You can store and read string properties.
1 // Save a property
2 GUIPropertyManager.SetProperty("#status", "Ready");
3
4 // Read a property value
5 string strUrl = GUIPropertyManager.GetProperty("#urltonavigate");
Dialogs
Message/Error Box
- This is how to present an "OK" dialog (it can be used do display error messages as well":
1 /// <summary>
2 /// Shows the Error Dialog
3 /// </summary>
4 private void ShowErrorDialog(string messsage)
5 {
6 GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
7 if (dlgOK != null)
8 {
9 dlgOK.SetHeading("Error" /* or Message */);
10 dlgOK.SetLine(1, messsage);
11 dlgOK.SetLine(2, "");
12 dlgOK.DoModal(PARENT_WINDOW_ID);
13 }
14 }
Context Menu
- To show a context menu (in the middle of the screen):
1 private int ShowContextMenu()
2 {
3 GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
4 if (dlgMenu != null)
5 {
6 dlgMenu.Reset();
7 dlgMenu.SetHeading("Header");
8 dlgMenu.Add("line 1");
9 dlgMenu.Add("line 2");
10 ...
11 dlgMenu.DoModal(PARENT_WINDOW_ID);
12
13 if (dlgMenu.SelectedLabel == -1) // Nothing was selected
14 return EventAction.Nothing;
15
16 return dlgMenu.SelectedLabel;
17 }
18 }
Unconfirmed Tips & Tricks
Interface for NON-GUI plugins
Found here: http://forum.team-mediaportal.com/interface_non_gui_plugins-t538.html (by Frodo)
1 namespace MediaPortal.GUI.Library
2 {
3 public interface IPlugin
4 {
5 void Start();
6 void Stop();
7 }
8 }
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.
MediaPortal Wiki 