Esempio n. 1
0
    def reload_code(self):
        # empty out the .pyc and .py file
        self.storefile(self.intermediatefilename, "")
        self.storefile(self.intermediatefilename + 'c', "")
        text = self.get_text()
        try:
            self.intermediate = reload(self.intermediate)
            # save and compile the text in the text widget on change.
            # always get the latest itteration of the compiled code.
            self.storefile(self.intermediatefilename, text)
            py_compile.compile(self.intermediatefilename)
        except Exception as e:
            print >>self, ("%s: %s" % (get_trace(), e))

        # check agains all the classes in intermediate code base.
        try:
            self.intermediate = reload(self.intermediate)
        except Exception as e:
            print >>self, "reload()>> " + str(e)

        selected = None
        try:
            if self.intermediate.select:
                selected = self.intermediate.select
                print >>self, "select: %s" % selected
        except:
            pass

        patterns = get_pattern_classes(self.intermediate)
        try:
            if selected:
                for Object in patterns:
                    if Object.__name__ == selected:
                        pattern = Object()
                        print >>self, "PatternSelected: %s" % Object.__name__
            else:
                pattern = patterns[0]()
                print >>self, "PatternSelected: %s" % patterns[0].__name__
        except Exception as e:
            print >>self, "generating from dummy for now"
            pattern = PatternDummy()
            print >>self, "%s" % get_pattern_classes(self.intermediate)
            print >>self, "No valid Class with Generate function found!"
            print >>self, "%s:%s" % (get_trace(), e)

        self.matrix_widget.set_pattern(pattern)
        # reset hasprinted in matrix_widget, cause now it might work.
        if self.matrix_widget.hasprinted:
            self.matrix_widget.hasprinted = False
Esempio n. 2
0
 def sendout(self, data):
     try:
         if(self.sendoutData != data):
             self.sendoutData = data
             self.socket.sendto(artnet.buildPacket(0, data),
                                (self.dest_ip, self.port))
     except Exception as e:
         fmt = (get_trace(), e)
         print >>self.par, ("pattern:%s:%s:sendPacket>> %s" % fmt)
Esempio n. 3
0
 def process(self):
     try:
         self.data = self.pattern.generate()
         self.matrixscreen.process_pixels(self.data)
         self.queue_draw()
     except Exception as e:
         if not self.hasprinted:
             l = get_trace()
             print >>self.par, ("%s:Wrong data Generated>> %s" % (l, e))
         self.hasprinted = True
     return True
Esempio n. 4
0
 def expose(self, widget, event):
     try:
         cr = widget.window.cairo_create()
         if len(self.matrixscreen.pixels):
             for pixel in self.matrixscreen.pixels:
                 x, y, width, height = pixel.getRect()
                 pixelcolor = pixel.getColor()
                 r, g, b = self.color_convert_f(pixelcolor)
                 cr.set_source_rgb(0.0, 0.0, 0.0)
                 cr.rectangle(x, y, width, height)
                 cr.stroke()
                 cr.set_source_rgb(r, g, b)
                 cr.rectangle(x + 1, y + 1, width - 2, height - 2)
                 cr.fill()
     except Exception as e:
         if not self.hasprinted:
             print >>self.par, "%s:%s" % (get_trace(), e)
         self.hasprinted = True
         return