~ubuntu-branches/ubuntu/maverick/mythbuntu-control-centre/maverick

« back to all changes in this revision

Viewing changes to examples/plugins/python/skeletor.py

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2009-06-09 00:34:54 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20090609003454-emyxkwn8kbgj9by3
Tags: 0.50-0ubuntu1
* Complete rewrite of mcc.  We're now plugin based
  where plugins are dynamically detected upon loading.
* Setup translation system based on python-distutils-extra instead.
* debian/control:
  - Clean up depends which should now be on mythbuntu-common.
* debian/links:
  - Drop, no longer necessary since all plugins are in common

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## -*- coding: utf-8 -*-
 
2
#
 
3
# «skeletor» - An Example Plugin for showing how to use MCC as a developer
 
4
#
 
5
# Copyright (C) 2009, Mario Limonciello, for Mythbuntu
 
6
#
 
7
#
 
8
# Mythbuntu is free software; you can redistribute it and/or modify it under
 
9
# the terms of the GNU General Public License as published by the Free
 
10
# Software Foundation; either version 2 of the License, or at your option)
 
11
# any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License along
 
19
# with this application; if not, write to the Free Software Foundation, Inc., 51
 
20
# Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
##################################################################################
 
22
 
 
23
from MythbuntuControlCentre.plugin import MCCPlugin
 
24
import gtk
 
25
 
 
26
class SkeletonPlugin(MCCPlugin):
 
27
    """An Example Plugin for showing how to use MCC as a developer"""
 
28
    #
 
29
    #Load GUI & Calculate Changes
 
30
    #
 
31
 
 
32
    def __init__(self):
 
33
        #Initialize parent class
 
34
        information = {}
 
35
        information["name"] = "Skeletor"
 
36
        information["icon"] = "gtk-stop"
 
37
        information["glade"] = "tab_skeletor"
 
38
        MCCPlugin.__init__(self,information)
 
39
 
 
40
    def captureState(self):
 
41
        """Determines the state of the items on managed by this plugin
 
42
           and stores it into the plugin's own internal structures"""
 
43
        import os
 
44
        self.changes = {}
 
45
        self.changes['user_file'] = os.path.exists('/tmp/user_file')
 
46
        self.changes['root_file'] = os.path.exists('/tmp/root_file')
 
47
        self.changes['tuxeyes'] = self.query_installed('tuxeyes')
 
48
 
 
49
    def applyStateToGUI(self):
 
50
        """Takes the current state information and sets the GUI
 
51
           for this plugin"""
 
52
        self.user_touch_checkbox.set_active(self.changes['user_file'])
 
53
        self.root_touch_checkbox.set_active(self.changes['root_file'])
 
54
        self.tuxeyes_checkbox.set_active(self.changes['tuxeyes'])
 
55
 
 
56
    def compareState(self):
 
57
        """Determines what items have been modified on this plugin"""
 
58
        MCCPlugin.clearParentState(self)
 
59
        if self.user_touch_checkbox.get_active() != self.changes['user_file']:
 
60
            self._markReconfigureUser('user_file',self.user_touch_checkbox.get_active())
 
61
        if self.root_touch_checkbox.get_active() != self.changes['root_file']:
 
62
            self._markReconfigureRoot('root_file',self.root_touch_checkbox.get_active())
 
63
        if self.tuxeyes_checkbox.get_active() != self.changes['tuxeyes']:
 
64
            if self.tuxeyes_checkbox.get_active():
 
65
                self._markInstall('tuxeyes')
 
66
            else:
 
67
                self._markRemove('tuxeyes')
 
68
    #
 
69
    # Callbacks
 
70
    #
 
71
    def callback_example(self,widget,data=None):
 
72
        """Shows an example of how a callback can do stuff"""
 
73
        widget_was_visible = self.callback_image.flags() & gtk.VISIBLE
 
74
        if widget_was_visible:
 
75
            self.callback_image.hide()
 
76
        else:
 
77
            self.callback_image.show()
 
78
 
 
79
    #
 
80
    # Process selected activities
 
81
    #
 
82
 
 
83
    def root_scripted_changes(self,reconfigure):
 
84
        """System-wide changes that need root access to be applied.
 
85
           This function is ran by the dbus backend"""
 
86
        for item in reconfigure:
 
87
            if item == "root_file":
 
88
                if reconfigure[item]:
 
89
                    file = open("/tmp/root_file", "a")
 
90
                else:
 
91
                    import os
 
92
                    os.remove("/tmp/root_file")
 
93
 
 
94
    def user_scripted_changes(self,reconfigure):
 
95
        """Local changes that can be performed by the user account.
 
96
           This function will be ran by the frontend"""
 
97
        for item in reconfigure:
 
98
            if item == "user_file":
 
99
                if reconfigure[item]:
 
100
                    file = open("/tmp/user_file", "a")
 
101
                else:
 
102
                    import os
 
103
                    os.remove("/tmp/user_file")