+UPDATE_URL = "http://wxPython.org/"
+#UPDATE_URL = "http://sourceforge.net/project/showfiles.php?group_id=10718"
+
+_EM_DEBUG=0
+
+def ensureMinimal(minVersion, optionsRequired=False):
+ """
+ Checks to see if the default version of wxPython is greater-than
+ or equal to `minVersion`. If not then it will try to find an
+ installed version that is >= minVersion. If none are available
+ then a message is displayed that will inform the user and will
+ offer to open their web browser to the wxPython downloads page,
+ and will then exit the application.
+ """
+ assert type(minVersion) == str
+
+ # ensure that wxPython hasn't been imported yet.
+ if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'):
+ raise VersionError("wxversion.ensureMinimal() must be called before wxPython is imported")
+
+ bestMatch = None
+ minv = _wxPackageInfo(minVersion)
+
+ # check the default version first
+ defaultPath = _find_default()
+ if defaultPath:
+ defv = _wxPackageInfo(defaultPath, True)
+ if defv >= minv and minv.CheckOptions(defv, optionsRequired):
+ bestMatch = defv
+
+ # if still no match then check look at all installed versions
+ if bestMatch is None:
+ installed = _find_installed()
+ # The list is in reverse sorted order, so find the first
+ # one that is big enough and optionally matches the
+ # options
+ for inst in installed:
+ if inst >= minv and minv.CheckOptions(inst, optionsRequired):
+ bestMatch = inst
+ break
+
+ # if still no match then prompt the user
+ if bestMatch is None:
+ if _EM_DEBUG: # We'll do it this way just for the test code below
+ raise VersionError("Requested version of wxPython not found")
+
+ import wx, webbrowser
+ versions = "\n".join([" "+ver for ver in getInstalled()])
+ app = wx.PySimpleApp()
+ result = wx.MessageBox("This application requires a version of wxPython "
+ "greater than or equal to %s, but a matching version "
+ "was not found.\n\n"
+ "You currently have these version(s) installed:\n%s\n\n"
+ "Would you like to download a new version of wxPython?\n"
+ % (minVersion, versions),
+ "wxPython Upgrade Needed", style=wx.YES_NO)
+ if result == wx.YES:
+ webbrowser.open(UPDATE_URL)
+ app.MainLoop()
+ sys.exit()
+
+ sys.path.insert(0, bestMatch.pathname)
+ global _selected
+ _selected = bestMatch
+
+
+#----------------------------------------------------------------------
+
+def checkInstalled(versions, optionsRequired=False):