~tualatrix/ubuntu-tweak/arb-packaging

« back to all changes in this revision

Viewing changes to ubuntutweak/module/gnomesettings.py

  • Committer: Tualatrix Chou
  • Date: 2011-03-15 11:44:46 UTC
  • Revision ID: git-v1:638ab7e8545fbb783e490b588d058cbf9acd75da
Rename the modules to module temporarily

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
# Ubuntu Tweak - PyGTK based desktop configuration tool
 
4
#
 
5
# Copyright (C) 2007-2008 TualatriX <tualatrix@gmail.com>
 
6
#
 
7
# Ubuntu Tweak is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# Ubuntu Tweak is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with Ubuntu Tweak; if not, write to the Free Software Foundation, Inc.,
 
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 
20
 
 
21
import pygtk
 
22
pygtk.require("2.0")
 
23
import os
 
24
import gtk
 
25
import glob
 
26
import logging
 
27
 
 
28
from ubuntutweak import system
 
29
from ubuntutweak.modules  import TweakModule
 
30
from ubuntutweak.ui import ListPack, TablePack
 
31
from ubuntutweak.ui.dialogs import ErrorDialog, QuestionDialog, WarningDialog
 
32
 
 
33
from ubuntutweak.common.config import TweakSettings
 
34
from ubuntutweak.common.factory import WidgetFactory
 
35
from ubuntutweak.utils import icon
 
36
from ubuntutweak.conf.gconfsetting import GconfSetting
 
37
 
 
38
log = logging.getLogger("Gnome")
 
39
 
 
40
class Gnome(TweakModule):
 
41
    __title__ = _('GNOME Settings')
 
42
    __desc__ = _('A lot of GNOME settings for panels, menus and other desktop elements')
 
43
    __icon__ = ['gnome-desktop-config', 'control-center2']
 
44
    __category__ = 'desktop'
 
45
    __desktop__ = ['gnome', 'une']
 
46
 
 
47
    def __init__(self):
 
48
        TweakModule.__init__(self)
 
49
 
 
50
        self.__setting = TweakSettings()
 
51
 
 
52
        changeicon_hbox = self.create_change_icon_hbox()
 
53
 
 
54
        box = TablePack(_("Panel Settings"), (
 
55
                    WidgetFactory.create("GconfCheckButton", 
 
56
                                    label=_("Display warning when removing a panel"),
 
57
                                    enable_reset=True,
 
58
                                    key="confirm_panel_remove"),
 
59
                    WidgetFactory.create("GconfCheckButton", 
 
60
                                    label=_("Complete lockdown of all panels"),
 
61
                                    enable_reset=True,
 
62
                                    key="locked_down"),
 
63
                    WidgetFactory.create("GconfCheckButton", 
 
64
                                    label=_("Enable panel animations"),
 
65
                                    enable_reset=True,
 
66
                                    key="enable_animations"),
 
67
                    WidgetFactory.create('GconfComboBox',
 
68
                                         label=_('Me Menu Setting'),
 
69
                                         key='/system/indicator/me/display',
 
70
                                         texts=[_("Don't Display"), _('Display user name'), _('Display real name')],
 
71
                                         values=[0, 1, 2],
 
72
                                         type='int')
 
73
            ))
 
74
        self.add_start(box, False, False, 0)
 
75
 
 
76
        box = ListPack(_("Menu Settings"), (
 
77
                    WidgetFactory.create("GconfCheckButton", 
 
78
                                    label=_("Show Input Method menu in the context menu"),
 
79
                                    enable_reset=True,
 
80
                                    key="show_input_method_menu"),
 
81
                    WidgetFactory.create("GconfCheckButton",
 
82
                                    label=_("Show Unicode Control Character menu in the context menu"),
 
83
                                    enable_reset=True,
 
84
                                    key="show_unicode_menu"),
 
85
                    WidgetFactory.create("GconfCheckButton",
 
86
                                    label=_('Show icons in menus'),
 
87
                                    enable_reset=True,
 
88
                                    key='/desktop/gnome/interface/menus_have_icons'),
 
89
                    WidgetFactory.create("GconfCheckButton",
 
90
                                    label=_('Show icons on buttons'),
 
91
                                    enable_reset=True,
 
92
                                    key='/desktop/gnome/interface/buttons_have_icons'),
 
93
                    changeicon_hbox,
 
94
            ))
 
95
        self.add_start(box, False, False, 0)
 
96
 
 
97
        box = ListPack(_("Screensaver"), (
 
98
                    WidgetFactory.create("GconfCheckButton", 
 
99
                                         label=_("Enable user switching whilst screen is locked."),
 
100
                                         enable_reset=True,
 
101
                                         key="user_switch_enabled"),
 
102
            ))
 
103
        self.add_start(box, False, False, 0)
 
104
 
 
105
        current_terminal_profile_key = GconfSetting('/apps/gnome-terminal/global/default_profile')
 
106
        current_terminal_profile = current_terminal_profile_key.get_value()
 
107
        default_show_menubar_key = '/apps/gnome-terminal/profiles/%s/default_show_menubar' % current_terminal_profile
 
108
        box = ListPack(_("Terminal"), (
 
109
                    WidgetFactory.create("GconfCheckButton", 
 
110
                                         label=_("Display menubar when Terminal starts up (for current profile)"),
 
111
                                         enable_reset=True,
 
112
                                         key=default_show_menubar_key),
 
113
            ))
 
114
        self.add_start(box, False, False, 0)
 
115
 
 
116
        self.recently_used = gtk.CheckButton(_('Enable system-wide "Recent Documents" list'))
 
117
        self.recently_used.connect('toggled', self.colleague_changed)
 
118
        self.recently_used.set_active(self.get_state())
 
119
        box = ListPack(_("History"), (
 
120
                    self.recently_used,
 
121
            ))
 
122
        self.add_start(box, False, False, 0)
 
123
 
 
124
    def create_change_icon_hbox(self):
 
125
        hbox = gtk.HBox(False, 10)
 
126
        label = gtk.Label(_('Click this button to change the menu logo image'))
 
127
        label.set_alignment(0, 0.5)
 
128
        hbox.pack_start(label, False, False, 0)
 
129
 
 
130
        button = gtk.Button()
 
131
        button.connect('clicked', self.on_change_icon_clicked)
 
132
        image = gtk.image_new_from_pixbuf(icon.get_from_name('start-here'))
 
133
        button.set_image(image)
 
134
        hbox.pack_end(button, False, False, 0)
 
135
 
 
136
        return hbox
 
137
 
 
138
    def on_change_icon_clicked(self, widget):
 
139
        dialog = gtk.FileChooserDialog(_('Choose a new logo image'),
 
140
                                        action=gtk.FILE_CHOOSER_ACTION_OPEN,
 
141
                                        buttons=(gtk.STOCK_REVERT_TO_SAVED, gtk.RESPONSE_DELETE_EVENT,
 
142
                                                 gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
 
143
                                                 gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT))
 
144
        filter = gtk.FileFilter()
 
145
        filter.set_name(_("PNG images with 24x24 size or SVG images"))
 
146
        filter.add_pattern('*.png')
 
147
        filter.add_pattern('*.svg')
 
148
        dialog.set_current_folder(os.path.expanduser('~'))
 
149
        dialog.add_filter(filter)
 
150
 
 
151
        if system.CODENAME == 'karmic':
 
152
            dest = os.path.expanduser('~/.icons/%s/places/24/start-here' % self.__setting.get_icon_theme())
 
153
        else:
 
154
            dest = os.path.expanduser('~/.icons/%s/apps/24/start-here' % self.__setting.get_icon_theme())
 
155
 
 
156
        revert_button = dialog.action_area.get_children()[-1]
 
157
 
 
158
        HAVE_ICON = os.path.exists(dest + '.png') or os.path.exists(dest + '.svg')
 
159
 
 
160
        if not HAVE_ICON:
 
161
            revert_button.set_sensitive(False)
 
162
 
 
163
        filename = ''
 
164
        response = dialog.run()
 
165
 
 
166
        if response == gtk.RESPONSE_ACCEPT:
 
167
            filename = dialog.get_filename()
 
168
            dialog.destroy()
 
169
 
 
170
            if filename:
 
171
                ext = os.path.splitext(filename)[1]
 
172
                log.debug('The select file name is: %s' % ext)
 
173
                pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
 
174
                w, h = pixbuf.get_width(), pixbuf.get_height()
 
175
                dest = dest + ext
 
176
 
 
177
                if ext == '.png' and (w != 24 or h != 24):
 
178
                    ErrorDialog(_("This image size isn't suitable for the panel.\nIt should measure 24x24.")).launch()
 
179
                    return
 
180
                else:
 
181
                    os.system('mkdir -p %s' % os.path.dirname(dest))
 
182
                    os.system('cp %s %s' % (filename, dest))
 
183
 
 
184
                    if ext == '.svg':
 
185
                        pixbuf = pixbuf.scale_simple(24, 24, gtk.gdk.INTERP_BILINEAR)
 
186
                    image = gtk.image_new_from_pixbuf(pixbuf)
 
187
                    widget.set_image(image)
 
188
        elif response == gtk.RESPONSE_DELETE_EVENT:
 
189
            dialog.destroy()
 
190
            for dest in glob.glob(dest + '*'):
 
191
                os.remove(dest)
 
192
            image = gtk.image_new_from_pixbuf(icon.get_from_name('start-here', force_reload=True))
 
193
            widget.set_image(image)
 
194
        else:
 
195
            dialog.destroy()
 
196
            return
 
197
 
 
198
        dialog = QuestionDialog(_('Do you want your changes to take effect immediately?'))
 
199
        if dialog.run() == gtk.RESPONSE_YES:
 
200
            os.system('killall gnome-panel')
 
201
 
 
202
        dialog.destroy()
 
203
 
 
204
    def get_state(self):
 
205
        file = os.path.join(os.path.expanduser("~"), ".recently-used.xbel")
 
206
        if os.path.exists(file):
 
207
            if os.path.isdir(file):
 
208
                return False
 
209
            elif os.path.isfile(file):
 
210
                return True
 
211
        else:
 
212
            return True
 
213
 
 
214
    def colleague_changed(self, widget):
 
215
        enabled = self.recently_used.get_active()
 
216
        file = os.path.expanduser("~/.recently-used.xbel")
 
217
        if enabled:
 
218
            os.system('rm -r %s' % file)
 
219
            os.system('touch %s' % file)
 
220
        else:
 
221
            dialog = WarningDialog(_('Disabling "Recent Documents" may break other software, for example the history feature in VMware Player.'),
 
222
                                   title=_("Warning"))
 
223
            if dialog.run() == gtk.RESPONSE_YES:
 
224
                os.system('rm -r %s' % file)
 
225
                os.system('mkdir %s' % file)
 
226
            else:
 
227
                widget.set_active(True)
 
228
            dialog.destroy()