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