Package Gnumed :: Package timelinelib :: Package wxgui :: Package dialogs :: Package export :: Module controller |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.wxgui.dialogs.export.controller

     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  from timelinelib.wxgui.dialogs.fieldselection.controller import FIELDS
    20  from timelinelib.wxgui.framework import Controller
    21
    22
    23  CSV_FILE = _("CSV File")
    24  TARGET_TYPES = (CSV_FILE,)
    25  TEXT_ENCODINGS = ("utf-8", "cp1252", "cp850")
    26
    27
    28 -class ExportDialogController(Controller):
    29
    30 -    def on_init(self):
    31          self.event_fields = FIELDS["Event"]
    32          self.category_fields = FIELDS["Category"]
    33          self.view.SetTargetTypes(TARGET_TYPES)
    34          self.view.SetTextEncodings(TEXT_ENCODINGS)
    35          self.view.SetEvents(True)
    36          self.view.SetCategories(False)
    37
    38 -    def on_ok(self, evt):
    39          try:
    40              if self._validate_input():
    41                  self.view.Close()
    42          except ValueError:
    43              pass
    44
    45 -    def on_edit_event_fields(self, evt):
    46          self.view.EditEventFields()
    47
    48 -    def on_edit_categories_fields(self, evt):
    49          self.view.EditCategoryFields()
    50
    51 -    def get_event_fields(self):
    52          return self.event_fields
    53
    54 -    def set_event_fields(self, fields):
    55          self.event_fields = fields
    56
    57 -    def get_category_fields(self):
    58          return self.category_fields
    59
    60 -    def set_category_fields(self, fields):
    61          self.category_fields = fields
    62
    63 -    def _validate_input(self):
    64          if not self.view.GetExportEvents() and not self.view.GetExportCategories():
    65              self.view.DisplayInformationMessage(_("Invalid Data"), _("At least one Export Item must be selected"))
    66              return False
    67          if self.view.GetExportEvents() and self.event_fields == []:
    68              self.view.DisplayInformationMessage(_("Invalid Data"), _("At least one Event Field must be selected"))
    69              return False
    70          if self.view.GetExportCategories() and self.category_fields == []:
    71              self.view.DisplayInformationMessage(_("Invalid Data"), _("At least one Category Field must be selected"))
    72              return False
    73          return True
    74