1 |
# Copyright (C) 2001, 2002, 2003 by Intevation GmbH |
# Copyright (C) 2001, 2002, 2003, 2004 by Intevation GmbH |
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. |
12 |
""" |
""" |
13 |
|
|
14 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
15 |
|
# $Source$ |
16 |
__ThubanVersion__ = "0.2" #"$THUBAN_0_2$" |
# $Id$ |
|
#__BuildDate__ = "$Date$" |
|
17 |
|
|
18 |
import os |
import os |
19 |
|
import copy |
20 |
|
|
21 |
from wxPython.wx import * |
from wxPython.wx import * |
22 |
|
|
23 |
import Thuban |
import Thuban |
24 |
|
|
25 |
from Thuban import _ |
from Thuban import _ |
26 |
|
from Thuban.Model.messages import TITLE_CHANGED |
27 |
from Thuban.Model.session import create_empty_session |
from Thuban.Model.session import create_empty_session |
28 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer, RasterLayer |
29 |
from Thuban.Model.color import Color |
from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support |
30 |
from Thuban.Model.proj import Projection |
# XXX: replace this by |
31 |
|
# from wxPython.lib.dialogs import wxMultipleChoiceDialog |
32 |
|
# when Thuban does not support wxPython 2.4.0 any more. |
33 |
|
from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog |
34 |
|
|
35 |
import view |
import view |
36 |
import tree |
import tree |
|
import proj4dialog |
|
37 |
import tableview, identifyview |
import tableview, identifyview |
|
import classifier |
|
38 |
import legend |
import legend |
39 |
from menu import Menu |
from menu import Menu |
40 |
|
|
41 |
from context import Context |
from context import Context |
42 |
from command import registry, Command, ToolCommand |
from command import registry, Command, ToolCommand |
43 |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \ |
44 |
|
MAP_REPLACED |
45 |
|
from about import About |
46 |
|
|
47 |
|
from Thuban.UI.dock import DockFrame |
48 |
|
from Thuban.UI.join import JoinDialog |
49 |
|
from Thuban.UI.dbdialog import DBFrame, DBDialog, ChooseDBTableDialog |
50 |
|
import resource |
51 |
|
import Thuban.Model.resource |
52 |
|
|
53 |
|
import projdialog |
54 |
|
|
55 |
# the directory where the toolbar icons are stored |
from Thuban.Lib.classmapper import ClassMapper |
|
bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps") |
|
|
bitmapext = ".xpm" |
|
56 |
|
|
57 |
|
layer_properties_dialogs = ClassMapper() |
58 |
|
|
59 |
class MainWindow(wxFrame): |
class MainWindow(DockFrame): |
60 |
|
|
61 |
# Some messages that can be subscribed/unsubscribed directly through |
# Some messages that can be subscribed/unsubscribed directly through |
62 |
# 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 |
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", |
76 |
} |
} |
77 |
|
|
78 |
def __init__(self, parent, ID, title, application, interactor, |
def __init__(self, parent, ID, title, application, interactor, |
79 |
initial_message = None, size = wxSize(-1, -1)): |
initial_message = None, size = wxSize(-1, -1)): |
80 |
wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
81 |
|
#wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
82 |
|
|
83 |
self.application = application |
self.application = application |
84 |
|
|
98 |
# call Realize to make sure that the tools appear. |
# call Realize to make sure that the tools appear. |
99 |
toolbar.Realize() |
toolbar.Realize() |
100 |
|
|
101 |
|
|
102 |
# Create the map canvas |
# Create the map canvas |
103 |
canvas = view.MapCanvas(self, -1) |
canvas = view.MapCanvas(self, -1) |
104 |
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
105 |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
106 |
self.canvas = canvas |
self.canvas = canvas |
107 |
|
self.canvas.Subscribe(TITLE_CHANGED, self.title_changed) |
108 |
|
|
109 |
|
self.SetMainWindow(self.canvas) |
110 |
|
|
111 |
|
self.SetAutoLayout(True) |
112 |
|
|
113 |
self.init_dialogs() |
self.init_dialogs() |
114 |
|
|
115 |
|
self.ShowLegend() |
116 |
|
|
117 |
EVT_CLOSE(self, self.OnClose) |
EVT_CLOSE(self, self.OnClose) |
118 |
|
|
119 |
def Subscribe(self, channel, *args): |
def Subscribe(self, channel, *args): |
136 |
""" |
""" |
137 |
if channel in self.delegated_messages: |
if channel in self.delegated_messages: |
138 |
object = getattr(self, self.delegated_messages[channel]) |
object = getattr(self, self.delegated_messages[channel]) |
139 |
object.Unsubscribe(channel, *args) |
try: |
140 |
|
object.Unsubscribe(channel, *args) |
141 |
|
except wxPyDeadObjectError: |
142 |
|
# The object was a wxObject and has already been |
143 |
|
# destroyed. Hopefully it has unsubscribed all its |
144 |
|
# subscribers already so that it's OK if we do nothing |
145 |
|
# here |
146 |
|
pass |
147 |
|
|
148 |
def __getattr__(self, attr): |
def __getattr__(self, attr): |
149 |
"""If attr is one of the delegated methods return that method |
"""If attr is one of the delegated methods return that method |
263 |
command = registry.Command(name) |
command = registry.Command(name) |
264 |
if command is not None: |
if command is not None: |
265 |
ID = self.get_id(name) |
ID = self.get_id(name) |
266 |
filename = os.path.join(bitmapdir, command.Icon()) + bitmapext |
bitmap = resource.GetBitmapResource(command.Icon(), |
267 |
bitmap = wxBitmap(filename, wxBITMAP_TYPE_XPM) |
wxBITMAP_TYPE_XPM) |
268 |
toolbar.AddTool(ID, bitmap, |
toolbar.AddTool(ID, bitmap, |
269 |
shortHelpString = command.HelpText(), |
shortHelpString = command.HelpText(), |
270 |
isToggle = command.IsCheckCommand()) |
isToggle = command.IsCheckCommand()) |
351 |
""" |
""" |
352 |
self.SetStatusText(text) |
self.SetStatusText(text) |
353 |
|
|
354 |
|
def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw): |
355 |
|
""" |
356 |
|
Open or raise a dialog. |
357 |
|
|
358 |
|
If a dialog with the denoted name does already exist it is |
359 |
|
raised. Otherwise a new dialog, an instance of dialog_class, |
360 |
|
is created, inserted into the main list and displayed. |
361 |
|
""" |
362 |
|
dialog = self.get_open_dialog(name) |
363 |
|
|
364 |
|
if dialog is None: |
365 |
|
dialog = dialog_class(self, name, *args, **kw) |
366 |
|
self.add_dialog(name, dialog) |
367 |
|
dialog.Show(True) |
368 |
|
else: |
369 |
|
dialog.Raise() |
370 |
|
|
371 |
def save_modified_session(self, can_veto = 1): |
def save_modified_session(self, can_veto = 1): |
372 |
"""If the current session has been modified, ask the user |
"""If the current session has been modified, ask the user |
373 |
whether to save it and do so if requested. Return the outcome of |
whether to save it and do so if requested. Return the outcome of |
391 |
result = wxID_NO |
result = wxID_NO |
392 |
return result |
return result |
393 |
|
|
|
def prepare_new_session(self): |
|
|
for d in self.dialogs.values(): |
|
|
if not isinstance(d, tree.SessionTreeView): |
|
|
d.Close() |
|
|
|
|
394 |
def NewSession(self): |
def NewSession(self): |
395 |
self.save_modified_session() |
if self.save_modified_session() != wxID_CANCEL: |
396 |
self.prepare_new_session() |
self.application.SetSession(create_empty_session()) |
|
self.application.SetSession(create_empty_session()) |
|
397 |
|
|
398 |
def OpenSession(self): |
def OpenSession(self): |
399 |
self.save_modified_session() |
if self.save_modified_session() != wxID_CANCEL: |
400 |
dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN) |
dlg = wxFileDialog(self, _("Open Session"), |
401 |
if dlg.ShowModal() == wxID_OK: |
self.application.Path("data"), "", |
402 |
self.prepare_new_session() |
"Thuban Session File (*.thuban)|*.thuban", |
403 |
self.application.OpenSession(dlg.GetPath()) |
wxOPEN) |
404 |
dlg.Destroy() |
if dlg.ShowModal() == wxID_OK: |
405 |
|
self.application.OpenSession(dlg.GetPath(), |
406 |
|
self.run_db_param_dialog) |
407 |
|
self.application.SetPath("data", dlg.GetPath()) |
408 |
|
dlg.Destroy() |
409 |
|
|
410 |
|
def run_db_param_dialog(self, parameters, message): |
411 |
|
dlg = DBDialog(self, _("DB Connection Parameters"), parameters, |
412 |
|
message) |
413 |
|
return dlg.RunDialog() |
414 |
|
|
415 |
def SaveSession(self): |
def SaveSession(self): |
416 |
if self.application.session.filename == None: |
if self.application.session.filename == None: |
419 |
self.application.SaveSession() |
self.application.SaveSession() |
420 |
|
|
421 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
422 |
dlg = wxFileDialog(self, _("Save Session As"), ".", "", |
dlg = wxFileDialog(self, _("Save Session As"), |
423 |
"*.thuban", wxOPEN) |
self.application.Path("data"), "", |
424 |
|
"Thuban Session File (*.thuban)|*.thuban", |
425 |
|
wxSAVE|wxOVERWRITE_PROMPT) |
426 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
427 |
self.application.session.SetFilename(dlg.GetPath()) |
self.application.session.SetFilename(dlg.GetPath()) |
428 |
self.application.SaveSession() |
self.application.SaveSession() |
429 |
|
self.application.SetPath("data",dlg.GetPath()) |
430 |
dlg.Destroy() |
dlg.Destroy() |
431 |
|
|
432 |
def Exit(self): |
def Exit(self): |
433 |
self.Close(false) |
self.Close(False) |
434 |
|
|
435 |
def OnClose(self, event): |
def OnClose(self, event): |
436 |
result = self.save_modified_session(can_veto = event.CanVeto()) |
result = self.save_modified_session(can_veto = event.CanVeto()) |
441 |
# wx's destroy event, but that isn't implemented for wxGTK |
# wx's destroy event, but that isn't implemented for wxGTK |
442 |
# yet. |
# yet. |
443 |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
444 |
|
DockFrame.OnClose(self, event) |
445 |
|
for dlg in self.dialogs.values(): |
446 |
|
dlg.Destroy() |
447 |
|
self.canvas.Destroy() |
448 |
self.Destroy() |
self.Destroy() |
449 |
|
|
450 |
def SetMap(self, map): |
def SetMap(self, map): |
451 |
self.canvas.SetMap(map) |
self.canvas.SetMap(map) |
452 |
|
self.update_title() |
453 |
|
|
454 |
|
dialog = self.FindRegisteredDock("legend") |
455 |
|
if dialog is not None: |
456 |
|
dialog.GetPanel().SetMap(self.Map()) |
457 |
|
|
458 |
def Map(self): |
def Map(self): |
459 |
"""Return the map displayed by this mainwindow""" |
"""Return the map displayed by this mainwindow""" |
460 |
|
|
461 |
return self.canvas.Map() |
return self.canvas.Map() |
462 |
|
|
463 |
def ShowSessionTree(self): |
def ToggleSessionTree(self): |
464 |
|
"""If the session tree is shown close it otherwise create a new tree""" |
465 |
name = "session_tree" |
name = "session_tree" |
466 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
467 |
if dialog is None: |
if dialog is None: |
469 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
470 |
dialog.Show(True) |
dialog.Show(True) |
471 |
else: |
else: |
472 |
# FIXME: bring dialog to front here |
dialog.Close() |
|
pass |
|
473 |
|
|
474 |
|
def SessionTreeShown(self): |
475 |
|
"""Return true iff the session tree is currently shown""" |
476 |
|
return self.get_open_dialog("session_tree") is not None |
477 |
|
|
478 |
def About(self): |
def About(self): |
479 |
self.RunMessageBox(_("About"), |
dlg = About(self) |
480 |
_("Thuban v%s\n" |
dlg.ShowModal() |
481 |
#"Build Date: %s\n" |
dlg.Destroy() |
482 |
"\n" |
|
483 |
"Thuban is a program for\n" |
def DatabaseManagement(self): |
484 |
"exploring geographic data.\n" |
name = "dbmanagement" |
485 |
"Copyright (C) 2001-2003 Intevation GmbH.\n" |
dialog = self.get_open_dialog(name) |
486 |
"Thuban is licensed under the GNU GPL" |
if dialog is None: |
487 |
% __ThubanVersion__), #__BuildDate__)), |
map = self.canvas.Map() |
488 |
wxOK | wxICON_INFORMATION) |
dialog = DBFrame(self, name, self.application.Session()) |
489 |
|
self.add_dialog(name, dialog) |
490 |
|
dialog.Show() |
491 |
|
dialog.Raise() |
492 |
|
|
493 |
def AddLayer(self): |
def AddLayer(self): |
494 |
dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*", |
dlg = wxFileDialog(self, _("Select one or more data files"), |
495 |
|
self.application.Path("data"), "", |
496 |
|
_("Shapefiles (*.shp)") + "|*.shp;*.SHP|" + |
497 |
|
_("All Files (*.*)") + "|*.*", |
498 |
|
wxOPEN | wxMULTIPLE) |
499 |
|
if dlg.ShowModal() == wxID_OK: |
500 |
|
filenames = dlg.GetPaths() |
501 |
|
for filename in filenames: |
502 |
|
title = os.path.splitext(os.path.basename(filename))[0] |
503 |
|
map = self.canvas.Map() |
504 |
|
has_layers = map.HasLayers() |
505 |
|
try: |
506 |
|
store = self.application.Session().OpenShapefile(filename) |
507 |
|
except IOError: |
508 |
|
# the layer couldn't be opened |
509 |
|
self.RunMessageBox(_("Add Layer"), |
510 |
|
_("Can't open the file '%s'.")%filename) |
511 |
|
else: |
512 |
|
layer = Layer(title, store) |
513 |
|
map.AddLayer(layer) |
514 |
|
if not has_layers: |
515 |
|
# if we're adding a layer to an empty map, fit the |
516 |
|
# new map to the window |
517 |
|
self.canvas.FitMapToWindow() |
518 |
|
self.application.SetPath("data",filename) |
519 |
|
dlg.Destroy() |
520 |
|
|
521 |
|
def AddRasterLayer(self): |
522 |
|
dlg = wxFileDialog(self, _("Select an image file"), |
523 |
|
self.application.Path("data"), "", "*.*", |
524 |
wxOPEN) |
wxOPEN) |
525 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
526 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
527 |
title = os.path.splitext(os.path.basename(filename))[0] |
title = os.path.splitext(os.path.basename(filename))[0] |
|
layer = Layer(title, filename) |
|
528 |
map = self.canvas.Map() |
map = self.canvas.Map() |
529 |
has_layers = map.HasLayers() |
has_layers = map.HasLayers() |
530 |
try: |
try: |
531 |
map.AddLayer(layer) |
layer = RasterLayer(title, filename) |
532 |
except IOError: |
except IOError: |
533 |
# the layer couldn't be opened |
# the layer couldn't be opened |
534 |
self.RunMessageBox(_("Add Layer"), |
self.RunMessageBox(_("Add Image Layer"), |
535 |
_("Can't open the file '%s'.") % filename) |
_("Can't open the file '%s'.") % filename) |
536 |
else: |
else: |
537 |
|
map.AddLayer(layer) |
538 |
if not has_layers: |
if not has_layers: |
539 |
# if we're adding a layer to an empty map, fit the |
# if we're adding a layer to an empty map, fit the |
540 |
# new map to the window |
# new map to the window |
541 |
self.canvas.FitMapToWindow() |
self.canvas.FitMapToWindow() |
542 |
|
self.application.SetPath("data", filename) |
543 |
|
dlg.Destroy() |
544 |
|
|
545 |
|
def AddDBLayer(self): |
546 |
|
"""Add a layer read from a database""" |
547 |
|
session = self.application.Session() |
548 |
|
dlg = ChooseDBTableDialog(self, self.application.Session()) |
549 |
|
|
550 |
|
if dlg.ShowModal() == wxID_OK: |
551 |
|
dbconn, dbtable, id_column, geo_column = dlg.GetTable() |
552 |
|
try: |
553 |
|
title = str(dbtable) |
554 |
|
|
555 |
|
# Chose the correct Interface for the database type |
556 |
|
store = session.OpenDBShapeStore(dbconn, dbtable, |
557 |
|
id_column = id_column, |
558 |
|
geometry_column = geo_column) |
559 |
|
layer = Layer(title, store) |
560 |
|
except: |
561 |
|
# Some error occured while initializing the layer |
562 |
|
self.RunMessageBox(_("Add Layer from database"), |
563 |
|
_("Can't open the database table '%s'") |
564 |
|
% dbtable) |
565 |
|
return |
566 |
|
|
567 |
|
map = self.canvas.Map() |
568 |
|
|
569 |
|
has_layers = map.HasLayers() |
570 |
|
map.AddLayer(layer) |
571 |
|
if not has_layers: |
572 |
|
self.canvas.FitMapToWindow() |
573 |
|
|
574 |
dlg.Destroy() |
dlg.Destroy() |
575 |
|
|
576 |
def RemoveLayer(self): |
def RemoveLayer(self): |
581 |
def CanRemoveLayer(self): |
def CanRemoveLayer(self): |
582 |
"""Return true if the currently selected layer can be deleted. |
"""Return true if the currently selected layer can be deleted. |
583 |
|
|
584 |
If no layer is selected return false. |
If no layer is selected return False. |
585 |
|
|
586 |
The return value of this method determines whether the remove |
The return value of this method determines whether the remove |
587 |
layer command is sensitive in menu. |
layer command is sensitive in menu. |
589 |
layer = self.current_layer() |
layer = self.current_layer() |
590 |
if layer is not None: |
if layer is not None: |
591 |
return self.canvas.Map().CanRemoveLayer(layer) |
return self.canvas.Map().CanRemoveLayer(layer) |
592 |
return 0 |
return False |
593 |
|
|
594 |
|
def LayerToTop(self): |
595 |
|
layer = self.current_layer() |
596 |
|
if layer is not None: |
597 |
|
self.canvas.Map().MoveLayerToTop(layer) |
598 |
|
|
599 |
def RaiseLayer(self): |
def RaiseLayer(self): |
600 |
layer = self.current_layer() |
layer = self.current_layer() |
606 |
if layer is not None: |
if layer is not None: |
607 |
self.canvas.Map().LowerLayer(layer) |
self.canvas.Map().LowerLayer(layer) |
608 |
|
|
609 |
|
def LayerToBottom(self): |
610 |
|
layer = self.current_layer() |
611 |
|
if layer is not None: |
612 |
|
self.canvas.Map().MoveLayerToBottom(layer) |
613 |
|
|
614 |
def current_layer(self): |
def current_layer(self): |
615 |
"""Return the currently selected layer. |
"""Return the currently selected layer. |
616 |
|
|
622 |
"""Return true if a layer is currently selected""" |
"""Return true if a layer is currently selected""" |
623 |
return self.canvas.HasSelectedLayer() |
return self.canvas.HasSelectedLayer() |
624 |
|
|
625 |
def choose_color(self): |
def has_selected_shape_layer(self): |
626 |
"""Run the color selection dialog and return the selected color. |
"""Return true if a shape layer is currently selected""" |
627 |
|
return isinstance(self.current_layer(), Layer) |
628 |
If the user cancels, return None. |
|
629 |
""" |
def has_selected_shapes(self): |
630 |
dlg = wxColourDialog(self) |
"""Return true if a shape is currently selected""" |
631 |
color = None |
return self.canvas.HasSelectedShapes() |
|
if dlg.ShowModal() == wxID_OK: |
|
|
data = dlg.GetColourData() |
|
|
wxc = data.GetColour() |
|
|
color = Color(wxc.Red() / 255.0, |
|
|
wxc.Green() / 255.0, |
|
|
wxc.Blue() / 255.0) |
|
|
dlg.Destroy() |
|
|
return color |
|
632 |
|
|
633 |
def LayerFillColor(self): |
def HideLayer(self): |
634 |
layer = self.current_layer() |
layer = self.current_layer() |
635 |
if layer is not None: |
if layer is not None: |
636 |
color = self.choose_color() |
layer.SetVisible(False) |
|
if color is not None: |
|
|
layer.GetClassification().SetDefaultFill(color) |
|
637 |
|
|
638 |
def LayerTransparentFill(self): |
def ShowLayer(self): |
639 |
layer = self.current_layer() |
layer = self.current_layer() |
640 |
if layer is not None: |
if layer is not None: |
641 |
layer.GetClassification().SetDefaultFill(Color.None) |
layer.SetVisible(True) |
642 |
|
|
643 |
def LayerOutlineColor(self): |
def ToggleLayerVisibility(self): |
644 |
layer = self.current_layer() |
layer = self.current_layer() |
645 |
if layer is not None: |
layer.SetVisible(not layer.Visible()) |
|
color = self.choose_color() |
|
|
if color is not None: |
|
|
layer.GetClassification().SetDefaultLineColor(color) |
|
646 |
|
|
647 |
def LayerNoOutline(self): |
def DuplicateLayer(self): |
648 |
|
"""Ceate a new layer above the selected layer with the same shapestore |
649 |
|
""" |
650 |
layer = self.current_layer() |
layer = self.current_layer() |
651 |
if layer is not None: |
if layer is not None and hasattr(layer, "ShapeStore"): |
652 |
layer.GetClassification().SetDefaultLineColor(Color.None) |
new_layer = Layer(_("Copy of `%s'") % layer.Title(), |
653 |
|
layer.ShapeStore(), |
654 |
|
projection = layer.GetProjection()) |
655 |
|
new_classification = copy.deepcopy(layer.GetClassification()) |
656 |
|
new_layer.SetClassificationColumn( |
657 |
|
layer.GetClassificationColumn()) |
658 |
|
new_layer.SetClassification(new_classification) |
659 |
|
self.Map().AddLayer(new_layer) |
660 |
|
|
661 |
def HideLayer(self): |
def CanDuplicateLayer(self): |
662 |
|
"""Return whether the DuplicateLayer method can create a duplicate""" |
663 |
layer = self.current_layer() |
layer = self.current_layer() |
664 |
if layer is not None: |
return layer is not None and hasattr(layer, "ShapeStore") |
|
layer.SetVisible(0) |
|
|
|
|
|
def ShowLayer(self): |
|
|
layer = self.current_layer() |
|
|
if layer is not None: |
|
|
layer.SetVisible(1) |
|
665 |
|
|
666 |
def LayerShowTable(self): |
def LayerShowTable(self): |
667 |
|
""" |
668 |
|
Present a TableView Window for the current layer. |
669 |
|
In case the window is already open, bring it to the front. |
670 |
|
In case, there is no active layer, do nothing. |
671 |
|
In case, the layer has no ShapeStore, do nothing. |
672 |
|
""" |
673 |
layer = self.current_layer() |
layer = self.current_layer() |
674 |
if layer is not None: |
if layer is not None: |
675 |
table = layer.table |
if not hasattr(layer, "ShapeStore"): |
676 |
|
return |
677 |
|
table = layer.ShapeStore().Table() |
678 |
name = "table_view" + str(id(table)) |
name = "table_view" + str(id(table)) |
679 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
680 |
if dialog is None: |
if dialog is None: |
681 |
dialog = tableview.LayerTableFrame(self, name, |
dialog = tableview.LayerTableFrame(self, name, |
682 |
_("Table: %s") % layer.Title(), |
_("Layer Table: %s") % layer.Title(), |
683 |
layer, table) |
layer, table) |
684 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
685 |
dialog.Show(true) |
dialog.Show(True) |
686 |
else: |
else: |
687 |
# FIXME: bring dialog to front here |
dialog.Raise() |
|
pass |
|
688 |
|
|
689 |
def Projection(self): |
def MapProjection(self): |
690 |
map = self.canvas.Map() |
|
691 |
proj = map.projection |
name = "map_projection" |
692 |
if proj is None: |
dialog = self.get_open_dialog(name) |
693 |
proj4Dlg = proj4dialog.Proj4Dialog(NULL, None, map.BoundingBox()) |
|
694 |
else: |
if dialog is None: |
695 |
proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params, |
map = self.canvas.Map() |
696 |
map.BoundingBox()) |
dialog = projdialog.ProjFrame(self, name, |
697 |
if proj4Dlg.ShowModal() == wxID_OK: |
_("Map Projection: %s") % map.Title(), map) |
698 |
params = proj4Dlg.GetParams() |
self.add_dialog(name, dialog) |
699 |
if params is not None: |
dialog.Show() |
700 |
proj = Projection(params) |
dialog.Raise() |
701 |
else: |
|
702 |
proj = None |
def LayerProjection(self): |
703 |
map.SetProjection(proj) |
|
704 |
proj4Dlg.Destroy() |
layer = self.current_layer() |
705 |
|
|
706 |
def Classify(self): |
name = "layer_projection" + str(id(layer)) |
707 |
|
dialog = self.get_open_dialog(name) |
708 |
|
|
709 |
|
if dialog is None: |
710 |
|
map = self.canvas.Map() |
711 |
|
dialog = projdialog.ProjFrame(self, name, |
712 |
|
_("Layer Projection: %s") % layer.Title(), layer) |
713 |
|
self.add_dialog(name, dialog) |
714 |
|
dialog.Show() |
715 |
|
dialog.Raise() |
716 |
|
|
717 |
|
def LayerEditProperties(self): |
718 |
|
|
719 |
# |
# |
720 |
# the menu option for this should only be available if there |
# the menu option for this should only be available if there |
723 |
# |
# |
724 |
|
|
725 |
layer = self.current_layer() |
layer = self.current_layer() |
726 |
self.OpenClassifier(layer) |
self.OpenLayerProperties(layer) |
727 |
|
|
728 |
def OpenClassifier(self, layer): |
def OpenLayerProperties(self, layer, group = None): |
729 |
name = "classifier" + str(id(layer)) |
""" |
730 |
dialog = self.get_open_dialog(name) |
Open or raise the properties dialog. |
731 |
|
|
732 |
if dialog is None: |
This method opens or raises the properties dialog for the |
733 |
dialog = classifier.Classifier(self, name, layer) |
currently selected layer if one is defined for this layer |
734 |
self.add_dialog(name, dialog) |
type. |
735 |
dialog.Show() |
""" |
736 |
|
dialog_class = layer_properties_dialogs.get(layer) |
737 |
|
|
738 |
|
if dialog_class is not None: |
739 |
|
name = "layer_properties" + str(id(layer)) |
740 |
|
self.OpenOrRaiseDialog(name, dialog_class, layer, group = group) |
741 |
|
|
742 |
|
def LayerJoinTable(self): |
743 |
|
layer = self.canvas.SelectedLayer() |
744 |
|
if layer is not None: |
745 |
|
dlg = JoinDialog(self, _("Join Layer with Table"), |
746 |
|
self.application.session, |
747 |
|
layer = layer) |
748 |
|
dlg.ShowModal() |
749 |
|
|
750 |
|
def LayerUnjoinTable(self): |
751 |
|
layer = self.canvas.SelectedLayer() |
752 |
|
if layer is not None: |
753 |
|
orig_store = layer.ShapeStore().OrigShapeStore() |
754 |
|
if orig_store: |
755 |
|
layer.SetShapeStore(orig_store) |
756 |
|
|
757 |
def ShowLegend(self): |
def ShowLegend(self): |
758 |
|
if not self.LegendShown(): |
759 |
|
self.ToggleLegend() |
760 |
|
|
761 |
|
def ToggleLegend(self): |
762 |
|
"""Show the legend if it's not shown otherwise hide it again""" |
763 |
name = "legend" |
name = "legend" |
764 |
dialog = self.get_open_dialog(name) |
dialog = self.FindRegisteredDock(name) |
765 |
|
|
766 |
if dialog is None: |
if dialog is None: |
767 |
dialog = legend.Legend(self, name, self.Map()) |
dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT) |
768 |
self.add_dialog(name, dialog) |
legend.LegendPanel(dialog, None, self) |
769 |
|
dialog.Dock() |
770 |
|
dialog.GetPanel().SetMap(self.Map()) |
771 |
dialog.Show() |
dialog.Show() |
772 |
|
else: |
773 |
|
dialog.Show(not dialog.IsShown()) |
774 |
|
|
775 |
|
def LegendShown(self): |
776 |
|
"""Return true iff the legend is currently open""" |
777 |
|
dialog = self.FindRegisteredDock("legend") |
778 |
|
return dialog is not None and dialog.IsShown() |
779 |
|
|
780 |
|
def TableOpen(self): |
781 |
|
dlg = wxFileDialog(self, _("Open Table"), |
782 |
|
self.application.Path("data"), "", |
783 |
|
_("DBF Files (*.dbf)") + "|*.dbf|" + |
784 |
|
#_("CSV Files (*.csv)") + "|*.csv|" + |
785 |
|
_("All Files (*.*)") + "|*.*", |
786 |
|
wxOPEN) |
787 |
|
if dlg.ShowModal() == wxID_OK: |
788 |
|
filename = dlg.GetPath() |
789 |
|
dlg.Destroy() |
790 |
|
try: |
791 |
|
table = self.application.session.OpenTableFile(filename) |
792 |
|
except IOError: |
793 |
|
# the layer couldn't be opened |
794 |
|
self.RunMessageBox(_("Open Table"), |
795 |
|
_("Can't open the file '%s'.") % filename) |
796 |
|
else: |
797 |
|
self.ShowTableView(table) |
798 |
|
self.application.SetPath("data",filename) |
799 |
|
|
800 |
|
def TableClose(self): |
801 |
|
tables = self.application.session.UnreferencedTables() |
802 |
|
|
803 |
|
lst = [(t.Title(), t) for t in tables] |
804 |
|
lst.sort() |
805 |
|
titles = [i[0] for i in lst] |
806 |
|
dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"), |
807 |
|
_("Close Table"), titles, |
808 |
|
size = (400, 300), |
809 |
|
style = wxDEFAULT_DIALOG_STYLE | |
810 |
|
wxRESIZE_BORDER) |
811 |
|
if dlg.ShowModal() == wxID_OK: |
812 |
|
for i in dlg.GetValue(): |
813 |
|
self.application.session.RemoveTable(lst[i][1]) |
814 |
|
|
815 |
|
|
816 |
|
def TableShow(self): |
817 |
|
"""Offer a multi-selection dialog for tables to be displayed |
818 |
|
|
819 |
|
The windows for the selected tables are opened or brought to |
820 |
|
the front. |
821 |
|
""" |
822 |
|
tables = self.application.session.Tables() |
823 |
|
|
824 |
|
lst = [(t.Title(), t) for t in tables] |
825 |
|
lst.sort() |
826 |
|
titles = [i[0] for i in lst] |
827 |
|
dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"), |
828 |
|
_("Show Table"), titles, |
829 |
|
size = (400,300), |
830 |
|
style = wxDEFAULT_DIALOG_STYLE | |
831 |
|
wxRESIZE_BORDER) |
832 |
|
if (dlg.ShowModal() == wxID_OK): |
833 |
|
for i in dlg.GetValue(): |
834 |
|
# XXX: if the table belongs to a layer, open a |
835 |
|
# LayerTableFrame instead of QueryTableFrame |
836 |
|
self.ShowTableView(lst[i][1]) |
837 |
|
|
838 |
|
def TableJoin(self): |
839 |
|
dlg = JoinDialog(self, _("Join Tables"), self.application.session) |
840 |
|
dlg.ShowModal() |
841 |
|
|
842 |
|
def ShowTableView(self, table): |
843 |
|
"""Open a table view for the table and optionally""" |
844 |
|
name = "table_view%d" % id(table) |
845 |
|
dialog = self.get_open_dialog(name) |
846 |
|
if dialog is None: |
847 |
|
dialog = tableview.QueryTableFrame(self, name, |
848 |
|
_("Table: %s") % table.Title(), |
849 |
|
table) |
850 |
|
self.add_dialog(name, dialog) |
851 |
|
dialog.Show(True) |
852 |
|
dialog.Raise() |
853 |
|
|
854 |
|
def TableRename(self): |
855 |
|
"""Let the user rename a table""" |
856 |
|
|
857 |
|
# First, let the user select a table |
858 |
|
tables = self.application.session.Tables() |
859 |
|
lst = [(t.Title(), t) for t in tables] |
860 |
|
lst.sort() |
861 |
|
titles = [i[0] for i in lst] |
862 |
|
dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"), |
863 |
|
_("Rename Table"), titles, |
864 |
|
size = (400,300), |
865 |
|
style = wxDEFAULT_DIALOG_STYLE | |
866 |
|
wxRESIZE_BORDER) |
867 |
|
if (dlg.ShowModal() == wxID_OK): |
868 |
|
to_rename = [lst[i][1] for i in dlg.GetValue()] |
869 |
|
dlg.Destroy() |
870 |
|
else: |
871 |
|
to_rename = [] |
872 |
|
|
873 |
|
# Second, let the user rename the layers |
874 |
|
for table in to_rename: |
875 |
|
dlg = wxTextEntryDialog(self, _("Table Title:"), _("Rename Table"), |
876 |
|
table.Title()) |
877 |
|
try: |
878 |
|
if dlg.ShowModal() == wxID_OK: |
879 |
|
title = dlg.GetValue() |
880 |
|
if title != "": |
881 |
|
table.SetTitle(title) |
882 |
|
|
883 |
|
# Make sure the session is marked as modified. |
884 |
|
# FIXME: This should be handled automatically, |
885 |
|
# but that requires more changes to the tables |
886 |
|
# than I have time for currently. |
887 |
|
self.application.session.changed() |
888 |
|
finally: |
889 |
|
dlg.Destroy() |
890 |
|
|
891 |
|
|
892 |
def ZoomInTool(self): |
def ZoomInTool(self): |
893 |
self.canvas.ZoomInTool() |
self.canvas.ZoomInTool() |
908 |
def FullExtent(self): |
def FullExtent(self): |
909 |
self.canvas.FitMapToWindow() |
self.canvas.FitMapToWindow() |
910 |
|
|
911 |
|
def FullLayerExtent(self): |
912 |
|
self.canvas.FitLayerToWindow(self.current_layer()) |
913 |
|
|
914 |
|
def FullSelectionExtent(self): |
915 |
|
self.canvas.FitSelectedToWindow() |
916 |
|
|
917 |
|
def ExportMap(self): |
918 |
|
self.canvas.Export() |
919 |
|
|
920 |
def PrintMap(self): |
def PrintMap(self): |
921 |
self.canvas.Print() |
self.canvas.Print() |
922 |
|
|
923 |
|
def RenameMap(self): |
924 |
|
dlg = wxTextEntryDialog(self, _("Map Title:"), _("Rename Map"), |
925 |
|
self.Map().Title()) |
926 |
|
if dlg.ShowModal() == wxID_OK: |
927 |
|
title = dlg.GetValue() |
928 |
|
if title != "": |
929 |
|
self.Map().SetTitle(title) |
930 |
|
|
931 |
|
dlg.Destroy() |
932 |
|
|
933 |
|
def RenameLayer(self): |
934 |
|
"""Let the user rename the currently selected layer""" |
935 |
|
layer = self.current_layer() |
936 |
|
if layer is not None: |
937 |
|
dlg = wxTextEntryDialog(self, _("Layer Title:"), _("Rename Layer"), |
938 |
|
layer.Title()) |
939 |
|
try: |
940 |
|
if dlg.ShowModal() == wxID_OK: |
941 |
|
title = dlg.GetValue() |
942 |
|
if title != "": |
943 |
|
layer.SetTitle(title) |
944 |
|
finally: |
945 |
|
dlg.Destroy() |
946 |
|
|
947 |
def identify_view_on_demand(self, layer, shapes): |
def identify_view_on_demand(self, layer, shapes): |
948 |
|
"""Subscribed to the canvas' SHAPES_SELECTED message |
949 |
|
|
950 |
|
If the current tool is the identify tool, at least one shape is |
951 |
|
selected and the identify dialog is not shown, show the dialog. |
952 |
|
""" |
953 |
|
# If the selection has become empty we don't need to do |
954 |
|
# anything. Otherwise it could happen that the dialog was popped |
955 |
|
# up when the selection became empty, e.g. when a new selection |
956 |
|
# is opened while the identify tool is active and dialog had |
957 |
|
# been closed |
958 |
|
if not shapes: |
959 |
|
return |
960 |
|
|
961 |
name = "identify_view" |
name = "identify_view" |
962 |
if self.canvas.CurrentTool() == "IdentifyTool": |
if self.canvas.CurrentTool() == "IdentifyTool": |
963 |
if not self.dialog_open(name): |
if not self.dialog_open(name): |
964 |
dialog = identifyview.IdentifyView(self, name) |
dialog = identifyview.IdentifyView(self, name) |
965 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
966 |
dialog.Show(true) |
dialog.Show(True) |
967 |
else: |
else: |
968 |
# FIXME: bring dialog to front? |
# FIXME: bring dialog to front? |
969 |
pass |
pass |
970 |
|
|
971 |
|
def title_changed(self, map): |
972 |
|
"""Subscribed to the canvas' TITLE_CHANGED messages""" |
973 |
|
self.update_title() |
974 |
|
|
975 |
|
def update_title(self): |
976 |
|
"""Update the window's title according to it's current state. |
977 |
|
|
978 |
|
In this default implementation the title is 'Thuban - ' followed |
979 |
|
by the map's title or simply 'Thuban' if there is not map. |
980 |
|
Derived classes should override this method to get different |
981 |
|
titles. |
982 |
|
|
983 |
|
This method is called automatically by other methods when the |
984 |
|
title may have to change. For the methods implemented in this |
985 |
|
class this usually only means that a different map has been set |
986 |
|
or the current map's title has changed. |
987 |
|
""" |
988 |
|
map = self.Map() |
989 |
|
if map is not None: |
990 |
|
title = _("Thuban - %s") % (map.Title(),) |
991 |
|
else: |
992 |
|
title = _("Thuban") |
993 |
|
self.SetTitle(title) |
994 |
|
|
995 |
|
|
996 |
# |
# |
997 |
# Define all the commands available in the main window |
# Define all the commands available in the main window |
998 |
# |
# |
1004 |
apply(getattr(context.mainwindow, methodname), args) |
apply(getattr(context.mainwindow, methodname), args) |
1005 |
|
|
1006 |
def _method_command(name, title, method, helptext = "", |
def _method_command(name, title, method, helptext = "", |
1007 |
icon = "", sensitive = None): |
icon = "", sensitive = None, checked = None): |
1008 |
"""Add a command implemented by a method of the mainwindow object""" |
"""Add a command implemented by a method of the mainwindow object""" |
1009 |
registry.Add(Command(name, title, call_method, args=(method,), |
registry.Add(Command(name, title, call_method, args=(method,), |
1010 |
helptext = helptext, icon = icon, |
helptext = helptext, icon = icon, |
1011 |
sensitive = sensitive)) |
sensitive = sensitive, checked = checked)) |
1012 |
|
|
1013 |
def make_check_current_tool(toolname): |
def make_check_current_tool(toolname): |
1014 |
"""Return a function that tests if the currently active tool is toolname |
"""Return a function that tests if the currently active tool is toolname |
1033 |
"""Return true if a layer is selected in the context""" |
"""Return true if a layer is selected in the context""" |
1034 |
return context.mainwindow.has_selected_layer() |
return context.mainwindow.has_selected_layer() |
1035 |
|
|
1036 |
|
def _has_selected_layer_visible(context): |
1037 |
|
"""Return true if a layer is selected in the context which is |
1038 |
|
visible.""" |
1039 |
|
if context.mainwindow.has_selected_layer(): |
1040 |
|
layer = context.mainwindow.current_layer() |
1041 |
|
if layer.Visible(): return True |
1042 |
|
return False |
1043 |
|
|
1044 |
|
def _has_selected_shape_layer(context): |
1045 |
|
"""Return true if a shape layer is selected in the context""" |
1046 |
|
return context.mainwindow.has_selected_shape_layer() |
1047 |
|
|
1048 |
|
def _has_selected_shapes(context): |
1049 |
|
"""Return true if a layer is selected in the context""" |
1050 |
|
return context.mainwindow.has_selected_shapes() |
1051 |
|
|
1052 |
def _can_remove_layer(context): |
def _can_remove_layer(context): |
1053 |
return context.mainwindow.CanRemoveLayer() |
return context.mainwindow.CanRemoveLayer() |
1054 |
|
|
1055 |
def _has_tree_window_shown(context): |
def _has_tree_window_shown(context): |
1056 |
"""Return true if the tree window is shown""" |
"""Return true if the tree window is shown""" |
1057 |
return context.mainwindow.get_open_dialog("session_tree") is None |
return context.mainwindow.SessionTreeShown() |
1058 |
|
|
1059 |
def _has_visible_map(context): |
def _has_visible_map(context): |
1060 |
"""Return true iff theres a visible map in the mainwindow. |
"""Return true iff theres a visible map in the mainwindow. |
1064 |
if map is not None: |
if map is not None: |
1065 |
for layer in map.Layers(): |
for layer in map.Layers(): |
1066 |
if layer.Visible(): |
if layer.Visible(): |
1067 |
return 1 |
return True |
1068 |
return 0 |
return False |
1069 |
|
|
1070 |
def _has_legend_shown(context): |
def _has_legend_shown(context): |
1071 |
"""Return true if the legend window is shown""" |
"""Return true if the legend window is shown""" |
1072 |
return context.mainwindow.get_open_dialog("legend") is None |
return context.mainwindow.LegendShown() |
1073 |
|
|
1074 |
|
def _has_gdal_support(context): |
1075 |
|
"""Return True if the GDAL is available""" |
1076 |
|
return Thuban.Model.resource.has_gdal_support() |
1077 |
|
|
1078 |
|
def _has_dbconnections(context): |
1079 |
|
"""Return whether the the session has database connections""" |
1080 |
|
return context.session.HasDBConnections() |
1081 |
|
|
1082 |
|
def _has_postgis_support(context): |
1083 |
|
return has_postgis_support() |
1084 |
|
|
1085 |
|
|
1086 |
# File menu |
# File menu |
1087 |
_method_command("new_session", _("&New Session"), "NewSession") |
_method_command("new_session", _("&New Session"), "NewSession", |
1088 |
_method_command("open_session", _("&Open Session"), "OpenSession") |
helptext = _("Start a new session")) |
1089 |
_method_command("save_session", _("&Save Session"), "SaveSession") |
_method_command("open_session", _("&Open Session..."), "OpenSession", |
1090 |
_method_command("save_session_as", _("Save Session &As"), "SaveSessionAs") |
helptext = _("Open a session file")) |
1091 |
_method_command("show_session_tree", _("Show Session &Tree"), "ShowSessionTree", |
_method_command("save_session", _("&Save Session"), "SaveSession", |
1092 |
sensitive = _has_tree_window_shown) |
helptext =_("Save this session to the file it was opened from")) |
1093 |
_method_command("exit", _("E&xit"), "Exit") |
_method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs", |
1094 |
|
helptext = _("Save this session to a new file")) |
1095 |
|
_method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree", |
1096 |
|
checked = _has_tree_window_shown, |
1097 |
|
helptext = _("Toggle on/off the session tree analysis window")) |
1098 |
|
_method_command("toggle_legend", _("Legend"), "ToggleLegend", |
1099 |
|
checked = _has_legend_shown, |
1100 |
|
helptext = _("Toggle Legend on/off")) |
1101 |
|
_method_command("database_management", _("&Database Connections..."), |
1102 |
|
"DatabaseManagement", |
1103 |
|
sensitive = _has_postgis_support) |
1104 |
|
_method_command("exit", _("E&xit"), "Exit", |
1105 |
|
helptext = _("Finish working with Thuban")) |
1106 |
|
|
1107 |
# Help menu |
# Help menu |
1108 |
_method_command("help_about", _("&About"), "About") |
_method_command("help_about", _("&About..."), "About", |
1109 |
|
helptext = _("Info about Thuban authors, version and modules")) |
1110 |
|
|
1111 |
|
|
1112 |
# Map menu |
# Map menu |
1113 |
_method_command("map_projection", _("Pro&jection"), "Projection") |
_method_command("map_projection", _("Pro&jection..."), "MapProjection", |
1114 |
|
helptext = _("Set or change the map projection")) |
1115 |
|
|
1116 |
_tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool", |
_tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool", |
1117 |
helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in", |
helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in", |
1130 |
helptext = _("Add/Remove labels"), icon = "label", |
helptext = _("Add/Remove labels"), icon = "label", |
1131 |
sensitive = _has_visible_map) |
sensitive = _has_visible_map) |
1132 |
_method_command("map_full_extent", _("&Full extent"), "FullExtent", |
_method_command("map_full_extent", _("&Full extent"), "FullExtent", |
1133 |
helptext = _("Full Extent"), icon = "fullextent", |
helptext = _("Zoom to the full map extent"), icon = "fullextent", |
1134 |
sensitive = _has_visible_map) |
sensitive = _has_visible_map) |
1135 |
|
_method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent", |
1136 |
|
helptext = _("Zoom to the full layer extent"), |
1137 |
|
icon = "fulllayerextent", sensitive = _has_selected_layer) |
1138 |
|
_method_command("selected_full_extent", _("&Full selection extent"), |
1139 |
|
"FullSelectionExtent", |
1140 |
|
helptext = _("Zoom to the full selection extent"), |
1141 |
|
icon = "fullselextent", sensitive = _has_selected_shapes) |
1142 |
|
_method_command("map_export", _("E&xport"), "ExportMap", |
1143 |
|
helptext = _("Export the map to file")) |
1144 |
_method_command("map_print", _("Prin&t"), "PrintMap", |
_method_command("map_print", _("Prin&t"), "PrintMap", |
1145 |
helptext = _("Print the map")) |
helptext = _("Print the map")) |
1146 |
|
_method_command("map_rename", _("&Rename..."), "RenameMap", |
1147 |
# Layer menu |
helptext = _("Rename the map")) |
1148 |
_method_command("layer_add", _("&Add Layer"), "AddLayer", |
_method_command("layer_add", _("&Add Layer..."), "AddLayer", |
1149 |
helptext = _("Add a new layer to active map")) |
helptext = _("Add a new layer to the map")) |
1150 |
|
_method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer", |
1151 |
|
helptext = _("Add a new image layer to the map"), |
1152 |
|
sensitive = _has_gdal_support) |
1153 |
|
_method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer", |
1154 |
|
helptext = _("Add a new database layer to active map"), |
1155 |
|
sensitive = _has_dbconnections) |
1156 |
_method_command("layer_remove", _("&Remove Layer"), "RemoveLayer", |
_method_command("layer_remove", _("&Remove Layer"), "RemoveLayer", |
1157 |
helptext = _("Remove selected layer(s)"), |
helptext = _("Remove selected layer"), |
1158 |
sensitive = _can_remove_layer) |
sensitive = _can_remove_layer) |
1159 |
_method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor", |
|
1160 |
helptext = _("Set the fill color of selected layer(s)"), |
# Layer menu |
1161 |
sensitive = _has_selected_layer) |
_method_command("layer_projection", _("Pro&jection..."), "LayerProjection", |
1162 |
_method_command("layer_transparent_fill", _("&Transparent Fill"), |
sensitive = _has_selected_layer, |
1163 |
"LayerTransparentFill", |
helptext = _("Specify projection for selected layer")) |
1164 |
helptext = _("Do not fill the selected layer(s)"), |
_method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer", |
1165 |
sensitive = _has_selected_layer) |
helptext = _("Duplicate selected layer"), |
1166 |
_method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor", |
sensitive = lambda context: context.mainwindow.CanDuplicateLayer()) |
1167 |
helptext = _("Set the outline color of selected layer(s)"), |
_method_command("layer_rename", _("Re&name ..."), "RenameLayer", |
1168 |
sensitive = _has_selected_layer) |
helptext = _("Rename selected layer"), |
|
_method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline", |
|
|
helptext= _("Do not draw the outline of the selected layer(s)"), |
|
1169 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1170 |
_method_command("layer_raise", _("&Raise"), "RaiseLayer", |
_method_command("layer_raise", _("&Raise"), "RaiseLayer", |
1171 |
helptext = _("Raise selected layer(s)"), |
helptext = _("Raise selected layer"), |
1172 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1173 |
_method_command("layer_lower", _("&Lower"), "LowerLayer", |
_method_command("layer_lower", _("&Lower"), "LowerLayer", |
1174 |
helptext = _("Lower selected layer(s)"), |
helptext = _("Lower selected layer"), |
1175 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1176 |
_method_command("layer_show", _("&Show"), "ShowLayer", |
_method_command("layer_show", _("&Show"), "ShowLayer", |
1177 |
helptext = _("Make selected layer(s) visible"), |
helptext = _("Make selected layer visible"), |
1178 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1179 |
_method_command("layer_hide", _("&Hide"), "HideLayer", |
_method_command("layer_hide", _("&Hide"), "HideLayer", |
1180 |
helptext = _("Make selected layer(s) unvisible"), |
helptext = _("Make selected layer unvisible"), |
1181 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1182 |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
1183 |
helptext = _("Show the selected layer's table"), |
helptext = _("Show the selected layer's table"), |
1184 |
|
sensitive = _has_selected_shape_layer) |
1185 |
|
_method_command("layer_properties", _("&Properties..."), "LayerEditProperties", |
1186 |
|
sensitive = _has_selected_layer, |
1187 |
|
helptext = _("Edit the properties of the selected layer")) |
1188 |
|
_method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable", |
1189 |
|
sensitive = _has_selected_shape_layer, |
1190 |
|
helptext = _("Join and attach a table to the selected layer")) |
1191 |
|
|
1192 |
|
# further layer methods: |
1193 |
|
_method_command("layer_to_top", _("&Top"), "LayerToTop", |
1194 |
|
helptext = _("Put selected layer to the top"), |
1195 |
|
sensitive = _has_selected_layer) |
1196 |
|
_method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom", |
1197 |
|
helptext = _("Put selected layer to the bottom"), |
1198 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
1199 |
_method_command("layer_classifier", _("Classify"), "Classify", |
_method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility", |
1200 |
|
checked = _has_selected_layer_visible, |
1201 |
|
helptext = _("Toggle visibility of selected layer"), |
1202 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
|
_method_command("show_legend", _("Legend"), "ShowLegend", |
|
|
sensitive = _has_legend_shown) |
|
1203 |
|
|
1204 |
# the menu structure |
def _can_unjoin(context): |
1205 |
main_menu = Menu("<main>", "<main>", |
"""Return whether the Layer/Unjoin command can be executed. |
1206 |
[Menu("file", _("&File"), |
|
1207 |
["new_session", "open_session", None, |
This is the case if a layer is selected and that layer has a |
1208 |
"save_session", "save_session_as", None, |
shapestore that has an original shapestore. |
1209 |
"show_session_tree", None, |
""" |
1210 |
"show_legend", None, |
layer = context.mainwindow.SelectedLayer() |
1211 |
"exit"]), |
if layer is None: |
1212 |
Menu("map", _("&Map"), |
return 0 |
1213 |
["layer_add", "layer_remove", |
getstore = getattr(layer, "ShapeStore", None) |
1214 |
|
if getstore is not None: |
1215 |
|
return getstore().OrigShapeStore() is not None |
1216 |
|
else: |
1217 |
|
return 0 |
1218 |
|
_method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable", |
1219 |
|
sensitive = _can_unjoin, |
1220 |
|
helptext = _("Undo the last join operation")) |
1221 |
|
|
1222 |
|
|
1223 |
|
def _has_tables(context): |
1224 |
|
return bool(context.session.Tables()) |
1225 |
|
|
1226 |
|
# Table menu |
1227 |
|
_method_command("table_open", _("&Open..."), "TableOpen", |
1228 |
|
helptext = _("Open a DBF-table from a file")) |
1229 |
|
_method_command("table_close", _("&Close..."), "TableClose", |
1230 |
|
sensitive = lambda context: bool(context.session.UnreferencedTables()), |
1231 |
|
helptext = _("Close one or more tables from a list")) |
1232 |
|
_method_command("table_rename", _("&Rename..."), "TableRename", |
1233 |
|
sensitive = _has_tables, |
1234 |
|
helptext = _("Rename one or more tables")) |
1235 |
|
_method_command("table_show", _("&Show..."), "TableShow", |
1236 |
|
sensitive = _has_tables, |
1237 |
|
helptext = _("Show one or more tables in a dialog")) |
1238 |
|
_method_command("table_join", _("&Join..."), "TableJoin", |
1239 |
|
sensitive = _has_tables, |
1240 |
|
helptext = _("Join two tables creating a new one")) |
1241 |
|
|
1242 |
|
# Export only under Windows ... |
1243 |
|
map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove", |
1244 |
None, |
None, |
1245 |
|
"map_rename", |
1246 |
"map_projection", |
"map_projection", |
1247 |
None, |
None, |
1248 |
"map_zoom_in_tool", "map_zoom_out_tool", |
"map_zoom_in_tool", "map_zoom_out_tool", |
1249 |
"map_pan_tool", "map_identify_tool", "map_label_tool", |
"map_pan_tool", |
|
None, |
|
1250 |
"map_full_extent", |
"map_full_extent", |
1251 |
|
"layer_full_extent", |
1252 |
|
"selected_full_extent", |
1253 |
|
None, |
1254 |
|
"map_identify_tool", "map_label_tool", |
1255 |
None, |
None, |
1256 |
"map_print"]), |
"toggle_legend", |
1257 |
|
None] |
1258 |
|
if wxPlatform == '__WXMSW__': |
1259 |
|
map_menu.append("map_export") |
1260 |
|
map_menu.append("map_print") |
1261 |
|
|
1262 |
|
# the menu structure |
1263 |
|
main_menu = Menu("<main>", "<main>", |
1264 |
|
[Menu("file", _("&File"), |
1265 |
|
["new_session", "open_session", None, |
1266 |
|
"save_session", "save_session_as", None, |
1267 |
|
"database_management", None, |
1268 |
|
"toggle_session_tree", None, |
1269 |
|
"exit"]), |
1270 |
|
Menu("map", _("&Map"), map_menu), |
1271 |
Menu("layer", _("&Layer"), |
Menu("layer", _("&Layer"), |
1272 |
["layer_fill_color", "layer_transparent_fill", |
["layer_rename", "layer_duplicate", |
|
"layer_outline_color", "layer_no_outline", |
|
1273 |
None, |
None, |
1274 |
"layer_raise", "layer_lower", |
"layer_raise", "layer_lower", |
1275 |
None, |
None, |
1276 |
"layer_show", "layer_hide", |
"layer_show", "layer_hide", |
1277 |
None, |
None, |
1278 |
|
"layer_projection", |
1279 |
|
None, |
1280 |
"layer_show_table", |
"layer_show_table", |
1281 |
|
"layer_jointable", |
1282 |
|
"layer_unjointable", |
1283 |
None, |
None, |
1284 |
"layer_classifier"]), |
"layer_properties"]), |
1285 |
|
Menu("table", _("&Table"), |
1286 |
|
["table_open", "table_close", "table_rename", |
1287 |
|
None, |
1288 |
|
"table_show", |
1289 |
|
None, |
1290 |
|
"table_join"]), |
1291 |
Menu("help", _("&Help"), |
Menu("help", _("&Help"), |
1292 |
["help_about"])]) |
["help_about"])]) |
1293 |
|
|
1295 |
|
|
1296 |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
1297 |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
1298 |
"map_full_extent", None, |
"map_full_extent", |
1299 |
|
"layer_full_extent", |
1300 |
|
"selected_full_extent", |
1301 |
|
None, |
1302 |
"map_identify_tool", "map_label_tool"]) |
"map_identify_tool", "map_label_tool"]) |
1303 |
|
|