38 |
from command import registry, Command, ToolCommand |
from command import registry, Command, ToolCommand |
39 |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED |
40 |
|
|
41 |
from Thuban.UI.dock import DockableWindow |
from Thuban.UI.dock import DockableWindow, DockFrame, DockPanel |
42 |
|
|
43 |
|
|
44 |
# the directory where the toolbar icons are stored |
# the directory where the toolbar icons are stored |
49 |
ID_WINDOW_CANVAS = 4002 |
ID_WINDOW_CANVAS = 4002 |
50 |
|
|
51 |
|
|
52 |
class MainWindow(wxFrame): |
class MainWindow(DockFrame): |
53 |
|
|
54 |
# Some messages that can be subscribed/unsubscribed directly through |
# Some messages that can be subscribed/unsubscribed directly through |
55 |
# the MapCanvas come in fact from other objects. This is a map to |
# the MapCanvas come in fact from other objects. This is a map to |
67 |
|
|
68 |
def __init__(self, parent, ID, title, application, interactor, |
def __init__(self, parent, ID, title, application, interactor, |
69 |
initial_message = None, size = wxSize(-1, -1)): |
initial_message = None, size = wxSize(-1, -1)): |
70 |
wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
71 |
|
#wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
72 |
|
|
73 |
self.application = application |
self.application = application |
74 |
|
|
88 |
# call Realize to make sure that the tools appear. |
# call Realize to make sure that the tools appear. |
89 |
toolbar.Realize() |
toolbar.Realize() |
90 |
|
|
|
win = wxSashLayoutWindow(self, ID_WINDOW_LEGEND, |
|
|
style=wxNO_BORDER|wxSW_3D) |
|
|
win.SetOrientation(wxLAYOUT_VERTICAL) |
|
|
win.SetAlignment(wxLAYOUT_LEFT) |
|
|
win.SetSashVisible(wxSASH_RIGHT, True) |
|
|
win.SetSashBorder(wxSASH_RIGHT, True) |
|
|
win.Hide() |
|
|
self.sash_legend = win |
|
|
|
|
91 |
|
|
92 |
# Create the map canvas |
# Create the map canvas |
93 |
canvas = view.MapCanvas(self, -1) |
canvas = view.MapCanvas(self, -1) |
95 |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
96 |
self.canvas = canvas |
self.canvas = canvas |
97 |
|
|
98 |
|
self.SetMainWindow(self.canvas) |
99 |
|
|
100 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
101 |
|
|
102 |
self.init_dialogs() |
self.init_dialogs() |
103 |
|
|
|
self.legendPanel = None |
|
|
self.legendWindow = None |
|
|
|
|
|
|
|
|
|
|
104 |
EVT_CLOSE(self, self.OnClose) |
EVT_CLOSE(self, self.OnClose) |
|
EVT_SASH_DRAGGED_RANGE(self, |
|
|
ID_WINDOW_LEGEND, ID_WINDOW_CANVAS, |
|
|
self._OnSashDrag) |
|
|
EVT_SIZE(self, self._OnSize) |
|
105 |
|
|
106 |
def Subscribe(self, channel, *args): |
def Subscribe(self, channel, *args): |
107 |
"""Subscribe a function to a message channel. |
"""Subscribe a function to a message channel. |
591 |
layer = self.current_layer() |
layer = self.current_layer() |
592 |
self.OpenClassifier(layer) |
self.OpenClassifier(layer) |
593 |
|
|
594 |
def OpenClassifier(self, layer): |
def OpenClassifier(self, layer, group = None): |
595 |
name = "classifier" + str(id(layer)) |
name = "classifier" + str(id(layer)) |
596 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
597 |
|
|
598 |
if dialog is None: |
if dialog is None: |
599 |
dialog = classifier.Classifier(self, name, layer) |
dialog = classifier.Classifier(self, name, layer, group) |
600 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
601 |
dialog.Show() |
dialog.Show() |
602 |
|
dialog.Raise() |
603 |
|
|
604 |
|
|
605 |
def ShowLegend(self, switch = False): |
def ShowLegend(self, switch = False): |
|
|
|
606 |
name = "legend" |
name = "legend" |
607 |
dialog = self.get_open_dialog(name) |
dialog = self.FindRegisteredDock(name) |
608 |
|
|
609 |
if dialog is None: |
if dialog is None: |
610 |
self.legendPanel = \ |
title = "Legend: %s" % self.Map().Title() |
611 |
legend.LegendPanel(self.sash_legend, None, self) |
dialog = self.CreateDock(name, -1, title, wxLAYOUT_LEFT) |
612 |
dialog = DockableWindow(self, -1, name, |
legend.LegendPanel(dialog, None, self) |
|
"Legend: %s" % self.Map().Title(), |
|
|
self.sash_legend, self.legendPanel) |
|
|
|
|
|
|
|
|
self.add_dialog(name, dialog) |
|
|
|
|
|
dialog.Subscribe(DOCKABLE_DOCKED, self._OnLegendDock) |
|
|
dialog.Subscribe(DOCKABLE_UNDOCKED, self._OnLegendUnDock) |
|
|
dialog.Subscribe(DOCKABLE_CLOSED, self._OnLegendClosed) |
|
|
|
|
|
self.legendWindow = dialog |
|
|
self.legendPanel.SetMap(self.Map()) |
|
613 |
|
|
614 |
|
dialog.GetPanel().SetMap(self.Map()) |
615 |
dialog.Show() |
dialog.Show() |
616 |
|
|
617 |
def ZoomInTool(self): |
def ZoomInTool(self): |
647 |
# FIXME: bring dialog to front? |
# FIXME: bring dialog to front? |
648 |
pass |
pass |
649 |
|
|
|
|
|
|
def _OnSashDrag(self, event): |
|
|
|
|
|
if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE: |
|
|
return |
|
|
|
|
|
id = event.GetId() |
|
|
|
|
|
rect = event.GetDragRect() |
|
|
|
|
|
if id == ID_WINDOW_LEGEND: |
|
|
#assert(self.legendPanel.IsDocked()) |
|
|
assert(self.legendWindow.IsDocked()) |
|
|
#assert(self.legendPanel.GetParent() is self.sash_legend) |
|
|
self.__SetLegendDockSize(rect) |
|
|
|
|
|
wxLayoutAlgorithm().LayoutWindow(self, self.canvas) |
|
|
|
|
|
def _OnSize(self, event): |
|
|
wxLayoutAlgorithm().LayoutWindow(self, self.canvas) |
|
|
|
|
|
def _OnLegendDock(self, id, win): |
|
|
if not self.sash_legend.IsShown(): |
|
|
self.sash_legend.Show() |
|
|
self.__SetLegendDockSize(None) |
|
|
wxLayoutAlgorithm().LayoutWindow(self, self.canvas) |
|
|
|
|
|
def _OnLegendUnDock(self, id, win): |
|
|
if self.sash_legend.IsShown(): |
|
|
self.sash_legend.Hide() |
|
|
wxLayoutAlgorithm().LayoutWindow(self, self.canvas) |
|
|
|
|
|
def _OnLegendClosed(self, id, win): |
|
|
if self.sash_legend.IsShown(): |
|
|
self.sash_legend.Hide() |
|
|
wxLayoutAlgorithm().LayoutWindow(self, self.canvas) |
|
|
|
|
|
def __SetLegendDockSize(self, rect): |
|
|
|
|
|
w, h = self.legendWindow.GetBestSize() |
|
|
#w, h = self.legendPanel.GetBestSize() |
|
|
|
|
|
if rect is not None: |
|
|
rw = rect.width |
|
|
rh = rect.height |
|
|
if rw < w: rw = w |
|
|
else: |
|
|
rw = w |
|
|
rh = h |
|
|
|
|
|
rw += 2 # XXX: without this the sash isn't visible!?!?!?! |
|
|
|
|
|
self.sash_legend.SetDefaultSize(wxSize(rw, 1000)) |
|
|
|
|
650 |
# |
# |
651 |
# Define all the commands available in the main window |
# Define all the commands available in the main window |
652 |
# |
# |
707 |
|
|
708 |
def _has_legend_shown(context): |
def _has_legend_shown(context): |
709 |
"""Return true if the legend window is shown""" |
"""Return true if the legend window is shown""" |
710 |
return context.mainwindow.get_open_dialog("legend") is None |
return context.mainwindow.FindRegisteredDock("legend") is None |
711 |
|
|
712 |
|
|
713 |
# File menu |
# File menu |
784 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
785 |
_method_command("layer_classifier", _("Classify"), "Classify", |
_method_command("layer_classifier", _("Classify"), "Classify", |
786 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
787 |
_method_command("show_legend", _("Legend"), "ShowLegend", |
_method_command("show_legend", _("Show Legend"), "ShowLegend", |
788 |
sensitive = _has_legend_shown) |
sensitive = _has_legend_shown) |
789 |
|
|
790 |
# the menu structure |
# the menu structure |