Gnumed.timelinelib.wxgui.components.propertyeditors.alerteditor

Package Gnumed :: Package timelinelib :: Package wxgui :: Package components :: Package propertyeditors :: Module alerteditor |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.wxgui.components.propertyeditors.alerteditor

      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.wxgui.components.propertyeditors.baseeditor import BaseEditor
     22
     23
     24 -class AlertEditorGuiCreator(wx.Panel):
     25
     26 -    def __init__(self, parent):
     27          self.parent = parent
     28          wx.Panel.__init__(self, parent)
     29
     30 -    def create_sizer(self):
     31          return wx.GridBagSizer(vgap=5, hgap=5)
     32
     33 -    def create_controls(self):
     34          self.btn_add = self._create_add_button()
     35          self.btn_clear = self._create_clear_button()
     36          self.input_panel = self._create_input_controls()
     37          return (self.btn_add, self.btn_clear, self.input_panel)
     38
     39 -    def put_controls_in_sizer(self, sizer, controls):
     40          btn_add, btn_clear, input_panel = controls
     41          sizer.Add(btn_add, wx.GBPosition(0, 0), wx.GBSpan(1, 1))
     42          sizer.Add(btn_clear, wx.GBPosition(0, 1), wx.GBSpan(1, 1))
     43          sizer.Add(input_panel, wx.GBPosition(1, 0), wx.GBSpan(4, 5))
     44
     45 -    def _create_add_button(self):
     46          btn_add = wx.Button(self, wx.ID_ADD)
     47          self.Bind(wx.EVT_BUTTON, self._btn_add_on_click, btn_add)
     48          return btn_add
     49
     50 -    def _create_clear_button(self):
     51          btn_clear = wx.Button(self, wx.ID_CLEAR)
     52          self.Bind(wx.EVT_BUTTON, self._btn_clear_on_click, btn_clear)
     53          return btn_clear
     54
     55 -    def _create_input_controls(self):
     56          alert_panel = wx.Panel(self)
     57          alert_panel.on_return = self._on_return
     58          time_type = self.editor.timeline.get_time_type()
     59          self.dtp_start = time_type.create_time_picker(alert_panel, config=self.editor.config)
     60          self.text_data = wx.TextCtrl(alert_panel, size=(300, 80), style=wx.TE_MULTILINE)
     61          self.data = self.dtp_start
     62          self._layout_input_controls(alert_panel)
     63          return alert_panel
     64
     65 -    def _on_return(self):
     66          self.parent.on_return()
     67
     68 -    def _layout_input_controls(self, alert_panel):
     69          when = wx.StaticText(alert_panel, label=_("When:"))
     70          text = wx.StaticText(alert_panel, label=_("Text:"))
     71          sizer = wx.GridBagSizer(5, 10)
     72          sizer.Add(when, wx.GBPosition(0, 0), wx.GBSpan(1, 1))
     73          sizer.Add(self.dtp_start, wx.GBPosition(0, 1), wx.GBSpan(1, 3))
     74          sizer.Add(text, wx.GBPosition(1, 0), wx.GBSpan(1, 1))
     75          sizer.Add(self.text_data, wx.GBPosition(1, 1), wx.GBSpan(1, 9))
     76          alert_panel.SetSizerAndFit(sizer)
     77
     78
     79 -class AlertEditor(BaseEditor, AlertEditorGuiCreator):
     80
     81 -    def __init__(self, parent, editor, name=""):
     82          BaseEditor.__init__(self, parent, editor)
     83          AlertEditorGuiCreator.__init__(self, parent)
     84          self.create_gui()
     85          self._initialize_data()
     86
     87 -    def _initialize_data(self):
     88          self._set_initial_time()
     89          self._set_initial_text()
     90          self._set_visible(False)
     91
     92 -    def _set_initial_time(self):
     93          if self.editor.event is not None:
     94              self.dtp_start.set_value(self.editor.event.get_start_time())
     95          else:
     96              self.dtp_start.set_value(self.editor.start)
     97
     98 -    def _set_initial_text(self):
     99          self.text_data.SetValue("")
    100
    101 -    def get_data(self):
    102          if self.input_visible:
    103              time = self.dtp_start.get_value()
    104              text = self.text_data.GetValue()
    105              return (time, text)
    106          else:
    107              return None
    108
    109 -    def set_data(self, data):
    110          if data is None:
    111              self._set_visible(False)
    112          else:
    113              self._set_visible(True)
    114              time, text = data
    115              self.dtp_start.set_value(time)
    116              self.text_data.SetValue(text)
    117
    118 -    def _btn_add_on_click(self, evt):
    119          self._set_visible(True)
    120
    121 -    def _btn_clear_on_click(self, evt):
    122          self.clear_data()
    123
    124 -    def clear_data(self):
    125          self._set_initial_time()
    126          self._set_initial_text()
    127          self._set_visible(False)
    128
    129 -    def _set_visible(self, value):
    130          self.input_visible = value
    131          self.input_panel.Show(self.input_visible)
    132          self.btn_add.Enable(not value)
    133          self.btn_clear.Enable(value)
    134          self.GetSizer().Layout()
    135