45 #------------------------------------------------------------------------------- |
45 #------------------------------------------------------------------------------- |
46 # Action Table |
46 # Action Table |
47 #------------------------------------------------------------------------------- |
47 #------------------------------------------------------------------------------- |
48 |
48 |
49 class ActionTable(CustomTable): |
49 class ActionTable(CustomTable): |
50 |
50 |
51 def GetValue(self, row, col): |
51 def GetValue(self, row, col): |
52 if row < self.GetNumberRows(): |
52 if row < self.GetNumberRows(): |
53 colname = self.GetColLabelValue(col, False) |
53 colname = self.GetColLabelValue(col, False) |
54 value = getattr(self.data[row], colname.lower()) |
54 value = getattr(self.data[row], colname.lower()) |
55 if colname == "Type": |
55 if colname == "Type": |
56 return _(value) |
56 return _(value) |
57 return value |
57 return value |
58 |
58 |
59 def SetValue(self, row, col, value): |
59 def SetValue(self, row, col, value): |
60 if col < len(self.colnames): |
60 if col < len(self.colnames): |
61 colname = self.GetColLabelValue(col, False) |
61 colname = self.GetColLabelValue(col, False) |
62 if colname == "Type": |
62 if colname == "Type": |
63 value = self.Parent.TranslateType[value] |
63 value = self.Parent.TranslateType[value] |
64 elif colname == "Qualifier" and not self.Parent.DurationList[value]: |
64 elif colname == "Qualifier" and not self.Parent.DurationList[value]: |
65 self.data[row].duration = "" |
65 self.data[row].duration = "" |
66 setattr(self.data[row], colname.lower(), value) |
66 setattr(self.data[row], colname.lower(), value) |
67 |
67 |
68 def _updateColAttrs(self, grid): |
68 def _updateColAttrs(self, grid): |
69 """ |
69 """ |
70 wx.Grid -> update the column attributes to add the |
70 wx.Grid -> update the column attributes to add the |
71 appropriate renderer given the column name. |
71 appropriate renderer given the column name. |
72 |
72 |
73 Otherwise default to the default renderer. |
73 Otherwise default to the default renderer. |
74 """ |
74 """ |
75 |
75 |
76 for row in range(self.GetNumberRows()): |
76 for row in range(self.GetNumberRows()): |
77 for col in range(self.GetNumberCols()): |
77 for col in range(self.GetNumberCols()): |
78 editor = None |
78 editor = None |
79 renderer = None |
79 renderer = None |
80 readonly = False |
80 readonly = False |
101 editor = wx.grid.GridCellTextEditor() |
101 editor = wx.grid.GridCellTextEditor() |
102 renderer = wx.grid.GridCellStringRenderer() |
102 renderer = wx.grid.GridCellStringRenderer() |
103 elif colname == "Indicator": |
103 elif colname == "Indicator": |
104 editor = wx.grid.GridCellChoiceEditor() |
104 editor = wx.grid.GridCellChoiceEditor() |
105 editor.SetParameters(self.Parent.VariableList) |
105 editor.SetParameters(self.Parent.VariableList) |
106 |
106 |
107 grid.SetCellEditor(row, col, editor) |
107 grid.SetCellEditor(row, col, editor) |
108 grid.SetCellRenderer(row, col, renderer) |
108 grid.SetCellRenderer(row, col, renderer) |
109 grid.SetReadOnly(row, col, readonly) |
109 grid.SetReadOnly(row, col, readonly) |
110 |
110 |
111 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
111 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
112 self.ResizeRow(grid, row) |
112 self.ResizeRow(grid, row) |
113 |
113 |
114 #------------------------------------------------------------------------------- |
114 #------------------------------------------------------------------------------- |
115 # Action Block Dialog |
115 # Action Block Dialog |
116 #------------------------------------------------------------------------------- |
116 #------------------------------------------------------------------------------- |
117 |
117 |
118 class ActionBlockDialog(wx.Dialog): |
118 class ActionBlockDialog(wx.Dialog): |
119 |
119 |
120 def __init__(self, parent): |
120 def __init__(self, parent): |
121 wx.Dialog.__init__(self, parent, title=_('Edit action block properties')) |
121 wx.Dialog.__init__(self, parent, title=_('Edit action block properties')) |
122 |
122 |
123 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
123 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
124 main_sizer.AddGrowableCol(0) |
124 main_sizer.AddGrowableCol(0) |
125 main_sizer.AddGrowableRow(1) |
125 main_sizer.AddGrowableRow(1) |
126 |
126 |
127 top_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
127 top_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
128 top_sizer.AddGrowableCol(0) |
128 top_sizer.AddGrowableCol(0) |
129 top_sizer.AddGrowableRow(0) |
129 top_sizer.AddGrowableRow(0) |
130 main_sizer.AddSizer(top_sizer, border=20, |
130 main_sizer.AddSizer(top_sizer, border=20, |
131 flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
131 flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
132 |
132 |
133 actions_label = wx.StaticText(self, label=_('Actions:')) |
133 actions_label = wx.StaticText(self, label=_('Actions:')) |
134 top_sizer.AddWindow(actions_label, flag=wx.ALIGN_BOTTOM) |
134 top_sizer.AddWindow(actions_label, flag=wx.ALIGN_BOTTOM) |
135 |
135 |
136 for name, bitmap, help in [ |
136 for name, bitmap, help in [ |
137 ("AddButton", "add_element", _("Add action")), |
137 ("AddButton", "add_element", _("Add action")), |
138 ("DeleteButton", "remove_element", _("Remove action")), |
138 ("DeleteButton", "remove_element", _("Remove action")), |
139 ("UpButton", "up", _("Move action up")), |
139 ("UpButton", "up", _("Move action up")), |
140 ("DownButton", "down", _("Move action down"))]: |
140 ("DownButton", "down", _("Move action down"))]: |
141 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
141 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
142 size=wx.Size(28, 28), style=wx.NO_BORDER) |
142 size=wx.Size(28, 28), style=wx.NO_BORDER) |
143 button.SetToolTipString(help) |
143 button.SetToolTipString(help) |
144 setattr(self, name, button) |
144 setattr(self, name, button) |
145 top_sizer.AddWindow(button) |
145 top_sizer.AddWindow(button) |
146 |
146 |
147 self.ActionsGrid = CustomGrid(self, size=wx.Size(-1, 250), style=wx.VSCROLL) |
147 self.ActionsGrid = CustomGrid(self, size=wx.Size(-1, 250), style=wx.VSCROLL) |
148 self.ActionsGrid.DisableDragGridSize() |
148 self.ActionsGrid.DisableDragGridSize() |
149 self.ActionsGrid.EnableScrolling(False, True) |
149 self.ActionsGrid.EnableScrolling(False, True) |
150 self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
150 self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
151 self.OnActionsGridCellChange) |
151 self.OnActionsGridCellChange) |
152 main_sizer.AddSizer(self.ActionsGrid, border=20, |
152 main_sizer.AddSizer(self.ActionsGrid, border=20, |
153 flag=wx.GROW|wx.LEFT|wx.RIGHT) |
153 flag=wx.GROW|wx.LEFT|wx.RIGHT) |
154 |
154 |
155 button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
155 button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
156 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
156 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
157 main_sizer.AddSizer(button_sizer, border=20, |
157 main_sizer.AddSizer(button_sizer, border=20, |
158 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
158 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
159 |
159 |
160 self.SetSizer(main_sizer) |
160 self.SetSizer(main_sizer) |
161 |
161 |
162 self.Table = ActionTable(self, [], GetActionTableColnames()) |
162 self.Table = ActionTable(self, [], GetActionTableColnames()) |
163 typelist = GetTypeList() |
163 typelist = GetTypeList() |
164 self.TypeList = ",".join(map(_,typelist)) |
164 self.TypeList = ",".join(map(_,typelist)) |
165 self.TranslateType = dict([(_(value), value) for value in typelist]) |
165 self.TranslateType = dict([(_(value), value) for value in typelist]) |
166 self.ColSizes = [60, 90, 130, 200, 50] |
166 self.ColSizes = [60, 90, 130, 200, 50] |
167 self.ColAlignements = [wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] |
167 self.ColAlignements = [wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] |
168 |
168 |
169 self.ActionsGrid.SetTable(self.Table) |
169 self.ActionsGrid.SetTable(self.Table) |
170 self.ActionsGrid.SetDefaultValue(_ActionInfos("N", "Action", "", "", "")) |
170 self.ActionsGrid.SetDefaultValue(_ActionInfos("N", "Action", "", "", "")) |
171 self.ActionsGrid.SetButtons({"Add": self.AddButton, |
171 self.ActionsGrid.SetButtons({"Add": self.AddButton, |
172 "Delete": self.DeleteButton, |
172 "Delete": self.DeleteButton, |
173 "Up": self.UpButton, |
173 "Up": self.UpButton, |
174 "Down": self.DownButton}) |
174 "Down": self.DownButton}) |
175 self.ActionsGrid.SetRowLabelSize(0) |
175 self.ActionsGrid.SetRowLabelSize(0) |
176 |
176 |
177 for col in range(self.Table.GetNumberCols()): |
177 for col in range(self.Table.GetNumberCols()): |
178 attr = wx.grid.GridCellAttr() |
178 attr = wx.grid.GridCellAttr() |
179 attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
179 attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
180 self.ActionsGrid.SetColAttr(col, attr) |
180 self.ActionsGrid.SetColAttr(col, attr) |
181 self.ActionsGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
181 self.ActionsGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
182 self.ActionsGrid.AutoSizeColumn(col, False) |
182 self.ActionsGrid.AutoSizeColumn(col, False) |
183 |
183 |
184 self.Table.ResetView(self.ActionsGrid) |
184 self.Table.ResetView(self.ActionsGrid) |
185 self.ActionsGrid.SetFocus() |
185 self.ActionsGrid.SetFocus() |
186 self.ActionsGrid.RefreshButtons() |
186 self.ActionsGrid.RefreshButtons() |
187 self.Fit() |
187 self.Fit() |
188 |
188 |
189 def OnOK(self, event): |
189 def OnOK(self, event): |
190 self.ActionsGrid.CloseEditControl() |
190 self.ActionsGrid.CloseEditControl() |
191 self.EndModal(wx.ID_OK) |
191 self.EndModal(wx.ID_OK) |
192 |
192 |
193 def OnActionsGridCellChange(self, event): |
193 def OnActionsGridCellChange(self, event): |
194 wx.CallAfter(self.Table.ResetView, self.ActionsGrid) |
194 wx.CallAfter(self.Table.ResetView, self.ActionsGrid) |
195 event.Skip() |
195 event.Skip() |
196 |
196 |
197 def SetQualifierList(self, list): |
197 def SetQualifierList(self, list): |
198 self.QualifierList = ",".join(list) |
198 self.QualifierList = ",".join(list) |
199 self.DurationList = list |
199 self.DurationList = list |
200 |
200 |
201 def SetVariableList(self, list): |
201 def SetVariableList(self, list): |
202 self.VariableList = "," + ",".join([variable.Name for variable in list]) |
202 self.VariableList = "," + ",".join([variable.Name for variable in list]) |
203 |
203 |
204 def SetActionList(self, list): |
204 def SetActionList(self, list): |
205 self.ActionList = "," + ",".join(list) |
205 self.ActionList = "," + ",".join(list) |
206 |
206 |
207 def SetValues(self, actions): |
207 def SetValues(self, actions): |
208 for action in actions: |
208 for action in actions: |