1
# Copyright (c) 2005 by Intevation GmbH
3
# Jonathan Coles <jonathan@intevation.de>
5
# This program is free software under the GPL (>=v2)
6
# Read the file COPYING coming with Thuban for details.
8
"""Base class for Layer Properties dialogs"""
10
__version__ = "$Revision: 2700 $"
12
# $Id: layerproperties.py 2700 2006-09-18 14:27:02Z dpinte $
17
from Thuban.Model.messages import MAP_LAYERS_REMOVED, LAYER_SHAPESTORE_REPLACED
18
from dialogs import NonModalNonParentDialog
19
from messages import MAP_REPLACED
21
ID_PROPERTY_REVERT = 4002
22
ID_PROPERTY_TRY = 4008
23
ID_PROPERTY_TITLE = 4012
25
class LayerProperties(NonModalNonParentDialog):
27
def __init__(self, parent, name, layer):
29
NonModalNonParentDialog.__init__(self, parent, name, "")
31
self.SetTitle(layer.Title())
33
self.parent.Subscribe(MAP_REPLACED, self.map_replaced)
35
self.map = parent.Map()
37
self.map.Subscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
39
self.layout_recurse = False
41
def dialog_layout(self, *args, **kw):
43
if self.layout_recurse: return
44
self.layout_recurse = True
46
panel = wx.Panel(self, -1)
48
topBox = wx.BoxSizer(wx.VERTICAL)
49
panelBox = wx.BoxSizer(wx.VERTICAL)
53
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)
57
text_title = wx.TextCtrl(panel, ID_PROPERTY_TITLE, self.layer.Title())
58
text_title.SetInsertionPointEnd()
59
sizer.Add(text_title, 1, wx.GROW | wx.RIGHT, 0)
61
panelBox.Add(sizer, 0, wx.GROW | wx.ALL, 4)
64
panelBox.Add(wx.StaticText(panel, -1,
65
_("Layer Type: %s") % self.layer.Type()),
66
0, wx.ALIGN_LEFT | wx.ALL, 4)
69
proj = self.layer.GetProjection()
71
text = _("Projection: None")
73
text = _("Projection: %s") % proj.Label()
75
panelBox.Add(wx.StaticText(panel, -1, text), 0, wx.ALIGN_LEFT | wx.ALL, 4)
77
self.dialog_layout(panel, panelBox)
79
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
button_ok.SetDefault()
85
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)
91
panel.SetAutoLayout(True)
92
panel.SetSizer(panelBox)
94
panelBox.SetSizeHints(panel)
96
topBox.Add(panel, 1, wx.GROW | wx.ALL, 4)
97
topBox.Add(buttonBox, 0, wx.ALIGN_RIGHT|wx.ALL, 10)
99
self.SetAutoLayout(True)
100
self.SetSizer(topBox)
102
topBox.SetSizeHints(self)
107
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)
113
######################
115
text_title.SetFocus()
116
self.haveApplied = False
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)
124
def map_layers_removed(self):
125
"""Subscribed to MAP_LAYERS_REMOVED. If this layer was removed,
128
if self.layer not in self.map.Layers():
131
def map_replaced(self, *args):
132
"""Subscribed to the mainwindow's MAP_REPLACED message. Close self."""
135
def OnTry(self, event):
138
def OnOK(self, event):
141
def OnClose(self, event):
142
self.unsubscribe_messages()
143
NonModalNonParentDialog.OnClose(self, event)
145
def OnCloseBtn(self, event):
146
"""Close is similar to Cancel except that any changes that were
147
made and applied remain applied.
152
def OnRevert(self, event):
155
def SetTitle(self, title):
156
"""Set the title of the dialog."""
160
NonModalNonParentDialog.SetTitle(self, _("Layer Properties") + title)
162
def OnTitleChanged(self, event):
163
"""Update the dialog title when the user changed the layer name."""
164
obj = event.GetEventObject()
166
self.layer.SetTitle(obj.GetValue())
167
self.SetTitle(self.layer.Title())