summaryrefslogtreecommitdiffstats
path: root/Mac/Lib
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1998-05-06 15:33:09 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1998-05-06 15:33:09 (GMT)
commitbb6193c553fca0532f78af80a8f745c305144b87 (patch)
tree92d57164c834e398cc3017593a844203950fc6d2 /Mac/Lib
parente7b6e396fcbcd26b9af5c13ba27fd7c5629628cf (diff)
downloadcpython-bb6193c553fca0532f78af80a8f745c305144b87.zip
cpython-bb6193c553fca0532f78af80a8f745c305144b87.tar.gz
cpython-bb6193c553fca0532f78af80a8f745c305144b87.tar.bz2
Added a PopupMenu class.
Diffstat (limited to 'Mac/Lib')
-rw-r--r--Mac/Lib/FrameWork.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/Mac/Lib/FrameWork.py b/Mac/Lib/FrameWork.py
index c002b1f..69378b5 100644
--- a/Mac/Lib/FrameWork.py
+++ b/Mac/Lib/FrameWork.py
@@ -453,10 +453,11 @@ class MenuBar:
if DEBUG: print 'Newmenu', title, id # XXXX
m = NewMenu(id, title)
m.InsertMenu(after)
- if self.parent:
- self.parent.needmenubarredraw = 1
- else:
- DrawMenuBar()
+ if after >= 0:
+ if self.parent:
+ self.parent.needmenubarredraw = 1
+ else:
+ DrawMenuBar()
return id, m
def delmenu(self, id):
@@ -582,6 +583,27 @@ class Menu:
self.menu.EnableItem(0)
else:
self.menu.DisableItem(0)
+
+class PopupMenu(Menu):
+ def __init__(self, bar):
+ Menu.__init__(self, bar, '(popup)', -1)
+
+ def popup(self, x, y, event, default=1, window=None):
+ # NOTE that x and y are global coordinates, and they should probably
+ # be topleft of the button the user clicked (not mouse-coordinates),
+ # so the popup nicely overlaps.
+ reply = self.menu.PopUpMenuSelect(x, y, default)
+ if not reply:
+ return
+ id = (reply & 0xffff0000) >> 16
+ item = reply & 0xffff
+ if not window:
+ wid = Win.FrontWindow()
+ try:
+ window = self.bar.parent._windows[wid]
+ except:
+ pass # If we can't find the window we pass None
+ self.dispatch(id, item, window, event)
class MenuItem:
def __init__(self, menu, title, shortcut=None, callback=None, kind=None):