|
| 1 | +import sys |
| 2 | +import talkshowConfig |
| 3 | +import pyglet |
| 4 | + |
| 5 | +from talkshowLogger import logger |
| 6 | + |
| 7 | +debug = logger.debug |
| 8 | +info = logger.info |
| 9 | +warn = logger.warn |
| 10 | + |
| 11 | +import talkshowUtils |
| 12 | +def loadImage(path): |
| 13 | + newpath = talkshowUtils.getRelativePath(path) |
| 14 | + return pyglet.image.load(newpath) |
| 15 | + |
| 16 | + |
| 17 | +class CommandBar(object): |
| 18 | + |
| 19 | + def __init__(self, screen, orientation): |
| 20 | + |
| 21 | + self.style = talkshowConfig.config().parser.style |
| 22 | + self.screen = screen |
| 23 | + |
| 24 | + |
| 25 | + # expecting a list of 4 values for the padding values. no css shorthands allowed. |
| 26 | + self.imagePadding = self.style.commandImage.padding |
| 27 | + self.pagePadding = map(lambda x:x/100.0, self.style.page.padding) |
| 28 | + |
| 29 | + self.leftPadding = self.screen.w * self.pagePadding[3] + self.imagePadding[3] |
| 30 | + self.topPadding = self.screen.w * self.pagePadding[0] + self.imagePadding[0] |
| 31 | + |
| 32 | + # 0 = landscape; 1 = vertical |
| 33 | + self.orientation = orientation |
| 34 | + |
| 35 | + # calculate bar size by orientation property |
| 36 | + if self.orientation == 0: |
| 37 | + self.height = screen.h * self.style.commandBar.height / 100.0 |
| 38 | + self.width = screen.w * self.style.commandBar.width / 100.0 |
| 39 | + else: |
| 40 | + self.height = screen.h * self.style.sideBar.height / 100.0 |
| 41 | + self.width = screen.w * self.style.sideBar.width / 100.0 |
| 42 | + |
| 43 | + self.increaseX = 0; |
| 44 | + self.increaseY = 0; |
| 45 | + |
| 46 | +class MenuBar(CommandBar): |
| 47 | + |
| 48 | + def __init__(self, screen, orientation=0): |
| 49 | + |
| 50 | + super(MenuBar, self).__init__(screen, orientation) |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + x = self.leftPadding |
| 55 | + y = self.topPadding |
| 56 | + |
| 57 | + |
| 58 | + if self.orientation == 0: |
| 59 | + debug("orientation 0") |
| 60 | + increaseX = int(self.style.warning.width) + self.imagePadding[1] + self.imagePadding[3] |
| 61 | + increaseY = 0 |
| 62 | + |
| 63 | + else: |
| 64 | + debug("orientation 1") |
| 65 | + increaseX = 0 |
| 66 | + increaseY = int(self.style.warning.height) + self.imagePadding[0] + self.imagePadding[2] |
| 67 | + |
| 68 | + # create the warning button properties |
| 69 | + self.warningImage = loadImage(self.style.warning.background_image[5:-2]) |
| 70 | + self.warningHeight = int(self.style.warning.height) |
| 71 | + self.warningWidth = int(self.style.warning.width) |
| 72 | + self.warningX = x |
| 73 | + self.warningY = y |
| 74 | + self.warningSprite = pyglet.sprite.Sprite(self.warningImage, self.warningX, self.warningY) |
| 75 | + |
| 76 | + x = x + increaseX |
| 77 | + y = y + increaseY |
| 78 | + |
| 79 | + # create the home button properties |
| 80 | + self.homeImage = loadImage(self.style.home.background_image[5:-2]) |
| 81 | + self.homeHeight = int(self.style.home.height) |
| 82 | + self.homeWidth = int(self.style.home.width) |
| 83 | + self.homeX = x |
| 84 | + self.homeY = y |
| 85 | + self.homeSprite = pyglet.sprite.Sprite(self.homeImage, self.homeX, self.homeY) |
| 86 | + |
| 87 | + x = x + increaseX |
| 88 | + y = y + increaseY |
| 89 | + |
| 90 | + # create the back button properties |
| 91 | + self.backImage = loadImage(self.style.back.background_image[5:-2]) |
| 92 | + self.backHeight = int(self.style.back.height) |
| 93 | + self.backWidth = int(self.style.back.width) |
| 94 | + self.backX = x |
| 95 | + self.backY = y |
| 96 | + self.backSprite = pyglet.sprite.Sprite(self.backImage, self.backX, self.backY) |
| 97 | + |
| 98 | + x = x + increaseX |
| 99 | + y = y + increaseY |
| 100 | + |
| 101 | + # create the shutDown button properties |
| 102 | + self.shutDownImage = loadImage(self.style.shutDown.background_image[5:-2]) |
| 103 | + self.shutDownHeight = int(self.style.shutDown.height) |
| 104 | + self.shutDownWidth = int(self.style.shutDown.width) |
| 105 | + self.shutDownX = x |
| 106 | + self.shutDownY = y |
| 107 | + self.shutDownSprite = pyglet.sprite.Sprite(self.shutDownImage, self.shutDownX, self.shutDownY) |
| 108 | + |
| 109 | + x = x + increaseX |
| 110 | + y = y + increaseY |
| 111 | + |
| 112 | + # create the settings button properties |
| 113 | + self.settingsImage = loadImage(self.style.settings.background_image[5:-2]) |
| 114 | + self.settingsHeight = int(self.style.settings.height) |
| 115 | + self.settingsWidth = int(self.style.settings.width) |
| 116 | + self.settingsX = x |
| 117 | + self.settingsY = y |
| 118 | + self.settingsSprite = pyglet.sprite.Sprite(self.settingsImage, self.settingsX, self.settingsY) |
| 119 | + |
| 120 | + |
| 121 | +class PlayerBar(CommandBar): |
| 122 | + |
| 123 | + def __init__(self, screen, orientation=0): |
| 124 | + |
| 125 | + super(PlayerBar, self).__init__(screen, orientation) |
| 126 | + |
| 127 | + y = self.topPadding |
| 128 | + |
| 129 | + if self.orientation == 0: |
| 130 | + increaseX = int(self.style.volumeDown.width) + self.imagePadding[1] + self.imagePadding[3] |
| 131 | + increaseY = 0 |
| 132 | + x = self.screen.w - 5*increaseX |
| 133 | + else: |
| 134 | + x = self.imagePadding[3] + self.screen.w - self.width |
| 135 | + increaseX = 0 |
| 136 | + increaseY = int(self.style.volumeDown.height) + self.imagePadding[0] + self.imagePadding[2] |
| 137 | + |
| 138 | + # create the volumeDown button properties |
| 139 | + self.volumeDownImage = loadImage(self.style.volumeDown.background_image[5:-2]) |
| 140 | + self.volumeDownHeight = int(self.style.volumeDown.height) |
| 141 | + self.volumeDownWidth = int(self.style.volumeDown.width) |
| 142 | + self.volumeDownX = x |
| 143 | + self.volumeDownY = y |
| 144 | + self.volumeDownSprite = pyglet.sprite.Sprite(self.volumeDownImage, self.volumeDownX, self.volumeDownY) |
| 145 | + |
| 146 | + x = x + increaseX |
| 147 | + y = y + increaseY |
| 148 | + |
| 149 | + # create the volumeUp button properties |
| 150 | + self.volumeUpImage = loadImage(self.style.volumeUp.background_image[5:-2]) |
| 151 | + self.volumeUpHeight = int(self.style.volumeUp.height) |
| 152 | + self.volumeUpWidth = int(self.style.volumeUp.width) |
| 153 | + self.volumeUpX = x |
| 154 | + self.volumeUpY = y |
| 155 | + self.volumeUpSprite = pyglet.sprite.Sprite(self.volumeUpImage, self.volumeUpX, self.volumeUpY) |
| 156 | + |
| 157 | + x = x + increaseX |
| 158 | + y = y + increaseY |
| 159 | + |
| 160 | + self.volumeHeight = int(self.style.volumeUp.height) |
| 161 | + self.volumeWidth = int(self.style.volumeUp.width) |
| 162 | + self.volumeX = x |
| 163 | + self.volumeY = y |
| 164 | + self.volumeSize = 50 |
| 165 | + |
| 166 | + x = x + increaseX |
| 167 | + y = y + increaseY |
| 168 | + |
| 169 | + |
| 170 | + # create the playPrevious button properties |
| 171 | + self.playPreviousImage = loadImage(self.style.playPrevious.background_image[5:-2]) |
| 172 | + self.playPreviousHeight = int(self.style.playPrevious.height) |
| 173 | + self.playPreviousWidth = int(self.style.playPrevious.width) |
| 174 | + self.playPreviousX = x |
| 175 | + self.playPreviousY = y |
| 176 | + self.playPreviousSprite = pyglet.sprite.Sprite(self.playPreviousImage, self.playPreviousX, self.playPreviousY) |
| 177 | + |
| 178 | + x = x + increaseX |
| 179 | + y = y + increaseY |
| 180 | + |
| 181 | + # create the play button properties |
| 182 | + self.playImage = loadImage(self.style.play.background_image[5:-2]) |
| 183 | + self.playHeight = int(self.style.play.height) |
| 184 | + self.playWidth = int(self.style.play.width) |
| 185 | + self.playX = x |
| 186 | + self.playY = y |
| 187 | + self.playSprite = pyglet.sprite.Sprite(self.playImage, self.playX, self.playY) |
| 188 | + |
| 189 | + x = x + increaseX |
| 190 | + y = y + increaseY |
| 191 | + |
| 192 | + # create the playNext button properties |
| 193 | + self.playNextImage = loadImage(self.style.playNext.background_image[5:-2]) |
| 194 | + self.playNextHeight = int(self.style.playNext.height) |
| 195 | + self.playNextWidth = int(self.style.playNext.width) |
| 196 | + self.playNextX = x |
| 197 | + self.playNextY = y |
| 198 | + self.playNextSprite = pyglet.sprite.Sprite(self.playNextImage, self.playNextX, self.playNextY) |
| 199 | + |
0 commit comments