2 |
# Authors: |
# Authors: |
3 |
# Jan-Oliver Wagner <[email protected]> |
# Jan-Oliver Wagner <[email protected]> |
4 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
5 |
|
# Frank Koormann <[email protected]> |
6 |
# |
# |
7 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
8 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
13 |
|
|
14 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
15 |
|
|
16 |
__ThubanVersion__ = "0.2" #"$THUBAN_0_2$" |
__ThubanVersion__ = "0.8" #"$THUBAN_0_2$" |
17 |
#__BuildDate__ = "$Date$" |
#__BuildDate__ = "$Date$" |
18 |
|
|
19 |
import os |
import os |
20 |
|
import copy |
21 |
|
|
22 |
from wxPython.wx import * |
from wxPython.wx import * |
23 |
|
from wxPython.wx import __version__ as wxPython_version |
24 |
|
|
25 |
import Thuban |
import Thuban |
26 |
|
import Thuban.version |
27 |
|
|
28 |
from Thuban import _ |
from Thuban import _ |
29 |
from Thuban.Model.session import create_empty_session |
from Thuban.Model.session import create_empty_session |
30 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer, RasterLayer |
31 |
from Thuban.Model.color import Color |
|
32 |
from Thuban.Model.proj import Projection |
# XXX: replace this by |
33 |
|
# from wxPython.lib.dialogs import wxMultipleChoiceDialog |
34 |
|
# when Thuban does not support wxPython 2.4.0 any more. |
35 |
|
from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog |
36 |
|
|
37 |
import view |
import view |
38 |
import tree |
import tree |
|
import proj4dialog |
|
39 |
import tableview, identifyview |
import tableview, identifyview |
40 |
from Thuban.UI.classifier import Classifier |
from Thuban.UI.classifier import Classifier |
41 |
import legend |
import legend |
43 |
|
|
44 |
from context import Context |
from context import Context |
45 |
from command import registry, Command, ToolCommand |
from command import registry, Command, ToolCommand |
46 |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \ |
47 |
|
MAP_REPLACED |
48 |
|
from about import About |
49 |
|
|
50 |
from Thuban.UI.dock import DockFrame |
from Thuban.UI.dock import DockFrame |
51 |
from Thuban.UI.join import JoinDialog |
from Thuban.UI.join import JoinDialog |
52 |
|
|
53 |
import resource |
import resource |
54 |
|
import Thuban.Model.resource |
55 |
|
|
56 |
import projdialog |
import projdialog |
57 |
|
|
58 |
|
|
|
|
|
59 |
class MainWindow(DockFrame): |
class MainWindow(DockFrame): |
60 |
|
|
61 |
# Some messages that can be subscribed/unsubscribed directly through |
# Some messages that can be subscribed/unsubscribed directly through |
64 |
# actually come from. This delegation is implemented in the |
# actually come from. This delegation is implemented in the |
65 |
# Subscribe and unsubscribed methods |
# Subscribe and unsubscribed methods |
66 |
delegated_messages = {LAYER_SELECTED: "canvas", |
delegated_messages = {LAYER_SELECTED: "canvas", |
67 |
SHAPES_SELECTED: "canvas"} |
SHAPES_SELECTED: "canvas", |
68 |
|
MAP_REPLACED: "canvas"} |
69 |
|
|
70 |
# Methods delegated to some instance variables. The delegation is |
# Methods delegated to some instance variables. The delegation is |
71 |
# implemented in the __getattr__ method. |
# implemented in the __getattr__ method. |
72 |
delegated_methods = {"SelectLayer": "canvas", |
delegated_methods = {"SelectLayer": "canvas", |
73 |
"SelectShapes": "canvas", |
"SelectShapes": "canvas", |
74 |
|
"SelectedLayer": "canvas", |
75 |
"SelectedShapes": "canvas", |
"SelectedShapes": "canvas", |
76 |
} |
} |
77 |
|
|
111 |
|
|
112 |
self.init_dialogs() |
self.init_dialogs() |
113 |
|
|
114 |
EVT_CLOSE(self, self._OnClose) |
self.ShowLegend() |
115 |
|
|
116 |
|
EVT_CLOSE(self, self.OnClose) |
117 |
|
|
118 |
def Subscribe(self, channel, *args): |
def Subscribe(self, channel, *args): |
119 |
"""Subscribe a function to a message channel. |
"""Subscribe a function to a message channel. |
366 |
result = wxID_NO |
result = wxID_NO |
367 |
return result |
return result |
368 |
|
|
|
def prepare_new_session(self): |
|
|
for d in self.dialogs.values(): |
|
|
if not isinstance(d, tree.SessionTreeView): |
|
|
d.Close() |
|
|
|
|
369 |
def NewSession(self): |
def NewSession(self): |
370 |
self.save_modified_session() |
if self.save_modified_session() != wxID_CANCEL: |
371 |
self.prepare_new_session() |
self.application.SetSession(create_empty_session()) |
|
self.application.SetSession(create_empty_session()) |
|
372 |
|
|
373 |
def OpenSession(self): |
def OpenSession(self): |
374 |
self.save_modified_session() |
if self.save_modified_session() != wxID_CANCEL: |
375 |
dlg = wxFileDialog(self, _("Open Session"), ".", "", |
dlg = wxFileDialog(self, _("Open Session"), ".", "", |
376 |
"Thuban Session File (*.thuban)|*.thuban", wxOPEN) |
"Thuban Session File (*.thuban)|*.thuban", |
377 |
if dlg.ShowModal() == wxID_OK: |
wxOPEN) |
378 |
self.prepare_new_session() |
if dlg.ShowModal() == wxID_OK: |
379 |
self.application.OpenSession(dlg.GetPath()) |
self.application.OpenSession(dlg.GetPath()) |
380 |
dlg.Destroy() |
dlg.Destroy() |
381 |
|
|
382 |
def SaveSession(self): |
def SaveSession(self): |
383 |
if self.application.session.filename == None: |
if self.application.session.filename == None: |
397 |
def Exit(self): |
def Exit(self): |
398 |
self.Close(False) |
self.Close(False) |
399 |
|
|
400 |
def _OnClose(self, event): |
def OnClose(self, event): |
401 |
result = self.save_modified_session(can_veto = event.CanVeto()) |
result = self.save_modified_session(can_veto = event.CanVeto()) |
402 |
if result == wxID_CANCEL: |
if result == wxID_CANCEL: |
403 |
event.Veto() |
event.Veto() |
406 |
# wx's destroy event, but that isn't implemented for wxGTK |
# wx's destroy event, but that isn't implemented for wxGTK |
407 |
# yet. |
# yet. |
408 |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
409 |
DockFrame._OnClose(self, event) |
DockFrame.OnClose(self, event) |
410 |
|
for dlg in self.dialogs.values(): |
411 |
|
dlg.Destroy() |
412 |
|
self.canvas.Destroy() |
413 |
self.Destroy() |
self.Destroy() |
414 |
|
|
415 |
def SetMap(self, map): |
def SetMap(self, map): |
441 |
return self.get_open_dialog("session_tree") is not None |
return self.get_open_dialog("session_tree") is not None |
442 |
|
|
443 |
def About(self): |
def About(self): |
444 |
self.RunMessageBox(_("About"), |
dlg = About(self) |
445 |
_("Thuban v%s\n" |
dlg.ShowModal() |
446 |
#"Build Date: %s\n" |
dlg.Destroy() |
|
"\n" |
|
|
"Thuban is a program for\n" |
|
|
"exploring geographic data.\n" |
|
|
"Copyright (C) 2001-2003 Intevation GmbH.\n" |
|
|
"Thuban is licensed under the GNU GPL" |
|
|
% __ThubanVersion__), #__BuildDate__)), |
|
|
wxOK | wxICON_INFORMATION) |
|
447 |
|
|
448 |
def AddLayer(self): |
def AddLayer(self): |
449 |
dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*", |
dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*", |
451 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
452 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
453 |
title = os.path.splitext(os.path.basename(filename))[0] |
title = os.path.splitext(os.path.basename(filename))[0] |
|
store = self.application.Session().OpenShapefile(filename) |
|
|
layer = Layer(title, store) |
|
454 |
map = self.canvas.Map() |
map = self.canvas.Map() |
455 |
has_layers = map.HasLayers() |
has_layers = map.HasLayers() |
456 |
try: |
try: |
457 |
map.AddLayer(layer) |
store = self.application.Session().OpenShapefile(filename) |
458 |
except IOError: |
except IOError: |
459 |
# the layer couldn't be opened |
# the layer couldn't be opened |
460 |
self.RunMessageBox(_("Add Layer"), |
self.RunMessageBox(_("Add Layer"), |
461 |
_("Can't open the file '%s'.") % filename) |
_("Can't open the file '%s'.") % filename) |
462 |
else: |
else: |
463 |
|
layer = Layer(title, store) |
464 |
|
map.AddLayer(layer) |
465 |
|
if not has_layers: |
466 |
|
# if we're adding a layer to an empty map, fit the |
467 |
|
# new map to the window |
468 |
|
self.canvas.FitMapToWindow() |
469 |
|
dlg.Destroy() |
470 |
|
|
471 |
|
def AddRasterLayer(self): |
472 |
|
dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*", |
473 |
|
wxOPEN) |
474 |
|
if dlg.ShowModal() == wxID_OK: |
475 |
|
filename = dlg.GetPath() |
476 |
|
title = os.path.splitext(os.path.basename(filename))[0] |
477 |
|
map = self.canvas.Map() |
478 |
|
has_layers = map.HasLayers() |
479 |
|
try: |
480 |
|
layer = RasterLayer(title, filename) |
481 |
|
except IOError: |
482 |
|
# the layer couldn't be opened |
483 |
|
self.RunMessageBox(_("Add Image Layer"), |
484 |
|
_("Can't open the file '%s'.") % filename) |
485 |
|
else: |
486 |
|
map.AddLayer(layer) |
487 |
if not has_layers: |
if not has_layers: |
488 |
# if we're adding a layer to an empty map, fit the |
# if we're adding a layer to an empty map, fit the |
489 |
# new map to the window |
# new map to the window |
537 |
layer = self.current_layer() |
layer = self.current_layer() |
538 |
if layer is not None: |
if layer is not None: |
539 |
layer.SetVisible(0) |
layer.SetVisible(0) |
540 |
|
|
541 |
def ShowLayer(self): |
def ShowLayer(self): |
542 |
layer = self.current_layer() |
layer = self.current_layer() |
543 |
if layer is not None: |
if layer is not None: |
544 |
layer.SetVisible(1) |
layer.SetVisible(1) |
545 |
|
|
546 |
|
def DuplicateLayer(self): |
547 |
|
"""Ceate a new layer above the selected layer with the same shapestore |
548 |
|
""" |
549 |
|
layer = self.current_layer() |
550 |
|
if layer is not None and hasattr(layer, "ShapeStore"): |
551 |
|
new_layer = Layer(_("Copy of `%s'") % layer.Title(), |
552 |
|
layer.ShapeStore(), |
553 |
|
projection = layer.GetProjection()) |
554 |
|
new_classification = copy.deepcopy(layer.GetClassification()) |
555 |
|
new_layer.SetClassification(new_classification) |
556 |
|
self.Map().AddLayer(new_layer) |
557 |
|
|
558 |
|
def CanDuplicateLayer(self): |
559 |
|
"""Return whether the DuplicateLayer method can create a duplicate""" |
560 |
|
layer = self.current_layer() |
561 |
|
return layer is not None and hasattr(layer, "ShapeStore") |
562 |
|
|
563 |
def LayerShowTable(self): |
def LayerShowTable(self): |
564 |
layer = self.current_layer() |
layer = self.current_layer() |
565 |
if layer is not None: |
if layer is not None: |
566 |
table = layer.table |
table = layer.ShapeStore().Table() |
567 |
name = "table_view" + str(id(table)) |
name = "table_view" + str(id(table)) |
568 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
569 |
if dialog is None: |
if dialog is None: |
570 |
dialog = tableview.LayerTableFrame(self, name, |
dialog = tableview.LayerTableFrame(self, name, |
571 |
_("Table: %s") % layer.Title(), |
_("Layer Table: %s") % layer.Title(), |
572 |
layer, table) |
layer, table) |
573 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
574 |
dialog.Show(true) |
dialog.Show(True) |
575 |
else: |
else: |
576 |
# FIXME: bring dialog to front here |
# FIXME: bring dialog to front here |
577 |
pass |
pass |
620 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
621 |
|
|
622 |
if dialog is None: |
if dialog is None: |
623 |
dialog = Classifier(self, name, layer, group) |
dialog = Classifier(self, name, self.Map(), layer, group) |
624 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
625 |
dialog.Show() |
dialog.Show() |
626 |
dialog.Raise() |
dialog.Raise() |
627 |
|
|
628 |
def LayerJoinTable(self): |
def LayerJoinTable(self): |
629 |
print "LayerJoinTable" |
layer = self.canvas.SelectedLayer() |
630 |
|
if layer is not None: |
631 |
|
dlg = JoinDialog(self, _("Join Layer with Table"), |
632 |
|
self.application.session, |
633 |
|
layer = layer) |
634 |
|
dlg.ShowModal() |
635 |
|
|
636 |
def LayerUnjoinTable(self): |
def LayerUnjoinTable(self): |
637 |
print "LayerUnjoinTable" |
layer = self.canvas.SelectedLayer() |
638 |
|
if layer is not None: |
639 |
|
orig_store = layer.ShapeStore().OrigShapeStore() |
640 |
|
if orig_store: |
641 |
|
layer.SetShapeStore(orig_store) |
642 |
|
|
643 |
def ShowLegend(self): |
def ShowLegend(self): |
644 |
if not self.LegendShown(): |
if not self.LegendShown(): |
664 |
return dialog is not None and dialog.IsShown() |
return dialog is not None and dialog.IsShown() |
665 |
|
|
666 |
def TableOpen(self): |
def TableOpen(self): |
|
print "TableOpen" |
|
667 |
dlg = wxFileDialog(self, _("Open Table"), ".", "", |
dlg = wxFileDialog(self, _("Open Table"), ".", "", |
668 |
"DBF Files (*.dbf)|*.dbf|" + |
_("DBF Files (*.dbf)") + "|*.dbf|" + |
669 |
"CSV Files (*.csv)|*.csv|" + |
#_("CSV Files (*.csv)") + "|*.csv|" + |
670 |
"All Files (*.*)|*.*", |
_("All Files (*.*)") + "|*.*", |
671 |
wxOPEN) |
wxOPEN) |
672 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
673 |
#self.application.session.OpenTable(dlg.GetPath()) |
filename = dlg.GetPath() |
674 |
pass |
dlg.Destroy() |
675 |
|
try: |
676 |
dlg.Destroy() |
table = self.application.session.OpenTableFile(filename) |
677 |
|
except IOError: |
678 |
|
# the layer couldn't be opened |
679 |
|
self.RunMessageBox(_("Open Table"), |
680 |
|
_("Can't open the file '%s'.") % filename) |
681 |
|
else: |
682 |
|
self.ShowTableView(table) |
683 |
|
|
684 |
def TableClose(self): |
def TableClose(self): |
685 |
print "TableClose" |
tables = self.application.session.UnreferencedTables() |
686 |
|
|
687 |
|
lst = [(t.Title(), t) for t in tables] |
688 |
|
lst.sort() |
689 |
|
titles = [i[0] for i in lst] |
690 |
|
dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"), |
691 |
|
_("Close Table"), titles, |
692 |
|
size = (400, 300), |
693 |
|
style = wxDEFAULT_DIALOG_STYLE | |
694 |
|
wxRESIZE_BORDER) |
695 |
|
if dlg.ShowModal() == wxID_OK: |
696 |
|
for i in dlg.GetValue(): |
697 |
|
self.application.session.RemoveTable(lst[i][1]) |
698 |
|
|
699 |
|
|
700 |
def TableShow(self): |
def TableShow(self): |
701 |
print "TableShow" |
"""Offer a multi-selection dialog for tables to be displayed |
702 |
|
|
703 |
|
The windows for the selected tables are opened or brought to |
704 |
|
the front. |
705 |
|
""" |
706 |
|
tables = self.application.session.Tables() |
707 |
|
|
708 |
def TableHide(self): |
lst = [(t.Title(), t) for t in tables] |
709 |
print "TableHide" |
lst.sort() |
710 |
|
titles = [i[0] for i in lst] |
711 |
|
dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"), |
712 |
|
_("Show Table"), titles, |
713 |
|
size = (400,300), |
714 |
|
style = wxDEFAULT_DIALOG_STYLE | |
715 |
|
wxRESIZE_BORDER) |
716 |
|
if (dlg.ShowModal() == wxID_OK): |
717 |
|
for i in dlg.GetValue(): |
718 |
|
# XXX: if the table belongs to a layer, open a |
719 |
|
# LayerTableFrame instead of QueryTableFrame |
720 |
|
self.ShowTableView(lst[i][1]) |
721 |
|
|
722 |
def TableJoin(self): |
def TableJoin(self): |
|
print "TableJoin" |
|
723 |
dlg = JoinDialog(self, _("Join Tables"), self.application.session) |
dlg = JoinDialog(self, _("Join Tables"), self.application.session) |
724 |
if dlg.ShowModal() == wxID_OK: |
dlg.ShowModal() |
725 |
print "OK" |
|
726 |
|
def ShowTableView(self, table): |
727 |
|
"""Open a table view for the table and optionally""" |
728 |
|
name = "table_view%d" % id(table) |
729 |
|
dialog = self.get_open_dialog(name) |
730 |
|
if dialog is None: |
731 |
|
dialog = tableview.QueryTableFrame(self, name, |
732 |
|
_("Table: %s") % table.Title(), |
733 |
|
table) |
734 |
|
self.add_dialog(name, dialog) |
735 |
|
dialog.Show(True) |
736 |
|
dialog.Raise() |
737 |
|
|
738 |
|
def TableRename(self): |
739 |
|
"""Let the user rename a table""" |
740 |
|
|
741 |
|
# First, let the user select a table |
742 |
|
tables = self.application.session.Tables() |
743 |
|
lst = [(t.Title(), t) for t in tables] |
744 |
|
lst.sort() |
745 |
|
titles = [i[0] for i in lst] |
746 |
|
dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"), |
747 |
|
_("Rename Table"), titles, |
748 |
|
size = (400,300), |
749 |
|
style = wxDEFAULT_DIALOG_STYLE | |
750 |
|
wxRESIZE_BORDER) |
751 |
|
if (dlg.ShowModal() == wxID_OK): |
752 |
|
to_rename = [lst[i][1] for i in dlg.GetValue()] |
753 |
|
dlg.Destroy() |
754 |
|
else: |
755 |
|
to_rename = [] |
756 |
|
|
757 |
|
# Second, let the user rename the layers |
758 |
|
for table in to_rename: |
759 |
|
dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table", |
760 |
|
table.Title()) |
761 |
|
try: |
762 |
|
if dlg.ShowModal() == wxID_OK: |
763 |
|
title = dlg.GetValue() |
764 |
|
if title != "": |
765 |
|
table.SetTitle(title) |
766 |
|
|
767 |
|
# Make sure the session is marked as modified. |
768 |
|
# FIXME: This should be handled automatically, |
769 |
|
# but that requires more changes to the tables |
770 |
|
# than I have time for currently. |
771 |
|
self.application.session.changed() |
772 |
|
finally: |
773 |
|
dlg.Destroy() |
774 |
|
|
775 |
|
|
776 |
def ZoomInTool(self): |
def ZoomInTool(self): |
777 |
self.canvas.ZoomInTool() |
self.canvas.ZoomInTool() |
798 |
def FullSelectionExtent(self): |
def FullSelectionExtent(self): |
799 |
self.canvas.FitSelectedToWindow() |
self.canvas.FitSelectedToWindow() |
800 |
|
|
801 |
|
def ExportMap(self): |
802 |
|
self.canvas.Export() |
803 |
|
|
804 |
def PrintMap(self): |
def PrintMap(self): |
805 |
self.canvas.Print() |
self.canvas.Print() |
806 |
|
|
815 |
|
|
816 |
dlg.Destroy() |
dlg.Destroy() |
817 |
|
|
818 |
|
def RenameLayer(self): |
819 |
|
"""Let the user rename the currently selected layer""" |
820 |
|
layer = self.current_layer() |
821 |
|
if layer is not None: |
822 |
|
dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer", |
823 |
|
layer.Title()) |
824 |
|
try: |
825 |
|
if dlg.ShowModal() == wxID_OK: |
826 |
|
title = dlg.GetValue() |
827 |
|
if title != "": |
828 |
|
layer.SetTitle(title) |
829 |
|
finally: |
830 |
|
dlg.Destroy() |
831 |
|
|
832 |
def identify_view_on_demand(self, layer, shapes): |
def identify_view_on_demand(self, layer, shapes): |
833 |
"""Subscribed to the canvas' SHAPES_SELECTED message |
"""Subscribed to the canvas' SHAPES_SELECTED message |
834 |
|
|
922 |
"""Return true if the legend window is shown""" |
"""Return true if the legend window is shown""" |
923 |
return context.mainwindow.LegendShown() |
return context.mainwindow.LegendShown() |
924 |
|
|
925 |
|
def _has_gdal_support(context): |
926 |
|
"""Return True if the GDAL is available""" |
927 |
|
return Thuban.Model.resource.has_gdal_support() |
928 |
|
|
929 |
# File menu |
# File menu |
930 |
_method_command("new_session", _("&New Session"), "NewSession") |
_method_command("new_session", _("&New Session"), "NewSession", |
931 |
_method_command("open_session", _("&Open Session..."), "OpenSession") |
helptext = _("Start a new session")) |
932 |
_method_command("save_session", _("&Save Session"), "SaveSession") |
_method_command("open_session", _("&Open Session..."), "OpenSession", |
933 |
_method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs") |
helptext = _("Open a session file")) |
934 |
|
_method_command("save_session", _("&Save Session"), "SaveSession", |
935 |
|
helptext =_("Save this session to the file it was opened from")) |
936 |
|
_method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs", |
937 |
|
helptext = _("Save this session to a new file")) |
938 |
_method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree", |
_method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree", |
939 |
checked = _has_tree_window_shown) |
checked = _has_tree_window_shown, |
940 |
|
helptext = _("Toggle on/off the session tree analysis window")) |
941 |
_method_command("toggle_legend", _("Legend"), "ToggleLegend", |
_method_command("toggle_legend", _("Legend"), "ToggleLegend", |
942 |
checked = _has_legend_shown) |
checked = _has_legend_shown, |
943 |
_method_command("exit", _("E&xit"), "Exit") |
helptext = _("Toggle Legend on/off")) |
944 |
|
_method_command("exit", _("E&xit"), "Exit", |
945 |
|
helptext = _("Finish working with Thuban")) |
946 |
|
|
947 |
# Help menu |
# Help menu |
948 |
_method_command("help_about", _("&About..."), "About") |
_method_command("help_about", _("&About..."), "About", |
949 |
|
helptext = _("Info about Thuban authors, version and modules")) |
950 |
|
|
951 |
|
|
952 |
# Map menu |
# Map menu |
953 |
_method_command("map_projection", _("Pro&jection..."), "MapProjection") |
_method_command("map_projection", _("Pro&jection..."), "MapProjection", |
954 |
|
helptext = _("Set or change the map projection")) |
955 |
|
|
956 |
_tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool", |
_tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool", |
957 |
helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in", |
helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in", |
970 |
helptext = _("Add/Remove labels"), icon = "label", |
helptext = _("Add/Remove labels"), icon = "label", |
971 |
sensitive = _has_visible_map) |
sensitive = _has_visible_map) |
972 |
_method_command("map_full_extent", _("&Full extent"), "FullExtent", |
_method_command("map_full_extent", _("&Full extent"), "FullExtent", |
973 |
helptext = _("Full Extent"), icon = "fullextent", |
helptext = _("Zoom to the full map extent"), icon = "fullextent", |
974 |
sensitive = _has_visible_map) |
sensitive = _has_visible_map) |
975 |
_method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent", |
_method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent", |
976 |
helptext = _("Full Layer Extent"), icon = "fulllayerextent", |
helptext = _("Zoom to the full layer extent"), |
977 |
sensitive = _has_selected_layer) |
icon = "fulllayerextent", sensitive = _has_selected_layer) |
978 |
_method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent", |
_method_command("selected_full_extent", _("&Full selection extent"), |
979 |
helptext = _("Full Selection Extent"), icon = "fullselextent", |
"FullSelectionExtent", |
980 |
sensitive = _has_selected_shapes) |
helptext = _("Zoom to the full selection extent"), |
981 |
|
icon = "fullselextent", sensitive = _has_selected_shapes) |
982 |
|
_method_command("map_export", _("E&xport"), "ExportMap", |
983 |
|
helptext = _("Export the map to file")) |
984 |
_method_command("map_print", _("Prin&t"), "PrintMap", |
_method_command("map_print", _("Prin&t"), "PrintMap", |
985 |
helptext = _("Print the map")) |
helptext = _("Print the map")) |
986 |
_method_command("map_rename", _("&Rename..."), "RenameMap", |
_method_command("map_rename", _("&Rename..."), "RenameMap", |
987 |
helptext = _("Rename the map")) |
helptext = _("Rename the map")) |
988 |
_method_command("layer_add", _("&Add Layer..."), "AddLayer", |
_method_command("layer_add", _("&Add Layer..."), "AddLayer", |
989 |
helptext = _("Add a new layer to active map")) |
helptext = _("Add a new layer to the map")) |
990 |
|
_method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer", |
991 |
|
helptext = _("Add a new image layer to the map"), |
992 |
|
sensitive = _has_gdal_support) |
993 |
_method_command("layer_remove", _("&Remove Layer"), "RemoveLayer", |
_method_command("layer_remove", _("&Remove Layer"), "RemoveLayer", |
994 |
helptext = _("Remove selected layer(s)"), |
helptext = _("Remove selected layer"), |
995 |
sensitive = _can_remove_layer) |
sensitive = _can_remove_layer) |
996 |
|
|
997 |
# Layer menu |
# Layer menu |
998 |
_method_command("layer_projection", _("Pro&jection..."), "LayerProjection", |
_method_command("layer_projection", _("Pro&jection..."), "LayerProjection", |
999 |
|
sensitive = _has_selected_layer, |
1000 |
|
helptext = _("Specify projection for selected layer")) |
1001 |
|
_method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer", |
1002 |
|
helptext = _("Duplicate selected layer"), |
1003 |
|
sensitive = lambda context: context.mainwindow.CanDuplicateLayer()) |
1004 |
|
_method_command("layer_rename", _("Re&name ..."), "RenameLayer", |
1005 |
|
helptext = _("Rename selected layer"), |
1006 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1007 |
_method_command("layer_raise", _("&Raise"), "RaiseLayer", |
_method_command("layer_raise", _("&Raise"), "RaiseLayer", |
1008 |
helptext = _("Raise selected layer(s)"), |
helptext = _("Raise selected layer"), |
1009 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1010 |
_method_command("layer_lower", _("&Lower"), "LowerLayer", |
_method_command("layer_lower", _("&Lower"), "LowerLayer", |
1011 |
helptext = _("Lower selected layer(s)"), |
helptext = _("Lower selected layer"), |
1012 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1013 |
_method_command("layer_show", _("&Show"), "ShowLayer", |
_method_command("layer_show", _("&Show"), "ShowLayer", |
1014 |
helptext = _("Make selected layer(s) visible"), |
helptext = _("Make selected layer visible"), |
1015 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1016 |
_method_command("layer_hide", _("&Hide"), "HideLayer", |
_method_command("layer_hide", _("&Hide"), "HideLayer", |
1017 |
helptext = _("Make selected layer(s) unvisible"), |
helptext = _("Make selected layer unvisible"), |
1018 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1019 |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
1020 |
helptext = _("Show the selected layer's table"), |
helptext = _("Show the selected layer's table"), |
1021 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1022 |
_method_command("layer_properties", _("&Properties..."), "LayerEditProperties", |
_method_command("layer_properties", _("&Properties..."), "LayerEditProperties", |
1023 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer, |
1024 |
|
helptext = _("Edit the properties of the selected layer")) |
1025 |
_method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable", |
_method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable", |
1026 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer, |
1027 |
|
helptext = _("Join and attach a table to the selected layer")) |
1028 |
|
|
1029 |
|
def _can_unjoin(context): |
1030 |
|
"""Return whether the Layer/Unjoin command can be executed. |
1031 |
|
|
1032 |
|
This is the case if a layer is selected and that layer has a |
1033 |
|
shapestore that has an original shapestore. |
1034 |
|
""" |
1035 |
|
layer = context.mainwindow.SelectedLayer() |
1036 |
|
if layer is None: |
1037 |
|
return 0 |
1038 |
|
getstore = getattr(layer, "ShapeStore", None) |
1039 |
|
if getstore is not None: |
1040 |
|
return getstore().OrigShapeStore() is not None |
1041 |
|
else: |
1042 |
|
return 0 |
1043 |
_method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable", |
_method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable", |
1044 |
sensitive = _has_selected_layer) |
sensitive = _can_unjoin, |
1045 |
|
helptext = _("Undo the last join operation")) |
1046 |
|
|
1047 |
|
|
1048 |
|
def _has_tables(context): |
1049 |
|
return bool(context.session.Tables()) |
1050 |
|
|
1051 |
# Table menu |
# Table menu |
1052 |
_method_command("table_open", _("&Open..."), "TableOpen") |
_method_command("table_open", _("&Open..."), "TableOpen", |
1053 |
_method_command("table_close", _("&Close"), "TableClose") |
helptext = _("Open a DBF-table from a file")) |
1054 |
_method_command("table_show", _("&Show"), "TableShow") |
_method_command("table_close", _("&Close..."), "TableClose", |
1055 |
_method_command("table_hide", _("&Hide"), "TableHide") |
sensitive = lambda context: bool(context.session.UnreferencedTables()), |
1056 |
_method_command("table_join", _("&Join..."), "TableJoin") |
helptext = _("Close one or more tables from a list")) |
1057 |
|
_method_command("table_rename", _("&Rename..."), "TableRename", |
1058 |
|
sensitive = _has_tables, |
1059 |
|
helptext = _("Rename one or more tables")) |
1060 |
|
_method_command("table_show", _("&Show..."), "TableShow", |
1061 |
|
sensitive = _has_tables, |
1062 |
|
helptext = _("Show one or more tables in a dialog")) |
1063 |
|
_method_command("table_join", _("&Join..."), "TableJoin", |
1064 |
|
sensitive = _has_tables, |
1065 |
|
helptext = _("Join two tables creating a new one")) |
1066 |
|
|
1067 |
# the menu structure |
# Export only under Windows ... |
1068 |
main_menu = Menu("<main>", "<main>", |
map_menu = ["layer_add", "rasterlayer_add", "layer_remove", |
|
[Menu("file", _("&File"), |
|
|
["new_session", "open_session", None, |
|
|
"save_session", "save_session_as", None, |
|
|
"toggle_session_tree", None, |
|
|
"exit"]), |
|
|
Menu("map", _("&Map"), |
|
|
["layer_add", "layer_remove", "map_rename", |
|
1069 |
None, |
None, |
1070 |
|
"map_rename", |
1071 |
"map_projection", |
"map_projection", |
1072 |
None, |
None, |
1073 |
"map_zoom_in_tool", "map_zoom_out_tool", |
"map_zoom_in_tool", "map_zoom_out_tool", |
1079 |
"map_identify_tool", "map_label_tool", |
"map_identify_tool", "map_label_tool", |
1080 |
None, |
None, |
1081 |
"toggle_legend", |
"toggle_legend", |
1082 |
None, |
None] |
1083 |
"map_print"]), |
if wxPlatform == '__WXMSW__': |
1084 |
|
map_menu.append("map_export") |
1085 |
|
map_menu.append("map_print") |
1086 |
|
|
1087 |
|
# the menu structure |
1088 |
|
main_menu = Menu("<main>", "<main>", |
1089 |
|
[Menu("file", _("&File"), |
1090 |
|
["new_session", "open_session", None, |
1091 |
|
"save_session", "save_session_as", None, |
1092 |
|
"toggle_session_tree", None, |
1093 |
|
"exit"]), |
1094 |
|
Menu("map", _("&Map"), map_menu), |
1095 |
Menu("layer", _("&Layer"), |
Menu("layer", _("&Layer"), |
1096 |
["layer_raise", "layer_lower", |
["layer_rename", "layer_duplicate", |
1097 |
|
None, |
1098 |
|
"layer_raise", "layer_lower", |
1099 |
None, |
None, |
1100 |
"layer_show", "layer_hide", |
"layer_show", "layer_hide", |
1101 |
None, |
None, |
1107 |
None, |
None, |
1108 |
"layer_properties"]), |
"layer_properties"]), |
1109 |
Menu("table", _("&Table"), |
Menu("table", _("&Table"), |
1110 |
["table_open", "table_close", |
["table_open", "table_close", "table_rename", |
1111 |
None, |
None, |
1112 |
"table_show", "table_hide", |
"table_show", |
1113 |
None, |
None, |
1114 |
"table_join"]), |
"table_join"]), |
1115 |
Menu("help", _("&Help"), |
Menu("help", _("&Help"), |
1124 |
"selected_full_extent", |
"selected_full_extent", |
1125 |
None, |
None, |
1126 |
"map_identify_tool", "map_label_tool"]) |
"map_identify_tool", "map_label_tool"]) |
1127 |
|
|