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              allow_edit="True"
    106              timeline="$(db)"
    107              align="ALIGN_LEFT"
    108          />
    109      """
    110
    111      CONTAINER_LISTBOX_ROW = """
    112          <StaticText align="ALIGN_CENTER_VERTICAL" label="$(container_label)" />
    113          <ContainerChoice
    114              name="container_choice"
    115              event_EVT_CONTAINER_CHANGED="on_container_changed"
    116              db="$(db)"
    117              align="ALIGN_LEFT"
    118          />
    119      """
    120
    121      NOTEBOOK_ROW = """
    122          <Spacer />
    123          <Notebook name="notebook" style="BK_DEFAULT">
    124              <DescriptionEditor
    125                  name="description"
    126                  notebookLabel="$(page_description)"
    127                  editor="$(self)"
    128                  proportion="1"
    129              />
    130              <IconEditor
    131                  name="icon"
    132                  notebookLabel="$(page_icon)"
    133                  editor="$(self)"
    134                  proportion="1"
    135              />
    136              <AlertEditor
    137                  name="alert"
    138                  notebookLabel="$(page_alert)"
    139                  editor="$(self)"
    140                  proportion="1"
    141              />
    142              <HyperlinkEditor
    143                  name="hyperlink"
    144                  notebookLabel="$(page_hyperlink)"
    145                  editor="$(self)"
    146                  proportion="1"
    147              />
    148              <ProgressEditor
    149                  name="progress"
    150                  notebookLabel="$(page_progress)"
    151                  editor="$(self)"
    152                  proportion="1"
    153              />
    154              <ColorEditor
    155                  name="default_color"
    156                  notebookLabel="$(color)"
    157                  editor="$(self)"
    158                  proportion="1"
    159              />
    160          </Notebook>
    161      """
    162
    163 -    def __init__(self, parent, config, title, db, start=None, end=None, event=None):
    164          self.parent = parent
    165          self.timeline = db
    166          self.config = config
    167          self.start = start
    168          self.event = event
    169          self._insert_rows_in_correct_order_in_xml()
    170          Dialog.__init__(self, EditEventDialogController, parent, {
    171              "self": self,
    172              "db": db,
    173              "time_type": db.get_time_type(),
    174              "config": config,
    175              "properties_label": _("Event Properties"),
    176              "when_label": _("When:"),
    177              "fuzzy_checkbox_text": _("Fuzzy"),
    178              "locked_checkbox_text": _("Locked"),
    179              "ends_today_checkbox_text": _("Ends today"),
    180              "text_label": _("Text:"),
    181              "category_label": _("Category:"),
    182              "container_label": _("Container:"),
    183              "page_description": _("Description"),
    184              "page_icon": _("Icon"),
    185              "page_alert": _("Alert"),
    186              "page_hyperlink": _("Hyperlink"),
    187              "page_progress": _("Progress"),
    188              "color": _("Default color"),
    189              "add_more_label": _("Add more events after this one"),
    190              "enlarge": _("&Enlarge"),
    191              "reduce": _("&Reduce"),
    192              "duplicate_label": _("Save and Duplicate"),
    193          }, title=title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
    194          self.controller.on_init(
    195              config,
    196              db.get_time_type(),
    197              DbWrapperEventRepository(db),
    198              db,
    199              start,
    200              end,
    201              event)
    202          self._make_row_with_notebook_growable()
    203          self.SetMinSize((800, -1))
    204          self.Fit()
    205          self.SetMinSize(self.GetSize())
    206
    207 -    def GetDuplicateEventDialog(self, timeline, event):
    208          return DuplicateEventDialog(self.parent, timeline, event)
    209
    210 -    def GetPeriod(self):
    211          return self.period_picker.GetValue()
    212
    213 -    def SetPeriod(self, value):
    214          self.period_picker.SetValue(value)
    215
    216 -    def GetShowPeriod(self):
    217          return self.period_picker.GetShowPeriod()
    218
    219 -    def SetShowPeriod(self, value):
    220          self.period_picker.SetShowPeriod(value)
    221
    222 -    def GetShowTime(self):
    223          return self.period_picker.GetShowTime()
    224
    225 -    def SetShowTime(self, value):
    226          self.period_picker.SetShowTime(value)
    227
    228 -    def DisableTime(self):
    229          self.period_picker.DisableTime()
    230
    231 -    def GetFuzzy(self):
    232          return self.fuzzy_checkbox.GetValue()
    233
    234 -    def SetFuzzy(self, value):
    235          self.fuzzy_checkbox.SetValue(value)
    236
    237 -    def GetLocked(self):
    238          return self.locked_checkbox.GetValue()
    239
    240 -    def SetLocked(self, value):
    241          self.locked_checkbox.SetValue(value)
    242
    243 -    def EnableLocked(self, value):
    244          self.locked_checkbox.Enable(value)
    245
    246 -    def GetEndsToday(self):
    247          return self.ends_today_checkbox.GetValue()
    248
    249 -    def SetEndsToday(self, value):
    250          self.ends_today_checkbox.SetValue(value)
    251
    252 -    def EnableEndsToday(self, value):
    253          self.ends_today_checkbox.Enable(value)
    254
    255 -    def GetName(self):
    256          return self.name.GetValue().strip()
    257
    258 -    def SetName(self, value):
    259          self.name.SetValue(value)
    260
    261 -    def GetCategory(self):
    262          return self.category_choice.GetSelectedCategory()
    263
    264 -    def SetCategory(self, value):
    265          self.category_choice.Populate(select=value)
    266
    267 -    def GetContainer(self):
    268          return self.container_choice.GetSelectedContainer()
    269
    270 -    def SetContainer(self, value):
    271          self.container_choice.Fill(value)
    272
    273 -    def GetEventData(self):
    274          event_data = {}
    275          for data_id, editor in self._get_event_data():
    276              data = editor.get_data()
    277              if data is not None:
    278                  event_data[data_id] = editor.get_data()
    279          return event_data
    280
    281 -    def SetEventData(self, event_data):
    282          for data_id, editor in self._get_event_data():
    283              if data_id in event_data:
    284                  data = event_data[data_id]
    285                  if data is not None:
    286                      editor.set_data(data)
    287
    288 -    def ClearEventData(self):
    289          for _, editor in self._get_event_data():
    290              editor.clear_data()
    291
    292 -    def IsAddMoreChecked(self):
    293          return self.add_more_checkbox.GetValue()
    294
    295 -    def SetShowAddMoreCheckbox(self, value):
    296          self.add_more_checkbox.Show(value)
    297          self.add_more_checkbox.SetValue(False)
    298          self.SetSizerAndFit(self.GetSizer())
    299
    300 -    def SetFocusOnFirstControl(self):
    301          control = {
    302              "0": self.period_picker,
    303              "1": self.fuzzy_checkbox,
    304              "2": self.name,
    305              "3": self.category_choice,
    306              "4": self.container_choice,
    307              ":": self.notebook,
    308          }[self.config.event_editor_tab_order[0]]
    309          _set_focus_and_select(control)
    310
    311 -    def DisplayInvalidPeriod(self, message):
    312          self._display_invalid_input(message, self.period_picker)
    313
    314 -    def _display_invalid_input(self, message, control):
    315          self.DisplayErrorMessage(message)
    316          _set_focus_and_select(control)
    317
    318 -    def _get_event_data(self):
    319          return [
    320              ("description", self.description),
    321              ("alert", self.alert),
    322              ("icon", self.icon),
    323              ("hyperlink", self.hyperlink),
    324              ("progress", self.progress),
    325              ("default_color", self.default_color)
    326          ]
    327
    328 -    def _insert_rows_in_correct_order_in_xml(self):
    329          rows_by_key = {
    330              "0": self.TIME_DETAILS_ROW,
    331              "1": self.CHECKBOX_ROW,
    332              "2": self.TEXT_FIELD_ROW,
    333              "3": self.CATEGORY_LISTBOX_ROW,
    334              "4": self.CONTAINER_LISTBOX_ROW,
    335              ":": self.NOTEBOOK_ROW,
    336          }
    337          placeholder_content = "".join(rows_by_key[key] for key in self.config.event_editor_tab_order)
    338          self.__doc__ = self.__doc__ % placeholder_content
    339
    340 -    def _make_row_with_notebook_growable(self):
    341          self.grid_sizer.AddGrowableRow(self.config.event_editor_tab_order.index(":"))
    342
    343
    344 -def open_event_editor_for(edit_controller, parent, config, db, event):
    345      def create_event_editor():
    346          if event.is_container():
    347              title = _("Edit Container")
    348              return EditContainerDialog(parent, title, db, event)
    349          else:
    350              return EditEventDialog(
    351                  parent, config, _("Edit Event"), db, event=event)
    352
    353      def edit_function():
    354          dialog = create_event_editor()
    355          dialog.ShowModal()
    356          dialog.Destroy()
    357      safe_locking(edit_controller, edit_function)
    358
    359
    360 -def open_create_event_editor(edit_controller, parent, config, db, start=None, end=None):
    361      def create_event_editor():
    362          label = _("Create Event")
    363          return EditEventDialog(parent, config, label, db, start, end)
    364
    365      def edit_function():
    366          dialog = create_event_editor()
    367          dialog.ShowModal()
    368          dialog.Destroy()
    369      safe_locking(edit_controller, edit_function)
    370