~tualatrix/ubuntu-tweak/arb-packaging

« back to all changes in this revision

Viewing changes to src/modules/gnomesettings.py

  • Committer: TualatriX
  • Date: 2009-10-22 14:14:56 UTC
  • Revision ID: git-v1:455f01496d7149fb9832dabdf1bf0eef506a0101
WIP, make most things works

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
# Ubuntu Tweak - PyGTK based desktop configure 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 gconf
26
 
 
27
 
from tweak import TweakModule
28
 
from common.config import TweakSettings
29
 
from common.factory import WidgetFactory
30
 
from common.utils import get_icon_with_name
31
 
from common.widgets import ListPack
32
 
from common.widgets.dialogs import ErrorDialog, QuestionDialog
33
 
 
34
 
class Gnome(TweakModule):
35
 
    __title__ = _('GNOME Settings')
36
 
    __desc__ = _('A lot of GNOME settings about panel and others')
37
 
    __icon__ = ['gnome-desktop-config', 'control-center2']
38
 
    __category__ = 'desktop'
39
 
 
40
 
    def __init__(self):
41
 
        TweakModule.__init__(self)
42
 
 
43
 
        self.__setting = TweakSettings()
44
 
 
45
 
        changeicon_hbox = self.create_change_icon_hbox()
46
 
 
47
 
        box = ListPack(_("Panel and Menu"), (
48
 
                    WidgetFactory.create("GconfCheckButton", 
49
 
                                    label = _("Display warning when removing a panel"), 
50
 
                                    key = "confirm_panel_remove"),
51
 
                    WidgetFactory.create("GconfCheckButton", 
52
 
                                    label = _("Complete lockdown of all panels"), 
53
 
                                    key = "locked_down"),
54
 
                    WidgetFactory.create("GconfCheckButton", 
55
 
                                    label = _("Enable panel animations"), 
56
 
                                    key = "enable_animations"),
57
 
                    WidgetFactory.create("GconfCheckButton", 
58
 
                                    label = _("Show Input Method menu on the context menu"), 
59
 
                                    key = "show_input_method_menu"),
60
 
                    WidgetFactory.create("GconfCheckButton",
61
 
                                    label = _("Show Unicode Method menu on the context menu"), 
62
 
                                    key = "show_unicode_menu"),
63
 
                    changeicon_hbox,
64
 
                    notify_hbox,
65
 
            ))
66
 
        self.add_start(box, False, False, 0)
67
 
 
68
 
        box = ListPack(_("Screensaver"), (
69
 
                    WidgetFactory.create("GconfCheckButton", 
70
 
                                         label = _("Enable user switching when screen is locked."), 
71
 
                                         key = "user_switch_enabled"),
72
 
            ))
73
 
        self.add_start(box, False, False, 0)
74
 
 
75
 
        self.recently_used = gtk.CheckButton(_('Enable system-wide "Recently Documents" list'))
76
 
        self.recently_used.connect('toggled', self.colleague_changed)
77
 
        self.recently_used.set_active(self.get_state())
78
 
        box = ListPack(_("History"), (
79
 
                    self.recently_used,
80
 
            ))
81
 
        self.add_start(box, False, False, 0)
82
 
 
83
 
    def create_change_icon_hbox(self):
84
 
        hbox = gtk.HBox(False, 10)
85
 
        label = gtk.Label(_('Click the button to change the menu logo'))
86
 
        label.set_alignment(0, 0.5)
87
 
        hbox.pack_start(label, False, False, 0)
88
 
 
89
 
        button = gtk.Button()
90
 
        button.connect('clicked', self.on_change_icon_clicked)
91
 
        image = gtk.image_new_from_pixbuf(get_icon_with_name('start-here', 24))
92
 
        button.set_image(image)
93
 
        hbox.pack_end(button, False, False, 0)
94
 
 
95
 
        return hbox
96
 
 
97
 
    def on_change_icon_clicked(self, widget):
98
 
        dialog = gtk.FileChooserDialog(_('Choose a new logo'),action = gtk.FILE_CHOOSER_ACTION_OPEN, buttons = (gtk.STOCK_REVERT_TO_SAVED, gtk.RESPONSE_DELETE_EVENT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT))
99
 
        filter = gtk.FileFilter()
100
 
        filter.set_name(_("PNG image (*.png)"))
101
 
        filter.add_mime_type("image/png")
102
 
        dialog.set_current_folder(os.path.expanduser('~'))
103
 
        dialog.add_filter(filter)
104
 
 
105
 
        dest = os.path.expanduser('~/.icons/%s/24x24/places/start-here.png' % self.__setting.get_icon_theme())
106
 
        revert_button = dialog.action_area.get_children()[-1]
107
 
        if not os.path.exists(dest):
108
 
            revert_button.set_sensitive(False)
109
 
 
110
 
        filename = ''
111
 
        response = dialog.run()
112
 
        if response == gtk.RESPONSE_ACCEPT:
113
 
            filename = dialog.get_filename()
114
 
 
115
 
            if filename:
116
 
                pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
117
 
                w, h = pixbuf.get_width(), pixbuf.get_height()
118
 
                if w != 24 or h != 24:
119
 
                    ErrorDialog(_("The size isn't suitable for the panel.\nIt should be 24x24.")).launch()
120
 
                else:
121
 
                    os.system('mkdir -p %s' % os.path.dirname(dest))
122
 
                    os.system('cp %s %s' % (filename, dest))
123
 
 
124
 
                    image = gtk.image_new_from_file(dest)
125
 
                    widget.set_image(image)
126
 
            dialog.destroy()
127
 
        elif response == gtk.RESPONSE_DELETE_EVENT:
128
 
            os.remove(dest)
129
 
            image = gtk.image_new_from_pixbuf(get_icon_with_name('start-here', 24))
130
 
            widget.set_image(image)
131
 
            dialog.destroy()
132
 
        else:
133
 
            dialog.destroy()
134
 
            return
135
 
 
136
 
        dialog = QuestionDialog(_('Do you want your changes to take effect immediately?'))
137
 
        if dialog.run() == gtk.RESPONSE_YES:
138
 
            os.system('killall gnome-panel')
139
 
 
140
 
        dialog.destroy()
141
 
 
142
 
    def get_state(self):
143
 
        file = os.path.join(os.path.expanduser("~"), ".recently-used.xbel")
144
 
        if os.path.exists(file):
145
 
            if os.path.isdir(file):
146
 
                return False
147
 
            elif os.path.isfile(file):
148
 
                return True
149
 
        else:
150
 
            return True
151
 
 
152
 
    def colleague_changed(self, widget):
153
 
        enabled = self.recently_used.get_active()
154
 
        file = os.path.expanduser("~/.recently-used.xbel")
155
 
        if enabled:
156
 
            os.system('rm -r %s' % file)
157
 
            os.system('touch %s' % file)
158
 
        else:
159
 
            os.system('rm -r %s' % file)
160
 
            os.system('mkdir %s' % file)