10 |
|
|
11 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
12 |
|
|
13 |
from wxPython.wx import wxListCtrl, wxLC_REPORT, wxLIST_AUTOSIZE_USEHEADER, \ |
import wx |
14 |
EVT_LIST_ITEM_SELECTED |
from wx import grid |
|
from wxPython.grid import wxPyGridTableBase, wxGrid, wxGRID_VALUE_STRING, \ |
|
|
wxGridTableMessage, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, \ |
|
|
wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES |
|
15 |
|
|
16 |
from Thuban import _ |
from Thuban import _ |
17 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
class RecordListCtrl(wxListCtrl): |
class RecordListCtrl(wx.ListCtrl): |
25 |
|
|
26 |
"""List Control showing a single record from a thuban table""" |
"""List Control showing a single record from a thuban table""" |
27 |
|
|
28 |
def __init__(self, parent, id): |
def __init__(self, parent, id): |
29 |
wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT) |
wx.ListCtrl.__init__(self, parent, id, style = wx.LC_REPORT) |
30 |
|
|
31 |
self.InsertColumn(0, _("Field")) |
self.InsertColumn(0, _("Field")) |
32 |
self.SetColumnWidth(0, 200) |
self.SetColumnWidth(0, 200) |
64 |
# selected is the index of the selected record or -1 if none is |
# selected is the index of the selected record or -1 if none is |
65 |
# selected |
# selected |
66 |
self.selected = -1 |
self.selected = -1 |
67 |
EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected) |
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, id=self.GetId()) |
68 |
|
|
69 |
def OnItemSelected(self, event): |
def OnItemSelected(self, event): |
70 |
"""Event handler. Update the selected instvar""" |
"""Event handler. Update the selected instvar""" |
78 |
return None |
return None |
79 |
|
|
80 |
|
|
81 |
class RecordTable(wxPyGridTableBase): |
class RecordTable(grid.PyGridTableBase): |
82 |
|
|
83 |
"""Wrapper that makes a Thuban table record look like a table for a |
"""Wrapper that makes a Thuban table record look like a table for a |
84 |
wxGrid |
wxGrid |
85 |
""" |
""" |
86 |
|
|
87 |
def __init__(self, table = None, record = None): |
def __init__(self, table = None, record = None): |
88 |
wxPyGridTableBase.__init__(self) |
grid.PyGridTableBase.__init__(self) |
89 |
self.num_cols = 1 |
self.num_cols = 1 |
90 |
self.num_rows = 0 |
self.num_rows = 0 |
91 |
self.table = None |
self.table = None |
122 |
|
|
123 |
def notify_append_rows(self, num): |
def notify_append_rows(self, num): |
124 |
"""Tell the view that num rows were appended""" |
"""Tell the view that num rows were appended""" |
125 |
self.send_view_message(wxGRIDTABLE_NOTIFY_ROWS_APPENDED, num) |
self.send_view_message(grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, num) |
126 |
|
|
127 |
def notify_delete_rows(self, start, num): |
def notify_delete_rows(self, start, num): |
128 |
"""Tell the view that num rows were deleted starting at start""" |
"""Tell the view that num rows were deleted starting at start""" |
129 |
self.send_view_message(wxGRIDTABLE_NOTIFY_ROWS_DELETED, start, num) |
self.send_view_message(grid.GRIDTABLE_NOTIFY_ROWS_DELETED, start, num) |
130 |
|
|
131 |
def notify_get_values(self): |
def notify_get_values(self): |
132 |
"""Tell the view that the grid's values have to be updated""" |
"""Tell the view that the grid's values have to be updated""" |
133 |
self.send_view_message(wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
self.send_view_message(grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
134 |
|
|
135 |
def send_view_message(self, msgid, *args): |
def send_view_message(self, msgid, *args): |
136 |
"""Send the message msgid to the view with arguments args""" |
"""Send the message msgid to the view with arguments args""" |
137 |
view = self.GetView() |
view = self.GetView() |
138 |
if view: |
if view: |
139 |
#print "send_view_message", msgid, args |
#print "send_view_message", msgid, args |
140 |
msg = apply(wxGridTableMessage, (self, msgid) + args) |
msg = apply(grid.GridTableMessage, (self, msgid) + args) |
141 |
view.ProcessTableMessage(msg) |
view.ProcessTableMessage(msg) |
142 |
|
|
143 |
# |
# |
189 |
# it's probably a wx bug (filed as #593189 on sourceforge) |
# it's probably a wx bug (filed as #593189 on sourceforge) |
190 |
if 0 <= row < self.num_rows: |
if 0 <= row < self.num_rows: |
191 |
return self.rows[row][1] |
return self.rows[row][1] |
192 |
return wxGRID_VALUE_STRING |
return grid.GRID_VALUE_STRING |
193 |
|
|
194 |
# Called to determine how the data can be fetched and stored by the |
# Called to determine how the data can be fetched and stored by the |
195 |
# editor and renderer. This allows you to enforce some type-safety |
# editor and renderer. This allows you to enforce some type-safety |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
class RecordGridCtrl(wxGrid): |
class RecordGridCtrl(grid.Grid): |
207 |
|
|
208 |
"""Grid view for a RecordTable""" |
"""Grid view for a RecordTable""" |
209 |
|
|
210 |
def __init__(self, parent, table = None, record = None): |
def __init__(self, parent, table = None, record = None): |
211 |
wxGrid.__init__(self, parent, -1) |
grid.Grid.__init__(self, parent, -1) |
212 |
|
|
213 |
self.table = RecordTable(table, record) |
self.table = RecordTable(table, record) |
214 |
|
|