XVirtualEvents (for conditional events)

Xlobby plugin development

XVirtualEvents (for conditional events)

Postby badubo on Tue Sep 09, 2008 9:56 am

Hello,

In order to enhance XRemote and allowing a better control of buttons, I created a small plugin.
Probably that some of you may find it usefull, so I post it.

http://france.xlobby.com/plugins/XVirtualEvents.zip

This plugin allows to create conditional events (working like a switch/case) called "Virtual Events"
these events will call another Xlobby event depending on the result of a condition
One example of use is the stop button in the media player, if you are playing music, or video, you want that the button trigger a different event (either stopping music, either stopping video). Using the states feature is a possibility but I found it quite boring when you have many buttons (or if you want to use a remote)

As an extend,using plugin's variables, it allows also to show text or image in a textbox depending of a condition (Virtual Strings).

1/What are Virtual Events :

The principle is quite simple
Each Virtual event contains a "condition" and a list of possible results each associated with a xlobby event to call.
The condition is a string containing some basic functions provided by the plugin (see below)
Once the virtal event is triggered (as any event in xlobby), the plugin will evaluate the condition and will compare the result against the list of results and, if one is matching, it will call the corresponding event.
For easier use, these virtual events are stored in the XVirtualEvents events group (in the skin folder). This group is automatically created by the plugin so do not edit it ;). But you can also call them using the execute method of the plugin (with the virtual event name as parameter)

2/How creating Virtual events :
- Open the configuration dialog of the plugin (F2/plugins/configuration)
- on the left side, you have the list of existing virtual events.
- for creating a new one, type the name in the edit box et click "create", it will appear in the list.
- select it on the list.
- In the condition box, you can call one or several functions (see the list below). You can try to evaluate the condition (click evaluate)
- in the grid below the condition, right click to add a new result (or remove the selected)
- double click on the Result column to edit the value. This value is similar to a "case of" in a switch
- double click in the event column to show the event tree and select the event you want to call if the result matches
The event will be available next time you restart xlobby (unfortunately, there is no way to dynamicaly add an event from a plugin :( )

note : If there is no matching result, no event are called except if you create a special result that you must call : default

3/The conditions:
Condition can be any combination of functions, each function has the prototype :
XL.Function([ListofArgs])
You can use a function as argument of another : XL.IsEqual(XL.Screen(),menu) will return true if the current screen is menu
Note that the plugin replaces the function by its computed value, so, if you have 2 functions separated by a space, you will get a new string with the result of each function separated by a space
i.e. if you are in the music screen and you are coming from menu :
calling : XL.Screen() XL.OldScreen()
will return : music menu

4/Virtual strings:
Using the same principle you can create variable (called with plugin>XVirtualEvents>VariableName), it works the same way except that if the result matches, it is not an event that is called, but another string that is displayed (the string is stored in the second column, double click to edit it).
This string is also evaluated like the condition, so you can use the same set of functions + specific to this fiels (images and result, see below).
To configure them, simply select the string radio button on the upper right side

5/List of functions you can use in conditions or virtual strings

There are two kinds of functions : literal or boolean.

- LITERALS functions return a string (like the screen, the content of a variable,...)

XL.Variable(XlobbyVar) : returns the value of XlobbyVar (xlobbyvar must be written the same as in the skin editor)
XL.Screen() : returns the current screen
XL.OldScreen() : returns the previous screen

- BOOLEAN : returning True or False
XL.IsEqual(Arg1,Arg2) : returns True if Arg1=Arg2
XL.Or(Args1, Args2,...) : returns True if any of the args (separated by a comma) is true
XL.And(Args1, Args2,...) : returns True if all args are True
XL.Screen(name) : returns True is the current screen is "name"
Note : If you append a ! in front of a boolean functions, you invert the result :
if XL.Screen(menu) is True : !XL.Screen(menu) is False

-Specific for Virtual strings :
XL.Image(Path) : display the image found in path in the textbox (you can use absolute path or skin://)
XL.Result() : is replaced by the computed result of the condition


Hope it will be usefull.
If you have some ideas to extend this plugin(i.e. new functions), don't hesitate ;)
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Re: XVirtualEvents (for conditional events)

Postby smarty on Tue Sep 09, 2008 2:51 pm

Great stuff Badubo!
smarty
 
Posts: 179
Joined: Thu Jul 27, 2006 12:04 am
Location: San Antonio, TX USA

Re: XVirtualEvents (for conditional events)

Postby rika on Wed Sep 10, 2008 6:13 pm

Badubo, realy useful, big thanks!!

Rika
rika
 
Posts: 401
Joined: Fri Apr 02, 2004 5:43 am
Location: Sweden

Re: XVirtualEvents (for conditional events)

Postby Bill Lott on Sat Mar 28, 2009 3:05 pm

I need a little help in formatting a virtual event.

I store movies on the hard drive and also have a DVD jukebox. I currently have two play events - Play DVD and Play Movie. I would like to create a virtual "play" event that would run the proper event based on whether the movie is stored on the hard drive or an actual DVD in the DVD jukebox.

It seems that an easy way to determine which "play event" to run would be based on a field in the movies database called "CollectionNumber". Movies stored on the hard drive do not have a collection number. DVD Movies do.

If there is a CollectionNumber then Play DVD...

if there is no CollectionNumber then Play Movie

Having very limited programming skills, I could use some help in formatting the virtual conditional in XVirtualEvents.

I think I can use the XL.IsEqual condition.

XL.IsEqual(CollectionNumber," " ) or something similar.

What is the proper format?
Bill Lott
 
Posts: 293
Joined: Sun Sep 05, 2004 3:25 pm
Location: Louisville, KY

Re: XVirtualEvents (for conditional events)

Postby badubo on Mon Mar 30, 2009 8:28 am

Hi,

I consider that your category is "movies"
you can test as condition :

XL.IsEqual(XL.Variable(%movies>CollectionNumber%),)

Then as results :
True --> Play Movie
False --> Play DVD
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Re: XVirtualEvents (for conditional events)

Postby Bill Lott on Tue Mar 31, 2009 3:54 am

Results have special characters after the "True" or 'False"
so when i run the plugin my result says 'True{}{}{}{}' <-example, i believe they were carriage returns

would special characters have any effect on the plugin?
Bill Lott
 
Posts: 293
Joined: Sun Sep 05, 2004 3:25 pm
Location: Louisville, KY

Re: XVirtualEvents (for conditional events)

Postby badubo on Tue Mar 31, 2009 7:46 pm

Delete all characters after the last ')'
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Re: XVirtualEvents (for conditional events)

Postby Bill Lott on Tue Mar 31, 2009 9:38 pm

YES!

That was it. Now working perfectly. I can see many other uses for this plugin.

Off to creating more conditional events...

Thanks again!
Bill Lott
 
Posts: 293
Joined: Sun Sep 05, 2004 3:25 pm
Location: Louisville, KY

Re: XVirtualEvents (for conditional events)

Postby Carlos Delgado on Sun Feb 21, 2010 7:24 pm

Badubo

Hi

I am also looking to do someting like what you sujested to a post about DVD jukebox below.

I have 3 DVD Changeers and have imported all my DVD Profiler 3.x data to Xlobby I set up 3 Events called DVD1,DVD2,DVD3 what I would like to know, if your program can select the correct event based on the movie.xml database on a field called Disc1_Location. The way I do it now is I have to assign each movie the correct event either it be dvd1 or dvd2 ect. The problem is when I add more movies to DVDProfiler and Convert the Data again to Xlobby the assigned event that I assigned manualy to all those movies goes away then I have to redo it all over again.

Events setup - dvd1 - dvd2 - dvd3
movie.xml - Field I want XvirtualEvents to look for --> Disc1_Location
then based on what it sees in the field selct the correct event and execute it.
Every movie will have to point to one of the 3 events based on what is in the Disc1_Location field

Can you tell me what to input in your program to have it look at the Disc1_Location field and then based on what it sees select the correct event and execute the commands I setup in it.

Thanks

Carlos D.



badubo wrote:Hello,

In order to enhance XRemote and allowing a better control of buttons, I created a small plugin.
Probably that some of you may find it usefull, so I post it.

http://france.xlobby.com/plugins/XVirtualEvents.zip

This plugin allows to create conditional events (working like a switch/case) called "Virtual Events"
these events will call another Xlobby event depending on the result of a condition
One example of use is the stop button in the media player, if you are playing music, or video, you want that the button trigger a different event (either stopping music, either stopping video). Using the states feature is a possibility but I found it quite boring when you have many buttons (or if you want to use a remote)

As an extend,using plugin's variables, it allows also to show text or image in a textbox depending of a condition (Virtual Strings).

1/What are Virtual Events :

The principle is quite simple
Each Virtual event contains a "condition" and a list of possible results each associated with a xlobby event to call.
The condition is a string containing some basic functions provided by the plugin (see below)
Once the virtal event is triggered (as any event in xlobby), the plugin will evaluate the condition and will compare the result against the list of results and, if one is matching, it will call the corresponding event.
For easier use, these virtual events are stored in the XVirtualEvents events group (in the skin folder). This group is automatically created by the plugin so do not edit it ;). But you can also call them using the execute method of the plugin (with the virtual event name as parameter)

2/How creating Virtual events :
- Open the configuration dialog of the plugin (F2/plugins/configuration)
- on the left side, you have the list of existing virtual events.
- for creating a new one, type the name in the edit box et click "create", it will appear in the list.
- select it on the list.
- In the condition box, you can call one or several functions (see the list below). You can try to evaluate the condition (click evaluate)
- in the grid below the condition, right click to add a new result (or remove the selected)
- double click on the Result column to edit the value. This value is similar to a "case of" in a switch
- double click in the event column to show the event tree and select the event you want to call if the result matches
The event will be available next time you restart xlobby (unfortunately, there is no way to dynamicaly add an event from a plugin :( )

note : If there is no matching result, no event are called except if you create a special result that you must call : default

3/The conditions:
Condition can be any combination of functions, each function has the prototype :
XL.Function([ListofArgs])
You can use a function as argument of another : XL.IsEqual(XL.Screen(),menu) will return true if the current screen is menu
Note that the plugin replaces the function by its computed value, so, if you have 2 functions separated by a space, you will get a new string with the result of each function separated by a space
i.e. if you are in the music screen and you are coming from menu :
calling : XL.Screen() XL.OldScreen()
will return : music menu

4/Virtual strings:
Using the same principle you can create variable (called with plugin>XVirtualEvents>VariableName), it works the same way except that if the result matches, it is not an event that is called, but another string that is displayed (the string is stored in the second column, double click to edit it).
This string is also evaluated like the condition, so you can use the same set of functions + specific to this fiels (images and result, see below).
To configure them, simply select the string radio button on the upper right side

5/List of functions you can use in conditions or virtual strings

There are two kinds of functions : literal or boolean.

- LITERALS functions return a string (like the screen, the content of a variable,...)

XL.Variable(XlobbyVar) : returns the value of XlobbyVar (xlobbyvar must be written the same as in the skin editor)
XL.Screen() : returns the current screen
XL.OldScreen() : returns the previous screen

- BOOLEAN : returning True or False
XL.IsEqual(Arg1,Arg2) : returns True if Arg1=Arg2
XL.Or(Args1, Args2,...) : returns True if any of the args (separated by a comma) is true
XL.And(Args1, Args2,...) : returns True if all args are True
XL.Screen(name) : returns True is the current screen is "name"
Note : If you append a ! in front of a boolean functions, you invert the result :
if XL.Screen(menu) is True : !XL.Screen(menu) is False

-Specific for Virtual strings :
XL.Image(Path) : display the image found in path in the textbox (you can use absolute path or skin://)
XL.Result() : is replaced by the computed result of the condition


Hope it will be usefull.
If you have some ideas to extend this plugin(i.e. new functions), don't hesitate ;)
Carlos Delgado
 
Posts: 21
Joined: Wed Feb 10, 2010 4:59 am

Re: XVirtualEvents (for conditional events)

Postby badubo on Sat Feb 27, 2010 11:56 am

in the condition :
XL.Variable(%movies>Disc1_Location%)

then create 3 results :
DVD1 -->event dvd1
DVD2 -->event dvd2
DVD3 -->event dvd3
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Re: XVirtualEvents (for conditional events)

Postby Carlos Delgado on Thu Mar 31, 2011 5:06 am

Hi. Badubo

I just looked at the post you did for me awhile back, can you tell me how do I assign the Play Buttom to XVertuialEvents. I did get it to work doing what you told me to do just makeing the connection I do not understand.

P.S Also have you worked with Xlobby 3 I think it could also do this I will be going to XL3 in a few weeks maybe you could tell me how to do this in Xlobby3.

Thanks again

Badubo

Hi

I am also looking to do someting like what you sujested to a post about DVD jukebox below.

I have 3 DVD Changeers and have imported all my DVD Profiler 3.x data to Xlobby I set up 3 Events called DVD1,DVD2,DVD3 what I would like to know, if your program can select the correct event based on the movie.xml database on a field called Disc1_Location. The way I do it now is I have to assign each movie the correct event either it be dvd1 or dvd2 ect. The problem is when I add more movies to DVDProfiler and Convert the Data again to Xlobby the assigned event that I assigned manualy to all those movies goes away then I have to redo it all over again.

Events setup - dvd1 - dvd2 - dvd3
movie.xml - Field I want XvirtualEvents to look for --> Disc1_Location then based on what it sees in the field selct the correct event and execute it.
Every movie will have to point to one of the 3 events based on what is in the Disc1_Location field

Can you tell me what to input in your program to have it look at the Disc1_Location field and then based on what it sees select the correct event and execute the commands I setup in it.

Thanks

Carlos D.

Re: XVirtualEvents (for conditional events)

by badubo on Sat Feb 27, 2010 3:56 am

in the condition :
XL.Variable(%movies>Disc1_Location%)

then create 3 results :
DVD1 -->event dvd1
DVD2 -->event dvd2
DVD3 -->event dvd3

Carlos D.
Carlos Delgado
 
Posts: 21
Joined: Wed Feb 10, 2010 4:59 am