1 |
bh |
6 |
# Copyright (c) 2001 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Bernhard Herzog <[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 |
|
|
__version__ = "$Revision$" |
9 |
|
|
|
10 |
|
|
from wxPython.wx import * |
11 |
|
|
from wxPython.grid import * |
12 |
|
|
|
13 |
|
|
import view |
14 |
bh |
29 |
from dialogs import NonModalDialog |
15 |
bh |
6 |
from messages import SELECTED_SHAPE |
16 |
|
|
|
17 |
|
|
class IdentifyListCtrl(wxListCtrl): |
18 |
|
|
|
19 |
bh |
29 |
def __init__(self, parent, id): |
20 |
bh |
6 |
wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT) |
21 |
|
|
|
22 |
|
|
self.InsertColumn(0, "Field") |
23 |
|
|
self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER) |
24 |
|
|
self.InsertColumn(1, "Value") |
25 |
|
|
self.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER) |
26 |
|
|
|
27 |
|
|
def fill_list(self, layer, shape): |
28 |
|
|
self.DeleteAllItems() |
29 |
|
|
|
30 |
|
|
if shape is not None: |
31 |
|
|
table = layer.shapetable |
32 |
|
|
num_cols = table.field_count() |
33 |
|
|
num_rows = table.record_count() |
34 |
|
|
|
35 |
|
|
names = [] |
36 |
|
|
for i in range(num_cols): |
37 |
|
|
type, name, length, decc = table.field_info(i) |
38 |
|
|
names.append(name) |
39 |
|
|
record = table.read_record(shape) |
40 |
|
|
i = 0 |
41 |
|
|
for name in names: |
42 |
|
|
value = record[name] |
43 |
|
|
i = self.InsertStringItem(i, name) |
44 |
|
|
self.SetStringItem(i, 1, str(value)) |
45 |
|
|
|
46 |
|
|
def selected_shape(self, layer, shape): |
47 |
|
|
self.fill_list(layer, shape) |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
bh |
29 |
class IdentifyView(NonModalDialog): |
52 |
bh |
6 |
|
53 |
bh |
29 |
def __init__(self, parent, interactor, name): |
54 |
|
|
NonModalDialog.__init__(self, parent, interactor, name, |
55 |
|
|
"Identify Shape") |
56 |
|
|
self.interactor.Subscribe(SELECTED_SHAPE, self.selected_shape) |
57 |
|
|
|
58 |
bh |
6 |
panel = wxPanel(self, -1, style = wxWANTS_CHARS) |
59 |
bh |
29 |
self.list = IdentifyListCtrl(panel, -1) |
60 |
bh |
6 |
|
61 |
|
|
sizer = wxBoxSizer(wxVERTICAL) |
62 |
|
|
sizer.Add(self.list, 1, wx.wxEXPAND| wx.wxALL, 0) |
63 |
|
|
|
64 |
|
|
panel.SetAutoLayout(true) |
65 |
|
|
panel.SetSizer(sizer) |
66 |
|
|
sizer.Fit(panel) |
67 |
bh |
29 |
|
68 |
|
|
def OnClose(self, event): |
69 |
|
|
self.interactor.Unsubscribe(SELECTED_SHAPE, self.selected_shape) |
70 |
|
|
NonModalDialog.OnClose(self, event) |
71 |
|
|
|
72 |
|
|
def selected_shape(self, layer, shape): |
73 |
|
|
self.list.selected_shape(layer, shape) |