Package Gnumed :: Package timelinelib :: Package wxgui :: Package dialogs :: Package editevent :: Module view
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.wxgui.dialogs.editevent.view

  1  # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  Rickard Lindberg, Roger Lindberg 
  2  # 
  3  # This file is part of Timeline. 
  4  # 
  5  # Timeline is free software: you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation, either version 3 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Timeline is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18   
 19  import wx 
 20   
 21  from timelinelib.db.utils import safe_locking 
 22  from timelinelib.repositories.dbwrapper import DbWrapperEventRepository 
 23  from timelinelib.wxgui.dialogs.editcontainer.view import EditContainerDialog 
 24  from timelinelib.wxgui.dialogs.editevent.controller import EditEventDialogController 
 25  from timelinelib.wxgui.framework import Dialog 
 26  from timelinelib.wxgui.utils import _set_focus_and_select 
 27  from timelinelib.wxgui.dialogs.duplicateevent.view import DuplicateEventDialog 
 28   
 29   
30 -class EditEventDialog(Dialog):
31 32 """ 33 <BoxSizerVertical> 34 <StaticBoxSizerVertical label="$(properties_label)" border="ALL" proportion="1"> 35 <FlexGridSizer name="grid_sizer" columns="2" growableColumns="1" border="ALL" proportion="1"> 36 %s 37 </FlexGridSizer> 38 </StaticBoxSizerVertical> 39 <CheckBox 40 name="add_more_checkbox" 41 label="$(add_more_label)" 42 border="LEFT|RIGHT|BOTTOM" 43 /> 44 <BoxSizerHorizontal border="LEFT|RIGHT|BOTTOM"> 45 <TwoStateButton 46 initial_state_label="$(enlarge)" 47 second_state_label="$(reduce)" 48 event_EVT_INITIAL_STATE_CLICKED="on_enlarge_click" 49 event_EVT_SECOND_STATE_CLICKED="on_reduce_click" 50 /> 51 <Spacer /> 52 <Button 53 name="duplicate" 54 label="$(duplicate_label)" 55 event_EVT_BUTTON="on_duplicate" 56 /> 57 <StretchSpacer /> 58 <DialogButtonsOkCancelSizer 59 event_EVT_BUTTON__ID_OK="on_ok_clicked" 60 /> 61 </BoxSizerHorizontal> 62 </BoxSizerVertical> 63 """ 64 65 TIME_DETAILS_ROW = """ 66 <StaticText align="ALIGN_CENTER_VERTICAL" label="$(when_label)" /> 67 <BoxSizerHorizontal> 68 <PeriodPicker 69 name="period_picker" 70 time_type="$(time_type)" 71 config="$(config)" 72 /> 73 </BoxSizerHorizontal> 74 """ 75 76 CHECKBOX_ROW = """ 77 <Spacer /> 78 <FlexGridSizer rows="1"> 79 <CheckBox 80 name="fuzzy_checkbox" 81 label="$(fuzzy_checkbox_text)" 82 /> 83 <CheckBox 84 name="locked_checkbox" 85 event_EVT_CHECKBOX="on_locked_checkbox_changed" 86 label="$(locked_checkbox_text)" 87 /> 88 <CheckBox 89 name="ends_today_checkbox" 90 label="$(ends_today_checkbox_text)" 91 /> 92 </FlexGridSizer> 93 """ 94 95 TEXT_FIELD_ROW = """ 96 <StaticText align="ALIGN_CENTER_VERTICAL" label="$(text_label)" /> 97 <TextCtrl name="name" /> 98 """ 99 100 CATEGORY_LISTBOX_ROW = """ 101 <StaticText align="ALIGN_CENTER_VERTICAL" label="$(category_label)" /> 102 <CategoryChoice 103 name="category_choice" 104 allow_add="True" 105 timeline="$(db)" 106 align="ALIGN_LEFT" 107 /> 108 """ 109 110 CONTAINER_LISTBOX_ROW = """ 111 <StaticText align="ALIGN_CENTER_VERTICAL" label="$(container_label)" /> 112 <ContainerChoice 113 name="container_choice" 114 event_EVT_CONTAINER_CHANGED="on_container_changed" 115 db="$(db)" 116 align="ALIGN_LEFT" 117 /> 118 """ 119 120 NOTEBOOK_ROW = """ 121 <Spacer /> 122 <Notebook name="notebook" style="BK_DEFAULT"> 123 <DescriptionEditor 124 name="description" 125 notebookLabel="$(page_description)" 126 editor="$(self)" 127 proportion="1" 128 /> 129 <IconEditor 130 name="icon" 131 notebookLabel="$(page_icon)" 132 editor="$(self)" 133 proportion="1" 134 /> 135 <AlertEditor 136 name="alert" 137 notebookLabel="$(page_alert)" 138 editor="$(self)" 139 proportion="1" 140 /> 141 <HyperlinkEditor 142 name="hyperlink" 143 notebookLabel="$(page_hyperlink)" 144 editor="$(self)" 145 proportion="1" 146 /> 147 <ProgressEditor 148 name="progress" 149 notebookLabel="$(page_progress)" 150 editor="$(self)" 151 proportion="1" 152 /> 153 <ColorEditor 154 name="default_color" 155 notebookLabel="$(color)" 156 editor="$(self)" 157 proportion="1" 158 /> 159 </Notebook> 160 """ 161
162 - def __init__(self, parent, config, title, db, start=None, end=None, event=None):
163 self.parent = parent 164 self.timeline = db 165 self.config = config 166 self.start = start 167 self.event = event 168 self._insert_rows_in_correct_order_in_xml() 169 Dialog.__init__(self, EditEventDialogController, parent, { 170 "self": self, 171 "db": db, 172 "time_type": db.get_time_type(), 173 "config": config, 174 "properties_label": _("Event Properties"), 175 "when_label": _("When:"), 176 "fuzzy_checkbox_text": _("Fuzzy"), 177 "locked_checkbox_text": _("Locked"), 178 "ends_today_checkbox_text": _("Ends today"), 179 "text_label": _("Text:"), 180 "category_label": _("Category:"), 181 "container_label": _("Container:"), 182 "page_description": _("Description"), 183 "page_icon": _("Icon"), 184 "page_alert": _("Alert"), 185 "page_hyperlink": _("Hyperlink"), 186 "page_progress": _("Progress"), 187 "color": _("Default color"), 188 "add_more_label": _("Add more events after this one"), 189 "enlarge": _("&Enlarge"), 190 "reduce": _("&Reduce"), 191 "duplicate_label": _("Save and Duplicate"), 192 }, title=title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) 193 self.controller.on_init( 194 config, 195 db.get_time_type(), 196 DbWrapperEventRepository(db), 197 db, 198 start, 199 end, 200 event) 201 self._make_row_with_notebook_growable() 202 self.SetMinSize((800, -1)) 203 self.Fit() 204 self.SetMinSize(self.GetSize())
205
206 - def GetDuplicateEventDialog(self, timeline, event):
207 return DuplicateEventDialog(self.parent, timeline, event)
208
209 - def GetPeriod(self):
210 return self.period_picker.GetValue()
211
212 - def SetPeriod(self, value):
213 self.period_picker.SetValue(value)
214
215 - def GetShowPeriod(self):
216 return self.period_picker.GetShowPeriod()
217
218 - def SetShowPeriod(self, value):
219 self.period_picker.SetShowPeriod(value)
220
221 - def GetShowTime(self):
222 return self.period_picker.GetShowTime()
223
224 - def SetShowTime(self, value):
225 self.period_picker.SetShowTime(value)
226
227 - def DisableTime(self):
228 self.period_picker.DisableTime()
229
230 - def GetFuzzy(self):
231 return self.fuzzy_checkbox.GetValue()
232
233 - def SetFuzzy(self, value):
234 self.fuzzy_checkbox.SetValue(value)
235
236 - def GetLocked(self):
237 return self.locked_checkbox.GetValue()
238
239 - def SetLocked(self, value):
240 self.locked_checkbox.SetValue(value)
241
242 - def EnableLocked(self, value):
243 self.locked_checkbox.Enable(value)
244
245 - def GetEndsToday(self):
246 return self.ends_today_checkbox.GetValue()
247
248 - def SetEndsToday(self, value):
249 self.ends_today_checkbox.SetValue(value)
250
251 - def EnableEndsToday(self, value):
252 self.ends_today_checkbox.Enable(value)
253
254 - def GetName(self):
255 return self.name.GetValue().strip()
256
257 - def SetName(self, value):
258 self.name.SetValue(value)
259
260 - def GetCategory(self):
261 return self.category_choice.GetSelectedCategory()
262
263 - def SetCategory(self, value):
264 self.category_choice.Populate(select=value)
265
266 - def GetContainer(self):
267 return self.container_choice.GetSelectedContainer()
268
269 - def SetContainer(self, value):
270 self.container_choice.Fill(value)
271
272 - def GetEventData(self):
273 event_data = {} 274 for data_id, editor in self._get_event_data(): 275 data = editor.get_data() 276 if data is not None: 277 event_data[data_id] = editor.get_data() 278 return event_data
279
280 - def SetEventData(self, event_data):
281 for data_id, editor in self._get_event_data(): 282 if data_id in event_data: 283 data = event_data[data_id] 284 if data is not None: 285 editor.set_data(data)
286
287 - def ClearEventData(self):
288 for _, editor in self._get_event_data(): 289 editor.clear_data()
290
291 - def IsAddMoreChecked(self):
292 return self.add_more_checkbox.GetValue()
293
294 - def SetShowAddMoreCheckbox(self, value):
295 self.add_more_checkbox.Show(value) 296 self.add_more_checkbox.SetValue(False) 297 self.SetSizerAndFit(self.GetSizer())
298
299 - def SetFocusOnFirstControl(self):
300 control = { 301 "0": self.period_picker, 302 "1": self.fuzzy_checkbox, 303 "2": self.name, 304 "3": self.category_choice, 305 "4": self.container_choice, 306 ":": self.notebook, 307 }[self.config.event_editor_tab_order[0]] 308 _set_focus_and_select(control)
309
310 - def DisplayInvalidPeriod(self, message):
311 self._display_invalid_input(message, self.period_picker)
312
313 - def _display_invalid_input(self, message, control):
314 self.DisplayErrorMessage(message) 315 _set_focus_and_select(control)
316
317 - def _get_event_data(self):
318 return [ 319 ("description", self.description), 320 ("alert", self.alert), 321 ("icon", self.icon), 322 ("hyperlink", self.hyperlink), 323 ("progress", self.progress), 324 ("default_color", self.default_color) 325 ]
326
328 rows_by_key = { 329 "0": self.TIME_DETAILS_ROW, 330 "1": self.CHECKBOX_ROW, 331 "2": self.TEXT_FIELD_ROW, 332 "3": self.CATEGORY_LISTBOX_ROW, 333 "4": self.CONTAINER_LISTBOX_ROW, 334 ":": self.NOTEBOOK_ROW, 335 } 336 placeholder_content = "".join(rows_by_key[key] for key in self.config.event_editor_tab_order) 337 self.__doc__ = self.__doc__ % placeholder_content
338
340 self.grid_sizer.AddGrowableRow(self.config.event_editor_tab_order.index(":"))
341 342
343 -def open_event_editor_for(edit_controller, parent, config, db, event):
344 def create_event_editor(): 345 if event.is_container(): 346 title = _("Edit Container") 347 return EditContainerDialog(parent, title, db, event) 348 else: 349 return EditEventDialog( 350 parent, config, _("Edit Event"), db, event=event)
351 352 def edit_function(): 353 dialog = create_event_editor() 354 dialog.ShowModal() 355 dialog.Destroy() 356 safe_locking(edit_controller, edit_function) 357 358
359 -def open_create_event_editor(edit_controller, parent, config, db, start=None, end=None):
360 def create_event_editor(): 361 label = _("Create Event") 362 return EditEventDialog(parent, config, label, db, start, end)
363 364 def edit_function(): 365 dialog = create_event_editor() 366 dialog.ShowModal() 367 dialog.Destroy() 368 safe_locking(edit_controller, edit_function) 369