Exemple #1
0
class Loader(object):
    """ Loader class. """

    def __init__(self, size=(640, 480)):
        """ Default constructor. """
        self.size = size
        self.window = Window(size=size, fullscreen=False, backgroundColor=WHITE)
        self.container = Panel(orientation='vertical')
        self.window.add(self.container)
    
    def welcome(self):
        """ Welcome screen. """
        header = Label('Bienvenue', color=BLACK, size='huge')
        message = Label('Appuyer pour commencer', color=BLACK, size='medium')
        self.container.add(header)
        self.container.add(message)
        def onClick(position):
            """ Window click callback. """
            self.container.remove(header)
            self.container.remove(message)
            self.window.onWindowClick = None
            self.prompt('Voulez vous configurer la connection internet ?', lambda r: self.wifi(r))
        self.window.onWindowClick = onClick

    def prompt(self, question, callback):
        """ Prompt screen (Yes / No question only) """
        header = Label(question, color=BLACK, size='medium')
        panel = Panel(orientation='horizontal', padding=20)
        def createPromptCallback(callback, answer):
            def delegate():
                self.container.remove(header)
                self.container.remove(panel)
                callback(answer)
            return delegate
        yes = Label(' Oui ', color=WHITE, background=GRAY, size='medium')
        no = Label(' Non ', color=WHITE, background=GRAY, size='medium')
        yes.onClick = createPromptCallback(callback, True)
        no.onClick = createPromptCallback(callback, False)
        panel.add(yes)
        panel.add(no)
        self.container.add(header)
        self.container.add(panel)
        self.window.invalidate()

    def wifi(self, configure):
        """ WiFi configuration screen. """
        if configure:
            # TODO : Set RPI as WiFi hotspot.
            # TODO : Start webserver.
            # TODO : Quit and go next.
            pass
        else:
            quit()
Exemple #2
0
class PiBooth(object):
    """ Main application. """
    def __init__(self, camera, size=(640, 480)):
        """ Default constructor. """
        self.inCapture = False
        self.camera = camera
        self.window = Window(size=size)
        self.currentMode = PHOTO_MODE
        self.root = Panel(orientation='horizontal', )
        self.sidebar = Panel(orientation='vertical', padding=10)
        self.mode = Panel(orientation='horizontal', padding=10)
        self.modeLabel = Label('Photo', size='large')
        self.bind()

    def bind(self):
        """ """
        self.sidebar.add(self.mode)
        self.root.add(self.sidebar)
        self.window.add(self.root)

    def createModeController(self):
        """ Creates and configures widget for booth mode controller. """
        photo = Image('resources/icons/photo.png')
        video = Image('resources/icons/video.png')
        self.mode.add(photo)
        self.mode.add(self.modeLabel)
        self.mode.add(video)
        photo.onClick = lambda: self.setMode(PHOTO_MODE)
        video.onClick = lambda: self.setMode(VIDEO_MODE)

    def createRecordButton(self):
        """ """
        # TODO : Use centered button.
        container = Panel(orientation='horizontal', padding=30)
        button = Image('resources/icons/record.png')
        button.onClick = lambda: self.capture()
        container.add(button)
        self.sidebar.add(container)

    def createSettings(self):
        """ Creates and configures widget for photo configuration. """
        self.effects = self.camera.effects()
        self.currentEffect = 0
        effectPanel = Panel(orientation='horizontal', padding=0)
        effectPanel.add(Image('resources/icons/filter.png'))
        container = Panel(orientation='horizontal', padding=10)
        prevEffect = Label('<', size='large')
        nextEffect = Label('>', size='large')
        self.effectLabel = Label(self.effects[self.currentEffect],
                                 size='large')
        container.add(prevEffect)
        container.add(self.effectLabel)
        container.add(nextEffect)
        effectPanel.add(container)
        self.sidebar.add(effectPanel)

    def capture(self):
        """ """
        pass

    def setMode(self, mode):
        """ Sets current mode and updates UI accordingly. """
        if self.inCapture or mode == self.currentMode: return
        self.modeLabel.text = 'Photo' if mode == PHOTO_MODE else 'Video'
        self.currentMode = mode
        self.window.invalidate()

    def setEffect(self, iteration):
        """ Sets the current camera filter and updates UI accordingly. """
        self.currentEffect += iteration
        if self.currentEffect < 0:
            self.currentEffect = len(self.effects) - 1
        elif self.currentEffect >= len(self.effects):
            self.currentEffect = 0
        self.camera.setEffect(self.effects[self.currentEffect])
        self.effectLabel.text = self.effects[self.currentEffect]
        self.window.invalidate()