Gnumed.timelinelib.wxgui.dialogs.preferences.controller

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          self.config.time_scale_pos = self.view.GetTimeScalePos()
     44          self.config.default_year = self.view.GetDefaultYear()
     45          self.config.default_month = self.view.GetDefaultMonth()
     46          self.config.default_day = self.view.GetDefaultDay()
     47
     48 -    def on_open_recent_change(self, event):
     49          self.config.open_recent_at_startup = event.IsChecked()
     50
     51 -    def on_inertial_scrolling_changed(self, event):
     52          self.config.use_inertial_scrolling = event.IsChecked()
     53
     54 -    def on_never_period_point_changed(self, event):
     55          self.config.never_show_period_events_as_point_events = event.IsChecked()
     56
     57 -    def on_center_text_changed(self, event):
     58          self.config.center_event_texts = event.IsChecked()
     59
     60 -    def on_display_checkmark_on_events_done_changed(self, event):
     61          self.config.display_checkmark_on_events_done = event.IsChecked()
     62
     63 -    def on_week_start_changed(self, event):
     64          self.config.set_week_start(self._index_week(event.GetSelection()))
     65
     66 -    def on_date_formatter_click(self, event):
     67          self.view.ShowSelectDateFormatDialog(self.config)
     68          self.view.SetCurrentDateFormat("%s: %s" % (_("Current"), self.config.date_format))
     69
     70 -    def on_uncheck_time_for_new_events(self, event):
     71          self.config.uncheck_time_for_new_events = event.IsChecked()
     72
     73 -    def on_text_below_icon(self, event):
     74          self.config.text_below_icon = event.IsChecked()
     75
     76 -    def on_filtered_listbox_export(self, event):
     77          self.config.filtered_listbox_export = event.IsChecked()
     78
     79 -    def on_tab_order_click(self, event):
     80          self.view.ShowSelectTabOrderDialog(self.config)
     81
     82 -    def on_balloon_click(self, evt):
     83          font = deserialize_font(self.config.balloon_font)
     84          if self.view.ShowEditFontDialog(font):
     85              self.config.balloon_font = font.serialize()
     86              self.view.SetBalloonFont(font)
     87
     88 -    def on_major_strip_click(self, event):
     89          font = deserialize_font(self.config.major_strip_font)
     90          if self.view.ShowEditFontDialog(font):
     91              self.config.major_strip_font = font.serialize()
     92              self.view.SetMajorStripFont(font)
     93
     94 -    def on_minor_strip_click(self, event):
     95          font = deserialize_font(self.config.minor_strip_font)
     96          if self.view.ShowEditFontDialog(font):
     97              self.config.minor_strip_font = font.serialize()
     98              self.view.SetMinorStripFont(font)
     99
    100 -    def on_legend_click(self, event):
    101          font = deserialize_font(self.config.legend_font)
    102          if self.view.ShowEditFontDialog(font):
    103              self.config.legend_font = font.serialize()
    104              self.view.SetLegendFont(font)
    105
    106 -    def on_experimental_changed(self, event):
    107          self.experimental_features.set_active_state_on_feature_by_name(
    108              event.GetEventObject().GetLabel(), event.IsChecked())
    109          self.config.experimental_features = str(self.experimental_features)
    110
    111 -    def on_fuzzy_icon_changed(self, event):
    112          self.config.fuzzy_icon = event.GetString()
    113          self.view.DisplayIcons()
    114
    115 -    def on_locked_icon_changed(self, event):
    116          self.config.locked_icon = event.GetString()
    117          self.view.DisplayIcons()
    118
    119 -    def on_hyperlink_icon_changed(self, event):
    120          self.config.hyperlink_icon = event.GetString()
    121          self.view.DisplayIcons()
    122
    123 -    def on_vertical_space_between_events_click(self, event):
    124          self.config.vertical_space_between_events = self.view.GetVerticalSpaceBetweenEvents()
    125
    126 -    def on_use_bold_nowline(self, event):
    127          self.config.use_bold_nowline = self.view.GetUseBoldNowline()
    128
    129 -    def on_colorize_weekends(self, event):
    130          self.config.colorize_weekends = self.view.GetColorizeWeekends()
    131
    132 -    def on_skip_s_in_decade_text(self, event):
    133          self.config.skip_s_in_decade_text = self.view.GetSkipSInDecadeText()
    134
    135 -    def on_never_use_time_change(self, event):
    136          self.config.never_use_time = self.view.GetNeverUseTime()
    137
    138 -    def on_use_second_change(self, event):
    139          self.config.use_second = self.view.GetUseSecond()
    140
    141 -    def on_use_date_default_values(self, event):
    142          self.config.use_date_default_values = self.view.GetUseDateDefaultValues()
    143
    144 -    def _set_initial_values(self):
    145          self.view.SetOpenRecentCheckboxValue(self.config.open_recent_at_startup)
    146          self.view.SetInertialScrollingCheckboxValue(self.config.use_inertial_scrolling)
    147          self.view.SetNeverPeriodPointCheckboxValue(self.config.never_show_period_events_as_point_events)
    148          self.view.SetCenterTextCheckboxValue(self.config.center_event_texts)
    149          self.view.SetWeekStartSelection(self._week_index(self.config.get_week_start()))
    150          self.view.AddExperimentalFeatures(self.experimental_features.get_all_features())
    151          self.view.SetUncheckTimeForNewEventsCheckboxValue(self.config.uncheck_time_for_new_events)
    152          self.view.SetTextBelowIconCheckboxValue(self.config.text_below_icon)
    153          self.view.SetFilteredListboxExport(self.config.filtered_listbox_export)
    154          self.view.SetMinorStripColor(wx.Colour(*self.config.minor_strip_divider_line_colour))
    155          self.view.SetMajorStripColor(wx.Colour(*self.config.major_strip_divider_line_colour))
    156          self.view.SetNowLineColor(wx.Colour(*self.config.now_line_colour))
    157          self.view.SetWeekendColor(wx.Colour(*self.config.weekend_colour))
    158          self.view.SetBgColor(wx.Colour(*self.config.bg_colour))
    159          choices = [f for f in os.listdir(EVENT_ICONS_DIR) if f.endswith(".png")]
    160          self.view.SetIconsChoices(choices)
    161          self.view.SetFuzzyIcon(self.config.fuzzy_icon)
    162          self.view.SetLockedIcon(self.config.locked_icon)
    163          self.view.SetHyperlinkIcon(self.config.hyperlink_icon)
    164          self.view.SetCurrentDateFormat("%s: %s" % (_("Current"), self.config.date_format))
    165          self.view.DisplayIcons()
    166          self.view.SetVerticalSpaceBetweenEvents(self.config.vertical_space_between_events)
    167          self.view.SetColorizeWeekends(self.config.colorize_weekends)
    168          self.view.SetUseBoldNowline(self.config.use_bold_nowline)
    169          self.view.SetSkipSInDecadeText(self.config.skip_s_in_decade_text)
    170          self.view.SetDisplayCheckmarkOnEventsDone(self.config.display_checkmark_on_events_done)
    171          self.view.SetNeverUseTime(self.config.never_use_time)
    172          self.view.SetUseSecond(self.config.use_second)
    173          self.view.SetUseDateDefaultValues(self.config.use_date_default_values)
    174          self.view.SetDefaultYear(self.config.default_year)
    175          self.view.SetDefaultMonth(self.config.default_month)
    176          self.view.SetDefaultDay(self.config.default_day)
    177          self.view.SetMajorStripFont(deserialize_font(self.config.major_strip_font))
    178          self.view.SetMinorStripFont(deserialize_font(self.config.minor_strip_font))
    179          self.view.SetLegendFont(deserialize_font(self.config.legend_font))
    180          self.view.SetBalloonFont(deserialize_font(self.config.balloon_font))
    181          self.view.SetLegendPos(self.config.legend_pos)
    182          self.view.SetTimeScalePos(self.config.time_scale_pos)
    183
    184 -    def _week_index(self, week):
    185          for (i, w) in self.weeks_map:
    186              if w == week:
    187                  return i
    188          raise ValueError("Unknown week '%s'." % week)
    189
    190 -    def _index_week(self, index):
    191          for (i, w) in self.weeks_map:
    192              if i == index:
    193                  return w
    194          raise ValueError("Unknown week index '%s'." % index)
    195