Пример #1
0
 def get_widget(self):
     if self._widget is None:
         self._widget = FixtureWidget(self._controller.get_canvas(),
                                      model=self)
         x, y = self._pos1[0], self._pos1[1]
         cx, cy = self._controller.get_canvas().scene_to_canvas(x, y)
         self._widget.setPos(cx, cy)
         #self._widget.setRotation(self.angle)
     return self._widget
Пример #2
0
 def get_widget(self):
     if self.widget is None:
         self.widget = FixtureWidget(self.controller.get_canvas(), model=self)
         x, y = self.pos1[0], self.pos1[1]
         self.widget.setPos(x, y)
         #self.widget.setRotation(self.angle)
     return self.widget
Пример #3
0
 def get_widget(self):
     if self._widget is None:
         self._widget = FixtureWidget(self._controller.get_canvas(), model=self)
         x, y = self._pos1[0], self._pos1[1]
         cx, cy = self._controller.get_canvas().scene_to_canvas(x, y)
         self._widget.setPos(cx, cy)
         #self._widget.setRotation(self.angle)
     return self._widget
Пример #4
0
class Fixture:

    def __init__(self, data=None, controller=None):
        self.strand = 0
        self.address = 0
        self.type = "linear"
        self.pixels = 32
        self.pos1 = (10, 10)
        self.pos2 = (50, 50)
        self.locked = False

        if data is not None:
            self.unpack(data)

        self.widget = None
        self.controller = controller

        self.pixel_data = [(0, 0, 0)] * self.pixels

    def __repr__(self):
        return "[%d:%d]*%d" % (self.strand, self.address, self.pixels)

    def destroy(self):
        self.widget.deleteLater()

    def request_destruction(self):
        self.controller.delete_fixture(self)

    def get_widget(self):
        if self.widget is None:
            self.widget = FixtureWidget(self.controller.get_canvas(), model=self)
            x, y = self.pos1[0], self.pos1[1]
            self.widget.setPos(x, y)
            #self.widget.setRotation(self.angle)
        return self.widget

    def unpack(self, data):
        self.strand = data.get("strand", 0)
        self.address = data.get("address", 0)
        self.type = data.get("type", "")
        self.pixels = data.get("pixels", 0)
        self.pos1 = data.get("pos1", [0, 0])
        self.pos2 = data.get("pos2", [0, 0])

    def pack(self):
        return {
                'strand': self.strand,
                'address': self.address,
                'type': self.type,
                'pixels': self.pixels,
                'pos1': self.pos1,
                'pos2': self.pos2
                }

    def fixture_move_callback(self, fixture):
        self.pos1 = map(int, fixture.drag1.pos().toTuple())
        self.pos2 = map(int, fixture.drag2.pos().toTuple())
        fixture.update_geometry()

    def blackout(self):
        self.pixel_data = [(0, 0, 0)] * self.pixels
        self.widget.update()

    def set(self, pixel, color):
        assert isinstance(color, tuple), "Color must be a 3-tuple (R, G, B)"
        self.pixel_data[pixel] = color
        self.widget.update()

    def set_all(self, color):
        assert isinstance(color, tuple), "Color must be a 3-tuple (R, G, B)"
        self.pixel_data = [color] * self.pixels
        self.widget.update()

    def random_color(self):
        r, g, b = [int(255.0 * c) for c in colorsys.hsv_to_rgb(random.random(), 1.0, 1.0)]
        self.set_all((r, g, b))
Пример #5
0
class Fixture:

    def __init__(self, data=None, controller=None):
        self._strand = 0
        self._address = 0
        self._type = "linear"
        self._num_pixels = 32
        self._pos1 = (-1, -1)
        self._pos2 = (-1, -1)
        self._locked = False
        self._data_offset = 0

        if data is not None:
            self.unpack(data)

        self._widget = None
        self._controller = controller

        #self._pixel_data = [(0, 0, 0)] * self._pixels

    def __repr__(self):
        return "[%d:%d]*%d" % (self._strand, self._address, self._num_pixels)

    def strand(self):
        return self._strand

    def set_strand(self, strand):
        self._strand = strand

    def address(self):
        return self._address

    def update_offset(self, offset):
        self._data_offset = offset

    def set_address(self, address):
        self._address = address
        self.update_offset()

    def pixels(self):
        return self._num_pixels

    def set_pixels(self, pixels):
        self._num_pixels = pixels

    def pos1(self):
        return self._pos1

    def set_pos1(self, pos1):
        self._pos1 = pos1

    def pos2(self):
        return self._pos2

    def set_pos2(self, pos2):
        self._pos2 = pos2

    def destroy(self):
        self._widget.deleteLater()

    def request_destruction(self):
        self._controller.delete_fixture(self)

    def get_widget(self):
        if self._widget is None:
            self._widget = FixtureWidget(self._controller.get_canvas(), model=self)
            x, y = self._pos1[0], self._pos1[1]
            cx, cy = self._controller.get_canvas().scene_to_canvas(x, y)
            self._widget.setPos(cx, cy)
            #self._widget.setRotation(self.angle)
        return self._widget

    def pixel_data(self):
        data = self._controller.strand_data[self._strand][self._data_offset:self._data_offset+self._num_pixels]
        return data

    def unpack(self, data):
        self._strand = data.get("strand", 0)
        self._address = data.get("address", 0)
        self._type = data.get("type", "")
        self._num_pixels = data.get("pixels", 0)
        self._pos1 = data.get("pos1", [0, 0])
        self._pos2 = data.get("pos2", [0, 0])

    def pack(self):
        return {
                'strand': self._strand,
                'address': self._address,
                'type': self._type,
                'pixels': self._num_pixels,
                'pos1': self._pos1,
                'pos2': self._pos2
                }

    def fixture_move_callback(self, fixture):
        self._pos1 = map(int, (fixture.drag1.scene_x, fixture.drag1.scene_y))
        self._pos2 = map(int, (fixture.drag2.scene_x, fixture.drag2.scene_y))
        fixture.update_geometry()

    def random_color(self):
        r, g, b = [int(255.0 * c) for c in colorsys.hsv_to_rgb(random.random(), 1.0, 1.0)]
        self.set_all((r, g, b))
Пример #6
0
class Fixture:

    def __init__(self, data=None, controller=None):
        self._strand = 0
        self._address = 0
        self._type = "linear"
        self._pixels = 32
        self._pos1 = (10, 10)
        self._pos2 = (50, 50)
        self._locked = False

        if data is not None:
            self.unpack(data)

        self._widget = None
        self._controller = controller

        self._pixel_data = (0, 0, 0) * self._pixels

    def __repr__(self):
        return "[%d:%d]*%d" % (self._strand, self._address, self._pixels)

    def strand(self):
        return self._strand

    def set_strand(self, strand):
        self._strand = strand

    def address(self):
        return self._address

    def set_address(self, address):
        self._address = address

    def pixels(self):
        return self._pixels

    def set_pixels(self, pixels):
        self._pixels = pixels

    def pos1(self):
        return self._pos1

    def set_pos1(self, pos1):
        self._pos1 = pos1

    def pos2(self):
        return self._pos2

    def set_pos2(self, pos2):
        self._pos2 = pos2

    def destroy(self):
        self._widget.deleteLater()

    def request_destruction(self):
        self._controller.delete_fixture(self)

    def get_widget(self):
        if self._widget is None:
            self._widget = FixtureWidget(self._controller.get_canvas(), model=self)
            x, y = self._pos1[0], self._pos1[1]
            self._widget.setPos(x, y)
            #self._widget.setRotation(self.angle)
        return self._widget

    def unpack(self, data):
        self._strand = data.get("strand", 0)
        self._address = data.get("address", 0)
        self._type = data.get("type", "")
        self._pixels = data.get("pixels", 0)
        self._pos1 = data.get("pos1", [0, 0])
        self._pos2 = data.get("pos2", [0, 0])

    def pack(self):
        return {
                'strand': self._strand,
                'address': self._address,
                'type': self._type,
                'pixels': self._pixels,
                'pos1': self._pos1,
                'pos2': self._pos2
                }

    def fixture_move_callback(self, fixture):
        self._pos1 = map(int, fixture.drag1.pos().toTuple())
        self._pos2 = map(int, fixture.drag2.pos().toTuple())
        fixture.update_geometry()

    def blackout(self):
        self._pixel_data = [(0, 0, 0)] * self._pixels

    def set(self, pixel, color):
        assert isinstance(color, tuple), "Color must be a 3-tuple (R, G, B)"
        pixel_index = pixel * 3
        self._pixel_data[pixel_index:pixels_index + 3] = color

    def set_all(self, color):
        assert isinstance(color, tuple), "Color must be a 3-tuple (R, G, B)"
        self._pixel_data = list(color) * self._pixels

    def set_array(self, color_array):
        if len(color_array) != self.pixels():
            raise ValueError("set_array argument length must match fixture pixel count")
        self._pixel_data = color_array

    def set_flat_array(self, color_array, bgr=False, color_mode="RGB8"):
        if len(color_array) != 3 * self.pixels():
            print len(color_array)
            raise ValueError("set_flat_array argument length must match fixture pixel count")
        is_hlsf32 = color_mode == "HLSF32"

        # Common case
        if color_mode == 'RGB8':
            self._pixel_data = color_array
        else:
            for i, base_offset in enumerate(xrange(0, len(self._pixel_data)*3, 3)):
                if is_hlsf32:
                    hls = color_array[base_offset], color_array[base_offset + 1], color_array[base_offset + 2]
                    rgb = colorsys.hls_to_rgb(*hls)
                    red, green, blue = tuple([int(clip(0.0, 255.0 * channel, 255.0)) for channel in rgb])
                else:
                    red, green, blue = color_array[base_offset], color_array[base_offset + 1], color_array[base_offset + 2]

                if bgr:
                    self._pixel_data[i] = (blue, green, red)
                else:
                    self._pixel_data[i] = (red, green, blue)

    def random_color(self):
        r, g, b = [int(255.0 * c) for c in colorsys.hsv_to_rgb(random.random(), 1.0, 1.0)]
        self.set_all((r, g, b))
Пример #7
0
class Fixture:
    def __init__(self, data=None, controller=None, strand=0, address=0):
        self._strand = strand
        self._address = address
        self._type = "linear"
        self._num_pixels = 32
        self._pos1 = (-1, -1)
        self._pos2 = (-1, -1)
        self._locked = False
        self._data_offset = 0

        if data is not None:
            self.unpack(data)

        self._widget = None
        self._controller = controller

        #self._pixel_data = [(0, 0, 0)] * self._pixels

    def __repr__(self):
        return "[%d:%d]*%d" % (self._strand, self._address, self._num_pixels)

    def strand(self):
        return self._strand

    def set_strand(self, strand):
        self._strand = strand

    def address(self):
        return self._address

    def update_offset(self, offset):
        self._data_offset = offset

    def set_address(self, address):
        self._address = address
        # Offset will be updated from the SceneController

    def pixels(self):
        return self._num_pixels

    def set_pixels(self, pixels):
        self._num_pixels = pixels

    def pos1(self):
        return self._pos1

    def set_pos1(self, pos1):
        self._pos1 = pos1

    def pos2(self):
        return self._pos2

    def set_pos2(self, pos2):
        self._pos2 = pos2

    def destroy(self):
        log.info("Destroying fixture %s" % self)
        self._widget.deleteLater()

    def request_destruction(self):
        self._controller.delete_fixture(self)

    def get_widget(self):
        if self._widget is None:
            self._widget = FixtureWidget(self._controller.get_canvas(),
                                         model=self)
            x, y = self._pos1[0], self._pos1[1]
            cx, cy = self._controller.get_canvas().scene_to_canvas(x, y)
            self._widget.setPos(cx, cy)
            #self._widget.setRotation(self.angle)
        return self._widget

    def pixel_data(self):
        data = self._controller.strand_data[
            self._strand][self._data_offset:self._data_offset +
                          self._num_pixels]
        return data

    def unpack(self, data):
        self._strand = data.get("strand", 0)
        self._address = data.get("address", 0)
        self._type = data.get("type", "")
        self._num_pixels = data.get("pixels", 0)
        self._pos1 = data.get("pos1", [0, 0])
        self._pos2 = data.get("pos2", [0, 0])

    def pack(self):
        return {
            'strand': self._strand,
            'address': self._address,
            'type': self._type,
            'pixels': self._num_pixels,
            'pos1': self._pos1,
            'pos2': self._pos2
        }

    def fixture_move_callback(self, fixture):
        self._pos1 = map(int, (fixture.drag1.scene_x, fixture.drag1.scene_y))
        self._pos2 = map(int, (fixture.drag2.scene_x, fixture.drag2.scene_y))
        fixture.update_geometry()

    def random_color(self):
        r, g, b = [
            int(255.0 * c)
            for c in colorsys.hsv_to_rgb(random.random(), 1.0, 1.0)
        ]
        self.set_all((r, g, b))