Exemplo n.º 1
0
    def getSlideDimensionsFromFirstLayer(self, n=None):
        """Returns the [width, height] of the first slide layer"""
        if n is None:
            n = self.__deck.getIndex()
        layers = self.__deck.getSlideLayers(n)

        # return some default reasonable value if this is an empty slide
        if len(layers) == 0:
            return [640.0, 480.0]

        ftype = utils.getFileType(layers[0])

        # This may be optimizable to avoid having to open the first layer to get its size,
        # or at least keeping it around to re-use it when the slide is first
        # rendered
        if ftype == "svg":
            handle = Rsvg.Handle.new_from_file(layers[0])
            return [handle.width, handle.height]
        elif ftype == "png":
            surface = cairo.ImageSurface.create_from_png(layers[0])
            return [float(surface.get_width()), float(surface.get_height())]
        elif ftype == "jpg":
            pbuf = GdkPixbuf.Pixbuf.new_from_file(layers[0])
            return [float(pbuf.get_width()), float(pbuf.get_height())]
        else:
            return [640.0, 480.0]
Exemplo n.º 2
0
 def getSlideDimensionsFromFirstLayer(self, n=None):
     """Returns the [width, height] of the first slide layer"""
     if n is None:
         n = self.__deck.getIndex()
     layers = self.__deck.getSlideLayers(n)
     
     # return some default reasonable value if this is an empty slide
     if len(layers) == 0:
         return [640.0, 480.0]
     
     ftype = utils.getFileType(layers[0])
     
     # This may be optimizable to avoid having to open the first layer to get its size,
     # or at least keeping it around to re-use it when the slide is first rendered
     if ftype == "svg":
         f = open(layers[0], 'rb')
         svg_data = f.read()
         f.close()
         handle = rsvg.Handle(data=svg_data)
         a, b, w, h = handle.get_dimension_data()
         return [w,h]
     elif ftype == "png":
         surface = cairo.ImageSurface.create_from_png(layers[0])
         return [float(surface.get_width()), float(surface.get_height())]
     elif ftype == "jpg":
         pbuf = gtk.gdk.pixbuf_new_from_file(layers[0])
         return [float(pbuf.get_width()), float(pbuf.get_height())]
     else:
         return [640.0, 480.0]
Exemplo n.º 3
0
def main(onlyfiles=None):

    if (onlyfiles == None):
        mypath = getcwd() + r'/pdfs/'
        onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

    print(onlyfiles)

    for file in onlyfiles:
        if (utils.getFileType(file) == '.PDF'
                or utils.getFileType(file) == '.pdf'):
            utils.pdfToImg(file)
        else:
            utils.saveImgOnRightFolder(file)

        utils.invertColor(file)

        a = Contour(file)
        a.start()
        newContours = a.filterCountours()
        a.saveContours(newContours)
        a.saveCSVs(newContours)
 def read_file(self, file_path):
     self.__logger.debug("read_file " + str(file_path))
     print 'read_file:', file_path
     ftype = utils.getFileType(file_path)
     z = zipfile.ZipFile(file_path, "r")
     for i in z.infolist():
         f = open(os.path.join(self.__deck_dir, i.filename), "wb")
         f.write(z.read(i.filename))
         f.close()
     z.close()
     self.__deck.reload()
     print 'read_file: before', self.__deck.get_title(), self.metadata['title']
     self.__makeTB.decktitle_set_new(self.metadata['title'])
     print 'read_file: after', self.__deck.get_title()
     newindex = 0
     if 'current_index' in self.metadata:
         newindex = int(self.metadata.get('current_index', '0'))
     self.__deck.goToIndex(newindex, is_local=False)
Exemplo n.º 5
0
 def read_file(self, file_path):
     self.__logger.debug("read_file " + str(file_path))
     print 'read_file:', file_path
     ftype = utils.getFileType(file_path)
     z = zipfile.ZipFile(file_path, "r")
     for i in z.infolist():
         f = open(os.path.join(self.__deck_dir, i.filename), "wb")
         f.write(z.read(i.filename))
         f.close()
     z.close()
     self.__deck.reload()
     print 'read_file: before', self.__deck.get_title(), self.metadata['title']
     self.__makeTB.decktitle_set_new(self.metadata['title'])
     print 'read_file: after',  self.__deck.get_title()
     self.__toolbox.set_current_toolbar(NAVIGATION_TOOLBAR)
     newindex = 0
     if 'current_index' in self.metadata:
         newindex = int(self.metadata.get('current_index', '0'))
     self.__deck.goToIndex(newindex, is_local=False)
Exemplo n.º 6
0
    def renderSlideToSurface(self, surface, n=None):
        if n is None:
            n = self.__deck.getIndex()

        timerstart = time.time()

        self.__logger.debug("rendering slide " + str(n))
        ##ctx = gtk.gdk.CairoContext(cairo.Context(surface))
        ctx = cairo.Context(surface)

        self.__logger.debug("Got context at " + str(time.time() - timerstart))

        # Get the slide dimensions and set up a Cairo transformation matrix
        srcw, srch = self.getSlideDimensions(n)
        if srcw > 640:
            srcw = 640
        if srch > 480:
            srch = 480

        targw = float(surface.get_width())
        targh = float(surface.get_height())
        x_scale = targw / srcw
        y_scale = targh / srch
        print 'rendering slide', str(
            n), "w=", targw, srcw, x_scale, "h=", targh, srch, y_scale

        self.__logger.debug("Surface is " + str(targw) + "x" + str(targh))

        scale = x_scale
        if y_scale < x_scale:
            scale = y_scale

        if scale < .98 or scale > 1.02:
            ctx.transform(cairo.Matrix(scale, 0, 0, scale, 0, 0))

        self.__logger.debug("Got transformation matrix at " +
                            str(time.time() - timerstart))

        # Paint the slide background
        ctx.set_source_rgb(1.0, 1.0, 1.0)
        ctx.rectangle(0, 0, srcw, srch)
        ctx.fill()

        self.__logger.debug("Filled background at " +
                            str(time.time() - timerstart))

        # Paint the layers
        layers = self.__deck.getSlideLayers(n)
        self.__logger.debug("Got layers at " + str(time.time() - timerstart))
        for layer in layers:
            type = utils.getFileType(layer)
            print 'Drawing layer ', type, layer
            self.__logger.debug("Drawing layer " + str(layer) + " " +
                                str(scale) + " at " +
                                str(time.time() - timerstart))
            print 'drawing layer', type, str(layer)
            if type == "svg":
                handle = Rsvg.Handle.new_from_file(layer)
                handle.render_cairo(ctx)
            elif type == "png":
                png_surface = cairo.ImageSurface.create_from_png(layer)
                self.__logger.debug("Got PNG surface at " +
                                    str(time.time() - timerstart))
                ctx.set_source_surface(png_surface, 0, 0)
                ctx.rectangle(0, 0, png_surface.get_width(),
                              png_surface.get_height())
                ctx.fill()
            elif type == "jpg":
                jpg_pixbuf = GdkPixbuf.Pixbuf.new_from_file(layer)
                self.__logger.debug("Got JPG pixbuf at " +
                                    str(time.time() - timerstart))
                ctx.set_source_pixbuf(jpg_pixbuf, 0, 0)
                ctx.rectangle(0, 0, jpg_pixbuf.get_width(),
                              jpg_pixbuf.get_height())
                ctx.fill()
            elif type == "html":
                # use hulahop to display
                print 'html slide', self.__htmlflag, layer
                scrn4 = self.__activity.set_screen(3)
                if self.__htmlflag:
                    scrn4.add(self.__wv)
                    self.__htmlflag = False
                self.__wv.load_uri('file://' + layer)
                self.__wv.show()
            self.__logger.debug("Finished drawing layer at " +
                                str(time.time() - timerstart))
Exemplo n.º 7
0
 def renderSlideToSurface(self, surface, n=None):
     if n is None:
         n = self.__deck.getIndex()
         
     timerstart = time.time()
         
     self.__logger.debug("rendering slide " + str(n))
     ctx = gtk.gdk.CairoContext(cairo.Context(surface))
     #ctx = cairo.Context(surface)
     
     self.__logger.debug("Got context at " + str(time.time() - timerstart))
     
     # Get the slide dimensions and set up a Cairo transformation matrix
     srcw, srch = self.getSlideDimensions(n)
     if srcw > 640:
         srcw = 640
     if srch > 480:
         srch = 480
     targw = float(surface.get_width())
     targh = float(surface.get_height())
     x_scale = targw/srcw
     y_scale = targh/srch
     print 'rendering slide', str(n), "w=", targw, srcw, x_scale, "h=", targh, srch, y_scale
     
     self.__logger.debug("Surface is " + str(targw) +  "x" + str(targh)) 
     
     scale = x_scale
     if y_scale < x_scale:
         scale = y_scale
     
     if scale < .98 or scale > 1.02:
         ctx.transform(cairo.Matrix(scale, 0, 0, scale, 0, 0))
     
     self.__logger.debug("Got transformation matrix at " + str(time.time() - timerstart))
     
     # Paint the slide background
     ctx.set_source_rgb(1.0, 1.0, 1.0)
     ctx.rectangle(0, 0, srcw, srch)
     ctx.fill()
     
     self.__logger.debug("Filled background at " + str(time.time() - timerstart))
     
     # Paint the layers
     layers = self.__deck.getSlideLayers(n)
     self.__logger.debug("Got layers at " + str(time.time() - timerstart))
     for layer in layers:
         type = utils.getFileType(layer)
         print 'Drawing layer ', type, layer
         self.__logger.debug("Drawing layer " + str(layer) +" " + str(scale) + " at "  + str(time.time() - timerstart))
         print 'drawing layer', type, str(layer)
         if type == "svg":
             f = open(layer, "rb")
             svg_data = f.read()
             f.close()
             handle = rsvg.Handle(data=svg_data)
             handle.render_cairo(ctx)
         elif type == "png":
             png_surface = cairo.ImageSurface.create_from_png(layer)
             self.__logger.debug("Got PNG surface at "+ str(time.time() - timerstart))
             ctx.set_source_surface(png_surface, 0, 0)
             ctx.rectangle(0, 0, png_surface.get_width(), png_surface.get_height())
             ctx.fill()
         elif type == "jpg":
             jpg_pixbuf = gtk.gdk.pixbuf_new_from_file(layer)
             self.__logger.debug("Got JPG pixbuf at "+ str(time.time() - timerstart))
             ctx.set_source_pixbuf(jpg_pixbuf, 0, 0)
             ctx.rectangle(0, 0, jpg_pixbuf.get_width(), jpg_pixbuf.get_height())
             ctx.fill()
         elif type == "html":
             #use hulahop to display
             print 'html slide', self.__htmlflag, layer
             scrn4 = self.__activity.set_screen(3)
             if self.__htmlflag:
                 scrn4.add(self.__wv)
                 self.__htmlflag = False
             self.__wv.load_uri('file://' + layer)
             self.__wv.show()
         self.__logger.debug("Finished drawing layer at "+ str(time.time() - timerstart))
Exemplo n.º 8
0
	def render_slide_to_surface(self, surface, n=None):
		if n is None:
			n = self.__arbiter.get_slide_index()
			
		timerstart = time.time()
			
		self.__logger.debug("rendering slide " + str(n))
		ctx = gtk.gdk.CairoContext(cairo.Context(surface))
		#ctx = cairo.Context(surface)
		
		self.__logger.debug("Got context at " + str(time.time() - timerstart))
		
		# Get the slide dimensions and set up a Cairo transformation matrix
		srcw, srch = self.getSlideDimensions(n)
		targw = float(surface.get_width())
		targh = float(surface.get_height())
		x_scale = targw/srcw
		y_scale = targh/srch
		
		self.__logger.debug("Surface is " + str(targw) +  "x" + str(targh)) 
		
		scale = x_scale
		if y_scale < x_scale:
			scale = y_scale
		
		if scale < .98 or scale > 1.02:
			ctx.transform(cairo.Matrix(scale, 0, 0, scale, 0, 0))
		
		self.__logger.debug("Got transformation matrix at " + str(time.time() - timerstart))
		
		# Paint the slide background
		ctx.set_source_rgb(1.0, 1.0, 1.0)
		ctx.rectangle(0, 0, srcw, srch)
		ctx.fill()
		
		self.__logger.debug("Filled background at " + str(time.time() - timerstart))
		
		# Paint the layers
		layers = self.__arbiter.get_slide_layers(n)
		self.__logger.debug("Got layers at " + str(time.time() - timerstart))
		for layer in layers:
			type = utils.getFileType(layer)
			self.__logger.debug("Drawing layer " + str(layer) +" " + str(scale) + " at "  + str(time.time() - timerstart))
			if type == "svg":
				f = open(layer, "rb")
				svg_data = f.read()
				f.close()
				handle = rsvg.Handle(data=svg_data)
				handle.render_cairo(ctx)
			elif type == "png":
				png_surface = cairo.ImageSurface.create_from_png(layer)
				self.__logger.debug("Got PNG surface at "+ str(time.time() - timerstart))
				ctx.set_source_surface(png_surface, 0, 0)
				ctx.rectangle(0, 0, png_surface.get_width(), png_surface.get_height())
				ctx.fill()
			elif type == "jpg":
				jpg_pixbuf = gtk.gdk.pixbuf_new_from_file(layer)
				self.__logger.debug("Got JPG pixbuf at "+ str(time.time() - timerstart))
				ctx.set_source_pixbuf(jpg_pixbuf, 0, 0)
				ctx.rectangle(0, 0, jpg_pixbuf.get_width(), jpg_pixbuf.get_height())
				ctx.fill()
			self.__logger.debug("Finished drawing layer at "+ str(time.time() - timerstart))