コード例 #1
0
ファイル: fixture.py プロジェクト: aszlig/GrandPA
    def __init__(self, length, sect=None, rect=None, bar=None):
        if sect is None and rect is None:
            raise RuntimeError("Section was initialized without rect or sect")

        self.sect = sect
        self.rect = rect

        self.bar = bar

        self.length = length

        self.selected = False

        self.dimmer_lock = threading.RLock()
        self._dimmer = None

        dimchars = []
        for dc in self.DIMCHARS:
            if dc.startswith("ACS_"):
                dimchars.append(getattr(curses, dc))
            else:
                dimchars.append(dc)
        self.dimchars = dimchars

        self.color_lock = threading.Lock()
        self._color = Color()
コード例 #2
0
ファイル: fixture.py プロジェクト: aszlig/GrandPA
class Section(object):
    """
    Represents a visual section where the dimmer gets delegated to DMXout.
    """

    DIMCHARS = [
        " ",
        "+",
        "*",
        "ACS_DIAMOND",
        "ACS_BULLET",
        "ACS_BOARD",
        "ACS_PLUS",
        "ACS_CKBOARD",
        "ACS_LANTERN",
        "ACS_BLOCK",
    ]

    def __init__(self, length, sect=None, rect=None, bar=None):
        if sect is None and rect is None:
            raise RuntimeError("Section was initialized without rect or sect")

        self.sect = sect
        self.rect = rect

        self.bar = bar

        self.length = length

        self.selected = False

        self.dimmer_lock = threading.RLock()
        self._dimmer = None

        dimchars = []
        for dc in self.DIMCHARS:
            if dc.startswith("ACS_"):
                dimchars.append(getattr(curses, dc))
            else:
                dimchars.append(dc)
        self.dimchars = dimchars

        self.color_lock = threading.Lock()
        self._color = Color()

    def _set_dimmer(self, val):
        self.dimmer_lock.acquire()
        self._dimmer = val
        self.dimmer_lock.release()

    def _get_dimmer(self):
        self.dimmer_lock.acquire()
        ret = self._dimmer
        self.dimmer_lock.release()
        return ret

    dimmer = property(_get_dimmer, _set_dimmer)

    def _set_color(self, val):
        self.color_lock.acquire()
        self._color.set_color(val)
        self.color_lock.release()

    def _get_color(self):
        self.color_lock.acquire()
        ret = self._color
        self.color_lock.release()
        return ret

    color = property(_get_color, _set_color)

    def update(self):
        self.dimmer_lock.acquire()

        if self.sect is not None:
            if self.dimmer is None:
                dim = 0
            else:
                dim = int(max(self.color.to_tuple()) / 255.0 * self.dimmer / 255.0 * len(self.dimchars))

            try:
                dimchar = self.dimchars[dim]
            except IndexError:
                dimchar = self.dimchars[len(self.dimchars) - 1]

            colname = self.color.get_name()
            if colname is not None:
                attr = style.attr("color_%s" % colname)
            else:
                attr = 0

            self.sect.hline(0, 0, dimchar, self.length, attr)
        elif self.rect is not None:
            if self.dimmer is None:
                dim = 0
            else:
                dim = self.dimmer
            color = self.color.to_tuple(use_alpha=dim)
            self.rect.fill(*color)

        self.dimmer_lock.release()

    def refresh(self, hard=False):
        locking.refresh_lock.acquire()
        self.update()
        if self.sect is not None:
            if hard:
                self.sect.redrawwin()
            else:
                self.sect.refresh()
        locking.refresh_lock.release()