Author Topic: Need Help...display an image when you press a button  (Read 3404 times)

malfacine

  • Full Member
  • ***
  • Posts: 33
  • fliper80s@me.com
    • View Profile
Need Help...display an image when you press a button
« on: November 30, 2015, 04:11:22 PM »
Make a show image press a key
example press "H" show a image with instructions

Somebody helppp....

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 361
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #1 on: December 03, 2015, 11:17:01 PM »
Here you go:

- Save the code set out below as the file "PopUp.nut" in your attract mode /plugins directory.  Change "image.png" to whatever the filename of your image is.
- In Attract-Mode's plugin configuration enable the PopUp plugin.  In the controls configuration, map the "custom1" control to whatever you want to trigger the image.

Pushing the key should now flip the selected image on and off...

Code: [Select]
class PopUpImage
{
        _my_image=null;

        constructor()
        {
                _my_image = fe.add_image( "image.png", 0, 0 );
                _my_image.visible=false;
                fe.add_signal_handler( this, "on_signal" )
        }

        function on_signal( signal )
        {
                if ( signal == "custom1" )
                {
                        _my_image.visible=!_my_image.visible;
                        return true;
                }
                return false;
        }
}

local blah = PopUpImage();

malfacine

  • Full Member
  • ***
  • Posts: 33
  • fliper80s@me.com
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #2 on: December 10, 2015, 07:48:35 PM »
Oh man thanks....  ;D

xbs

  • Sr. Member
  • ****
  • Posts: 169
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #3 on: December 15, 2015, 01:09:37 PM »
Very useful, maybe someone could make a script with options for image path and button.
I tried but couldn't make it work.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #4 on: December 15, 2015, 08:54:46 PM »
Here's a plugin version with a few changes... copy the code into plugins/PopupImage.nut

* I changed it to use get_input_state so you can use more than just a specific signal
* Added option to Hold key (default is toggle)
* Make sure to specify the full path to the image, otherwise it will look in the plugins folder

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified key is pressed." /> {
</ label="Image", help="The full path to the image that will be displayed", order=1 />
image="";
</ label="Key", help="The key that will display the image", is_input="yes", order=2 />
key="";
</ label="Hold Key", help="If enabled, you must hold the key down", options="Yes,No", order=3 />
hold="No";
};

class PopUpImage
{
        _image = null;
_key = null;
_hold = false;
_showing = false;
_key_delay = 250;
_last_check = 0;

        constructor()
        {
local config = fe.get_config();
_image = fe.add_image( config["image"], 0, 0, fe.layout.width, fe.layout.height );
_image.visible=false;
_image.preserve_aspect_ratio = true;
_key = config["key"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

function on_tick( ttime )
{
local is_down = fe.get_input_state( _key );
if ( _hold == "Yes" )
{
_image.visible = is_down;
_showing = is_down;
} else
{
if ( is_down )
{
if ( ttime - _last_check > _key_delay )
{
_last_check = ttime;
_image.visible = !_showing;
_showing = !_showing;
}
}
}
}
}

fe.plugin[ "PopUpImage" ] <- PopUpImage();

Let me know if you find any issues, then I will add this to my github... :)

verion

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 767
    • View Profile
    • new projects
Re: Need Help...display an image when you press a button
« Reply #5 on: December 16, 2015, 12:48:09 AM »
This is great!

And that addition with "hold-key-to-display" is very user friendly, especially for real cabinet use - this way people not familiar with cabinet won't "lock" themselves in help screen.

Can I display another artwork or text - or it is limited to one image?

« Last Edit: December 16, 2015, 01:40:05 AM by verion »

xbs

  • Sr. Member
  • ****
  • Posts: 169
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #6 on: December 16, 2015, 01:20:47 AM »
Here's a plugin version with a few changes... copy the code into plugins/PopupImage.nut

* I changed it to use get_input_state so you can use more than just a specific signal
* Added option to Hold key (default is toggle)
* Make sure to specify the full path to the image, otherwise it will look in the plugins folder

Let me know if you find any issues, then I will add this to my github... :)

Thank you so much!  :D

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 361
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #7 on: December 16, 2015, 11:14:00 PM »
This is great!

And that addition with "hold-key-to-display" is very user friendly, especially for real cabinet use - this way people not familiar with cabinet won't "lock" themselves in help screen.

Can I display another artwork or text - or it is limited to one image?

if you hack the "fe.add_image()" to "fe.add_artwork()" in the constructor  then I would think this will work for artworks instead of images... you would just have to specify the artwork label you want ("snap", "cpanel"...) in the configuration instead of the "Image"...

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #8 on: December 18, 2015, 01:33:42 PM »
Here's an updated version.. now just set Is Artwork to Yes and you can use snap, marquee, wheel, etc as the image:

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified button is pressed." /> {
</ label="Image", help="The full path to the image that will be displayed", order=1 />
image="";
</ label="Is Artwork" help="If enabled, the image is the selected artwork type", options="Yes,No" order=2 />
is_art=false;
</ label="Key", help="The key that will display the image", is_input="yes", order=3 />
key="";
</ label="Hold Key", help="If enabled, you must hold the key down", options="Yes,No", order=4 />
hold="No";
};

class PopUpImage
{
        _image = null;
_key = null;
_hold = false;
_showing = false;
_key_delay = 250;
_last_check = 0;
_is_art = false;

        constructor()
        {
local config = fe.get_config();
_is_art = config["is_art"];
_image = ( _is_art ) ? fe.add_artwork( config["image"], 0, 0, fe.layout.width, fe.layout.height ) : fe.add_image( config["image"], 0, 0, fe.layout.width, fe.layout.height );
_image.visible=false;
_image.preserve_aspect_ratio = true;
_key = config["key"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

function on_tick( ttime )
{
if ( !fe.overlay.is_up )
{
local is_down = fe.get_input_state( _key );
if ( _hold == "Yes" )
{
_image.visible = is_down;
_showing = is_down;
} else
{
if ( is_down )
{
if ( ttime - _last_check > _key_delay )
{
_last_check = ttime;
_image.visible = !_showing;
_showing = !_showing;
}
}
}
}
}
}

fe.plugin[ "PopUpImage" ] <- PopUpImage();

Also fixed so the key has no effect when the fe.overlay is up (i.e. in config)
« Last Edit: December 18, 2015, 01:42:07 PM by liquid8d »

bobby_magee

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #9 on: February 20, 2017, 11:53:22 AM »
This is a great script, I was wondering if you could offer some help in getting user specific sizes for the image to be used.

If I add say:

   </ label="Image Height", help="Choose the image height", order=5 />
   hsize="";
   </ label="Image Width", help="Choose the image width", order=6 />
   wsize="";

I doesn't work if I try to then get the config information under the constructor using:

         _image = fe.add_image( config["image"], 0, 0, config["hsize], config["wsize"]);

   //      _image = fe.add_image( config["image"], 0, 0, 100, 100);  This does work of course!

I'm not great with programming so any help would be appreciated!

thanks

keilmillerjr

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #10 on: February 20, 2017, 01:19:47 PM »
This is a great script, I was wondering if you could offer some help in getting user specific sizes for the image to be used.

If I add say:

   </ label="Image Height", help="Choose the image height", order=5 />
   hsize="";
   </ label="Image Width", help="Choose the image width", order=6 />
   wsize="";

I doesn't work if I try to then get the config information under the constructor using:

         _image = fe.add_image( config["image"], 0, 0, config["hsize], config["wsize"]);

   //      _image = fe.add_image( config["image"], 0, 0, 100, 100);  This does work of course!

I'm not great with programming so any help would be appreciated!

thanks

You need to convert the string to an integer using the built in function tointeger()

bobby_magee

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #11 on: February 20, 2017, 02:03:21 PM »
That's great, thank you. All working :)

Bbuschke

  • Jr. Member
  • **
  • Posts: 11
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #12 on: March 01, 2017, 01:20:25 PM »
instead of a stored image I have a url to my surveillance camera feed. Could that be used in place of an image somehow? the url is just my ip address and port

keilmillerjr

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #13 on: March 01, 2017, 02:26:51 PM »
instead of a stored image I have a url to my surveillance camera feed. Could that be used in place of an image somehow? the url is just my ip address and port

No. If you have something as important as a surveillance, my suggestion for the time being is to buy a dedicated rpi and have it output to a dedicated monitor. Perhaps you could use a smart strip and have it turn on a monitor when it senses motion? If you find an 8 inch cut, the rip could probably fit inside and make a cool project. Unless your a pro at coding and want to add http functionality to attract mode, or create a borderless webkit app and pin it to the corner of the monitor when monition is detected.

Bbuschke

  • Jr. Member
  • **
  • Posts: 11
    • View Profile
Re: Need Help...display an image when you press a button
« Reply #14 on: March 01, 2017, 04:47:53 PM »
Here's a plugin version with a few changes... copy the code into plugins/PopupImage.nut

* I changed it to use get_input_state so you can use more than just a specific signal
* Added option to Hold key (default is toggle)
* Make sure to specify the full path to the image, otherwise it will look in the plugins folder

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified key is pressed." /> {
</ label="Image", help="The full path to the image that will be displayed", order=1 />
image="";
</ label="Key", help="The key that will display the image", is_input="yes", order=2 />
key="";
</ label="Hold Key", help="If enabled, you must hold the key down", options="Yes,No", order=3 />
hold="No";
};

class PopUpImage
{
        _image = null;
_key = null;
_hold = false;
_showing = false;
_key_delay = 250;
_last_check = 0;

        constructor()
        {
local config = fe.get_config();
_image = fe.add_image( config["image"], 0, 0, fe.layout.width, fe.layout.height );
_image.visible=false;
_image.preserve_aspect_ratio = true;
_key = config["key"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

function on_tick( ttime )
{
local is_down = fe.get_input_state( _key );
if ( _hold == "Yes" )
{
_image.visible = is_down;
_showing = is_down;
} else
{
if ( is_down )
{
if ( ttime - _last_check > _key_delay )
{
_last_check = ttime;
_image.visible = !_showing;
_showing = !_showing;
}
}
}
}
}

fe.plugin[ "PopUpImage" ] <- PopUpImage();

Let me know if you find any issues, then I will add this to my github... :)
right now its displaying snaps. how can i get it to display the boxart. im not seeing what i would change