/[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 58 by bh, Thu Sep 13 13:56:23 2001 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 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"]:
108              self.add_toolbar_command(toolbar, name)              self.add_toolbar_command(toolbar, name)
# 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 242  class MainWindow(wxFrame): Line 273  class MainWindow(wxFrame):
273          self.Close(false)          self.Close(false)
274    
275      def OnClose(self, event):      def OnClose(self, event):
276          veto = 0          result = self.save_modified_session(can_veto = event.CanVeto())
277          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:  
278              event.Veto()              event.Veto()
279          else:          else:
280              self.Destroy()              self.Destroy()
# Line 264  class MainWindow(wxFrame): Line 282  class MainWindow(wxFrame):
282      def SetMap(self, map):      def SetMap(self, map):
283          self.canvas.SetMap(map)          self.canvas.SetMap(map)
284    
285        def ShowSessionTree(self):
286            name = "session_tree"
287            dialog = self.get_open_dialog(name)
288            if dialog is None:
289                dialog = tree.SessionTreeView(self, main.app, name)
290                self.add_dialog(name, dialog)
291                dialog.Show(true)
292            else:
293                # FIXME: bring dialog to front here
294                pass
295    
296      def About(self):      def About(self):
297          self.RunMessageBox("About",          self.RunMessageBox("About",
298                             ("Thuban is a program for\n"                             ("Thuban is a program for\n"
# Line 314  class MainWindow(wxFrame): Line 343  class MainWindow(wxFrame):
343    
344          If no layer is selected, return None          If no layer is selected, return None
345          """          """
346          tree = main.app.tree.tree          return self.interactor.SelectedLayer()
         layer = tree.GetPyData(tree.GetSelection())  
         if isinstance(layer, Layer):  
             return layer  
         return None  
347    
348      def has_selected_layer(self):      def has_selected_layer(self):
349          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
350          tree = main.app.tree.tree          return self.interactor.HasSelectedLayer()
         layer = tree.GetPyData(tree.GetSelection())  
         return isinstance(layer, Layer)  
351    
352      def choose_color(self):      def choose_color(self):
353          """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 406  class MainWindow(wxFrame):
406              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
407              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
408              if dialog is None:              if dialog is None:
409                  dialog = tableview.TableFrame(self, main.app.interactor, name,                  dialog = tableview.TableFrame(self, self.interactor, name,
410                                                "Table: %s" % layer.Title(),                                                "Table: %s" % layer.Title(),
411                                                table)                                                layer, table)
412                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
413                  dialog.Show(true)                  dialog.Show(true)
414              else:              else:
# Line 419  class MainWindow(wxFrame): Line 442  class MainWindow(wxFrame):
442    
443      def IdentifyTool(self):      def IdentifyTool(self):
444          self.canvas.IdentifyTool()          self.canvas.IdentifyTool()
445            self.identify_view_on_demand(None, None)
446    
447      def LabelTool(self):      def LabelTool(self):
448          self.canvas.LabelTool()          self.canvas.LabelTool()
# Line 433  class MainWindow(wxFrame): Line 457  class MainWindow(wxFrame):
457          name = "identify_view"          name = "identify_view"
458          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
459              if not self.dialog_open(name):              if not self.dialog_open(name):
460                  dialog = identifyview.IdentifyView(self, main.app.interactor,                  dialog = identifyview.IdentifyView(self, self.interactor, name)
                                                    name)  
461                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
462                  dialog.Show(true)                  dialog.Show(true)
463              else:              else:
464                  # FIXME: bring dialog to from?                  # FIXME: bring dialog to front?
465                  pass                  pass
466    
467  #  #

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26