Phoenix Logo

phoenix_title wx.InfoBar

An info bar is a transient window shown at top or bottom of its parent window to display non-critical information to the user.

This class provides another way to show messages to the user, intermediate between message boxes and status bar messages. The message boxes are modal and thus interrupt the users work flow and should be used sparingly for this reason. However status bar messages are often too easy not to notice at all. An info bar provides a way to present the messages which has a much higher chance to be noticed by the user but without being annoying.

Info bar may show an icon (on the left), text message and, optionally, buttons allowing the user to react to the information presented. It always has a close button at the right allowing the user to dismiss it so it isn’t necessary to provide a button just to close it.

wx.InfoBar calls its parent wx.Window.Layout method and assumes that it will change the parent layout appropriately depending on whether the info bar itself is shown or hidden. Usually this is achieved by simply using a sizer for the parent window layout and adding wx.InfoBar to this sizer as one of the items. Considering the usual placement of the info bars, normally this sizer should be a vertical wx.BoxSizer and the bar its first or last element so the simplest possible example of using this class would be:

class MyFrame(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent, title='InfoBar!')

        self.infoBar = wx.InfoBar(self)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.infoBar, wx.SizerFlags().Expand())

        # ... add other frame controls to the sizer ...
        self.SetSizer(sizer)


    def SomeMethod(self):

        self.infoBar.ShowMessage("Something happened", wx.ICON_INFORMATION)

See the dialogs sample for more sophisticated examples.

Currently this class is implemented generically (i.e. in the same platform-independent way for all ports) and also natively in wxGTK but the native implementation requires a recent

New in version 2.9.1.


class_hierarchy Class Hierarchy

Inheritance diagram for class InfoBar:

method_summary Methods Summary

__init__ Default constructor.
AddButton Add a button to be shown in the info bar.
Create Create the info bar window.
Dismiss Hide the info bar window.
GetEffectDuration Return the effect animation duration currently used.
GetHideEffect Return the effect currently used for hiding the bar.
GetShowEffect Return the effect currently used for showing the bar.
RemoveButton Remove a button previously added by AddButton .
SetEffectDuration Set the duration of the animation used when showing or hiding the bar.
SetFont Overridden base class methods changes the font of the text message.
SetShowHideEffects Set the effects to use when showing and hiding the bar.
ShowMessage Show a message in the bar.

api Class API



class wx.InfoBar(Control)

Possible constructors:

InfoBar()

InfoBar(parent, winid=ID_ANY)

An info bar is a transient window shown at top or bottom of its parent window to display non-critical information to the user.


Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.

Use Create for the objects created using this constructor.



__init__ (self, parent, winid=ID_ANY)

Constructor creating the info bar window.

Parameters:
  • parent (wx.Window) –
  • winid (wx.WindowID) –

See also

Create





AddButton(self, btnid, label="")

Add a button to be shown in the info bar.

The button added by this method will be shown to the right of the text (in LTR layout), with each successive button being added to the right of the previous one. If any buttons are added to the info bar using this method, the default “Close” button is not shown as it is assumed that the extra buttons already allow the user to close it.

Clicking the button will generate a normal EVT_COMMAND_BUTTON_CLICKED event which can be handled as usual. The default handler in wx.InfoBar itself closes the window whenever a button in it is clicked so if you wish the info bar to be hidden when the button is clicked, simply call event.Skip() in the button handler to let the base class handler do it (calling Dismiss explicitly works too, of course). On the other hand, if you don’t skip the event, the info bar will remain opened so make sure to do it for at least some buttons to allow the user to close it.

Notice that the generic wx.InfoBar implementation handles the button events itself and so they are not propagated to the info bar parent and you need to either inherit from wx.InfoBar and handle them in your derived class or use wx.EvtHandler.Connect , as is done in the dialogs sample, to handle the button events in the parent frame.

Parameters:
  • btnid (wx.WindowID) – Id of the button. It will be used in the button message clicking this button will generate.
  • label (string) – The label of the button. It may only be empty if btnid is one of the stock ids in which case the corresponding stock label (see wx.GetStockLabel ) will be used.


Create(self, parent, winid=ID_ANY)

Create the info bar window.

Notice that unlike most of the other Window-derived classes, wx.InfoBar is created hidden and is only shown when ShowMessage is called. This is more convenient as usually the info bar is created to be shown at some later time and not immediately and so creating it hidden avoids the need to call Hide explicitly from the code using it.

This should be only called if the object was created using its default constructor.

Parameters:
  • parent (wx.Window) – A valid parent window pointer.
  • winid (wx.WindowID) – The id of the info bar window, usually unused as currently no events are generated by this class.
Return type:

bool



Dismiss(self)

Hide the info bar window.

This method hides the window and lays out the parent window to account for its disappearance (unlike a simple Hide ).



GetEffectDuration(self)

Return the effect animation duration currently used.

Return type:int


GetHideEffect(self)

Return the effect currently used for hiding the bar.

Return type: wx.ShowEffect


GetShowEffect(self)

Return the effect currently used for showing the bar.

Return type: wx.ShowEffect


RemoveButton(self, btnid)

Remove a button previously added by AddButton .

Parameters:btnid (wx.WindowID) – Id of the button to remove. If more than one button with the same id is used in the info bar (which is in any case not recommended), the last, i.e. most recently added, button with this id is removed.


SetEffectDuration(self, duration)

Set the duration of the animation used when showing or hiding the bar.

By default, 500ms duration is used.

Parameters:duration (int) – Duration of the animation, in milliseconds.


SetFont(self, font)

Overridden base class methods changes the font of the text message.

wx.InfoBar overrides this method to use the font passed to it for its text message part. By default a larger and bold version of the standard font is used.

This method is generic-only.

Parameters:font (wx.Font) –
Return type:bool


SetShowHideEffects(self, showEffect, hideEffect)

Set the effects to use when showing and hiding the bar.

Either or both of the parameters can be set to wx.SHOW_EFFECT_NONE to disable using effects entirely.

By default, the info bar uses wx.SHOW_EFFECT_SLIDE_TO_BOTTOM effect for showing itself and wx.SHOW_EFFECT_SLIDE_TO_TOP for hiding if it is the first element of the containing sizer and reverse effects if it’s the last one. If it is neither the first nor the last element, no effect is used to avoid the use of an inappropriate one and this function must be called if an effect is desired.

Parameters:
  • showEffect (ShowEffect) – The effect to use when showing the bar.
  • hideEffect (ShowEffect) – The effect to use when hiding the bar.


ShowMessage(self, msg, flags=ICON_INFORMATION)

Show a message in the bar.

If the bar is currently hidden, it will be shown. Otherwise its message will be updated in place.

Parameters:
  • msg (string) – The text of the message.
  • flags (int) – One of wx.ICON_NONE, wx.ICON_INFORMATION (default), wx.ICON_QUESTION, wx.ICON_WARNING or wx.ICON_ERROR values. These flags have the same meaning as in wx.MessageDialog for the generic version, i.e. show (or not, in case of wx.ICON_NONE) the corresponding icon in the bar but can be interpreted by the native versions. For example, the GTK+ native implementation doesn’t show icons at all but uses this parameter to select the appropriate background colour for the notification.

Properties



EffectDuration

See GetEffectDuration and SetEffectDuration



HideEffect

See GetHideEffect



ShowEffect

See GetShowEffect