Introduction

This section contains usefull controls for providing help to the user, these can include context-sensitive help, help menus, tooltips etc.

Recipies

Help Button Using wxTransientPopup

This widget is a help button that uses wxPopUpTransientWindow to create a button, which when clicked upon will open a flyout window containing the help contents. (note: thanks to the writer of the wxTransientWindow example included with the wxPy demo, I stole some of your code _)

Code

Add the following to your GUI, make sure to define an ID for your button:

   1 NameTextCtrlBtn = wxButton(self, ID_HELPBTN, "?", size = wxSize(20,20))
   2 EVT_BUTTON(self, ID_HELPBTN, self.OnHelpBtn)

This code snippit is tied to the buttonpress and creates the transient window (Taken from wxPy demo):

   1 def OnHelpBtn(self, event):
   2     win = HelpTransientPopup(self)
   3     # Show the popup right below or above the button
   4     # depending on available screen space...
   5     btn = event.GetEventObject()
   6     pos = btn.ClientToScreen( (0,0) )
   7     sz =  btn.GetSize()
   8     win.Position(pos, (0, sz.height))
   9     win.Popup()

And finally, this code snippit represents the transient window:

   1 class HelpTransientPopup(wxPopupTransientWindow):
   2     def __init__(self, parent):
   3     wxPopupTransientWindow.__init__(self, parent, wxSIMPLE_BORDER)
   4     panel = wxPanel(self, -1)
   5     panel.SetBackgroundColour("WHITE")
   6     st = wxStaticText(panel, -1,
   7                                 "Name Formatting Help:\n"
   8                                 "Input any text you wish, special tags\n"
   9                                 "listed below will be replaced with\n"
  10                                 "the corresponding info extracted from\n"
  11                                 "the MP3 file. The tags are: \n"
  12                                 "<artist>, <title>, <genre>, <track#>,\n"
  13                                 "<album>, <year>"
  14                                 ,
  15                                 pos=(10,10))
  16     sz = st.GetBestSize()
  17     panel.SetSize( (sz.width+20, sz.height+20) )
  18     self.SetSize(panel.GetSize())

Comments

This could definately be expanded upon by passing in another variable on init containing the string to be displayed in the transientwindow, or alternatively you could tie a key to the button and pass that key which would reference the help string from a dictionary.

Hope someone finds a use for this, Jeff Peck (sanguinus@earthlink.net)

User Help Controls (last edited 2008-03-11 10:50:31 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.