diff --git a/G-Earth/src/main/java/gearth/services/g_python/GPythonVersionUtils.java b/G-Earth/src/main/java/gearth/services/g_python/GPythonVersionUtils.java index 9b4917e..c0f83a7 100644 --- a/G-Earth/src/main/java/gearth/services/g_python/GPythonVersionUtils.java +++ b/G-Earth/src/main/java/gearth/services/g_python/GPythonVersionUtils.java @@ -27,16 +27,16 @@ public class GPythonVersionUtils { return maybeVersion.split(" ")[1]; } - public static boolean validInstallation() { + public static boolean validInstallation() throws Exception { // validates if user has all dependencies installed String pythonVersion = pythonVersion(); if (pythonVersion == null) { - return false; + throw new Exception("Python is not installed."); } ComparableVersion version = new ComparableVersion(pythonVersion); if (version.compareTo(new ComparableVersion(MIN_PYTHON_VERSION)) < 0) { - return false; + throw new Exception("Python version must be at least "+MIN_PYTHON_VERSION+", but only "+version+" was found."); } List allPackages = executeCommand("python", "-m", "pip", "list"); @@ -48,11 +48,15 @@ public class GPythonVersionUtils { String gPython = getPackageVersion(allPackages, "g-python"); if (qtconsole == null || pyqt5 == null || jupyterConsole == null || gPython == null) { - return false; + throw new Exception("One or more of these dependencies was not found: 'qtconsole', 'pyqt5', 'jupyter-console', 'g-python'."); } ComparableVersion gVersion = new ComparableVersion(gPython); - return gVersion.compareTo(new ComparableVersion(MIN_GPYTHON_VERSION)) >= 0; + if (gVersion.compareTo(new ComparableVersion(MIN_GPYTHON_VERSION)) < 0) { + throw new Exception("G-Python version must be at least "+MIN_GPYTHON_VERSION+", but only "+gVersion+" was found."); + } + + return true; } // null if not found diff --git a/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java b/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java index 24373cf..abde1a6 100644 --- a/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java +++ b/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java @@ -172,13 +172,22 @@ public class ExtraController extends SubForm implements SocksConfiguration { cbx_gpython.setSelected(false); cbx_gpython.setDisable(true); }); - if (!GPythonVersionUtils.validInstallation()) { + try { + GPythonVersionUtils.validInstallation(); + Platform.runLater(() -> { + cbx_gpython.setSelected(true); + cbx_gpython.setDisable(false); + parentController.extensionsController.updateGPythonStatus(); + }); + } catch (Exception e) { Platform.runLater(() -> { Alert alert = new Alert(Alert.AlertType.ERROR, "G-Python installation", ButtonType.OK); alert.setTitle("G-Python installation"); FlowPane fp = new FlowPane(); - Label lbl = new Label("Before using G-Python, install the right packages using pip!" + + Label lbl = new Label("Something isn't right in the G-Python instalation:" + + System.lineSeparator() + System.lineSeparator() + "Error: "+ e.message + + System.lineSeparator() + System.lineSeparator() + "Before using G-Python, install the right packages using pip!" + System.lineSeparator() + System.lineSeparator() + "More information here:"); Hyperlink link = new Hyperlink(INFO_URL_GPYTHON); fp.getChildren().addAll( lbl, link); @@ -194,13 +203,6 @@ public class ExtraController extends SubForm implements SocksConfiguration { cbx_gpython.setDisable(false); }); } - else { - Platform.runLater(() -> { - cbx_gpython.setSelected(true); - cbx_gpython.setDisable(false); - parentController.extensionsController.updateGPythonStatus(); - }); - } }).start();