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 |
# |
# |
16 |
wxGridTableMessage, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, \ |
wxGridTableMessage, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, \ |
17 |
wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES |
wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES |
18 |
|
|
19 |
|
from Thuban import _ |
20 |
|
|
21 |
# FIXME: the wx_value_type_map should be moved from tableview to a |
# FIXME: the wx_value_type_map should be moved from tableview to a |
22 |
# separate module |
# separate module |
23 |
from tableview import wx_value_type_map |
from tableview import wx_value_type_map |
31 |
def __init__(self, parent, id): |
def __init__(self, parent, id): |
32 |
wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT) |
wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT) |
33 |
|
|
34 |
self.InsertColumn(0, "Field") |
self.InsertColumn(0, _("Field")) |
35 |
self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER) |
self.SetColumnWidth(0, 200) |
36 |
self.InsertColumn(1, "Value") |
self.InsertColumn(1, _("Value")) |
37 |
self.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER) |
self.SetColumnWidth(1, 100) |
38 |
|
|
39 |
# vaues maps row numbers to the corresponding python values |
# vaues maps row numbers to the corresponding python values |
40 |
self.values = {} |
self.values = {} |
45 |
values = {} |
values = {} |
46 |
|
|
47 |
if shape is not None: |
if shape is not None: |
|
num_cols = table.field_count() |
|
|
|
|
48 |
names = [] |
names = [] |
49 |
for i in range(num_cols): |
for col in table.Columns(): |
50 |
type, name, length, decc = table.field_info(i) |
names.append(col.name) |
51 |
names.append(name) |
record = table.ReadRowAsDict(shape) |
|
record = table.read_record(shape) |
|
52 |
|
|
53 |
for i in range(len(names)): |
for i in range(len(names)): |
54 |
name = names[i] |
name = names[i] |
91 |
wxPyGridTableBase.__init__(self) |
wxPyGridTableBase.__init__(self) |
92 |
self.num_cols = 1 |
self.num_cols = 1 |
93 |
self.num_rows = 0 |
self.num_rows = 0 |
|
self.columns = [] |
|
94 |
self.table = None |
self.table = None |
95 |
self.record_index = record |
self.record_index = record |
96 |
self.record = None |
self.record = None |
101 |
if record_index is not None: |
if record_index is not None: |
102 |
self.table = table |
self.table = table |
103 |
self.record_index = record_index |
self.record_index = record_index |
104 |
self.record = table.read_record(record_index) |
self.record = table.ReadRowAsDict(record_index) |
105 |
|
|
106 |
# we have one row for each field in the table |
# we have one row for each field in the table |
107 |
self.num_rows = table.field_count() |
self.num_rows = table.NumColumns() |
108 |
|
|
109 |
# extract the field types and names of the row we're showing. |
# extract the field types and names of the row we're showing. |
110 |
self.rows = [] |
self.rows = [] |
111 |
for i in range(self.num_rows): |
for i in range(self.num_rows): |
112 |
type, name, len, decc = table.field_info(i) |
col = table.Column(i) |
113 |
self.rows.append((name, wx_value_type_map[type], len, decc)) |
self.rows.append((col.name, wx_value_type_map[col.type])) |
114 |
self.notify_get_values() |
self.notify_get_values() |
115 |
else: |
else: |
116 |
# make the grid empty |
# make the grid empty |
168 |
def SetValue(self, row, col, value): |
def SetValue(self, row, col, value): |
169 |
if row < self.num_rows: |
if row < self.num_rows: |
170 |
name = self.rows[row][0] |
name = self.rows[row][0] |
171 |
print "Set value of field %s to %s" % (name, value) |
self.record[name] = value |
172 |
|
self.table.write_record(self.record_index, {name: value}) |
173 |
|
|
174 |
# |
# |
175 |
# Some optional methods |
# Some optional methods |
177 |
|
|
178 |
# Called when the grid needs to display labels |
# Called when the grid needs to display labels |
179 |
def GetColLabelValue(self, col): |
def GetColLabelValue(self, col): |
180 |
return "Value" |
return _("Value") |
181 |
|
|
182 |
def GetRowLabelValue(self, row): |
def GetRowLabelValue(self, row): |
183 |
if row < self.num_rows: |
if row < self.num_rows: |
188 |
# default, doesn't necessarily have to be the same type used |
# default, doesn't necessarily have to be the same type used |
189 |
# nativly by the editor/renderer if they know how to convert. |
# nativly by the editor/renderer if they know how to convert. |
190 |
def GetTypeName(self, row, col): |
def GetTypeName(self, row, col): |
191 |
if row < self.num_rows: |
# for some reason row and col may be negative sometimes, but |
192 |
|
# it's probably a wx bug (filed as #593189 on sourceforge) |
193 |
|
if 0 <= row < self.num_rows: |
194 |
return self.rows[row][1] |
return self.rows[row][1] |
195 |
return wxGRID_VALUE_STRING |
return wxGRID_VALUE_STRING |
196 |
|
|
204 |
def CanSetValueAs(self, row, col, typeName): |
def CanSetValueAs(self, row, col, typeName): |
205 |
return self.CanGetValueAs(row, col, typeName) |
return self.CanGetValueAs(row, col, typeName) |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
class RecordGridCtrl(wxGrid): |
class RecordGridCtrl(wxGrid): |
210 |
|
|
225 |
self.AutoSizeColumn(0, true) |
self.AutoSizeColumn(0, true) |
226 |
|
|
227 |
#self.SetSelectionMode(wxGrid.wxGridSelectRows) |
#self.SetSelectionMode(wxGrid.wxGridSelectRows) |
228 |
|
|
229 |
#EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect) |
#EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect) |
230 |
#EVT_GRID_SELECT_CELL(self, self.OnSelectCell) |
#EVT_GRID_SELECT_CELL(self, self.OnSelectCell) |
231 |
|
|