1 |
# Copyright (c) 2001 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. |
11 |
from wxPython.wx import * |
from wxPython.wx import * |
12 |
from wxPython.grid import * |
from wxPython.grid import * |
13 |
|
|
14 |
import view |
from Thuban import _ |
|
from messages import SELECTED_SHAPE |
|
15 |
|
|
16 |
class IdentifyListCtrl(wxListCtrl): |
from dialogs import NonModalDialog |
17 |
|
from controls import RecordListCtrl, RecordGridCtrl |
18 |
|
from messages import SHAPES_SELECTED |
19 |
|
|
20 |
def __init__(self, parent, id, interactor): |
class IdentifyListCtrl(RecordListCtrl): |
|
wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT) |
|
|
self.interactor = interactor |
|
|
self.interactor.Subscribe(SELECTED_SHAPE, self.selected_shape) |
|
|
|
|
|
self.InsertColumn(0, "Field") |
|
|
self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER) |
|
|
self.InsertColumn(1, "Value") |
|
|
self.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER) |
|
|
|
|
|
def fill_list(self, layer, shape): |
|
|
self.DeleteAllItems() |
|
|
|
|
|
if shape is not None: |
|
|
table = layer.shapetable |
|
|
num_cols = table.field_count() |
|
|
num_rows = table.record_count() |
|
|
|
|
|
names = [] |
|
|
for i in range(num_cols): |
|
|
type, name, length, decc = table.field_info(i) |
|
|
names.append(name) |
|
|
record = table.read_record(shape) |
|
|
i = 0 |
|
|
for name in names: |
|
|
value = record[name] |
|
|
i = self.InsertStringItem(i, name) |
|
|
self.SetStringItem(i, 1, str(value)) |
|
21 |
|
|
22 |
def selected_shape(self, layer, shape): |
def selected_shape(self, layer, shape): |
23 |
self.fill_list(layer, shape) |
if layer is not None: |
24 |
|
table = layer.ShapeStore().Table() |
25 |
|
else: |
26 |
|
table = None |
27 |
|
self.fill_list(table, shape) |
28 |
|
|
29 |
|
class IdentifyGridCtrl(RecordGridCtrl): |
30 |
|
|
31 |
class IdentifyView(wxFrame): |
def selected_shape(self, layer, shape): |
32 |
|
if layer is not None: |
33 |
def __init__(self, parent, app): |
table = layer.ShapeStore().Table() |
34 |
# assume parent is Thuban's main window python object |
else: |
35 |
wxFrame.__init__(self, parent, -1, "Identify Shape") |
table = None |
36 |
panel = wxPanel(self, -1, style = wxWANTS_CHARS) |
self.SetTableRecord(table, shape) |
37 |
self.list = IdentifyListCtrl(panel, -1, app.interactor) |
|
38 |
|
class IdentifyView(NonModalDialog): |
39 |
sizer = wxBoxSizer(wxVERTICAL) |
|
40 |
sizer.Add(self.list, 1, wx.wxEXPAND| wx.wxALL, 0) |
ID_STOP = 100 |
41 |
|
|
42 |
panel.SetAutoLayout(true) |
def __init__(self, parent, name): |
43 |
panel.SetSizer(sizer) |
NonModalDialog.__init__(self, parent, name, _("Identify Shape")) |
44 |
sizer.Fit(panel) |
parent.Subscribe(SHAPES_SELECTED, self.selected_shape) |
45 |
|
|
46 |
|
top_box = wxBoxSizer(wxVERTICAL) |
47 |
|
#self.list = IdentifyGridCtrl(panel) |
48 |
|
self.list = IdentifyListCtrl(self, -1) |
49 |
|
self.list.SetSize(wxSize(305,200)) |
50 |
|
top_box.Add(self.list, 1, wxEXPAND|wxALL, 4) |
51 |
|
|
52 |
|
box = wxBoxSizer(wxHORIZONTAL) |
53 |
|
box.Add(wxButton(self, wxID_CLOSE, _("Close Window")), 0, wxALL, 4) |
54 |
|
box.Add(wxButton(self, self.ID_STOP, _("Stop Identify Mode")), |
55 |
|
0, wxALL, 4) |
56 |
|
top_box.Add(box, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 4) |
57 |
|
|
58 |
|
EVT_BUTTON(self, wxID_CLOSE, self.OnClose) |
59 |
|
EVT_BUTTON(self, self.ID_STOP, self.OnStop) |
60 |
|
|
61 |
|
self.SetAutoLayout(True) |
62 |
|
self.SetSizer(top_box) |
63 |
|
top_box.Fit(self) |
64 |
|
top_box.SetSizeHints(self) |
65 |
|
|
66 |
|
# Make sure to reflect the current selection. |
67 |
|
self.selected_shape(parent.SelectedLayer(), parent.SelectedShapes()) |
68 |
|
|
69 |
|
def OnClose(self, event): |
70 |
|
self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape) |
71 |
|
NonModalDialog.OnClose(self, event) |
72 |
|
|
73 |
|
def OnStop(self, event): |
74 |
|
self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape) |
75 |
|
self.parent.canvas.SelectTool(None) |
76 |
|
NonModalDialog.OnClose(self, event) |
77 |
|
|
78 |
|
def selected_shape(self, layer, shapes): |
79 |
|
"""Subscribed to the SHAPES_SELECTED messages. |
80 |
|
|
81 |
|
If exatly one shape is selected, pass that shape id to the |
82 |
|
list's selected_shape method. Otherwise pass None as the shape |
83 |
|
id. |
84 |
|
""" |
85 |
|
if len(shapes) == 1: |
86 |
|
shape = shapes[0] |
87 |
|
else: |
88 |
|
shape = None |
89 |
|
self.list.selected_shape(layer, shape) |