Gnumed.timelinelib.wxgui.dialogs.preferences

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

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

      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.config.preferences import PreferencesEditor
     22  from timelinelib.wxgui.utils import BORDER
     23
     24
     25 -class PreferencesDialog(wx.Dialog):
     26
     27 -    def __init__(self, parent, config):
     28          wx.Dialog.__init__(self, parent, title=_("Preferences"))
     29          self._create_gui()
     30          self._controller = PreferencesEditor(self, config)
     31          self._controller.initialize_controls()
     32
     33 -    def set_checkbox_enable_wide_date_range(self, value):
     34          self.chb_wide_date_range.SetValue(value)
     35
     36 -    def set_checkbox_use_inertial_scrolling(self, value):
     37          self.chb_inertial_scrolling.SetValue(value)
     38
     39 -    def set_checkbox_open_recent_at_startup(self, value):
     40          self.chb_open_recent.SetValue(value)
     41
     42 -    def set_week_start(self, index):
     43          self.choice_week.SetSelection(index)
     44
     45 -    def _create_gui(self):
     46          main_box = self._create_main_box()
     47          self.SetSizerAndFit(main_box)
     48
     49 -    def _create_main_box(self):
     50          notebook = self._create_nootebook_control()
     51          button_box = self._create_button_box()
     52          main_box = wx.BoxSizer(wx.VERTICAL)
     53          flag = wx.ALL|wx.EXPAND
     54          main_box.Add(notebook, flag=flag, border=BORDER, proportion=1)
     55          main_box.Add(button_box, flag=flag, border=BORDER)
     56          return main_box
     57
     58 -    def _create_nootebook_control(self):
     59          notebook = wx.Notebook(self, style=wx.BK_DEFAULT)
     60          self._create_general_tab(notebook)
     61          self._create_date_time_tab(notebook)
     62          return notebook
     63
     64 -    def _create_button_box(self):
     65          btn_close = self._create_close_button()
     66          button_box = wx.BoxSizer(wx.HORIZONTAL)
     67          button_box.AddStretchSpacer()
     68          button_box.Add(btn_close, flag=wx.LEFT, border=BORDER)
     69          return button_box
     70
     71 -    def _create_general_tab(self, notebook):
     72          panel = self._create_tab_panel(notebook, _("General"))
     73          controls = self._create_general_tab_controls(panel)
     74          self._size_tab_panel(panel, controls)
     75
     76 -    def _create_general_tab_controls(self, panel):
     77          self.chb_open_recent = self._create_chb_open_recent(panel)
     78          self.chb_inertial_scrolling = self._create_chb_inertial_scrolling(panel)
     79          return (self.chb_open_recent, self.chb_inertial_scrolling)
     80
     81 -    def _create_date_time_tab(self, notebook):
     82          panel = self._create_tab_panel(notebook, _("Date && Time"))
     83          controls = self._create_date_time_tab_controls(panel)
     84          self._size_tab_panel(panel, controls)
     85
     86 -    def _create_date_time_tab_controls(self, panel):
     87          self.chb_wide_date_range = self._create_chb_wide_date_range(panel)
     88          self.choice_week = self._create_choice_week(panel)
     89          grid = wx.FlexGridSizer(1, 2, BORDER, BORDER)
     90          grid.Add(wx.StaticText(panel, label=_("Week start on:")),
     91                   flag=wx.ALIGN_CENTER_VERTICAL)
     92          grid.Add(self.choice_week, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
     93          warning = _("This feature is experimental. If events are\ncreated in the extended range, you can not\ndisable this option and successfully load\nthe timeline again. A reload of the timeline\nis also needed for this to take effect.")
     94          warning_text_control = wx.StaticText(panel, label=warning)
     95          warning_text_control.SetForegroundColour((255, 0, 0))
     96          return (grid, self.chb_wide_date_range, warning_text_control)
     97
     98 -    def _create_tab_panel(self, notebook, label):
     99          panel = wx.Panel(notebook)
    100          notebook.AddPage(panel, label)
    101          return panel
    102
    103 -    def _size_tab_panel(self, panel, controls):
    104          sizer = wx.BoxSizer(wx.VERTICAL)
    105          for control in controls:
    106              sizer.Add(control, flag=wx.ALL|wx.EXPAND, border=BORDER)
    107          panel.SetSizer(sizer)
    108
    109 -    def _create_chb_open_recent(self, panel):
    110          label = _("Open most recent timeline on startup")
    111          handler = self._chb_open_recent_startup_on_checkbox
    112          chb = self._create_chb(panel, label, handler)
    113          return chb
    114
    115 -    def _create_chb_inertial_scrolling(self, panel):
    116          label = _("Use inertial scrolling")
    117          handler = self._chb_use_inertial_scrolling_on_checkbox
    118          chb = self._create_chb(panel, label, handler)
    119          return chb
    120
    121 -    def _create_chb_wide_date_range(self, panel):
    122          label = _("Use extended date range (before 1 AD)")
    123          handler = self._chb_use_wide_date_range_on_checkbox
    124          chb = self._create_chb(panel, label, handler)
    125          return chb
    126
    127 -    def _create_chb(self, panel, label, handler):
    128          chb = wx.CheckBox(panel, label=label)
    129          self.Bind(wx.EVT_CHECKBOX, handler, chb)
    130          return chb
    131
    132 -    def _create_choice_week(self, panel):
    133          choice_week = wx.Choice(panel, choices=[_("Monday"), _("Sunday")])
    134          self.Bind(wx.EVT_CHOICE, self._choice_week_on_choice, choice_week)
    135          return choice_week
    136
    137 -    def _create_close_button(self):
    138          btn_close = wx.Button(self, wx.ID_CLOSE)
    139          btn_close.SetDefault()
    140          btn_close.SetFocus()
    141          self.SetAffirmativeId(wx.ID_CLOSE)
    142          self.Bind(wx.EVT_BUTTON, self._btn_close_on_click, btn_close)
    143          return btn_close
    144
    145 -    def _chb_use_wide_date_range_on_checkbox(self, evt):
    146          self._controller.on_use_wide_date_range_changed(evt.IsChecked())
    147
    148 -    def _chb_use_inertial_scrolling_on_checkbox(self, evt):
    149          self._controller.on_use_inertial_scrolling_changed(evt.IsChecked())
    150
    151 -    def _chb_open_recent_startup_on_checkbox(self, evt):
    152          self._controller.on_open_recent_changed(evt.IsChecked())
    153
    154 -    def _choice_week_on_choice(self, evt):
    155          self._controller.on_week_start_changed(evt.IsChecked())
    156
    157 -    def _btn_close_on_click(self, e):
    158          self.Close()
    159