MCGClient._add_action(): varags added

This commit is contained in:
coderkun 2012-06-22 15:56:02 +02:00
commit 15824e65f8

28
mcg.py
View file

@ -44,11 +44,7 @@ class MCGClient:
"""Connects to MPD with the given host, port and password or """Connects to MPD with the given host, port and password or
with standard values. with standard values.
""" """
# TODO als Parameter an _add_action() übergeben, nicht speichern self._add_action(self._connect, host, port, password)
self._host = host
self._port = port
self._password = password
self._add_action(self._connect)
def is_connected(self): def is_connected(self):
@ -86,8 +82,7 @@ class MCGClient:
def play(self, album): def play(self, album):
"""Plays the given album. """Plays the given album.
""" """
# TODO Pass parameters self._add_action(self._play, album)
self._add_action(self._play)
def connect_signal(self, signal, callback): def connect_signal(self, signal, callback):
@ -111,10 +106,11 @@ class MCGClient:
callback(*args) callback(*args)
def _add_action(self, method): def _add_action(self, method, *args):
"""Adds an action to the action list. """Adds an action to the action list.
""" """
self._actions.append(method) action = [method, args]
self._actions.append(action)
self._start_worker() self._start_worker()
@ -138,7 +134,9 @@ class MCGClient:
while True: while True:
if self._actions: if self._actions:
action = self._actions.pop(0) action = self._actions.pop(0)
action() method = action[0]
params = action[1]
method(*params)
else: else:
if not self.is_connected(): if not self.is_connected():
break break
@ -148,13 +146,13 @@ class MCGClient:
self._idle(modules) self._idle(modules)
def _connect(self): def _connect(self, host, port, password):
"""Action: Performs the real connect to MPD. """Action: Performs the real connect to MPD.
""" """
try: try:
self._client.connect(self._host, self._port) self._client.connect(host, port)
if self._password: if password:
self._client.password(self._password) self._client.password(password)
# TODO Verbindung testen # TODO Verbindung testen
self._connected = True self._connected = True
self._callback(self.SIGNAL_CONNECT, self._connected, None) self._callback(self.SIGNAL_CONNECT, self._connected, None)
@ -198,7 +196,7 @@ class MCGClient:
self._callback(self.SIGNAL_UPDATE, self._albums) self._callback(self.SIGNAL_UPDATE, self._albums)
def _play(self): def _play(self, album):
"""Action: Performs the real play command. """Action: Performs the real play command.
""" """
# TODO _play() # TODO _play()