/[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 18 by bh, Mon Sep 3 16:25:09 2001 UTC revision 37 by bh, Thu Sep 6 17:16:54 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    
47            self.interactor = interactor
48    
49          self.CreateStatusBar()          self.CreateStatusBar()
50          self.SetStatusText("This is the wxPython-based "          self.SetStatusText("This is the wxPython-based "
51                        "Graphical User Interface for exploring geographic data")                        "Graphical User Interface for exploring geographic data")
# Line 101  class MainWindow(wxFrame): Line 104  class MainWindow(wxFrame):
104          toolbar.Realize()          toolbar.Realize()
105    
106          # Create the map canvas          # Create the map canvas
107          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1, interactor)
108          self.canvas = canvas          self.canvas = canvas
109    
110            self.init_dialogs()
111    
112            interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)
113    
114          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
115    
116      def init_ids(self):      def init_ids(self):
# Line 181  class MainWindow(wxFrame): Line 188  class MainWindow(wxFrame):
188              if command.IsCheckCommand():              if command.IsCheckCommand():
189                  event.Check(command.Checked(self))                  event.Check(command.Checked(self))
190    
191        def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
192            """Run a modla message box with the given text, title and flags
193            and return the result"""
194            dlg = wxMessageDialog(self, text, title, flags)
195            result = dlg.ShowModal()
196            dlg.Destroy()
197            return result
198    
199        def init_dialogs(self):
200            """Initialize the dialog handling"""
201            # The mainwindow maintains a dict mapping names to open
202            # non-modal dialogs. The dialogs are put into this dict when
203            # they're created and removed when they're closed
204            self.dialogs = {}
205    
206        def add_dialog(self, name, dialog):
207            if self.dialogs.has_key(name):
208                raise RuntimeError("The Dialog named %s is already open" % name)
209            self.dialogs[name] = dialog
210    
211        def dialog_open(self, name):
212            return self.dialogs.has_key(name)
213    
214        def remove_dialog(self, name):
215            del self.dialogs[name]
216    
217        def get_open_dialog(self, name):
218            return self.dialogs.get(name)
219    
220      def NewSession(self):      def NewSession(self):
221          session = Session("")          session = Session("")
222          session.AddMap(Map(""))          session.AddMap(Map(""))
# Line 213  class MainWindow(wxFrame): Line 249  class MainWindow(wxFrame):
249              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
250              if event.CanVeto():              if event.CanVeto():
251                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
252              dlg = wxMessageDialog(self,              result = self.RunMessageBox("Exit",
253                                    ("The session has been modified."                                          ("The session has been modified."
254                                     " Do you want to save it?"),                                           " Do you want to save it?"),
255                                    "Exit", flags)                                          flags)
             result = dlg.ShowModal()  
             dlg.Destroy()  
256              if result == wxID_YES:              if result == wxID_YES:
257                  self.SaveSession()                  self.SaveSession()
258              elif result == wxID_CANCEL:              elif result == wxID_CANCEL:
# Line 232  class MainWindow(wxFrame): Line 266  class MainWindow(wxFrame):
266      def SetMap(self, map):      def SetMap(self, map):
267          self.canvas.SetMap(map)          self.canvas.SetMap(map)
268    
269        def ShowSessionTree(self):
270            name = "session_tree"
271            dialog = self.get_open_dialog(name)
272            if dialog is None:
273                dialog = tree.SessionTreeView(self, main.app, name)
274                self.add_dialog(name, dialog)
275                dialog.Show(true)
276            else:
277                # FIXME: bring dialog to front here
278                pass
279    
280      def About(self):      def About(self):
281          dlg = wxMessageDialog(self,          self.RunMessageBox("About",
282                                ("Thuban is a program for\n"                             ("Thuban is a program for\n"
283                                 "exploring geographic data.\n"                              "exploring geographic data.\n"
284                                 "Copyright (C) 2001 Intevation GmbH.\n"                              "Copyright (C) 2001 Intevation GmbH.\n"
285                                 "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GPL"),
286                                "About", wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
         dlg.ShowModal()  
         dlg.Destroy()  
287    
288      def AddLayer(self):      def AddLayer(self):
289          dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*",          dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*",
# Line 251  class MainWindow(wxFrame): Line 294  class MainWindow(wxFrame):
294              layer = Layer(title, filename)              layer = Layer(title, filename)
295              map = self.canvas.Map()              map = self.canvas.Map()
296              has_layers = map.HasLayers()              has_layers = map.HasLayers()
297              map.AddLayer(layer)              try:
298              if not has_layers:                  map.AddLayer(layer)
299                  # if we're adding a layer to an empty map, for the new              except IOError:
300                  # map to the window                  # the layer couldn't be opened
301                  self.canvas.FitMapToWindow()                  self.RunMessageBox("Add Layer",
302                                       "Can't open the file '%s'." % filename)
303                else:
304                    if not has_layers:
305                        # if we're adding a layer to an empty map, for the
306                        # new map to the window
307                        self.canvas.FitMapToWindow()
308          dlg.Destroy()          dlg.Destroy()
309    
310      def RemoveLayer(self):      def RemoveLayer(self):
311          layer = self.current_layer()          layer = self.current_layer()
312          if layer is not None:          if layer is not None:
313              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()  
314    
315      def RaiseLayer(self):      def RaiseLayer(self):
316          layer = self.current_layer()          layer = self.current_layer()
# Line 283  class MainWindow(wxFrame): Line 327  class MainWindow(wxFrame):
327    
328          If no layer is selected, return None          If no layer is selected, return None
329          """          """
330          tree = main.app.tree.tree          return self.interactor.SelectedLayer()
         layer = tree.GetPyData(tree.GetSelection())  
         if isinstance(layer, Layer):  
             return layer  
         return None  
331    
332      def has_selected_layer(self):      def has_selected_layer(self):
333          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
334          tree = main.app.tree.tree          return self.interactor.HasSelectedLayer()
         layer = tree.GetPyData(tree.GetSelection())  
         return isinstance(layer, Layer)  
335    
336      def choose_color(self):      def choose_color(self):
337          """Run the color selection dialog and return the selected color.          """Run the color selection dialog and return the selected color.
# Line 348  class MainWindow(wxFrame): Line 386  class MainWindow(wxFrame):
386      def LayerShowTable(self):      def LayerShowTable(self):
387          layer = self.current_layer()          layer = self.current_layer()
388          if layer is not None:          if layer is not None:
389              tv = tableview.TableFrame(self, layer.table)              table = layer.table
390              tv.Show(true)              name = "table_view" + str(id(table))
391                dialog = self.get_open_dialog(name)
392                if dialog is None:
393                    dialog = tableview.TableFrame(self, self.interactor, name,
394                                                  "Table: %s" % layer.Title(),
395                                                  layer, table)
396                    self.add_dialog(name, dialog)
397                    dialog.Show(true)
398                else:
399                    # FIXME: bring dialog to front here
400                    pass
401    
402      def Projection(self):      def Projection(self):
403          map = self.canvas.Map()          map = self.canvas.Map()
# Line 377  class MainWindow(wxFrame): Line 425  class MainWindow(wxFrame):
425          self.canvas.PanTool()          self.canvas.PanTool()
426    
427      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)  
428          self.canvas.IdentifyTool()          self.canvas.IdentifyTool()
429    
430      def LabelTool(self):      def LabelTool(self):
# Line 391  class MainWindow(wxFrame): Line 436  class MainWindow(wxFrame):
436      def PrintMap(self):      def PrintMap(self):
437          self.canvas.Print()          self.canvas.Print()
438    
439        def identify_view_on_demand(self, layer, shape):
440            name = "identify_view"
441            if self.canvas.CurrentTool() == "IdentifyTool":
442                if not self.dialog_open(name):
443                    dialog = identifyview.IdentifyView(self, self.interactor, name)
444                    self.add_dialog(name, dialog)
445                    dialog.Show(true)
446                else:
447                    # FIXME: bring dialog to front?
448                    pass
449    
450  #  #
451  # Define all the commands available in the main window  # Define all the commands available in the main window

Legend:
Removed from v.18  
changed lines
  Added in v.37

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26