/[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 6 by bh, Tue Aug 28 15:41:52 2001 UTC revision 33 by bh, Thu Sep 6 15:31:31 2001 UTC
# Line 30  import tableview, identifyview Line 30  import tableview, identifyview
30    
31  import main  import main
32  from command import registry, Command  from command import registry, Command
33    from messages import SELECTED_SHAPE
34    
35    
36  # the directory where the toolbar icons are stored  # the directory where the toolbar icons are stored
# Line 39  bitmapext = ".xpm" Line 40  bitmapext = ".xpm"
40    
41  class MainWindow(wxFrame):  class MainWindow(wxFrame):
42    
43      def __init__(self, parent, ID):      def __init__(self, parent, ID, interactor):
44          wxFrame.__init__(self, parent, ID, 'Thuban',          wxFrame.__init__(self, parent, ID, 'Thuban',
45                           wxDefaultPosition, wxSize(400, 300))                           wxDefaultPosition, wxSize(400, 300))
46    
# Line 97  class MainWindow(wxFrame): Line 98  class MainWindow(wxFrame):
98          for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",          for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
99                       "map_identify_tool", "map_label_tool"]:                       "map_identify_tool", "map_label_tool"]:
100              self.add_toolbar_command(toolbar, name)              self.add_toolbar_command(toolbar, name)
101            # call Realize to make sure that the tools appear.
102            toolbar.Realize()
103    
104          # Create the map canvas          # Create the map canvas
105          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1, interactor)
106          self.canvas = canvas          self.canvas = canvas
107    
108            self.init_dialogs()
109    
110            interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)
111    
112          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
113    
114      def init_ids(self):      def init_ids(self):
# Line 175  class MainWindow(wxFrame): Line 182  class MainWindow(wxFrame):
182          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
183          if command is not None:          if command is not None:
184              event.Enable(command.Sensitive(self))              event.Enable(command.Sensitive(self))
             event.Check(command.Checked(self))  
185              event.SetText(command.DynText(self))              event.SetText(command.DynText(self))
186                if command.IsCheckCommand():
187                    event.Check(command.Checked(self))
188    
189        def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
190            """Run a modla message box with the given text, title and flags
191            and return the result"""
192            dlg = wxMessageDialog(self, text, title, flags)
193            result = dlg.ShowModal()
194            dlg.Destroy()
195            return result
196    
197        def init_dialogs(self):
198            """Initialize the dialog handling"""
199            # The mainwindow maintains a dict mapping names to open
200            # non-modal dialogs. The dialogs are put into this dict when
201            # they're created and removed when they're closed
202            self.dialogs = {}
203    
204        def add_dialog(self, name, dialog):
205            if self.dialogs.has_key(name):
206                raise RuntimeError("The Dialog named %s is already open" % name)
207            self.dialogs[name] = dialog
208    
209        def dialog_open(self, name):
210            return self.dialogs.has_key(name)
211    
212        def remove_dialog(self, name):
213            del self.dialogs[name]
214    
215        def get_open_dialog(self, name):
216            return self.dialogs.get(name)
217    
218      def NewSession(self):      def NewSession(self):
219          session = Session("")          session = Session("")
# Line 210  class MainWindow(wxFrame): Line 247  class MainWindow(wxFrame):
247              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
248              if event.CanVeto():              if event.CanVeto():
249                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
250              dlg = wxMessageDialog(self,              result = self.RunMessageBox("Exit",
251                                    ("The session has been modified."                                          ("The session has been modified."
252                                     " Do you want to save it?"),                                           " Do you want to save it?"),
253                                    "Exit", flags)                                          flags)
             result = dlg.ShowModal()  
             dlg.Destroy()  
254              if result == wxID_YES:              if result == wxID_YES:
255                  self.SaveSession()                  self.SaveSession()
256              elif result == wxID_CANCEL:              elif result == wxID_CANCEL:
# Line 230  class MainWindow(wxFrame): Line 265  class MainWindow(wxFrame):
265          self.canvas.SetMap(map)          self.canvas.SetMap(map)
266    
267      def About(self):      def About(self):
268          dlg = wxMessageDialog(self,          self.RunMessageBox("About",
269                                ("Thuban is a program for\n"                             ("Thuban is a program for\n"
270                                 "exploring geographic data.\n"                              "exploring geographic data.\n"
271                                 "Copyright (C) 2001 Intevation GmbH.\n"                              "Copyright (C) 2001 Intevation GmbH.\n"
272                                 "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GPL"),
273                                "About", wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
         dlg.ShowModal()  
         dlg.Destroy()  
274    
275      def AddLayer(self):      def AddLayer(self):
276          dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*",          dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*",
# Line 246  class MainWindow(wxFrame): Line 279  class MainWindow(wxFrame):
279              filename = dlg.GetPath()              filename = dlg.GetPath()
280              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
281              layer = Layer(title, filename)              layer = Layer(title, filename)
282              self.canvas.Map().AddLayer(layer)              map = self.canvas.Map()
283                has_layers = map.HasLayers()
284                try:
285                    map.AddLayer(layer)
286                except IOError:
287                    # the layer couldn't be opened
288                    self.RunMessageBox("Add Layer",
289                                       "Can't open the file '%s'." % filename)
290                else:
291                    if not has_layers:
292                        # if we're adding a layer to an empty map, for the
293                        # new map to the window
294                        self.canvas.FitMapToWindow()
295          dlg.Destroy()          dlg.Destroy()
296    
297      def RemoveLayer(self):      def RemoveLayer(self):
298          layer = self.current_layer()          layer = self.current_layer()
299          if layer is not None:          if layer is not None:
300              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()  
301    
302      def RaiseLayer(self):      def RaiseLayer(self):
303          layer = self.current_layer()          layer = self.current_layer()
# Line 339  class MainWindow(wxFrame): Line 379  class MainWindow(wxFrame):
379      def LayerShowTable(self):      def LayerShowTable(self):
380          layer = self.current_layer()          layer = self.current_layer()
381          if layer is not None:          if layer is not None:
382              tv = tableview.TableFrame(self, layer.table)              table = layer.table
383              tv.Show(true)              name = "table_view" + str(id(table))
384                dialog = self.get_open_dialog(name)
385                if dialog is None:
386                    dialog = tableview.TableFrame(self, main.app.interactor, name,
387                                                  "Table: %s" % layer.Title(),
388                                                  layer, table)
389                    self.add_dialog(name, dialog)
390                    dialog.Show(true)
391                else:
392                    # FIXME: bring dialog to front here
393                    pass
394    
395      def Projection(self):      def Projection(self):
396          map = self.canvas.Map()          map = self.canvas.Map()
# Line 368  class MainWindow(wxFrame): Line 418  class MainWindow(wxFrame):
418          self.canvas.PanTool()          self.canvas.PanTool()
419    
420      def IdentifyTool(self):      def IdentifyTool(self):
         if self.identify_view is None:  
             self.identify_view = identifyview.IdentifyView(self, main.app)  
             self.identify_view.Show(true)  
421          self.canvas.IdentifyTool()          self.canvas.IdentifyTool()
422    
423      def LabelTool(self):      def LabelTool(self):
# Line 382  class MainWindow(wxFrame): Line 429  class MainWindow(wxFrame):
429      def PrintMap(self):      def PrintMap(self):
430          self.canvas.Print()          self.canvas.Print()
431    
432        def identify_view_on_demand(self, layer, shape):
433            name = "identify_view"
434            if self.canvas.CurrentTool() == "IdentifyTool":
435                if not self.dialog_open(name):
436                    dialog = identifyview.IdentifyView(self, main.app.interactor,
437                                                       name)
438                    self.add_dialog(name, dialog)
439                    dialog.Show(true)
440                else:
441                    # FIXME: bring dialog to front?
442                    pass
443    
444  #  #
445  # Define all the commands available in the main window  # Define all the commands available in the main window

Legend:
Removed from v.6  
changed lines
  Added in v.33

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26