help with nongui plugin (1 Viewer)

lar282

Portal Pro
July 11, 2004
414
2
Hi
can somebody help me out?

Gonna create a NONGIU plugin that sends messages to Girder when a specific module is opened in MP. for example
---when MyMovies is opened send message to girder "MyMovies"

Question1: Can I do this in a regular plugin?(Without touching the code of MP
Question2: what should I look for?
OnMessage(GUIMessage message)
or
OnAction(Action action)
Question3: where in the pligin should this check be? In
public Girder_Plugin()
or
public void Start()


Regards

Lasse
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
lar282 said:
Hi
can somebody help me out?

Gonna create a NONGIU plugin that sends messages to Girder when a specific module is opened in MP. for example
---when MyMovies is opened send message to girder "MyMovies"

Question1: Can I do this in a regular plugin?(Without touching the code of MP
Question2: what should I look for?
OnMessage(GUIMessage message)
or
OnAction(Action action)
Question3: where in the pligin should this check be? In
public Girder_Plugin()
or
public void Start()


Regards

Lasse

Well, to get the ID of the current window do this:
Code:
GUIWindowManager.ActiveWindow;

To get messages though, I reckon the best way is to register the plugin on startup with the Messages system by:
Code:
 GUIWindowManager.Receivers += new SendMessageHandler(this.OnThreadMessage);

Then in the same class add this:
Code:
void OnThreadMessage(GUIMessage message)
		{
			switch (message.Message)
			{
				case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT: 
					//Do your code here for sending messages to girder...
                                        //Get the ActiveWindow ID then translate it to text if needed then send it to Girder.
					break;
			}
		}

HTH

Sam
 

lar282

Portal Pro
July 11, 2004
414
2
thanks for the help, but as usuall I can't get it to work. Just trying to get a mess box with the windowid when it gets initialized. code so far



using System.ComponentModel;
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.Player;
using System.IO;
using System.Web;
using MediaPortal.Dialogs;

namespace Girder
{
/// <summary>
/// Summary description for a DVD Play button on the home menu.
/// Created by Shaggy ;-)
/// </summary>
public class Girder_Plugin : System.Windows.Forms.Form, ISetupForm
{
private System.ComponentModel.Container components = null;
public interface IPlugin
{
void Start();
void Stop();
}
public Girder_Plugin()
{
//
GUIWindowManager.Receivers += new SendMessageHandler(this.OnThreadMessage);
System.Windows.Forms.MessageBox.Show ("GUIWindowManager.ActiveWindow"+GUIWindowManager.ActiveWindow);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
public void Start()
{
//
GUIWindowManager.Receivers += new SendMessageHandler(this.OnThreadMessage);
System.Windows.Forms.MessageBox.Show ("GUIWindowManager.ActiveWindow"+GUIWindowManager.ActiveWindow);
}

void OnThreadMessage(GUIMessage message)
{
switch (message.Message)
{
case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT:
int lasse= GUIWindowManager.ActiveWindow;
System.Windows.Forms.MessageBox.Show ("GUIWindowManager.ActiveWindow"+lasse);
//Do your code here for sending messages to girder...
//Get the ActiveWindow ID then translate it to text if needed then send it to Girder.
break;
}
}


protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


public string PluginName()
{
return "Girder Action Plugin";
}

public string Description()
{
return "Call Girder events on specific MP events.";
}

public string Author()
{
return "Shaggy";
}

public void ShowPlugin()
{
ShowDialog();
}
public bool DefaultEnabled()
{
return false;
}
public bool CanEnable()
{
return true;
}

public bool HasSetup()
{
return false;
}
public int GetWindowId()
{
return 1200;
}

/// <summary>
/// If the plugin should have its own button on the home screen then it
/// should return true to this method, otherwise if it should not be on home
/// it should return false
/// </summary>
/// <param name="strButtonText">text the button should have</param>
/// <param name="strButtonImage">image for the button, or empty for default</param>
/// <param name="strButtonImageFocus">image for the button, or empty for default</param>
/// <param name="strPictureImage">subpicture for the button or empty for none</param>
/// <returns>true : plugin needs its own button on home
/// false : plugin does not need its own button on home</returns>
public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
{

strButtonText = "Girder Plugin";
strButtonImage = "";
strButtonImageFocus = "";
strPictureImage = "dvd.png";
return false;
}

private void InitializeComponent()
{
//
// Girder_Plugin
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Girder_Plugin";
this.Load += new System.EventHandler(this.Girder_Plugin_Load);

}

private void Girder_Plugin_Load(object sender, System.EventArgs e)
{

}


//------------------------------------------------------------------------------

}
}
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
You haven't implemented the NON-GUI plugin interface, instead you've defined it again ;-) MP only loads plugins that have implemented the interface.

BTW, because you have the same code in the constructor (public Girder_Plugin()) and the Start method, you might get two messages... Also, I'm not sure if System.Windows.Forms message boxes will show on top of MP (MP does not use windows forms). You can get MP to display a message box but I don't have the code with me right now. When I'm debugging, I'm just writing to the log by:
Code:
Log.Write("write log message");

Anyway, try this:
Code:
thanks for the help, but as usuall I can't get it to work. Just trying to get a mess box with the windowid when it gets initialized. code so far



using System.ComponentModel;
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.Player;
using System.IO;
using System.Web;
using MediaPortal.Dialogs;

namespace Girder
{
/// <summary>
/// Summary description for a DVD Play button on the home menu.
/// Created by Shaggy Wink
/// </summary>
public class Girder_Plugin : System.Windows.Forms.Form, ISetupForm, IPlugin
{
private System.ComponentModel.Container components = null;

public Girder_Plugin()
{
//
GUIWindowManager.Receivers += new SendMessageHandler(this.OnThreadMessage);
System.Windows.Forms.MessageBox.Show ("GUIWindowManager.ActiveWindow"+GUIWindowManager.ActiveWindow);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
public void Start()
{
//
GUIWindowManager.Receivers += new SendMessageHandler(this.OnThreadMessage);
System.Windows.Forms.MessageBox.Show ("GUIWindowManager.ActiveWindow"+GUIWindowManager.ActiveWindow);
}

void OnThreadMessage(GUIMessage message)
{
switch (message.Message)
{
case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT:
int lasse= GUIWindowManager.ActiveWindow;
System.Windows.Forms.MessageBox.Show ("GUIWindowManager.ActiveWindow"+lasse);
//Do your code here for sending messages to girder...
//Get the ActiveWindow ID then translate it to text if needed then send it to Girder.
break;
}
}


protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


public string PluginName()
{
return "Girder Action Plugin";
}

public string Description()
{
return "Call Girder events on specific MP events.";
}

public string Author()
{
return "Shaggy";
}

public void ShowPlugin()
{
ShowDialog();
}
public bool DefaultEnabled()
{
return false;
}
public bool CanEnable()
{
return true;
}

public bool HasSetup()
{
return false;
}
public int GetWindowId()
{
return 1200;
}

/// <summary>
/// If the plugin should have its own button on the home screen then it
/// should return true to this method, otherwise if it should not be on home
/// it should return false
/// </summary>
/// <param name="strButtonText">text the button should have</param>
/// <param name="strButtonImage">image for the button, or empty for default</param>
/// <param name="strButtonImageFocus">image for the button, or empty for default</param>
/// <param name="strPictureImage">subpicture for the button or empty for none</param>
/// <returns>true : plugin needs its own button on home
/// false : plugin does not need its own button on home</returns>
public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
{

strButtonText = "Girder Plugin";
strButtonImage = "";
strButtonImageFocus = "";
strPictureImage = "dvd.png";
return false;
}

private void InitializeComponent()
{
//
// Girder_Plugin
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Girder_Plugin";
this.Load += new System.EventHandler(this.Girder_Plugin_Load);

}

private void Girder_Plugin_Load(object sender, System.EventArgs e)
{

}


//------------------------------------------------------------------------------

}
}

HTH

Sam
 

lar282

Portal Pro
July 11, 2004
414
2
Tack

Thanks for the help. I'm sure this is basic stuff for u, so I really appriciate it. I got it to work but the problem was (is) that the windows init doesn't work. Tried music playback instead and that works? Must be something special here with WINDOWS_INIT. Do u know??
I also tried to add ALL messages and write to the log but when a Windows is opened NO message is sent.

private void OnThreadMessage(GUIMessage message)
{
// string lasse=
switch (message.Message)
{
case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT:
//int lasse= GUIWindowManager.ActiveWindow;
Log.Write("Windows just opened.This comes from switch message");
break;

case GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED:
Log.Write("Playback started.This comes from switch message");
break;

}
Log.Write("alla GUIMess" + (message.Message));
}



log file

2005-01-11 09:22:40 window:MediaPortal.GUI.Music.GUIMusicFiles init
2005-01-11 09:22:40 open folderdatabase
2005-01-11 09:22:40 texturemanager:added:skin\mce\media\defaultFolderBack.png total:53 mem left:307232768
2005-01-11 09:22:42 key:13 0xD
2005-01-11 09:22:42 alla GUIMessGUI_MSG_CLICKED
2005-01-11 09:22:42 texturemanager:added:skin\mce\media\defaultHardDisk.png total:54 mem left:307232768
2005-01-11 09:22:42 texturemanager:added:skin\mce\media\defaultDVDRom.png total:55 mem left:307232768
2005-01-11 09:22:42 texturemanager:added:skin\mce\media\defaultFolder.png total:56 mem left:307232768
2005-01-11 09:22:43 key:13 0xD
2005-01-11 09:22:43 alla GUIMessGUI_MSG_CLICKED
2005-01-11 09:22:45 key:121 0x79
2005-01-11 09:22:45 alla GUIMessGUI_MSG_CLICKED
2005-01-11 09:22:45 Player.Play(F:\mp3\Aerosmith\-Aerosmith-Young Lust The Anthology\Cd1\01 - Let The Music Do The Talking.mp3)
2005-01-11 09:22:45 Loading external players plugins
2005-01-11 09:22:45 found plugin:MediaPortal.FoobarPlugin.FoobarPlugin in plugins\ExternalPlayers\ExternalPlayers.dll
2005-01-11 09:22:45 player:Foobar2000. author: int_20h
2005-01-11 09:22:45 found plugin:MediaPortal.WinampPlayer.WinampPlugin in plugins\ExternalPlayers\ExternalPlayers.dll
2005-01-11 09:22:45 player:Winamp. author: int_20h
2005-01-11 09:22:45 AudioPlayerVMR7.play F:\mp3\Aerosmith\-Aerosmith-Young Lust The Anthology\Cd1\01 - Let The Music Do The Talking.mp3
2005-01-11 09:22:46 Playback started.This comes from switch message
2005-01-11 09:22:46 alla GUIMessGUI_MSG_PLAYBACK_STARTED

//Lasse
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
Whoops, sorry. I just thought the situation though and realised my stupid mistake. If MP sent the INIT message as a global message, then all the windows would initialise (not good ;-) ). Instead MP sends it only to the window that needs opening.

I have two suggestions:
In the code you have now, tell your plugin to write to the log every message that it receives (Log.Write("GirderPlugin: received message: " + message.Message); ). Put this before the switch line. Go into MP, open and close a few windows and see if there are any messages sent that are useful.

The other suggestion is to maintain a timer which constantly checks the GUIWindowManager.ActiveWindow value - if it changes, do something. This is how Power Scheduler works. It seems clumsy, but it might be the only way.

Any one else got any suggestions?

Sam
 

lar282

Portal Pro
July 11, 2004
414
2
samuel337 said:
Whoops, sorry. I just thought the situation though and realised my stupid mistake. If MP sent the INIT message as a global message, then all the windows would initialise (not good ;-) ). Instead MP sends it only to the window that needs opening.

I have two suggestions:
In the code you have now, tell your plugin to write to the log every message that it receives (Log.Write("GirderPlugin: received message: " + message.Message); ). Put this before the switch line. Go into MP, open and close a few windows and see if there are any messages sent that are useful.

The other suggestion is to maintain a timer which constantly checks the GUIWindowManager.ActiveWindow value - if it changes, do something. This is how Power Scheduler works. It seems clumsy, but it might be the only way.

Any one else got any suggestions?

Sam

I did that already, changed the post above.

Maybe I can check the player states and tv states, but its clumsy. Hopefully Frodo knows a better way.


//Lasse
 

lar282

Portal Pro
July 11, 2004
414
2
Solution

Talked to the FRODO on the forum and he told me to use

GUIPropertyManager.OnPropertyChanged += new GUIPropertyManager.OnPropertyChangedHandler(this.OnReceivedProperty);


Just wanted other people to now.


//Lasse
 

Users who are viewing this thread

Top Bottom