As of this writing, the current wxWidgets API does not supply an interface to enumerate the tools in a toolbar if the tool IDs are not known in advance. A ticket suggesting this feature has been posted in the tracker. In the meantime, this recipe describes techniques that attempt to elicit this information using the existing APIs.

A Simple Approach for a Simple Toolbar

If you have a simple horizontal tool bar with exactly one row and evenly-spaced tools and no spacers, the following code snippet appears to work to retrieve the tools.

   1 def getToolsForToolbar(tb):
   2         tool_size = tb.GetToolSize()
   3         width, height = tool_size
   4         pos = 0
   5         while True:
   6                 tool = tb.FindToolForPosition(pos, 0)
   7                 if tool: yield tool
   8                 else: break
   9                 pos += width

If you end up building on this to handle some of the aforementioned limitations, please consider updating this Wiki.

EnumeratingToolbarTools (last edited 2010-01-13 21:39:01 by c-68-33-182-134)

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