%newgroup
+MustHaveApp(wxMenu);
+
class wxMenu : public wxEvtHandler
{
public:
- %addtofunc wxMenu "self._setOORInfo(self)"
+ %pythonAppend wxMenu "self._setOORInfo(self)"
+ %typemap(out) wxMenu*; // turn off this typemap
+
wxMenu(const wxString& title = wxPyEmptyString, long style = 0);
+ // Turn it back on again
+ %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, $owner); }
+
// append any kind of item (normal/check/radio/separator)
- void Append(int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString,
- wxItemKind kind = wxITEM_NORMAL);
+ wxMenuItem* Append(int id,
+ const wxString& text = wxPyEmptyString,
+ const wxString& help = wxPyEmptyString,
+ wxItemKind kind = wxITEM_NORMAL);
// append a separator to the menu
- void AppendSeparator();
+ wxMenuItem* AppendSeparator();
// append a check item
- void AppendCheckItem(int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString);
+ wxMenuItem* AppendCheckItem(int id,
+ const wxString& text,
+ const wxString& help = wxPyEmptyString);
// append a radio item
- void AppendRadioItem(int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString);
+ wxMenuItem* AppendRadioItem(int id,
+ const wxString& text,
+ const wxString& help = wxPyEmptyString);
// append a submenu
- %name(AppendMenu)void Append(int itemid,
- const wxString& text,
- wxMenu *submenu,
- const wxString& help = wxPyEmptyString);
+ %Rename(AppendMenu, wxMenuItem*, Append(int id,
+ const wxString& text,
+ wxMenu *submenu,
+ const wxString& help = wxPyEmptyString));
+
+ wxMenuItem* AppendSubMenu(wxMenu *submenu,
+ const wxString& text,
+ const wxString& help = wxPyEmptyString);
+ %disownarg(wxMenuItem*);
// the most generic form of Append() - append anything
- %name(AppendItem) void Append(wxMenuItem *item);
+ %Rename(AppendItem, wxMenuItem*, Append(wxMenuItem *item));
+ // insert an item before given position
+ %Rename(InsertItem, wxMenuItem*, Insert(size_t pos, wxMenuItem *item));
+ // prepend an item to the menu
+ %Rename(PrependItem, wxMenuItem*, Prepend(wxMenuItem *item));
+ %cleardisown(wxMenuItem*);
+
// insert a break in the menu (only works when appending the items, not
// inserting them)
virtual void Break();
// insert an item before given position
- %name(InsertItem) bool Insert(size_t pos, wxMenuItem *item);
-
- // insert an item before given position
- void Insert(size_t pos,
- int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString,
- wxItemKind kind = wxITEM_NORMAL);
+ wxMenuItem* Insert(size_t pos,
+ int id,
+ const wxString& text = wxPyEmptyString,
+ const wxString& help = wxPyEmptyString,
+ wxItemKind kind = wxITEM_NORMAL);
// insert a separator
- void InsertSeparator(size_t pos);
+ wxMenuItem* InsertSeparator(size_t pos);
// insert a check item
- void InsertCheckItem(size_t pos,
- int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString);
+ wxMenuItem* InsertCheckItem(size_t pos,
+ int id,
+ const wxString& text,
+ const wxString& help = wxPyEmptyString);
// insert a radio item
- void InsertRadioItem(size_t pos,
- int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString);
+ wxMenuItem* InsertRadioItem(size_t pos,
+ int id,
+ const wxString& text,
+ const wxString& help = wxPyEmptyString);
// insert a submenu
- %name(InsertMenu) void Insert(size_t pos,
- int itemid,
- const wxString& text,
- wxMenu *submenu,
- const wxString& help = wxPyEmptyString);
-
- // prepend an item to the menu
- %name(PrependItem)void Prepend(wxMenuItem *item);
+ %Rename(InsertMenu, wxMenuItem*, Insert(size_t pos,
+ int id,
+ const wxString& text,
+ wxMenu *submenu,
+ const wxString& help = wxPyEmptyString));
// prepend any item to the menu
- void Prepend(int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString,
- wxItemKind kind = wxITEM_NORMAL);
+ wxMenuItem* Prepend(int id,
+ const wxString& text = wxPyEmptyString,
+ const wxString& help = wxPyEmptyString,
+ wxItemKind kind = wxITEM_NORMAL);
// prepend a separator
- void PrependSeparator();
+ wxMenuItem* PrependSeparator();
// prepend a check item
- void PrependCheckItem(int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString);
+ wxMenuItem* PrependCheckItem(int id,
+ const wxString& text,
+ const wxString& help = wxPyEmptyString);
// prepend a radio item
- void PrependRadioItem(int itemid,
- const wxString& text,
- const wxString& help = wxPyEmptyString);
+ wxMenuItem* PrependRadioItem(int id,
+ const wxString& text,
+ const wxString& help = wxPyEmptyString);
// prepend a submenu
- %name(PrependMenu)void Prepend(int itemid,
- const wxString& text,
- wxMenu *submenu,
- const wxString& help = wxPyEmptyString);
+ %Rename(PrependMenu, wxMenuItem*, Prepend(int id,
+ const wxString& text,
+ wxMenu *submenu,
+ const wxString& help = wxPyEmptyString));
+
// detach an item from the menu, but don't delete it so that it can be
// added back later (but if it's not, the caller is responsible for
// deleting it!)
- wxMenuItem *Remove(int itemid);
- %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
-
+ %newobject Remove;
+ wxMenuItem *Remove(int id);
+
+ %feature("shadow") Remove(wxMenuItem *item) %{
+ def RemoveItem(self, item):
+ """RemoveItem(self, MenuItem item) -> MenuItem"""
+ #// The return object is always the parameter, so return that
+ #// proxy instead of the new one
+ val = _core_.Menu_RemoveItem(self, item)
+ item.this.own(val.this.own())
+ val.this.disown()
+ return item
+ %}
+ %Rename(RemoveItem, wxMenuItem*, Remove(wxMenuItem *item));
+
// delete an item from the menu (submenus are not destroyed by this
// function, see Destroy)
- bool Delete(int itemid);
- %name(DeleteItem) bool Delete(wxMenuItem *item);
+ bool Delete(int id);
+ %Rename(DeleteItem, bool, Delete(wxMenuItem *item));
- // delete the item from menu and destroy it (if it's a submenu)
+ %pythonPrepend Destroy "args[0].this.own(False)"
%extend { void Destroy() { delete self; } }
- %name(DestroyId) bool Destroy(int itemid);
- %name(DestroyItem) bool Destroy(wxMenuItem *item);
+
+ // delete the item from menu and destroy it (if it's a submenu)
+ %pythonPrepend Destroy "";
+ DocDeclStrName(
+ bool , Destroy(int id),
+ "", "",
+ DestroyId);
+
+ DocDeclStrName(
+ bool , Destroy(wxMenuItem *item),
+ "", "",
+ DestroyItem);
// get the items
// search
int FindItem(const wxString& item) const;
- %name(FindItemById) wxMenuItem* FindItem(int itemid /*, wxMenu **menu = NULL*/) const;
+ %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
// find by position
wxMenuItem* FindItemByPosition(size_t position) const;
// get/set items attributes
- void Enable(int itemid, bool enable);
- bool IsEnabled(int itemid) const;
+ void Enable(int id, bool enable);
+ bool IsEnabled(int id) const;
- void Check(int itemid, bool check);
- bool IsChecked(int itemid) const;
+ void Check(int id, bool check);
+ bool IsChecked(int id) const;
- void SetLabel(int itemid, const wxString& label);
- wxString GetLabel(int itemid) const;
+ void SetLabel(int id, const wxString& label);
+ wxString GetLabel(int id) const;
- virtual void SetHelpString(int itemid, const wxString& helpString);
- virtual wxString GetHelpString(int itemid) const;
+ virtual void SetHelpString(int id, const wxString& helpString);
+ virtual wxString GetHelpString(int id) const;
// the title
// set/get the parent of this menu
void SetParent(wxMenu *parent);
wxMenu *GetParent() const;
+
+ %property(EventHandler, GetEventHandler, SetEventHandler, doc="See `GetEventHandler` and `SetEventHandler`");
+ %property(HelpString, GetHelpString, SetHelpString, doc="See `GetHelpString` and `SetHelpString`");
+ %property(InvokingWindow, GetInvokingWindow, SetInvokingWindow, doc="See `GetInvokingWindow` and `SetInvokingWindow`");
+ %property(MenuBar, GetMenuBar, doc="See `GetMenuBar`");
+ %property(MenuItemCount, GetMenuItemCount, doc="See `GetMenuItemCount`");
+ %property(MenuItems, GetMenuItems, doc="See `GetMenuItems`");
+ %property(Parent, GetParent, SetParent, doc="See `GetParent` and `SetParent`");
+ %property(Style, GetStyle, doc="See `GetStyle`");
+ %property(Title, GetTitle, SetTitle, doc="See `GetTitle` and `SetTitle`");
+
};
//---------------------------------------------------------------------------
%newgroup
+MustHaveApp(wxMenuBar);
+
class wxMenuBar : public wxWindow
{
public:
- %addtofunc wxMenuBar "self._setOORInfo(self)"
+ %pythonAppend wxMenuBar "self._setOORInfo(self)"
+ %typemap(out) wxMenuBar*; // turn off this typemap
+
wxMenuBar(long style = 0);
+ // Turn it back on again
+ %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
- // append a menu to the end of menubar, return TRUE if ok
+ // append a menu to the end of menubar, return True if ok
virtual bool Append(wxMenu *menu, const wxString& title);
- // insert a menu before the given position into the menubar, return TRUE
+ // insert a menu before the given position into the menubar, return True
// if inserted ok
virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
virtual void EnableTop(size_t pos, bool enable);
// is the menu enabled?
- virtual bool IsEnabledTop(size_t WXUNUSED(pos)) const { return TRUE; }
+ virtual bool IsEnabledTop(size_t pos) const;
// get or change the label of the menu at given position
virtual void SetLabelTop(size_t pos, const wxString& label);
// find item by id (in any menu), returns NULL if not found
//
// if menu is !NULL, it will be filled with wxMenu this item belongs to
- %name(FindItemById) virtual wxMenuItem* FindItem(int itemid /*, wxMenu **menu = NULL*/) const;
+ %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
// find menu by its caption, return wxNOT_FOUND on failure
- int FindMenu(const wxString& title) const;
+ int FindMenu(const wxString& title);
// all these functions just use FindItem() and then call an appropriate
// NB: under MSW, these methods can only be used after the menubar had
// been attached to the frame
- void Enable(int itemid, bool enable);
- void Check(int itemid, bool check);
- bool IsChecked(int itemid) const;
- bool IsEnabled(int itemid) const;
-
- void SetLabel(int itemid, const wxString &label);
- wxString GetLabel(int itemid) const;
+ void Enable(int id, bool enable);
+ void Check(int id, bool check);
+ bool IsChecked(int id) const;
+ bool IsEnabled(int id) const;
+ // TODO: bool IsEnabled() const;
+
+ void SetLabel(int id, const wxString &label);
+ wxString GetLabel(int id) const;
- void SetHelpString(int itemid, const wxString& helpString);
- wxString GetHelpString(int itemid) const;
+ void SetHelpString(int id, const wxString& helpString);
+ wxString GetHelpString(int id) const;
// get the frame we are attached to (may return NULL)
wxFrame *GetFrame() const;
- // returns TRUE if we're attached to a frame
+ // returns True if we're attached to a frame
bool IsAttached() const;
// associate the menubar with the frame
// called before deleting the menubar normally
virtual void Detach();
+
+ // update all menu item states in all menus
+ virtual void UpdateMenus();
+
+#ifdef __WXMAC__
+ static void SetAutoWindowMenu( bool enable );
+ static bool GetAutoWindowMenu();
+#else
+ %extend {
+ static void SetAutoWindowMenu( bool enable ) {}
+ static bool GetAutoWindowMenu() { return false; }
+ }
+#endif
+
+ %pythoncode {
+ def GetMenus(self):
+ """Return a list of (menu, label) items for the menus in the MenuBar. """
+ return [(self.GetMenu(i), self.GetLabelTop(i))
+ for i in range(self.GetMenuCount())]
+
+ def SetMenus(self, items):
+ """Clear and add new menus to the MenuBar from a list of (menu, label) items. """
+ for i in range(self.GetMenuCount()-1, -1, -1):
+ self.Remove(i)
+ for m, l in items:
+ self.Append(m, l)
+ }
+
+ %property(Frame, GetFrame, doc="See `GetFrame`");
+ %property(Menu, GetMenu, doc="See `GetMenu`");
+ %property(MenuCount, GetMenuCount, doc="See `GetMenuCount`");
+ %property(Menus, GetMenus, SetMenus, doc="See `GetMenus` and `SetMenus`");
};
//---------------------------------------------------------------------------
class wxMenuItem : public wxObject {
public:
+ // turn off this typemap
+ %typemap(out) wxMenuItem*;
+
wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
const wxString& text = wxPyEmptyString,
const wxString& help = wxPyEmptyString,
wxItemKind kind = wxITEM_NORMAL,
wxMenu* subMenu = NULL);
+ ~wxMenuItem();
+
+ // Turn it back on again
+ %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, $owner); }
+ // Make Destroy a NOP. The destruction will be handled by SWIG.
+ %pythoncode { def Destroy(self): pass }
+
+
// the menu we're in
wxMenu *GetMenu() const;
void SetMenu(wxMenu* menu);
// get/set id
- void SetId(int itemid);
+ void SetId(int id);
int GetId() const;
bool IsSeparator() const;
// what kind of menu item we are
wxItemKind GetKind() const;
+ void SetKind(wxItemKind kind);
virtual void SetCheckable(bool checkable);
bool IsCheckable() const;
wxMenu *GetSubMenu() const;
// state
- virtual void Enable(bool enable = TRUE);
+ virtual void Enable(bool enable = true);
virtual bool IsEnabled() const;
- virtual void Check(bool check = TRUE);
+ virtual void Check(bool check = true);
virtual bool IsChecked() const;
void Toggle();
// SetText()
virtual void SetAccel(wxAcceleratorEntry *accel);
-
+ void SetBitmap(const wxBitmap& bitmap);
+ const wxBitmap& GetBitmap();
+
// wxOwnerDrawn methods
#ifdef __WXMSW__
void SetFont(const wxFont& font);
bool IsOwnerDrawn();
// switch on/off owner-drawing the item
- void SetOwnerDrawn(bool ownerDrawn = TRUE);
+ void SetOwnerDrawn(bool ownerDrawn = true);
void ResetOwnerDrawn();
#else
- // just to keep the global renamers in sync
%extend {
+ void SetFont(const wxFont& font) {}
+ wxFont GetFont() { return wxNullFont; }
+ void SetTextColour(const wxColour& colText) {}
+ wxColour GetTextColour() { return wxNullColour; }
+ void SetBackgroundColour(const wxColour& colBack) {}
+ wxColour GetBackgroundColour() { return wxNullColour; }
+
+ void SetBitmaps(const wxBitmap& bmpChecked,
+ const wxBitmap& bmpUnchecked = wxNullBitmap)
+ { self->SetBitmap( bmpChecked ); }
+
+ void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {}
+ const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; }
+
+ void SetMarginWidth(int nWidth) {}
+ int GetMarginWidth() { return 0; }
static int GetDefaultMarginWidth() { return 0; }
+ bool IsOwnerDrawn() { return false; }
+ void SetOwnerDrawn(bool ownerDrawn = true) {}
+ void ResetOwnerDrawn() {}
}
#endif
- void SetBitmap(const wxBitmap& bitmap);
- const wxBitmap& GetBitmap();
+ %property(Accel, GetAccel, SetAccel, doc="See `GetAccel` and `SetAccel`");
+ %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
+ %property(Bitmap, GetBitmap, SetBitmap, doc="See `GetBitmap` and `SetBitmap`");
+ %property(DisabledBitmap, GetDisabledBitmap, SetDisabledBitmap, doc="See `GetDisabledBitmap` and `SetDisabledBitmap`");
+ %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
+ %property(Help, GetHelp, SetHelp, doc="See `GetHelp` and `SetHelp`");
+ %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
+ %property(Kind, GetKind, SetKind, doc="See `GetKind` and `SetKind`");
+ %property(Label, GetLabel, doc="See `GetLabel`");
+ %property(MarginWidth, GetMarginWidth, SetMarginWidth, doc="See `GetMarginWidth` and `SetMarginWidth`");
+ %property(Menu, GetMenu, SetMenu, doc="See `GetMenu` and `SetMenu`");
+ %property(SubMenu, GetSubMenu, SetSubMenu, doc="See `GetSubMenu` and `SetSubMenu`");
+ %property(Text, GetText, SetText, doc="See `GetText` and `SetText`");
+ %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
+
};
//---------------------------------------------------------------------------