1 |
# Copyright (c) 2001, 2002 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
|
# Frank Koormann <[email protected]> |
5 |
# |
# |
6 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
7 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
8 |
|
|
9 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
10 |
|
|
11 |
from wxPython.wx import * |
import wx |
12 |
from wxPython.grid import * |
from wx import grid |
13 |
|
|
14 |
|
from Thuban import _ |
15 |
|
|
|
import view |
|
16 |
from dialogs import NonModalDialog |
from dialogs import NonModalDialog |
17 |
from controls import RecordListCtrl, RecordGridCtrl |
from controls import RecordListCtrl, RecordGridCtrl |
18 |
from messages import SELECTED_SHAPE |
from messages import SHAPES_SELECTED |
19 |
|
import main |
20 |
|
|
21 |
class IdentifyListCtrl(RecordListCtrl): |
class IdentifyListCtrl(RecordListCtrl): |
22 |
|
|
23 |
def selected_shape(self, layer, shape): |
def selected_shape(self, layer, shape): |
24 |
if layer is not None: |
if layer is not None: |
25 |
table = layer.shapetable |
table = layer.ShapeStore().Table() |
26 |
else: |
else: |
27 |
table = None |
table = None |
28 |
self.fill_list(table, shape) |
self.fill_list(table, shape) |
31 |
|
|
32 |
def selected_shape(self, layer, shape): |
def selected_shape(self, layer, shape): |
33 |
if layer is not None: |
if layer is not None: |
34 |
table = layer.shapetable |
table = layer.ShapeStore().Table() |
35 |
else: |
else: |
36 |
table = None |
table = None |
37 |
self.SetTableRecord(table, shape) |
self.SetTableRecord(table, shape) |
38 |
|
|
39 |
class IdentifyView(NonModalDialog): |
class IdentifyView(NonModalDialog): |
40 |
|
|
41 |
def __init__(self, parent, interactor, name): |
ID_STOP = 100 |
42 |
NonModalDialog.__init__(self, parent, interactor, name, |
|
43 |
"Identify Shape") |
def __init__(self, parent, name): |
44 |
self.interactor.Subscribe(SELECTED_SHAPE, self.selected_shape) |
NonModalDialog.__init__(self, parent, name, _("Identify Shape")) |
45 |
|
parent.Subscribe(SHAPES_SELECTED, self.selected_shape) |
46 |
panel = wxPanel(self, -1, style = wxWANTS_CHARS) |
|
47 |
#self.list = IdentifyListCtrl(panel, -1) |
top_box = wx.BoxSizer(wx.VERTICAL) |
48 |
self.list = IdentifyGridCtrl(panel) |
if main.options.attribute_editing_enabled: |
49 |
|
self.list = IdentifyGridCtrl(self) |
50 |
sizer = wxBoxSizer(wxVERTICAL) |
else: |
51 |
sizer.Add(self.list, 1, wx.wxEXPAND| wx.wxALL, 0) |
self.list = IdentifyListCtrl(self, -1) |
52 |
|
self.list.SetSize(wx.Size(305,200)) |
53 |
panel.SetAutoLayout(true) |
top_box.Add(self.list, 1, wx.EXPAND|wx.ALL, 4) |
54 |
panel.SetSizer(sizer) |
|
55 |
sizer.Fit(panel) |
box = wx.BoxSizer(wx.HORIZONTAL) |
56 |
|
box.Add(wx.Button(self, wx.ID_CLOSE, _("Close Window")), 0, wx.ALL, 4) |
57 |
|
box.Add(wx.Button(self, self.ID_STOP, _("Stop Identify Mode")), |
58 |
|
0, wx.ALL, 4) |
59 |
|
top_box.Add(box, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 4) |
60 |
|
|
61 |
|
self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE) |
62 |
|
self.Bind(wx.EVT_BUTTON, self.OnStop, id=self.ID_STOP) |
63 |
|
|
64 |
|
self.SetAutoLayout(True) |
65 |
|
self.SetSizer(top_box) |
66 |
|
top_box.Fit(self) |
67 |
|
top_box.SetSizeHints(self) |
68 |
|
|
69 |
|
# Make sure to reflect the current selection. |
70 |
|
self.selected_shape(parent.SelectedLayer(), parent.SelectedShapes()) |
71 |
|
|
72 |
def OnClose(self, event): |
def OnClose(self, event): |
73 |
self.interactor.Unsubscribe(SELECTED_SHAPE, self.selected_shape) |
self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape) |
74 |
NonModalDialog.OnClose(self, event) |
NonModalDialog.OnClose(self, event) |
75 |
|
|
76 |
def selected_shape(self, layer, shape): |
def OnStop(self, event): |
77 |
|
self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape) |
78 |
|
self.parent.canvas.SelectTool(None) |
79 |
|
NonModalDialog.OnClose(self, event) |
80 |
|
|
81 |
|
def selected_shape(self, layer, shapes): |
82 |
|
"""Subscribed to the SHAPES_SELECTED messages. |
83 |
|
|
84 |
|
If exactly one shape is selected, pass that shape id to the |
85 |
|
list's selected_shape method. Otherwise pass None as the shape |
86 |
|
id. |
87 |
|
""" |
88 |
|
if len(shapes) == 1: |
89 |
|
shape = shapes[0] |
90 |
|
else: |
91 |
|
shape = None |
92 |
self.list.selected_shape(layer, shape) |
self.list.selected_shape(layer, shape) |