[wxPython] ToggleTool in wxToolBar

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] ToggleTool in wxToolBar

Robin Barendregt-2
Hi all,

I'm having trouble getting ToggleTool to work for my toolbar when it is
parented by a notebook.
I just can seem to figure out why, please someone enlighten me :)

Tia,
Robin Barendregt

Here's the code. Take out comments and the toggling stops working..

#-----
from wxPython.wx import *


class MyFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, id, title, wxPoint(100,100),
                         wxSize(50,55), wxDEFAULT_FRAME_STYLE)

        self.SetAutoLayout(true)

#        nb = wxNotebook(self, -1)

#        self.palette = nb

#        lc = wxLayoutConstraints()
#        lc.top.SameAs(self, wxTop)
#        lc.bottom.SameAs(self, wxBottom)
#        lc.left.SameAs(self, wxLeft)
#        lc.right.SameAs(self, wxRight)

#        nb.SetConstraints(lc)

#        tb = wxToolBar(nb, -1, wxDefaultPosition, wxDefaultSize,
        tb = wxToolBar(self, -1, wxDefaultPosition, wxDefaultSize,
                       wxTB_HORIZONTAL | wxNO_BORDER)

        id = NewId()

        tb.AddTool(id, wxNullBitmap, wxNullBitmap, true, NULL, "Test")

        EVT_TOOL(self, id, self.toolClicked)

        id = NewId()

        tb.AddTool(id, wxNullBitmap, wxNullBitmap, true, NULL, "Test")

        EVT_TOOL(self, id, self.toolClicked)

        tb.Realize()

        self.toolBar = tb

        self.selId = 0


    def toolClicked(self, event):
        if self.selId > 0:
            self.toolBar.ToggleTool(self.selId, false)
        self.selId = event.GetId()


class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(NULL, -1, "Test")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true


app = MyApp(0)
app.MainLoop()
#-----


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users