12 |
|
|
13 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
14 |
|
|
15 |
import sys, os |
import os |
16 |
|
|
17 |
from wxPython.wx import * |
from wxPython.wx import * |
18 |
|
|
19 |
import Thuban |
import Thuban |
20 |
from Thuban.Model.session import Session, create_empty_session |
from Thuban.Model.session import create_empty_session |
|
from Thuban.Model.map import Map |
|
21 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
22 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
23 |
from Thuban.Model.proj import Projection |
from Thuban.Model.proj import Projection |
26 |
import tree |
import tree |
27 |
import proj4dialog |
import proj4dialog |
28 |
import tableview, identifyview |
import tableview, identifyview |
29 |
|
from menu import Menu |
30 |
|
|
31 |
import main |
import main |
32 |
from command import registry, Command |
from command import registry, Command |
54 |
|
|
55 |
self.init_ids() |
self.init_ids() |
56 |
|
|
57 |
menuBar = wxMenuBar() |
#main_menu.print_menu() |
58 |
|
self.SetMenuBar(self.build_menu_bar(main_menu)) |
|
menu = wxMenu() |
|
|
menuBar.Append(menu, "&File"); |
|
|
for name in ["new_session", "open_session", None, |
|
|
"save_session", "save_session_as", None, |
|
|
"exit"]: |
|
|
self.add_menu_command(menu, name) |
|
|
|
|
|
menu = wxMenu() |
|
|
menuBar.Append(menu, "&Map"); |
|
|
for name in ["layer_add", "layer_remove", |
|
|
None, |
|
|
"map_projection", |
|
|
None, |
|
|
"map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
|
|
"map_identify_tool", "map_label_tool", |
|
|
None, |
|
|
"map_full_extent", |
|
|
None, |
|
|
"map_print"]: |
|
|
self.add_menu_command(menu, name) |
|
|
|
|
|
menu = wxMenu() |
|
|
menuBar.Append(menu, "&Layer"); |
|
|
for name in ["layer_fill_color", "layer_transparent_fill", |
|
|
"layer_ourline_color", "layer_no_outline", |
|
|
None, |
|
|
"layer_raise", "layer_lower", |
|
|
None, |
|
|
"layer_show", "layer_hide", |
|
|
None, |
|
|
"layer_show_table"]: |
|
|
self.add_menu_command(menu, name) |
|
|
|
|
|
menu = wxMenu() |
|
|
menuBar.Append(menu, "&Help"); |
|
|
self.add_menu_command(menu, "help_about") |
|
|
|
|
|
self.SetMenuBar(menuBar) |
|
59 |
|
|
60 |
# toolbar |
# toolbar |
61 |
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
99 |
self.name_to_id[name] = ID |
self.name_to_id[name] = ID |
100 |
self.id_to_name[ID] = name |
self.id_to_name[ID] = name |
101 |
return ID |
return ID |
102 |
|
|
103 |
|
def build_menu_bar(self, menudesc): |
104 |
|
"""Build and return the menu bar from the menu description""" |
105 |
|
menu_bar = wxMenuBar() |
106 |
|
|
107 |
|
for item in menudesc.items: |
108 |
|
# here the items must all be Menu instances themselves |
109 |
|
menu_bar.Append(self.build_menu(item), item.title) |
110 |
|
|
111 |
|
return menu_bar |
112 |
|
|
113 |
|
def build_menu(self, menudesc): |
114 |
|
"""Build and return a wxMenu from a menudescription""" |
115 |
|
wxmenu = wxMenu() |
116 |
|
last = None |
117 |
|
for item in menudesc.items: |
118 |
|
# here the items must all be Menu instances themselves |
119 |
|
if item is None: |
120 |
|
# a separator. Only add one if the last item was not a |
121 |
|
# separator |
122 |
|
if last is not None: |
123 |
|
wxmenu.AppendSeparator() |
124 |
|
elif isinstance(item, Menu): |
125 |
|
# a submenu |
126 |
|
wxmenu.AppendMenu(wxNewId(), item.title, self.build_menu(item)) |
127 |
|
else: |
128 |
|
# must the name the name of a command |
129 |
|
self.add_menu_command(wxmenu, item) |
130 |
|
last = item |
131 |
|
return wxmenu |
132 |
|
|
133 |
def add_menu_command(self, menu, name): |
def add_menu_command(self, menu, name): |
134 |
"""Add the command with name name to the menu menu. |
"""Add the command with name name to the menu menu. |
135 |
|
|
188 |
event.Check(command.Checked(self)) |
event.Check(command.Checked(self)) |
189 |
|
|
190 |
def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION): |
def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION): |
191 |
"""Run a modla message box with the given text, title and flags |
"""Run a modal message box with the given text, title and flags |
192 |
and return the result""" |
and return the result""" |
193 |
dlg = wxMessageDialog(self, text, title, flags) |
dlg = wxMessageDialog(self, text, title, flags) |
194 |
result = dlg.ShowModal() |
result = dlg.ShowModal() |
254 |
def OpenSession(self): |
def OpenSession(self): |
255 |
self.save_modified_session() |
self.save_modified_session() |
256 |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
257 |
"*.session", wxOPEN) |
"*.thuban", wxOPEN) |
258 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
259 |
main.app.OpenSession(dlg.GetPath()) |
main.app.OpenSession(dlg.GetPath()) |
260 |
dlg.Destroy() |
dlg.Destroy() |
266 |
|
|
267 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
268 |
dlg = wxFileDialog(self, "Enter a filename for session", ".", "", |
dlg = wxFileDialog(self, "Enter a filename for session", ".", "", |
269 |
"*.session", wxOPEN) |
"*.thuban", wxOPEN) |
270 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
271 |
main.app.session.SetFilename(dlg.GetPath()) |
main.app.session.SetFilename(dlg.GetPath()) |
272 |
main.app.SaveSession() |
main.app.SaveSession() |
503 |
_method_command("open_session", "&Open Session", "OpenSession") |
_method_command("open_session", "&Open Session", "OpenSession") |
504 |
_method_command("save_session", "&Save Session", "SaveSession") |
_method_command("save_session", "&Save Session", "SaveSession") |
505 |
_method_command("save_session_as", "Save Session &As", "SaveSessionAs") |
_method_command("save_session_as", "Save Session &As", "SaveSessionAs") |
506 |
|
_method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree") |
507 |
_method_command("exit", "&Exit", "Exit") |
_method_command("exit", "&Exit", "Exit") |
508 |
|
|
509 |
# Help menu |
# Help menu |
540 |
"LayerTransparentFill", |
"LayerTransparentFill", |
541 |
helptext = "Do not fill the selected layer(s)", |
helptext = "Do not fill the selected layer(s)", |
542 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
543 |
_method_command("layer_ourline_color", "&Outline Color", "LayerOutlineColor", |
_method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor", |
544 |
helptext = "Set the outline color of selected layer(s)", |
helptext = "Set the outline color of selected layer(s)", |
545 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
546 |
_method_command("layer_no_outline", "&No Outline", "LayerNoOutline", |
_method_command("layer_no_outline", "&No Outline", "LayerNoOutline", |
561 |
_method_command("layer_show_table", "Show Ta&ble", "LayerShowTable", |
_method_command("layer_show_table", "Show Ta&ble", "LayerShowTable", |
562 |
helptext = "Show the selected layer's table", |
helptext = "Show the selected layer's table", |
563 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
564 |
|
|
565 |
|
|
566 |
|
# the menu structure |
567 |
|
main_menu = Menu("<main>", "<main>", |
568 |
|
[Menu("file", "&File", |
569 |
|
["new_session", "open_session", None, |
570 |
|
"save_session", "save_session_as", None, |
571 |
|
"show_session_tree", None, |
572 |
|
"exit"]), |
573 |
|
Menu("map", "&Map", |
574 |
|
["layer_add", "layer_remove", |
575 |
|
None, |
576 |
|
"map_projection", |
577 |
|
None, |
578 |
|
"map_zoom_in_tool", "map_zoom_out_tool", |
579 |
|
"map_pan_tool", "map_identify_tool", "map_label_tool", |
580 |
|
None, |
581 |
|
"map_full_extent", |
582 |
|
None, |
583 |
|
"map_print"]), |
584 |
|
Menu("layer", "&Layer", |
585 |
|
["layer_fill_color", "layer_transparent_fill", |
586 |
|
"layer_outline_color", "layer_no_outline", |
587 |
|
None, |
588 |
|
"layer_raise", "layer_lower", |
589 |
|
None, |
590 |
|
"layer_show", "layer_hide", |
591 |
|
None, |
592 |
|
"layer_show_table"]), |
593 |
|
Menu("help", "&Help", |
594 |
|
["help_about"])]) |