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

# Source Code for Module Gnumed.timelinelib.wxgui.components.messagebar

     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.canvas.drawing.utils import darken_color
    22
    23
    24  WARNING_BG_COLOR = (251, 100, 100)
    25  INFO_BG_COLOR = ((251, 203, 58))
    26
    27
    28 -class MessageBar(wx.Panel):
    29
    30      """
    31      This class is used to create (or hide) a message text displayed
    32      at the top of the Timeline window.
    33      A message comes in two flavors:
    34         - Information message
    35         - Warning message
    36      What distinguishes the two flavors is the background color of the
    37      message text area.
    38      """
    39
    40 -    def __init__(self, parent, name=None):
    41          """The name parameter is needed for testing purposes."""
    42          wx.Panel.__init__(self, parent, style=wx.BORDER_NONE)
    43          self._create_gui()
    44
    45 -    def ShowWarningMessage(self, message):
    46          self._show_message(message, WARNING_BG_COLOR)
    47
    48 -    def ShowInformationMessage(self, message):
    49          self._show_message(message, INFO_BG_COLOR)
    50
    51 -    def ShowNoMessage(self):
    52          self.Hide()
    53          self.GetParent().Layout()
    54
    55 -    def _create_gui(self):
    56          self._inner_panel = wx.Panel(self)
    57          self._label = wx.StaticText(self._inner_panel, style=wx.ALIGN_CENTRE_HORIZONTAL)
    58          self._add_with_border(self, self._inner_panel, 2, style=wx.EXPAND)
    59          self._add_with_border(self._inner_panel, self._label, 5, style=wx.ALIGN_CENTER)
    60
    61 -    def _add_with_border(self, parent, child, border, style=0):
    62          sizer = wx.BoxSizer(wx.VERTICAL)
    63          sizer.Add(child, proportion=1, flag=wx.ALL | style, border=border)
    64          parent.SetSizer(sizer)
    65
    66 -    def _show_message(self, message, color):
    67          self._set_colour(color)
    68          self._set_message(message)
    69          self._repaint_window()
    70
    71 -    def _set_colour(self, colour):
    72          self.SetBackgroundColour(darken_color(colour))
    73          self._inner_panel.SetBackgroundColour(colour)
    74
    75 -    def _set_message(self, message):
    76          self._label.SetLabel(message)
    77
    78 -    def _repaint_window(self):
    79          self.Refresh()
    80          self.Show()
    81          self.GetParent().Layout()
    82