]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/PopupWindow.py
'[1219035] cleanup: miscellaneous' and minor source cleaning.
[wxWidgets.git] / wxPython / demo / PopupWindow.py
index cc4d71b83fc04a1a651aefc91f70884eb10e5fd2..cc2de54b36b97e166ac041b2bc5f2b108a6263a5 100644 (file)
@@ -1,29 +1,22 @@
-# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
-#
-# o Updated for wx namespace
 # 
 # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
 #
 # o Some issues with the listbox example; I tried correcting
 #   it but it's still not working the way it should. Commented
 # 
 # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
 #
 # o Some issues with the listbox example; I tried correcting
 #   it but it's still not working the way it should. Commented
-#   out for now but will be revisited.
-# o The math in determining the popup window's position is
-#   a bit off.
+#   out for now, as I found it.
 # 
 
 import  wx
 
 havePopupWindow = 1
 # 
 
 import  wx
 
 havePopupWindow = 1
-try:
-    wx.PopupWindow
-except NameError:
+if wx.Platform == '__WXMAC__':
     havePopupWindow = 0
     wx.PopupWindow = wx.PopupTransientWindow = wx.Window
 
 #---------------------------------------------------------------------------
 
 class TestPopup(wx.PopupWindow):
     havePopupWindow = 0
     wx.PopupWindow = wx.PopupTransientWindow = wx.Window
 
 #---------------------------------------------------------------------------
 
 class TestPopup(wx.PopupWindow):
-    """Adds a bit of text and mouse movement to the wxPopupWindow"""
+    """Adds a bit of text and mouse movement to the wx.PopupWindow"""
     def __init__(self, parent, style):
         wx.PopupWindow.__init__(self, parent, style)
         self.SetBackgroundColour("CADET BLUE")
     def __init__(self, parent, style):
         wx.PopupWindow.__init__(self, parent, style)
         self.SetBackgroundColour("CADET BLUE")
@@ -55,7 +48,10 @@ class TestPopup(wx.PopupWindow):
         st.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
         st.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
 
         st.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
         st.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
 
+        wx.CallAfter(self.Refresh)
+
     def OnMouseLeftDown(self, evt):
     def OnMouseLeftDown(self, evt):
+        self.Refresh()
         self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
         self.wPos = self.ClientToScreen((0,0))
         self.CaptureMouse()
         self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
         self.wPos = self.ClientToScreen((0,0))
         self.CaptureMouse()
@@ -76,15 +72,14 @@ class TestPopup(wx.PopupWindow):
 
 
 class TestTransientPopup(wx.PopupTransientWindow):
 
 
 class TestTransientPopup(wx.PopupTransientWindow):
-    """Adds a bit of text and mouse movement to the wxPopupWindow"""
+    """Adds a bit of text and mouse movement to the wx.PopupWindow"""
     def __init__(self, parent, style, log):
         wx.PopupTransientWindow.__init__(self, parent, style)
         self.log = log
     def __init__(self, parent, style, log):
         wx.PopupTransientWindow.__init__(self, parent, style)
         self.log = log
-        panel = wx.Panel(self, -1)
-        panel.SetBackgroundColour("#FFB6C1")
-        st = wx.StaticText(panel, -1,
-                          "wxPopupTransientWindow is a\n"
-                          "wxPopupWindow which disappears\n"
+        self.SetBackgroundColour("#FFB6C1")
+        st = wx.StaticText(self, -1,
+                          "wx.PopupTransientWindow is a\n"
+                          "wx.PopupWindow which disappears\n"
                           "automatically when the user\n"
                           "clicks the mouse outside it or if it\n"
                           "(or its first child) loses focus in \n"
                           "automatically when the user\n"
                           "clicks the mouse outside it or if it\n"
                           "(or its first child) loses focus in \n"
@@ -92,8 +87,7 @@ class TestTransientPopup(wx.PopupTransientWindow):
                           ,
                           pos=(10,10))
         sz = st.GetBestSize()
                           ,
                           pos=(10,10))
         sz = st.GetBestSize()
-        panel.SetSize( (sz.width+20, sz.height+20) )
-        self.SetSize(panel.GetSize())
+        self.SetSize( (sz.width+20, sz.height+20) )
 
     def ProcessLeftDown(self, evt):
         self.log.write("ProcessLeftDown\n")
 
     def ProcessLeftDown(self, evt):
         self.log.write("ProcessLeftDown\n")
@@ -109,21 +103,22 @@ class TestPanel(wx.Panel):
         wx.Panel.__init__(self, parent, -1)
         self.log = log
 
         wx.Panel.__init__(self, parent, -1)
         self.log = log
 
-        b = wx.Button(self, -1, "Show wxPopupWindow", (25, 50))
+        b = wx.Button(self, -1, "Show wx.PopupWindow", (25, 50))
         self.Bind(wx.EVT_BUTTON, self.OnShowPopup, b)
 
         self.Bind(wx.EVT_BUTTON, self.OnShowPopup, b)
 
-        b = wx.Button(self, -1, "Show wxPopupTransientWindow", (25, 95))
+        b = wx.Button(self, -1, "Show wx.PopupTransientWindow", (25, 95))
         self.Bind(wx.EVT_BUTTON, self.OnShowPopupTransient, b)
 
         # This isn't working so well, not sure why. Commented out for
         # now.
         
         self.Bind(wx.EVT_BUTTON, self.OnShowPopupTransient, b)
 
         # This isn't working so well, not sure why. Commented out for
         # now.
         
-#        b = wx.Button(self, -1, "Show wxPopupWindow with listbox", (25, 140))
+#        b = wx.Button(self, -1, "Show wx.PopupWindow with listbox", (25, 140))
 #        self.Bind(wx.EVT_BUTTON, self.OnShowPopupListbox, b)
 
 
     def OnShowPopup(self, evt):
         win = TestPopup(self, wx.SIMPLE_BORDER)
 #        self.Bind(wx.EVT_BUTTON, self.OnShowPopupListbox, b)
 
 
     def OnShowPopup(self, evt):
         win = TestPopup(self, wx.SIMPLE_BORDER)
+        #win = TestPopupWithListbox(self, wx.SIMPLE_BORDER, self.log)
 
         # Show the popup right below or above the button
         # depending on available screen space...
 
         # Show the popup right below or above the button
         # depending on available screen space...
@@ -136,7 +131,9 @@ class TestPanel(wx.Panel):
 
 
     def OnShowPopupTransient(self, evt):
 
 
     def OnShowPopupTransient(self, evt):
-        win = TestTransientPopup(self, wx.SIMPLE_BORDER, self.log)
+        win = TestTransientPopup(self,
+                                 wx.SIMPLE_BORDER,
+                                 self.log)
 
         # Show the popup right below or above the button
         # depending on available screen space...
 
         # Show the popup right below or above the button
         # depending on available screen space...
@@ -160,34 +157,34 @@ class TestPanel(wx.Panel):
 
         win.Show(True)
 
 
         win.Show(True)
 
+
+
+# This class is currently not implemented in the demo. It does not
+# behave the way it should, so for the time being it's only here
+# for show. If you figure out how to make it work, please send
+# a corrected file to Robin! 
 class TestPopupWithListbox(wx.PopupWindow):
     def __init__(self, parent, style, log):
         wx.PopupWindow.__init__(self, parent, style)
 class TestPopupWithListbox(wx.PopupWindow):
     def __init__(self, parent, style, log):
         wx.PopupWindow.__init__(self, parent, style)
-
+        self.log = log
         import keyword
         import keyword
-
         self.lb = wx.ListBox(self, -1, choices = keyword.kwlist)
         #sz = self.lb.GetBestSize()
         self.SetSize((150, 75)) #sz)
         self.lb.SetSize(self.GetClientSize())
         self.lb.SetFocus()
         self.Bind(wx.EVT_LISTBOX, self.OnListBox)
         self.lb = wx.ListBox(self, -1, choices = keyword.kwlist)
         #sz = self.lb.GetBestSize()
         self.SetSize((150, 75)) #sz)
         self.lb.SetSize(self.GetClientSize())
         self.lb.SetFocus()
         self.Bind(wx.EVT_LISTBOX, self.OnListBox)
-        self.lb.Bind(wx.EVT_LEFT_DOWN, self.OnLeft)
-
-    def OnLeft(self, evt):
-        obj = evt.GetEventObject()
-        print "OnLeft", obj
-        print 'Selected: %s' % obj.GetStringSelection()
-        obj.Show(False)
-        evt.Skip()
+        self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnListBoxDClick)
 
     def OnListBox(self, evt):
         obj = evt.GetEventObject()
 
     def OnListBox(self, evt):
         obj = evt.GetEventObject()
-        print "OnListBox", obj
-        print 'Selected: %s' % obj.GetString()
+        self.log.write("OnListBox: %s\n" % obj)
+        self.log.write('Selected: %s\n' % obj.GetString(evt.GetInt()))
         evt.Skip()
 
         evt.Skip()
 
-
+    def OnListBoxDClick(self, evt):
+        self.Hide()
+        self.Destroy()
 
 #---------------------------------------------------------------------------
 
 
 #---------------------------------------------------------------------------
 
@@ -196,13 +193,10 @@ def runTest(frame, nb, log):
         win = TestPanel(nb, log)
         return win
     else:
         win = TestPanel(nb, log)
         return win
     else:
-        dlg = wx.MessageDialog(
-                frame, 'wxPopupWindow is not available on this platform.',
-                'Sorry', wx.OK | wx.ICON_INFORMATION
-                )
-
-        dlg.ShowModal()
-        dlg.Destroy()
+        from Main import MessagePanel
+        win = MessagePanel(nb, 'wx.PopupWindow is not available on this platform.',
+                           'Sorry', wx.ICON_WARNING)
+        return win
 
 #---------------------------------------------------------------------------
 
 
 #---------------------------------------------------------------------------
 
@@ -214,5 +208,5 @@ overview = """\
 if __name__ == '__main__':
     import sys,os
     import run
 if __name__ == '__main__':
     import sys,os
     import run
-    run.main(['', os.path.basename(sys.argv[0])])
+    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])