Hello,
I have Python 1.5.2 and wxPython 2.1 for Win32. WxPython is gread, but I have problem: I create wxToolbar and ToolBar Buttons: [...] for x in self.c_list: if x['category'] == page: mID = NewId() print "mID: ",mID tb.AddTool(mID, wxNoRefBitmap(x['icon'], \ wxBITMAP_TYPE_BMP),\ wxNullBitmap, false, -1, -1, x['comment'], x['tooltip']) EVT_TOOL(self, mID, self.OnToolClick) [...] def OnToolClick(self, event): print event.GetEventObject(),": ", type(event.GetEventObject()) This is OK. I Click on ToolButton now: _1286590_wxObject_p: <type 'string'> Is this OK too? I want this: event.GetEventObject().setlabel("TEST") but event.GetEventObject is string, not pointer. Can you help me? Thanks Petr Snajdr _______________________________________________ wxPython-users maillist - [hidden email] http://starship.python.net/mailman/listinfo/wxpython-users |
> This is OK. I Click on ToolButton now:
> > _1286590_wxObject_p: <type 'string'> > > Is this OK too? > > I want this: > > event.GetEventObject().setlabel("TEST") > but event.GetEventObject is string, not pointer. > > Can you help me? There are a couple problems. Since the C++ version of GetEventObject returns a wxObject*, which wxPython doesn't know much about, it just returns the "SWIGified pointer" which is a string. Even if wxPython knew about wxObject it wouldn't help much as it can't tell if it's really a wxWindow, a wxButton, or a wxToolBarTool. For this purpose I have included a helper function called wxPyTypeCast (**) which behaves similarly to a typecast in C++, it allows you to take the swigified pointer and convert it to a specific shadow class object. So in your case: eo = event.GetEventObject() tbt = wxPyTypeCast(eo, "wxToolBarTool") It looks like you are expecting to get a wxButton and be able to set it's label. Unfortunately the toolbar tools are not wxButtons so you are out of luck there. There are several "public members" of the wxToolBarTool that you do have access to, so you might be able to do something like this: tbt.m_bitmap1 = SomeOtherBitmap tbt.m_shortHelpString = "test text" # this is the tooltip You can also change some of these things from the toolbar itself: self.toolbar.SetToolShortHelp(event.GetId(), "test text") (**) the current version of wxPyTypeCast has a bug. If you are using it please edit its definition in wx.py to look like this: def wxPyTypeCast(obj, typeStr): if hasattr(obj, "this"): newPtr = ptrcast(obj.this, typeStr+"_p") else: newPtr = ptrcast(obj, typeStr+"_p") theClass = globals()[typeStr+"Ptr"] theObj = theClass(newPtr) if hasattr(obj, "this"): theObj.thisown = obj.thisown return theObj -- Robin Dunn Software Craftsman [hidden email] http://AllDunn.com/robin/ http://AllDunn.com/wxPython/ Check it out! _______________________________________________ wxPython-users maillist - [hidden email] http://starship.python.net/mailman/listinfo/wxpython-users |
Free forum by Nabble | Edit this page |