MyScript (3 Viewers)

Clodo

Portal Pro
July 8, 2005
53
0
Milan, Italy
Plugin Name:MyScript
Current Version/State:1.0 (20/06/2006).
Download : http://www.itazz.net/files/Clodo/MediaPortal/MyScript.zip
Source : http://www.itazz.net/files/Clodo/MediaPortal/MyScript_src.zip
Description: C# "script" without need to build the sources.
Screenshot:

MyScript.gif



Can be useful to add some custom code (cool stuffs, for automatization, for patch, for debug) without the MP sources.
Install Instructions : Extract the zip file to the MAIN MediaPortal directory.

The development of this plugin is started from this discussion thread:
http://nolanparty.com/mediaportal.sourceforge.net/phpBB2/viewtopic.php?t=9623&highlight=

Please discuss here about plugin problems, and in the topic above for the
"conceptional/design level" around the plugin.

Press 'Ctrl+S' inside MP to show the Scripts Manager.

Enjoy!
 

Clodo

Portal Pro
July 8, 2005
53
0
Milan, Italy
I'm start to writing a new version with a script manager inside configuration, for every script opyion like language (c# or VB), compiling options, Scintilla text editor, autostart (none,config,application,both), start/stop method inside script to allow connection/deconnection to MP events, store all scripts data inside an xml file (there is also an option for storing the code externally, for debugging purpose), more compiler error feedback, etc.. etc..

But i don't read any feedback, nobody think that can be useful?

Bye! Clodo
 

Smirnuff

Portal Pro
December 7, 2004
630
3
United Kingdom
My thoughts on this are that Python (or more specifically IronPython) would make a better scripting language for MP, the main reason being that its the easiest language for a beginner to use and subsequently would be of more use to your average MP user. Either way, the scripting concept should be the same so scripting in .NET languages is still a nice idea.

I also think it will receive more attention if you were to give a couple of real world examples of how this can be used and perhaps come up with a list of useful events that we can add to the application that will make it possible to do much more within a script.

I almost forgot, we are doing a huge amount of work on the skinning engine, so in the future such nice keyboard designs as the one you previously presented will be far easier to code, but the point here is that its going to be based on XAML/Avalon and perhaps you could take a look at how M$ are implementing their automation layer within XAML, would be mighty cool...

Cheers,
Smirnoff.
 

Clodo

Portal Pro
July 8, 2005
53
0
Milan, Italy
Hi smirnoff, i don't know anything about the integration of Python or IronPython, but probably require a modification in the core, and many wrapper to c# code, right? If people create a process plugin without knowing that exists the script engine, and declare an event, the event can be directly used by MyScriptC#.

So, as explained in the 'conceptional' thread here, if every script it's derived from a IScript base class, that offer different useful methods and events, can be very useful not only for developer, but also for a beginner.

I try to include some better examples in the next release, but i write this post also for feedback about examples that can be useful...

For example, a script that link the PerformanceCounter on a variable in GuiProperty, that allow people to write a custom 'System Info' gui window, can be useful?

thanks for reply! bye!
 

Clodo

Portal Pro
July 8, 2005
53
0
Milan, Italy
About XAML/Avalon, it's very cool, but i have too much ideas open, and i want to finish at least one, in this case the script engine, before continue on another idea (my keyboard), that is not useful to many users that don't have an analog stick...
 

mzemina

Retired Team Member
  • Premium Supporter
  • February 23, 2005
    2,065
    14
    Tulsa, OK
    Home Country
    United States of America United States of America
    Who is going to record and publish a help file so that this plugin can be used with all the MP events? Without that, this plugin really won't be used by many people and then will be dropped because of a lack of use.

    Mike
     

    Clodo

    Portal Pro
    July 8, 2005
    53
    0
    Milan, Italy
    here exists a thread about a CHM documentation file that can be useful to find events, allow people to write a script without need to browse the sources.... (really? imho, too much difficult....)

    open chm > search tab > check the check box 'search only in title', and use "events" as searching string.

    bye!.
     

    Clodo

    Portal Pro
    July 8, 2005
    53
    0
    Milan, Italy
    I have updated the first post with a new release.

    There are some little-fix that i need to do, but works.
    Support C#, VB.NET and JScript, but for the moment i test only C#.

    Two sample scripts are in plugins\process\myscript

    Please feedback any suggestions/bug report!

    We need help on some things, read the 'Help' tab in Scripts Manager, thanks!

    enjoy!
     

    Clodo

    Portal Pro
    July 8, 2005
    53
    0
    Milan, Italy
    The question: Can be python (or lua, or ecma-script, or...) can be added to this plugins?

    MP & community plugins are compiled in .NET assembly, in a language called CLR (Common Language Runtime).
    See http://www.gotdotnet.com/team/clr/about_clr.aspx


    MyScript uses .NET reflection to compile the script in a .NET assembly, and for this reason only language that can be compiled in CLR
    (C#, VB.NET and JScript) are currenly supported.

    This allow people to write script that interact with MP or other plugins, without need to change the MP core, and without need that others plugins authors know the
    existence of MyScript or the language that MyScript support.

    I have some esperience about integration of Python,Lua and java-script in C++ code, but every solutions require to create many wrapper class that create a 'link'
    between the C++ internal code and the script.

    Adding a language script that are not compiled in CLR (so, don't use reflection) need creations of class wrapper around all features in MP core that need to be exposed to script language, and is a very very big works.
    Also, people that write plugin need also to create this kind of wrapper to allow people to write script that interact with the plugin.


    To understand, this is a piece of code inside \WindowPlugins\GUIScript\MPScript.cs, the actual MyScript included in MP distributions:

    Code:
    	private void callAction(string ac)
    		{
    			Action act;
    			switch (ac)
    			{
    				case "reboot" :
    					act = new Action(Action.ActionType.ACTION_REBOOT,0,0);
    					GUIGraphicsContext.OnAction(act);
    					break;
    				case "shutdown" :
    					act = new Action(Action.ActionType.ACTION_SHUTDOWN,0,0);
    					GUIGraphicsContext.OnAction(act);
    					break;
    				case "hibernate" :
    					WindowsController.ExitWindows(RestartOptions.Hibernate, m_bForceShutdown);
    					break;
    				case "ejectcd" :
    					act = new Action(Action.ActionType.ACTION_EJECTCD,0,0);
    					GUIGraphicsContext.OnAction(act);
    					break;
    				case "previous_menu" :
    					act = new Action(Action.ActionType.ACTION_PREVIOUS_MENU,0,0);
    					GUIGraphicsContext.OnAction(act);
    					break;
    			}
    		}

    As explained, the author need to create wrapper between script and MP core.



    My question is: Why people want Python? C# Script allow people to write any kind of code.
    The only problem is the complexity to write a script, for that i suggest
    to create the Main class in script derived from 'Script', and add some simply methods in this class (like the 'MessageBox' or 'Trace' method already present).



    Another example,

    I found a topic called "Text to Speech.......Make MediaPortal Talk" here.

    To allow that, can simple write a 'script' like:

    Code:
    using System;
    using System.Windows.Forms;
    using MediaPortal.GUI.Library;
    using MediaPortal.Dialogs;
    using MyScript;
    using SpeechLib;
    
    class Main : Script
    {
    	public void Start()
    	{
    			Say("Mediaportal starts!!");
    	}
    
    	public void Stop()
    	{
    	}
    
    	public void Say(string input)
    	{
    		SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
    		SpVoice Voice = new SpVoice();
    		Voice.Speak(input,SpFlags);
    	}
    }

    , and copy the dll Interop.SpeechLib.dll in MP directory.

    (N.B. it's not actually possible to write this script, because in this current release we cannot add additional external assembly reference, but can be possible in the next release).

    With another language not-CLR like Python, we need to create a class wrapper between Interop.SpeechLib.dll and Python.



    --------------------------


    I'm looking on IronPython, suggested by Smirnoff.
    Can be possible to write Python scripts that use CLR-based assembly, but, if i understand correctly, the script itself is not compiled in CLR.

    It's not derived from ICodeCompiler , so don't allow code compiling over reflection....

    In contrast of all texts written above, i can try to integrate to check how it works....
    I don't know the python syntax, but i don't think that python language can be more simple to write than a C# or VB.NET script (with a good 'Script' base class)

    Bye!
     

    Users who are viewing this thread

    Top Bottom