Ejemplo n.º 1
0
    def onData(self, fd, condition):
        self.msgbuf = self.msgbuf + \
            self.io_subsys.read(fd, 8 - len(self.msgbuf))

        if len(self.msgbuf) < 8:
            # print "incomplete message: %s" % list(self.msgbuf)
            return True

        (t, size) = struct.unpack("2i", self.msgbuf)
        self.msgbuf = b""
        bytes = self.io_subsys.read(fd, size)
        if len(bytes) < size:
            print(
                "not enough bytes, got %d instead of %d" %
                (len(bytes), size))
            return True

        m = messages.parse(t, bytes)

        if utils.threads_enabled:
            Gdk.threads_enter()

        # print "msg: %s %d %d %d %d" % (m,p1,p2,p3,p4)
        if t == fract4dc.MESSAGE_TYPE_ITERS:
            if not self.skip_updates:
                self.iters_changed(m.iterations)
        elif t == fract4dc.MESSAGE_TYPE_IMAGE:
            if not self.skip_updates:
                self.image_changed(m.x, m.y, m.w, m.h)
        elif t == fract4dc.MESSAGE_TYPE_PROGRESS:
            if not self.skip_updates:
                progress = m.progress
                # filters out 'backwards' progress which can occur due to
                # threading
                if progress > self.last_progress or progress == 0.0:
                    self.progress_changed(progress)
                    self.last_progress = progress
        elif t == fract4dc.MESSAGE_TYPE_STATUS:
            if m.status == fract4dc.CALC_DONE:  # DONE
                self.running = False
            if not self.skip_updates:
                self.status_changed(m.status)
        elif t == fract4dc.MESSAGE_TYPE_PIXEL:
            # FIXME pixel_changed
            pass
        elif t == fract4dc.MESSAGE_TYPE_TOLERANCE:
            # tolerance changed
            if not self.skip_updates:
                self.tolerance_changed(m.tolerance)
        elif t == fract4dc.MESSAGE_TYPE_STATS:
            if not self.skip_updates:
                self.stats_changed(m)
        else:
            print("Unknown message from fractal thread; %s" % list(bytes))

        if utils.threads_enabled:
            Gdk.threads_leave()
        return True
Ejemplo n.º 2
0
    def onData(self, fd, condition):
        self.msgbuf = self.msgbuf + self.io_subsys.read(fd, 8 - len(self.msgbuf))

        if len(self.msgbuf) < 8:
            # print "incomplete message: %s" % list(self.msgbuf)
            return True

        (t, size) = struct.unpack("2i", self.msgbuf)
        self.msgbuf = ""
        bytes = self.io_subsys.read(fd, size)
        if len(bytes) < size:
            print "not enough bytes, got %d instead of %d" % (len(bytes), size)
            return True

        m = messages.parse(t, bytes)

        if utils.threads_enabled:
            gtk.gdk.threads_enter()

        # print "msg: %s %d %d %d %d" % (m,p1,p2,p3,p4)
        if t == fract4dc.MESSAGE_TYPE_ITERS:
            if not self.skip_updates:
                self.iters_changed(m.iterations)
        elif t == fract4dc.MESSAGE_TYPE_IMAGE:
            if not self.skip_updates:
                self.image_changed(m.x, m.y, m.w, m.h)
        elif t == fract4dc.MESSAGE_TYPE_PROGRESS:
            if not self.skip_updates:
                progress = m.progress
                # filters out 'backwards' progress which can occur due to threading
                if progress > self.last_progress or progress == 0.0:
                    self.progress_changed(progress)
                    self.last_progress = progress
        elif t == fract4dc.MESSAGE_TYPE_STATUS:
            if m.status == fract4dc.CALC_DONE:  # DONE
                self.running = False
            if not self.skip_updates:
                self.status_changed(m.status)
        elif t == fract4dc.MESSAGE_TYPE_PIXEL:
            # FIXME pixel_changed
            pass
        elif t == fract4dc.MESSAGE_TYPE_TOLERANCE:
            # tolerance changed
            if not self.skip_updates:
                self.tolerance_changed(m.tolerance)
        elif t == fract4dc.MESSAGE_TYPE_STATS:
            if not self.skip_updates:
                self.stats_changed(m)
        else:
            print "Unknown message from fractal thread; %s" % list(bytes)

        if utils.threads_enabled:
            gtk.gdk.threads_leave()
        return True
Ejemplo n.º 3
0
    def testFDSite(self):
        xsize = 64
        ysize = int(xsize * 3.0 / 4.0)
        im = image.T(xsize, ysize)
        (rfd, wfd) = os.pipe()
        site = fract4dc.fdsite_create(wfd)

        file = self.compileColorMandel()

        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)

        for x in range(2):
            fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params)
            cmap = fract4dc.cmap_create(
                [(0.0, 0, 0, 0, 255),
                 (1 / 256.0, 255, 255, 255, 255),
                 (1.0, 255, 255, 255, 255)])

            fract4dc.calc(
                params=[0.0, 0.0, 0.0, 0.0,
                        4.0,
                        0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                antialias=0,
                maxiter=100,
                yflip=0,
                nthreads=1,
                pfo=pfunc,
                cmap=cmap,
                auto_deepen=0,
                periodicity=1,
                render_type=0,
                image=im._img,
                site=site,
                asynchronous=True)

            while True:
                # read message type and size
                # we use a buffer here like in gtkfractal.py "onData"
                nb = 2 * 4
                bytes = b""
                while True:
                    # wait up to 1 sec until we can read, otherwise we assume the counterpart is gone (an error ocurred on the C++ layer)
                    r, w, e = select.select([rfd], [], [], 1)
                    if rfd in r:
                        temp = os.read(rfd, nb - len(bytes))
                    else:
                        self.fail("no one on the other side")
                    bytes = bytes + temp
                    if (len(bytes) == nb):
                        break
                    elif temp == '':
                        self.fail(
                            "bad message with length %s, value %s" %
                            (len(bytes), bytes))
                (t, size) = struct.unpack("2i", bytes)

                # read the actual message
                bytes = os.read(rfd, size)
                if len(bytes) < size:
                    self.fail("bad message")
                    break
                msg = messages.parse(t, bytes)
                # if the fractal is done
                if msg.name == "Status" and msg.status == 0:
                    # fract4dc.interrupt(site)
                    break
Ejemplo n.º 4
0
    def testFDSite(self):
        xsize = 64
        ysize = int(xsize * 3.0/4.0)
        im = image.T(xsize,ysize)
        (rfd,wfd) = os.pipe()
        site = fract4dc.fdsite_create(wfd)

        file = self.compileColorMandel()

        for x in range(2):
            handle = fract4dc.pf_load(file)
            pfunc = fract4dc.pf_create(handle)
            fract4dc.pf_init(pfunc,pos_params,self.color_mandel_params)
            cmap = fract4dc.cmap_create(
                [(0.0,0,0,0,255),
                 (1/256.0,255,255,255,255),
                 (1.0, 255, 255, 255, 255)])

            fract4dc.calc(
                params=[0.0, 0.0, 0.0, 0.0,
                 4.0,
                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                antialias=0,
                maxiter=100,
                yflip=0,
                nthreads=1,
                pfo=pfunc,
                cmap=cmap,
                auto_deepen=0,
                periodicity=1,
                render_type=0,
                image=im._img,
                site=site,
                asynchronous=True)

            nrecved = 0
            while True:
                if nrecved == x:
                    #print "hit message count"
                    fract4dc.interrupt(site)
                
                nb = 2*4
                bytes = os.read(rfd,nb)
                if len(bytes) < nb:
                    self.fail("bad message with length %s, value %s" % (len(bytes), bytes))
                    break

                (t,size) = struct.unpack("2i",bytes)
                #print "read %d, len %d" % (t,size)

                # read the rest of the message
                bytes = os.read(rfd,size)
                if len(bytes) < size:
                    self.fail("bad message")
                    break
                
                msg = messages.parse(t, bytes)
                #print "msg: %s" % msg.show()
                if msg.name == "Status" and msg.status == 0:
                    #done
                    #print "done"
                    break
                
                nrecved += 1
Ejemplo n.º 5
0
    def testFDSite(self):
        xsize = 64
        ysize = int(xsize * 3.0 / 4.0)
        im = image.T(xsize, ysize)
        (rfd, wfd) = os.pipe()
        site = fract4dc.fdsite_create(wfd)

        file = self.compileColorMandel()

        for x in range(2):
            handle = fract4dc.pf_load(file)
            pfunc = fract4dc.pf_create(handle)
            fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params)
            cmap = fract4dc.cmap_create([(0.0, 0, 0, 0, 255),
                                         (1 / 256.0, 255, 255, 255, 255),
                                         (1.0, 255, 255, 255, 255)])

            fract4dc.calc(
                params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                antialias=0,
                maxiter=100,
                yflip=0,
                nthreads=1,
                pfo=pfunc,
                cmap=cmap,
                auto_deepen=0,
                periodicity=1,
                render_type=0,
                image=im._img,
                site=site,
                asynchronous=True)

            nrecved = 0
            while True:
                if nrecved == x:
                    # print "hit message count"
                    fract4dc.interrupt(site)

                nb = 2 * 4
                bytes = os.read(rfd, nb)
                if len(bytes) < nb:
                    self.fail("bad message with length %s, value %s" %
                              (len(bytes), bytes))
                    break

                (t, size) = struct.unpack("2i", bytes)
                # print "read %d, len %d" % (t,size)

                # read the rest of the message
                bytes = os.read(rfd, size)
                if len(bytes) < size:
                    self.fail("bad message")
                    break

                msg = messages.parse(t, bytes)
                # print "msg: %s" % msg.show()
                if msg.name == "Status" and msg.status == 0:
                    # done
                    # print "done"
                    break

                nrecved += 1