/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/projdialog.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/projdialog.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 717 by jonathan, Wed Apr 23 08:59:57 2003 UTC revision 730 by jonathan, Thu Apr 24 16:07:41 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/env python  #!/usr/bin/env python
2  # generated by wxGlade 0.2.1 on Thu Apr 17 11:51:39 2003  # generated by wxGlade 0.2.1 on Thu Apr 17 11:51:39 2003
3    
4    import os, sys
5  from wxPython.wx import *  from wxPython.wx import *
6    
7  from Thuban import _  from Thuban import _
8    
9  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection, ProjFile
10    
11  from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles  from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles, \
12                                      ReadProjFile, WriteProjFile
13  from Thuban.UI.dialogs import NonModalDialog  from Thuban.UI.dialogs import NonModalDialog
14    
15    
16  ID_PROJ_ADVANCED  = 4001  ID_PROJ_ADVANCED  = 4001
17  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
18  ID_PROJ_SAVEAS    = 4003  ID_PROJ_SAVEAS    = 4003
# Line 19  ID_PROJ_REVERT    = 4006 Line 22  ID_PROJ_REVERT    = 4006
22  ID_PROJ_OK        = 4007  ID_PROJ_OK        = 4007
23  ID_PROJ_CLOSE     = 4008  ID_PROJ_CLOSE     = 4008
24  ID_PROJ_AVAIL     = 4009  ID_PROJ_AVAIL     = 4009
25    ID_PROJ_SAVE      = 4010
26    ID_PROJ_IMPORT    = 4011
27    ID_PROJ_EXPORT    = 4012
28    ID_PROJ_REMOVE    = 4013
29    ID_PROJ_PROJNAME  = 4014
30    
31    CLIENT_PROJ = 0
32    CLIENT_PROJFILE = 1
33    
34  class ProjFrame(NonModalDialog):  class ProjFrame(NonModalDialog):
35    
   
36      def __init__(self, parent, name, receiver, *args, **kwds):      def __init__(self, parent, name, receiver, *args, **kwds):
37          #          """Initialize the projection dialog.
         # Changes to the wxGlade generated code:  
         #   o   call NonModalDialog.__init__(self, parent, name, "")  
         #   o   remove default choices in combo box  
         #  
38    
39          self.editing = False          receiver -- An object that implements the following methods:
40                            SetProjection(projection)
41                            GetProjection()
42            """
43            
44          self.receiver = receiver          self.receiver = receiver
45          self.originalProjection = -1          self.originalProjection = -1
46          self.curProjPanel = None          self.curProjPanel = None
47    
48          self.projPanels = []          self.projPanels = []
49          self.projPanels.append(          self.projPanels.append(
50              ("tmerc", _("Transverse Mercartor"), TMPanel))              ("tmerc", _("Transverse Mercator"), TMPanel))
51          self.projPanels.append(          self.projPanels.append(
52              ("utm", _("Universal Transverse Mercartor"), UTMPanel))              ("utm", _("Universal Transverse Mercator"), UTMPanel))
53          self.projPanels.append(          self.projPanels.append(
54              ("lcc", _("Lambert Conic Conformal"), LCCPanel))              ("lcc", _("Lambert Conic Conformal"), LCCPanel))
55          self.projPanels.append(          self.projPanels.append(
56              ("latlong", _("Geographic"), GeoPanel))              ("latlong", _("Geographic"), GeoPanel))
57    
         # begin wxGlade: ProjFrame.__init__  
         #kwds["style"] = wxDEFAULT_FRAME_STYLE  
58          NonModalDialog.__init__(self, parent, name, "")          NonModalDialog.__init__(self, parent, name, "")
59            # originally generate by wxGlade
60          self.panel_1 = wxPanel(self, -1)          self.panel_1 = wxPanel(self, -1)
61            self.panel_edit = wxPanel(self, -1)
62            self.panel_buttons = wxPanel(self, -1)
63          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))
64          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_SINGLE|wxLB_SORT)          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED |wxLB_SORT)
65          self.button_advanced = wxButton(self.panel_1, ID_PROJ_ADVANCED, _("Advanced >>"))          self.projfilepath = wxStaticText(self.panel_1, -1, "")
66          self.label_2 = wxStaticText(self.panel_1, -1, _("Name:"))          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))
67          self.projname = wxTextCtrl(self.panel_1, -1, "")          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")
68          self.label_3 = wxStaticText(self.panel_1, -1, _("Projection:"))          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))
69          self.projchoice = wxChoice(self.panel_1, ID_PROJ_PROJCHOICE)          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)
70          self.button_new = wxButton(self.panel_1, ID_PROJ_NEW, _("New"))          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, _("Import..."))
71          self.button_saveas = wxButton(self.panel_1, ID_PROJ_SAVEAS, _("Save"))          self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT, _("Export..."))
72          self.button_try = wxButton(self.panel_1, ID_PROJ_TRY, _("Try"))          self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove"))
73          self.button_revert = wxButton(self.panel_1, ID_PROJ_REVERT, _("Revert"))          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))
74          self.button_ok = wxButton(self.panel_1, ID_PROJ_OK, _("OK"))          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))
75          self.button_close = wxButton(self.panel_1, ID_PROJ_CLOSE, _("Close"))          self.button_add = wxButton(self.panel_edit, ID_PROJ_SAVEAS,
76                                          _("Add to List"))
77            self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))
78            self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))
79            self.button_ok = wxButton(self.panel_buttons, ID_PROJ_OK, _("OK"))
80            self.button_close = wxButton(self.panel_buttons, ID_PROJ_CLOSE, _("Close"))
81    
82          self.__set_properties()          self.__set_properties()
83          self.__do_layout()          self.__do_layout()
84          # end wxGlade          # wxGlade
   
         self.sizer_edit.GetStaticBox().Show(False)  
         self.sizer_mainctrls.Show(self.sizer_edit, False)  
         self.topBox.Layout()  
85    
86            self.__DoOnProjAvail()
87            
88          EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry)          EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry)
89          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
90          EVT_BUTTON(self, ID_PROJ_OK, self._OnOK)          EVT_BUTTON(self, ID_PROJ_OK, self._OnOK)
91          EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose)          EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose)
         EVT_BUTTON(self, ID_PROJ_ADVANCED, self._OnAdvanced)  
92          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
93          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
94            EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
95            EVT_BUTTON(self, ID_PROJ_EXPORT, self._OnExport)
96            EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)
97    
98          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
99          EVT_BUTTON(self, ID_PROJ_SAVEAS, self._OnSave)          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
100            EVT_BUTTON(self, ID_PROJ_SAVEAS, self._OnSaveAs)
101    
102            EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
103    
104      def GetReceiver(self):      def GetReceiver(self):
105          return self.receiver          return self.receiver
# Line 100  class ProjFrame(NonModalDialog): Line 118  class ProjFrame(NonModalDialog):
118      def _OnClose(self, event):      def _OnClose(self, event):
119          self.Close()          self.Close()
120    
121      def _OnAdvanced(self, event):      def _OnNew(self, event):
122          self.sizer_edit.GetStaticBox().Show(True)          self.__DoOnNew()
         self.sizer_mainctrls.Show(self.sizer_edit, True)  
         self.topBox.Fit(self)  
         self.topBox.SetSizeHints(self)  
         self.topBox.Layout()  
123    
124          self.editing = True      def _OnSave(self, event):
125    
126          self.__DoOnProjAvail()          sel = self.availprojs.GetSelections()
127            assert len(sel) == 1,  "button shouldn't be enabled"
128    
129          self.button_advanced.Enable(False)          proj, projfile = self.availprojs.GetClientData(sel[0])
130    
131      def _OnNew(self, event):          assert proj is not None and projfile is not None
         print "_OnNew"  
         self.availprojs.SetSelection(-1)  
         self.projname.Clear()  
         self.curProjPanel.Clear()  
132    
133      def _OnSave(self, event):          newproj = self.__GetProjection()
134          print "_OnSave"  
135            if newproj is not None:
136                projfile.Remove(proj)
137                projfile.Add(newproj)
138                try:
139                    WriteProjFile(projfile)
140                except IOError, (errno, errstr):
141                    wxMessageDialog(self,
142                        _("The following error occured:\n") +
143                        projfile.GetFileName() + "\n" + errstr,
144                        _("Error"), wxOK | wxICON_ERROR).ShowModal()
145                self.__FillAvailList()
146    
147        def _OnSaveAs(self, event):
148    
149            proj = self.__GetProjection()
150            if proj is not None:
151                self.__usrProjFile.Add(proj)
152                try:
153                    WriteProjFile(self.__usrProjFile)
154                except IOError, (errno, errstr):
155                    wxMessageDialog(self,
156                        _("The following error occured:\n") +
157                        self.__usrProjFile.GetFileName() + "\n" + errstr,
158                        _("Error"), wxOK | wxICON_ERROR).ShowModal()
159                self.__FillAvailList()
160    
161            return
162    
163            """Save the projection somewhere.
164    
165            There are three important cases to consider.
166                1. the file already exists and the user wants to overwrite it.
167                2. the file already exists and the user wants to append the
168                   current projection to the end of the file
169                3. the file doesn't exist and the user wants to create it
170    
171            The list of available projections is then updated.
172            """
173    
174            proj = Projection(self.curProjPanel.GetParameters())
175            if self.projname.GetValue() != "":
176                proj.SetName(self.projname.GetValue())
177    
178            dlg = wxFileDialog(self, _("Save As"), style = wxSAVE)
179            if dlg.ShowModal() == wxID_OK:
180                path = dlg.GetPath()
181    
182                if os.access(path, os.F_OK):
183                    # file already exists.
184                    if os.access(path, os.W_OK | os.R_OK):
185                    
186                        # is it a .proj file?
187                        try:
188                            projFile = ReadProjFile(path)
189                        except:
190                            # obviously not.
191                            dlg = wxMessageDialog(self,
192                                path + _(" already exists. Overwrite?"),
193                                _(""),
194                                wxYES | wxNO)
195    
196                            if dlg.ShowModal() == wxID_YES:
197                                projFile = ProjFile(path)
198                            else:
199                                return # returning early
200                        else:
201                            # ask the user to overwrite or append
202                            dlg = wxMessageDialog(self,
203                                _("The selected projection file already exists.\n"+
204                                  "The current projection can be added to the " +
205                                  "file, or it can completely replace the " +
206                                  "selected file.\n\nShould the current " +
207                                  "projection be added to the file?"),
208                                _("Question"),
209                                wxYES | wxNO | wxICON_QUESTION)
210    
211                            if dlg.ShowModal() == wxID_NO:
212                                projFile = ProjFile(path)
213                    else:
214                        # can't access the file
215                        dlg = wxMessageDialog(self,
216                            _("Couldn't access ") + path,
217                            _(""),
218                            wxOK | wxICON | wxICON_EXCLAMATION)
219                        return
220    
221                else:
222                    # file doesn't exist. make a new one.
223                    projFile = ProjFile(path)
224                    
225                #
226                # if we get this far we have a valid projFile and
227                # can just write the file
228                #
229                projFile.Add(proj)
230                try:
231                    WriteProjFile(projFile)
232                    self.__FillAvailList()
233                except IOError, (errno, errstr):
234                    wxMessageDialog(self,
235                        _("The following error occured:\n") +
236                        dlg.GetPath() + "\n" + errstr,
237                        _("Error"), wxOK | wxICON_ERROR).ShowModal()
238            dlg.Destroy()
239    
240      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
241          self.__DoOnProjAvail()          self.__DoOnProjAvail()
242    
243        def _OnImport(self, event):
244    
245            dlg = wxFileDialog(self, _("Import"), style = wxOPEN)
246    
247            if dlg.ShowModal() == wxID_OK:
248                path = dlg.GetPath()
249    
250                try:
251                    projFile = ReadProjFile(path)
252                    for proj in projFile.GetProjections():
253                        self.__usrProjFile.Add(proj)
254                    WriteProjFile(self.__usrProjFile)
255                except IOError, (errno, errstr):
256                    wxMessageDialog(self,
257                        _("The following error occured:\n") +
258                        dlg.GetPath() + "\n" + errstr,
259                        _("Error"), wxOK | wxICON_ERROR).ShowModal()
260    
261                self.__FillAvailList()
262    
263            dlg.Destroy()
264    
265        def _OnExport(self, event):
266            proj = self.__GetProjection()
267    
268            if proj is None: return
269    
270            dlg = wxFileDialog(self, _("Export"),
271                               style = wxSAVE|wxOVERWRITE_PROMPT)
272    
273            if dlg.ShowModal() == wxID_OK:
274                path = dlg.GetPath()
275    
276                projFile = ProjFile(path)
277                projFile.Add(proj)
278                try:
279                    WriteProjFile(projFile)
280                except IOError, (errno, errstr):
281                    wxMessageDialog(self,
282                        _("The following error occured:\n") +
283                        dlg.GetPath() + "\n" + errstr,
284                        _("Error"), wxOK | wxICON_ERROR).ShowModal()
285    
286            dlg.Destroy()
287    
288        def _OnRemove(self, event):
289    
290            sel = self.availprojs.GetSelections()
291            assert len(sel) != 0, "button should be disabled!"
292    
293            #
294            # remove the items backwards so the indices don't change
295            #
296            sel = list(sel)
297            sel.sort()
298            sel.reverse()
299    
300            newselection = -1
301            if len(sel) == 1:
302                newselection = sel[0] - 1
303                if newselection < 0:
304                    newselection = 0
305    
306            for i in sel:
307                proj, projfile = self.availprojs.GetClientData(i)
308    
309                #
310                # this could be the case if they selected <None> or
311                # the currently used projection
312                #
313                if proj is not None and projfile is not None:
314                    projfile.Remove(proj)
315    
316            try:
317                WriteProjFile(projfile)
318            except IOError, (errno, errstr):
319                wxMessageDialog(self,
320                    _("The following error occured:\n") +
321                    projfile.GetFileName() + "\n" + errstr,
322                    _("Error"), wxOK | wxICON_ERROR).ShowModal()
323    
324    
325            self.__FillAvailList()
326    
327            #
328            # this *could* produce incorrect results if the .proj files
329            # change between the last list update and this selection
330            # because the list has been repopulated.
331            #
332            if newselection != -1 and self.availprojs.GetCount() > 0:
333                self.availprojs.SetSelection(newselection)
334    
335        def _OnProjName(self, event):
336            self.__VerifyButtons()
337    
338        def __VerifyButtons(self):
339            sel = self.availprojs.GetSelections()
340    
341            self.button_import.Enable(True)
342            self.button_export.Enable(True)
343            self.button_save.Enable(True)
344            self.button_remove.Enable(True)
345    
346            self.panel_edit.Enable(True)
347    
348            if len(sel) == 0:
349                self.button_import.Enable(True)
350                self.button_export.Enable(False)
351                self.button_remove.Enable(False)
352    
353            elif len(sel) == 1:
354    
355                proj, projFile = self.availprojs.GetClientData(sel[0])
356    
357                self.button_save.Enable(len(self.projname.GetValue()) > 0)
358                self.button_add.Enable(len(self.projname.GetValue()) > 0)
359    
360                if proj is None:
361                    self.button_export.Enable(False)
362                    self.button_remove.Enable(False)
363    
364                if projFile is None:
365                    self.button_save.Enable(False)
366    
367            else:
368                self.panel_edit.Enable(False)
369    
370        def __DoOnNew(self):
371            sel = self.availprojs.GetSelections()
372            if len(sel) != 0:
373                self.availprojs.SetSelection(sel, False)
374            self.projname.Clear()
375            self.curProjPanel.Clear()
376    
377      def __DoOnProjAvail(self):      def __DoOnProjAvail(self):
         print "_OnProjAvail"  
378    
379          if not self.editing: return          sel = self.availprojs.GetSelections()
380            if len(sel) == 1:
381    
382          sel = self.availprojs.GetSelection()              proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ]
383          if sel == -1: return              projfile = self.availprojs.GetClientData(sel[0])[CLIENT_PROJFILE]
384    
385          proj = self.availprojs.GetClientData(sel)              if proj is None:
386          assert proj != None                  # user selected <None>
387                    self.projname.Clear()
388          self.projname.SetValue(proj.GetName())              else:
389                
390          myProjType = proj.GetParameter("proj")                  if projfile is not None:
391          i = 0                      self.projfilepath.SetLabel(projfile.GetFileName())
392          for projType, name, clazz in self.projPanels:                  else:
393              if myProjType == projType:                      # only None if the currently used projection is selected
394                  self.projchoice.SetSelection(i)                      self.projfilepath.SetLabel("")
395                  self.__DoOnProjChoice()  
396                  self.curProjPanel.SetProjection(proj)                  self.projname.SetValue(proj.GetName())
397              i += 1  
398                    myProjType = proj.GetParameter("proj")
399                    i = 0
400                    for projType, name, clazz in self.projPanels:
401                        if myProjType == projType:
402                            self.projchoice.SetSelection(i)
403                            self.__DoOnProjChoice()
404                            self.curProjPanel.SetProjection(proj)
405                        i += 1
406    
407            self.__VerifyButtons()
408    
409      def _OnProjChoice(self, event):      def _OnProjChoice(self, event):
410          self.__DoOnProjChoice()          self.__DoOnProjChoice()
411    
412      def __DoOnProjChoice(self):      def __DoOnProjChoice(self):
         print "_OnProjChoice()"  
413          choice = self.projchoice          choice = self.projchoice
414    
415          sel = choice.GetSelection()          sel = choice.GetSelection()
416          if sel == -1: return          if sel != -1:
   
         clazz, obj = choice.GetClientData(choice.GetSelection())  
417    
418          if obj is None:              clazz, obj = choice.GetClientData(sel)
             obj = clazz(self)  
             choice.SetClientData(sel, [clazz, obj])  
419    
420          if self.curProjPanel is not None:              if obj is None:
421              self.curProjPanel.Hide()                  obj = clazz(self.panel_edit, self.receiver)
422              self.sizer_projctrls.Remove(self.curProjPanel)                  choice.SetClientData(sel, [clazz, obj])
   
         self.curProjPanel = obj  
         self.curProjPanel.Show()  
423    
424          print "++", self.topBox.GetSize(), self.GetSize()              if self.curProjPanel is not None:
425          print "!!", self.sizer_projctrls.GetSize(), \                  self.curProjPanel.Hide()
426                      self.sizer_edit.GetSize(), \                  self.sizer_projctrls.Remove(self.curProjPanel)
                     self.sizer_mainctrls.GetSize(), \  
                     self.sizer_panel.GetSize()  
         self.sizer_projctrls.Add(self.curProjPanel, 1, wxALL|wxEXPAND, 3)  
         #print "$$", self.sizer_projctrls.GetSize()  
 #       self.topBox.Fit(self)  
 #       self.topBox.SetSizeHints(self)  
 #       self.topBox.Layout()  
   
         self.sizer_panel.SetSizeHints(self.panel_1)  
         w, h = self.sizer_panel.GetSize()  
         self.topBox.SetDimension(0, 0, w, h)  
427    
428          #self.sizer_panel.Fit(self.panel_1)              self.curProjPanel = obj
429          self.topBox.Fit(self)              self.curProjPanel.Show()
         #self.SetAutoLayout(1)  
         self.topBox.SetSizeHints(self)  
         self.SetSize(self.topBox.GetSize())  
         print "!!", self.sizer_projctrls.GetSize(), \  
                     self.sizer_edit.GetSize(), \  
                     self.sizer_mainctrls.GetSize(), \  
                     self.sizer_panel.GetSize()  
         print "--", self.topBox.GetSize(), self.GetSize()  
430    
431                                self.sizer_projctrls.Add(self.curProjPanel, 1,
432                    wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)
433                self.sizer_projctrls.Layout()
434                self.Layout()
435                self.topBox.SetSizeHints(self)
436    
437      def __SetProjection(self):      def __SetProjection(self):
438    
# Line 207  class ProjFrame(NonModalDialog): Line 443  class ProjFrame(NonModalDialog):
443          if self.originalProjection == -1:          if self.originalProjection == -1:
444              self.originalProjection = self.receiver.GetProjection()              self.originalProjection = self.receiver.GetProjection()
445    
446          sel = self.availprojs.GetSelection()          self.receiver.SetProjection(self.__GetProjection())
         proj = -1  
447    
448          if self.editing:      def __GetProjection(self):
449              if self.curProjPanel is not None:          """Return the packaged projection.
                 proj = Projection(self.curProjPanel.GetParameters())  
         elif sel != -1:  
             proj = self.availprojs.GetClientData(sel)  
   
         if proj != -1:  
             if proj is not None:  
                 print proj.GetAllParameters()  
             self.receiver.SetProjection(proj)  
450    
451            Could be None.
452            """
453    
454      def __set_properties(self):          proj = None
455          self.availprojs.Append("<None>", None)  
456            if self.curProjPanel is not None:
457                proj = Projection(self.curProjPanel.GetParameters())
458                proj.SetName(self.projname.GetValue())
459    
460            return proj
461    
462        def __FillAvailList(self):
463            self.availprojs.Clear()
464    
465            #
466            # the list can never be empty. there will always be
467            # at least this one item
468            #
469            self.availprojs.Append("<None>", (None, None))
470    
471            self.__sysProjFile = None
472            self.__usrProjFile = None
473    
474          projfiles = GetSystemProjFiles()          projfile = GetSystemProjFiles()
475          for projfile in projfiles:          if len(projfile) > 0:
476                projfile = projfile[0]
477              for proj in projfile.GetProjections():              for proj in projfile.GetProjections():
478                  self.availprojs.Append(proj.GetName(), proj)                  self.availprojs.Append(proj.GetName(), [proj, projfile])
479                self.__sysProjFile = projfile
480    
481          projfiles = GetUserProjFiles()          projfile = GetUserProjFiles()
482          for projfile in projfiles:          if len(projfile) > 0:
483                projfile = projfile[0]
484              for proj in projfile.GetProjections():              for proj in projfile.GetProjections():
485                  self.availprojs.Append(proj.GetName(), proj)                  self.availprojs.Append(proj.GetName(), [proj, projfile])
486                self.__usrProjFile = projfile
487    
488    #       projfiles = GetSystemProjFiles()
489    #       for projfile in projfiles:
490    #           for proj in projfile.GetProjections():
491    #               self.availprojs.Append(proj.GetName(), [proj, projfile])
492    #       self.__sysProjFiles = projfiles
493    
494    #       projfiles = GetUserProjFiles()
495    #       for projfile in projfiles:
496    #           for proj in projfile.GetProjections():
497    #               self.availprojs.Append(proj.GetName(), [proj, projfile])
498    #       self.__usrProjFiles = projfiles
499    
500          proj = self.receiver.GetProjection()          proj = self.receiver.GetProjection()
501          if proj is not None:          if proj is not None:
502              self.availprojs.Append("## " + proj.GetName() + " ##", proj)              self.availprojs.Append(proj.GetName() + _(" (current)"),
503                                       [proj, None])
504    
505          for proj, name, clazz in self.projPanels:          for proj, name, clazz in self.projPanels:
506              self.projchoice.Append(name, [clazz, None])              self.projchoice.Append(name, [clazz, None])
507    
508        def __set_properties(self):
509            self.__FillAvailList()
510    
511          # begin wxGlade: ProjFrame.__set_properties          # begin wxGlade: ProjFrame.__set_properties
512          self.SetTitle(_("Projections"))          self.SetTitle(_("Projections"))
513          self.availprojs.SetSelection(0)          self.availprojs.SetSelection(0)
514          self.projchoice.SetSelection(0)          self.projchoice.SetSelection(0)
515          # end wxGlade          # end wxGlade
516    
517            self.projname.SetMaxLength(32)
518    
519      def __do_layout(self):      def __do_layout(self):
520          # begin wxGlade: ProjFrame.__do_layout          # originally generated by wxGlade
521    
522          self.topBox = wxBoxSizer(wxVERTICAL)          self.topBox = wxBoxSizer(wxVERTICAL)
523          self.sizer_panel = wxBoxSizer(wxVERTICAL)          self.sizer_panel = wxBoxSizer(wxVERTICAL)
524          sizer_6 = wxBoxSizer(wxHORIZONTAL)          sizer_6 = wxBoxSizer(wxHORIZONTAL)
525          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)
526          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_1, -1, _("Edit")), wxHORIZONTAL)          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)
527          sizer_11 = wxBoxSizer(wxVERTICAL)          sizer_11 = wxBoxSizer(wxVERTICAL)
528          self.sizer_projctrls = wxBoxSizer(wxVERTICAL)          self.sizer_projctrls = wxBoxSizer(wxVERTICAL)
529          sizer_14 = wxBoxSizer(wxHORIZONTAL)          sizer_14 = wxBoxSizer(wxHORIZONTAL)
530          sizer_13 = wxBoxSizer(wxHORIZONTAL)          sizer_13 = wxBoxSizer(wxHORIZONTAL)
531          grid_sizer_1 = wxFlexGridSizer(2, 2, 0, 0)          sizer_15 = wxBoxSizer(wxVERTICAL)
532            sizer_15.Add(self.button_import, 0, wxALL, 4)
533            sizer_15.Add(self.button_export, 0, wxALL, 4)
534            sizer_15.Add(20, 20, 0, wxEXPAND, 0)
535            sizer_15.Add(self.button_remove, 0, wxALL|wxALIGN_BOTTOM, 4)
536    
537            # list controls
538            grid_sizer_1 = wxFlexGridSizer(3, 2, 0, 0)
539          grid_sizer_1.Add(self.label_5, 0, wxLEFT|wxRIGHT|wxTOP, 4)          grid_sizer_1.Add(self.label_5, 0, wxLEFT|wxRIGHT|wxTOP, 4)
540          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)
541          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND, 4)          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
542          grid_sizer_1.Add(self.button_advanced, 0, wxALL, 4)          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)
543            grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4)
544          grid_sizer_1.AddGrowableRow(1)          grid_sizer_1.AddGrowableRow(1)
545          grid_sizer_1.AddGrowableCol(0)          grid_sizer_1.AddGrowableCol(0)
546          self.sizer_mainctrls.Add(grid_sizer_1, 1, wxEXPAND, 0)  
547            # edit controls
548          sizer_13.Add(self.label_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_13.Add(self.label_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
549          sizer_13.Add(self.projname, 1, wxALL, 4)          sizer_13.Add(self.projname, 1, wxALL, 4)
550          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)
551          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
552          sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND, 4)          sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
553          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
554          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
555          sizer_11.Add(self.button_new, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_new, 0, wxALL|wxEXPAND, 4)
556          sizer_11.Add(self.button_saveas, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_save, 0, wxALL|wxEXPAND, 4)
557            sizer_11.Add(self.button_add, 0, wxALL|wxEXPAND, 4)
558          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)
559          self.sizer_mainctrls.Add(self.sizer_edit, 0, wxALL|wxEXPAND, 4)  
         self.sizer_panel.Add(self.sizer_mainctrls, 1, wxEXPAND, 0)  
560          sizer_6.Add(20, 20, 1, wxEXPAND, 0)          sizer_6.Add(20, 20, 1, wxEXPAND, 0)
561          sizer_6.Add(self.button_try, 0, wxALL, 4)          sizer_6.Add(self.button_try, 0, wxALL, 4)
562          sizer_6.Add(20, 20, 1, 0, 0)          sizer_6.Add(20, 20, 1, 0, 0)
# Line 288  class ProjFrame(NonModalDialog): Line 566  class ProjFrame(NonModalDialog):
566          sizer_6.Add(20, 20, 1, 0, 0)          sizer_6.Add(20, 20, 1, 0, 0)
567          sizer_6.Add(self.button_close, 0, wxALL, 4)          sizer_6.Add(self.button_close, 0, wxALL, 4)
568          sizer_6.Add(20, 20, 1, wxEXPAND, 0)          sizer_6.Add(20, 20, 1, wxEXPAND, 0)
569          self.sizer_panel.Add(sizer_6, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 0)  
570          self.panel_1.SetAutoLayout(1)          self.panel_1.SetAutoLayout(1)
571          self.panel_1.SetSizer(self.sizer_panel)          self.panel_1.SetSizer(grid_sizer_1)
572          self.sizer_panel.Fit(self.panel_1)          grid_sizer_1.Fit(self.panel_1)
573          self.sizer_panel.SetSizeHints(self.panel_1)          grid_sizer_1.SetSizeHints(self.panel_1)
574          self.topBox.Add(self.panel_1, 1, wxEXPAND, 0)  
575            self.panel_edit.SetAutoLayout(1)
576            self.panel_edit.SetSizer(self.sizer_edit)
577            self.sizer_edit.Fit(self.panel_edit)
578            self.sizer_edit.SetSizeHints(self.panel_edit)
579    
580            self.panel_buttons.SetAutoLayout(1)
581            self.panel_buttons.SetSizer(sizer_6)
582            sizer_6.Fit(self.panel_buttons)
583            sizer_6.SetSizeHints(self.panel_buttons)
584    
585            self.sizer_mainctrls.Add(self.panel_1, 0,
586                wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
587            self.sizer_mainctrls.Add(self.panel_edit, 1,
588                wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
589    
590            self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)
591            self.topBox.Add(self.panel_buttons, 0, wxEXPAND, 0)
592    
593          self.SetAutoLayout(1)          self.SetAutoLayout(1)
594          self.SetSizer(self.topBox)          self.SetSizer(self.topBox)
595          self.topBox.Fit(self)          self.topBox.Fit(self)
596          self.topBox.SetSizeHints(self)          self.topBox.SetSizeHints(self)
597          self.Layout()          self.Layout()
         # end wxGlade  
598    
599  # end of class ProjFrame  # end of class ProjFrame
600    
# Line 332  class ProjPanel(wxPanel): Line 627  class ProjPanel(wxPanel):
627                            
628          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
629          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)
630          sizer.Add(self.__ellps, 1, wxALL|wxEXPAND, 4)          sizer.Add(self.__ellps, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
631          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)
632    
633          self.SetAutoLayout(1)          self.SetAutoLayout(1)
# Line 357  class ProjPanel(wxPanel): Line 652  class ProjPanel(wxPanel):
652          self.__ellps.SetSelection(0)          self.__ellps.SetSelection(0)
653    
654      def GetParameters(self):      def GetParameters(self):
         print "asdfsdf"  
655          return ["ellps=" + self.__ellps.GetClientData(          return ["ellps=" + self.__ellps.GetClientData(
656                                          self.__ellps.GetSelection())]                                          self.__ellps.GetSelection())]
657    
# Line 369  ID_TMPANEL_FALSE_NORTH = 4004 Line 663  ID_TMPANEL_FALSE_NORTH = 4004
663  ID_TMPANEL_SCALE = 4005  ID_TMPANEL_SCALE = 4005
664    
665  class UnknownProjPanel(ProjPanel):  class UnknownProjPanel(ProjPanel):
666      def __init__(self, parent):      def __init__(self, parent, receiver):
667          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
668    
669          self._DoLayout()          self._DoLayout()
# Line 394  class UnknownProjPanel(ProjPanel): Line 688  class UnknownProjPanel(ProjPanel):
688          return None          return None
689    
690  class TMPanel(ProjPanel):  class TMPanel(ProjPanel):
691      """Projection panel for Transverse Mercartor."""      """Projection panel for Transverse Mercator."""
692    
693      def __init__(self, parent):      def __init__(self, parent, receiver):
694          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
695    
696          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)
# Line 424  class TMPanel(ProjPanel): Line 718  class TMPanel(ProjPanel):
718          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
719    
720      def GetProjName(self):      def GetProjName(self):
721          return _("Transverse Mercartor")          return _("Transverse Mercator")
722    
723      def SetProjection(self, proj):      def SetProjection(self, proj):
724          ProjPanel.SetProjection(self, proj)          ProjPanel.SetProjection(self, proj)
# Line 438  class TMPanel(ProjPanel): Line 732  class TMPanel(ProjPanel):
732          ProjPanel.SetProjection(self, proj)          ProjPanel.SetProjection(self, proj)
733    
734      def GetParameters(self):      def GetParameters(self):
         print "** asdfsdf"  
735          params = ["proj=tmerc",          params = ["proj=tmerc",
736                    "lat_0=" + self.__latitude.GetValue(),                    "lat_0=" + self.__latitude.GetValue(),
737                    "lon_0=" + self.__longitude.GetValue(),                    "lon_0=" + self.__longitude.GetValue(),
# Line 462  ID_UTMPANEL_SOUTH = 4002 Line 755  ID_UTMPANEL_SOUTH = 4002
755  ID_UTMPANEL_PROP = 4003  ID_UTMPANEL_PROP = 4003
756    
757  class UTMPanel(ProjPanel):  class UTMPanel(ProjPanel):
758      """Projection Panel for Universal Transverse Mercartor."""      """Projection Panel for Universal Transverse Mercator."""
759    
760      def __init__(self, parent):      def __init__(self, parent, receiver):
761          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
762    
763          self.parent = parent          self.receiver = receiver
764    
765          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)
766          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,
# Line 491  class UTMPanel(ProjPanel): Line 784  class UTMPanel(ProjPanel):
784          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
785    
786      def GetProjName(self):      def GetProjName(self):
787          return _("Universal Transverse Mercartor")          return _("Universal Transverse Mercator")
788    
789      def SetProjection(self, proj):      def SetProjection(self, proj):
790          self.__zone.SetValue(int(proj.GetParameter("zone")))          self.__zone.SetValue(int(proj.GetParameter("zone")))
# Line 499  class UTMPanel(ProjPanel): Line 792  class UTMPanel(ProjPanel):
792          ProjPanel.SetProjection(self, proj)          ProjPanel.SetProjection(self, proj)
793    
794      def GetParameters(self):      def GetParameters(self):
         print "** asdfsdf"  
795          params = ["proj=utm", "zone=" + str(self.__zone.GetValue())]          params = ["proj=utm", "zone=" + str(self.__zone.GetValue())]
796          if self.__south.IsChecked():          if self.__south.IsChecked():
797              params.append("south")              params.append("south")
# Line 514  class UTMPanel(ProjPanel): Line 806  class UTMPanel(ProjPanel):
806    
807      def _OnPropose(self, event):      def _OnPropose(self, event):
808          UTMProposeZoneDialog          UTMProposeZoneDialog
809          dlg = UTMProposeZoneDialog(self, self.parent.GetReceiver().BoundingBox())          dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())
810          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
811              self.__zone.SetValue(dlg.GetProposedZone())              self.__zone.SetValue(dlg.GetProposedZone())
812    
813  class LCCPanel(ProjPanel):  class LCCPanel(ProjPanel):
814      """Projection Panel for Lambert Conic Conformal."""      """Projection Panel for Lambert Conic Conformal."""
815    
816      def __init__(self, parent):      def __init__(self, parent, receiver):
817          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
818                    
819          self.__fspLatitude = wxTextCtrl(self, -1)          self.__fspLatitude = wxTextCtrl(self, -1)
# Line 591  class LCCPanel(ProjPanel): Line 883  class LCCPanel(ProjPanel):
883  class GeoPanel(ProjPanel):  class GeoPanel(ProjPanel):
884      """Projection Panel for a Geographic Projection."""      """Projection Panel for a Geographic Projection."""
885    
886      def __init__(self, parent):      def __init__(self, parent, receiver):
887          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
888          ProjPanel._DoLayout(self, None)          ProjPanel._DoLayout(self, None)
889    

Legend:
Removed from v.717  
changed lines
  Added in v.730

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26