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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (show annotations)
Mon Sep 10 16:04:21 2001 UTC (23 years, 5 months ago) by bh
Original Path: trunk/thuban/Thuban/UI/controls.py
File MIME type: text/x-python
File size: 2272 byte(s)
New file with two classes RecordListCtrl and SelectableRecordListCtrl
that implement the code shared by the identify view and the label dialog

1 # 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
9 """Common Thuban specific control widgets"""
10
11 __version__ = "$Revision$"
12
13 from wxPython.wx import wxListCtrl, wxLC_REPORT, wxLIST_AUTOSIZE_USEHEADER, \
14 EVT_LIST_ITEM_SELECTED
15
16
17 class RecordListCtrl(wxListCtrl):
18
19 """List Control showing a single record from a thuban table"""
20
21 def __init__(self, parent, id):
22 wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT)
23
24 self.InsertColumn(0, "Field")
25 self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
26 self.InsertColumn(1, "Value")
27 self.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER)
28
29 # vaues maps row numbers to the corresponding python values
30 self.values = {}
31
32 def fill_list(self, table, shape):
33 """Fill self with the contents shape's record from table"""
34 self.DeleteAllItems()
35 values = {}
36
37 if shape is not None:
38 num_cols = table.field_count()
39
40 names = []
41 for i in range(num_cols):
42 type, name, length, decc = table.field_info(i)
43 names.append(name)
44 record = table.read_record(shape)
45
46 for i in range(len(names)):
47 name = names[i]
48 value = record[name]
49 self.InsertStringItem(i, name)
50 self.SetStringItem(i, 1, str(value))
51 values[i] = value
52
53 self.values = values
54
55 class SelectableRecordListCtrl(RecordListCtrl):
56
57 def __init__(self, parent, id):
58 RecordListCtrl.__init__(self, parent, id)
59
60 # selected is the index of the selected record or -1 if none is
61 # selected
62 self.selected = -1
63 EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected)
64
65 def OnItemSelected(self, event):
66 """Event handler. Update the selected instvar"""
67 self.selected = event.m_itemIndex
68
69 def GetValue(self):
70 """Return the currently selected value. None if no value is selected"""
71 if self.selected >= 0:
72 return self.values[self.selected]
73 else:
74 return None

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26