Gnumed.timelinelib.wxgui.components.propertyeditors.descriptioneditor

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

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

     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 DescriptionEditorGuiCreator(wx.Panel):
    25
    26 -    def __init__(self, parent):
    27          wx.Panel.__init__(self, parent)
    28
    29 -    def create_sizer(self):
    30          return wx.BoxSizer()
    31
    32 -    def create_controls(self):
    33          text = self._create_text_control()
    34          return (text,)
    35
    36 -    def put_controls_in_sizer(self, sizer, controls):
    37          text, = controls
    38          sizer.Add(text, 1, wx.ALL | wx.EXPAND, 0)
    39
    40 -    def _create_text_control(self):
    41          self.data = wx.TextCtrl(self, style=wx.TE_MULTILINE)
    42          self.data.Bind(wx.EVT_CHAR, self._on_char)
    43          self.data.Bind(wx.EVT_KEY_DOWN, self._on_key_down)
    44          return self.data
    45
    46 -    def _on_char(self, evt):
    47          if self._ctrl_a(evt):
    48              self.data.SetSelection(-1, -1)
    49          else:
    50              evt.Skip()
    51
    52 -    def _on_key_down(self, evt):
    53          if self._ctrl_plus(evt):
    54              self._increase_font()
    55          elif self._ctrl_minus(evt):
    56              self._decrease_font()
    57          else:
    58              evt.Skip()
    59
    60 -    def _increase_font(self):
    61          font = self.data.GetFont()
    62          font.MakeLarger()
    63          self.data.SetFont(font)
    64
    65 -    def _decrease_font(self):
    66          font = self.data.GetFont()
    67          font.MakeSmaller()
    68          self.data.SetFont(font)
    69
    70 -    def _ctrl_a(self, evt):
    71          KEY_CODE_A = 1
    72          return evt.ControlDown() and evt.KeyCode == KEY_CODE_A
    73
    74 -    def _ctrl_plus(self, evt):
    75          KEY_CODE_PLUS = 43
    76          return evt.ControlDown() and evt.KeyCode == KEY_CODE_PLUS
    77
    78 -    def _ctrl_minus(self, evt):
    79          KEY_CODE_MINUS = 45
    80          return evt.ControlDown() and evt.KeyCode == KEY_CODE_MINUS
    81
    82
    83 -class DescriptionEditor(BaseEditor, DescriptionEditorGuiCreator):
    84
    85 -    def __init__(self, parent, editor, name=""):
    86          BaseEditor.__init__(self, parent, editor)
    87          DescriptionEditorGuiCreator.__init__(self, parent)
    88          self.create_gui()
    89
    90 -    def get_data(self):
    91          description = self.data.GetValue().strip()
    92          if description != "":
    93              return description
    94          return None
    95
    96 -    def clear_data(self):
    97          self.data.SetValue("")
    98