Forráskód Böngészése

wxplot: add giface to write log correctly (#428)

Anna Petrasova 5 éve
szülő
commit
ab1e4bda8d

+ 1 - 2
gui/wxpython/lmgr/layertree.py

@@ -39,7 +39,6 @@ from mapdisp.frame import MapFrame
 from core.render import Map
 from wxplot.histogram import HistogramPlotFrame
 from core.utils import GetLayerNameFromCmd, ltype2command
-from wxplot.profile import ProfileFrame
 from core.debug import Debug
 from core.settings import UserSettings, GetDisplayVectSettings
 from vdigit.main import haveVDigit
@@ -1127,7 +1126,7 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
                              "raster map. No map name defined."))
             return
 
-        win = HistogramPlotFrame(parent=self, rasterList=rasterList)
+        win = HistogramPlotFrame(parent=self, giface=self._giface, rasterList=rasterList)
         win.CentreOnScreen()
         win.Show()
 

+ 4 - 3
gui/wxpython/mapdisp/frame.py

@@ -1144,7 +1144,7 @@ class MapFrame(SingleMapFrame):
 
         self.profileController = ProfileController(
             self._giface, mapWindow=self.GetMapWindow())
-        win = ProfileFrame(parent=self, rasterList=rasters,
+        win = ProfileFrame(parent=self, giface=self._giface, rasterList=rasters,
                            units=self.Map.projinfo['units'],
                            controller=self.profileController)
         win.Show()
@@ -1162,7 +1162,8 @@ class MapFrame(SingleMapFrame):
                 raster.append(layer.maplayer.GetName())
 
         from wxplot.histogram import HistogramPlotFrame
-        win = HistogramPlotFrame(parent=self, rasterList=raster)
+        win = HistogramPlotFrame(parent=self, giface=self._giface,
+                                 rasterList=raster)
         win.CentreOnParent()
         win.Show()
 
@@ -1176,7 +1177,7 @@ class MapFrame(SingleMapFrame):
                 raster.append(layer.maplayer.GetName())
 
         from wxplot.scatter import ScatterFrame
-        win = ScatterFrame(parent=self, rasterList=raster)
+        win = ScatterFrame(parent=self, giface=self._giface, rasterList=raster)
 
         win.CentreOnParent()
         win.Show()

+ 1 - 0
gui/wxpython/mapdisp/test_mapdisp.py

@@ -267,6 +267,7 @@ class Tester(object):
 
         from wxplot.profile import ProfileFrame
         profileWindow = ProfileFrame(parent=self.frame,
+                                     giface=giface,
                                      controller=self.controller,
                                      units=map_.projinfo['units'],
                                      rasterList=rasters)

+ 4 - 3
gui/wxpython/wxplot/base.py

@@ -56,7 +56,7 @@ PlotIcons = {
 class BasePlotFrame(wx.Frame):
     """Abstract PyPlot display frame class"""
 
-    def __init__(self, parent=None, size=wx.Size(700, 400),
+    def __init__(self, parent=None, giface=None, size=wx.Size(700, 400),
                  style=wx.DEFAULT_FRAME_STYLE, rasterList=[], **kwargs):
 
         wx.Frame.__init__(
@@ -68,6 +68,7 @@ class BasePlotFrame(wx.Frame):
             **kwargs)
 
         self.parent = parent  # MapFrame for a plot type
+        self._giface = giface
         self.Map = Map()             # instance of render.Map to be associated with display
         self.rasterList = rasterList  # list of rasters to plot
         self.raster = {}    # dictionary of raster maps and their plotting parameters
@@ -572,7 +573,7 @@ class BasePlotFrame(wx.Frame):
     def PlotText(self, event):
         """Set custom text values for profile title and axis labels.
         """
-        dlg = TextDialog(parent=self, id=wx.ID_ANY,
+        dlg = TextDialog(parent=self, giface=self._giface, id=wx.ID_ANY,
                          plottype=self.plottype,
                          title=_('Text settings'))
 
@@ -586,7 +587,7 @@ class BasePlotFrame(wx.Frame):
         options.  Calls OptDialog class.
         """
 
-        dlg = OptDialog(parent=self, id=wx.ID_ANY,
+        dlg = OptDialog(parent=self, giface=self._giface, id=wx.ID_ANY,
                         plottype=self.plottype,
                         title=_('Plot settings'))
         btnval = dlg.ShowModal()

+ 7 - 15
gui/wxpython/wxplot/dialogs.py

@@ -613,7 +613,7 @@ class HistRasterDialog(wx.Dialog):
 
 class TextDialog(wx.Dialog):
 
-    def __init__(self, parent, id, title, plottype='',
+    def __init__(self, parent, giface, id, title, plottype='',
                  style=wx.DEFAULT_DIALOG_STYLE, **kwargs):
         """Dialog to set histogram text options: font, title
         and font size, axis labels and font size
@@ -622,6 +622,7 @@ class TextDialog(wx.Dialog):
         #
         # initialize variables
         #
+        self._giface = giface
         # combo box entry lists
         self.ffamilydict = {'default': wx.FONTFAMILY_DEFAULT,
                             'decorative': wx.FONTFAMILY_DECORATIVE,
@@ -834,7 +835,6 @@ class TextDialog(wx.Dialog):
         btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
         btnSave.SetToolTip(
             _("Apply and save changes to user settings file (default for next sessions)"))
-        btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
         btnCancel.SetToolTip(_("Close dialog and ignore changes"))
 
         # sizers
@@ -900,7 +900,7 @@ class TextDialog(wx.Dialog):
         UserSettings.ReadSettingsFile(settings=fileSettings)
         fileSettings[self.plottype] = UserSettings.Get(group=self.plottype)
         UserSettings.SaveToFile(fileSettings)
-        self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(
+        self._giface.WriteLog(
             _('Plot text sizes saved to file \'%s\'.') % UserSettings.filePath)
         self.EndModal(wx.ID_OK)
 
@@ -914,14 +914,10 @@ class TextDialog(wx.Dialog):
         self.OnApply(None)
         self.EndModal(wx.ID_OK)
 
-    def OnCancel(self, event):
-        """Button 'Cancel' pressed"""
-        self.EndModal(wx.ID_CANCEL)
-
 
 class OptDialog(wx.Dialog):
 
-    def __init__(self, parent, id, title, plottype='',
+    def __init__(self, parent, giface, id, title, plottype='',
                  style=wx.DEFAULT_DIALOG_STYLE, **kwargs):
         """Dialog to set various options for data plotted, including: line
         width, color, style; marker size, color, fill, and style; grid
@@ -931,6 +927,7 @@ class OptDialog(wx.Dialog):
 
         # init variables
         self.parent = parent
+        self._giface = giface
         self.linestyledict = parent.linestyledict
         self.ptfilldict = parent.ptfilldict
         self.parent = parent
@@ -1464,7 +1461,6 @@ class OptDialog(wx.Dialog):
         btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
         btnOk.SetDefault()
         btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
-        btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
 
         self.SetSizer(sizer)
         sizer.Fit(self)
@@ -1593,9 +1589,9 @@ class OptDialog(wx.Dialog):
         UserSettings.ReadSettingsFile(settings=fileSettings)
         fileSettings[self.plottype] = UserSettings.Get(group=self.plottype)
         UserSettings.SaveToFile(fileSettings)
-        self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(
+        self._giface.WriteLog(
             _('Plot settings saved to file \'%s\'.') % UserSettings.filePath)
-        self.Close()
+        self.EndModal(wx.ID_OK)
 
     def OnApply(self, event):
         """Button 'Apply' pressed. Does not close dialog"""
@@ -1608,7 +1604,3 @@ class OptDialog(wx.Dialog):
         """Button 'OK' pressed"""
         self.OnApply(None)
         self.EndModal(wx.ID_OK)
-
-    def OnCancel(self, event):
-        """Button 'Cancel' pressed"""
-        self.Close()

+ 2 - 2
gui/wxpython/wxplot/histogram.py

@@ -32,9 +32,9 @@ class HistogramPlotFrame(BasePlotFrame):
     """Mainframe for displaying histogram of raster map. Uses wx.lib.plot.
     """
 
-    def __init__(self, parent, id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE,
+    def __init__(self, parent, giface, id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE,
                  size=wx.Size(700, 400), rasterList=[], **kwargs):
-        BasePlotFrame.__init__(self, parent, size=size, **kwargs)
+        BasePlotFrame.__init__(self, parent, giface=giface, size=size, **kwargs)
 
         self.toolbar = HistogramPlotToolbar(parent=self)
         # workaround for http://trac.wxwidgets.org/ticket/13888

+ 2 - 2
gui/wxpython/wxplot/profile.py

@@ -36,9 +36,9 @@ class ProfileFrame(BasePlotFrame):
     """Mainframe for displaying profile of one or more raster maps. Uses wx.lib.plot.
     """
 
-    def __init__(self, parent, controller, units, size=wx.Size(700, 400),
+    def __init__(self, parent, giface, controller, units, size=wx.Size(700, 400),
                  rasterList=None, **kwargs):
-        BasePlotFrame.__init__(self, parent=parent, size=size, **kwargs)
+        BasePlotFrame.__init__(self, parent=parent, giface=giface, size=size, **kwargs)
 
         self.controller = controller
         self.controller.transectChanged.connect(self.SetTransect)

+ 2 - 2
gui/wxpython/wxplot/scatter.py

@@ -32,10 +32,10 @@ class ScatterFrame(BasePlotFrame):
     """Mainframe for displaying bivariate scatter plot of two raster maps. Uses wx.lib.plot.
     """
 
-    def __init__(self, parent, id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE,
+    def __init__(self, parent, giface, id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE,
                  size=wx.Size(700, 400),
                  rasterList=[], **kwargs):
-        BasePlotFrame.__init__(self, parent, size=size, **kwargs)
+        BasePlotFrame.__init__(self, parent, giface=giface, size=size, **kwargs)
 
         self.toolbar = ScatterToolbar(parent=self)
         # workaround for http://trac.wxwidgets.org/ticket/13888