/[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 562 by jonathan, Thu Mar 20 09:45:19 2003 UTC revision 563 by jonathan, Wed Mar 26 11:07:02 2003 UTC
# Line 36  from menu import Menu Line 36  from menu import Menu
36    
37  from context import Context  from context import Context
38  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
39  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED
40    
41    from Thuban.UI.dock import DockableWindow
42    
43    
44  # the directory where the toolbar icons are stored  # the directory where the toolbar icons are stored
45  bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")
46  bitmapext = ".xpm"  bitmapext = ".xpm"
47    
48    ID_WINDOW_LEGEND = 4001
49    ID_WINDOW_CANVAS = 4002
50    
51    
52  class MainWindow(wxFrame):  class MainWindow(wxFrame):
53    
# Line 82  class MainWindow(wxFrame): Line 87  class MainWindow(wxFrame):
87          # call Realize to make sure that the tools appear.          # call Realize to make sure that the tools appear.
88          toolbar.Realize()          toolbar.Realize()
89    
90            win = wxSashLayoutWindow(self, ID_WINDOW_LEGEND,
91                                     style=wxNO_BORDER|wxSW_3D)
92            win.SetOrientation(wxLAYOUT_VERTICAL)
93            win.SetAlignment(wxLAYOUT_LEFT)
94            win.SetSashVisible(wxSASH_RIGHT, True)
95            win.SetSashBorder(wxSASH_RIGHT, True)
96            win.Hide()
97            self.sash_legend = win
98    
99    
100          # Create the map canvas          # Create the map canvas
101          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1)
102          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
103          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
104          self.canvas = canvas          self.canvas = canvas
105    
106            self.SetAutoLayout(True)
107    
108          self.init_dialogs()          self.init_dialogs()
109    
110            self.legendPanel = None
111            self.legendWindow = None
112    
113    
114    
115          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
116            EVT_SASH_DRAGGED_RANGE(self,
117                ID_WINDOW_LEGEND, ID_WINDOW_CANVAS,
118                self._OnSashDrag)
119            EVT_SIZE(self, self._OnSize)
120    
121      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
122          """Subscribe a function to a message channel.          """Subscribe a function to a message channel.
# Line 391  class MainWindow(wxFrame): Line 417  class MainWindow(wxFrame):
417    
418      def SetMap(self, map):      def SetMap(self, map):
419          self.canvas.SetMap(map)          self.canvas.SetMap(map)
420            #self.legendPanel.SetMap(map)
421    
422      def Map(self):      def Map(self):
423          """Return the map displayed by this mainwindow"""          """Return the map displayed by this mainwindow"""
424    
425            # sanity check
426            #assert(self.canvas.Map() is self.legendPanel.GetMap())
427    
428          return self.canvas.Map()          return self.canvas.Map()
429    
430      def ShowSessionTree(self):      def ShowSessionTree(self):
# Line 585  class MainWindow(wxFrame): Line 616  class MainWindow(wxFrame):
616              dialog.Show()              dialog.Show()
617    
618    
619      def ShowLegend(self):      def ShowLegend(self, switch = False):
620            
621          name = "legend"          name = "legend"
622          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
623    
624          if dialog is None:          if dialog is None:
625              dialog = legend.Legend(self, name, self.Map())              self.legendPanel = \
626                    legend.LegendPanel(self.sash_legend, None, self)
627                dialog = DockableWindow(self, -1, name,
628                                        "Legend: %s" % self.Map().Title(),
629                                        self.sash_legend, self.legendPanel)
630    
631    
632              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
633              dialog.Show()  
634                dialog.Subscribe(DOCKABLE_DOCKED, self._OnLegendDock)
635                dialog.Subscribe(DOCKABLE_UNDOCKED, self._OnLegendUnDock)
636                dialog.Subscribe(DOCKABLE_CLOSED, self._OnLegendClosed)
637    
638                self.legendWindow = dialog
639                self.legendPanel.SetMap(self.Map())
640    
641            dialog.Show()
642    
643      def ZoomInTool(self):      def ZoomInTool(self):
644          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 622  class MainWindow(wxFrame): Line 668  class MainWindow(wxFrame):
668              if not self.dialog_open(name):              if not self.dialog_open(name):
669                  dialog = identifyview.IdentifyView(self, name)                  dialog = identifyview.IdentifyView(self, name)
670                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
671                  dialog.Show(true)                  dialog.Show(True)
672              else:              else:
673                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
674                  pass                  pass
675    
676    
677        def _OnSashDrag(self, event):
678    
679            if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
680                return
681    
682            id = event.GetId()
683    
684            rect = event.GetDragRect()
685    
686            if id == ID_WINDOW_LEGEND:
687                #assert(self.legendPanel.IsDocked())
688                assert(self.legendWindow.IsDocked())
689                #assert(self.legendPanel.GetParent() is self.sash_legend)
690                self.__SetLegendDockSize(rect)
691    
692            wxLayoutAlgorithm().LayoutWindow(self, self.canvas)
693    
694        def _OnSize(self, event):
695            wxLayoutAlgorithm().LayoutWindow(self, self.canvas)
696    
697        def _OnLegendDock(self, id, win):
698            if not self.sash_legend.IsShown():
699                self.sash_legend.Show()
700                self.__SetLegendDockSize(None)
701                wxLayoutAlgorithm().LayoutWindow(self, self.canvas)
702    
703        def _OnLegendUnDock(self, id, win):
704            if self.sash_legend.IsShown():
705                self.sash_legend.Hide()
706                wxLayoutAlgorithm().LayoutWindow(self, self.canvas)
707    
708        def _OnLegendClosed(self, id, win):
709            if self.sash_legend.IsShown():
710                self.sash_legend.Hide()
711                wxLayoutAlgorithm().LayoutWindow(self, self.canvas)
712    
713        def __SetLegendDockSize(self, rect):
714        
715            w, h = self.legendWindow.GetBestSize()
716            #w, h = self.legendPanel.GetBestSize()
717    
718            if rect is not None:
719                rw = rect.width
720                rh = rect.height
721                if rw < w: rw = w
722            else:
723                rw = w
724                rh = h
725    
726            rw += 2 # XXX: without this the sash isn't visible!?!?!?!
727    
728            self.sash_legend.SetDefaultSize(wxSize(rw, 1000))
729    
730  #  #
731  # Define all the commands available in the main window  # Define all the commands available in the main window
732  #  #

Legend:
Removed from v.562  
changed lines
  Added in v.563

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26