From c73f48cd9ec11b70e1aff6c3b0f2d8ed2f7b5b2a Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Fri, 2 Jun 2023 11:52:56 +0200 Subject: [PATCH 1/3] check min required wx version when starting wxgui --- gui/wxpython/core/globalvar.py | 8 +++++--- gui/wxpython/wxgui.py | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gui/wxpython/core/globalvar.py b/gui/wxpython/core/globalvar.py index 6d57829a373..e4cc9c16c6d 100644 --- a/gui/wxpython/core/globalvar.py +++ b/gui/wxpython/core/globalvar.py @@ -80,10 +80,12 @@ def CheckWxPhoenix(): def CheckWxVersion(version): - """Check wx version""" - ver = wx.__version__ - parsed_version = parse_version_string(ver) + """Check wx version. + :return: True if current wx version is greater or equal than + specifed version otherwise False + """ + parsed_version = parse_version_string(wx.__version__) if parsed_version < version: return False diff --git a/gui/wxpython/wxgui.py b/gui/wxpython/wxgui.py index 50dd290d50e..ee23034e03e 100644 --- a/gui/wxpython/wxgui.py +++ b/gui/wxpython/wxgui.py @@ -26,7 +26,7 @@ # i18n is taken care of in the grass library code. # So we need to import it before any of the GUI code. from grass.exceptions import Usage -from grass.script.core import set_raise_on_error +from grass.script.core import set_raise_on_error, warning from core import globalvar from core.utils import registerPid, unregisterPid @@ -45,6 +45,11 @@ except ImportError: SC = None +min_required_wx_version = [4, 2, 0] +if not globalvar.CheckWxVersion(min_required_wx_version): + warning("!" * 50) + warning("Minimum required WxPython version: {}".format('.'.join(map(str, min_required_wx_version)))) + warning("!" * 50) class GMApp(wx.App): def __init__(self, workspace=None): From 6519c585bdae284006a83bcc484a3deb2c1feec9 Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Fri, 2 Jun 2023 11:59:21 +0200 Subject: [PATCH 2/3] black applied --- gui/wxpython/wxgui.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gui/wxpython/wxgui.py b/gui/wxpython/wxgui.py index ee23034e03e..37bc710c02a 100644 --- a/gui/wxpython/wxgui.py +++ b/gui/wxpython/wxgui.py @@ -48,9 +48,14 @@ min_required_wx_version = [4, 2, 0] if not globalvar.CheckWxVersion(min_required_wx_version): warning("!" * 50) - warning("Minimum required WxPython version: {}".format('.'.join(map(str, min_required_wx_version)))) + warning( + "Minimum required WxPython version: {}".format( + ".".join(map(str, min_required_wx_version)) + ) + ) warning("!" * 50) + class GMApp(wx.App): def __init__(self, workspace=None): """Main GUI class. From 305dad030540762918a20cd2209a80a422db5de8 Mon Sep 17 00:00:00 2001 From: Anna Petrasova Date: Sun, 4 Jun 2023 13:48:55 +0200 Subject: [PATCH 3/3] improve warning --- gui/wxpython/wxgui.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/gui/wxpython/wxgui.py b/gui/wxpython/wxgui.py index 37bc710c02a..48a1b4d7630 100644 --- a/gui/wxpython/wxgui.py +++ b/gui/wxpython/wxgui.py @@ -26,7 +26,7 @@ # i18n is taken care of in the grass library code. # So we need to import it before any of the GUI code. from grass.exceptions import Usage -from grass.script.core import set_raise_on_error, warning +from grass.script.core import set_raise_on_error, warning, error from core import globalvar from core.utils import registerPid, unregisterPid @@ -45,16 +45,6 @@ except ImportError: SC = None -min_required_wx_version = [4, 2, 0] -if not globalvar.CheckWxVersion(min_required_wx_version): - warning("!" * 50) - warning( - "Minimum required WxPython version: {}".format( - ".".join(map(str, min_required_wx_version)) - ) - ) - warning("!" * 50) - class GMApp(wx.App): def __init__(self, workspace=None): @@ -101,10 +91,28 @@ def show_main_gui(): from main_window.frame import GMFrame else: from lmgr.frame import GMFrame - - mainframe = GMFrame(parent=None, id=wx.ID_ANY, workspace=self.workspaceFile) - mainframe.Show() - self.SetTopWindow(mainframe) + try: + mainframe = GMFrame( + parent=None, id=wx.ID_ANY, workspace=self.workspaceFile + ) + except Exception as err: + min_required_wx_version = [4, 2, 0] + if not globalvar.CheckWxVersion(min_required_wx_version): + error(err) + warning( + _( + "Current version of wxPython {} is lower than " + "minimum required version {}".format( + wx.__version__, + ".".join(map(str, min_required_wx_version)), + ) + ) + ) + else: + raise + else: + mainframe.Show() + self.SetTopWindow(mainframe) wx.CallAfter(show_main_gui)