Skip to content

Commit

Permalink
wxGUI, d.rast.edit: remove 'wxversion' module (#713)
Browse files Browse the repository at this point in the history
* d.rast.edit, wxpyimgview, wxGUI globalvar: remove 'wxversion' module

* wxGUI globalvar: remove obsolete 'wxPython3' var
  • Loading branch information
tmszi committed Jun 20, 2020
1 parent 32848ab commit 1245b5c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
35 changes: 8 additions & 27 deletions gui/wxpython/core/globalvar.py
Expand Up @@ -34,6 +34,8 @@

from core.debug import Debug

WXPY3_MIN_VERSION = [4, 0, 0, 0]


def parse_version_string(version):
"""Parse version number, return three numbers as list
Expand Down Expand Up @@ -88,44 +90,24 @@ def CheckWxVersion(version):
return True


def CheckForWx(forceVersion=os.getenv('GRASS_WXVERSION', None)):
"""Try to import wx module and check its version
:param forceVersion: force wxPython version, eg. '2.8'
"""
def CheckForWx():
"""Try to import wx module"""
if 'wx' in sys.modules.keys():
return

minVersion = [2, 8, 10, 1]
try:
try:
# Note that Phoenix doesn't have wxversion anymore
import wxversion
except ImportError as e:
# if there is no wx raises ImportError
import wx
return
if forceVersion:
wxversion.select(forceVersion)
wxversion.ensureMinimal(str(minVersion[0]) + '.' + str(minVersion[1]))
import wx # noqa: F811
import wx
version = parse_version_string(wx.__version__)

if version < minVersion:
if version < WXPY3_MIN_VERSION:
raise ValueError(
"Your wxPython version is {}".format(wx.__version__))

return
except ImportError as e:
print('ERROR: wxGUI requires wxPython. %s' % str(e),
print('ERROR: wxGUI requires wxPython. {}'.format(e),
file=sys.stderr)
print('You can still use GRASS GIS modules in'
' the command line or in Python.', file=sys.stderr)
sys.exit(1)
except (ValueError, wxversion.VersionError) as e:
message = "ERROR: wxGUI requires wxPython >= {version}: {error}".format(
version=version_as_string(minVersion), error=e)
print(message, file=sys.stderr)
sys.exit(1)
except locale.Error as e:
print("Unable to set locale:", e, file=sys.stderr)
os.environ['LC_ALL'] = ''
Expand Down Expand Up @@ -263,7 +245,6 @@ def UpdateGRASSAddOnCommands(eList=None):

"""@Check version of wxPython, use agwStyle for 2.8.11+"""
hasAgw = CheckWxVersion([2, 8, 11, 0])
wxPython3 = CheckWxVersion([3, 0, 0, 0])
wxPythonPhoenix = CheckWxPhoenix()

gtk3 = True if 'gtk3' in wx.PlatformInfo else False
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/mapdisp/frame.py
Expand Up @@ -226,8 +226,7 @@ def CreateStatusbar(self):

# create statusbar and its manager
statusbar = self.CreateStatusBar(number=4, style=0)
if globalvar.wxPython3:
statusbar.SetMinHeight(24)
statusbar.SetMinHeight(24)
statusbar.SetStatusWidths([-5, -2, -1, -1])
self.statusbarManager = sb.SbManager(
mapframe=self, statusbar=statusbar)
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/mapswipe/frame.py
Expand Up @@ -23,7 +23,6 @@
from gui_core.mapdisp import DoubleMapFrame
from gui_core.dialogs import GetImageHandlers
from mapwin.base import MapWindowProperties
from core import globalvar
from core.render import Map
from mapdisp import statusbar as sb
from core.debug import Debug
Expand Down Expand Up @@ -170,8 +169,7 @@ def InitStatusbar(self):

# create statusbar and its manager
statusbar = self.CreateStatusBar(number=4, style=0)
if globalvar.wxPython3:
statusbar.SetMinHeight(24)
statusbar.SetMinHeight(24)
statusbar.SetStatusWidths([-5, -2, -1, -1])
self.statusbarManager = sb.SbManager(
mapframe=self, statusbar=statusbar)
Expand Down
4 changes: 1 addition & 3 deletions scripts/d.rast.edit/d.rast.edit.py
Expand Up @@ -80,10 +80,8 @@
import grass.script as grass

try:
import wxversion
wxversion.select(['3.0', '2.8', '2.6'])
import wx
except Exception:
except ImportError:
# ensure that --help, --interface-description etc work even without wx
if __name__ == "__main__":
if len(sys.argv) == 2:
Expand Down
2 changes: 0 additions & 2 deletions scripts/wxpyimgview/wxpyimgview_gui.py
Expand Up @@ -42,8 +42,6 @@
import time
import signal

import wxversion
wxversion.select('2.8')
import wx


Expand Down

0 comments on commit 1245b5c

Please sign in to comment.