<reponame>eddy-ilg/iviz
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

from .GridSetup import GridSetup

class GridMapper:
    def __init__(self, numColums=8):
        self._maps = {}
        self._displays = {}
        self._pos = (0, 0)
        self._numColums = numColums

    def _incrementPosition(self):
        i, j = self._pos
        i += 1
        if i == self._numColums:
            j += 1
            i = 0
        self._pos = (i, j)

    def add(self, display, func=None):
        pos = self._pos
        self._maps[pos] = func
        self._displays[pos] = display
        self._incrementPosition()

    def set(self, pos, display, func=None):
        self._maps[pos] = func
        self._displays[pos] = display
        self._pos = pos
        self._incrementPosition()

    def map(self, numItems):
        items = []

        for i in range(0, numItems):
            item = {}

            for pos, func in self._maps.items():
                if func is not None:
                    item[pos] = func

            items.append(item)

        setup = GridSetup()
        setup.configure(self._displays, items)

        return setup

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

from .GridSetup import GridSetup

class GridMapper:
    def __init__(self, numColums=8):
        self._maps = {}
        self._displays = {}
        self._pos = (0, 0)
        self._numColums = numColums

    def _incrementPosition(self):
        i, j = self._pos
        i += 1
        if i == self._numColums:
            j += 1
            i = 0
        self._pos = (i, j)

    def add(self, display, func=None):
        pos = self._pos
        self._maps[pos] = func
        self._displays[pos] = display
        self._incrementPosition()

    def set(self, pos, display, func=None):
        self._maps[pos] = func
        self._displays[pos] = display
        self._pos = pos
        self._incrementPosition()

    def map(self, numItems):
        items = []

        for i in range(0, numItems):
            item = {}

            for pos, func in self._maps.items():
                if func is not None:
                    item[pos] = func

            items.append(item)

        setup = GridSetup()
        setup.configure(self._displays, items)

        return setup
#!/usr/bin/env python3 #-*- coding: utf-8 -*-