-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_impl.py
128 lines (104 loc) · 4.55 KB
/
menu_impl.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
from menu import MenuItem, Menu
from config import config
import sys
#import pygame
class MenuImpl:
"""
Class that implements the concrete menus for touchbmc.
"""
def __init__(self, config, xbmc):
self.config = config
self.albums_menu = Menu(config)
self.artists_menu = Menu(config)
# def image_convert(image):
# """
# Change the image to the correct size
# """
#
# allowed_width = int(config["item distance"] * 0.9)
# allowed_height = int(config["height"] * 0.5)
#
# if image.get_width() < allowed_width and image.get_height < allowed_height:
# return image.convert_alpha()
#
# aspect = image.get_width() / float(image.get_height())
# allowed_aspect = allowed_width / float(allowed_height)
#
# if aspect > allowed_aspect:
# width = allowed_width
# height = int(allowed_width / aspect)
# else:
# width = int(allowed_height * aspect)
# height = allowed_height
#
# image = pygame.transform.smoothscale(image, (width, height))
# return image.convert_alpha()
def tracks_action(menuitem, gui, album_id = None):
pass
def albums_action(menuitem, gui, artist_id = None):
"""
Load the list of artists from the XBMC and display the menu.
"""
if artist_id:
result = xbmc.call.AudioLibrary.GetAlbums(artistid = artist_id)
else:
result = xbmc.call.AudioLibrary.GetAlbums()
def convert(album):
text = album["label"]
if album.has_key('thumbnail'):
pass
#image = self.cache.open_http(
# album["thumbnail"], self.config["default album"],
# image_convert)
else:
image = self.cache.open(self.config["default album"])
def action(menuitem2, gui2):
tracks_action(menuitem2, gui2, album["albumid"])
return MenuItem(image, text, action)
self.albums_menu.fill(*map(convert, result["albums"]))
Menu.action_helper(self.albums_menu)(menuitem, gui)
def artists_action(menuitem, gui):
"""
Load the list of artists from the XBMC and display the menu.
"""
result = xbmc.call.AudioLibrary.GetArtists()
def convert(artist):
text = artist["label"]
if artist.has_key('thumbnail'):
image = self.cache.open_http(
artist["thumbnail"], self.config["default artist"],
image_convert)
else:
image = self.cache.open(self.config["default artist"])
def action(menuitem2, gui2):
albums_action(menuitem2, gui2, artist["artistid"])
return MenuItem(image, text, action)
self.artists_menu.fill(*map(convert, result["artists"]))
Menu.action_helper(self.artists_menu)(menuitem, gui)
def poweroff_action(menuitem, gui):
gui.go_back()
xbmc.call.System.Suspend()
def playpause_action(menuitem, gui):
state = ()
print state
self.power_menu = Menu(
MenuItem(config["shutdown"], "Power off", poweroff_action),
MenuItem(config["exit"], "Exit", lambda menuitem, gui: sys.exit()),
)
self.library_menu = Menu(
MenuItem(config["artists"], "Artists ...", artists_action),
MenuItem(config["albums"], "Albums ...", albums_action),
)
self.root = Menu(
MenuItem(config["prev"], "Previous", lambda menuitem, gui: xbmc.call.AudioPlayer.SkipPrevious()),
MenuItem(config["next"], "Next", lambda menuitem, gui: xbmc.call.AudioPlayer.SkipNext()),
MenuItem(config["play"], "Play", lambda menuitem, gui: xbmc.call.AudioPlayer.PlayPause()),
MenuItem(config["stop"], "Stop", lambda menuitem, gui: xbmc.call.AudioPlayer.Stop()),
MenuItem(config["artists"], "Artists ...", artists_action),
MenuItem(config["albums"], "Albums ...", albums_action),
MenuItem(config["power"], "Power ...",
Menu.action_helper(self.power_menu)),
current = 2
)
def get_root_menu(self):
return self.root