Exemplo n.º 1
0
from dot3k.menu import Menu
import dot3k.backlight
import dot3k.lcd
import time
"""
Let there be light!
"""
dot3k.backlight.rgb(255, 255, 255)
"""
The menu structure is defined as a nested dictionary,
to "install" your plugin, it should be added like so:

You will also need to pass Menu a reference to the LCD
you wish to draw to.
"""
menu = Menu(structure={'Hello World': HelloWorld()}, lcd=dot3k.lcd)
"""
We're not going to handle any input, so go
right ahead and virtually press "right" to
enter your plugin:

"""
menu.right()
"""
You can decide when the menu is redrawn, but
you'll usually want to do this:
"""
while 1:
    menu.redraw()
    time.sleep(0.01)
Exemplo n.º 2
0
Arquivo: radio.py Projeto: akx/dot3k
    joystick.repeat(joystick.UP, menu.up, REPEAT_DELAY, 0.9)


@joystick.on(joystick.DOWN)
def handle_down(pin):
    menu.down()
    joystick.repeat(joystick.DOWN, menu.down, REPEAT_DELAY, 0.9)


@joystick.on(joystick.LEFT)
def handle_left(pin):
    menu.left()
    joystick.repeat(joystick.LEFT, menu.left, REPEAT_DELAY, 0.9)


@joystick.on(joystick.RIGHT)
def handle_right(pin):
    menu.right()
    joystick.repeat(joystick.RIGHT, menu.right, REPEAT_DELAY, 0.9)


@joystick.on(joystick.BUTTON)
def handle_button(pin):
    menu.select()


while 1:
    # Redraw the menu, since we don't want to hand this off to a thread
    menu.redraw()
    time.sleep(0.05)
Exemplo n.º 3
0
class MainMenu():
    controller = None

    def __init__(self, repline, controller):
        self.repline = repline
        self.controller = controller

        self.menu = Menu(
            structure={
                'Record': self.record,
                'Settings': {
                    'Recording': {
                        'Normalisation': Normalisation(repline)
                    },
                    'Track detection': {
                        SilenceThreshold.title: SilenceThreshold(repline),
                        MinSilenceLength.title: MinSilenceLength(repline)
                    },
                    'Encoding': {
                        OutputFormat.title:
                        OutputFormat(repline),
                        get_quality_setting(repline).title:
                        get_quality_setting(repline)
                    },
                    # 'Saving': {
                    # },
                    'Hardware': {
                        SetInputDevice.title: SetInputDevice(repline),
                        SetOutputDevice.title: SetOutputDevice(repline),
                    }
                }
            },
            lcd=lcd)
        nav.bind_defaults(self.menu)

    def on_active(self):
        pass

    def redraw(self):
        self.menu.redraw()

    def record(self):
        self.controller.open_record_ui()

    def handle_up(self, ch, evt):
        self.menu.up()

    def handle_down(self, ch, evt):
        self.menu.down()

    def handle_left(self, ch, evt):
        self.menu.left()

    def handle_right(self, ch, evt):
        self.menu.right()

    def handle_select(self, ch, evt):
        self.menu.select()

    def handle_cancel(self, ch, evt):
        self.menu.cancel()
Exemplo n.º 4
0
class App:
    def __init__(self):

        self.structure = {}

        with open('local.json') as f:
            self.cards = json.load(f)
            self.config = self.cards['CONFIG']

        self.cards = self.formatCards(self.cards)
        for subject in self.cards:
            for topic in self.cards[subject]:
                self.cards[subject][topic] = self.CardSession(
                    self, self.cards[subject][topic], subject + "." + topic)

        print(self.config['favorites'])
        self.structure.update({
            'Continue': {},
            'Favorites':
            self.CardSession(self, self.config['favorites'], "favorites"),
            'View All Cards':
            self.cards,
            #'Get More Cards' : self.getCards(),
            #'Save and Exit' : saveAndExit(),
            'Settings': {
                # 'Check Server': line.checkServer()
            }
        })

        self.menu = Menu(structure=self.structure, lcd=lcd, idle_timeout=30)

        self.updateLastSession(self.config['lastSession'])

        touch.bind_defaults(self.menu)

    class CardSession(MenuOption):
        def __init__(self, app, cards, name, cont=False):
            self.cards = cards
            self.name = name
            self.cont = cont
            self.app = app

            self.currentIndex = 0
            self.indices = [i for i in cards]

            self.back = False
            self.lastUpdate = 0
            self.running = False

            MenuOption.__init__(self)

        def begin(self):
            self.running = False
            self.reset()

            if not self.cont:
                self.app.setLastSession(self.name)

        def reset(self):

            self.running = True
            lcd.clear()

        def right(self):
            if not self.running:
                return True
            self.reset()
            self.currentIndex += 1
            self.back = False

            if self.currentIndex == len(self.indices):
                self.currentIndex = 0
            return True

        def left(self):
            if not self.running:
                return False
            self.reset()
            self.currentIndex -= 1
            self.back = False

            if self.currentIndex == -1:
                self.currentIndex = len(self.indices) - 1
            return True

        def up(self):
            self.app.favoriteCard(self.indices[self.currentIndex],
                                  self.cards[self.indices[self.currentIndex]])

            return True

        def down(self):
            self.app.unfavoriteCard(
                self.indices[self.currentIndex],
                self.cards[self.indices[self.currentIndex]])

            return True

        def select(self):
            self.reset()
            self.back = not self.back

        def redraw(self, menu):

            if self.millis() - self.lastUpdate <= 250:
                return

            if not self.running:
                return False

            self.lastUpdate = self.millis()

            lcd.set_cursor_position(0, 1)
            if not self.back:
                lcd.write(self.indices[self.currentIndex])
            else:
                lcd.write(self.cards[self.indices[self.currentIndex]])

    def formatCards(self, toLoad):
        cards = {}
        for pack in toLoad:
            if pack.split(".")[0] != "CONFIG":
                packContents = toLoad[pack]
                pack = pack.split(".")
                subject = pack[0]
                topic = pack[1]

                try:
                    cards[subject]
                except KeyError:
                    cards[subject] = {}

                cards[subject][topic] = packContents

        return cards

    def setLastSession(self, name):
        with open('local.json', "r+") as f:
            data = json.load(f)
            data['CONFIG']['lastSession'] = name
            self.config = data['CONFIG']
            f.seek(0)
            json.dump(data, f)
            f.truncate()

        self.updateLastSession(name)

    def updateLastSession(self, name):
        print(name)
        if name == "favorites":
            self.menu.menu_options['Continue'] = self.CardSession(
                self, self.config["favorites"], name, True)
            print("wut")
            print(self.menu.menu_options['Continue'].cards)
        else:
            subject = name.split('.')[0]
            topic = name.split('.')[1]
            self.menu.menu_options['Continue'] = self.cards[subject][topic]

    def favoriteCard(self, cardFront, cardBack):
        if cardFront not in self.config['favorites']:
            with open('local.json', "r+") as f:
                data = json.load(f)
                data['CONFIG']['favorites'].update({cardFront: cardBack})
                self.config = data['CONFIG']
                f.seek(0)
                json.dump(data, f)
                f.truncate()

    def unfavoriteCard(self, cardFront, cardBack):
        if cardFront in self.config['favorites']:
            with open('local.json', "r+") as f:
                data = json.load(f)
                data['CONFIG']['favorites'].pop(cardFront)
                self.config = data['CONFIG']
                f.seek(0)
                json.dump(data, f)
                f.truncate()

        self.menu.menu_options['Favorites'] = self.CardSession(
            self, self.config["favorites"], 'favorites')

        print(self.config['favorites'])

    def saveAndExit(self):
        pass

    def getCards(self):
        pass

    def update(self):
        self.menu.redraw()
Exemplo n.º 5
-1
def main():
    """ 
       Set up a menu with the Calendar and go straight into it.
    """

    menu = Menu(
      structure={
          'calendar': GoogleCalendar()
      },
      lcd=lcd
    )

    # Register a function to turn the lights off on script exit.
    atexit.register(cleanup)

    # Go straight into out menu plugin, making it an app in this case
    menu.right()

    # setup default menu handlers 
    touch.bind_defaults(menu)
    while 1:
        menu.redraw()
        time.sleep(0.02)