Rookie help: Pass variable to plugin

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
User avatar
Luca Brasi
Experienced User
Posts: 262
Joined: Sat Oct 11, 2008 12:39 pm

Rookie help: Pass variable to plugin

Post by Luca Brasi » Sat Jun 24, 2017 7:06 am

Hey guys,
I am learning python the hard way by trial and error. I am trying to use the osd plugin in a script:
eg.plugins.EventGhost.ShowOSD(u'Some text', u'0;-35;0;0;0;300;0;0;0;0;3;2;1;34;TitanLight', (255, 255, 255), None, 1, (400, 50), 0, 5.0, u'Default')

Now I am trying to pass some variables to this:
eg.plugins.EventGhost.ShowOSD(u'Some text', u'0;eg.globals.osd_vol_font_size;0;0;0;400;0;0;0;0;3;2;1;34;eg.globals.osd_font, (255, 255, 255), None, 6, (eg.globals.osd_vol_fscreen_x, eg.globals.osd_vol_fscreen_y), 0, show_osd_duration, eg.globals.osd_skin)

Now, those parts of the date send to the plugin which are in u'...' will not get parsed. I do understand that this is because of u'' which will convert to unicode and the variables will not be processed. So I was thinking that some escape statements like \ will do the trick but it doesn't work. I noticed that you can use {variable} in the text field (u'Some text') and this will work. But not in the second part for the font settings. I guess this is because of the multiple statements inside of u''.
Can someone of you give me a hint please?
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi

yokel22
Experienced User
Posts: 153
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Rookie help: Pass variable to plugin

Post by yokel22 » Sat Jun 24, 2017 8:59 pm

the part's with u'something' are parameters of the plugins action. You can use variables for any of them, but they must be formatted correctly for the plugin's action.

The comma's separate each parameter. So for the OSD plugin it would be in this order corresponding to each of the actions config settings.
eg.plugins.EventGhost.ShowOSD(u'Shown Text', u'0;-35;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (64, 0, 64), (0, 0, 0), 4, (0, 0), 0, 3.0, None)
1.The text you want displayed
2.Position on the screen you want text displayed(x,y cord.)
3.Text font
4.Text color(R,G,B hex)
5.Text Outline(1, or None)
6.Horizontal/Vertical offset
7.Use skin(1,0)
8.hide after x seconds(integer)

If you want to manipulate them via script with eg.globals you just need to make sure your sending the proper formatting for the parameter.
Here's a quick example that will change the text and text color based on eg.globals. This will show pink text of "Show some text". You'll see that the text color parameter needs to be integer values, where the text value needs to be a string.

Code: Select all

eg.globals.testText = 'Show some text'
eg.globals.testTextColor = (255, 0, 128)
eg.plugins.EventGhost.ShowOSD(eg.globals.testText, u'0;-35;0;0;0;700;0;0;0;0;3;2;1;34;Arial', eg.globals.testTextColor, (0, 0, 0), 4, (0, 0), 0, 3.0, None)

User avatar
kgschlosser
Site Admin
Posts: 3113
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Rookie help: Pass variable to plugin

Post by kgschlosser » Sat Jun 24, 2017 11:51 pm

eg.plugins.EventGhost.ShowOSD(u'Shown Text', u'0;-35;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (64, 0, 64), (0, 0, 0), 4, (0, 0), 0, 3.0, None)

eg.plugins.EventGhost.ShowOSD(1, 2, 3, 4, 5, 6, 7, 8, 9)

1 = Text you want to display
2 = String representing the font information - This is a bit tricky and I will explain it more below
3 = text color - (red, green, blue) each of the colors can be 0-255
4 = outline color - (red, green, blue) each of the colors can be 0-255
5 = location on the screen 0=top left, 1=top right, 2=bottom left, 3=bottom right, 4=center, 5=bottom center, 6=top center, 7=left center, 8=right center
6 = offset on the screen - (horizontal offset, vertical offset) either of these can be a + or a - number. these numbers are the number of pixels to shift the text
7 = monitor number - if you go into the windows screen resolution the monitor numbers start at 1 so simply pick a monitor number from there and subtract 1 from that number and that is what to enter here
8 = timeout - Number of seconds to keep the OSD on the screen for. if you want it to be displayed for a half a second then enter 0.5 for 5 seconds enter 5.0
9 = skin name - I am not sure if this can be used to load a custom skin or not.


The font has to be a string. and the easiest way for you to do this is like so.

The code below will make a string that looks like this

'0;-96;0;0;0;400;0;0;0;0;3;2;1;34;Arial'

Code: Select all

eg.globals.osd_vol_font_size = -96
eg.globals.osd_font = 'Arial'

font = '0;%d;0;0;0;400;0;0;0;0;3;2;1;34;%s' % (eg.globals.osd_vol_font_size, eg.globals.osd_font)
This is what I know about the font string.
makes text smaller ; font size ; horizontal size ; text pitch ; don't know ; bold weight ; italic weight ; underline ; strike through ; script ; don't know ; don't know ; don't know ; don't know ; font name'

with the font size the lower the number the larger the font. a -96 is the same as a 72 point font.
If you like the work I have been doing then feel free to Image

User avatar
Luca Brasi
Experienced User
Posts: 262
Joined: Sat Oct 11, 2008 12:39 pm

Re: Rookie help: Pass variable to plugin

Post by Luca Brasi » Sun Jun 25, 2017 5:31 pm

Hey guys,
thank you very much for your detailed responses. I managed to get it working with all your tips.
yokel22 wrote:you just need to make sure your sending the proper formatting for the parameter
in combination with
kgschlosser wrote:font = '0;%d;0;0;0;400;0;0;0;0;3;2;1;34;%s' % (eg.globals.osd_vol_font_size, eg.globals.osd_font)
did the trick.
Thank you again!

Edit:
It came to my mind that some other people might wanna do something similar. So as a starting point the code I used. It does set different settings for kodi and mediaportal. Here's the kodi part.

Code: Select all

eg.globals.osd_skin = "kodi" #I created a skin in C:\Program Files (x86)\EventGhost\plugins\EventGhost\OsdSkins with the name kodi and a png with matching colors. Same goes for mediaportal
eg.globals.osd_font = "MC360"
eg.globals.osd_font_size = -29
eg.globals.osd_vol_font_size = -32
eg.globals.osd_vol_font_size_fscreen = -32
eg.globals.osd_vol_font_bold_weight = 200
eg.globals.osd_vol_pos = 1
eg.globals.osd_vol_x = 28
eg.globals.osd_vol_y = 90
eg.globals.osd_vol_pos_fscreen = 6
eg.globals.osd_vol_fscreen_x = 0
eg.globals.osd_vol_fscreen_y = 20
This script will be run on startup of kodi.

Then on volume change the following will be triggered.

Code: Select all

osd_font_string = '0;%d;0;0;0;%d;0;0;0;0;3;2;1;34;%s' % (eg.globals.osd_vol_font_size, eg.globals.osd_vol_font_bold_weight, eg.globals.osd_font)
#fullscreen or not will be controlled by events out of kodi or mediaportal and used as follows
if not eg.globals.fullscreen:
    OSDText = eg.globals.pretext+":  "+str(eg.globals.volume)
    osd_skin = None
    osd_x = eg.globals.osd_vol_x
    osd_y = eg.globals.osd_vol_y
    osd_vol_pos = eg.globals.osd_vol_pos 
else:
    OSDText = eg.globals.pretext+":   "+"|"*eg.globals.volume+" "+str(eg.globals.volume)+" "+"."*(eg.globals.volmaxcalc-eg.globals.volume)
    osd_skin = eg.globals.osd_skin
    osd_x = eg.globals.osd_vol_fscreen_x
    osd_y = eg.globals.osd_vol_fscreen_y
    osd_vol_pos = eg.globals.osd_vol_pos_fscreen 
#trigger osd
eg.plugins.EventGhost.ShowOSD(OSDText, osd_font_string, (255, 255, 255), None, osd_vol_pos, (osd_x, osd_y), 0, show_osd_duration, osd_skin)
eg.globals.volume is fed elsewhere depending on which audio device is used. Same goes for show_osd_duration.

Results:
mp menu:
screen_mmnote_2017-06-25 20 29 21.png
mp fullscreen:
screen_mmnote_2017-06-25 20 29 02.png
kodi menu:
screen_mmnote_2017-06-25 20 29 51.png
kodi fullscreen:
screen_mmnote_2017-06-25 20 31 03.png
Please do not wonder why I went through all the effort to get similar looking osds. I'll start tweaking with colors, fonts and sizes now...

Oh and
9 = skin name - I am not sure if this can be used to load a custom skin or not.
It does work!
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi

User avatar
kgschlosser
Site Admin
Posts: 3113
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Rookie help: Pass variable to plugin

Post by kgschlosser » Mon Jun 26, 2017 3:23 am

One of the things you can add to this is automatic changing of the volume to a 0 to 100 range

What that means is that not every one's AVR outputs volume levels that fall into the 0 to 100 spectrum. Like my Harman Kardon is -80 to 10.

This will take a -30 reported volume level and convert it to be the equivalent number that falls in the 0 to 100 scale. This way the OSD script can properly add the pipes and dots

Code: Select all

OLD_MIN = -80
OLD_MAX = 10

volume = -30

print volume

old_range = OLD_MAX - OLD_MIN
volume = ((volume - OLD_MIN) * 100) / old_range


print volume

If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3113
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Rookie help: Pass variable to plugin

Post by kgschlosser » Mon Jun 26, 2017 3:34 am

I made something very similar I would have to dig it up. It doesn't use the OSD plugin. I created a custom window that would fade in and fade out. You can set the text and text border colors but you could also set the transparency of each and you could choose to draw a colored box with or without a border and the color for the border both with transparency adjustments as well. And you could set the width of the border for the text as well as the box. And if you wanted the box to have rounded corners and you could set the radius of the rounded corners. The really cool thing was you could also set a hover color so if you used your mouse and hovered over the osd it would begin to pulse the color of the border of the box between the hover color and the original color. And depending on where you clicked on the volume bar it would set the volume to that amount. And as long as the mouse was over the volume bar it wouldn't disappear
If you like the work I have been doing then feel free to Image

RiseUp
Posts: 15
Joined: Mon Nov 24, 2014 3:28 am

Re: Rookie help: Pass variable to plugin

Post by RiseUp » Wed Dec 06, 2017 4:48 pm

kgschlosser wrote:
Mon Jun 26, 2017 3:34 am
I made something very similar I would have to dig it up. It doesn't use the OSD plugin. I created a custom window that would fade in and fade out. You can set the text and text border colors but you could also set the transparency of each and you could choose to draw a colored box with or without a border and the color for the border both with transparency adjustments as well. And you could set the width of the border for the text as well as the box. And if you wanted the box to have rounded corners and you could set the radius of the rounded corners. The really cool thing was you could also set a hover color so if you used your mouse and hovered over the osd it would begin to pulse the color of the border of the box between the hover color and the original color. And depending on where you clicked on the volume bar it would set the volume to that amount. And as long as the mouse was over the volume bar it wouldn't disappear
Have you been able to dig this up? I'd love to try it out! I've been wanting something a bit more customizable than the OSD plugin, especially with fade-in and fade-out capabilities.

User avatar
kgschlosser
Site Admin
Posts: 3113
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Rookie help: Pass variable to plugin

Post by kgschlosser » Wed Dec 06, 2017 5:40 pm

I am sure i can locate it and dust it off. LOL

But it is something that was never put into a full fledged plugin. I has started some work on updating the remote plugin for EG. but never really finished it up. it's a tricky thing to do custom drawings on the screen. it is even more complex when you throw in the added bonus of dynamically changing elements. If you do to much at one time it gets horribly slow. This is not something I am a master at yet. I am working on it tho.

But let me see what i can dig up and see if i can't fashion it into a quick and dirty plugin for ya.
If you like the work I have been doing then feel free to Image

RiseUp
Posts: 15
Joined: Mon Nov 24, 2014 3:28 am

Re: Rookie help: Pass variable to plugin

Post by RiseUp » Wed Dec 06, 2017 6:04 pm

kgschlosser wrote:
Wed Dec 06, 2017 5:40 pm
But let me see what i can dig up and see if i can't fashion it into a quick and dirty plugin for ya.
That's all I can ask for. Much appreciated! :D

Post Reply