~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to Dbus/interfaces/python/CairoDock.py

  • Committer: Kees Cook
  • Date: 2011-08-11 23:17:39 UTC
  • mfrom: (20.1.1 cairo-dock-plug-ins)
  • Revision ID: kees@outflux.net-20110811231739-cteedan51tmdg77v
Tags: 2.4.0~0beta2-0ubuntu1
releasing version 2.4.0~0beta2-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This is a part of the Cairo-Dock plug-ins.
 
2
# Copyright : (C) 2010-2011 by Fabounet
 
3
# E-mail : fabounet@glx-dock.org
 
4
#
 
5
# This program is free software; you can redistribute it and/or
 
6
# modify it under the terms of the GNU General Public License
 
7
# as published by the Free Software Foundation; either version 2
 
8
# of the License, or (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
# GNU General Public License for more details.
 
14
# http://www.gnu.org/licenses/licenses.html#GPL
 
15
 
 
16
# Base class for Cairo-Dock's main interface.
 
17
 
 
18
####################
 
19
### dependancies ###
 
20
####################
 
21
import os.path
 
22
import dbus
 
23
import re
 
24
 
 
25
USER_CONFIG_DIR = os.path.abspath("~/.config")
 
26
 
 
27
 
 
28
##################
 
29
### Main class ###
 
30
##################
 
31
class CairoDock:
 
32
        
 
33
        #############
 
34
        ### Enums ###
 
35
        #############
 
36
        # orientation
 
37
        BOTTOM = 0
 
38
        TOP    = 1
 
39
        RIGHT  = 2
 
40
        LEFT   = 3
 
41
        # container type
 
42
        DOCK    = "Dock"
 
43
        DESKLET = "Desklet"
 
44
        # emblem position
 
45
        UPPER_LEFT  = 0
 
46
        LOWER_RIGHT = 1
 
47
        LOWER_LEFT  = 2
 
48
        UPPER_RIGHT = 3
 
49
        MIDDLE      = 4
 
50
        # module category
 
51
        CATEGORY_BEHAVIOR         = 0
 
52
        CATEGORY_THEME            = 1
 
53
        CATEGORY_APPLET_FILES     = 2
 
54
        CATEGORY_APPLET_INTERNET  = 3
 
55
        CATEGORY_APPLET_DESKTOP   = 4
 
56
        CATEGORY_APPLET_ACCESSORY = 5
 
57
        CATEGORY_APPLET_SYSTEM    = 6
 
58
        CATEGORY_APPLET_FUN       = 7
 
59
        # module type
 
60
        CAN_DOCK    = 1
 
61
        CAN_DESKLET = 2
 
62
        # icon type
 
63
        TYPE_LAUNCHER        = "Launcher"
 
64
        TYPE_APPLICATION     = "Application"
 
65
        TYPE_APPLET          = "Applet"
 
66
        TYPE_SEPARATOR       = "Separator"
 
67
        TYPE_CONTAINER       = "Container"
 
68
        TYPE_CLASS_CONTAINER = "Class-Container"
 
69
        TYPE_OTHER           = "Other"
 
70
        # toggle dock visibility
 
71
        HIDE_DOCK   = 0
 
72
        SHOW_DOCK   = 1
 
73
        TOGGLE_DOCK = 2
 
74
        
 
75
        #####################
 
76
        ### INIT AND DBUS ###
 
77
        #####################
 
78
        
 
79
        def __init__(self, app_name="cairo-dock"):
 
80
                """ Initialize the interface.
 
81
                It defines the following:
 
82
                 - cDataDir: main dir
 
83
                 - cCurrentThemeDir: current theme dir
 
84
                 - cConfFile : path to the global config file
 
85
                 """
 
86
                self.dock = None
 
87
                self.cAppName = app_name
 
88
                self.cDataDir = USER_CONFIG_DIR + '/' + app_name
 
89
                self.cCurrentThemeDir = self.cDataDir + '/current_theme'
 
90
                self.cLaunchersDir = self.cCurrentThemeDir + '/launchers'
 
91
                self.cPluginsDir = self.cCurrentThemeDir + '/plug-ins'
 
92
                self.cConfFile = self.cCurrentThemeDir + '/' + app_name + '.conf'
 
93
                
 
94
                self._connect()
 
95
        
 
96
        def _connect(self):
 
97
                # get gldi on the bus.
 
98
                bus = dbus.SessionBus()
 
99
                
 
100
                name1 = self.cAppName.replace('-','')  # -> cairodock
 
101
                name2 = re.sub('-[a-z]', lambda x: x.group(0).upper(), self.cAppName)
 
102
                name2 = re.sub('^[a-z]', lambda x: x.group(0).upper(), name2)  # -> CairoDock
 
103
                name2 = name2.replace('-','')  # -> CairoDock
 
104
                cBusPath = '/org/'+name1+'/'+name2
 
105
                try:
 
106
                        dbus_object = bus.get_object("org.cairodock.CairoDock", cBusPath)
 
107
                except:
 
108
                        print ">>> object '"+cBusPath+"' can't be found on the bus, exit.\nMake sure that Cairo-Dock is running"
 
109
                        return
 
110
                self.iface = dbus.Interface(dbus_object, "org.cairodock.CairoDock")  # this object represents gldi.
 
111