~ubuntu-branches/ubuntu/lucid/thuban/lucid

« back to all changes in this revision

Viewing changes to Thuban/UI/layerproperties.py

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2007-04-07 21:03:28 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070407210328-9a20n4dmbim3c3yc
Tags: 1.2.0-1
* New upstream release.
* Patchset updated.
* Policy bumped to 3.7.2 (no changes).
* Updated for current Python Policy by using python-support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2005 by Intevation GmbH
 
2
# Authors:
 
3
# Jonathan Coles <jonathan@intevation.de> 
 
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: 2700 $"
 
11
# $Source$
 
12
# $Id: layerproperties.py 2700 2006-09-18 14:27:02Z dpinte $
 
13
 
 
14
from Thuban import _
 
15
 
 
16
import wx
 
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 = wx.Panel(self, -1)
 
47
 
 
48
        topBox = wx.BoxSizer(wx.VERTICAL)
 
49
        panelBox = wx.BoxSizer(wx.VERTICAL)
 
50
 
 
51
        # Title
 
52
 
 
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)
 
56
 
 
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)
 
60
 
 
61
        panelBox.Add(sizer, 0, wx.GROW | wx.ALL, 4)
 
62
 
 
63
        # Type
 
64
        panelBox.Add(wx.StaticText(panel, -1,
 
65
            _("Layer Type: %s") % self.layer.Type()),
 
66
            0, wx.ALIGN_LEFT | wx.ALL, 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(wx.StaticText(panel, -1, text), 0, wx.ALIGN_LEFT | wx.ALL, 4)
 
76
 
 
77
        self.dialog_layout(panel, panelBox)
 
78
 
 
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()
 
84
 
 
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)
 
90
 
 
91
        panel.SetAutoLayout(True)
 
92
        panel.SetSizer(panelBox)
 
93
        panelBox.Fit(panel)
 
94
        panelBox.SetSizeHints(panel)
 
95
 
 
96
        topBox.Add(panel, 1, wx.GROW | wx.ALL, 4)
 
97
        topBox.Add(buttonBox, 0, wx.ALIGN_RIGHT|wx.ALL, 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
        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
 
 
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