Menu item - programmatic control

I have a menu item which I like to check/uncheck programmatically and have the menu event fire.

Searched the documentation and the list archive and came up with the following but can't make it work.

I can get the event fired using this code:
    def DoClickMenuItem(self, menuItem):
        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_MENU_SELECTED, menuItem.GetId())
        self.ProcessEvent(clickEvent)

But this does not toggle the state of the menu item (kind = wx.ITEM_CHECK).

So, I do this in addition.
self.GetMenuBar().Check(self.menuHideTabCB.GetId(), bool(hideTabCB))

'hideTabCB' is a string coming from wx.FileConfig and contains either "True" or "False".

But once checked it will not uncheck if the above call gets "False" from the FileConfig.

What am I missing or doing wrong?

Werner

True

You need bool(hideTabCB == "True")

···

On Jul 12, 8:53 am, "Werner F. Bruhin" <wbru...@gmail.com> wrote:

I have a menu item which I like to check/uncheck programmatically and
have the menu event fire.

Searched the documentation and the list archive and came up with the
following but can't make it work.

I can get the event fired using this code:
def DoClickMenuItem(self, menuItem):
clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_MENU_SELECTED,
menuItem.GetId())
self.ProcessEvent(clickEvent)

But this does not toggle the state of the menu item (kind = wx.ITEM_CHECK).

So, I do this in addition.
self.GetMenuBar().Check(self.menuHideTabCB.GetId(), bool(hideTabCB))

'hideTabCB' is a string coming from wx.FileConfig and contains either
"True" or "False".

But once checked it will not uncheck if the above call gets "False" from
the FileConfig.

What am I missing or doing wrong?

Werner

bool("False")

Phil,

Phil Mayes wrote:

True

You need bool(hideTabCB == "True")
  

This will check it (which works for me), but how do I un-check the menu item?

I thought passing "False" would do it but ....

Werner

Phil,

Phil Mayes wrote:
> True

> You need bool(hideTabCB == "True")

This will check it (which works for me), but how do I un-check the menu
item?

I thought passing "False" would do it but ....

Werner

No, you probably overlooked that it's a string comparison:

s = "True"
bool(s)

True

bool(s == "True")

True

s = "False"
bool(s)

True <--- this is True because the string is not empty

bool(s == "True")

False <--- This is False because the string is not "True"

···

On Jul 12, 11:23 am, "Werner F. Bruhin" <wbru...@gmail.com> wrote:

Phil,

Phil Mayes wrote:

···

On Jul 12, 11:23 am, "Werner F. Bruhin" <wbru...@gmail.com> wrote:
  

Phil,

Phil Mayes wrote:
    

True
      You need bool(hideTabCB == "True")
      

This will check it (which works for me), but how do I un-check the menu
item?

I thought passing "False" would do it but ....

Werner
    
No, you probably overlooked that it's a string comparison:
  

Yeap, that was my mistake. Thanks for clarifying it.

Werner

Hi,

I have a class that starts like this:

class Repository(wx.Dialog):
def init(self, parent, id, title, logs, logs_to_use_list):
wx.Dialog.init(self, None, id, title, style=wx.RESIZE_BORDER|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX, size = (1300,200))

But the instances of this class are windows that cannot be resized, nor have they minimize/maximize capabilities.

Sample such window looks like so (on Windows XP):

Outlook.jpg

Could you point me in the right direction of creating a descendant class of wx.Dialog that can be resized ?

Thanks,
Ron.

Ron,

···

wxPython-users.comverse@9ox.net wrote:

Hi,

I have a class that starts like this:

class Repository(wx.Dialog):
    def __init__(self, parent, id, title, logs, logs_to_use_list):
        wx.Dialog.__init__(self, None, id, title, style=wx.RESIZE_BORDER|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX, size = (1300,200))

Try this:
style=wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE,

Without the last one I get a dialog without any title bar.

Werner