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

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

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

revision 13 by bh, Fri Aug 31 15:33:42 2001 UTC revision 24 by bh, Wed Sep 5 13:35:46 2001 UTC
# Line 39  bitmapext = ".xpm" Line 39  bitmapext = ".xpm"
39    
40  class MainWindow(wxFrame):  class MainWindow(wxFrame):
41    
42      def __init__(self, parent, ID):      def __init__(self, parent, ID, interactor):
43          wxFrame.__init__(self, parent, ID, 'Thuban',          wxFrame.__init__(self, parent, ID, 'Thuban',
44                           wxDefaultPosition, wxSize(400, 300))                           wxDefaultPosition, wxSize(400, 300))
45    
# Line 101  class MainWindow(wxFrame): Line 101  class MainWindow(wxFrame):
101          toolbar.Realize()          toolbar.Realize()
102    
103          # Create the map canvas          # Create the map canvas
104          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1, interactor)
105          self.canvas = canvas          self.canvas = canvas
106    
107          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
# Line 181  class MainWindow(wxFrame): Line 181  class MainWindow(wxFrame):
181              if command.IsCheckCommand():              if command.IsCheckCommand():
182                  event.Check(command.Checked(self))                  event.Check(command.Checked(self))
183    
184        def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
185            """Run a modla message box with the given text, title and flags
186            and return the result"""
187            dlg = wxMessageDialog(self, text, title, flags)
188            result = dlg.ShowModal()
189            dlg.Destroy()
190            return result
191    
192      def NewSession(self):      def NewSession(self):
193          session = Session("")          session = Session("")
194          session.AddMap(Map(""))          session.AddMap(Map(""))
# Line 213  class MainWindow(wxFrame): Line 221  class MainWindow(wxFrame):
221              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
222              if event.CanVeto():              if event.CanVeto():
223                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
224              dlg = wxMessageDialog(self,              result = self.RunMessageBox("Exit",
225                                    ("The session has been modified."                                          ("The session has been modified."
226                                     " Do you want to save it?"),                                           " Do you want to save it?"),
227                                    "Exit", flags)                                          flags)
             result = dlg.ShowModal()  
             dlg.Destroy()  
228              if result == wxID_YES:              if result == wxID_YES:
229                  self.SaveSession()                  self.SaveSession()
230              elif result == wxID_CANCEL:              elif result == wxID_CANCEL:
# Line 233  class MainWindow(wxFrame): Line 239  class MainWindow(wxFrame):
239          self.canvas.SetMap(map)          self.canvas.SetMap(map)
240    
241      def About(self):      def About(self):
242          dlg = wxMessageDialog(self,          self.RunMessageBox("About",
243                                ("Thuban is a program for\n"                             ("Thuban is a program for\n"
244                                 "exploring geographic data.\n"                              "exploring geographic data.\n"
245                                 "Copyright (C) 2001 Intevation GmbH.\n"                              "Copyright (C) 2001 Intevation GmbH.\n"
246                                 "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GPL"),
247                                "About", wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
         dlg.ShowModal()  
         dlg.Destroy()  
248    
249      def AddLayer(self):      def AddLayer(self):
250          dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*",          dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*",
# Line 249  class MainWindow(wxFrame): Line 253  class MainWindow(wxFrame):
253              filename = dlg.GetPath()              filename = dlg.GetPath()
254              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
255              layer = Layer(title, filename)              layer = Layer(title, filename)
256              self.canvas.Map().AddLayer(layer)              map = self.canvas.Map()
257                has_layers = map.HasLayers()
258                try:
259                    map.AddLayer(layer)
260                except IOError:
261                    # the layer couldn't be opened
262                    self.RunMessageBox("Add Layer",
263                                       "Can't open the file '%s'." % filename)
264                else:
265                    if not has_layers:
266                        # if we're adding a layer to an empty map, for the
267                        # new map to the window
268                        self.canvas.FitMapToWindow()
269          dlg.Destroy()          dlg.Destroy()
270    
271      def RemoveLayer(self):      def RemoveLayer(self):
272          layer = self.current_layer()          layer = self.current_layer()
273          if layer is not None:          if layer is not None:
274              self.canvas.Map().RemoveLayer(layer)              self.canvas.Map().RemoveLayer(layer)
         else:  
             dlg = wxMessageDialog(self, "No layer is selected.\n",  
                                   "Remove layer", wxOK | wxICON_INFORMATION)  
             dlg.ShowModal()  
             dlg.Destroy()  
275    
276      def RaiseLayer(self):      def RaiseLayer(self):
277          layer = self.current_layer()          layer = self.current_layer()

Legend:
Removed from v.13  
changed lines
  Added in v.24

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26