+UPDATE_URL = "http://wxPython.org/"
+#UPDATE_URL = "http://sourceforge.net/project/showfiles.php?group_id=10718"
+
+
+def ensureMinimal(minVersion):
+ """
+ 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)
+ defaultPath = _find_default()
+ if defaultPath:
+ defv = _wxPackageInfo(defaultPath, True)
+ if defv >= minv:
+ bestMatch = defv
+
+ if bestMatch is None:
+ installed = _find_installed()
+ if installed:
+ # The list is in reverse sorted order, so if the first one is
+ # big enough then choose it
+ if installed[0] >= minv:
+ bestMatch = installed[0]
+
+ if bestMatch is None:
+ 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)
+ _selected = bestMatch
+
+
+#----------------------------------------------------------------------
+