def __init__(self): """ """ self.stage = clutter.stage_get_default() if settings.FULLSCREEN: logging.info('Setting GUI to fullscreen.') self.stage.hide_cursor() self.stage.set_fullscreen(True) self.stage.set_size(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT) else: logging.info('Setting GUI to windowed mode.') self.stage.show_cursor() self.stage.set_fullscreen(False) self.stage.set_user_resizable(True) self.stage.set_size(settings.SCREEN_WIDTH * 0.5, settings.SCREEN_HEIGHT * 0.5) self.stage.set_color(clutter.Color(0x00, 0x00, 0x00, 0xff)) self.stage.set_title("AS220 Jukebox") self.stage.connect('destroy', clutter.main_quit) self.stage.connect('allocation-changed', self.on_allocation_changed) self.stage.connect('key-press-event', self.on_press) self.stage.connect('key-release-event', self.on_release) self.layout = clutter.BinLayout(clutter.BIN_ALIGNMENT_CENTER, clutter.BIN_ALIGNMENT_CENTER) self.container = clutter.Box(self.layout) self.stage.add(self.container) # Setup screen container self.screen_container = ScreenContainer() self.container.add(self.screen_container) front = FrontScreen() self.screen_container.add_screen(front) self.screen_container.active_screen = front self.transient_message = transient_message self.footer = footer self.layout.add(self.footer, clutter.BIN_ALIGNMENT_CENTER, clutter.BIN_ALIGNMENT_END) self.container.add(transient_message)
class GUI(object): """ Main GUI for the jukebox. """ def __init__(self): """ """ self.stage = clutter.stage_get_default() if settings.FULLSCREEN: logging.info('Setting GUI to fullscreen.') self.stage.hide_cursor() self.stage.set_fullscreen(True) self.stage.set_size(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT) else: logging.info('Setting GUI to windowed mode.') self.stage.show_cursor() self.stage.set_fullscreen(False) self.stage.set_user_resizable(True) self.stage.set_size(settings.SCREEN_WIDTH * 0.5, settings.SCREEN_HEIGHT * 0.5) self.stage.set_color(clutter.Color(0x00, 0x00, 0x00, 0xff)) self.stage.set_title("AS220 Jukebox") self.stage.connect('destroy', clutter.main_quit) self.stage.connect('allocation-changed', self.on_allocation_changed) self.stage.connect('key-press-event', self.on_press) self.stage.connect('key-release-event', self.on_release) self.layout = clutter.BinLayout(clutter.BIN_ALIGNMENT_CENTER, clutter.BIN_ALIGNMENT_CENTER) self.container = clutter.Box(self.layout) self.stage.add(self.container) # Setup screen container self.screen_container = ScreenContainer() self.container.add(self.screen_container) front = FrontScreen() self.screen_container.add_screen(front) self.screen_container.active_screen = front self.transient_message = transient_message self.footer = footer self.layout.add(self.footer, clutter.BIN_ALIGNMENT_CENTER, clutter.BIN_ALIGNMENT_END) self.container.add(transient_message) def on_allocation_changed(self, stage, allocation, flags): """ Callback for when the screen size allocation changes. """ width, height = allocation.size self.container.set_size(width, height) def on_press(self, actor, event): """ Toplevel callback for when buttons are pressed. """ if event.keyval == clutter.keysyms.Escape: logging.info('Escape button pressed. Quitting jukebox.') clutter.main_quit() elif event.keyval == clutter.keysyms.space: logging.debug('Space button pressed which means credit insert.') logging.info('Reading new credits value.') credits_load() self.screen_container.update_screens() elif event.keyval == clutter.keysyms.BackSpace: logging.info('Showing now playing information.') self.footer.display() elif event.keyval == clutter.keysyms.f: logging.info('Toggling fullscreen.') self.stage.set_fullscreen(not stage.get_fullscreen()) self.screen_container.on_press(actor, event) def on_release(self, actor, event): """ Callback for when a button is released. Currently does nothing. """ pass def on_second(self): """ Callback heartbeat tick that arrives each second. """ self.footer.update() self.screen_container.on_second() self.screen_container.update_screens() return True def set_transient_message(self, text): """ Display a transient message. """ self.transient_message.message(text) self.transient_message.raise_top() def run(self): """ Run the GUI. """ self.stage.show() clutter.main()