1 |
jonathan |
2551 |
# Copyright (c) 2005 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Jonathan Coles <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
"""Base class for Layer Properties dialogs""" |
9 |
|
|
|
10 |
|
|
__version__ = "$Revision$" |
11 |
|
|
# $Source$ |
12 |
|
|
# $Id$ |
13 |
|
|
|
14 |
|
|
from Thuban import _ |
15 |
|
|
|
16 |
dpinte |
2700 |
import wx |
17 |
jonathan |
2551 |
from Thuban.Model.messages import MAP_LAYERS_REMOVED, LAYER_SHAPESTORE_REPLACED |
18 |
|
|
from dialogs import NonModalNonParentDialog |
19 |
|
|
from messages import MAP_REPLACED |
20 |
|
|
|
21 |
|
|
ID_PROPERTY_REVERT = 4002 |
22 |
|
|
ID_PROPERTY_TRY = 4008 |
23 |
|
|
ID_PROPERTY_TITLE = 4012 |
24 |
|
|
|
25 |
|
|
class LayerProperties(NonModalNonParentDialog): |
26 |
|
|
|
27 |
|
|
def __init__(self, parent, name, layer): |
28 |
|
|
|
29 |
|
|
NonModalNonParentDialog.__init__(self, parent, name, "") |
30 |
|
|
|
31 |
|
|
self.SetTitle(layer.Title()) |
32 |
|
|
|
33 |
|
|
self.parent.Subscribe(MAP_REPLACED, self.map_replaced) |
34 |
|
|
self.layer = layer |
35 |
|
|
self.map = parent.Map() |
36 |
|
|
|
37 |
|
|
self.map.Subscribe(MAP_LAYERS_REMOVED, self.map_layers_removed) |
38 |
|
|
|
39 |
|
|
self.layout_recurse = False |
40 |
|
|
|
41 |
|
|
def dialog_layout(self, *args, **kw): |
42 |
|
|
|
43 |
|
|
if self.layout_recurse: return |
44 |
|
|
self.layout_recurse = True |
45 |
|
|
|
46 |
dpinte |
2700 |
panel = wx.Panel(self, -1) |
47 |
jonathan |
2551 |
|
48 |
dpinte |
2700 |
topBox = wx.BoxSizer(wx.VERTICAL) |
49 |
|
|
panelBox = wx.BoxSizer(wx.VERTICAL) |
50 |
jonathan |
2551 |
|
51 |
|
|
# Title |
52 |
|
|
|
53 |
dpinte |
2700 |
sizer = wx.BoxSizer(wx.HORIZONTAL) |
54 |
|
|
sizer.Add(wx.StaticText(panel, -1, _("Title: ")), |
55 |
|
|
0, wx.ALIGN_LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 4) |
56 |
jonathan |
2551 |
|
57 |
dpinte |
2700 |
text_title = wx.TextCtrl(panel, ID_PROPERTY_TITLE, self.layer.Title()) |
58 |
jonathan |
2551 |
text_title.SetInsertionPointEnd() |
59 |
dpinte |
2700 |
sizer.Add(text_title, 1, wx.GROW | wx.RIGHT, 0) |
60 |
jonathan |
2551 |
|
61 |
dpinte |
2700 |
panelBox.Add(sizer, 0, wx.GROW | wx.ALL, 4) |
62 |
jonathan |
2551 |
|
63 |
|
|
# Type |
64 |
dpinte |
2700 |
panelBox.Add(wx.StaticText(panel, -1, |
65 |
jonathan |
2551 |
_("Layer Type: %s") % self.layer.Type()), |
66 |
dpinte |
2700 |
0, wx.ALIGN_LEFT | wx.ALL, 4) |
67 |
jonathan |
2551 |
|
68 |
|
|
# Projection |
69 |
|
|
proj = self.layer.GetProjection() |
70 |
|
|
if proj is None: |
71 |
|
|
text = _("Projection: None") |
72 |
|
|
else: |
73 |
|
|
text = _("Projection: %s") % proj.Label() |
74 |
|
|
|
75 |
dpinte |
2700 |
panelBox.Add(wx.StaticText(panel, -1, text), 0, wx.ALIGN_LEFT | wx.ALL, 4) |
76 |
|
|
|
77 |
jonathan |
2551 |
self.dialog_layout(panel, panelBox) |
78 |
|
|
|
79 |
dpinte |
2700 |
button_try = wx.Button(self, ID_PROPERTY_TRY, _("Try")) |
80 |
|
|
button_revert = wx.Button(self, ID_PROPERTY_REVERT, _("Revert")) |
81 |
|
|
button_ok = wx.Button(self, wx.ID_OK, _("OK")) |
82 |
|
|
button_close = wx.Button(self, wx.ID_CANCEL, _("Close")) |
83 |
jonathan |
2551 |
button_ok.SetDefault() |
84 |
|
|
|
85 |
dpinte |
2700 |
buttonBox = wx.BoxSizer(wx.HORIZONTAL) |
86 |
|
|
buttonBox.Add(button_try, 0, wx.RIGHT|wx.EXPAND, 10) |
87 |
|
|
buttonBox.Add(button_revert, 0, wx.RIGHT|wx.EXPAND, 10) |
88 |
|
|
buttonBox.Add(button_ok, 0, wx.RIGHT|wx.EXPAND, 10) |
89 |
|
|
buttonBox.Add(button_close, 0, wx.RIGHT|wx.EXPAND, 0) |
90 |
jonathan |
2551 |
|
91 |
|
|
panel.SetAutoLayout(True) |
92 |
|
|
panel.SetSizer(panelBox) |
93 |
dpinte |
2700 |
panelBox.Fit(panel) |
94 |
|
|
panelBox.SetSizeHints(panel) |
95 |
jonathan |
2551 |
|
96 |
dpinte |
2700 |
topBox.Add(panel, 1, wx.GROW | wx.ALL, 4) |
97 |
|
|
topBox.Add(buttonBox, 0, wx.ALIGN_RIGHT|wx.ALL, 10) |
98 |
jonathan |
2551 |
|
99 |
|
|
self.SetAutoLayout(True) |
100 |
|
|
self.SetSizer(topBox) |
101 |
|
|
topBox.Fit(self) |
102 |
|
|
topBox.SetSizeHints(self) |
103 |
|
|
self.Layout() |
104 |
|
|
|
105 |
|
|
########### |
106 |
|
|
|
107 |
dpinte |
2700 |
self.Bind(wx.EVT_TEXT, self.OnTitleChanged, id=ID_PROPERTY_TITLE) |
108 |
|
|
self.Bind(wx.EVT_BUTTON, self.OnOK, id=wx.ID_OK) |
109 |
|
|
self.Bind(wx.EVT_BUTTON, self.OnTry, id=ID_PROPERTY_TRY) |
110 |
|
|
self.Bind(wx.EVT_BUTTON, self.OnCloseBtn, id=wx.ID_CANCEL) |
111 |
|
|
self.Bind(wx.EVT_BUTTON, self.OnRevert, id=ID_PROPERTY_REVERT) |
112 |
jonathan |
2551 |
|
113 |
|
|
###################### |
114 |
|
|
|
115 |
|
|
text_title.SetFocus() |
116 |
|
|
self.haveApplied = False |
117 |
|
|
|
118 |
|
|
|
119 |
|
|
def unsubscribe_messages(self): |
120 |
|
|
"""Unsubscribe from all messages.""" |
121 |
|
|
self.parent.Unsubscribe(MAP_REPLACED, self.map_replaced) |
122 |
|
|
self.map.Unsubscribe(MAP_LAYERS_REMOVED, self.map_layers_removed) |
123 |
|
|
|
124 |
|
|
def map_layers_removed(self): |
125 |
|
|
"""Subscribed to MAP_LAYERS_REMOVED. If this layer was removed, |
126 |
|
|
Close self. |
127 |
|
|
""" |
128 |
|
|
if self.layer not in self.map.Layers(): |
129 |
|
|
self.Close() |
130 |
|
|
|
131 |
|
|
def map_replaced(self, *args): |
132 |
|
|
"""Subscribed to the mainwindow's MAP_REPLACED message. Close self.""" |
133 |
|
|
self.Close() |
134 |
|
|
|
135 |
|
|
def OnTry(self, event): |
136 |
|
|
return |
137 |
|
|
|
138 |
|
|
def OnOK(self, event): |
139 |
|
|
self.Close() |
140 |
|
|
|
141 |
|
|
def OnClose(self, event): |
142 |
|
|
self.unsubscribe_messages() |
143 |
|
|
NonModalNonParentDialog.OnClose(self, event) |
144 |
|
|
|
145 |
|
|
def OnCloseBtn(self, event): |
146 |
|
|
"""Close is similar to Cancel except that any changes that were |
147 |
|
|
made and applied remain applied. |
148 |
|
|
""" |
149 |
|
|
|
150 |
|
|
self.Close() |
151 |
|
|
|
152 |
|
|
def OnRevert(self, event): |
153 |
|
|
return |
154 |
|
|
|
155 |
|
|
def SetTitle(self, title): |
156 |
|
|
"""Set the title of the dialog.""" |
157 |
|
|
if title != "": |
158 |
|
|
title = ": " + title |
159 |
|
|
|
160 |
|
|
NonModalNonParentDialog.SetTitle(self, _("Layer Properties") + title) |
161 |
|
|
|
162 |
|
|
def OnTitleChanged(self, event): |
163 |
|
|
"""Update the dialog title when the user changed the layer name.""" |
164 |
|
|
obj = event.GetEventObject() |
165 |
|
|
|
166 |
|
|
self.layer.SetTitle(obj.GetValue()) |
167 |
|
|
self.SetTitle(self.layer.Title()) |
168 |
|
|
|