/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/layerproperties.py
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/Thuban/UI/layerproperties.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2587 - (show annotations)
Wed Mar 23 15:30:27 2005 UTC (19 years, 11 months ago) by jonathan
Original Path: trunk/thuban/Thuban/UI/layerproperties.py
File MIME type: text/x-python
File size: 4963 byte(s)
Add support for adjusting the opacity of a raster layer.

1 # 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 from wxPython.wx import *
17 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 panel = wxPanel(self, -1)
47
48 topBox = wxBoxSizer(wxVERTICAL)
49 panelBox = wxBoxSizer(wxVERTICAL)
50
51 # Title
52
53 sizer = wxBoxSizer(wxHORIZONTAL)
54 sizer.Add(wxStaticText(panel, -1, _("Title: ")),
55 0, wxALIGN_LEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 4)
56
57 text_title = wxTextCtrl(panel, ID_PROPERTY_TITLE, self.layer.Title())
58 text_title.SetInsertionPointEnd()
59 sizer.Add(text_title, 1, wxGROW | wxRIGHT, 0)
60
61 panelBox.Add(sizer, 0, wxGROW | wxALL, 4)
62
63 # Type
64 panelBox.Add(wxStaticText(panel, -1,
65 _("Layer Type: %s") % self.layer.Type()),
66 0, wxALIGN_LEFT | wxALL, 4)
67
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 panelBox.Add(wxStaticText(panel, -1, text), 0, wxALIGN_LEFT | wxALL, 4)
76
77 self.dialog_layout(panel, panelBox)
78
79 button_try = wxButton(self, ID_PROPERTY_TRY, _("Try"))
80 button_revert = wxButton(self, ID_PROPERTY_REVERT, _("Revert"))
81 button_ok = wxButton(self, wxID_OK, _("OK"))
82 button_close = wxButton(self, wxID_CANCEL, _("Close"))
83 button_ok.SetDefault()
84
85 buttonBox = wxBoxSizer(wxHORIZONTAL)
86 buttonBox.Add(button_try, 0, wxRIGHT|wxEXPAND, 10)
87 buttonBox.Add(button_revert, 0, wxRIGHT|wxEXPAND, 10)
88 buttonBox.Add(button_ok, 0, wxRIGHT|wxEXPAND, 10)
89 buttonBox.Add(button_close, 0, wxRIGHT|wxEXPAND, 0)
90
91 panel.SetAutoLayout(True)
92 panel.SetSizer(panelBox)
93 panelBox.Fit(panel)
94 panelBox.SetSizeHints(panel)
95
96 topBox.Add(panel, 1, wxGROW | wxALL, 4)
97 topBox.Add(buttonBox, 0, wxALIGN_RIGHT|wxALL, 10)
98
99 self.SetAutoLayout(True)
100 self.SetSizer(topBox)
101 topBox.Fit(self)
102 topBox.SetSizeHints(self)
103 self.Layout()
104
105 ###########
106
107 EVT_TEXT(self, ID_PROPERTY_TITLE, self.OnTitleChanged)
108 EVT_BUTTON(self, wxID_OK, self.OnOK)
109 EVT_BUTTON(self, ID_PROPERTY_TRY, self.OnTry)
110 EVT_BUTTON(self, wxID_CANCEL, self.OnCloseBtn)
111 EVT_BUTTON(self, ID_PROPERTY_REVERT, self.OnRevert)
112
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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26