-
Notifications
You must be signed in to change notification settings - Fork 0
/
controlpanel.py
executable file
·131 lines (104 loc) · 4.29 KB
/
controlpanel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /usr/bin/python
"""
Controlpanel is a easy to to use control panel for the mpd music daemon
and the zsnes Super Nintendo Emulator.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging
import pygame, sys
from pygame import Color
from pygame.time import Clock
from modules.pympd import PyMpd
from modules.pyemu import PyEmu
from modules.pynotify import NotificationArea
from settings.main import *
from helper import keyActions
class Panel():
def __init__(self, mode):
self.logger = logging.getLogger('controlpanel')
self.logger.debug('Init pygame')
pygame.init()
self.screen = pygame.display.set_mode(mode,pygame.RESIZABLE)
pygame.mouse.set_visible(False)
#Init Joystick
pygame.joystick.init()
try:
self.joystick = pygame.joystick.Joystick(0)
except pygame.error:
self.logger.info('No joystick found')
else:
self.joystick.init()
#Init Clock
self.clock = Clock()
#Activate notification area
self.notificationArea = NotificationArea(self, (60,540), (640,20))
#Init Applets
self.applets = []
self.applets.append(PyMpd(self, (60,60),(640,480)))
self.applets.append(PyEmu(self, (60,60),(640,480),'media/roms/'))
#self.applets[1].set_mpd_commander(self.applets[0].commander)
self.activeAppletNumber = 0
self.activeApplet = self.applets[0]
#Define actions for helper function
self.actions = {
"prev" : self.prevApplet,
"next" : self.nextApplet
}
def __handle_events(self):
"""
Handles the waiting events, if the key is not in the classes action
list the event is forwarded to the active applet.
"""
for event in pygame.event.get():
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
pygame.event.clear()
self.applets[0].exit()
self.running = False
break
elif keyActions(event, JOYSTICK_ACTIONS, KEYBOARD_ACTIONS, self.actions):
self.activeApplet= self.applets[self.activeAppletNumber]
else:
self.activeApplet.handle_events(event)
def __draw(self):
self.screen.fill(Color('black'))
self.activeApplet.draw(self.screen)
self.notificationArea.draw(self.screen)
pygame.display.flip()
def run(self):
self.running = True
while self.running:
self.__draw()
self.__handle_events()
self.clock.tick(12)
self.logger.debug('Terminating')
pygame.quit()
sys.exit()
def notify(self, caption):
"""
Prints a new caption to the notification area.
"""
self.notificationArea.setCaption(caption)
def prevApplet(self):
""" Rotates through the applets forward. The next applet is displayed. """
self.activeAppletNumber = ((self.activeAppletNumber+1) % len(self.applets))
def nextApplet(self):
""" Rotates through the applets backward. The next applet is displayed. """
self.activeAppletNumber = ((self.activeAppletNumber+1) % len(self.applets))
if __name__ == '__main__':
logging.basicConfig(filename=LOGGING_PATH,
filemode='w',
level=LOGGING_LEVEL,
format='%(asctime)s -[%(name)s-%(levelname)s]- %(message)s',
datefmt='%d.%m.%Y %H:%M')
logging.getLogger().addHandler(logging.StreamHandler()) #Write to Console too
instance = Panel(mode=(800,600))
instance.run()