소스 검색

wxGUI loc wizard: Improve new location's CRS method selection page (#721)

WKT page now accepts string rather than file.
Linda Kladivova 4 년 전
부모
커밋
f56d21d10c
1개의 변경된 파일55개의 추가작업 그리고 83개의 파일을 삭제
  1. 55 83
      gui/wxpython/location_wizard/wizard.py

+ 55 - 83
gui/wxpython/location_wizard/wizard.py

@@ -318,7 +318,7 @@ class CoordinateSystemPage(TitledPage):
 
     def __init__(self, wizard, parent):
         TitledPage.__init__(self, wizard, _(
-            "Choose method for creating a new location"))
+            "Select Coordinate Reference System (CRS)"))
         
         self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
         self.sizer.SetCols(5)
@@ -329,47 +329,42 @@ class CoordinateSystemPage(TitledPage):
 
         # toggles
         self.radioEpsg = wx.RadioButton(parent=self, id=wx.ID_ANY, label=_(
-            "Select coordinate reference system by EPSG"), style=wx.RB_GROUP)
+            "Select CRS from a list by EPSG or description"), style=wx.RB_GROUP)
         #self.radioIau = wx.RadioButton(
         #    parent=self, id=wx.ID_ANY,
         #    label=_("Select IAU code of spatial reference system"))
         self.radioFile = wx.RadioButton(
             parent=self, id=wx.ID_ANY, label=_(
-                "Read projection and datum terms from a "
-                "georeferenced data file"))
+                "Read CRS from a georeferenced data file"))
+        self.radioXy = wx.RadioButton(parent=self, id=wx.ID_ANY, label=_(
+                "Create a generic cartesian coordinate system (XY)"))
         self.radioWkt = wx.RadioButton(
             parent=self, id=wx.ID_ANY, label=_(
-                "Read projection and datum terms from a "
-                "Well Known Text (WKT) .prj file"))
-        self.radioSrs = wx.RadioButton(parent=self, id=wx.ID_ANY, label=_(
-            "Select coordinate system parameters from a list"))
+                "Specify CRS using WKT string"))
         self.radioProj = wx.RadioButton(
             parent=self, id=wx.ID_ANY, label=_(
-                "Specify projection and datum terms using custom "
-                "PROJ.4 parameters"))
-        self.radioXy = wx.RadioButton(parent=self, id=wx.ID_ANY, label=_(
-            "Create a generic Cartesian coordinate system (XY)"))
+                "Specify CRS using PROJ.4 string"))
+        self.radioSrs = wx.RadioButton(parent=self, id=wx.ID_ANY, label=_(
+                "Define custom CRS"))
 
         # layout
         self.sizer.SetVGap(10)
-        self.sizer.Add(StaticText(parent=self, label=_("Simple methods:")),
-                       flag=wx.ALIGN_LEFT, pos=(1, 1))
         self.sizer.Add(self.radioEpsg,
-                       flag=wx.ALIGN_LEFT, pos=(2, 1))
+                       flag=wx.ALIGN_LEFT, pos=(1, 1))
         #self.sizer.Add(self.radioIau,
         #               flag=wx.ALIGN_LEFT, pos=(1, 1))
         self.sizer.Add(self.radioFile,
+                       flag=wx.ALIGN_LEFT, pos=(2, 1))
+        self.sizer.Add(self.radioXy,
                        flag=wx.ALIGN_LEFT, pos=(3, 1))
-        self.sizer.Add(self.radioWkt,
+        self.sizer.Add(StaticText(parent=self, label=_("Additional methods:")),
                        flag=wx.ALIGN_LEFT, pos=(4, 1))
-        self.sizer.Add(self.radioXy,
+        self.sizer.Add(self.radioWkt,
                        flag=wx.ALIGN_LEFT, pos=(5, 1))
-        self.sizer.Add(StaticText(parent=self, label=_("Advanced methods:")),
+        self.sizer.Add(self.radioProj,
                        flag=wx.ALIGN_LEFT, pos=(6, 1))
         self.sizer.Add(self.radioSrs,
                        flag=wx.ALIGN_LEFT, pos=(7, 1))
-        self.sizer.Add(self.radioProj,
-                       flag=wx.ALIGN_LEFT, pos=(8, 1))
         self.sizer.AddGrowableCol(1)
 
         # bindings
@@ -464,10 +459,10 @@ class CoordinateSystemPage(TitledPage):
 
 
 class ProjectionsPage(TitledPage):
-    """Wizard page for selecting projection (select coordinate system option)"""
+    """Wizard page for defining custom CRS"""
 
     def __init__(self, wizard, parent):
-        TitledPage.__init__(self, wizard, _("Choose projection"))
+        TitledPage.__init__(self, wizard, _("Define custom CRS"))
         
         self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
         self.sizer.SetCols(5)
@@ -1367,7 +1362,7 @@ class GeoreferencedFilePage(TitledPage):
     for setting coordinate system parameters"""
 
     def __init__(self, wizard, parent):
-        TitledPage.__init__(self, wizard, _("Select georeferenced file"))
+        TitledPage.__init__(self, wizard, _("Read CRS from a georeferenced data file"))
         
         self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
         self.sizer.SetCols(5)
@@ -1413,8 +1408,6 @@ class GeoreferencedFilePage(TitledPage):
             event.Veto()
         self.GetNext().SetPrev(self)
 
-        event.Skip()
-
     def OnText(self, event):
         """File changed"""
         self.georeffile = event.GetString()
@@ -1447,37 +1440,37 @@ class WKTPage(TitledPage):
 
     def __init__(self, wizard, parent):
         TitledPage.__init__(self, wizard, _(
-            "Select Well Known Text (WKT) .prj file"))
+            "Specify CRS using WKT string"))
         
         self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
         self.sizer.SetCols(5)
         self.sizer.SetRows(8)
         
-        self.wktfile = ''
+        self.wktstring = ''
+        self.parent = parent
 
-        # create controls
-        self.lfile = self.MakeLabel(_("WKT .prj file:"))
-        self.tfile = self.MakeTextCtrl(size=(300, -1))
-        self.bbrowse = self.MakeButton(_("Browse"))
+        # widgets
+        self.text_wkt = self.MakeTextCtrl(size=(400, 200),
+                                          style=wx.TE_MULTILINE)
+        self.label_wkt = self.MakeLabel(
+            _("Enter WKT parameters string:"))
 
-        # do layout
-        self.sizer.Add(self.lfile, flag=wx.ALIGN_LEFT |
-                       wx.ALIGN_CENTRE_VERTICAL |
-                       wx.ALL, border=5, pos=(1, 1))
-        self.sizer.Add(self.tfile, flag=wx.ALIGN_LEFT |
-                       wx.ALIGN_CENTRE_VERTICAL |
-                       wx.ALL, border=5, pos=(1, 2))
-        self.sizer.Add(self.bbrowse, flag=wx.ALIGN_LEFT |
-                       wx.ALL, border=5, pos=(1, 3))
-        self.sizer.AddGrowableCol(3)
+        # layout
+        self.sizer.Add(self.label_wkt,
+                       flag=wx.ALIGN_LEFT | wx.ALL,
+                       border=5, pos=(1, 1))
+        self.sizer.Add(self.text_wkt,
+                       flag=wx.ALIGN_LEFT | wx.ALL | wx.EXPAND,
+                       border=5, pos=(2, 1), span=(1, 2))
+        self.sizer.AddGrowableRow(2)
+        self.sizer.AddGrowableCol(2)
 
-        self.bbrowse.Bind(wx.EVT_BUTTON, self.OnBrowse)
-        self.tfile.Bind(wx.EVT_TEXT, self.OnText)
+        self.text_wkt.Bind(wx.EVT_TEXT, self.OnText)
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
 
     def OnEnterPage(self, event):
-        if len(self.wktfile) == 0:
+        if len(self.wktstring) == 0:
             # disable 'next' button by default
             wx.FindWindowById(wx.ID_FORWARD).Enable(False)
         else:
@@ -1486,48 +1479,28 @@ class WKTPage(TitledPage):
         event.Skip()
 
     def OnPageChanging(self, event):
-        if event.GetDirection() and not os.path.isfile(self.wktfile):
+        if event.GetDirection() and not self.wktstring.strip():
             event.Veto()
         self.GetNext().SetPrev(self)
 
-        event.Skip()
-
     def OnText(self, event):
-        """File changed"""
-        self.wktfile = event.GetString()
+        """Change WKT string"""
+        # TODO: check WKT syntax
+        self.wktstring = event.GetString()
         nextButton = wx.FindWindowById(wx.ID_FORWARD)
-        if len(self.wktfile) > 0 and os.path.isfile(self.wktfile):
-            if not nextButton.IsEnabled():
-                nextButton.Enable(True)
-        else:
+        if len(self.wktstring) == 0:
             if nextButton.IsEnabled():
                 nextButton.Enable(False)
-
-        event.Skip()
-
-    def OnBrowse(self, event):
-        """Choose file"""
-        dlg = wx.FileDialog(
-            parent=self,
-            message=_("Select Well Known Text (WKT) .prj file"),
-            defaultDir=os.getcwd(),
-            wildcard="PRJ files (*.prj)|*.prj|Files (*.*)|*.*",
-            style=wx.FD_OPEN)
-
-        if dlg.ShowModal() == wx.ID_OK:
-            path = dlg.GetPath()
-            self.tfile.SetValue(path)
-        dlg.Destroy()
-
-        event.Skip()
-
+        else:
+            if not nextButton.IsEnabled():
+                nextButton.Enable()
 
 class EPSGPage(TitledPage):
     """Wizard page for selecting EPSG code for
     setting coordinate system parameters"""
 
     def __init__(self, wizard, parent):
-        TitledPage.__init__(self, wizard, _("Choose EPSG Code"))
+        TitledPage.__init__(self, wizard, _("Select CRS from a list"))
         
         self.sizer = wx.BoxSizer(wx.VERTICAL)  
         searchBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -1973,7 +1946,7 @@ class CustomPage(TitledPage):
     def __init__(self, wizard, parent):
         TitledPage.__init__(
             self, wizard,
-            _("Choose method of specifying georeferencing parameters"))
+            _("Specify CRS using PROJ.4 string"))
         global coordsys
         
         self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
@@ -2019,7 +1992,7 @@ class CustomPage(TitledPage):
                 return
 
             # check for datum tranforms
-            # FIXME: -t flag is a hack-around for trac bug #1849
+            # FIXME: -t flag is a hack-around for trac bug #1849          
             ret, out, err = RunCommand('g.proj',
                                        read=True, getErrorMsg=True,
                                        proj4=self.customstring,
@@ -2131,7 +2104,7 @@ class SummaryPage(TitledPage):
         self.panelProj4string.SetSizer(proj4stringSizer)
 
         self.panelProj4string.SetupScrolling()
-        self.panelProj.SetupScrolling(scroll_y=False)
+        self.panelProj.SetupScrolling()
         self.panelTitle.SetupScrolling(scroll_y=False)
 
         self.sizer.Add(self.MakeLabel(_("GRASS Database:")),
@@ -2170,7 +2143,6 @@ class SummaryPage(TitledPage):
                        flag=wx.ALIGN_LEFT | wx.ALL | wx.EXPAND,
                        border=0, pos=(5, 1))
         self.sizer.AddGrowableCol(1)
-        self.sizer.AddGrowableRow(3, 1)
         self.sizer.AddGrowableRow(4, 1)
         self.sizer.AddGrowableRow(5, 5)
 
@@ -2226,7 +2198,8 @@ class SummaryPage(TitledPage):
                     georef=self.parent.filepage.georeffile, **extra_opts)
             elif coordsys == 'wkt':
                 ret, projlabel, err = RunCommand(
-                    'g.proj', flags='jft', wkt=self.parent.wktpage.wktfile, **extra_opts)
+                    'g.proj', flags='jft', wkt="-", 
+                    stdin=self.parent.wktpage.wktstring, **extra_opts)
 
             finishButton = wx.FindWindowById(wx.ID_FORWARD)
             if ret == 0:
@@ -2259,7 +2232,7 @@ class SummaryPage(TitledPage):
             label = 'matches file %s' % self.parent.filepage.georeffile
 
         elif coordsys == 'wkt':
-            label = 'matches file %s' % self.parent.wktpage.wktfile
+            label = 'matches WKT string %s' % self.parent.wktpage.wktstring
 
         elif coordsys == 'proj':
             label = ('%s, %s %s' % (projdesc, datumdesc, ellipsedesc))
@@ -2659,13 +2632,12 @@ class LocationWizard(wx.Object):
                                       filename=self.filepage.georeffile,
                                       desc=self.startpage.locTitle)
             elif coordsys == "wkt":
-                if not self.wktpage.wktfile or \
-                        not os.path.isfile(self.wktpage.wktfile):
-                    return _("File <%s> not found." % self.wktpage.wktfile)
+                if not self.wktpage.wktstring:
+                    return _('WKT string missing.')
 
                 grass.create_location(dbase=self.startpage.grassdatabase,
                                       location=self.startpage.location,
-                                      wkt=self.wktpage.wktfile,
+                                      wkt=self.wktpage.wktstring,
                                       desc=self.startpage.locTitle)
 
         except grass.ScriptError as e: