/[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 31 by bh, Thu Sep 6 13:32:39 2001 UTC revision 113 by jan, Sun Apr 21 17:38:50 2002 UTC
# Line 17  import sys, os Line 17  import sys, os
17  from wxPython.wx import *  from wxPython.wx import *
18    
19  import Thuban  import Thuban
20  from Thuban.Model.session import Session  from Thuban.Model.session import Session, create_empty_session
21  from Thuban.Model.map import Map  from Thuban.Model.map import Map
22  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
23  from Thuban.Model.color import Color  from Thuban.Model.color import Color
# Line 44  class MainWindow(wxFrame): Line 44  class MainWindow(wxFrame):
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 63  class MainWindow(wxFrame): Line 65  class MainWindow(wxFrame):
65    
66          menu = wxMenu()          menu = wxMenu()
67          menuBar.Append(menu, "&Map");          menuBar.Append(menu, "&Map");
68          for name in ["map_projection",          for name in ["layer_add", "layer_remove",
69                         None,
70                         "map_projection",
71                       None,                       None,
72                       "map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                       "map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
73                       "map_identify_tool", "map_label_tool",                       "map_identify_tool", "map_label_tool",
# Line 75  class MainWindow(wxFrame): Line 79  class MainWindow(wxFrame):
79    
80          menu = wxMenu()          menu = wxMenu()
81          menuBar.Append(menu, "&Layer");          menuBar.Append(menu, "&Layer");
82          for name in ["layer_add", "layer_remove",          for name in ["layer_fill_color", "layer_transparent_fill",
                      None,  
                      "layer_fill_color", "layer_transparent_fill",  
83                       "layer_ourline_color", "layer_no_outline",                       "layer_ourline_color", "layer_no_outline",
84                       None,                       None,
85                       "layer_raise", "layer_lower",                       "layer_raise", "layer_lower",
# Line 95  class MainWindow(wxFrame): Line 97  class MainWindow(wxFrame):
97    
98          # toolbar          # toolbar
99          toolbar = self.CreateToolBar(wxTB_3DBUTTONS)          toolbar = self.CreateToolBar(wxTB_3DBUTTONS)
100    
101            # set the size of the tools' bitmaps. Not needed on wxGTK, but
102            # on Windows. We probably shouldn't hardwire the bitmap size
103            # here
104            toolbar.SetToolBitmapSize(wxSize(24, 24))
105    
106          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",
107                       "map_identify_tool", "map_label_tool"]:                       "map_identify_tool", "map_label_tool", "map_full_extent"]:
108              self.add_toolbar_command(toolbar, name)              self.add_toolbar_command(toolbar, name)
109          # call Realize to make sure that the tools appear.          # call Realize to make sure that the tools appear.
110          toolbar.Realize()          toolbar.Realize()
# Line 215  class MainWindow(wxFrame): Line 223  class MainWindow(wxFrame):
223      def get_open_dialog(self, name):      def get_open_dialog(self, name):
224          return self.dialogs.get(name)          return self.dialogs.get(name)
225    
226        def save_modified_session(self, can_veto = 1):
227            """If the current session has been modified, ask the user
228            whether to save it and do so if requested. Return the outcome of
229            the dialog (either wxID_OK, wxID_CANCEL or wxID_NO). If the
230            dialog wasn't run return wxID_NO.
231    
232            If the can_veto parameter is true (default) the dialog includes
233            a cancel button, otherwise not.
234            """
235            if main.app.session.WasModified():
236                flags = wxYES_NO | wxICON_QUESTION
237                if can_veto:
238                    flags = flags | wxCANCEL
239                result = self.RunMessageBox("Exit",
240                                            ("The session has been modified."
241                                             " Do you want to save it?"),
242                                            flags)
243                if result == wxID_YES:
244                    self.SaveSession()
245            else:
246                result = wxID_NO
247            return result
248    
249      def NewSession(self):      def NewSession(self):
250          session = Session("")          self.save_modified_session()
251          session.AddMap(Map(""))          main.app.SetSession(create_empty_session())
         main.app.SetSession(session)  
252    
253      def OpenSession(self):      def OpenSession(self):
254            self.save_modified_session()
255          dlg = wxFileDialog(self, "Select a session file", ".", "",          dlg = wxFileDialog(self, "Select a session file", ".", "",
256                             "*.session", wxOPEN)                             "*.session", wxOPEN)
257          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
# Line 228  class MainWindow(wxFrame): Line 259  class MainWindow(wxFrame):
259          dlg.Destroy()          dlg.Destroy()
260    
261      def SaveSession(self):      def SaveSession(self):
262            if main.app.session.filename == None:
263                self.SaveSessionAs()
264          main.app.SaveSession()          main.app.SaveSession()
265    
266      def SaveSessionAs(self):      def SaveSessionAs(self):
# Line 242  class MainWindow(wxFrame): Line 275  class MainWindow(wxFrame):
275          self.Close(false)          self.Close(false)
276    
277      def OnClose(self, event):      def OnClose(self, event):
278          veto = 0          result = self.save_modified_session(can_veto = event.CanVeto())
279          if main.app.session.WasModified():          if result == wxID_CANCEL:
             flags = wxYES_NO | wxICON_QUESTION  
             if event.CanVeto():  
                 flags = flags | wxCANCEL  
             result = self.RunMessageBox("Exit",  
                                         ("The session has been modified."  
                                          " Do you want to save it?"),  
                                         flags)  
             if result == wxID_YES:  
                 self.SaveSession()  
             elif result == wxID_CANCEL:  
                 veto = 1  
   
         if veto:  
280              event.Veto()              event.Veto()
281          else:          else:
282              self.Destroy()              self.Destroy()
# Line 264  class MainWindow(wxFrame): Line 284  class MainWindow(wxFrame):
284      def SetMap(self, map):      def SetMap(self, map):
285          self.canvas.SetMap(map)          self.canvas.SetMap(map)
286    
287        def ShowSessionTree(self):
288            name = "session_tree"
289            dialog = self.get_open_dialog(name)
290            if dialog is None:
291                dialog = tree.SessionTreeView(self, main.app, name)
292                self.add_dialog(name, dialog)
293                dialog.Show(true)
294            else:
295                # FIXME: bring dialog to front here
296                pass
297    
298      def About(self):      def About(self):
299          self.RunMessageBox("About",          self.RunMessageBox("About",
300                             ("Thuban is a program for\n"                             ("Thuban is a program for\n"
# Line 314  class MainWindow(wxFrame): Line 345  class MainWindow(wxFrame):
345    
346          If no layer is selected, return None          If no layer is selected, return None
347          """          """
348          tree = main.app.tree.tree          return self.interactor.SelectedLayer()
         layer = tree.GetPyData(tree.GetSelection())  
         if isinstance(layer, Layer):  
             return layer  
         return None  
349    
350      def has_selected_layer(self):      def has_selected_layer(self):
351          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
352          tree = main.app.tree.tree          return self.interactor.HasSelectedLayer()
         layer = tree.GetPyData(tree.GetSelection())  
         return isinstance(layer, Layer)  
353    
354      def choose_color(self):      def choose_color(self):
355          """Run the color selection dialog and return the selected color.          """Run the color selection dialog and return the selected color.
# Line 383  class MainWindow(wxFrame): Line 408  class MainWindow(wxFrame):
408              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
409              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
410              if dialog is None:              if dialog is None:
411                  dialog = tableview.TableFrame(self, main.app.interactor, name,                  dialog = tableview.TableFrame(self, self.interactor, name,
412                                                "Table: %s" % layer.Title(),                                                "Table: %s" % layer.Title(),
413                                                table)                                                layer, table)
414                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
415                  dialog.Show(true)                  dialog.Show(true)
416              else:              else:
# Line 396  class MainWindow(wxFrame): Line 421  class MainWindow(wxFrame):
421          map = self.canvas.Map()          map = self.canvas.Map()
422          proj = map.projection          proj = map.projection
423          if proj is None:          if proj is None:
424              proj4Dlg = proj4dialog.Proj4Dialog(NULL, None)              proj4Dlg = proj4dialog.Proj4Dialog(NULL, None, map.BoundingBox())
425          else:          else:
426              proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params)              proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params,
427                                                   map.BoundingBox())
428          if proj4Dlg.ShowModal() == wxID_OK:          if proj4Dlg.ShowModal() == wxID_OK:
429              params = proj4Dlg.GetParams()              params = proj4Dlg.GetParams()
430              if params is not None:              if params is not None:
# Line 419  class MainWindow(wxFrame): Line 445  class MainWindow(wxFrame):
445    
446      def IdentifyTool(self):      def IdentifyTool(self):
447          self.canvas.IdentifyTool()          self.canvas.IdentifyTool()
448            self.identify_view_on_demand(None, None)
449    
450      def LabelTool(self):      def LabelTool(self):
451          self.canvas.LabelTool()          self.canvas.LabelTool()
# Line 433  class MainWindow(wxFrame): Line 460  class MainWindow(wxFrame):
460          name = "identify_view"          name = "identify_view"
461          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
462              if not self.dialog_open(name):              if not self.dialog_open(name):
463                  dialog = identifyview.IdentifyView(self, main.app.interactor,                  dialog = identifyview.IdentifyView(self, self.interactor, name)
                                                    name)  
464                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
465                  dialog.Show(true)                  dialog.Show(true)
466              else:              else:
467                  # FIXME: bring dialog to from?                  # FIXME: bring dialog to front?
468                  pass                  pass
469    
470  #  #
# Line 451  def call_method(context, methodname, *ar Line 477  def call_method(context, methodname, *ar
477      """Call the context's method methodname with args *args"""      """Call the context's method methodname with args *args"""
478      apply(getattr(context, methodname), args)      apply(getattr(context, methodname), args)
479    
480  def _method_command(name, title, method, helptext = "", sensitive = None):  def _method_command(name, title, method, helptext = "",
481                        icon = "", sensitive = None):
482      """Add a command implemented by a method of the context object"""      """Add a command implemented by a method of the context object"""
483      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
484                           helptext = helptext, sensitive = sensitive))                           helptext = helptext, icon = icon,
485                             sensitive = sensitive))
486    
487  def _tool_command(name, title, method, toolname, helptext = "",  def _tool_command(name, title, method, toolname, helptext = "",
488                    icon = ""):                    icon = ""):
489      """Add a tool command"""      """Add a tool command"""
# Line 492  _tool_command("map_identify_tool", "&Ide Line 521  _tool_command("map_identify_tool", "&Ide
521                helptext = "Switch to map-mode 'identify'", icon = "identify")                helptext = "Switch to map-mode 'identify'", icon = "identify")
522  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",
523                helptext = "Add/Remove labels", icon = "label")                helptext = "Add/Remove labels", icon = "label")
524  _method_command("map_full_extent", "&Full extent", "FullExtent")  _method_command("map_full_extent", "&Full extent", "FullExtent",
525                   helptext = "Full Extent", icon = "fullextent")
526  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")
527    
528  # Layer menu  # Layer menu
529  _method_command("layer_add", "&Add", "AddLayer",  _method_command("layer_add", "&Add Layer", "AddLayer",
530                  helptext = "Add a new layer to active map")                  helptext = "Add a new layer to active map")
531  _method_command("layer_remove", "&Remove", "RemoveLayer",  _method_command("layer_remove", "&Remove Layer", "RemoveLayer",
532                  helptext = "Remove selected layer(s)",                  helptext = "Remove selected layer(s)",
533                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
534  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",

Legend:
Removed from v.31  
changed lines
  Added in v.113

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26