1 |
# Copyright (C) 2001, 2002, 2003, 2004 by Intevation GmbH |
# Copyright (C) 2001, 2002, 2003, 2004, 2005 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]> |
18 |
import os |
import os |
19 |
import copy |
import copy |
20 |
|
|
21 |
from wxPython.wx import * |
import wx |
22 |
|
|
23 |
import Thuban |
import Thuban |
24 |
|
|
25 |
from Thuban import _ |
from Thuban import _ |
26 |
from Thuban.Model.messages import TITLE_CHANGED |
from Thuban.Model.messages import TITLE_CHANGED, LAYER_PROJECTION_CHANGED, \ |
27 |
|
MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED |
28 |
|
|
29 |
from Thuban.Model.session import create_empty_session |
from Thuban.Model.session import create_empty_session |
30 |
from Thuban.Model.layer import Layer, RasterLayer |
from Thuban.Model.layer import Layer, RasterLayer |
31 |
from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support |
from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support |
32 |
# XXX: replace this by |
from wx.lib.dialogs import MultipleChoiceDialog |
|
# from wxPython.lib.dialogs import wxMultipleChoiceDialog |
|
|
# when Thuban does not support wxPython 2.4.0 any more. |
|
|
from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog |
|
33 |
|
|
34 |
import view |
import view |
35 |
import tree |
import tree |
51 |
|
|
52 |
import projdialog |
import projdialog |
53 |
|
|
54 |
|
from Thuban.UI.classifier import Classifier |
55 |
|
from Thuban.UI.rasterlayerproperties import RasterLayerProperties |
56 |
|
from Thuban.Model.layer import RasterLayer |
57 |
|
|
58 |
from Thuban.Lib.classmapper import ClassMapper |
from Thuban.Lib.classmapper import ClassMapper |
59 |
|
|
60 |
layer_properties_dialogs = ClassMapper() |
layer_properties_dialogs = ClassMapper() |
61 |
|
layer_properties_dialogs.add(RasterLayer, RasterLayerProperties) |
62 |
|
layer_properties_dialogs.add(Layer, Classifier) |
63 |
|
|
64 |
class MainWindow(DockFrame): |
class MainWindow(DockFrame): |
65 |
|
|
80 |
"SelectedShapes": "canvas", |
"SelectedShapes": "canvas", |
81 |
} |
} |
82 |
|
|
83 |
|
# Messages from the canvas that may require a status bar update. |
84 |
|
# The update_status_bar method will be subscribed to these messages. |
85 |
|
update_status_bar_messages = (VIEW_POSITION, LAYER_PROJECTION_CHANGED, |
86 |
|
MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED, |
87 |
|
MAP_LAYERS_REMOVED) |
88 |
|
|
89 |
def __init__(self, parent, ID, title, application, interactor, |
def __init__(self, parent, ID, title, application, interactor, |
90 |
initial_message = None, size = wxSize(-1, -1)): |
initial_message = None, size = wx.Size(-1, -1)): |
91 |
DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
DockFrame.__init__(self, parent, ID, title, wx.DefaultPosition, size) |
92 |
#wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
#wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
93 |
|
|
94 |
self.application = application |
self.application = application |
112 |
|
|
113 |
# Create the map canvas |
# Create the map canvas |
114 |
canvas = view.MapCanvas(self, -1) |
canvas = view.MapCanvas(self, -1) |
|
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
|
115 |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
116 |
self.canvas = canvas |
self.canvas = canvas |
117 |
self.canvas.Subscribe(TITLE_CHANGED, self.title_changed) |
self.canvas.Subscribe(TITLE_CHANGED, self.title_changed) |
118 |
|
|
119 |
|
for channel in self.update_status_bar_messages: |
120 |
|
self.canvas.Subscribe(channel, self.update_status_bar) |
121 |
|
|
122 |
self.SetMainWindow(self.canvas) |
self.SetMainWindow(self.canvas) |
123 |
|
|
124 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
127 |
|
|
128 |
self.ShowLegend() |
self.ShowLegend() |
129 |
|
|
130 |
EVT_CLOSE(self, self.OnClose) |
self.Bind(wx.EVT_CLOSE, self.OnClose) |
131 |
|
|
132 |
def Subscribe(self, channel, *args): |
def Subscribe(self, channel, *args): |
133 |
"""Subscribe a function to a message channel. |
"""Subscribe a function to a message channel. |
151 |
object = getattr(self, self.delegated_messages[channel]) |
object = getattr(self, self.delegated_messages[channel]) |
152 |
try: |
try: |
153 |
object.Unsubscribe(channel, *args) |
object.Unsubscribe(channel, *args) |
154 |
except wxPyDeadObjectError: |
except wx.PyDeadObjectError: |
155 |
# The object was a wxObject and has already been |
# The object was a wxObject and has already been |
156 |
# destroyed. Hopefully it has unsubscribed all its |
# destroyed. Hopefully it has unsubscribed all its |
157 |
# subscribers already so that it's OK if we do nothing |
# subscribers already so that it's OK if we do nothing |
190 |
"""Bind the necessary events for the given command and ID""" |
"""Bind the necessary events for the given command and ID""" |
191 |
if not self.events_bound.has_key(ID): |
if not self.events_bound.has_key(ID): |
192 |
# the events haven't been bound yet |
# the events haven't been bound yet |
193 |
EVT_MENU(self, ID, self.invoke_command) |
self.Bind(wx.EVT_MENU, self.invoke_command, id=ID) |
194 |
if command.IsDynamic(): |
if command.IsDynamic(): |
195 |
EVT_UPDATE_UI(self, ID, self.update_command_ui) |
self.Bind(wx.EVT_UPDATE_UI, self.update_command_ui, id=ID) |
196 |
|
|
197 |
def build_menu_bar(self, menudesc): |
def build_menu_bar(self, menudesc): |
198 |
"""Build and return the menu bar from the menu description""" |
"""Build and return the menu bar from the menu description""" |
199 |
menu_bar = wxMenuBar() |
menu_bar = wx.MenuBar() |
200 |
|
|
201 |
for item in menudesc.items: |
for item in menudesc.items: |
202 |
# here the items must all be Menu instances themselves |
# here the items must all be Menu instances themselves |
206 |
|
|
207 |
def build_menu(self, menudesc): |
def build_menu(self, menudesc): |
208 |
"""Return a wxMenu built from the menu description menudesc""" |
"""Return a wxMenu built from the menu description menudesc""" |
209 |
wxmenu = wxMenu() |
wxmenu = wx.Menu() |
210 |
last = None |
last = None |
211 |
for item in menudesc.items: |
for item in menudesc.items: |
212 |
if item is None: |
if item is None: |
216 |
wxmenu.AppendSeparator() |
wxmenu.AppendSeparator() |
217 |
elif isinstance(item, Menu): |
elif isinstance(item, Menu): |
218 |
# a submenu |
# a submenu |
219 |
wxmenu.AppendMenu(wxNewId(), item.title, self.build_menu(item)) |
wxmenu.AppendMenu(wx.NewId(), item.title, self.build_menu(item)) |
220 |
else: |
else: |
221 |
# must the name the name of a command |
# must the name the name of a command |
222 |
self.add_menu_command(wxmenu, item) |
self.add_menu_command(wxmenu, item) |
229 |
The parameter should be an instance of the Menu class but it |
The parameter should be an instance of the Menu class but it |
230 |
should not contain submenus. |
should not contain submenus. |
231 |
""" |
""" |
232 |
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
toolbar = self.CreateToolBar(wx.TB_3DBUTTONS) |
233 |
|
|
234 |
# set the size of the tools' bitmaps. Not needed on wxGTK, but |
# set the size of the tools' bitmaps. Not needed on wxGTK, but |
235 |
# on Windows, although it doesn't work very well there. It seems |
# on Windows, although it doesn't work very well there. It seems |
236 |
# that only 16x16 icons are really supported on windows. |
# that only 16x16 icons are really supported on windows. |
237 |
# We probably shouldn't hardwire the bitmap size here. |
# We probably shouldn't hardwire the bitmap size here. |
238 |
toolbar.SetToolBitmapSize(wxSize(24, 24)) |
toolbar.SetToolBitmapSize(wx.Size(24, 24)) |
239 |
|
|
240 |
for item in toolbardesc.items: |
for item in toolbardesc.items: |
241 |
if item is None: |
if item is None: |
276 |
command = registry.Command(name) |
command = registry.Command(name) |
277 |
if command is not None: |
if command is not None: |
278 |
ID = self.get_id(name) |
ID = self.get_id(name) |
279 |
bitmap = resource.GetBitmapResource(command.Icon(), |
bitmap = resource.GetBitmapResource(command.Icon(), |
280 |
wxBITMAP_TYPE_XPM) |
wx.BITMAP_TYPE_XPM) |
281 |
toolbar.AddTool(ID, bitmap, |
toolbar.AddTool(ID, bitmap, |
282 |
shortHelpString = command.HelpText(), |
shortHelpString = command.HelpText(), |
283 |
isToggle = command.IsCheckCommand()) |
isToggle = command.IsCheckCommand()) |
317 |
if command.IsCheckCommand(): |
if command.IsCheckCommand(): |
318 |
event.Check(command.Checked(context)) |
event.Check(command.Checked(context)) |
319 |
|
|
320 |
def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION): |
def RunMessageBox(self, title, text, flags = wx.OK | wx.ICON_INFORMATION): |
321 |
"""Run a modal message box with the given text, title and flags |
"""Run a modal message box with the given text, title and flags |
322 |
and return the result""" |
and return the result""" |
323 |
dlg = wxMessageDialog(self, text, title, flags) |
dlg = wx.MessageDialog(self, text, title, flags) |
324 |
dlg.CenterOnParent() |
dlg.CenterOnParent() |
325 |
result = dlg.ShowModal() |
result = dlg.ShowModal() |
326 |
dlg.Destroy() |
dlg.Destroy() |
347 |
def get_open_dialog(self, name): |
def get_open_dialog(self, name): |
348 |
return self.dialogs.get(name) |
return self.dialogs.get(name) |
349 |
|
|
350 |
def view_position_changed(self): |
def update_status_bar(self, *args): |
351 |
"""Put current position in status bar after a mouse move.""" |
"""Handler for a bunch of messages that may require a status bar update |
352 |
|
|
353 |
|
Currently this handles the canvas' VIEW_POSITION_CHANGED |
354 |
|
messages as well as several messages about changes in the map |
355 |
|
which may affect whether and how projections are used. |
356 |
|
|
357 |
|
These messages affect the text in the status bar in the following way: |
358 |
|
|
359 |
|
When VIEW_POSITION_CHANGED messages are sent and the mouse is |
360 |
|
actually in the canvas window, display the current mouse |
361 |
|
coordinates as defined by the canvas' CurrentPosition method. |
362 |
|
|
363 |
|
If there is no current position to show, check whether there is |
364 |
|
a potential problem with the map and layer projections and |
365 |
|
display a message about it. Otherwise the status bar will |
366 |
|
become empty. |
367 |
|
|
368 |
|
The text is displayed in the status bar using the |
369 |
|
set_position_text method. |
370 |
|
""" |
371 |
|
# Implementation note: We do not really have to know which |
372 |
|
# message was sent. We can simply call the canvas' |
373 |
|
# CurrentPosition method and if that returns a tuple, it was a |
374 |
|
# VIEW_POSITION_CHANGED message and we have to display it. |
375 |
|
# Otherwise it was a VIEW_POSITION_CHANGED message where the |
376 |
|
# mouse has left the canvas or it was a message about a change |
377 |
|
# to the map, in which case we check the projections. |
378 |
|
# |
379 |
|
# When changing this method, keep in mind that the |
380 |
|
# VIEW_POSITION_CHANGED message are sent for every mouse move in |
381 |
|
# the canvas window, that is they happen very often, so the path |
382 |
|
# taken in that case has to be fast. |
383 |
|
text = "" |
384 |
pos = self.canvas.CurrentPosition() |
pos = self.canvas.CurrentPosition() |
385 |
if pos is not None: |
if pos is not None: |
386 |
text = "(%10.10g, %10.10g)" % pos |
text = "(%10.10g, %10.10g)" % pos |
387 |
else: |
else: |
388 |
text = "" |
for layer in self.canvas.Map().Layers(): |
|
# XXX This is a hack until we find a better place for this code. |
|
|
# (BER 20050120) |
|
|
# BH wrote (20050120): |
|
|
# this branch is only executed when the mouse |
|
|
# leaves the canvas window, so it's not that often [..] |
|
|
# [Here] not the right place to put this code. |
|
|
# I don't have a better solution at hand, |
|
|
# but the view_position_changed is only there to update |
|
|
# the current position. If other information is to |
|
|
# be shown in the status bar it should |
|
|
# be handled in a different way and |
|
|
# by other methods. |
|
|
# |
|
|
# The status bar widget supports some kind of stack of texts. |
|
|
# maybe that can be used to distinguis |
|
|
# between short-lived information such as the mouse position |
|
|
# and more permanent information such as the hint |
|
|
# about the projections. |
|
|
map = self.canvas.Map() |
|
|
for layer in map.layers: |
|
389 |
bbox = layer.LatLongBoundingBox() |
bbox = layer.LatLongBoundingBox() |
390 |
if bbox: |
if bbox: |
391 |
left, bottom, right, top = bbox |
left, bottom, right, top = bbox |
392 |
if not (-180 <= left <= 180 and |
if not (-180 <= left <= 180 and |
393 |
-180 <= right <= 180 and |
-180 <= right <= 180 and |
394 |
-90 <= top <= 90 and |
-90 <= top <= 90 and |
395 |
-90 <= bottom <= 90): |
-90 <= bottom <= 90): |
396 |
text = ("Select '"+layer.title+"' and pick a " + |
text = _("Select layer '%s' and pick a projection " |
397 |
"projection using Layer/Projection...") |
"using Layer/Projection...") % layer.title |
398 |
break |
break |
399 |
|
|
400 |
self.set_position_text(text) |
self.set_position_text(text) |
401 |
|
|
402 |
def set_position_text(self, text): |
def set_position_text(self, text): |
403 |
"""Set the statusbar text showing the current position. |
"""Set the statusbar text to that created by update_status_bar |
404 |
|
|
405 |
By default the text is shown in field 0 of the status bar. |
By default the text is shown in field 0 of the status bar. |
406 |
Override this method in derived classes to put it into a |
Override this method in derived classes to put it into a |
407 |
different field of the statusbar. |
different field of the statusbar. |
408 |
""" |
|
409 |
|
For historical reasons this method is called set_position_text |
410 |
|
because at first the text was always either the current position |
411 |
|
or the empty string. Now it can contain other messages as well. |
412 |
|
The method will be renamed at one point. |
413 |
|
""" |
414 |
|
# Note: If this method is renamed we should perhaps think about |
415 |
|
# some backwards compatibility measures for projects like |
416 |
|
# GREAT-ER which override this method. |
417 |
self.SetStatusText(text) |
self.SetStatusText(text) |
418 |
|
|
419 |
def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw): |
def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw): |
432 |
dialog.Show(True) |
dialog.Show(True) |
433 |
else: |
else: |
434 |
dialog.Raise() |
dialog.Raise() |
435 |
|
|
436 |
def save_modified_session(self, can_veto = 1): |
def save_modified_session(self, can_veto = 1): |
437 |
"""If the current session has been modified, ask the user |
"""If the current session has been modified, ask the user |
438 |
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 |
443 |
a cancel button, otherwise not. |
a cancel button, otherwise not. |
444 |
""" |
""" |
445 |
if self.application.session.WasModified(): |
if self.application.session.WasModified(): |
446 |
flags = wxYES_NO | wxICON_QUESTION |
flags = wx.YES_NO | wx.ICON_QUESTION |
447 |
if can_veto: |
if can_veto: |
448 |
flags = flags | wxCANCEL |
flags = flags | wx.CANCEL |
449 |
result = self.RunMessageBox(_("Exit"), |
result = self.RunMessageBox(_("Exit"), |
450 |
_("The session has been modified." |
_("The session has been modified." |
451 |
" Do you want to save it?"), |
" Do you want to save it?"), |
452 |
flags) |
flags) |
453 |
if result == wxID_YES: |
if result == wx.ID_YES: |
454 |
self.SaveSession() |
self.SaveSession() |
455 |
else: |
else: |
456 |
result = wxID_NO |
result = wx.ID_NO |
457 |
return result |
return result |
458 |
|
|
459 |
def NewSession(self): |
def NewSession(self): |
460 |
if self.save_modified_session() != wxID_CANCEL: |
if self.save_modified_session() != wx.ID_CANCEL: |
461 |
self.application.SetSession(create_empty_session()) |
self.application.SetSession(create_empty_session()) |
462 |
|
|
463 |
def OpenSession(self): |
def OpenSession(self): |
464 |
if self.save_modified_session() != wxID_CANCEL: |
if self.save_modified_session() != wx.ID_CANCEL: |
465 |
dlg = wxFileDialog(self, _("Open Session"), |
dlg = wx.FileDialog(self, _("Open Session"), |
466 |
self.application.Path("data"), "", |
self.application.Path("data"), "", |
467 |
"Thuban Session File (*.thuban)|*.thuban", |
"Thuban Session File (*.thuban)|*.thuban", |
468 |
wxOPEN) |
wx.OPEN) |
469 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
470 |
self.application.OpenSession(dlg.GetPath(), |
self.application.OpenSession(dlg.GetPath(), |
471 |
self.run_db_param_dialog) |
self.run_db_param_dialog) |
472 |
self.application.SetPath("data", dlg.GetPath()) |
self.application.SetPath("data", dlg.GetPath()) |
484 |
self.application.SaveSession() |
self.application.SaveSession() |
485 |
|
|
486 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
487 |
dlg = wxFileDialog(self, _("Save Session As"), |
dlg = wx.FileDialog(self, _("Save Session As"), |
488 |
self.application.Path("data"), "", |
self.application.Path("data"), "", |
489 |
"Thuban Session File (*.thuban)|*.thuban", |
"Thuban Session File (*.thuban)|*.thuban", |
490 |
wxSAVE|wxOVERWRITE_PROMPT) |
wx.SAVE|wx.OVERWRITE_PROMPT) |
491 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
492 |
self.application.session.SetFilename(dlg.GetPath()) |
self.application.session.SetFilename(dlg.GetPath()) |
493 |
self.application.SaveSession() |
self.application.SaveSession() |
494 |
self.application.SetPath("data",dlg.GetPath()) |
self.application.SetPath("data",dlg.GetPath()) |
499 |
|
|
500 |
def OnClose(self, event): |
def OnClose(self, event): |
501 |
result = self.save_modified_session(can_veto = event.CanVeto()) |
result = self.save_modified_session(can_veto = event.CanVeto()) |
502 |
if result == wxID_CANCEL: |
if result == wx.ID_CANCEL: |
503 |
event.Veto() |
event.Veto() |
504 |
else: |
else: |
505 |
# FIXME: it would be better to tie the unsubscription to |
# FIXME: it would be better to tie the unsubscription to |
506 |
# wx's destroy event, but that isn't implemented for wxGTK |
# wx's destroy event, but that isn't implemented for wxGTK |
507 |
# yet. |
# yet. |
508 |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
for channel in self.update_status_bar_messages: |
509 |
|
self.canvas.Unsubscribe(channel, self.update_status_bar) |
510 |
|
|
511 |
DockFrame.OnClose(self, event) |
DockFrame.OnClose(self, event) |
512 |
for dlg in self.dialogs.values(): |
for dlg in self.dialogs.values(): |
513 |
dlg.Destroy() |
dlg.Destroy() |
558 |
dialog.Raise() |
dialog.Raise() |
559 |
|
|
560 |
def AddLayer(self): |
def AddLayer(self): |
561 |
dlg = wxFileDialog(self, _("Select one or more data files"), |
dlg = wx.FileDialog(self, _("Select one or more data files"), |
562 |
self.application.Path("data"), "", |
self.application.Path("data"), "", |
563 |
_("Shapefiles (*.shp)") + "|*.shp;*.SHP|" + |
_("Shapefiles (*.shp)") + "|*.shp;*.SHP|" + |
564 |
_("All Files (*.*)") + "|*.*", |
_("All Files (*.*)") + "|*.*", |
565 |
wxOPEN | wxMULTIPLE) |
wx.OPEN | wx.MULTIPLE) |
566 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
567 |
filenames = dlg.GetPaths() |
filenames = dlg.GetPaths() |
568 |
for filename in filenames: |
for filename in filenames: |
569 |
title = os.path.splitext(os.path.basename(filename))[0] |
title = os.path.splitext(os.path.basename(filename))[0] |
586 |
dlg.Destroy() |
dlg.Destroy() |
587 |
|
|
588 |
def AddRasterLayer(self): |
def AddRasterLayer(self): |
589 |
dlg = wxFileDialog(self, _("Select an image file"), |
dlg = wx.FileDialog(self, _("Select an image file"), |
590 |
self.application.Path("data"), "", "*.*", |
self.application.Path("data"), "", "*.*", |
591 |
wxOPEN) |
wx.OPEN) |
592 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
593 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
594 |
title = os.path.splitext(os.path.basename(filename))[0] |
title = os.path.splitext(os.path.basename(filename))[0] |
595 |
map = self.canvas.Map() |
map = self.canvas.Map() |
614 |
session = self.application.Session() |
session = self.application.Session() |
615 |
dlg = ChooseDBTableDialog(self, self.application.Session()) |
dlg = ChooseDBTableDialog(self, self.application.Session()) |
616 |
|
|
617 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
618 |
dbconn, dbtable, id_column, geo_column = dlg.GetTable() |
dbconn, dbtable, id_column, geo_column = dlg.GetTable() |
619 |
try: |
try: |
620 |
title = str(dbtable) |
title = str(dbtable) |
760 |
|
|
761 |
if dialog is None: |
if dialog is None: |
762 |
map = self.canvas.Map() |
map = self.canvas.Map() |
763 |
dialog = projdialog.ProjFrame(self, name, |
dialog = projdialog.ProjFrame(self, name, |
764 |
_("Map Projection: %s") % map.Title(), map) |
_("Map Projection: %s") % map.Title(), map) |
765 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
766 |
dialog.Show() |
dialog.Show() |
775 |
|
|
776 |
if dialog is None: |
if dialog is None: |
777 |
map = self.canvas.Map() |
map = self.canvas.Map() |
778 |
dialog = projdialog.ProjFrame(self, name, |
dialog = projdialog.ProjFrame(self, name, |
779 |
_("Layer Projection: %s") % layer.Title(), layer) |
_("Layer Projection: %s") % layer.Title(), layer) |
780 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
781 |
dialog.Show() |
dialog.Show() |
831 |
dialog = self.FindRegisteredDock(name) |
dialog = self.FindRegisteredDock(name) |
832 |
|
|
833 |
if dialog is None: |
if dialog is None: |
834 |
dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT) |
dialog = self.CreateDock(name, -1, _("Legend"), wx.LAYOUT_LEFT) |
835 |
legend.LegendPanel(dialog, None, self) |
legend.LegendPanel(dialog, None, self) |
836 |
dialog.Dock() |
dialog.Dock() |
837 |
dialog.GetPanel().SetMap(self.Map()) |
dialog.GetPanel().SetMap(self.Map()) |
841 |
|
|
842 |
def LegendShown(self): |
def LegendShown(self): |
843 |
"""Return true iff the legend is currently open""" |
"""Return true iff the legend is currently open""" |
844 |
dialog = self.FindRegisteredDock("legend") |
dialog = self.FindRegisteredDock("legend") |
845 |
return dialog is not None and dialog.IsShown() |
return dialog is not None and dialog.IsShown() |
846 |
|
|
847 |
def TableOpen(self): |
def TableOpen(self): |
848 |
dlg = wxFileDialog(self, _("Open Table"), |
dlg = wx.FileDialog(self, _("Open Table"), |
849 |
self.application.Path("data"), "", |
self.application.Path("data"), "", |
850 |
_("DBF Files (*.dbf)") + "|*.dbf|" + |
_("DBF Files (*.dbf)") + "|*.dbf|" + |
851 |
#_("CSV Files (*.csv)") + "|*.csv|" + |
#_("CSV Files (*.csv)") + "|*.csv|" + |
852 |
_("All Files (*.*)") + "|*.*", |
_("All Files (*.*)") + "|*.*", |
853 |
wxOPEN) |
wx.OPEN) |
854 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
855 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
856 |
dlg.Destroy() |
dlg.Destroy() |
857 |
try: |
try: |
870 |
lst = [(t.Title(), t) for t in tables] |
lst = [(t.Title(), t) for t in tables] |
871 |
lst.sort() |
lst.sort() |
872 |
titles = [i[0] for i in lst] |
titles = [i[0] for i in lst] |
873 |
dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"), |
dlg = MultipleChoiceDialog(self, _("Pick the tables to close:"), |
874 |
_("Close Table"), titles, |
_("Close Table"), titles, |
875 |
size = (400, 300), |
size = (400, 300), |
876 |
style = wxDEFAULT_DIALOG_STYLE | |
style = wx.DEFAULT_DIALOG_STYLE | |
877 |
wxRESIZE_BORDER) |
wx.RESIZE_BORDER) |
878 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
879 |
for i in dlg.GetValue(): |
for i in dlg.GetValue(): |
880 |
self.application.session.RemoveTable(lst[i][1]) |
self.application.session.RemoveTable(lst[i][1]) |
881 |
|
|
891 |
lst = [(t.Title(), t) for t in tables] |
lst = [(t.Title(), t) for t in tables] |
892 |
lst.sort() |
lst.sort() |
893 |
titles = [i[0] for i in lst] |
titles = [i[0] for i in lst] |
894 |
dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"), |
dlg = MultipleChoiceDialog(self, _("Pick the table to show:"), |
895 |
_("Show Table"), titles, |
_("Show Table"), titles, |
896 |
size = (400,300), |
size = (400,300), |
897 |
style = wxDEFAULT_DIALOG_STYLE | |
style = wx.DEFAULT_DIALOG_STYLE | |
898 |
wxRESIZE_BORDER) |
wx.RESIZE_BORDER) |
899 |
if (dlg.ShowModal() == wxID_OK): |
if (dlg.ShowModal() == wx.ID_OK): |
900 |
for i in dlg.GetValue(): |
for i in dlg.GetValue(): |
901 |
# XXX: if the table belongs to a layer, open a |
# XXX: if the table belongs to a layer, open a |
902 |
# LayerTableFrame instead of QueryTableFrame |
# LayerTableFrame instead of QueryTableFrame |
926 |
lst = [(t.Title(), t) for t in tables] |
lst = [(t.Title(), t) for t in tables] |
927 |
lst.sort() |
lst.sort() |
928 |
titles = [i[0] for i in lst] |
titles = [i[0] for i in lst] |
929 |
dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"), |
dlg = MultipleChoiceDialog(self, _("Pick the table to rename:"), |
930 |
_("Rename Table"), titles, |
_("Rename Table"), titles, |
931 |
size = (400,300), |
size = (400,300), |
932 |
style = wxDEFAULT_DIALOG_STYLE | |
style = wx.DEFAULT_DIALOG_STYLE | |
933 |
wxRESIZE_BORDER) |
wx.RESIZE_BORDER) |
934 |
if (dlg.ShowModal() == wxID_OK): |
if (dlg.ShowModal() == wx.ID_OK): |
935 |
to_rename = [lst[i][1] for i in dlg.GetValue()] |
to_rename = [lst[i][1] for i in dlg.GetValue()] |
936 |
dlg.Destroy() |
dlg.Destroy() |
937 |
else: |
else: |
939 |
|
|
940 |
# Second, let the user rename the layers |
# Second, let the user rename the layers |
941 |
for table in to_rename: |
for table in to_rename: |
942 |
dlg = wxTextEntryDialog(self, _("Table Title:"), _("Rename Table"), |
dlg = wx.TextEntryDialog(self, _("Table Title:"), _("Rename Table"), |
943 |
table.Title()) |
table.Title()) |
944 |
try: |
try: |
945 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
946 |
title = dlg.GetValue() |
title = dlg.GetValue() |
947 |
if title != "": |
if title != "": |
948 |
table.SetTitle(title) |
table.SetTitle(title) |
988 |
self.canvas.Print() |
self.canvas.Print() |
989 |
|
|
990 |
def RenameMap(self): |
def RenameMap(self): |
991 |
dlg = wxTextEntryDialog(self, _("Map Title:"), _("Rename Map"), |
dlg = wx.TextEntryDialog(self, _("Map Title:"), _("Rename Map"), |
992 |
self.Map().Title()) |
self.Map().Title()) |
993 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
994 |
title = dlg.GetValue() |
title = dlg.GetValue() |
995 |
if title != "": |
if title != "": |
996 |
self.Map().SetTitle(title) |
self.Map().SetTitle(title) |
1001 |
"""Let the user rename the currently selected layer""" |
"""Let the user rename the currently selected layer""" |
1002 |
layer = self.current_layer() |
layer = self.current_layer() |
1003 |
if layer is not None: |
if layer is not None: |
1004 |
dlg = wxTextEntryDialog(self, _("Layer Title:"), _("Rename Layer"), |
dlg = wx.TextEntryDialog(self, _("Layer Title:"), _("Rename Layer"), |
1005 |
layer.Title()) |
layer.Title()) |
1006 |
try: |
try: |
1007 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
1008 |
title = dlg.GetValue() |
title = dlg.GetValue() |
1009 |
if title != "": |
if title != "": |
1010 |
layer.SetTitle(title) |
layer.SetTitle(title) |
1322 |
None, |
None, |
1323 |
"toggle_legend", |
"toggle_legend", |
1324 |
None] |
None] |
1325 |
if wxPlatform == '__WXMSW__': |
if wx.Platform == '__WXMSW__': |
1326 |
map_menu.append("map_export") |
map_menu.append("map_export") |
1327 |
map_menu.append("map_print") |
map_menu.append("map_print") |
1328 |
|
|
1361 |
# the main toolbar |
# the main toolbar |
1362 |
|
|
1363 |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
1364 |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
1365 |
"map_full_extent", |
"map_full_extent", |
1366 |
"layer_full_extent", |
"layer_full_extent", |
1367 |
"selected_full_extent", |
"selected_full_extent", |
1368 |
None, |
None, |
1369 |
"map_identify_tool", "map_label_tool"]) |
"map_identify_tool", "map_label_tool"]) |
1370 |
|
|