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

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

      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 os
     20
     21  import wx
     22
     23  from timelinelib.wxgui.components.font import deserialize_font
     24  from timelinelib.wxgui.framework import Controller
     25  from timelinelib.config.paths import EVENT_ICONS_DIR
     26
     27
     28 -class PreferencesDialogController(Controller):
     29
     30 -    def on_init(self, config, experimental_features):
     31          self.config = config
     32          self.experimental_features = experimental_features
     33          self.weeks_map = ((0, "monday"), (1, "sunday"))
     34          self._set_initial_values()
     35
     36 -    def on_close(self):
     37          self.config.minor_strip_divider_line_colour = str(self.view.GetMinorStripColor())
     38          self.config.major_strip_divider_line_colour = str(self.view.GetMajorStripColor())
     39          self.config.now_line_colour = str(self.view.GetNowLineColor())
     40          self.config.weekend_colour = str(self.view.GetWeekendColor())
     41          self.config.bg_colour = str(self.view.GetBgColor())
     42          self.config.legend_pos = self.view.GetLegendPos()
     43
     44 -    def on_open_recent_change(self, event):
     45          self.config.open_recent_at_startup = event.IsChecked()
     46
     47 -    def on_inertial_scrolling_changed(self, event):
     48          self.config.use_inertial_scrolling = event.IsChecked()
     49
     50 -    def on_never_period_point_changed(self, event):
     51          self.config.never_show_period_events_as_point_events = event.IsChecked()
     52
     53 -    def on_center_text_changed(self, event):
     54          self.config.center_event_texts = event.IsChecked()
     55
     56 -    def on_display_checkmark_on_events_done_changed(self, event):
     57          self.config.display_checkmark_on_events_done = event.IsChecked()
     58
     59 -    def on_week_start_changed(self, event):
     60          self.config.set_week_start(self._index_week(event.GetSelection()))
     61
     62 -    def on_date_formatter_click(self, event):
     63          self.view.ShowSelectDateFormatDialog(self.config)
     64          self.view.SetCurrentDateFormat("%s: %s" % (_("Current"), self.config.date_format))
     65
     66 -    def on_uncheck_time_for_new_events(self, event):
     67          self.config.uncheck_time_for_new_events = event.IsChecked()
     68
     69 -    def on_text_below_icon(self, event):
     70          self.config.text_below_icon = event.IsChecked()
     71
     72 -    def on_filtered_listbox_export(self, event):
     73          self.config.filtered_listbox_export = event.IsChecked()
     74
     75 -    def on_tab_order_click(self, event):
     76          self.view.ShowSelectTabOrderDialog(self.config)
     77
     78 -    def on_balloon_click(self, evt):
     79          font = deserialize_font(self.config.balloon_font)
     80          if self.view.ShowEditFontDialog(font):
     81              self.config.balloon_font = font.serialize()
     82              self.view.SetBalloonFont(font)
     83
     84 -    def on_major_strip_click(self, event):
     85          font = deserialize_font(self.config.major_strip_font)
     86          if self.view.ShowEditFontDialog(font):
     87              self.config.major_strip_font = font.serialize()
     88              self.view.SetMajorStripFont(font)
     89
     90 -    def on_minor_strip_click(self, event):
     91          font = deserialize_font(self.config.minor_strip_font)
     92          if self.view.ShowEditFontDialog(font):
     93              self.config.minor_strip_font = font.serialize()
     94              self.view.SetMinorStripFont(font)
     95
     96 -    def on_legend_click(self, event):
     97          font = deserialize_font(self.config.legend_font)
     98          if self.view.ShowEditFontDialog(font):
     99              self.config.legend_font = font.serialize()
    100              self.view.SetLegendFont(font)
    101
    102 -    def on_experimental_changed(self, event):
    103          self.experimental_features.set_active_state_on_feature_by_name(
    104              event.GetEventObject().GetLabel(), event.IsChecked())
    105          self.config.experimental_features = str(self.experimental_features)
    106
    107 -    def on_fuzzy_icon_changed(self, event):
    108          self.config.fuzzy_icon = event.GetString()
    109          self.view.DisplayIcons()
    110
    111 -    def on_locked_icon_changed(self, event):
    112          self.config.locked_icon = event.GetString()
    113          self.view.DisplayIcons()
    114
    115 -    def on_hyperlink_icon_changed(self, event):
    116          self.config.hyperlink_icon = event.GetString()
    117          self.view.DisplayIcons()
    118
    119 -    def on_vertical_space_between_events_click(self, event):
    120          self.config.vertical_space_between_events = self.view.GetVerticalSpaceBetweenEvents()
    121
    122 -    def on_colorize_weekends(self, event):
    123          self.config.colorize_weekends = self.view.GetColorizeWeekends()
    124
    125 -    def on_skip_s_in_decade_text(self, event):
    126          self.config.skip_s_in_decade_text = self.view.GetSkipSInDecadeText()
    127
    128 -    def on_never_use_time_change(self, event):
    129          self.config.never_use_time = self.view.GetNeverUseTime()
    130
    131 -    def _set_initial_values(self):
    132          self.view.SetOpenRecentCheckboxValue(self.config.open_recent_at_startup)
    133          self.view.SetInertialScrollingCheckboxValue(self.config.use_inertial_scrolling)
    134          self.view.SetNeverPeriodPointCheckboxValue(self.config.never_show_period_events_as_point_events)
    135          self.view.SetCenterTextCheckboxValue(self.config.center_event_texts)
    136          self.view.SetWeekStartSelection(self._week_index(self.config.get_week_start()))
    137          self.view.AddExperimentalFeatures(self.experimental_features.get_all_features())
    138          self.view.SetUncheckTimeForNewEventsCheckboxValue(self.config.uncheck_time_for_new_events)
    139          self.view.SetTextBelowIconCheckboxValue(self.config.text_below_icon)
    140          self.view.SetFilteredListboxExport(self.config.filtered_listbox_export)
    141          self.view.SetMinorStripColor(wx.Colour(*self.config.minor_strip_divider_line_colour))
    142          self.view.SetMajorStripColor(wx.Colour(*self.config.major_strip_divider_line_colour))
    143          self.view.SetNowLineColor(wx.Colour(*self.config.now_line_colour))
    144          self.view.SetWeekendColor(wx.Colour(*self.config.weekend_colour))
    145          self.view.SetBgColor(wx.Colour(*self.config.bg_colour))
    146          choices = [f for f in os.listdir(EVENT_ICONS_DIR) if f.endswith(".png")]
    147          self.view.SetIconsChoices(choices)
    148          self.view.SetFuzzyIcon(self.config.fuzzy_icon)
    149          self.view.SetLockedIcon(self.config.locked_icon)
    150          self.view.SetHyperlinkIcon(self.config.hyperlink_icon)
    151          self.view.SetCurrentDateFormat("%s: %s" % (_("Current"), self.config.date_format))
    152          self.view.DisplayIcons()
    153          self.view.SetVerticalSpaceBetweenEvents(self.config.vertical_space_between_events)
    154          self.view.SetColorizeWeekends(self.config.colorize_weekends)
    155          self.view.SetSkipSInDecadeText(self.config.skip_s_in_decade_text)
    156          self.view.SetDisplayCheckmarkOnEventsDone(self.config.display_checkmark_on_events_done)
    157          self.view.SetNeverUseTime(self.config.never_use_time)
    158          self.view.SetMajorStripFont(deserialize_font(self.config.major_strip_font))
    159          self.view.SetMinorStripFont(deserialize_font(self.config.minor_strip_font))
    160          self.view.SetLegendFont(deserialize_font(self.config.legend_font))
    161          self.view.SetBalloonFont(deserialize_font(self.config.balloon_font))
    162          self.view.SetLegendPos(self.config.legend_pos)
    163
    164 -    def _week_index(self, week):
    165          for (i, w) in self.weeks_map:
    166              if w == week:
    167                  return i
    168          raise ValueError("Unknown week '%s'." % week)
    169
    170 -    def _index_week(self, index):
    171          for (i, w) in self.weeks_map:
    172              if i == index:
    173                  return w
    174          raise ValueError("Unknown week index '%s'." % index)
    175