Project

Profile

Help

How to connect?
Download (2.24 KB) Statistics View on GitHub Reload from mirrored respository
| Branch: | Tag: | Revision:

github / src / ui / dialogs / preferences.py @ e1d2d0dc

1
"""Module containing the preferences dialog."""
2

    
3
import wx
4

    
5
class TTSTab(wx.Panel):
6

    
7
    """TTS tab."""
8

    
9
    def __init__(self, parent, settings):
10
        super(TTSTab, self).__init__(parent)
11
        self.settings = settings
12

    
13
        self.InitUI()
14
        self.Fit()
15

    
16
    def InitUI(self):
17
        panel = wx.Panel(self)
18
        sizer = wx.GridBagSizer(15, 15)
19
        panel.SetSizer(sizer)
20

    
21
        # TTS preferendces
22
        self.TTS_on = wx.CheckBox(panel, label="Enable TTS (Text-To Speech)")
23
        self.TTS_on.SetValue(self.settings["options.TTS.on"])
24
        self.TTS_outside = wx.CheckBox(panel, label="Enable TTS when on a different window")
25
        self.TTS_outside.SetValue(self.settings["options.TTS.outside"])
26

    
27
        # Append to the sizer
28
        sizer.Add(self.TTS_on, pos=(0, 0))
29
        sizer.Add(self.TTS_outside, pos=(0, 1))
30

    
31

    
32
class PreferencesTabs(wx.Notebook):
33

    
34
    """Preference tabs."""
35

    
36
    def __init__(self, parent, settings):
37
        wx.Notebook.__init__(self, parent)
38

    
39
        TTS_tab = TTSTab(self, settings)
40
        self.AddPage(TTS_tab, "TTS")
41
        self.TTS = TTS_tab
42

    
43
class PreferencesDialog(wx.Dialog):
44

    
45
    """Preferences dialog."""
46

    
47
    def __init__(self, settings):
48
        super(PreferencesDialog, self).__init__(None, title="Preferences")
49
        self.settings = settings
50

    
51
        self.InitUI()
52
        self.Maximize()
53

    
54
    def InitUI(self):
55
        panel = wx.Panel(self)
56
        sizer = wx.GridBagSizer(15, 15)
57
        panel.SetSizer(sizer)
58

    
59
        # Add the tabs
60
        self.tabs = PreferencesTabs(panel, self.settings)
61
        buttons = self.CreateButtonSizer(wx.OK | wx.CANCEL)
62

    
63
        # Append to the sizer
64
        sizer.Add(self.tabs, pos=(1, 0), span=( 5, 5))
65
        sizer.Add(buttons, pos=(8, 0), span=(1, 2))
66

    
67
        # Event binding
68
        self.Bind(wx.EVT_BUTTON, self.OnOK, id=wx.ID_OK)
69
        self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL)
70

    
71
    def OnOK(self, e):
72
        """Save the preferences."""
73
        tts = self.tabs.TTS
74
        self.settings["options.TTS.on"] = tts.TTS_on.GetValue()
75
        self.settings["options.TTS.outside"] = tts.TTS_outside.GetValue()
76
        self.settings["options"].write()
77
        self.Destroy()
78

    
79
    def OnCancel(self, e):
80
        """Simply exit the dialog."""
81
        self.Destroy()
(2-2/2)