31 |
import proj4dialog |
import proj4dialog |
32 |
import tableview, identifyview |
import tableview, identifyview |
33 |
import classifier |
import classifier |
34 |
|
import legend |
35 |
from menu import Menu |
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, DockFrame, DockPanel |
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(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 |
|
|
91 |
|
|
92 |
# Create the map canvas |
# Create the map canvas |
93 |
canvas = view.MapCanvas(self, -1) |
canvas = view.MapCanvas(self, -1) |
94 |
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
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) |
101 |
|
|
102 |
self.init_dialogs() |
self.init_dialogs() |
103 |
|
|
104 |
EVT_CLOSE(self, self.OnClose) |
EVT_CLOSE(self, self._OnClose) |
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. |
387 |
dlg.Destroy() |
dlg.Destroy() |
388 |
|
|
389 |
def Exit(self): |
def Exit(self): |
390 |
self.Close(false) |
self.Close(False) |
391 |
|
|
392 |
def OnClose(self, event): |
def _OnClose(self, event): |
393 |
result = self.save_modified_session(can_veto = event.CanVeto()) |
result = self.save_modified_session(can_veto = event.CanVeto()) |
394 |
if result == wxID_CANCEL: |
if result == wxID_CANCEL: |
395 |
event.Veto() |
event.Veto() |
398 |
# wx's destroy event, but that isn't implemented for wxGTK |
# wx's destroy event, but that isn't implemented for wxGTK |
399 |
# yet. |
# yet. |
400 |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
401 |
|
DockFrame._OnClose(self, event) |
402 |
self.Destroy() |
self.Destroy() |
403 |
|
|
404 |
def SetMap(self, map): |
def SetMap(self, map): |
405 |
self.canvas.SetMap(map) |
self.canvas.SetMap(map) |
406 |
|
#self.legendPanel.SetMap(map) |
407 |
|
|
408 |
def Map(self): |
def Map(self): |
409 |
"""Return the map displayed by this mainwindow""" |
"""Return the map displayed by this mainwindow""" |
410 |
|
|
411 |
|
# sanity check |
412 |
|
#assert(self.canvas.Map() is self.legendPanel.GetMap()) |
413 |
|
|
414 |
return self.canvas.Map() |
return self.canvas.Map() |
415 |
|
|
416 |
def ShowSessionTree(self): |
def ShowSessionTree(self): |
467 |
def CanRemoveLayer(self): |
def CanRemoveLayer(self): |
468 |
"""Return true if the currently selected layer can be deleted. |
"""Return true if the currently selected layer can be deleted. |
469 |
|
|
470 |
If no layer is selected return false. |
If no layer is selected return False. |
471 |
|
|
472 |
The return value of this method determines whether the remove |
The return value of this method determines whether the remove |
473 |
layer command is sensitive in menu. |
layer command is sensitive in menu. |
475 |
layer = self.current_layer() |
layer = self.current_layer() |
476 |
if layer is not None: |
if layer is not None: |
477 |
return self.canvas.Map().CanRemoveLayer(layer) |
return self.canvas.Map().CanRemoveLayer(layer) |
478 |
return 0 |
return False |
479 |
|
|
480 |
def RaiseLayer(self): |
def RaiseLayer(self): |
481 |
layer = self.current_layer() |
layer = self.current_layer() |
524 |
def LayerTransparentFill(self): |
def LayerTransparentFill(self): |
525 |
layer = self.current_layer() |
layer = self.current_layer() |
526 |
if layer is not None: |
if layer is not None: |
527 |
layer.GetClassification().SetDefaultFill(Color.None) |
layer.GetClassification().SetDefaultFill(Color.Transparent) |
528 |
|
|
529 |
def LayerOutlineColor(self): |
def LayerOutlineColor(self): |
530 |
layer = self.current_layer() |
layer = self.current_layer() |
536 |
def LayerNoOutline(self): |
def LayerNoOutline(self): |
537 |
layer = self.current_layer() |
layer = self.current_layer() |
538 |
if layer is not None: |
if layer is not None: |
539 |
layer.GetClassification().SetDefaultLineColor(Color.None) |
layer.GetClassification().SetDefaultLineColor(Color.Transparent) |
540 |
|
|
541 |
def HideLayer(self): |
def HideLayer(self): |
542 |
layer = self.current_layer() |
layer = self.current_layer() |
590 |
# |
# |
591 |
|
|
592 |
layer = self.current_layer() |
layer = self.current_layer() |
593 |
|
self.OpenClassifier(layer) |
594 |
|
|
595 |
|
def OpenClassifier(self, layer, group = None): |
596 |
name = "classifier" + str(id(layer)) |
name = "classifier" + str(id(layer)) |
597 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
598 |
|
|
599 |
if dialog is None: |
if dialog is None: |
600 |
dialog = classifier.Classifier(self, name, self.current_layer()) |
dialog = classifier.Classifier(self, name, layer, group) |
601 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
602 |
dialog.Show() |
dialog.Show() |
603 |
|
dialog.Raise() |
604 |
|
|
605 |
|
|
606 |
|
def ShowLegend(self): |
607 |
|
name = "legend" |
608 |
|
dialog = self.FindRegisteredDock(name) |
609 |
|
|
610 |
|
if dialog is None: |
611 |
|
title = "Legend: %s" % self.Map().Title() |
612 |
|
dialog = self.CreateDock(name, -1, title, wxLAYOUT_LEFT) |
613 |
|
legend.LegendPanel(dialog, None, self) |
614 |
|
dialog.Dock() |
615 |
|
|
616 |
|
dialog.GetPanel().SetMap(self.Map()) |
617 |
|
dialog.Show() |
618 |
|
|
619 |
def ZoomInTool(self): |
def ZoomInTool(self): |
620 |
self.canvas.ZoomInTool() |
self.canvas.ZoomInTool() |
644 |
if not self.dialog_open(name): |
if not self.dialog_open(name): |
645 |
dialog = identifyview.IdentifyView(self, name) |
dialog = identifyview.IdentifyView(self, name) |
646 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
647 |
dialog.Show(true) |
dialog.Show(True) |
648 |
else: |
else: |
649 |
# FIXME: bring dialog to front? |
# FIXME: bring dialog to front? |
650 |
pass |
pass |
707 |
return 1 |
return 1 |
708 |
return 0 |
return 0 |
709 |
|
|
710 |
|
def _has_legend_shown(context): |
711 |
|
"""Return true if the legend window is shown""" |
712 |
|
return context.mainwindow.FindRegisteredDock("legend") is None |
713 |
|
|
714 |
|
|
715 |
# File menu |
# File menu |
716 |
_method_command("new_session", _("&New Session"), "NewSession") |
_method_command("new_session", _("&New Session"), "NewSession") |
717 |
_method_command("open_session", _("&Open Session"), "OpenSession") |
_method_command("open_session", _("&Open Session"), "OpenSession") |
718 |
_method_command("save_session", _("&Save Session"), "SaveSession") |
_method_command("save_session", _("&Save Session"), "SaveSession") |
719 |
_method_command("save_session_as", _("Save Session &As"), "SaveSessionAs") |
_method_command("save_session_as", _("Save Session &As"), "SaveSessionAs") |
720 |
_method_command("show_session_tree", _("Show Session &Tree"), "ShowSessionTree", |
_method_command("show_session_tree", _("Session &Tree"), "ShowSessionTree", |
721 |
sensitive = _has_tree_window_shown) |
sensitive = _has_tree_window_shown) |
722 |
|
_method_command("show_legend", _("Legend"), "ShowLegend", |
723 |
|
sensitive = _has_legend_shown) |
724 |
_method_command("exit", _("E&xit"), "Exit") |
_method_command("exit", _("E&xit"), "Exit") |
725 |
|
|
726 |
# Help menu |
# Help menu |
786 |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
787 |
helptext = _("Show the selected layer's table"), |
helptext = _("Show the selected layer's table"), |
788 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
|
|
|
789 |
_method_command("layer_classifier", _("Classify"), "Classify", |
_method_command("layer_classifier", _("Classify"), "Classify", |
790 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
791 |
|
|
794 |
[Menu("file", _("&File"), |
[Menu("file", _("&File"), |
795 |
["new_session", "open_session", None, |
["new_session", "open_session", None, |
796 |
"save_session", "save_session_as", None, |
"save_session", "save_session_as", None, |
797 |
"show_session_tree", None, |
"show_session_tree", |
798 |
|
"show_legend", None, |
799 |
"exit"]), |
"exit"]), |
800 |
Menu("map", _("&Map"), |
Menu("map", _("&Map"), |
801 |
["layer_add", "layer_remove", |
["layer_add", "layer_remove", |