[GRASS-SVN] r30492 - in grass/trunk/gui/wxpython: . gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Mar 7 07:27:04 EST 2008
Author: martinl
Date: 2008-03-07 07:27:04 -0500 (Fri, 07 Mar 2008)
New Revision: 30492
Added:
grass/trunk/gui/wxpython/gui_modules/grass-gxw.dtd
grass/trunk/gui/wxpython/gui_modules/workspace.py
Removed:
grass/trunk/gui/wxpython/gui_modules/grass-grc.dtd
Modified:
grass/trunk/gui/wxpython/gui_modules/__init__.py
grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: File rxtension of GRASS Workspace XML file renamed to gxw (trac #77)
(dtd) file renamed, tag grc renamed to gxw
Modified: grass/trunk/gui/wxpython/gui_modules/__init__.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/__init__.py 2008-03-06 21:20:42 UTC (rev 30491)
+++ grass/trunk/gui/wxpython/gui_modules/__init__.py 2008-03-07 12:27:04 UTC (rev 30492)
@@ -21,4 +21,5 @@
"toolbox",
"track",
"utils",
+ "workspace",
"wxgui_utils" ]
Deleted: grass/trunk/gui/wxpython/gui_modules/grass-grc.dtd
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/grass-grc.dtd 2008-03-06 21:20:42 UTC (rev 30491)
+++ grass/trunk/gui/wxpython/gui_modules/grass-grc.dtd 2008-03-07 12:27:04 UTC (rev 30492)
@@ -1,57 +0,0 @@
-<!-- grass-grc.dtd
-
- Copyright (C) 2007 by the GRASS Development Team
- Author: Martin Landa <landa.martin gmail.com>
-
- This program is free software under the GPL (>=v2)
- Read the file COPYING coming with GRASS for details.
--->
-
-
-<!--
- a grass-grc defines workspace file content
--->
-
-<!ELEMENT grass-grc (grc)>
-
-<!ELEMENT grc (display*)>
-
-<!-- a display element defines map layer connected to given
- map display widnow
--->
-<!ELEMENT display (group*, layer*)>
-
-<!-- group of map layers
--->
-<!ELEMENT group (layer*)>
-<!ATTLIST group name CDATA #REQUIRED>
-<!ATTLIST group checked CDATA #REQUIRED>
-
-<!-- map layer
--->
-<!ELEMENT layer (task?)>
-<!ATTLIST layer type CDATA #REQUIRED>
-<!ATTLIST layer name CDATA #REQUIRED>
-<!ATTLIST layer checked CDATA #REQUIRED>
-<!ATTLIST layer opacity CDATA #IMPLIED>
-
-<!-- task describes the interface of a single
- GRASS command.
--->
-<!ELEMENT task (parameter*, flag*)>
-<!ATTLIST task name CDATA #REQUIRED>
-
-<!-- a parameter must have a name and a value
--->
-<!ELEMENT parameter (value)>
-<!ATTLIST parameter name CDATA #REQUIRED>
-
-<!-- value of parameter
--->
-<!ELEMENT value (#PCDATA)>
-
-
-<!-- enabled flag
--->
-<!ELEMENT flag EMPTY>
-<!ATTLIST flag name CDATA #REQUIRED>
Copied: grass/trunk/gui/wxpython/gui_modules/grass-gxw.dtd (from rev 30491, grass/trunk/gui/wxpython/gui_modules/grass-grc.dtd)
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/grass-gxw.dtd (rev 0)
+++ grass/trunk/gui/wxpython/gui_modules/grass-gxw.dtd 2008-03-07 12:27:04 UTC (rev 30492)
@@ -0,0 +1,57 @@
+<!-- grass-gxw.dtd
+
+ Copyright (C) 2007 by the GRASS Development Team
+ Author: Martin Landa <landa.martin gmail.com>
+
+ This program is free software under the GPL (>=v2)
+ Read the file COPYING coming with GRASS for details.
+-->
+
+
+<!--
+ a grass-gxw defines workspace file content
+-->
+
+<!ELEMENT grass-gxw (gxw)>
+
+<!ELEMENT gxw (display*)>
+
+<!-- a display element defines map layer connected to given
+ map display widnow
+-->
+<!ELEMENT display (group*, layer*)>
+
+<!-- group of map layers
+-->
+<!ELEMENT group (layer*)>
+<!ATTLIST group name CDATA #REQUIRED>
+<!ATTLIST group checked CDATA #REQUIRED>
+
+<!-- map layer
+-->
+<!ELEMENT layer (task?)>
+<!ATTLIST layer type CDATA #REQUIRED>
+<!ATTLIST layer name CDATA #REQUIRED>
+<!ATTLIST layer checked CDATA #REQUIRED>
+<!ATTLIST layer opacity CDATA #IMPLIED>
+
+<!-- task describes the interface of a single
+ GRASS command.
+-->
+<!ELEMENT task (parameter*, flag*)>
+<!ATTLIST task name CDATA #REQUIRED>
+
+<!-- a parameter must have a name and a value
+-->
+<!ELEMENT parameter (value)>
+<!ATTLIST parameter name CDATA #REQUIRED>
+
+<!-- value of parameter
+-->
+<!ELEMENT value (#PCDATA)>
+
+
+<!-- enabled flag
+-->
+<!ELEMENT flag EMPTY>
+<!ATTLIST flag name CDATA #REQUIRED>
Added: grass/trunk/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/workspace.py (rev 0)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py 2008-03-07 12:27:04 UTC (rev 30492)
@@ -0,0 +1,146 @@
+"""
+ at package workspace
+
+ at brief Open/save workspace definition file
+
+Classes:
+ - ProcessWorkspaceFile
+
+(C) 2007-2008 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Martin Landa <landa.martin gmail.com>
+
+ at date 2007-2008
+"""
+
+### for gxw (workspace file) parsering
+# xmlproc not available on Mac OS
+# from xml.parsers.xmlproc import xmlproc
+# from xml.parsers.xmlproc import xmlval
+# from xml.parsers.xmlproc import xmldtd
+import xml.sax
+import xml.sax.handler
+HandlerBase=xml.sax.handler.ContentHandler
+from xml.sax import make_parser
+
+class ProcessWorkspaceFile(HandlerBase):
+ """
+ A SAX handler for the GXW XML file, as
+ defined in grass-gxw.dtd.
+ """
+ def __init__(self):
+ self.inGxw = False
+ self.inLayer = False
+ self.inTask = False
+ self.inParameter = False
+ self.inFlag = False
+ self.inValue = False
+ self.inGroup = False
+ self.inDisplay = False
+
+ # list of layers
+ self.layers = []
+ self.cmd = []
+ self.displayIndex = -1 # first display has index '0'
+
+ def startElement(self, name, attrs):
+ if name == 'gxw':
+ self.inGxw = True
+
+ elif name == 'display':
+ self.inDisplay = True
+ self.displayIndex += 1
+
+ elif name == 'group':
+ self.groupName = attrs.get('name', None)
+ self.groupChecked = attrs.get('checked', None)
+ self.layers.append({
+ "type" : 'group',
+ "name" : self.groupName,
+ "checked" : int(self.groupChecked),
+ "opacity" : None,
+ "cmd" : None,
+ "group" : self.inGroup,
+ "display" : self.displayIndex})
+ self.inGroup = True
+
+ elif name == 'layer':
+ self.inLayer = True
+ self.layerType = attrs.get('type', None)
+ self.layerName = attrs.get('name', None)
+ self.layerChecked = attrs.get('checked', None)
+ self.layerOpacity = attrs.get('opacity', None)
+ self.cmd = []
+
+ elif name == 'task':
+ self.inTask = True;
+ name = attrs.get('name', None)
+ self.cmd.append(name)
+
+ elif name == 'parameter':
+ self.inParameter = True;
+ self.parameterName = attrs.get('name', None)
+
+ elif name == 'value':
+ self.inValue = True
+ self.value = ''
+
+ elif name == 'flag':
+ self.inFlag = True;
+ name = attrs.get('name', None)
+ self.cmd.append('-' + name)
+
+ def endElement(self, name):
+ if name == 'gxw':
+ self.inGxw = False
+
+ elif name == 'display':
+ self.inDisplay = False
+
+ elif name == 'group':
+ self.inGroup = False
+ self.groupName = self.groupChecked = None
+
+ elif name == 'layer':
+ self.inLayer = False
+ self.layers.append({
+ "type" : self.layerType,
+ "name" : self.layerName,
+ "checked" : int(self.layerChecked),
+ "opacity" : None,
+ "cmd" : None,
+ "group" : self.inGroup,
+ "display" : self.displayIndex})
+
+ if self.layerOpacity:
+ self.layers[-1]["opacity"] = float(self.layerOpacity)
+ if self.cmd:
+ self.layers[-1]["cmd"] = self.cmd
+
+ self.layerType = self.layerName = self.Checked = \
+ self.Opacity = self.cmd = None
+
+ elif name == 'task':
+ self.inTask = False
+
+ elif name == 'parameter':
+ self.inParameter = False
+ self.cmd.append('%s=%s' % (self.parameterName, self.value))
+ self.parameterName = self.value = None
+
+ elif name == 'value':
+ self.inValue = False
+
+ elif name == 'flag':
+ self.inFlag = False
+
+ def characters(self, ch):
+ self.my_characters(ch)
+
+ def my_characters(self, ch):
+ if self.inValue:
+ self.value += ch
+
Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-03-06 21:20:42 UTC (rev 30491)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-03-07 12:27:04 UTC (rev 30492)
@@ -1129,7 +1129,6 @@
except:
cmdlist = command
- # print cmdlist[0], globalvar.grassCmd['all']
if cmdlist[0] in globalvar.grassCmd['all']:
# send GRASS command without arguments to GUI command interface
# except display commands (they are handled differently)
@@ -1166,14 +1165,12 @@
# for all non-display commands.
tmpreg = os.getenv("GRASS_REGION")
os.unsetenv("GRASS_REGION")
- print cmdlist
if len(cmdlist) == 1:
# process GRASS command without argument
menuform.GUI().ParseCommand(cmdlist, parentframe=self)
else:
# process GRASS command with argument
self.cmdPID = len(self.cmdThreads)+1
- print self.cmdPID
self.WriteCmdLog('%s' % ' '.join(cmdlist), pid=self.cmdPID)
grassCmd = gcmd.Command(cmdlist, wait=False,
@@ -1189,7 +1186,6 @@
else:
# Send any other command to the shell. Send output to
# console output window
- print cmdlist
if self.parent.notebook.GetSelection() != 1:
# select 'Command output' tab
self.parent.notebook.SetSelection(1)
Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py 2008-03-06 21:20:42 UTC (rev 30491)
+++ grass/trunk/gui/wxpython/wxgui.py 2008-03-07 12:27:04 UTC (rev 30492)
@@ -4,7 +4,6 @@
CLASSES:
* GMFrame
* GMApp
- * ProcessGrcXml
PURPOSE: Main Python app for GRASS wxPython GUI. Main menu, layer management
toolbar, notebook control for display management and access to
@@ -30,15 +29,13 @@
import re
import string
import getopt
-### for GRC (workspace file) parsering
-# xmlproc not available on Mac OS
-# from xml.parsers.xmlproc import xmlproc
-# from xml.parsers.xmlproc import xmlval
-# from xml.parsers.xmlproc import xmldtd
+
+### XML
import xml.sax
import xml.sax.handler
HandlerBase=xml.sax.handler.ContentHandler
from xml.sax import make_parser
+
### i18N
import gettext
gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
@@ -84,6 +81,7 @@
import gui_modules.georect as georect
import gui_modules.dbm as dbm
import gui_modules.globalvar as globalvar
+import gui_modules.workspace as workspace
from gui_modules.debug import Debug as Debug
from icons.icon import Icons as Icons
@@ -160,7 +158,7 @@
# load workspace file if requested
if (self.workspaceFile):
# load given workspace file
- if self.LoadGrcXmlToLayerTree(self.workspaceFile):
+ if self.LoadWorkspaceFile(self.workspaceFile):
self.SetTitle(self.baseTitle + " - " + os.path.basename(self.workspaceFile))
else:
self.workspaceFile = None
@@ -512,7 +510,7 @@
def OnWorkspaceOpen(self, event=None):
"""Open file with workspace definition"""
dlg = wx.FileDialog(parent=self, message=_("Choose workspace file"),
- defaultDir=os.getcwd(), wildcard="*.grc")
+ defaultDir=os.getcwd(), wildcard="*.gxw")
filename = ''
if dlg.ShowModal() == wx.ID_OK:
@@ -523,19 +521,19 @@
Debug.msg(4, "GMFrame.OnWorkspaceOpen(): filename=%s" % filename)
- self.LoadGrcXmlToLayerTree(filename)
+ self.LoadWorkspaceFile(filename)
self.workspaceFile = filename
self.SetTitle(self.baseTitle + " - " + os.path.basename(self.workspaceFile))
- def LoadGrcXmlToLayerTree(self, filename):
- """Load layer tree definition stored in GRC XML file
+ def LoadWorkspaceFile(self, filename):
+ """Load layer tree definition stored in GRASS Workspace XML file (gxw)
Return True on success
Return False on error"""
# dtd
- dtdFilename = os.path.join(globalvar.ETCWXDIR, "gui_modules", "grass-grc.dtd")
+ dtdFilename = os.path.join(globalvar.ETCWXDIR, "gui_modules", "grass-gxw.dtd")
# validate xml agains dtd
# dtd = xmldtd.load_dtd(dtdFilename)
@@ -548,7 +546,7 @@
# parser.parse_resource(filename)
# except:
# dlg = wx.MessageDialog(self, _("Unable to open workspace file <%s>. "
- # "It is not valid GRC XML file.") % filename,
+ # "It is not valid GRASS Workspace File.") % filename,
# _("Error"), wx.OK | wx.ICON_ERROR)
# dlg.ShowModal()
# dlg.Destroy()
@@ -562,26 +560,31 @@
file = open(filename, "r")
fileStream = ''.join(file.readlines())
- p = re.compile( '(grass-grc.dtd)')
+ p = re.compile( '(grass-gxw.dtd)')
p.search(fileStream)
fileStream = p.sub(dtdFilename, fileStream)
# sax
- grcXml = ProcessGrcXml()
+ gxwXml = workspace.ProcessWorkspaceFile()
try:
- xml.sax.parseString(fileStream, grcXml)
+ xml.sax.parseString(fileStream, gxwXml)
except xml.sax.SAXParseException, err:
raise gcmd.GStdError(_("Reading workspace file <%s> failed. "
"Invalid file, unable to parse XML document.") % filename + \
"\n\n%s" % err,
parent=self)
+ except ValueError, err:
+ raise gcmd.GStdError(_("Reading workspace file <%s> failed. "
+ "Invalid file, unable to parse XML document.") % filename + \
+ "\n\n%s" % err,
+ parent=self)
busy = wx.BusyInfo(message=_("Please wait, loading map layers into layer tree..."),
parent=self)
wx.Yield()
- for layer in grcXml.layers:
+ for layer in gxwXml.layers:
if layer['display'] >= self.disp_idx:
# create new map display window if needed
self.NewDisplay()
@@ -640,7 +643,7 @@
"""Save workspace definition to selected file"""
dlg = wx.FileDialog(parent=self, message=_("Choose file to save current workspace"),
- defaultDir=os.getcwd(), wildcard="*.grc", style=wx.FD_SAVE)
+ defaultDir=os.getcwd(), wildcard="*.gxw", style=wx.FD_SAVE)
filename = ''
if dlg.ShowModal() == wx.ID_OK:
@@ -650,8 +653,8 @@
return False
# check for extension
- if filename[-4:] != ".grc":
- filename += ".grc"
+ if filename[-4:] != ".gxw":
+ filename += ".gxw"
if os.path.exists(filename):
dlg = wx.MessageDialog(self, message=_("Workspace file <%s> already exists. "
@@ -663,7 +666,7 @@
Debug.msg(4, "GMFrame.OnWorkspaceSaveAs(): filename=%s" % filename)
- self.SaveLayerTreeToGrcXml(filename)
+ self.SaveToWorkspaceFile(filename)
self.workspaceFile = filename
self.SetTitle(self.baseTitle + " - " + os.path.basename(self.workspaceFile))
@@ -679,12 +682,12 @@
dlg.Destroy()
else:
Debug.msg(4, "GMFrame.OnWorkspaceSave(): filename=%s" % self.workspaceFile)
- self.SaveLayerTreeToGrcXml(self.workspaceFile)
+ self.SaveToWorkspaceFile(self.workspaceFile)
else:
self.OnWorkspaceSaveAs()
- def WriteLayersToGrcXml(self, file, mapTree, item):
- """Write bunch of layers to GRC XML file"""
+ def WriteLayersToWorkspaceFile(self, file, mapTree, item):
+ """Write bunch of layers to GRASS Workspace XML file"""
self.indent += 4
while item and item.IsOk():
type = mapTree.GetPyData(item)[0]['type']
@@ -705,7 +708,7 @@
(' ' * self.indent, name, checked));
self.indent += 4
subItem = mapTree.GetFirstChild(item)[0]
- self.WriteLayersToGrcXml(file, mapTree, subItem)
+ self.WriteLayersToWorkspaceFile(file, mapTree, subItem)
self.indent -= 4
file.write('%s</group>\n' % (' ' * self.indent));
else:
@@ -737,7 +740,7 @@
item = mapTree.GetNextSibling(item)
self.indent -= 4
- def SaveLayerTreeToGrcXml(self, filename):
+ def SaveToWorkspaceFile(self, filename):
"""Save layer tree layout to workspace file
Return True on success, False on error
@@ -756,8 +759,8 @@
self.indent = 0 # number of spaces
# write header
file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
- file.write('<!DOCTYPE grc SYSTEM "grass-grc.dtd">\n')
- file.write('%s<grc>\n' % (' ' * self.indent))
+ file.write('<!DOCTYPE gxw SYSTEM "grass-gxw.dtd">\n')
+ file.write('%s<gxw>\n' % (' ' * self.indent))
# list of displays
for page in range(0, self.gm_cb.GetPageCount()):
self.indent =+ 4
@@ -765,10 +768,10 @@
mapTree = self.gm_cb.GetPage(page).maptree
# list of layers
item = mapTree.GetFirstChild(mapTree.root)[0]
- self.WriteLayersToGrcXml(file, mapTree, item)
+ self.WriteLayersToWorkspaceFile(file, mapTree, item)
file.write('%s</display>\n' % (' ' * self.indent))
self.indent =- 4
- file.write('%s</grc>\n' % (' ' * self.indent))
+ file.write('%s</gxw>\n' % (' ' * self.indent))
del self.indent
except:
dlg = wx.MessageDialog(self, _("Writing current settings to workspace file failed."),
@@ -1291,124 +1294,6 @@
return True
-class ProcessGrcXml(HandlerBase):
- """
- A SAX handler for the GRC XML file, as
- defined in grass-grc.dtd.
- """
- def __init__(self):
- self.inGrc = False
- self.inLayer = False
- self.inTask = False
- self.inParameter = False
- self.inFlag = False
- self.inValue = False
- self.inGroup = False
- self.inDisplay = False
-
- # list of layers
- self.layers = []
- self.cmd = []
- self.displayIndex = -1 # first display has index '0'
-
- def startElement(self, name, attrs):
- if name == 'grc':
- self.inGrc = True
-
- elif name == 'display':
- self.inDisplay = True
- self.displayIndex += 1
-
- elif name == 'group':
- self.groupName = attrs.get('name', None)
- self.groupChecked = attrs.get('checked', None)
- self.layers.append({
- "type" : 'group',
- "name" : self.groupName,
- "checked" : int(self.groupChecked),
- "opacity" : None,
- "cmd" : None,
- "group" : self.inGroup,
- "display" : self.displayIndex})
- self.inGroup = True
-
- elif name == 'layer':
- self.inLayer = True
- self.layerType = attrs.get('type', None)
- self.layerName = attrs.get('name', None)
- self.layerChecked = attrs.get('checked', None)
- self.layerOpacity = attrs.get('opacity', None)
- self.cmd = []
-
- elif name == 'task':
- self.inTask = True;
- name = attrs.get('name', None)
- self.cmd.append(name)
-
- elif name == 'parameter':
- self.inParameter = True;
- self.parameterName = attrs.get('name', None)
-
- elif name == 'value':
- self.inValue = True
- self.value = ''
-
- elif name == 'flag':
- self.inFlag = True;
- name = attrs.get('name', None)
- self.cmd.append('-' + name)
-
- def endElement(self, name):
- if name == 'grc':
- self.inGrc = False
-
- elif name == 'display':
- self.inDisplay = False
-
- elif name == 'group':
- self.inGroup = False
- self.groupName = self.groupChecked = None
-
- elif name == 'layer':
- self.inLayer = False
- self.layers.append({
- "type" : self.layerType,
- "name" : self.layerName,
- "checked" : int(self.layerChecked),
- "opacity" : None,
- "cmd" : None,
- "group" : self.inGroup,
- "display" : self.displayIndex})
-
- if self.layerOpacity:
- self.layers[-1]["opacity"] = float(self.layerOpacity)
- if self.cmd:
- self.layers[-1]["cmd"] = self.cmd
-
- self.layerType = self.layerName = self.Checked = \
- self.Opacity = self.cmd = None
-
- elif name == 'task':
- self.inTask = False
-
- elif name == 'parameter':
- self.inParameter = False
- self.cmd.append('%s=%s' % (self.parameterName, self.value))
- self.parameterName = self.value = None
-
- elif name == 'value':
- self.inValue = False
-
- elif name == 'flag':
- self.inFlag = False
-
- def characters(self, ch):
- self.my_characters(ch)
-
- def my_characters(self, ch):
- if self.inValue:
- self.value += ch
-
def reexec_with_pythonw():
if sys.platform == 'darwin' and \
not sys.executable.endswith('MacOS/Python'):
More information about the grass-commit
mailing list