30 |
|
|
31 |
import main |
import main |
32 |
from command import registry, Command |
from command import registry, Command |
33 |
|
from messages import SELECTED_SHAPE |
34 |
|
|
35 |
|
|
36 |
# the directory where the toolbar icons are stored |
# the directory where the toolbar icons are stored |
40 |
|
|
41 |
class MainWindow(wxFrame): |
class MainWindow(wxFrame): |
42 |
|
|
43 |
def __init__(self, parent, ID): |
def __init__(self, parent, ID, interactor): |
44 |
wxFrame.__init__(self, parent, ID, 'Thuban', |
wxFrame.__init__(self, parent, ID, 'Thuban', |
45 |
wxDefaultPosition, wxSize(400, 300)) |
wxDefaultPosition, wxSize(400, 300)) |
46 |
|
|
47 |
|
self.interactor = interactor |
48 |
|
|
49 |
self.CreateStatusBar() |
self.CreateStatusBar() |
50 |
self.SetStatusText("This is the wxPython-based " |
self.SetStatusText("This is the wxPython-based " |
51 |
"Graphical User Interface for exploring geographic data") |
"Graphical User Interface for exploring geographic data") |
104 |
toolbar.Realize() |
toolbar.Realize() |
105 |
|
|
106 |
# Create the map canvas |
# Create the map canvas |
107 |
canvas = view.MapCanvas(self, -1) |
canvas = view.MapCanvas(self, -1, interactor) |
108 |
self.canvas = canvas |
self.canvas = canvas |
109 |
|
|
110 |
|
self.init_dialogs() |
111 |
|
|
112 |
|
interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand) |
113 |
|
|
114 |
EVT_CLOSE(self, self.OnClose) |
EVT_CLOSE(self, self.OnClose) |
115 |
|
|
116 |
def init_ids(self): |
def init_ids(self): |
196 |
dlg.Destroy() |
dlg.Destroy() |
197 |
return result |
return result |
198 |
|
|
199 |
|
def init_dialogs(self): |
200 |
|
"""Initialize the dialog handling""" |
201 |
|
# The mainwindow maintains a dict mapping names to open |
202 |
|
# non-modal dialogs. The dialogs are put into this dict when |
203 |
|
# they're created and removed when they're closed |
204 |
|
self.dialogs = {} |
205 |
|
|
206 |
|
def add_dialog(self, name, dialog): |
207 |
|
if self.dialogs.has_key(name): |
208 |
|
raise RuntimeError("The Dialog named %s is already open" % name) |
209 |
|
self.dialogs[name] = dialog |
210 |
|
|
211 |
|
def dialog_open(self, name): |
212 |
|
return self.dialogs.has_key(name) |
213 |
|
|
214 |
|
def remove_dialog(self, name): |
215 |
|
del self.dialogs[name] |
216 |
|
|
217 |
|
def get_open_dialog(self, name): |
218 |
|
return self.dialogs.get(name) |
219 |
|
|
220 |
def NewSession(self): |
def NewSession(self): |
221 |
session = Session("") |
session = Session("") |
222 |
session.AddMap(Map("")) |
session.AddMap(Map("")) |
266 |
def SetMap(self, map): |
def SetMap(self, map): |
267 |
self.canvas.SetMap(map) |
self.canvas.SetMap(map) |
268 |
|
|
269 |
|
def ShowSessionTree(self): |
270 |
|
name = "session_tree" |
271 |
|
dialog = self.get_open_dialog(name) |
272 |
|
if dialog is None: |
273 |
|
dialog = tree.SessionTreeView(self, main.app, name) |
274 |
|
self.add_dialog(name, dialog) |
275 |
|
dialog.Show(true) |
276 |
|
else: |
277 |
|
# FIXME: bring dialog to front here |
278 |
|
pass |
279 |
|
|
280 |
def About(self): |
def About(self): |
281 |
self.RunMessageBox("About", |
self.RunMessageBox("About", |
282 |
("Thuban is a program for\n" |
("Thuban is a program for\n" |
327 |
|
|
328 |
If no layer is selected, return None |
If no layer is selected, return None |
329 |
""" |
""" |
330 |
tree = main.app.tree.tree |
return self.interactor.SelectedLayer() |
|
layer = tree.GetPyData(tree.GetSelection()) |
|
|
if isinstance(layer, Layer): |
|
|
return layer |
|
|
return None |
|
331 |
|
|
332 |
def has_selected_layer(self): |
def has_selected_layer(self): |
333 |
"""Return true if a layer is currently selected""" |
"""Return true if a layer is currently selected""" |
334 |
tree = main.app.tree.tree |
return self.interactor.HasSelectedLayer() |
|
layer = tree.GetPyData(tree.GetSelection()) |
|
|
return isinstance(layer, Layer) |
|
335 |
|
|
336 |
def choose_color(self): |
def choose_color(self): |
337 |
"""Run the color selection dialog and return the selected color. |
"""Run the color selection dialog and return the selected color. |
386 |
def LayerShowTable(self): |
def LayerShowTable(self): |
387 |
layer = self.current_layer() |
layer = self.current_layer() |
388 |
if layer is not None: |
if layer is not None: |
389 |
tv = tableview.TableFrame(self, layer.table) |
table = layer.table |
390 |
tv.Show(true) |
name = "table_view" + str(id(table)) |
391 |
|
dialog = self.get_open_dialog(name) |
392 |
|
if dialog is None: |
393 |
|
dialog = tableview.TableFrame(self, self.interactor, name, |
394 |
|
"Table: %s" % layer.Title(), |
395 |
|
layer, table) |
396 |
|
self.add_dialog(name, dialog) |
397 |
|
dialog.Show(true) |
398 |
|
else: |
399 |
|
# FIXME: bring dialog to front here |
400 |
|
pass |
401 |
|
|
402 |
def Projection(self): |
def Projection(self): |
403 |
map = self.canvas.Map() |
map = self.canvas.Map() |
425 |
self.canvas.PanTool() |
self.canvas.PanTool() |
426 |
|
|
427 |
def IdentifyTool(self): |
def IdentifyTool(self): |
|
if self.identify_view is None: |
|
|
self.identify_view = identifyview.IdentifyView(self, main.app) |
|
|
self.identify_view.Show(true) |
|
428 |
self.canvas.IdentifyTool() |
self.canvas.IdentifyTool() |
429 |
|
|
430 |
def LabelTool(self): |
def LabelTool(self): |
436 |
def PrintMap(self): |
def PrintMap(self): |
437 |
self.canvas.Print() |
self.canvas.Print() |
438 |
|
|
439 |
|
def identify_view_on_demand(self, layer, shape): |
440 |
|
name = "identify_view" |
441 |
|
if self.canvas.CurrentTool() == "IdentifyTool": |
442 |
|
if not self.dialog_open(name): |
443 |
|
dialog = identifyview.IdentifyView(self, self.interactor, name) |
444 |
|
self.add_dialog(name, dialog) |
445 |
|
dialog.Show(true) |
446 |
|
else: |
447 |
|
# FIXME: bring dialog to front? |
448 |
|
pass |
449 |
|
|
450 |
# |
# |
451 |
# Define all the commands available in the main window |
# Define all the commands available in the main window |