[wxPython] [Q] Toolbar and toggle button

Hi, I'd like to know how to make one of the tool buttons always selected in
wxPython.
I created a tool bar and put tool bar icons. I set their isToggle to true so
all of them are toggle button. But the problem is I don't want more them one
tool button selected at once. Is there any convenient way to do this?
In other language, for instance Java, there is a group mechanism which
allows only one component can be selected.
If it is not in wxPython, how can I implemented it? Any comment would be
greatly appreciated.
Thanks for your wonderful help.

YJ

Young-Jin Lee wrote:

But the problem is I don't want more them one
tool button selected at once. Is there any convenient way to do this?
In other language, for instance Java, there is a group mechanism which
allows only one component can be selected.

Last I checked, there was not a way to do this automataically, but it
was being worked on, so this info may be old.

If it is not in wxPython, how can I implemented it? Any comment would be
greatly appreciated.

I have done it like this: (code cut and pasted from a larger app, get
ideas form it, it won't run as is.)

    ## Set up Tool Bar
    tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
    self.ToolBar = tb

## three toggle buttons, where one can only be active at once:
## they all call the SetMode method below.

    tb.AddTool(ID_ZOOM_IN_BUTTON, wxBitmap('Mag_plus3.bmp',
wxBITMAP_TYPE_BMP),isToggle=true)
    EVT_TOOL(self, ID_ZOOM_IN_BUTTON, self.SetMode)
    
    tb.AddTool(ID_ZOOM_OUT_BUTTON, wxBitmap('Mag_minus3.bmp',
wxBITMAP_TYPE_BMP),isToggle=true)
    EVT_TOOL(self, ID_ZOOM_OUT_BUTTON, self.SetMode)

    tb.AddTool(ID_MOVE_MODE_BUTTON, wxBitmap('hand3.bmp',
wxBITMAP_TYPE_BMP),isToggle=true)
    EVT_TOOL(self, ID_MOVE_MODE_BUTTON, self.SetMode)

<snip>
#and here is the set mode method:

  def SetMode(self,event):
    # set all the buttons toggle off
    for id in [ID_ZOOM_IN_BUTTON,ID_ZOOM_OUT_BUTTON,ID_MOVE_MODE_BUTTON]:
      self.ToolBar.ToggleTool(id,0)
    # set the one that was clicked on
    self.ToolBar.ToggleTool(event.GetId(),1)
    if event.GetId() == ID_ZOOM_IN_BUTTON:
      self.Canvas.SetGUIMode("ZoomIn")
    elif event.GetId() == ID_ZOOM_OUT_BUTTON:
      self.Canvas.SetGUIMode("ZoomOut")
    elif event.GetId() == ID_MOVE_MODE_BUTTON:
      self.Canvas.SetGUIMode("Move")

By the way, this would make a nice wiki entry> I doubt I will get a
chance to write it up, but once you get it figured outl, it would be
great if you did...

-Chris

···

--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

Thanks for your comment.
When I've done this, I will write it up in wiki.
By the way, what do you mean by
"> Last I checked, there was not a way to do this automatically, but it

was being worked on, so this info may be old."?

I am new to wxPython and I am asking several things here to get some ideas.
I was from Java and Java has wonderful documentation. I can get everything
from javadoc, but wxPython is not the case. All I have is wiki and wxPython
online document, but wxPython online document is basically wxWindow document
so that it does not reflect the actual classed and methods of wxPython.

From your comment, especially "Last I checked", there might a convenient way

of checking wxPython classes and methods which I don't know as a newbie in
wxPython. Can you point me to a reference or guide to look up the structure
of wxPython? I want to do things by myself as much as I can before I bother
wxPython community.
Thanks in advance.

Young-Jin Lee

···

----- Original Message -----
From: "Chris Barker" <chrishbarker@home.net>
To: <wxpython-users@lists.wxwindows.org>
Sent: Thursday, November 15, 2001 2:48 PM
Subject: Re: [wxPython] [Q] Toolbar and toggle button

Young-Jin Lee wrote:
> But the problem is I don't want more them one
> tool button selected at once. Is there any convenient way to do this?
> In other language, for instance Java, there is a group mechanism which
> allows only one component can be selected.

Last I checked, there was not a way to do this automataically, but it
was being worked on, so this info may be old.

> If it is not in wxPython, how can I implemented it? Any comment would be
> greatly appreciated.

I have done it like this: (code cut and pasted from a larger app, get
ideas form it, it won't run as is.)

## Set up Tool Bar
tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
self.ToolBar = tb

## three toggle buttons, where one can only be active at once:
## they all call the SetMode method below.

tb.AddTool(ID_ZOOM_IN_BUTTON, wxBitmap('Mag_plus3.bmp',
wxBITMAP_TYPE_BMP),isToggle=true)
EVT_TOOL(self, ID_ZOOM_IN_BUTTON, self.SetMode)

tb.AddTool(ID_ZOOM_OUT_BUTTON, wxBitmap('Mag_minus3.bmp',
wxBITMAP_TYPE_BMP),isToggle=true)
EVT_TOOL(self, ID_ZOOM_OUT_BUTTON, self.SetMode)

tb.AddTool(ID_MOVE_MODE_BUTTON, wxBitmap('hand3.bmp',
wxBITMAP_TYPE_BMP),isToggle=true)
EVT_TOOL(self, ID_MOVE_MODE_BUTTON, self.SetMode)

<snip>
#and here is the set mode method:

def SetMode(self,event):
# set all the buttons toggle off
for id in [ID_ZOOM_IN_BUTTON,ID_ZOOM_OUT_BUTTON,ID_MOVE_MODE_BUTTON]:
self.ToolBar.ToggleTool(id,0)
# set the one that was clicked on
self.ToolBar.ToggleTool(event.GetId(),1)
if event.GetId() == ID_ZOOM_IN_BUTTON:
self.Canvas.SetGUIMode("ZoomIn")
elif event.GetId() == ID_ZOOM_OUT_BUTTON:
self.Canvas.SetGUIMode("ZoomOut")
elif event.GetId() == ID_MOVE_MODE_BUTTON:
self.Canvas.SetGUIMode("Move")

By the way, this would make a nice wiki entry> I doubt I will get a
chance to write it up, but once you get it figured outl, it would be
great if you did...

-Chris

--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users