[GRASS-SVN] r58182 - grass/trunk/gui/wxpython/animation

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 9 20:00:04 PST 2013


Author: annakrat
Date: 2013-11-09 20:00:04 -0800 (Sat, 09 Nov 2013)
New Revision: 58182

Modified:
   grass/trunk/gui/wxpython/animation/controller.py
   grass/trunk/gui/wxpython/animation/dialogs.py
Log:
wxGUI/animations: use new grass.imaging lib for exporting animations

Modified: grass/trunk/gui/wxpython/animation/controller.py
===================================================================
--- grass/trunk/gui/wxpython/animation/controller.py	2013-11-10 03:58:13 UTC (rev 58181)
+++ grass/trunk/gui/wxpython/animation/controller.py	2013-11-10 04:00:04 UTC (rev 58182)
@@ -16,20 +16,9 @@
 import os
 import wx
 
-try:
-    import visvis.vvmovie as vv
-    hasVisvis = True
-except ImportError:
-    # if visvis.vvmovie is in grass python library
-    # import grass.visvis as vv
-    # 
-    # question: if integrate visvis, if integrate visvis.vvmovie or only 
-    # images2swf.py, images2gif.py?
-    hasVisvis = False
-
 from core.gcmd import GException, GError, GMessage
 from core.utils import _
-import grass.script as grass
+from grass.imaging import writeAvi, writeGif, writeIms, writeSwf
 
 from temporal_manager import TemporalManager
 from dialogs import InputDialog, EditDialog, AnimationData, ExportDialog
@@ -472,7 +461,7 @@
             self._dialogs['export'].Raise()
         else:
             dlg = ExportDialog(self.frame, temporal=self.temporalMode,
-                               timeTick=self.timeTick, visvis=hasVisvis)
+                               timeTick=self.timeTick)
             dlg.doExport.connect(self._export)
             self._dialogs['export'] = dlg
             dlg.Show()
@@ -549,56 +538,32 @@
         del busy
 
         # export
-        if exportInfo['method'] == 'sequence':
-            busy = wx.BusyInfo(message = _("Exporting images, please wait..."), parent = self.frame)
-            wx.Yield()
-            zeroPadding = len(str(len(images)))
-            for i, image in enumerate(images):
-                filename = "%s_%s.%s" % (exportInfo['prefix'], str(i + 1).zfill(zeroPadding),
-                                         exportInfo['format']['ext'])
-                image.SaveFile(os.path.join(exportInfo['directory'], filename), exportInfo['format']['type'])
-
+        pilImages = [WxImageToPil(image) for image in images]
+        busy = wx.BusyInfo(message=_("Exporting animation, please wait..."),
+                           parent=self.frame)
+        wx.Yield()
+        try:
+            if exportInfo['method'] == 'sequence':
+                filename = os.path.join(exportInfo['directory'],
+                                        exportInfo['prefix'] + '.' + exportInfo['format'].lower())
+                writeIms(filename=filename, images=pilImages)
+            elif exportInfo['method'] == 'gif':
+                writeGif(filename=exportInfo['file'], images=pilImages,
+                            duration=self.timeTick / float(1000), repeat=True)
+            elif exportInfo['method'] == 'swf':
+                writeSwf(filename=exportInfo['file'], images=pilImages,
+                            duration=self.timeTick / float(1000), repeat=True)
+            elif exportInfo['method'] == 'avi':
+                writeAvi(filename=exportInfo['file'], images=pilImages,
+                            duration=self.timeTick / float(1000),
+                            encoding=exportInfo['encoding'],
+                            inputOptions='-sameq')
+        except Exception, e:
             del busy
+            GError(parent=self.frame, message=str(e))
+            return
+        del busy
 
-        elif exportInfo['method'] in ('gif', 'swf', 'avi'):
-            pilImages = [WxImageToPil(image) for image in images]
-            
-
-            busy = wx.BusyInfo(message = _("Exporting animation, please wait..."), parent = self.frame)
-            wx.Yield()
-            try:
-                if exportInfo['method'] == 'gif':
-                    vv.writeGif(filename = exportInfo['file'], images = pilImages,
-                                duration = self.timeTick / float(1000), repeat = True)
-                elif exportInfo['method'] == 'swf':
-                    vv.writeSwf(filename = exportInfo['file'], images = pilImages,
-                                duration = self.timeTick / float(1000), repeat = True)
-                elif exportInfo['method'] == 'avi':
-                    vv.writeAvi(filename = exportInfo['file'], images = pilImages,
-                                duration = self.timeTick / float(1000),
-                                encoding = exportInfo['encoding'],
-                                inputOptions = '-sameq')
-            except Exception, e:
-                del busy
-                GError(parent = self.frame, message = str(e))
-                return
-            del busy
-
-
-            # image.SaveFile('/home/anna/testy/grass/export/export_%s.png' % frameIndex, wx.BITMAP_TYPE_PNG)
-
-
-            
-
-
-        
-
-        # for anim in self.animationData
-
-
-        
-
-
 #def test():
 #    import grass.script as grass
 #    import wx

Modified: grass/trunk/gui/wxpython/animation/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/animation/dialogs.py	2013-11-10 03:58:13 UTC (rev 58181)
+++ grass/trunk/gui/wxpython/animation/dialogs.py	2013-11-10 04:00:04 UTC (rev 58182)
@@ -846,14 +846,13 @@
 
 
 class ExportDialog(wx.Dialog):
-    def __init__(self, parent, temporal, timeTick, visvis):
+    def __init__(self, parent, temporal, timeTick):
         wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = _("Export animation"),
                            style = wx.DEFAULT_DIALOG_STYLE)
         self.decorations = []
 
         self.temporal = temporal
         self.timeTick = timeTick
-        self.visvis = visvis
         self._layout()
 
         # export animation
@@ -1006,18 +1005,8 @@
         panel = wx.Panel(notebook, id = wx.ID_ANY)
         borderSizer = wx.BoxSizer(wx.VERTICAL)
 
-        if not self.visvis:
-            isVisvisText = wx.StaticText(panel, id = wx.ID_ANY,
-                                     label = _("To enable export to GIF and SWF, please install visvis library."))
-            isVisvisText.Wrap(400)
-            borderSizer.Add(item = isVisvisText, proportion = 0,
-                            flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.ALL, border = 5)
-
         hSizer = wx.BoxSizer(wx.HORIZONTAL)
-        if not self.visvis:
-            choices = [_("image sequence")]
-        else:
-            choices = [_("image sequence"), _("animated GIF"), _("SWF"), _("AVI")]
+        choices = [_("image sequence"), _("animated GIF"), _("SWF"), _("AVI")]
         self.formatChoice = wx.Choice(parent = panel, id = wx.ID_ANY,
                                       choices = choices)
         self.formatChoice.Bind(wx.EVT_CHOICE, lambda event: self.ChangeFormat(event.GetSelection()))
@@ -1037,13 +1026,10 @@
         # panel for image sequence
         imSeqPanel = wx.Panel(parent = panel, id = wx.ID_ANY)
         prefixLabel = wx.StaticText(imSeqPanel, id = wx.ID_ANY, label = _("File prefix:"))
-        self.prefixCtrl = wx.TextCtrl(imSeqPanel, id = wx.ID_ANY, value = _("animation"))
+        self.prefixCtrl = wx.TextCtrl(imSeqPanel, id = wx.ID_ANY, value = _("animation_"))
         formatLabel = wx.StaticText(imSeqPanel, id = wx.ID_ANY, label = _("File format:"))
-        self.imSeqFormatChoice = wx.Choice(imSeqPanel, id = wx.ID_ANY)
-        wildcard, ltype = GetImageHandlers(wx.EmptyImage(10, 10))
-        formats = [format for format in wildcard.split('|') if 'file' in format]
-        for format, cdata in zip(formats, ltype):
-            self.imSeqFormatChoice.Append(format, cdata)
+        imageTypes = ['PNG', 'JPEG', 'GIF', 'TIFF', 'PPM', 'BMP']
+        self.imSeqFormatChoice = wx.Choice(imSeqPanel, choices=imageTypes)
         self.imSeqFormatChoice.SetSelection(0)
         self.dirBrowse = filebrowse.DirBrowseButton(parent = imSeqPanel, id = wx.ID_ANY,
                                                     labelText = _("Directory:"),
@@ -1277,7 +1263,7 @@
             info['method'] = 'sequence'
             info['directory'] = self.dirBrowse.GetValue()
             info['prefix'] = self.prefixCtrl.GetValue()
-            info['format'] = self.imSeqFormatChoice.GetClientData(self.imSeqFormatChoice.GetSelection())
+            info['format'] = self.imSeqFormatChoice.GetStringSelection()
 
         elif self.formatChoice.GetSelection() == 1:
             info['method'] = 'gif'



More information about the grass-commit mailing list