]> kaliko git repositories - mpd-sima.git/blob - sima/core.py
Initial import
[mpd-sima.git] / sima / core.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 from .client import PlayerClient
5
6 class Sima(object):
7     """Main class, plugin and player management
8     """
9
10     def __init__(self):
11         self.plugins = list()
12         self.player = None
13         self.connect_player()
14
15     def register_plugin(self, plugin_class):
16         self.plugins.append(plugin_class(self))
17
18     def foreach_plugin(self, method, *args, **kwds):
19         for plugin in self.plugins:
20             getattr(plugin, method)(*args, **kwds)
21
22     def connect_player(self):
23         """Instanciate player client and connect it
24         """
25         self.player = PlayerClient()  # Player client
26         self.player.connect()
27
28     def shutdown(self):
29         """General shutdown method
30         """
31         self.player.disconnect()
32         self.foreach_plugin('shutdown')
33
34     def run(self):
35         """Dispatching callbacks to plugins
36         """
37         print(self.player.status())
38         while 42:
39             # hanging here untill a monitored event is raised in the player
40             changed = self.player.monitor()
41             print(changed)
42             print(self.player.current)
43             if 'playlist' in changed:
44                 self.foreach_plugin('callback_playlist')
45             if 'player' in changed:
46                 pass
47
48
49
50 # VIM MODLINE
51 # vim: ai ts=4 sw=4 sts=4 expandtab