24 |
24 |
25 import wx |
25 import wx |
26 |
26 |
27 from dialogs.DurationEditorDialog import DurationEditorDialog |
27 from dialogs.DurationEditorDialog import DurationEditorDialog |
28 |
28 |
|
29 |
29 class DurationCellControl(wx.PyControl): |
30 class DurationCellControl(wx.PyControl): |
30 |
31 |
31 ''' |
32 ''' |
32 Custom cell editor control with a text box and a button that launches |
33 Custom cell editor control with a text box and a button that launches |
33 the DurationEditorDialog. |
34 the DurationEditorDialog. |
34 ''' |
35 ''' |
35 def __init__(self, parent): |
36 def __init__(self, parent): |
36 wx.Control.__init__(self, parent) |
37 wx.Control.__init__(self, parent) |
37 |
38 |
38 main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
39 main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
39 main_sizer.AddGrowableCol(0) |
40 main_sizer.AddGrowableCol(0) |
40 main_sizer.AddGrowableRow(0) |
41 main_sizer.AddGrowableRow(0) |
41 |
42 |
42 # create location text control |
43 # create location text control |
43 self.Duration = wx.TextCtrl(self, size=wx.Size(0, -1), |
44 self.Duration = wx.TextCtrl(self, size=wx.Size(0, -1), |
44 style=wx.TE_PROCESS_ENTER) |
45 style=wx.TE_PROCESS_ENTER) |
45 self.Duration.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar) |
46 self.Duration.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar) |
46 main_sizer.AddWindow(self.Duration, flag=wx.GROW) |
47 main_sizer.AddWindow(self.Duration, flag=wx.GROW) |
47 |
48 |
48 # create browse button |
49 # create browse button |
49 self.EditButton = wx.Button(self, label='...', size=wx.Size(30, -1)) |
50 self.EditButton = wx.Button(self, label='...', size=wx.Size(30, -1)) |
50 self.Bind(wx.EVT_BUTTON, self.OnEditButtonClick, self.EditButton) |
51 self.Bind(wx.EVT_BUTTON, self.OnEditButtonClick, self.EditButton) |
51 main_sizer.AddWindow(self.EditButton, flag=wx.GROW) |
52 main_sizer.AddWindow(self.EditButton, flag=wx.GROW) |
52 |
53 |
53 self.Bind(wx.EVT_SIZE, self.OnSize) |
54 self.Bind(wx.EVT_SIZE, self.OnSize) |
54 |
55 |
55 self.SetSizer(main_sizer) |
56 self.SetSizer(main_sizer) |
56 |
57 |
57 self.Default = None |
58 self.Default = None |
58 |
59 |
59 def SetValue(self, value): |
60 def SetValue(self, value): |
60 self.Default = value |
61 self.Default = value |
61 self.Duration.SetValue(value) |
62 self.Duration.SetValue(value) |
62 |
63 |
63 def GetValue(self): |
64 def GetValue(self): |
64 return self.Duration.GetValue() |
65 return self.Duration.GetValue() |
65 |
66 |
66 def OnSize(self, event): |
67 def OnSize(self, event): |
67 self.Layout() |
68 self.Layout() |
88 else: |
89 else: |
89 event.Skip() |
90 event.Skip() |
90 |
91 |
91 def SetInsertionPoint(self, i): |
92 def SetInsertionPoint(self, i): |
92 self.Duration.SetInsertionPoint(i) |
93 self.Duration.SetInsertionPoint(i) |
93 |
94 |
94 def SetFocus(self): |
95 def SetFocus(self): |
95 self.Duration.SetFocus() |
96 self.Duration.SetFocus() |
|
97 |
96 |
98 |
97 class DurationCellEditor(wx.grid.PyGridCellEditor): |
99 class DurationCellEditor(wx.grid.PyGridCellEditor): |
98 ''' |
100 ''' |
99 Grid cell editor that uses DurationCellControl to display an edit button. |
101 Grid cell editor that uses DurationCellControl to display an edit button. |
100 ''' |
102 ''' |
101 def __init__(self, table, colname): |
103 def __init__(self, table, colname): |
102 wx.grid.PyGridCellEditor.__init__(self) |
104 wx.grid.PyGridCellEditor.__init__(self) |
103 |
105 |
104 self.Table = table |
106 self.Table = table |
105 self.Colname = colname |
107 self.Colname = colname |
106 |
108 |
107 def __del__(self): |
109 def __del__(self): |
108 self.CellControl = None |
110 self.CellControl = None |
109 |
111 |
110 def Create(self, parent, id, evt_handler): |
112 def Create(self, parent, id, evt_handler): |
111 self.CellControl = DurationCellControl(parent) |
113 self.CellControl = DurationCellControl(parent) |
112 self.SetControl(self.CellControl) |
114 self.SetControl(self.CellControl) |
113 if evt_handler: |
115 if evt_handler: |
114 self.CellControl.PushEventHandler(evt_handler) |
116 self.CellControl.PushEventHandler(evt_handler) |
129 if wx.VERSION >= (3, 0, 0): |
131 if wx.VERSION >= (3, 0, 0): |
130 def EndEdit(self, row, col, grid, oldval): |
132 def EndEdit(self, row, col, grid, oldval): |
131 return self.EndEditInternal(row, col, grid, oldval) |
133 return self.EndEditInternal(row, col, grid, oldval) |
132 else: |
134 else: |
133 def EndEdit(self, row, col, grid): |
135 def EndEdit(self, row, col, grid): |
134 oldval = self.Table.GetValueByName(row, self.Colname) |
136 oldval = self.Table.GetValueByName(row, self.Colname) |
135 return self.EndEditInternal(row, col, grid, oldval) |
137 return self.EndEditInternal(row, col, grid, oldval) |
136 |
138 |
137 def SetSize(self, rect): |
139 def SetSize(self, rect): |
138 self.CellControl.SetDimensions(rect.x + 1, rect.y, |
140 self.CellControl.SetDimensions(rect.x + 1, rect.y, |
139 rect.width, rect.height, |
141 rect.width, rect.height, |
140 wx.SIZE_ALLOW_MINUS_ONE) |
142 wx.SIZE_ALLOW_MINUS_ONE) |
141 |
143 |
142 def Clone(self): |
144 def Clone(self): |
143 return DurationCellEditor(self.Table) |
145 return DurationCellEditor(self.Table) |