Make GUI toolboxes mechanism independent on wxGUI
|Reported by:||wenzeslaus||Owned by:||wenzeslaus|
|Keywords:||toolboxes, addons, XML, wxPython, compilation||Cc:||grass-dev@…|
All the main parts of GUI toolboxes mechanism should be independent on wxGUI to enable smooth usage at all occasions.
Python module or package to generate and to work with GUI toolbox files (in theory) does not need anything GUI-related, thus it does not need wxGUI. Making the toolboxes module/package independent on wxGUI makes it independent on wxPython, so as a consequence it would be possible to use toolboxes module/package without wxPython. This would enable usage of toolboxes module/package by other software which uses GRASS without wxGUI (and possibly does not have wxPython). Moreover, it would decrease the requirements on environment during compilation (which now requires wxPython to be ready to use), so toolboxes module/package would be more reliable when used during compilation.
Note that this would fix the cases when toolboxes are not compiled because of wrong linking to wxWidgets or wxPython during compilation (observed on Mac OS X and on some particular Linux system configurations). Note also that it is unclear what is causing errors related to toolboxes compilation and that it seems that the real problem is in Makefiles because when compiling inside GRASS session toolboxes compilation work.
Toolboxes module depends on:
from core.globalvar import ETCWXDIR from core.utils import GetSettingsPath, _ from core.gcmd import GError, RunCommand from core.debug import Debug
ETCWXDIR is simple and can be either defined in
grass package) or redefined in toolboxes module.
ETCWXDIR = os.path.join(ETCDIR, "gui", "wxpython")
GetSettingsPath is more complex it is would be better to not repeat it again. Maybe, moving to
grass package) is the right option if there is some usage of this function for GRASS modules in general.
def GetSettingsPath(): """!Get full path to the settings directory """ try: verFd = open(os.path.join(ETCDIR, "VERSIONNUMBER")) version = int(verFd.readlines().split(' ').split('.')) except (IOError, ValueError, TypeError, IndexError), e: sys.exit(_("ERROR: Unable to determine GRASS version. Details: %s") % e) verFd.close() # keep location of settings files rc and wx in sync with lib/init/grass.py if sys.platform == 'win32': return os.path.join(os.getenv('APPDATA'), 'GRASS%d' % version) return os.path.join(os.getenv('HOME'), '.grass%d' % version)
The underscore function might be defined again or moved from
utils to separate
translations module. (Site note: translation function must be handled carefully in toolboxes because of potential multiple sources for of translation strings in future.)
try: # intended to be used also outside this module import gettext _ = gettext.translation('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale')).ugettext except IOError: # using no translation silently def null_gettext(string): return string _ = null_gettext
GError class (why class, btw?) usages in toolboxes module should be replaced by other error mechanism, probably exceptions because only those are independent enough.
RunCommand function is just yet another wrapper (wxGUI friendly in this case) to
grass.script.core.start_command and can be probably replaced by some new wrapper which raises exception on error.
Debug can be easily replaced by
grass.pygrass.messages.Messenger. The only problem is the change from wxGUI
WXDEBUG variable to GRASS standard