Phoenix - wx.NewId returns long but AddTool complains about it

Hi,

wx.NewId()
115L

Still in matplotlib, I use this for Phoenix toolbar:

             self.wx_ids[text] = wx.NewId()
             if 'phoenix' in wx.PlatformInfo:
                 if text in ['Pan', 'Zoom']:
                     self.AddTool(self.wx_ids[text], label=text,
                                  bitmap=_load_bitmap(image_file + '.png'),
                                  shortHelpString=text,
                                  longHelpString=tooltip_text,
                                  kind=wx.ITEM_CHECK)
                 else:
                     self.AddTool(self.wx_ids[text], label=text,
                                  bitmap=_load_bitmap(image_file + '.png'),
                                  shortHelpString=text,
                                  longHelpString=tooltip_text,
                                  kind=wx.ITEM_NORMAL)

But get the following exception:

TypeError: ToolBar.AddTool(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'long'
overload 2: 'longHelpString' is not a valid keyword argument
overload 3: 'kind' is not a valid keyword argument
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 58, in <module>
   demo()
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 48, in demo
   axes1 = plotter.add('figure 1').gca()
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 39, in add
   page = Plot(self.nb)
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 22, in __init__
   self.toolbar = Toolbar(self.canvas)
File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py", line 1805, in __init__
   NavigationToolbar2.__init__(self, canvas)
File "c:\Python27\Lib\site-packages\matplotlib\backend_bases.py", line 2567, in __init__
   self._init_toolbar()
File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py", line 1837, in _init_toolbar
   kind=wx.ITEM_NORMAL)

Werner

Werner wrote:

Hi,

wx.NewId()
115L

Still in matplotlib, I use this for Phoenix toolbar:

self.wx_ids[text] = wx.NewId()
if 'phoenix' in wx.PlatformInfo:
if text in ['Pan', 'Zoom']:
self.AddTool(self.wx_ids[text], label=text,
bitmap=_load_bitmap(image_file + '.png'),
shortHelpString=text,
longHelpString=tooltip_text,
kind=wx.ITEM_CHECK)
else:
self.AddTool(self.wx_ids[text], label=text,
bitmap=_load_bitmap(image_file + '.png'),
shortHelpString=text,
longHelpString=tooltip_text,
kind=wx.ITEM_NORMAL)

But get the following exception:

TypeError: ToolBar.AddTool(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'long'

I think something has changed there as I thought that the wrappers would accept Python longs where an C int is expected, with a warning if the value would be truncated. I'll check in to that when I get back home. In the meantime you could use int() to downcast it yourself, like:

     self.wx_ids[text] = int(wx.NewId())

···

--
Robin Dunn
Software Craftsman

If I do that then I get this exception:

TypeError: ToolBar.AddTool(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'int'
overload 2: 'longHelpString' is not a valid keyword argument
overload 3: 'kind' is not a valid keyword argument
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 63, in <module>
   demo()
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 53, in demo
   axes1 = plotter.add('figure 1').gca()
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 44, in add
   page = Plot(self.nb)
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 27, in __init__
   self.toolbar = Toolbar(self.canvas)
File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py", line 1808, in __init__
   NavigationToolbar2.__init__(self, canvas)
File "c:\Python27\Lib\site-packages\matplotlib\backend_bases.py", line 2567, in __init__
   self._init_toolbar()
File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py", line 1840, in _init_toolbar
   kind=wx.ITEM_NORMAL)

Hopefully this helps you in narrowing it down when you get home.

Have a nice weekend
Werner

···

On 19/04/2013 22:24, Robin Dunn wrote:

Werner wrote:

Hi,

wx.NewId()
115L

Still in matplotlib, I use this for Phoenix toolbar:

self.wx_ids[text] = wx.NewId()
if 'phoenix' in wx.PlatformInfo:
if text in ['Pan', 'Zoom']:
self.AddTool(self.wx_ids[text], label=text,
bitmap=_load_bitmap(image_file + '.png'),
shortHelpString=text,
longHelpString=tooltip_text,
kind=wx.ITEM_CHECK)
else:
self.AddTool(self.wx_ids[text], label=text,
bitmap=_load_bitmap(image_file + '.png'),
shortHelpString=text,
longHelpString=tooltip_text,
kind=wx.ITEM_NORMAL)

But get the following exception:

TypeError: ToolBar.AddTool(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'long'

I think something has changed there as I thought that the wrappers would accept Python longs where an C int is expected, with a warning if the value would be truncated. I'll check in to that when I get back home. In the meantime you could use int() to downcast it yourself, like:

    self.wx_ids[text] = int(wx.NewId())

werner wrote:

Werner wrote:

Hi,

wx.NewId()
115L

Still in matplotlib, I use this for Phoenix toolbar:

self.wx_ids[text] = wx.NewId()
if 'phoenix' in wx.PlatformInfo:
if text in ['Pan', 'Zoom']:
self.AddTool(self.wx_ids[text], label=text,
bitmap=_load_bitmap(image_file + '.png'),
shortHelpString=text,
longHelpString=tooltip_text,
kind=wx.ITEM_CHECK)
else:
self.AddTool(self.wx_ids[text], label=text,
bitmap=_load_bitmap(image_file + '.png'),
shortHelpString=text,
longHelpString=tooltip_text,
kind=wx.ITEM_NORMAL)

But get the following exception:

TypeError: ToolBar.AddTool(): arguments did not match any overloaded
call:
overload 1: argument 1 has unexpected type 'long'

I think something has changed there as I thought that the wrappers
would accept Python longs where an C int is expected, with a warning
if the value would be truncated. I'll check in to that when I get back
home. In the meantime you could use int() to downcast it yourself, like:

self.wx_ids[text] = int(wx.NewId())

If I do that then I get this exception:

TypeError: ToolBar.AddTool(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'int'
overload 2: 'longHelpString' is not a valid keyword argument
overload 3: 'kind' is not a valid keyword argument
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 63, in
<module>
demo()
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 53, in
demo
axes1 = plotter.add('figure 1').gca()
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 44, in add
page = Plot(self.nb)
File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 27, in
__init__
self.toolbar = Toolbar(self.canvas)
File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py",
line 1808, in __init__
NavigationToolbar2.__init__(self, canvas)
File "c:\Python27\Lib\site-packages\matplotlib\backend_bases.py", line
2567, in __init__
self._init_toolbar()
File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py",
line 1840, in _init_toolbar
kind=wx.ITEM_NORMAL)

Hopefully this helps you in narrowing it down when you get home.

Here are the available overloads of AddTool:

     wxToolBarToolBase* AddTool(wxToolBarToolBase* tool);

     wxToolBarToolBase* AddTool(int toolId, const wxString& label,
                                const wxBitmap& bitmap,
                                const wxString& shortHelp = wxEmptyString,
                                wxItemKind kind = wxITEM_NORMAL);

     wxToolBarToolBase* AddTool(int toolId, const wxString& label,
                                const wxBitmap& bitmap,
                                const wxBitmap& bmpDisabled,
                                wxItemKind kind = wxITEM_NORMAL,
                                const wxString& shortHelpString = wxEmptyString,
                                const wxString& longHelpString = wxEmptyString,
                                wxObject* clientData = NULL);

So your call is not matching one of those, due using the longHelpString keyword and not providing the 2nd bitmap. Not sure why it isn't liking the kind keyword though...

···

On 19/04/2013 22:24, Robin Dunn wrote:

--
Robin Dunn
Software Craftsman

Hi Robin,

...

Here are the available overloads of AddTool:

    wxToolBarToolBase* AddTool(wxToolBarToolBase* tool);

    wxToolBarToolBase* AddTool(int toolId, const wxString& label,
                               const wxBitmap& bitmap,
                               const wxString& shortHelp = wxEmptyString,
                               wxItemKind kind = wxITEM_NORMAL);

    wxToolBarToolBase* AddTool(int toolId, const wxString& label,
                               const wxBitmap& bitmap,
                               const wxBitmap& bmpDisabled,
                               wxItemKind kind = wxITEM_NORMAL,
                               const wxString& shortHelpString = wxEmptyString,
                               const wxString& longHelpString = wxEmptyString,
                               wxObject* clientData = NULL);

So your call is not matching one of those, due using the longHelpString keyword and not providing the 2nd bitmap. Not sure why it isn't liking the kind keyword though...

Sorry, should have seen that bmpDisabled has no default, when I added "bmpDisabled=wx.NullBitmap," then it works.

Werner

···

On 19/04/2013 23:49, Robin Dunn wrote: