[GRASS-SVN] r57495 - in grass/trunk/gui/wxpython: . timeline

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 24 10:50:00 PDT 2013


Author: annakrat
Date: 2013-08-24 10:50:00 -0700 (Sat, 24 Aug 2013)
New Revision: 57495

Added:
   grass/trunk/gui/wxpython/timeline/
   grass/trunk/gui/wxpython/timeline/Makefile
   grass/trunk/gui/wxpython/timeline/__init__.py
Modified:
   grass/trunk/gui/wxpython/Makefile
   grass/trunk/gui/wxpython/timeline/frame.py
   grass/trunk/gui/wxpython/timeline/g.gui.timeline.py
Log:
wxGUI: move Timeline Tool (help tool for temporal framework) from addons to trunk, make it pep8 compliant

Modified: grass/trunk/gui/wxpython/Makefile
===================================================================
--- grass/trunk/gui/wxpython/Makefile	2013-08-23 18:55:52 UTC (rev 57494)
+++ grass/trunk/gui/wxpython/Makefile	2013-08-24 17:50:00 UTC (rev 57495)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-SUBDIRS = docs animation mapswipe gmodeler rlisetup psmap dbmgr vdigit iclass gcp
+SUBDIRS = docs animation mapswipe gmodeler rlisetup psmap dbmgr vdigit iclass gcp timeline
 EXTRA_CLEAN_FILES = menustrings.py build_ext.pyc xml/menudata.xml xml/module_tree_menudata.xml
 
 include $(MODULE_TOPDIR)/include/Make/Dir.make
@@ -12,7 +12,7 @@
 SRCFILES := $(wildcard icons/*.py scripts/*.py xml/*) \
 	$(wildcard animation/* core/*.py dbmgr/* gcp/*.py gmodeler/* \
 	gui_core/*.py iclass/* lmgr/*.py location_wizard/*.py mapwin/*.py mapdisp/*.py \
-	mapswipe/* modules/*.py nviz/*.py psmap/* rlisetup/* vdigit/* \
+	mapswipe/* modules/*.py nviz/*.py psmap/* rlisetup/* timeline/* vdigit/* \
 	vnet/*.py web_services/*.py wxplot/*.py) \
 	gis_set.py gis_set_error.py wxgui.py README
 
@@ -21,7 +21,7 @@
 
 PYDSTDIRS := $(patsubst %,$(ETCDIR)/%,animation core dbmgr gcp gmodeler \
 	gui_core iclass lmgr location_wizard mapwin mapdisp modules nviz psmap \
-	mapswipe vdigit wxplot web_services rlisetup vnet)
+	mapswipe vdigit wxplot web_services rlisetup vnet timeline)
 
 DSTDIRS := $(patsubst %,$(ETCDIR)/%,icons scripts xml)
 

Added: grass/trunk/gui/wxpython/timeline/Makefile
===================================================================
--- grass/trunk/gui/wxpython/timeline/Makefile	                        (rev 0)
+++ grass/trunk/gui/wxpython/timeline/Makefile	2013-08-24 17:50:00 UTC (rev 57495)
@@ -0,0 +1,5 @@
+MODULE_TOPDIR = ../../..
+
+include $(MODULE_TOPDIR)/include/Make/GuiScript.make
+
+default: guiscript

Added: grass/trunk/gui/wxpython/timeline/__init__.py
===================================================================
--- grass/trunk/gui/wxpython/timeline/__init__.py	                        (rev 0)
+++ grass/trunk/gui/wxpython/timeline/__init__.py	2013-08-24 17:50:00 UTC (rev 57495)
@@ -0,0 +1,4 @@
+all = [
+    'g.gui.timeline',
+    'frame',
+    ]

Modified: grass/trunk/gui/wxpython/timeline/frame.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.timeline/frame.py	2013-08-23 17:02:04 UTC (rev 57491)
+++ grass/trunk/gui/wxpython/timeline/frame.py	2013-08-24 17:50:00 UTC (rev 57495)
@@ -8,7 +8,7 @@
  - frame::TimelineFrame
  - frame::LookUp
 
-(C) 2012 by the GRASS Development Team
+(C) 2012-13 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.
@@ -17,46 +17,43 @@
 """
 import os
 import sys
-import pprint
-import random
 import wx
-# The recommended way to use wx with mpl is with the WXAgg
-# backend. 
-#
 from math import ceil
 from itertools import cycle
 import numpy as np
 
-import grass.script as grass
-
 try:
     import matplotlib
+    # The recommended way to use wx with mpl is with the WXAgg
+    # backend.
+    matplotlib.use('WXAgg')
+    from matplotlib.figure import Figure
+    import matplotlib.pyplot as plt
+    from matplotlib.backends.backend_wxagg import \
+        FigureCanvasWxAgg as FigCanvas, \
+        NavigationToolbar2WxAgg as NavigationToolbar
+    import matplotlib.dates as mdates
+    from matplotlib import cbook
 except ImportError:
-    grass.fatal(_("Matplotlib is not installed"))
+    raise ImportError(_('The Timeline Tool needs "Matplotlib" package to be installed.'))
 
-matplotlib.use('WXAgg')
-from matplotlib.figure import Figure
-import matplotlib.pyplot as plt
-from matplotlib.backends.backend_wxagg import \
-    FigureCanvasWxAgg as FigCanvas, \
-    NavigationToolbar2WxAgg as NavigationToolbar
-
-import matplotlib.dates as mdates
-from matplotlib import cbook
-from mpl_toolkits.mplot3d import Axes3D
-
 if __name__ == '__main__':
     sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
 
+import grass.script as grass
+from core.utils import _
+
 import grass.temporal as tgis
-from core.gcmd import RunCommand, GError, GException
+from core.gcmd import GError, GException, RunCommand
 from gui_core import gselect
 from core import globalvar
 
 ALPHA = 0.5
 COLORS = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
 
+
 def check_version(*version):
+    """!Checks if given version or newer is installed"""
     versionInstalled = []
     for i in matplotlib.__version__.split('.'):
         try:
@@ -69,10 +66,11 @@
     else:
         return True
 
+
 class TimelineFrame(wx.Frame):
     """!The main frame of the application"""
     def __init__(self, parent):
-        wx.Frame.__init__(self, parent, id = wx.ID_ANY, title = _("Timeline Tool"))
+        wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=_("Timeline Tool"))
 
         tgis.init()
         self.datasets = []
@@ -81,20 +79,19 @@
         self.temporalType = None
         self.unit = None
 
-
     def _layout(self):
         """!Creates the main panel with all the controls on it:
-             * mpl canvas 
+             * mpl canvas
              * mpl navigation toolbar
              * Control panel for interaction
         """
         self.panel = wx.Panel(self)
-        
-        # Create the mpl Figure and FigCanvas objects. 
+
+        # Create the mpl Figure and FigCanvas objects.
         # 5x4 inches, 100 dots-per-inch
         #
-        # color =  wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND) 
-        self.fig = Figure((5.0, 4.0), facecolor = (1, 1, 1))
+        # color =  wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND)
+        self.fig = Figure((5.0, 4.0), facecolor=(1, 1, 1))
         self.canvas = FigCanvas(self.panel, wx.ID_ANY, self.fig)
         # axes are initialized later
         self.axes2d = None
@@ -103,38 +100,43 @@
         # Create the navigation toolbar, tied to the canvas
         #
         self.toolbar = NavigationToolbar(self.canvas)
-        
+
         #
         # Layout
         #
-        
+
         self.vbox = wx.BoxSizer(wx.VERTICAL)
         self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
         self.vbox.Add(self.toolbar, 0, wx.EXPAND)
         self.vbox.AddSpacer(10)
-        
-        gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
 
-        self.datasetSelect = gselect.Select(parent = self.panel, id = wx.ID_ANY,
-                                            size = globalvar.DIALOG_GSELECT_SIZE,
-                                            type = 'stds', multiple = True)
-        self.drawButton = wx.Button(self.panel, id = wx.ID_ANY, label = _("Draw"))
+        gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
+
+        self.datasetSelect = gselect.Select(parent=self.panel, id=wx.ID_ANY,
+                                            size=globalvar.DIALOG_GSELECT_SIZE,
+                                            type='stds', multiple=True)
+        self.drawButton = wx.Button(self.panel, id=wx.ID_ANY, label=_("Draw"))
         self.drawButton.Bind(wx.EVT_BUTTON, self.OnRedraw)
-        self.view3dCheck = wx.CheckBox(self.panel, id = wx.ID_ANY, label = _("3D plot of spatio-temporal extents"))
+        self.helpButton = wx.Button(self.panel, id=wx.ID_ANY, label=_("Help"))
+        self.helpButton.Bind(wx.EVT_BUTTON, self.OnHelp)
+        self.view3dCheck = wx.CheckBox(self.panel, id=wx.ID_ANY,
+                                       label=_("3D plot of spatio-temporal extents"))
         self.view3dCheck.Bind(wx.EVT_CHECKBOX, self.OnRedraw)
         if not check_version(1, 0, 0):
-            self.view3dCheck.SetLabel(_("3D plot of spatio-temporal extents (matplotlib >= 1.0.0)"))
+            self.view3dCheck.SetLabel(_("3D plot of spatio-temporal extents "
+                                        "(matplotlib >= 1.0.0)"))
             self.view3dCheck.Disable()
 
-        gridSizer.Add(wx.StaticText(self.panel, id = wx.ID_ANY, label = _("Select space time dataset(s):")),
-                      pos = (0, 0), flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
-        gridSizer.Add(self.datasetSelect, pos = (1, 0), flag = wx.EXPAND)
-        gridSizer.Add(self.drawButton, pos = (1, 1), flag = wx.EXPAND)
-        gridSizer.Add(self.view3dCheck, pos = (2, 0), flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(wx.StaticText(self.panel, id=wx.ID_ANY,
+                                    label=_("Select space time dataset(s):")),
+                      pos=(0, 0), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(self.datasetSelect, pos=(1, 0), flag=wx.EXPAND)
+        gridSizer.Add(self.drawButton, pos=(1, 1), flag=wx.EXPAND)
+        gridSizer.Add(self.helpButton, pos=(1, 2), flag=wx.EXPAND)
+        gridSizer.Add(self.view3dCheck, pos=(2, 0), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
 
+        self.vbox.Add(gridSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=10)
 
-        self.vbox.Add(gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 10)
-        
         self.panel.SetSizer(self.vbox)
         self.vbox.Fit(self)
 
@@ -148,29 +150,28 @@
             etype = series[2]
             sp = tgis.dataset_factory(etype, name)
             if not sp.is_in_db():
-                GError(self, message = _("Dataset <%s> not found in temporal database") % (name))
+                GError(self, message=_("Dataset <%s> not found in temporal database") % (name))
                 return
 
             sp.select()
 
             self.timeData[name] = {}
             self.timeData[name]['elementType'] = series[2]
-            self.timeData[name]['temporalType'] = sp.get_temporal_type() # abs/rel
+            self.timeData[name]['temporalType'] = sp.get_temporal_type()  # abs/rel
 
-            extent = dict(zip(['north', 'south', 'west', 'east', 'top', 'bottom'], sp.get_spatial_extent()))
-            self.timeData[name]['spatialExtent'] = extent
             if mode is None:
                 mode = self.timeData[name]['temporalType']
             elif self.timeData[name]['temporalType'] != mode:
-                GError(parent = self, message = _("Datasets have different temporal type (absolute x relative), which is not allowed."))
+                GError(parent=self, message=_("Datasets have different temporal type "
+                                              "(absolute x relative), which is not allowed."))
                 return
 
             # check topology
             maps = sp.get_registered_maps_as_objects()
             self.timeData[name]['validTopology'] = sp.check_temporal_topology(maps)
 
-            self.timeData[name]['temporalMapType'] = sp.get_map_time() # point/interval
-            self.timeData[name]['unit'] = None # only with relative
+            self.timeData[name]['temporalMapType'] = sp.get_map_time()  # point/interval
+            self.timeData[name]['unit'] = None  # only with relative
             if self.timeData[name]['temporalType'] == 'relative':
                 start, end, self.timeData[name]['unit'] = sp.get_relative_time()
                 if unit is None:
@@ -189,10 +190,11 @@
             self.timeData[name]['west'] = []
             self.timeData[name]['east'] = []
 
+            columns = ','.join(['name', 'start_time', 'end_time',
+                                'north', 'south', 'west', 'east'])
 
-            columns = ','.join(['name', 'start_time', 'end_time', 'north', 'south', 'west', 'east'])
-            
-            rows = sp.get_registered_maps(columns = columns, where = None, order = 'start_time', dbif = None)
+            rows = sp.get_registered_maps(columns=columns, where=None,
+                                          order='start_time', dbif=None)
             if rows is None:
                 rows = []
             for row in rows:
@@ -228,7 +230,7 @@
 
         colors = cycle(COLORS)
         plots = []
-        for i, name in enumerate(self.datasets):
+        for name in self.datasets:
             name = name[0] + '@' + name[1]
             startZ = convert(self.timeData[name]['start_datetime'])
             mapType = self.timeData[name]['temporalMapType']
@@ -244,9 +246,10 @@
             dY = self.timeData[name]['north'] - np.array(startY)
 
             color = colors.next()
-            plots.append(self.axes3d.bar3d(startX, startY, startZ, dX, dY, dZ, color = color, alpha = ALPHA))
+            plots.append(self.axes3d.bar3d(startX, startY, startZ, dX, dY, dZ,
+                                           color=color, alpha=ALPHA))
 
-        params = grass.read_command('g.proj', flags = 'g')
+        params = grass.read_command('g.proj', flags='g')
         params = grass.parse_key_val(params)
         if 'unit' in params:
             self.axes3d.set_xlabel(_("X [%s]") % params['unit'])
@@ -258,7 +261,6 @@
         self.axes3d.set_zlabel(_('Time'))
         self.axes3d.mouse_init()
         self.canvas.draw()
-        
 
     def _draw2dFigure(self):
         """!Draws 2D plot (temporal extents)"""
@@ -292,19 +294,20 @@
                 lookUpData = zip(start, end)
                 duration = end - np.array(start)
                 barData = zip(start, duration)
-                yrange = (i - 0.1, 0.2)
-                lookUp.AddDataset(type = 'bar', yrange = (i - 0.1, i + 0.1), xranges = lookUpData, datasetName = name)
-                
+                lookUp.AddDataset(type_='bar', yrange=(i - 0.1, i + 0.1),
+                                  xranges=lookUpData, datasetName=name)
+
             else:
                 # self.timeData[name]['end_plot'] = None
                 pointData = start
-                lookUp.AddDataset(type = 'point', yrange = i, xranges = pointData, datasetName = name)
+                lookUp.AddDataset(type_='point', yrange=i, xranges=pointData, datasetName=name)
             color = colors.next()
             if mapType == 'interval':
-                plots.append(self.axes2d.broken_barh(xranges = barData , yrange = (i - 0.1, 0.2),
-                                                     facecolors = color, alpha = ALPHA))
+                plots.append(self.axes2d.broken_barh(xranges=barData, yrange=(i - 0.1, 0.2),
+                                                     facecolors=color, alpha=ALPHA))
             else:
-                plots.append(self.axes2d.plot(pointData, [i] * len(pointData), marker = 'o', linestyle = 'None', color = color)[0])
+                plots.append(self.axes2d.plot(pointData, [i] * len(pointData),
+                                              marker='o', linestyle='None', color=color)[0])
 
         if self.temporalType == 'absolute':
             pass
@@ -312,17 +315,15 @@
         else:
             self.axes2d.set_xlabel(_("Time [%s]") % self.unit)
 
-
         self.axes2d.set_yticks(yticksPos)
         self.axes2d.set_yticklabels(yticksNames)
-        self.axes2d.set_ylim(min(yticksPos)-1, max(yticksPos) + 1)
+        self.axes2d.set_ylim(min(yticksPos) - 1, max(yticksPos) + 1)
 
         # adjust xlim
         xlim = self.axes2d.get_xlim()
         padding = ceil((xlim[1] - xlim[0]) / 20.)
         self.axes2d.set_xlim(xlim[0] - padding, xlim[1] + padding)
 
-        
         self.canvas.draw()
         DataCursor(plots, lookUp, InfoFormat)
 
@@ -334,14 +335,14 @@
         try:
             datasets = self._checkDatasets(datasets)
         except GException:
-            GError(parent = self, message = _("Invalid input data"))
+            GError(parent=self, message=_("Invalid input data"))
             return
 
         self.datasets = datasets
         self._redraw()
-        
+
     def _redraw(self):
-        """!Readraw data. 
+        """!Readraw data.
 
         Decides if to draw also 3D and adjusts layout if needed.
         """
@@ -353,9 +354,11 @@
         self._draw2dFigure()
         if check_version(1, 0, 0):
             if self.view3dCheck.IsChecked():
-                self.axes2d.change_geometry(2,1,1)
+                self.axes2d.change_geometry(2, 1, 1)
                 if not self.axes3d:
-                    self.axes3d = self.fig.add_subplot(2, 1, 2, projection = '3d')
+                    # do not remove this import - unused but it is required for 3D
+#                    from mpl_toolkits.mplot3d import Axes3D  # pylint: disable=W0611
+                    self.axes3d = self.fig.add_subplot(2, 1, 2, projection='3d')
 
                 self.axes3d.set_visible(True)
                 self._draw3dFigure()
@@ -363,7 +366,7 @@
                 if self.axes3d:
                     self.fig.delaxes(self.axes3d)
                     self.axes3d = None
-                self.axes2d.change_geometry(1,1,1)
+                self.axes2d.change_geometry(1, 1, 1)
                 self.canvas.draw()
 
         if check_version(1, 1, 0):
@@ -381,14 +384,14 @@
         @return (mapName, mapset, type)
         """
         validated = []
-        tDict = tgis.tlist_grouped('stds', group_type = True)
+        tDict = tgis.tlist_grouped('stds', group_type=True)
         # nested list with '(map, mapset, etype)' items
         allDatasets = [[[(map, mapset, etype) for map in maps]
                      for etype, maps in etypesDict.iteritems()]
                     for mapset, etypesDict in tDict.iteritems()]
         # flatten this list
-        allDatasets = reduce(lambda x,y: x+y, reduce(lambda x,y: x+y, allDatasets))
-        
+        allDatasets = reduce(lambda x, y: x + y, reduce(lambda x, y: x + y, allDatasets))
+
         for dataset in datasets:
             errorMsg = _("Space time dataset <%s> not found.") % dataset
             if dataset.find("@") >= 0:
@@ -403,12 +406,13 @@
                 raise GException(errorMsg)
             elif len(indices) >= 2:
                 dlg = wx.SingleChoiceDialog(self,
-                         message = _("Please specify the space time dataset <%s>." % dataset),
-                         caption = _("Ambiguous dataset name"),
-                         choices = [("%(map)s@%(mapset)s: %(etype)s" % {'map': allDatasets[i][0],
-                                                                        'mapset': allDatasets[i][1],
-                                                                        'etype': allDatasets[i][2]}) for i in indices],
-                         style = wx.CHOICEDLG_STYLE | wx.OK)
+                         message=_("Please specify the space time dataset <%s>." % dataset),
+                         caption=_("Ambiguous dataset name"),
+                         choices=[("%(map)s@%(mapset)s: %(etype)s" % {'map': allDatasets[i][0],
+                                                                      'mapset': allDatasets[i][1],
+                                                                      'etype': allDatasets[i][2]})
+                                                                               for i in indices],
+                         style=wx.CHOICEDLG_STYLE | wx.OK)
                 if dlg.ShowModal() == wx.ID_OK:
                     index = dlg.GetSelection()
                     validated.append(allDatasets[indices[index]])
@@ -417,6 +421,9 @@
 
         return validated
 
+    def OnHelp(self, event):
+        RunCommand('g.manual', quiet=True, entry='g.gui.timeline')
+
 #  interface
 
     def SetDatasets(self, datasets):
@@ -426,7 +433,7 @@
         try:
             datasets = self._checkDatasets(datasets)
         except GException:
-            GError(parent = self, message = _("Invalid input data"))
+            GError(parent=self, message=_("Invalid input data"))
             return
         self.datasets = datasets
         self.datasetSelect.SetValue(','.join(map(lambda x: x[0] + '@' + x[1], datasets)))
@@ -444,18 +451,18 @@
         self.data = {}
         self.timeData = timeData
 
-    def AddDataset(self, type, yrange, xranges, datasetName):
-        if type == 'bar':
+    def AddDataset(self, type_, yrange, xranges, datasetName):
+        if type_ == 'bar':
             self.data[yrange] = {'name': datasetName}
             for i, (start, end) in enumerate(xranges):
                 self.data[yrange][(start, end)] = i
-        elif type == 'point':
+        elif type_ == 'point':
             self.data[(yrange, yrange)] = {'name': datasetName}
             for i, start in enumerate(xranges):
                 self.data[(yrange, yrange)][(start, start)] = i
 
     def GetInformation(self, x, y):
-        keys  = None
+        keys = None
         for keyY in self.data.keys():
             if keyY[0] <= y <= keyY[1]:
                 for keyX in self.data[keyY].keys():
@@ -490,6 +497,8 @@
     if not timeData[datasetName]['validTopology']:
         text.append(_("WARNING: invalid topology"))
 
+    text.append(_("\nPress Del to dismiss."))
+
     return '\n'.join(text)
 
 
@@ -501,18 +510,18 @@
     Source: http://stackoverflow.com/questions/4652439/
             is-there-a-matplotlib-equivalent-of-matlabs-datacursormode/4674445
     """
-    def __init__(self, artists, lookUp, formatFunction, tolerance=5, offsets=(-30, 30), 
+    def __init__(self, artists, lookUp, formatFunction, tolerance=5, offsets=(-30, 30),
                  display_all=False):
         """Create the data cursor and connect it to the relevant figure.
-        "artists" is the matplotlib artist or sequence of artists that will be 
-            selected. 
+        "artists" is the matplotlib artist or sequence of artists that will be
+            selected.
         "tolerance" is the radius (in points) that the mouse click must be
             within to select the artist.
         "offsets" is a tuple of (x,y) offsets in points from the selected
             point to the displayed annotation box
         "display_all" controls whether more than one annotation box will
             be shown if there are multiple axes.  Only one will be shown
-            per-axis, regardless. 
+            per-axis, regardless.
         """
         self.lookUp = lookUp
         self.formatFunction = formatFunction
@@ -521,7 +530,7 @@
         if not cbook.iterable(artists):
             artists = [artists]
         self.artists = artists
-        
+
         self.axes = tuple(set(art.axes for art in self.artists))
         self.figures = tuple(set(ax.figure for ax in self.axes))
 
@@ -532,15 +541,25 @@
             artist.set_picker(tolerance)
         for fig in self.figures:
             fig.canvas.mpl_connect('pick_event', self)
+            fig.canvas.mpl_connect('key_press_event', self.keyPressed)
 
+    def keyPressed(self, event):
+        """!Key pressed - hide annotation if Delete was pressed"""
+        if event.key != 'delete':
+            return
+        for ax in self.axes:
+            self.annotations[ax].set_visible(False)
+            event.canvas.draw()
+
     def annotate(self, ax):
         """Draws and hides the annotation box for the given axis "ax"."""
-        annotation = ax.annotate(self.formatFunction, xy=(0, 0), ha = 'center',
+        annotation = ax.annotate(self.formatFunction, xy=(0, 0), ha='center',
                 xytext=self.offsets, textcoords='offset points', va='bottom',
                 bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.7),
                 arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'),
-                annotation_clip = False, multialignment = 'left')
+                annotation_clip=False, multialignment='left')
         annotation.set_visible(False)
+
         return annotation
 
     def __call__(self, event):
@@ -556,11 +575,11 @@
                     ann.set_visible(False)
             # Update the annotation in the current axis..
             annotation.xy = x, y
-            
+
             if 'Line2D' in str(type(event.artist)):
-                y =  event.artist.get_ydata()[0]
+                y = event.artist.get_ydata()[0]
                 xData = event.artist.get_xdata()
-                x =  xData[np.argmin(abs(xData - x))]
+                x = xData[np.argmin(abs(xData - x))]
 
             info = self.lookUp.GetInformation(x, y)
             if not info:
@@ -569,3 +588,14 @@
             annotation.set_text(text)
             annotation.set_visible(True)
             event.canvas.draw()
+
+
+def run(parent=None, datasets=None):
+    frame = TimelineFrame(parent)
+    if datasets:
+        frame.SetDatasets(datasets)
+    frame.Show()
+
+
+if __name__ == '__main__':
+    run()

Modified: grass/trunk/gui/wxpython/timeline/g.gui.timeline.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.timeline/g.gui.timeline.py	2013-08-23 17:02:04 UTC (rev 57491)
+++ grass/trunk/gui/wxpython/timeline/g.gui.timeline.py	2013-08-24 17:50:00 UTC (rev 57495)
@@ -5,7 +5,7 @@
 # AUTHOR(S): Anna Kratochvilova
 # PURPOSE:   Timeline Tool is a wxGUI component (based on matplotlib)
 #            which allows the user to compare temporal datasets' extents.
-# COPYRIGHT: (C) 2012 by Anna Kratochvilova, and the GRASS Development Team
+# COPYRIGHT: (C) 2012-13 by Anna Kratochvilova, and the GRASS Development Team
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -33,28 +33,27 @@
 
 import os
 import sys
-
 import  wx
-import gettext
 
+gui_wx_path = os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython')
+if gui_wx_path not in sys.path:
+    sys.path.append(gui_wx_path)
+
 import grass.script as grass
+from core.utils import _, GuiModuleMain
 
-# if __name__ == '__main__':
-#     sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
 
-sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc', 'g.gui.timeline'))
-
 def main():
-    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+    try:
+        from timeline.frame import TimelineFrame
+    except ImportError, e:
+        grass.fatal(e.message)
 
-    options, flags = grass.parser()
-
     datasets = options['inputs'].strip().split(',')
     datasets = [data for data in datasets if data]
     view3d = flags['3']
 
-    app = wx.PySimpleApp()
-    from frame import TimelineFrame
+    app = wx.App()
     frame = TimelineFrame(None)
     frame.SetDatasets(datasets)
     frame.Show3D(view3d)
@@ -63,5 +62,6 @@
 
 
 if __name__ == '__main__':
-    main()
+    options, flags = grass.parser()
 
+    GuiModuleMain(main)



More information about the grass-commit mailing list