Exemple #1
0
    def _edit_engine_name(self, new_index):

        # detect if we try to manually adjust the name
        # if so, we need to reset the current index, overwrite the name and remove the new element
        # make sure to not do this when we created the first element this way
        if new_index >= len(self.engines.engines) and new_index >= 1:
            new_text = self.engine_combo.currentText()
            old_text = self.engine_combo.itemText(self.engine_combo_index)
            self.engine_combo.setItemText(self.engine_combo_index, new_text)
            self.engine_combo.setCurrentIndex(self.engine_combo_index)
            self.engine_combo.removeItem(new_index)

            # also adjusting the name in the config
            self.engines.engines[new_text] = self.engines.engines[old_text]
            del self.engines.engines[old_text]
            updateStatusBar('replaced engine name')
        elif new_index >= len(self.engines.engines) and new_index == 0:
            new_text = self.engine_combo.currentText()
            self.engines.engines[new_text] = Engine()
            self.engine_combo_index = self.engine_combo.currentIndex()
            updateStatusBar('created new engine')
        else:
            self.engine_combo_index = self.engine_combo.currentIndex()
            updateStatusBar('changed current engine')

        self._update_option_widgets()
Exemple #2
0
def runBox(boxUid):

    host = ConsoleHost()

    agnostic.collect()
    #TODO CH remove these test lines
    screen.clear()
    font.draw_generator(generatorFactory(), plotter)
    screen.redraw()

    agnostic.collect()

    boxUid = str(boxUid) # handle case of passing a number

    boxEngine = Engine(box=story.lookupBox(boxUid))
    boxEngine.registerStory(story)
    agnostic.collect()

    while True:
        agnostic.report_collect()
        try:
            tagUid = vault.awaitPresence()
            try:
                cardDict = vault.readJson(tagUid=tagUid)
                if "storyUid" not in cardDict or cardDict["storyUid"] is not loader.storyUid:
                    cardDict = None # existing card data incompatible
            except Exception as e:
                if type(e) is KeyboardInterrupt:
                    raise e
                else:
                    print(e)
                    cardDict = None # couldn't read card for some reason

            if cardDict is not None:
                print("JSON Good")
                card = dictToCard(tagUid, cardDict)
            else:
                print("JSON Bad")
                card = story.createBlankCard(tagUid)

            agnostic.collect()

            boxEngine.handleCard(card, host)
            print("Handled Card")
            vault.writeJson(cardToDict(card), tagUid=tagUid, unselect=True)
            print("Written JSON")
            vault.awaitAbsence()
            print("Card removed")
        except AssertionError as ae:
            print(type(ae).__name__ + str(ae))
        except KeyboardInterrupt:
            break
Exemple #3
0
    def _add_engine(self, name=None):

        new_idx = 1
        new_name = f"NewEngine{new_idx}" if name is None else name
        i = 0
        while i < self.engine_combo.count():
            if self.engine_combo.itemText(i) == new_name:
                i = 0
                new_idx += 1
            new_name = f"NewEngine{new_idx}"
            i += 1

        self.engines.engines[new_name] = Engine()
        self.engine_combo.addItem(new_name)
        self.engine_combo.setCurrentIndex(self.engine_combo.count() - 1)
        self.engine_combo_index = self.engine_combo.count() - 1
Exemple #4
0
    def __init__(self, *a, **k):
        super().__init__(*a, **k)

        # get boxes from story registry, create+store an engine for each
        boxTable = self.story._get_table(Box)
        self.engines = dict()
        for boxUid, box in boxTable.items():
            engine = Engine(box=box)
            engine.registerStory(self.story)
            self.engines[boxUid] = engine

        # for each card, register it with the emulator
        cardIds = "a"
        for cardId in cardIds:
            card = self.story.createBlankCard(cardId)
            self.registerCard(card)

        self.currentCard = None
Exemple #5
0
    keyState = KeyboardState(story)

    hosts = dict()
    screens = list()

    hostThreads = list()
    boxUids = list(boxTable.keys())
    boxUids.sort()
    for boxUid in boxUids:
        box = story.lookupBox(boxUid)
        rfid = keyState.create_rfid(boxUid) # TODO can simplify by creating window last, or does RFID need window beforehand?
        screen = st7920Emulator.PillowScreen()
        blackPlotter = screen.create_plotter(True)
        whitePlotter = screen.create_plotter(False)
        engine = Engine(box=box)
        engine.registerStory(story)
        host = Host(
            story = story,
            box = boxTable[boxUid],
            engine=engine,
            screen=screen,
            rfid = rfid,
            smallFont=smallFont,
            bigFont=bigFont,
            blackPlotter=blackPlotter,
            whitePlotter=whitePlotter,
            powerPin = None
        )
        hosts[boxUid] = host
        screens.append(screen)