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 = {} |
94 |
wxPyGridTableBase.__init__(self) |
wxPyGridTableBase.__init__(self) |
95 |
self.num_cols = 1 |
self.num_cols = 1 |
96 |
self.num_rows = 0 |
self.num_rows = 0 |
|
self.columns = [] |
|
97 |
self.table = None |
self.table = None |
98 |
self.record_index = record |
self.record_index = record |
99 |
self.record = None |
self.record = None |
171 |
def SetValue(self, row, col, value): |
def SetValue(self, row, col, value): |
172 |
if row < self.num_rows: |
if row < self.num_rows: |
173 |
name = self.rows[row][0] |
name = self.rows[row][0] |
174 |
print "Set value of field %s to %s" % (name, value) |
self.record[name] = value |
175 |
|
self.table.write_record(self.record_index, {name: value}) |
176 |
|
|
177 |
# |
# |
178 |
# Some optional methods |
# Some optional methods |
180 |
|
|
181 |
# Called when the grid needs to display labels |
# Called when the grid needs to display labels |
182 |
def GetColLabelValue(self, col): |
def GetColLabelValue(self, col): |
183 |
return "Value" |
return _("Value") |
184 |
|
|
185 |
def GetRowLabelValue(self, row): |
def GetRowLabelValue(self, row): |
186 |
if row < self.num_rows: |
if row < self.num_rows: |
191 |
# default, doesn't necessarily have to be the same type used |
# default, doesn't necessarily have to be the same type used |
192 |
# nativly by the editor/renderer if they know how to convert. |
# nativly by the editor/renderer if they know how to convert. |
193 |
def GetTypeName(self, row, col): |
def GetTypeName(self, row, col): |
194 |
if row < self.num_rows: |
# for some reason row and col may be negative sometimes, but |
195 |
|
# it's probably a wx bug (filed as #593189 on sourceforge) |
196 |
|
if 0 <= row < self.num_rows: |
197 |
return self.rows[row][1] |
return self.rows[row][1] |
198 |
return wxGRID_VALUE_STRING |
return wxGRID_VALUE_STRING |
199 |
|
|
207 |
def CanSetValueAs(self, row, col, typeName): |
def CanSetValueAs(self, row, col, typeName): |
208 |
return self.CanGetValueAs(row, col, typeName) |
return self.CanGetValueAs(row, col, typeName) |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
class RecordGridCtrl(wxGrid): |
class RecordGridCtrl(wxGrid): |
213 |
|
|
228 |
self.AutoSizeColumn(0, true) |
self.AutoSizeColumn(0, true) |
229 |
|
|
230 |
#self.SetSelectionMode(wxGrid.wxGridSelectRows) |
#self.SetSelectionMode(wxGrid.wxGridSelectRows) |
231 |
|
|
232 |
#EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect) |
#EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect) |
233 |
#EVT_GRID_SELECT_CELL(self, self.OnSelectCell) |
#EVT_GRID_SELECT_CELL(self, self.OnSelectCell) |
234 |
|
|