YaST2 Developers Documentation: YCP UI Reference: Widgets



YCP UI Widget Reference

Back to the widget index

Image Pixmap image

Description

Displays an image - if the respective UI is capable of that. If not, it is up to the UI to decide whether or not to display the specified default text instead ( e.g. with the NCurses UI ).

The image is specified as any of:

  • symbol - load a predefined static image. Valid values are:
    • `suseheader the SuSE standard header image
    • `yast2 the YaST2 logo
  • byteblock - something you read with SCR::Read( .target.byte, "image1.png" ). This works on any configuration, even remote.
  • string - a complete path name to an image in a supported format. This is the most convenient method ( since you don't need that SCR:: call mentioned above, but it has its limitations: It only works if the UI runs locally, i.e. has access to the local file system. This can not always be safely assumed.

Use `opt( `zeroWidth ) and / or `opt( `zeroHeight ) if the real size of the image widget is determined by outside factors, e.g. by the size of neighboring widgets. With those options you can override the default "nice size" of the image widget and make it show just a part of the image. This is used for example in the YaST2 title graphics that are 2000 pixels wide even when only 640 pixels are shown normally. If more screen space is available, more of the image is shown, if not, the layout engine doesn't complain about the image widget not getting its nice size.

`opt( `tiled ) will make the image repeat endlessly in both dimensions to fill up any available space. You might want to add `opt( `zeroWidth ) or `opt( `zeroHeight ) ( or both ), too to make use of this feature.

`opt( `scaleToFit ) scales the image to fit into the available space, i.e. the image will be zoomed in or out as needed.

This option implicitly sets `opt( `zeroWidth ) and `opt( zeroHeight ), too since there is no useful default size for such an image.

Please note that setting both `opt( `tiled ) and `opt( `scaleToFit ) at once doesn't make any sense.

Arguments

symbol|byteblock|string image specification which image to display
string label label or default text of the image

Special Properties

None


Options

`opt(`tiled) tile pixmap: repeat it as often as needed to fill all available space
`opt(`scaleToFit) scale the pixmap so it fits the available space: zoom in or out as needed
`opt(`zeroWidth) make widget report a nice width of 0
`opt(`zeroHeight) make widget report a nice height of 0
`opt(`animated) image data contain an animated image ( e.g. MNG )

Sample Usage

`Image( `suseheader, "SuSE Linux 7.0" )

Examples

Example 1: Image1.ycp


/**
 * Example for simple images:
 * Creates one standard (predefined) image and a user-defined image.  
 **/
{  
    global define void ImageDemo(byteblock pixels) ``{
        UI::OpenDialog(
                   `VBox(
                         `Image(pixels, "Image 1"), 
                         `Image(`suseheader, "SuSE header"),
                         `PushButton("&OK")));
        UI::UserInput();
        UI::CloseDialog();
    };

    byteblock image_data = (byteblock) SCR::Read( .target.byte, "image1.png" );
    ImageDemo( image_data );
}
		

Example 2: Image-animated.ycp

/**
 * Example for an animated image
 **/
{
    global define void MovieDemo(byteblock movie) ``{
        UI::OpenDialog(
                   `VBox(
                         `Image(`opt(`animated), movie, "Movie"), 
                         `PushButton("&OK")));
        UI::UserInput();
        UI::CloseDialog();
    };
    
    byteblock movie = (byteblock) SCR::Read( .target.byte, "/usr/share/splash/keys.mng" );
    MovieDemo( movie );
}
		

Example 3: Image-local.ycp


/**
 * Advanced Image widget features:
 * Load image from local file. This may not always be supported, so check if
 * this feature is available prior to using it! 
 **/
{

    if ( ! lookup( UI::GetDisplayInfo(), "HasLocalImageSupport", false ) )
    {
	UI::OpenDialog(
		   `VBox( 
			 `Label("Loading images from local files not supported!"),
			 `PushButton(`opt(`default), "&OK")
			 )
		   );
	UI::UserInput();
	UI::CloseDialog();
	
	return;
    }

    
    UI::OpenDialog(
	       `VBox( 
		     `Image( "/usr/share/doc/susetour/img/games0.png", "Games" ),
		     `PushButton(`opt(`default), "&OK")
		     )
	       );
    UI::UserInput();
    UI::CloseDialog();
}
		

Example 4: Image-scaled.ycp


/**
 * Advanced Image widget features:
 * Load image from local file and scale it to fit the available space.
 **/
{

    if ( ! lookup( UI::GetDisplayInfo(), "HasLocalImageSupport", false ) )
    {
	UI::OpenDialog(
		   `VBox( 
			 `Label("Loading images from local files not supported!"),
			 `PushButton(`opt(`default), "&OK")
			 )
		   );
	UI::UserInput();
	UI::CloseDialog();
	
	return;
    }

    
    UI::OpenDialog( `opt(`defaultsize), 
	       `VBox(
		     `Image( `opt(`scaleToFit), "/usr/share/doc/susetour/img/games0.png", "Games" ),
		     `Right( `Label( "Resize the window to scale the image" ) ),
		     `PushButton(`opt(`default), "&OK")
		     )
	       );
    UI::UserInput();
    UI::CloseDialog();
}
		

Example 5: Image-tiled.ycp


/**
 * Advanced Image widget features:
 * Load image from local file and scale it to fit the available space.
 **/
{

    if ( ! lookup( UI::GetDisplayInfo(), "HasLocalImageSupport", false ) )
    {
	UI::OpenDialog(
		   `VBox( 
			 `Label("Loading images from local files not supported!"),
			 `PushButton(`opt(`default), "&OK")
			 )
		   );
	UI::UserInput();
	UI::CloseDialog();
	
	return;
    }

    
    UI::OpenDialog(
	       `VBox(
		     `HBox(
			   `VSpacing( 5 ),
			   `Image( `opt(`tiled ), "/opt/kde2/share/apps/amor/static/tux.png", "tux" )
			   ),
		     `Right( `Label( "Resize the window to see the effect of image tiling" ) ),
		     `PushButton(`opt(`default), "&OK")
		     )
	       );
    UI::UserInput();
    UI::CloseDialog();
}
		

Back to the widget index


YaST2 Developers Documentation: YCP UI Reference: Widgets

Generated Fri May 21 12:39:01 2004