Gnumed.timelinelib.wxgui.frames.mainframe.toolbar

Package Gnumed :: Package timelinelib :: Package wxgui :: Package frames :: Package mainframe :: Module toolbar |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.wxgui.frames.mainframe.toolbar

     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
    22 -class ToolbarCreator(object):
    23
    24 -    def __init__(self, parent, config):
    25          self._parent = parent
    26          self._config = config
    27
    28 -    def create(self):
    29          self.toolbar = self._parent.CreateToolbar()
    30          self._add_event_text_alignment()
    31          self.toolbar.AddSeparator()
    32          self._add_point_event_alignment()
    33          self.toolbar.Realize()
    34          self._set_visibility()
    35          self._config.listen_for_any(self._set_visibility)
    36          return self.toolbar
    37
    38 -    def _add_event_text_alignment(self):
    39          spec = {'tool-1-name': _("Center"),
    40                  'tool-2-name': _("Left"),
    41                  'tool-1-image': 'format-justify-center.png',
    42                  'tool-2-image': 'format-justify-left.png',
    43                  'config-name': 'center_event_texts',
    44                  }
    45          self._toggle_toolbar(spec)
    46
    47 -    def _add_point_event_alignment(self):
    48          spec = {'tool-1-name': _("Left"),
    49                  'tool-2-name': _("Center"),
    50                  'tool-1-image': 'event-line-left.png',
    51                  'tool-2-image': 'event-line-center.png',
    52                  'config-name': 'draw_point_events_to_right',
    53                  }
    54          self._toggle_toolbar(spec)
    55
    56 -    def _add_radio(self, text, icon):
    57          return self.toolbar.AddRadioTool(
    58              wx.ID_ANY,
    59              text,
    60              self._parent.BitmapFromIcon(icon),
    61              shortHelp=text
    62          )
    63
    64 -    def _set_visibility(self):
    65          self.toolbar.Show(self._config.show_toolbar)
    66          self._parent.Layout()
    67
    68 -    def _toggle_toolbar(self, spec):
    69          first_tool = self._add_radio(spec['tool-1-name'], spec['tool-1-image'])
    70          second_tool = self._add_radio(spec['tool-2-name'], spec['tool-2-image'])
    71
    72          def on_first_tool_click(event):
    73              self._config._set(spec['config-name'], True)
    74
    75          def on_second_tool_click(event):
    76              self._config._set(spec['config-name'], False)
    77
    78          def check_item_corresponding_to_config():
    79              if self._config._get(spec['config-name']):
    80                  self.toolbar.ToggleTool(first_tool.GetId(), True)
    81              else:
    82                  self.toolbar.ToggleTool(second_tool.GetId(), True)
    83          self._parent.Bind(wx.EVT_TOOL, on_first_tool_click, first_tool)
    84          self._parent.Bind(wx.EVT_TOOL, on_second_tool_click, second_tool)
    85          self._config.listen_for_any(check_item_corresponding_to_config)
    86          check_item_corresponding_to_config()
    87