89
90
""" Initialize the interface.
90
91
It defines the following:
91
92
- cDataDir: main dir
92
- cCurrentThemeDir: current theme dir
93
- cConfFile : path to the global config file
93
- cCurrentThemeDir: path to the current theme folder
94
- cConfFile: path to the global config file
95
- cLaunchersDir: path to the launchers folder
96
- cPluginsDir: path to the plug-ins folders
97
- iface: the interface to control the dock
100
DBusGMainLoop(set_as_default=True) # set a main loop for the 'watch_name_owner' signal.
102
## initialize the class properties
96
104
self.cAppName = app_name
97
105
self.cDataDir = USER_CONFIG_DIR + '/' + app_name
98
106
self.cCurrentThemeDir = self.cDataDir + '/current_theme'
100
108
self.cPluginsDir = self.cCurrentThemeDir + '/plug-ins'
101
109
self.cConfFile = self.cCurrentThemeDir + '/' + app_name + '.conf'
106
# get gldi on the bus.
107
bus = dbus.SessionBus()
109
111
name1 = self.cAppName.replace('-','') # -> cairodock
110
112
name2 = re.sub('-[a-z]', lambda x: x.group(0).upper(), self.cAppName)
111
113
name2 = re.sub('^[a-z]', lambda x: x.group(0).upper(), name2) # -> CairoDock
112
114
name2 = name2.replace('-','') # -> CairoDock
113
cBusPath = '/org/'+name1+'/'+name2
115
self.cObjectPath = '/org/'+name1+'/'+name2
117
## connect to the dock
118
self.bus = dbus.SessionBus()
121
## if the watch for de/re-connections
122
self.bus.watch_name_owner(BUS_NAME, self.on_name_owner_changed)
124
def on_name_owner_changed(self,connection_name):
125
print("new owner:",connection_name)
126
if len(connection_name) == 0:
127
if self.iface != None:
129
print("-> no more connection to "+self.cAppName)
130
elif self.iface == None:
134
# get gldi on the bus.
115
dbus_object = bus.get_object("org.cairodock.CairoDock", cBusPath)
137
dbus_object = self.bus.get_object(BUS_NAME, self.cObjectPath)
117
print ">>> object '"+cBusPath+"' can't be found on the bus, exit.\nMake sure that Cairo-Dock is running"
139
print(">>> object '"+self.cObjectPath+"' can't be found on the bus, exit.\nMake sure that Cairo-Dock is running.")
119
141
self.iface = dbus.Interface(dbus_object, "org.cairodock.CairoDock") # this object represents gldi.
142
print("-> connected to "+self.cAppName)