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() |
# creat the menubar from the main_menu description |
58 |
|
self.SetMenuBar(self.build_menu_bar(main_menu)) |
59 |
|
|
60 |
menu = wxMenu() |
# Similarly, create the toolbar from main_toolbar |
61 |
menuBar.Append(menu, "&File"); |
toolbar = self.build_toolbar(main_toolbar) |
|
for name in ["new_session", "open_session", None, |
|
|
"save_session", "save_session_as", None, |
|
|
"show_session_tree", 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) |
|
|
|
|
|
# toolbar |
|
|
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
|
|
|
|
|
# set the size of the tools' bitmaps. Not needed on wxGTK, but |
|
|
# on Windows. We probably shouldn't hardwire the bitmap size |
|
|
# here |
|
|
toolbar.SetToolBitmapSize(wxSize(24, 24)) |
|
|
|
|
|
for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
|
|
"map_identify_tool", "map_label_tool", "map_full_extent"]: |
|
|
self.add_toolbar_command(toolbar, name) |
|
62 |
# call Realize to make sure that the tools appear. |
# call Realize to make sure that the tools appear. |
63 |
toolbar.Realize() |
toolbar.Realize() |
64 |
|
|
90 |
self.name_to_id[name] = ID |
self.name_to_id[name] = ID |
91 |
self.id_to_name[ID] = name |
self.id_to_name[ID] = name |
92 |
return ID |
return ID |
93 |
|
|
94 |
|
def build_menu_bar(self, menudesc): |
95 |
|
"""Build and return the menu bar from the menu description""" |
96 |
|
menu_bar = wxMenuBar() |
97 |
|
|
98 |
|
for item in menudesc.items: |
99 |
|
# here the items must all be Menu instances themselves |
100 |
|
menu_bar.Append(self.build_menu(item), item.title) |
101 |
|
|
102 |
|
return menu_bar |
103 |
|
|
104 |
|
def build_menu(self, menudesc): |
105 |
|
"""Build and return a wxMenu from a menudescription""" |
106 |
|
wxmenu = wxMenu() |
107 |
|
last = None |
108 |
|
for item in menudesc.items: |
109 |
|
# here the items must all be Menu instances themselves |
110 |
|
if item is None: |
111 |
|
# a separator. Only add one if the last item was not a |
112 |
|
# separator |
113 |
|
if last is not None: |
114 |
|
wxmenu.AppendSeparator() |
115 |
|
elif isinstance(item, Menu): |
116 |
|
# a submenu |
117 |
|
wxmenu.AppendMenu(wxNewId(), item.title, self.build_menu(item)) |
118 |
|
else: |
119 |
|
# must the name the name of a command |
120 |
|
self.add_menu_command(wxmenu, item) |
121 |
|
last = item |
122 |
|
return wxmenu |
123 |
|
|
124 |
|
def build_toolbar(self, toolbardesc): |
125 |
|
"""Build and return the main toolbar window from a toolbar description |
126 |
|
|
127 |
|
The parameter should be an instance of the Menu class but it |
128 |
|
should not contain submenus. |
129 |
|
""" |
130 |
|
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
131 |
|
|
132 |
|
# set the size of the tools' bitmaps. Not needed on wxGTK, but |
133 |
|
# on Windows, although it doesn't work very well there. It seems |
134 |
|
# that only 16x16 icons are really supported on windows. |
135 |
|
# We probably shouldn't hardwire the bitmap size here. |
136 |
|
toolbar.SetToolBitmapSize(wxSize(24, 24)) |
137 |
|
|
138 |
|
for item in toolbardesc.items: |
139 |
|
if item is None: |
140 |
|
toolbar.AddSeparator() |
141 |
|
else: |
142 |
|
# assume it's a string. |
143 |
|
self.add_toolbar_command(toolbar, item) |
144 |
|
|
145 |
|
return toolbar |
146 |
|
|
147 |
def add_menu_command(self, menu, name): |
def add_menu_command(self, menu, name): |
148 |
"""Add the command with name name to the menu menu. |
"""Add the command with name name to the menu menu. |
149 |
|
|
554 |
"LayerTransparentFill", |
"LayerTransparentFill", |
555 |
helptext = "Do not fill the selected layer(s)", |
helptext = "Do not fill the selected layer(s)", |
556 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
557 |
_method_command("layer_ourline_color", "&Outline Color", "LayerOutlineColor", |
_method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor", |
558 |
helptext = "Set the outline color of selected layer(s)", |
helptext = "Set the outline color of selected layer(s)", |
559 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
560 |
_method_command("layer_no_outline", "&No Outline", "LayerNoOutline", |
_method_command("layer_no_outline", "&No Outline", "LayerNoOutline", |
575 |
_method_command("layer_show_table", "Show Ta&ble", "LayerShowTable", |
_method_command("layer_show_table", "Show Ta&ble", "LayerShowTable", |
576 |
helptext = "Show the selected layer's table", |
helptext = "Show the selected layer's table", |
577 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
578 |
|
|
579 |
|
|
580 |
|
# the menu structure |
581 |
|
main_menu = Menu("<main>", "<main>", |
582 |
|
[Menu("file", "&File", |
583 |
|
["new_session", "open_session", None, |
584 |
|
"save_session", "save_session_as", None, |
585 |
|
"show_session_tree", None, |
586 |
|
"exit"]), |
587 |
|
Menu("map", "&Map", |
588 |
|
["layer_add", "layer_remove", |
589 |
|
None, |
590 |
|
"map_projection", |
591 |
|
None, |
592 |
|
"map_zoom_in_tool", "map_zoom_out_tool", |
593 |
|
"map_pan_tool", "map_identify_tool", "map_label_tool", |
594 |
|
None, |
595 |
|
"map_full_extent", |
596 |
|
None, |
597 |
|
"map_print"]), |
598 |
|
Menu("layer", "&Layer", |
599 |
|
["layer_fill_color", "layer_transparent_fill", |
600 |
|
"layer_outline_color", "layer_no_outline", |
601 |
|
None, |
602 |
|
"layer_raise", "layer_lower", |
603 |
|
None, |
604 |
|
"layer_show", "layer_hide", |
605 |
|
None, |
606 |
|
"layer_show_table"]), |
607 |
|
Menu("help", "&Help", |
608 |
|
["help_about"])]) |
609 |
|
|
610 |
|
# the main toolbar |
611 |
|
|
612 |
|
main_toolbar = Menu("<toolbar>", "<toolbar>", |
613 |
|
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
614 |
|
"map_identify_tool", "map_label_tool", "map_full_extent"]) |