Menu.Append returning None

Robert Liebeskind wrote:

Hi Mike,

Thanks for your reply. I am not sure how to keep the conversation thread going.. Perhaps I should reply some other way? Below is my original message and your response.

I am not re-assigning cancel before trying to act on the menuitem. Here is the relevant snippet
of code:

                tmp_menu = wx.Menu()
                if rx['Status'] == 'Printed':
                    cancel = tmp_menu.Append(-1, "Reject", "", wx.ITEM_NORMAL)
                else:
                    cancel = tmp_menu.Append(-1, "Cancel", "", wx.ITEM_NORMAL)
                Id = cancel.GetId()

The error occurs when I call cancel.GetId()

Any other ideas?

I'm not seeing anything obvious. I tried adding a GetId() to some of my sample code and it worked for me. Here's my sample code. Maybe you can see the difference between mine and yours (I also included a little introspection with "type" and "dir):

<code>

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent = None, id = -1, title = "Small Editor"):
        wx.Frame.__init__(
            self, parent, id ,title, size = (400,200),
            style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
        )
        self.control = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
        #--- START MENU CODE:

···

---------------------------------------------------
        self.CreateStatusBar()
        #------ Setting up the menu.
        filemenu = wx.Menu()
        about = filemenu.Append(-1, "&About", "Information about this program")
        print type(about)
        print
        print dir(about)
        print
        print about.GetId()
        filemenu.AppendSeparator()
        filemenu.Append(-1, "E&xit", "Terminate the program")
        #------ Creating the menu.
        menubar = wx.MenuBar()
        menubar.Append(filemenu, "&File")
        self.SetMenuBar(menubar)
        #--- END MENU CODE ------------------------------------------------------
        self.Show(True)

app = wx.PySimpleApp()
frame = MainWindow()
app.MainLoop()

</code>

Can you tell me how to properly respond to the mail list?

Sometimes you need to hit "Reply All" to get the wxPython email address in the TO field. But if it's not there, just put it in. Here it is for reference: wxpython-users@lists.wxwidgets.org

Thanks for your help,

Rob.

<snip>

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Hi Mike again,

Perhaps I was not clear about the fact that my codes works 999 times out of 1000. It only fails intermittently.
I do not see a significant difference between how you did it and how I did.

I do not think there is a python code issue here.. Could there be a failure occurring in the menu.Append call
that does not raise anything but results in the call return None?

Thanks for your help,

Rob.

···

On Feb 27, 2009, at 2:18 PM, Mike Driscoll wrote:

Robert Liebeskind wrote:

Hi Mike,
Thanks for your reply. I am not sure how to keep the conversation thread going.. Perhaps I should reply some other way? Below is my original message and your response.

I am not re-assigning cancel before trying to act on the menuitem. Here is the relevant snippet
of code:

               tmp_menu = wx.Menu()
               if rx['Status'] == 'Printed':
                   cancel = tmp_menu.Append(-1, "Reject", "", wx.ITEM_NORMAL)
               else:
                   cancel = tmp_menu.Append(-1, "Cancel", "", wx.ITEM_NORMAL)
               Id = cancel.GetId()

The error occurs when I call cancel.GetId()

Any other ideas?

I'm not seeing anything obvious. I tried adding a GetId() to some of my sample code and it worked for me. Here's my sample code. Maybe you can see the difference between mine and yours (I also included a little introspection with "type" and "dir):

<code>

import wx

class MainWindow(wx.Frame):
  def __init__(self, parent = None, id = -1, title = "Small Editor"):
      wx.Frame.__init__(
          self, parent, id ,title, size = (400,200),
          style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
      )
      self.control = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
      #--- START MENU CODE: ---------------------------------------------------
      self.CreateStatusBar()
      #------ Setting up the menu.
      filemenu = wx.Menu()
      about = filemenu.Append(-1, "&About", "Information about this program")
      print type(about)
      print
      print dir(about)
      print
      print about.GetId()
      filemenu.AppendSeparator()
      filemenu.Append(-1, "E&xit", "Terminate the program")
      #------ Creating the menu.
      menubar = wx.MenuBar()
      menubar.Append(filemenu, "&File")
      self.SetMenuBar(menubar)
      #--- END MENU CODE ------------------------------------------------------
      self.Show(True)

app = wx.PySimpleApp()
frame = MainWindow()
app.MainLoop()

</code>

Can you tell me how to properly respond to the mail list?

Sometimes you need to hit "Reply All" to get the wxPython email address in the TO field. But if it's not there, just put it in. Here it is for reference: wxpython-users@lists.wxwidgets.org

Thanks for your help,

Rob.

<snip>

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Robert Liebeskind wrote:

Hi Mike again,

Perhaps I was not clear about the fact that my codes works 999 times out of 1000. It only fails intermittently.
I do not see a significant difference between how you did it and how I did.

I do not think there is a python code issue here.. Could there be a failure occurring in the menu.Append call
that does not raise anything but results in the call return None?

Not that I'm aware of. I don't see any reason for it to ever return None from the code you've given. Maybe one of the other guys will have a clue?

- Mike

···

Thanks for your help,

Rob.

On Feb 27, 2009, at 2:18 PM, Mike Driscoll wrote:

Robert Liebeskind wrote:

Hi Mike,
Thanks for your reply. I am not sure how to keep the conversation thread going.. Perhaps I should reply some other way? Below is my original message and your response.

I am not re-assigning cancel before trying to act on the menuitem. Here is the relevant snippet
of code:

               tmp_menu = wx.Menu()
               if rx['Status'] == 'Printed':
                   cancel = tmp_menu.Append(-1, "Reject", "", wx.ITEM_NORMAL)
               else:
                   cancel = tmp_menu.Append(-1, "Cancel", "", wx.ITEM_NORMAL)
               Id = cancel.GetId()

The error occurs when I call cancel.GetId()

Any other ideas?

I'm not seeing anything obvious. I tried adding a GetId() to some of my sample code and it worked for me. Here's my sample code. Maybe you can see the difference between mine and yours (I also included a little introspection with "type" and "dir):

<code>

import wx

class MainWindow(wx.Frame):
  def __init__(self, parent = None, id = -1, title = "Small Editor"):
      wx.Frame.__init__(
          self, parent, id ,title, size = (400,200),
          style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
      )
      self.control = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
      #--- START MENU CODE: ---------------------------------------------------
      self.CreateStatusBar()
      #------ Setting up the menu.
      filemenu = wx.Menu()
      about = filemenu.Append(-1, "&About", "Information about this program")
      print type(about)
      print
      print dir(about)
      print
      print about.GetId()
      filemenu.AppendSeparator()
      filemenu.Append(-1, "E&xit", "Terminate the program")
      #------ Creating the menu.
      menubar = wx.MenuBar()
      menubar.Append(filemenu, "&File")
      self.SetMenuBar(menubar)
      #--- END MENU CODE ------------------------------------------------------
      self.Show(True)

app = wx.PySimpleApp()
frame = MainWindow()
app.MainLoop()

</code>

Can you tell me how to properly respond to the mail list?

Sometimes you need to hit "Reply All" to get the wxPython email address in the TO field. But if it's not there, just put it in. Here it is for reference: wxpython-users@lists.wxwidgets.org

Thanks for your help,

Rob.

<snip>

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

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

Robert Liebeskind wrote:

Hi Mike again,

Perhaps I was not clear about the fact that my codes works 999 times out of 1000. It only fails intermittently.
I do not see a significant difference between how you did it and how I did.

I do not think there is a python code issue here.. Could there be a failure occurring in the menu.Append call
that does not raise anything but results in the call return None?

What platform?

I took a quick glance at some of the menu C++ code and didn't see anything that explicitly returns NULL for error conditions, so the only thing that comes to mind is a memory allocation failure. But if that were the case that I would think that there would be lots of other problems manifesting at the same time, and probably some worse ones.

Can you think of anything that the failure situations may have in common besides the location in the code? (State of the system, other processes running, etc.) If this menu is used with PopupMenu do you Destroy() it when done with it?

If there is not a consistent way to reproduce the problem then I'm not sure there is anything that can be done about it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!