~iferca/yape/trunk

« back to all changes in this revision

Viewing changes to settings/settingsdialog.py

  • Committer: Israel Fernández Cabrera
  • Date: 2008-10-03 21:12:17 UTC
  • Revision ID: iferca@gmail.com-20081003211217-uu1df2ucq3wd67nd
YaPe project moved to the new YaPe project structure. Old one will work fine but it was not suitable for the next development phases

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: UTF-8 -*-
3
 
 
4
 
__license__ = "GPL V.2 or (at your option) any later version"
5
 
__copyright__ = "Israel Fernández Cabrera"
6
 
__author__ = "Israel Fernández Cabrera <iferca@gmail.com>"
7
 
 
8
 
import os
9
 
import localgtk
10
 
from config import Config
11
 
from signalhandler import SignalConnector
12
 
 
13
 
 
14
 
class SettingsDialog(localgtk.GladeInterface):
15
 
    def __init__(self):
16
 
        super(SettingsDialog, self).__init__("prefdialog.glade")
17
 
        self.setIcontoDialog(self._dialog)
18
 
        self._config = Config()
19
 
        path = self._config.getConfig("installation_path")
20
 
        signalMap = {"on_showMargin_toggled": self._toggleShowMargin, 
21
 
                     "on_okButton_clicked" : self._savePreferences,
22
 
                     "on_defaultFont_toggled": self._toggleDefaultFont,
23
 
                     "on_ProjectPathChooser_current_folder_changed": self._updateNewProjectPath,
24
 
                     "on_ShowClassBrowser_toggled": self._onShowClassBrowserToggled}
25
 
        self.signalAutoConnect(signalMap)
26
 
        self._loadPreferencesToDialog()
27
 
        self._dialog.run()
28
 
        self._dialog.destroy()
29
 
 
30
 
    def _onShowClassBrowserToggled(self, widget):
31
 
        self._classBrowserRBArea.set_sensitive(self._showClassBrowser.get_active())
32
 
 
33
 
    def _loadPreferencesToDialog(self):
34
 
        self._config = Config()
35
 
        try:
36
 
            self._loadYapePreferences()
37
 
            self._loadEditorPreferences()
38
 
            self._loadTerminalPreferences()
39
 
        except ValueError:
40
 
            pass
41
 
 
42
 
    def _loadYapePreferences(self):
43
 
        pythonCommand = self._config.getConfig("python_command")
44
 
        self._pythonShellCommand.set_text(pythonCommand)
45
 
        newProjectPath = self._config.getConfig("new_project_path")
46
 
        self._defaultProjectPath.set_text(newProjectPath)
47
 
        showCB = self._config.getConfig("show_class_browser")
48
 
        self._showClassBrowser.set_active(showCB)
49
 
        if self._config.getConfig("show_class_browser_as") == "bar":
50
 
            self.showAsBar.set_active(True)
51
 
        elif self._config.getConfig("show_class_browser_as") == "panel":
52
 
            self._showAsPanel.set_active(True)
53
 
        else:
54
 
            self.showAsBoth.set_active(True)
55
 
        if self._config.getConfig("panels/show_new_panels_as") == "tabs":
56
 
            self._showAsTabs.set_active(True)
57
 
        else:
58
 
            self.showAsRegios.set_active(True)
59
 
        self._createNewFile.set_active(self._config.getConfig("create_new_file_on_startup"))
60
 
 
61
 
    def _loadTerminalPreferences(self):
62
 
        basePath = "terminal/preferences/%s"
63
 
        self._transparent.set_active(self._config.getConfig(basePath % "transparent"))
64
 
        self._opacity.set_value(self._config.getConfig(basePath % "opacity"))
65
 
        self._blink.set_active(self._config.getConfig(basePath % "blink"))
66
 
        self._terminalCustomFont.set_font_name(self._config.getConfig(basePath % "font"))
67
 
        self._scrollback.set_value(self._config.getConfig(basePath % "scrollback"))
68
 
 
69
 
    def _loadEditorPreferences(self):
70
 
        self._showLineNumbers.set_active(self._config.getConfig("editor/preferences/show_line_numbers"))
71
 
        self._showMargin.set_active(self._config.getConfig("editor/preferences/show_margin"))
72
 
        self._marginColumn.set_sensitive(self._config.getConfig("editor/preferences/show_margin"))
73
 
        self._marginColumn.set_value(self._config.getConfig("editor/preferences/margin"))
74
 
        self._marginLabel.set_sensitive(self._config.getConfig("editor/preferences/show_margin"))
75
 
        self._smartHomeEnd.set_active(self._config.getConfig("editor/preferences/smart_home_end"))
76
 
        self._tabWidth.set_value(self._config.getConfig("editor/preferences/tabs_width"))
77
 
        self._hlightCurrLine.set_active(self._config.getConfig("editor/preferences/highlight_current_line"))
78
 
        self._insertSpaces.set_active(self._config.getConfig("editor/preferences/insert_spaces_instead_tabs"))
79
 
        if(self._config.getConfig("editor/preferences/font").lower() == "monospace 11"):
80
 
            self._defaultFont.set_active(True)
81
 
            self._customFont.set_sensitive(False)
82
 
            self._fontLabel.set_sensitive(False)
83
 
        else:
84
 
            self._defaultFont.set_active(False)
85
 
            self._customFont.set_sensitive(True)
86
 
            self._customFont.set_font_name(self._config.getConfig("editor/preferences/font"))
87
 
            self._fontLabel.set_sensitive(True)
88
 
 
89
 
    def _savePreferences(self, widget):
90
 
        self._saveEditorPreferences()
91
 
        self._saveTerminalPreferences()
92
 
        self._saveYapePreferences()
93
 
        sc = SignalConnector.getInstance()
94
 
        sc.notifyObservers("ConfigChanged")
95
 
 
96
 
    def _saveYapePreferences(self):
97
 
        self._config.setConfig("show_class_browser", self._showClassBrowser.get_active())
98
 
        showAs = "panel"
99
 
        if (self._showAsBar.get_active()):
100
 
            showAs = "bar"
101
 
        elif (self._showAsBoth.get_active()):
102
 
            showAs = "both"
103
 
        self._config.setConfig("show_class_browser_as", showAs)
104
 
        self._config.setConfig("python_command", self._pythonShellCommand.get_text())
105
 
        projectPath = self._defaultProjectPath.get_text()
106
 
        self._config.setConfig("new_project_path", projectPath)
107
 
        if (not os.path.exists(projectPath)):
108
 
                os.makedirs(projectPath, mode = 0744)
109
 
        showAs = "regions"
110
 
        if self._showAsTabs.get_active():
111
 
            showAs = "tabs"
112
 
        self._config.setConfig("panels/show_new_panels_as", showAs )
113
 
        self._config.setConfig("create_new_file_on_startup", self._createNewFile.get_active())
114
 
            
115
 
 
116
 
    def _saveTerminalPreferences(self):
117
 
        basePath = "terminal/preferences/%s"
118
 
        self._config.setConfig(basePath % "transparent", 
119
 
                         self._transparent.get_active())
120
 
        self._config.setConfig(basePath % "opacity", 
121
 
                         int(self._opacity.get_value()))
122
 
        self._config.setConfig(basePath % "blink", 
123
 
                         self._blink.get_active())
124
 
        self._config.setConfig(basePath % "font", 
125
 
                         self._terminalCustomFont.get_font_name())
126
 
        self._config.setConfig(basePath % "scrollback", 
127
 
                         int(self._scrollback.get_value()))
128
 
 
129
 
    def _saveEditorPreferences(self):
130
 
        self._config.setConfig("editor/preferences/show_line_numbers", 
131
 
                         self._showLineNumbers.get_active())
132
 
        self._config.setConfig("editor/preferences/tabs_width", 
133
 
                         int(self._tabWidth.get_value()))
134
 
        self._config.setConfig("editor/preferences/margin", 
135
 
                         int(self._marginColumn.get_value()))
136
 
        self._config.setConfig("editor/preferences/show_margin",
137
 
                         self._showMargin.get_active())
138
 
        self._config.setConfig("editor/preferences/highlight_current_line",
139
 
                         self._hlightCurrLine.get_active())
140
 
        self._config.setConfig("editor/preferences/insert_spaces_instead_tabs",
141
 
                         self._insertSpaces.get_active())
142
 
        self._config.setConfig("editor/preferences/smart_home_end",
143
 
                         self._smartHomeEnd.get_active())
144
 
        if(self._defaultFont.get_active()):
145
 
            self._config.setConfig("editor/preferences/font", "monospace 11")
146
 
        else:
147
 
            fontWidget = self._customFont
148
 
            self._config.setConfig("editor/preferences/font", fontWidget.get_font_name())
149
 
 
150
 
    def _updateNewProjectPath(self, widget):
151
 
        self._defaultProjectPath.set_text(self._projectPathChooser.get_filename())
152
 
 
153
 
    def _toggleDefaultFont(self, widget):
154
 
        fontButton = self._customFont
155
 
        defaultFont = self._defaultFont
156
 
        fontLabel = self._fontLabel
157
 
        fontButton.set_sensitive(not defaultFont.get_active())
158
 
        fontLabel.set_sensitive(not defaultFont.get_active())
159
 
 
160
 
    def _toggleShowMargin(self, widget):
161
 
        self._marginColumn.set_sensitive(self._showMargin.get_active())
162
 
        self._marginLabel.set_sensitive(self._showMargin.get_active())
163