[GRASS-SVN] r41867 - in grass/branches/develbranch_6/gui/wxpython:
. gui_modules icons xml
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Apr 14 16:57:48 EDT 2010
Author: martinl
Date: 2010-04-14 16:57:48 -0400 (Wed, 14 Apr 2010)
New Revision: 41867
Modified:
grass/branches/develbranch_6/gui/wxpython/Makefile
grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/menudata.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
grass/branches/develbranch_6/gui/wxpython/icons/icon.py
grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml
grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml
Log:
wxGUI/modeler: export to image
(merge r41866 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/Makefile
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/Makefile 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/Makefile 2010-04-14 20:57:48 UTC (rev 41867)
@@ -32,9 +32,11 @@
$(ETCDIR)/%: %
$(INSTALL_DATA) $< $@
-menustrings.py: gui_modules/menudata.py xml/menudata.xml
+menustrings.py: gui_modules/menudata.py $(ETCDIR)/xml/menudata.xml $(ETCDIR)/xml/menudata_modeler.xml
GISBASE="$(GISBASE)" \
$(PYTHON) $< > $@
+ GISBASE="$(GISBASE)" \
+ $(PYTHON) $< "modeler" >> $@
#doxygen:
DOXNAME=wxpython
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2010-04-14 20:57:48 UTC (rev 41867)
@@ -1501,4 +1501,49 @@
opacity = float(self.value.GetValue()) / 100
return opacity
+def GetImageHandlers(image):
+ """!Get list of supported image handlers"""
+ lext = list()
+ ltype = list()
+ for h in image.GetHandlers():
+ lext.append(h.GetExtension())
+
+ filetype = ''
+ if 'png' in lext:
+ filetype += "PNG file (*.png)|*.png|"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_PNG,
+ 'ext' : 'png' })
+ filetype += "BMP file (*.bmp)|*.bmp|"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_BMP,
+ 'ext' : 'bmp' })
+ if 'gif' in lext:
+ filetype += "GIF file (*.gif)|*.gif|"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_GIF,
+ 'ext' : 'gif' })
+
+ if 'jpg' in lext:
+ filetype += "JPG file (*.jpg)|*.jpg|"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_JPEG,
+ 'ext' : 'jpg' })
+ if 'pcx' in lext:
+ filetype += "PCX file (*.pcx)|*.pcx|"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_PCX,
+ 'ext' : 'pcx' })
+
+ if 'pnm' in lext:
+ filetype += "PNM file (*.pnm)|*.pnm|"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_PNM,
+ 'ext' : 'pnm' })
+
+ if 'tif' in lext:
+ filetype += "TIF file (*.tif)|*.tif|"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_TIF,
+ 'ext' : 'tif' })
+
+ if 'xpm' in lext:
+ filetype += "XPM file (*.xpm)|*.xpm"
+ ltype.append({ 'type' : wx.BITMAP_TYPE_XPM,
+ 'ext' : 'xpm' })
+
+ return filetype, ltype
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2010-04-14 20:57:48 UTC (rev 41867)
@@ -52,6 +52,7 @@
from debug import Debug
from gcmd import GMessage
from gdialogs import ElementDialog
+from gdialogs import GetImageHandlers
from grass.script import core as grass
class ModelFrame(wx.Frame):
@@ -164,6 +165,9 @@
"""!Close window"""
self.Destroy()
+ def OnDeleteData(self, event):
+ """!Delete intermediate data"""
+
def OnModelNew(self, event):
"""!Create new model"""
Debug.msg(4, "ModelFrame.OnModelNew():")
@@ -355,7 +359,47 @@
GMessage(parent = self,
message = _('Model is valid.'),
msgType = 'info')
-
+
+ def OnExportImage(self, event):
+ """!Export model to image (default image)"""
+ size = self.canvas.GetSize()
+ bitmap = wx.EmptyBitmap(width = size.width, height = size.height)
+
+ filetype, ltype = GetImageHandlers(wx.ImageFromBitmap(bitmap))
+
+ dlg = wx.FileDialog(parent = self,
+ message = _("Choose a file name to save the image (no need to add extension)"),
+ defaultDir = "",
+ defaultFile = "",
+ wildcard = filetype,
+ style=wx.SAVE | wx.FD_OVERWRITE_PROMPT)
+
+ if dlg.ShowModal() == wx.ID_OK:
+ path = dlg.GetPath()
+ if not path:
+ dlg.Destroy()
+ return
+
+ base, ext = os.path.splitext(path)
+ fileType = ltype[dlg.GetFilterIndex()]['type']
+ extType = ltype[dlg.GetFilterIndex()]['ext']
+ if ext != extType:
+ path = base + '.' + extType
+
+ dc = wx.MemoryDC(bitmap)
+ dc.SetBackground(wx.WHITE_BRUSH)
+ dc.SetBackgroundMode(wx.SOLID)
+
+ dc.BeginDrawing()
+ self.canvas.GetDiagram().Clear(dc)
+ self.canvas.GetDiagram().Redraw(dc)
+ dc.EndDrawing()
+
+ bitmap.SaveFile(path, fileType)
+ self.SetStatusText(_("Model exported to <%s>") % path)
+
+ dlg.Destroy()
+
def OnExportPython(self, event):
"""!Export model to Python script"""
filename = ''
@@ -1492,6 +1536,7 @@
def main():
app = wx.PySimpleApp()
+ wx.InitAllImageHandlers()
frame = ModelFrame(parent = None)
if len(sys.argv) > 1:
frame.LoadModelFile(sys.argv[1])
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py 2010-04-14 20:57:48 UTC (rev 41867)
@@ -488,7 +488,7 @@
if os.environ.has_key("GRASS_REGION"):
del os.environ["GRASS_REGION"]
- if len(cmdlist) == 1 and cmdlist[0] not in ('v.krige'):
+ if len(cmdlist) == 1 and cmdlist[0] not in ('v.krige.py'):
import menuform
# process GRASS command without argument
menuform.GUI().ParseCommand(cmdlist, parentframe=self)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2010-04-14 20:57:48 UTC (rev 41867)
@@ -1172,63 +1172,29 @@
win.SetSize((w, h))
def SaveToFile(self, event):
+ """!Save map to image
"""
- Save image to file
- """
- lext = []
- for h in self.MapWindow.img.GetHandlers():
- lext.append(h.GetExtension())
+ filetype, ltype = gdialogs.GetImageHandlers(self.MapWindow.img)
- filetype = "BMP file (*.bmp)|*.bmp|"
- if 'gif' in lext:
- filetype += "GIF file (*.gif)|*.gif|"
- if 'jpg' in lext:
- filetype += "JPG file (*.jpg)|*.jpg|"
- if 'pcx' in lext:
- filetype += "PCX file (*.pcx)|*.pcx|"
- if 'png' in lext:
- filetype += "PNG file (*.png)|*.png|"
- if 'pnm' in lext:
- filetype += "PNM file (*.pnm)|*.pnm|"
- if 'tif' in lext:
- filetype += "TIF file (*.tif)|*.tif|"
- if 'xpm' in lext:
- filetype += "XPM file (*.xpm)|*.xpm"
-
- dlg = wx.FileDialog(self, _("Choose a file name to save the image (no need to add extension)"),
+ dlg = wx.FileDialog(parent = self,
+ message = _("Choose a file name to save the image (no need to add extension)"),
defaultDir = "",
defaultFile = "",
wildcard = filetype,
- style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
+ style=wx.SAVE | wx.FD_OVERWRITE_PROMPT)
+
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
- if path == None: return
- base = os.path.splitext(dlg.GetPath())[0]
- ext = os.path.splitext(dlg.GetPath())[1]
- if dlg.GetFilterIndex() == 0:
- type = wx.BITMAP_TYPE_BMP
- if ext != '.bmp': path = base+'.bmp'
- if dlg.GetFilterIndex() == 1:
- type = wx.BITMAP_TYPE_GIF
- if ext != '.gif': path = base+'.gif'
- elif dlg.GetFilterIndex() == 2:
- type = wx.BITMAP_TYPE_JPEG
- if ext != '.jpg': path = base+'.jpg'
- elif dlg.GetFilterIndex() == 3:
- type = wx.BITMAP_TYPE_GIF
- if ext != '.pcx': path = base+'.pcx'
- elif dlg.GetFilterIndex() == 4:
- type = wx.BITMAP_TYPE_PNG
- if ext != '.png': path = base+'.png'
- elif dlg.GetFilterIndex() == 5:
- type = wx.BITMAP_TYPE_PNM
- if ext != '.pnm': path = base+'.pnm'
- elif dlg.GetFilterIndex() == 6:
- type = wx.BITMAP_TYPE_TIF
- if ext != '.tif': path = base+'.tif'
- elif dlg.GetFilterIndex() == 7:
- type = wx.BITMAP_TYPE_XPM
- if ext != '.xpm': path = base+'.xpm'
+ if not path:
+ dlg.Destroy()
+ return
+
+ base, ext = os.path.splitext(path)
+ fileType = ltype[dlg.GetFilterIndex()]['type']
+ extType = ltype[dlg.GetFilterIndex()]['ext']
+ if ext != extType:
+ path = base + '.' + extType
+
self.MapWindow.SaveToFile(path, type)
dlg.Destroy()
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menudata.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menudata.py 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menudata.py 2010-04-14 20:57:48 UTC (rev 41867)
@@ -10,7 +10,7 @@
Usage:
@code
-python menudata.py action [file]
+python menudata.py [action] [manager|modeler]
@endcode
where <i>action</i>:
@@ -115,7 +115,8 @@
"""!Print menu strings to file (used for localization)
@param fh file descriptor"""
- fh.write('menustrings = [\n')
+ className = str(self.__class__).split('.', 1)[1]
+ fh.write('menustrings_%s = [\n' % className)
for node in self.tree.getiterator():
if node.tag in ['label', 'help']:
fh.write(' _(%r),\n' % node.text)
@@ -235,18 +236,19 @@
import gettext
gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
- file = None
- if len(sys.argv) == 1:
- action = 'strings'
- elif len(sys.argv) > 1:
- action = sys.argv[1]
- if len(sys.argv) > 2:
- file = sys.argv[2]
-
- if file:
- data = ManagerData(file)
+ action = 'strings'
+ menu = 'manager'
+
+ for arg in sys.argv:
+ if arg in ('strings', 'tree', 'commands', 'dump'):
+ action = arg
+ elif arg in ('manager', 'modeler'):
+ menu = arg
+
+ if menu == 'manager':
+ data = ManagerData()
else:
- data = ManagerData()
+ data = ModelerData()
if action == 'strings':
data.PrintStrings(sys.stdout)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2010-04-14 20:57:48 UTC (rev 41867)
@@ -1388,6 +1388,8 @@
self.new = wx.NewId()
self.open = wx.NewId()
self.save = wx.NewId()
+ self.image = wx.NewId()
+ self.python = wx.NewId()
self.action = wx.NewId()
self.data = wx.NewId()
self.relation = wx.NewId()
@@ -1406,6 +1408,12 @@
(self.save, 'save', Icons['modelSave'].GetBitmap(),
wx.ITEM_NORMAL, Icons['modelSave'].GetLabel(), Icons['modelSave'].GetDesc(),
self.parent.OnModelSave),
+ (self.image, 'image', Icons['modelToImage'].GetBitmap(),
+ wx.ITEM_NORMAL, Icons['modelToImage'].GetLabel(), Icons['modelToImage'].GetDesc(),
+ self.parent.OnExportImage),
+ (self.python, 'python', Icons['modelToPython'].GetBitmap(),
+ wx.ITEM_NORMAL, Icons['modelToPython'].GetLabel(), Icons['modelToPython'].GetDesc(),
+ self.parent.OnExportPython),
('', '', '', '', '', '', ''),
(self.data, 'data', Icons['modelDataAdd'].GetBitmap(),
wx.ITEM_NORMAL, Icons['modelDataAdd'].GetLabel(), Icons['modelDataAdd'].GetDesc(),
Modified: grass/branches/develbranch_6/gui/wxpython/icons/icon.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/icons/icon.py 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/icons/icon.py 2010-04-14 20:57:48 UTC (rev 41867)
@@ -341,6 +341,10 @@
label=_("Load model from file (Ctrl+O)")),
"modelSave" : MetaIcon (img=Icons["fileSave"],
label=_("Save current model to file (Ctrl+S)")),
+ "modelToImage" : MetaIcon (img=Icons["savefile"],
+ label=_("Export model to image")),
+ "modelToPython" : MetaIcon (img=Icons["printmap"],
+ label=_("Export model to Python script")),
"modelActionAdd" : MetaIcon (img=Icons["modelActionAdd"],
label=_("Add action (GRASS module) to model")),
"modelDataAdd" : MetaIcon (img=Icons["modelDataAdd"],
Modified: grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml 2010-04-14 20:57:48 UTC (rev 41867)
@@ -1657,7 +1657,7 @@
<help>Performs ordinary or block kriging.</help>
<keywords>vector,interpolation,kriging</keywords>
<handler>RunMenuCmd</handler>
- <command>v.krige</command>
+ <command>v.krige.py</command>
</menuitem>
<separator />
<menuitem>
Modified: grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml 2010-04-14 20:52:22 UTC (rev 41866)
+++ grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml 2010-04-14 20:57:48 UTC (rev 41867)
@@ -33,13 +33,18 @@
</menuitem>
<separator />
<menuitem>
+ <label>Export to image</label>
+ <help>Export model to image</help>
+ <handler>OnExportImage</handler>
+ </menuitem>
+ <menuitem>
<label>Export to Python</label>
<help>Export model to Python script</help>
<handler>OnExportPython</handler>
</menuitem>
<separator />
<menuitem>
- <label>Close modeler</label>
+ <label>Quit modeler</label>
<help>Close modeler window</help>
<handler>OnCloseWindow</handler>
<shortcut>Ctrl+W</shortcut>
@@ -73,6 +78,12 @@
</menuitem>
<separator />
<menuitem>
+ <label>Delete intermediate data</label>
+ <help>Delete intermediate data defined in the model</help>
+ <handler>OnDeleteData</handler>
+ </menuitem>
+ <separator />
+ <menuitem>
<label>Run model</label>
<help>Run entire model</help>
<handler>OnRunModel</handler>
More information about the grass-commit
mailing list