28 |
import tableview, identifyview |
import tableview, identifyview |
29 |
from menu import Menu |
from menu import Menu |
30 |
|
|
|
import main |
|
31 |
from context import Context |
from context import Context |
32 |
from command import registry, Command |
from command import registry, Command |
33 |
from messages import SELECTED_SHAPE, VIEW_POSITION |
from messages import SELECTED_SHAPE, VIEW_POSITION |
40 |
|
|
41 |
class MainWindow(wxFrame): |
class MainWindow(wxFrame): |
42 |
|
|
43 |
def __init__(self, parent, ID, interactor): |
def __init__(self, parent, ID, title, application, interactor, |
44 |
wxFrame.__init__(self, parent, ID, 'Thuban', |
initial_message = None, size = wxSize(-1, -1)): |
45 |
wxDefaultPosition, wxSize(400, 300)) |
wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
46 |
|
|
47 |
|
self.application = application |
48 |
self.interactor = interactor |
self.interactor = interactor |
49 |
|
|
50 |
self.CreateStatusBar() |
self.CreateStatusBar() |
51 |
self.SetStatusText("This is the wxPython-based " |
if initial_message: |
52 |
"Graphical User Interface for exploring geographic data") |
self.SetStatusText(initial_message) |
53 |
|
|
54 |
self.identify_view = None |
self.identify_view = None |
55 |
|
|
193 |
else: |
else: |
194 |
print "Unknown command %s" % name |
print "Unknown command %s" % name |
195 |
|
|
196 |
|
def Context(self): |
197 |
|
"""Return the context object for a command invoked from this window |
198 |
|
""" |
199 |
|
return Context(self.application, self.application.Session(), self) |
200 |
|
|
201 |
def invoke_command(self, event): |
def invoke_command(self, event): |
202 |
name = self.id_to_name.get(event.GetId()) |
name = self.id_to_name.get(event.GetId()) |
203 |
if name is not None: |
if name is not None: |
204 |
command = registry.Command(name) |
command = registry.Command(name) |
205 |
command.Execute(Context(main.app, main.app.Session(), self)) |
command.Execute(self.Context()) |
206 |
else: |
else: |
207 |
print "Unknown command ID %d" % event.GetId() |
print "Unknown command ID %d" % event.GetId() |
208 |
|
|
209 |
def update_command_ui(self, event): |
def update_command_ui(self, event): |
210 |
#print "update_command_ui", self.id_to_name[event.GetId()] |
#print "update_command_ui", self.id_to_name[event.GetId()] |
211 |
context = Context(main.app, main.app.Session(), self) |
context = self.Context() |
212 |
command = registry.Command(self.id_to_name[event.GetId()]) |
command = registry.Command(self.id_to_name[event.GetId()]) |
213 |
if command is not None: |
if command is not None: |
214 |
event.Enable(command.Sensitive(context)) |
event.Enable(command.Sensitive(context)) |
262 |
If the can_veto parameter is true (default) the dialog includes |
If the can_veto parameter is true (default) the dialog includes |
263 |
a cancel button, otherwise not. |
a cancel button, otherwise not. |
264 |
""" |
""" |
265 |
if main.app.session.WasModified(): |
if self.application.session.WasModified(): |
266 |
flags = wxYES_NO | wxICON_QUESTION |
flags = wxYES_NO | wxICON_QUESTION |
267 |
if can_veto: |
if can_veto: |
268 |
flags = flags | wxCANCEL |
flags = flags | wxCANCEL |
278 |
|
|
279 |
def NewSession(self): |
def NewSession(self): |
280 |
self.save_modified_session() |
self.save_modified_session() |
281 |
main.app.SetSession(create_empty_session()) |
self.application.SetSession(create_empty_session()) |
282 |
|
|
283 |
def OpenSession(self): |
def OpenSession(self): |
284 |
self.save_modified_session() |
self.save_modified_session() |
285 |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
286 |
"*.thuban", wxOPEN) |
"*.thuban", wxOPEN) |
287 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
288 |
main.app.OpenSession(dlg.GetPath()) |
self.application.OpenSession(dlg.GetPath()) |
289 |
dlg.Destroy() |
dlg.Destroy() |
290 |
|
|
291 |
def SaveSession(self): |
def SaveSession(self): |
292 |
if main.app.session.filename == None: |
if self.application.session.filename == None: |
293 |
self.SaveSessionAs() |
self.SaveSessionAs() |
294 |
main.app.SaveSession() |
self.application.SaveSession() |
295 |
|
|
296 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
297 |
dlg = wxFileDialog(self, "Enter a filename for session", ".", "", |
dlg = wxFileDialog(self, "Enter a filename for session", ".", "", |
298 |
"*.thuban", wxOPEN) |
"*.thuban", wxOPEN) |
299 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
300 |
main.app.session.SetFilename(dlg.GetPath()) |
self.application.session.SetFilename(dlg.GetPath()) |
301 |
main.app.SaveSession() |
self.application.SaveSession() |
302 |
dlg.Destroy() |
dlg.Destroy() |
303 |
|
|
304 |
def Exit(self): |
def Exit(self): |
318 |
name = "session_tree" |
name = "session_tree" |
319 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
320 |
if dialog is None: |
if dialog is None: |
321 |
dialog = tree.SessionTreeView(self, main.app, name) |
dialog = tree.SessionTreeView(self, self.application, name) |
322 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
323 |
dialog.Show(true) |
dialog.Show(true) |
324 |
else: |
else: |
360 |
if layer is not None: |
if layer is not None: |
361 |
self.canvas.Map().RemoveLayer(layer) |
self.canvas.Map().RemoveLayer(layer) |
362 |
|
|
363 |
|
def CanRemoveLayer(self): |
364 |
|
"""Return true if the currently selected layer can be deleted. |
365 |
|
|
366 |
|
If no layer is selected return false. |
367 |
|
|
368 |
|
The return value of this method determines whether the remove |
369 |
|
layer command is sensitive in menu. |
370 |
|
""" |
371 |
|
layer = self.current_layer() |
372 |
|
if layer is not None: |
373 |
|
return self.canvas.Map().CanRemoveLayer(layer) |
374 |
|
return 0 |
375 |
|
|
376 |
def RaiseLayer(self): |
def RaiseLayer(self): |
377 |
layer = self.current_layer() |
layer = self.current_layer() |
378 |
if layer is not None: |
if layer is not None: |
451 |
name = "table_view" + str(id(table)) |
name = "table_view" + str(id(table)) |
452 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
453 |
if dialog is None: |
if dialog is None: |
454 |
dialog = tableview.TableFrame(self, self.interactor, name, |
dialog = tableview.LayerTableFrame(self, self.interactor, name, |
455 |
"Table: %s" % layer.Title(), |
"Table: %s" % layer.Title(), |
456 |
layer, table) |
layer, table) |
457 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
458 |
dialog.Show(true) |
dialog.Show(true) |
459 |
else: |
else: |
527 |
helptext = helptext, icon = icon, |
helptext = helptext, icon = icon, |
528 |
sensitive = sensitive)) |
sensitive = sensitive)) |
529 |
|
|
530 |
|
def make_check_current_tool(toolname): |
531 |
|
"""Return a function that tests if the currently active tool is toolname |
532 |
|
|
533 |
|
The returned function can be called with the context and returns |
534 |
|
true iff the currently active tool's name is toolname. It's directly |
535 |
|
usable as the 'checked' callback of a command. |
536 |
|
""" |
537 |
|
def check_current_tool(context, name=toolname): |
538 |
|
return context.mainwindow.canvas.CurrentTool() == name |
539 |
|
return check_current_tool |
540 |
|
|
541 |
def _tool_command(name, title, method, toolname, helptext = "", |
def _tool_command(name, title, method, toolname, helptext = "", |
542 |
icon = ""): |
icon = ""): |
543 |
"""Add a tool command""" |
"""Add a tool command""" |
|
def check_current_tool(context, name=toolname): |
|
|
return context.mainwindow.canvas.CurrentTool() == name |
|
544 |
registry.Add(Command(name, title, call_method, args=(method,), |
registry.Add(Command(name, title, call_method, args=(method,), |
545 |
helptext = helptext, icon = icon, |
helptext = helptext, icon = icon, |
546 |
checked = check_current_tool)) |
checked = make_check_current_tool(toolname))) |
547 |
|
|
548 |
def _has_selected_layer(context): |
def _has_selected_layer(context): |
549 |
"""Return true if a layer is selected in the context""" |
"""Return true if a layer is selected in the context""" |
550 |
return context.mainwindow.has_selected_layer() |
return context.mainwindow.has_selected_layer() |
551 |
|
|
552 |
|
def _can_remove_layer(context): |
553 |
|
return context.mainwindow.CanRemoveLayer() |
554 |
|
|
555 |
|
def _has_tree_window_shown(context): |
556 |
|
"""Return true if the tree window is shown""" |
557 |
|
return context.mainwindow.get_open_dialog("session_tree") is None |
558 |
|
|
559 |
# File menu |
# File menu |
560 |
_method_command("new_session", "&New Session", "NewSession") |
_method_command("new_session", "&New Session", "NewSession") |
561 |
_method_command("open_session", "&Open Session", "OpenSession") |
_method_command("open_session", "&Open Session", "OpenSession") |
562 |
_method_command("save_session", "&Save Session", "SaveSession") |
_method_command("save_session", "&Save Session", "SaveSession") |
563 |
_method_command("save_session_as", "Save Session &As", "SaveSessionAs") |
_method_command("save_session_as", "Save Session &As", "SaveSessionAs") |
564 |
_method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree") |
_method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree", |
565 |
|
sensitive = _has_tree_window_shown) |
566 |
_method_command("exit", "&Exit", "Exit") |
_method_command("exit", "&Exit", "Exit") |
567 |
|
|
568 |
# Help menu |
# Help menu |
591 |
helptext = "Add a new layer to active map") |
helptext = "Add a new layer to active map") |
592 |
_method_command("layer_remove", "&Remove Layer", "RemoveLayer", |
_method_command("layer_remove", "&Remove Layer", "RemoveLayer", |
593 |
helptext = "Remove selected layer(s)", |
helptext = "Remove selected layer(s)", |
594 |
sensitive = _has_selected_layer) |
sensitive = _can_remove_layer) |
595 |
_method_command("layer_fill_color", "&Fill Color", "LayerFillColor", |
_method_command("layer_fill_color", "&Fill Color", "LayerFillColor", |
596 |
helptext = "Set the fill color of selected layer(s)", |
helptext = "Set the fill color of selected layer(s)", |
597 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |