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

# Source Code for Module Gnumed.timelinelib.wxgui.dialogs.duplicateevent

      1  # Copyright (C) 2009, 2010, 2011  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.editors.duplicateevent import DuplicateEventEditor
     22  from timelinelib.wxgui.utils import BORDER
     23  from timelinelib.wxgui.utils import _display_error_message
     24  from timelinelib.wxgui.utils import _set_focus_and_select
     25  import timelinelib.wxgui.utils as gui_utils
     26
     27
     28 -class DuplicateEventDialog(wx.Dialog):
     29
     30 -    def __init__(self, parent, db, event):
     31          wx.Dialog.__init__(self, parent, title=_("Duplicate Event"))
     32          self._create_gui(db.get_time_type().get_duplicate_functions())
     33          self.controller = DuplicateEventEditor(self, db, event)
     34          self.controller.initialize()
     35
     36 -    def set_count(self, count):
     37          self.sc_count.SetValue(count)
     38
     39 -    def get_count(self):
     40          return self.sc_count.GetValue()
     41
     42 -    def set_frequency(self, count):
     43          self.sc_frequency.SetValue(count)
     44
     45 -    def get_frequency(self):
     46          return self.sc_frequency.GetValue()
     47
     48 -    def select_move_period_fn_at_index(self, index):
     49          self.rb_period.SetSelection(index)
     50
     51 -    def get_move_period_fn(self):
     52          return self._move_period_fns[self.rb_period.GetSelection()]
     53
     54 -    def set_direction(self, direction):
     55          self.rb_direction.SetSelection(direction)
     56
     57 -    def get_direction(self):
     58          return self.rb_direction.GetSelection()
     59
     60 -    def close(self):
     61          self.EndModal(wx.ID_OK)
     62
     63 -    def handle_db_error(self, e):
     64          gui_utils.handle_db_error_in_dialog(self, e)
     65
     66 -    def handle_date_errors(self, error_count):
     67         _display_error_message(
     68              _("%d Events not duplicated due to missing dates.")
     69              % error_count)
     70
     71 -    def _create_gui(self, move_period_config):
     72          self._move_period_fns = [fn for (label, fn) in move_period_config]
     73          period_list = [label for (label, fn) in move_period_config]
     74          vbox = wx.BoxSizer(wx.VERTICAL)
     75          self._create_and_add_sc_count_box(vbox)
     76          self._create_and_add_rb_period(vbox, period_list)
     77          self._create_and_add_sc_frequency_box(vbox)
     78          self._create_and_add_rb_direction(vbox)
     79          self._create_and_add_button_box(vbox)
     80          self.SetSizerAndFit(vbox)
     81          _set_focus_and_select(self.sc_count)
     82
     83 -    def _create_and_add_sc_count_box(self, form):
     84          sc_count_box = self._create_count_spin_control()
     85          form.Add(sc_count_box, border=BORDER)
     86
     87 -    def _create_count_spin_control(self):
     88          st_count = wx.StaticText(self, label=_("Number of duplicates:"))
     89          self.sc_count = wx.SpinCtrl(self, wx.ID_ANY, size=(50,-1))
     90          self.sc_count.SetRange(1,999)
     91          self.sc_count.SetValue(1)
     92          hbox = wx.BoxSizer(wx.HORIZONTAL)
     93          hbox.Add(st_count, flag=wx.ALL, border=BORDER)
     94          hbox.Add(self.sc_count, flag=wx.ALL, border=BORDER)
     95          return hbox
     96
     97 -    def _create_and_add_rb_period(self, form, period_list):
     98          self.rb_period = wx.RadioBox(self, wx.ID_ANY, _("Period"),
     99                                       wx.DefaultPosition, wx.DefaultSize,
    100                                       period_list)
    101          form.Add(self.rb_period, flag=wx.ALL|wx.EXPAND, border=BORDER)
    102
    103 -    def _create_and_add_sc_frequency_box(self, form):
    104          sc_frequency_box = self._creat_frequency_spin_control()
    105          form.Add(sc_frequency_box, border=BORDER)
    106
    107 -    def _creat_frequency_spin_control(self):
    108          st_frequency = wx.StaticText(self, label=_("Frequency:"))
    109          self.sc_frequency = wx.SpinCtrl(self, wx.ID_ANY, size=(50,-1))
    110          self.sc_frequency.SetRange(1,999)
    111          self.sc_frequency.SetValue(1)
    112          hbox = wx.BoxSizer(wx.HORIZONTAL)
    113          hbox.Add(st_frequency, flag=wx.ALL, border=BORDER)
    114          hbox.Add(self.sc_frequency, flag=wx.ALL, border=BORDER)
    115          return hbox
    116
    117 -    def _create_and_add_rb_direction(self, form):
    118          direction_list = [_("Forward"), _("Backward"), _("Both")]
    119          self.rb_direction = wx.RadioBox(self, wx.ID_ANY, _("Direction"),
    120                                          choices=direction_list)
    121          form.Add(self.rb_direction, flag=wx.ALL|wx.EXPAND, border=BORDER)
    122
    123 -    def _create_and_add_button_box(self, form):
    124          button_box = self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL)
    125          form.Add(button_box, flag=wx.ALL|wx.EXPAND, border=BORDER)
    126          self.Bind(wx.EVT_BUTTON, self._btn_ok_on_click, id=wx.ID_OK)
    127
    128 -    def _btn_ok_on_click(self, e):
    129          gui_utils.set_wait_cursor(self)
    130          self.controller.create_duplicates_and_save()
    131          gui_utils.set_default_cursor(self)
    132
    133
    134 -def open_duplicate_event_dialog_for_event(parent, db, handle_db_error, event):
    135      def create_dialog():
    136          return DuplicateEventDialog(parent, db, event)
    137      gui_utils.show_modal(create_dialog, handle_db_error)
    138