File: lockdowncheckbutton.py

package info (click to toggle)
pessulus 0.10.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,044 kB
  • ctags: 127
  • sloc: python: 949; sh: 656; makefile: 68
file content (129 lines) | stat: -rw-r--r-- 4,408 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python

# vim: set ts=4 sw=4 et:

#
# Copyright (C) 2005 Vincent Untz <vuntz@gnome.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
#

import gobject
import gtk
import gconf
import sys

import globalvar
import lockdownbutton

class PessulusLockdownCheckbutton:
    def __init__ (self, key):
        self.notify_id = None
        self.key = key

        self.lockdownbutton = None
        self.checkbutton = None
        self.hbox = None

    def new (key, label):
        lockdown = PessulusLockdownCheckbutton (key)

        lockdown.hbox = gtk.HBox ()
        lockdown.lockdownbutton = lockdownbutton.PessulusLockdownButton.new ()

        lockdown.checkbutton = gtk.CheckButton (label)
        lockdown.checkbutton.show ()

        lockdown.hbox.pack_start (lockdown.lockdownbutton.get_widget (),
                                  False, False)
        lockdown.hbox.pack_start (lockdown.checkbutton)
        lockdown.hbox.show ()

        lockdown.__connect_and_update ()
        return lockdown
    new = staticmethod (new)

    def new_with_widgets (key, button, checkbutton):
        lockdown = PessulusLockdownCheckbutton (key)

        lockdown.lockdownbutton = lockdownbutton.PessulusLockdownButton.new_with_widget (button)
        lockdown.checkbutton = checkbutton
        lockdown.hbox = lockdown.checkbutton.get_parent ()

        lockdown.__connect_and_update ()
        return lockdown
    new_with_widgets = staticmethod (new_with_widgets)

    def __connect_and_update (self):
        self.__update_toggle ()

        self.lockdownbutton.connect ("toggled",
                                     self.__on_lockdownbutton_toggled)

        self.checkbutton.connect ("toggled", self.__on_check_toggled)
        self.checkbutton.connect ("destroy", self.__on_destroyed)

        self.notify_id = globalvar.applier.notify_add (self.key,
                                                       self.__on_notified)
        self.__set_tooltip ()

    def get_widget (self):
        return self.hbox

    def get_lockdownbutton (self):
        return self.lockdownbutton

    def __set_tooltip (self):
        if not globalvar.applier:
            return

        try:
            schema = globalvar.applier.get_schema ("/schemas" + self.key)
            if schema:
                globalvar.tooltips.set_tip (self.checkbutton,
                                            " ".join (schema.get_long_desc ().split ()))
        except gobject.GError:
            print >> sys.stderr, "Warning: Could not get schema for %s" % self.key

    def __update_toggle (self):
        (active, mandatory) = globalvar.applier.get_bool (self.key)

        self.lockdownbutton.set (mandatory)

        self.checkbutton.set_active (active)
        self.checkbutton.set_sensitive (globalvar.applier.key_is_writable (self.key))

    def __on_notified (self, data):
        (active, mandatory) = globalvar.applier.get_bool (self.key)
        if active != self.checkbutton.get_active () or mandatory != self.lockdownbutton.get ():
            self.__update_toggle ()

    def __on_lockdownbutton_toggled (self, lockdownbutton, mandatory):
        self.__do_change ()

    def __on_check_toggled (self, checkbutton):
        self.__do_change ()

    def __do_change (self):
        if globalvar.applier and globalvar.applier.key_is_writable (self.key):
            globalvar.applier.set_bool (self.key,
                                        self.checkbutton.get_active (),
                                        self.lockdownbutton.get ())

    def __on_destroyed (self, checkbutton):
        if self.notify_id:
            if globalvar.applier:
                globalvar.applier.notify_remove (self.notify_id)
            self.notify_id = None