]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/wxMenu.py
corrected Unicode conversion when replacing shared library extension with ".rsrc"
[wxWidgets.git] / wxPython / demo / wxMenu.py
index c209977197e72faea56eaf856048645fc5e6dff4..7ee390800adbc5990cb9f2f0dad3d088f4abaef5 100644 (file)
@@ -6,7 +6,7 @@
 #-------------------------------------------------------------------
 
 from wxPython.wx import *
-
+import images
 import time
 
 #-------------------------------------------------------------------
@@ -69,6 +69,11 @@ check the source for this sample to see how to implement them.
         menuBar.Append(menu4, "Chec&k")
 
         menu5 = wxMenu()
+        # Show how to put an icon in the menu
+        item = wxMenuItem(menu5, 500, "&Smile!\tCtrl+S", "This one has an icon")
+        item.SetBitmap(images.getSmilesBitmap())
+        menu5.AppendItem(item)
+
         menu5.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!")
         menu5.AppendSeparator()
         menu5.Append(502, "Hello\tShift+H")
@@ -107,6 +112,7 @@ check the source for this sample to see how to implement them.
 
         EVT_MENU_RANGE(self, 401, 403, self.Menu401To403)
 
+        EVT_MENU(self, 500, self.Menu500)
         EVT_MENU(self, 501, self.Menu501)
         EVT_MENU(self, 502, self.Menu502)
         EVT_MENU(self, 503, self.TestRemove)
@@ -168,6 +174,9 @@ check the source for this sample to see how to implement them.
     def Menu401To403(self, event):
         self.log.write('From a EVT_MENU_RANGE event\n')
 
+    def Menu500(self, event):
+        self.log.write('Have a happy day!\n')
+
     def Menu501(self, event):
         self.log.write('Look in the code how the shortcut has been realized\n')
 
@@ -199,17 +208,26 @@ check the source for this sample to see how to implement them.
 
 
     def TestInsert(self, evt):
+        theID = 508
         # get the menu
         mb = self.GetMenuBar()
-        menuItem = mb.FindItemById(507)
+        menuItem = mb.FindItemById(theID)
         menu = menuItem.GetMenu()
 
+        # figure out the position to insert at
+        pos = 0
+        for i in menu.GetMenuItems():
+            if i.GetId() == theID:
+                break
+            pos += 1
+
+        # now insert the new item
         ID = wxNewId()
-        ##menu.Insert(9, ID, "NewItem " + str(ID))
+        ##menu.Insert(pos, ID, "NewItem " + str(ID))
         item = wxMenuItem(menu)
         item.SetId(ID)
         item.SetText("NewItem " + str(ID))
-        menu.InsertItem(9, item)
+        menu.InsertItem(pos, item)