Пример #1
0
    def createNewRecorded(self, type):
        recd = Recorded()

        recd.recorderName = self.get_nickname()
        recd.recorderHash = Instance.keyHashPrintable

        # to create a file, use the hardware_id+time *and* check if
        # available or not
        nowtime = int(time.time())
        recd.time = nowtime
        recd.type = type

        mediaThumbFilename = str(recd.recorderHash) + "_" + str(recd.time)
        mediaFilename = mediaThumbFilename
        mediaFilename = mediaFilename + "." + constants.MEDIA_INFO[type]['ext']
        mediaFilepath = os.path.join(Instance.instancePath, mediaFilename)
        mediaFilepath = utils.getUniqueFilepath(mediaFilepath, 0)
        recd.mediaFilename = os.path.basename(mediaFilepath)

        stringType = constants.MEDIA_INFO[type]['istr']

        # Translators: photo by photographer, e.g. "Photo by Mary"
        recd.title = _('%(type)s by %(name)s') % \
            {'type': stringType, 'name': recd.recorderName}

        color = sugar3.profile.get_color()
        recd.colorStroke = color.get_stroke_color()
        recd.colorFill = color.get_fill_color()

        logger.debug('createNewRecorded: ' + str(recd))
        return recd
Пример #2
0
    def createNewRecorded(self, type):
        recd = Recorded()

        recd.recorderName = self.get_nickname()
        recd.recorderHash = Instance.keyHashPrintable

        # to create a file, use the hardware_id+time *and* check if
        # available or not
        nowtime = int(time.time())
        recd.time = nowtime
        recd.type = type

        mediaThumbFilename = str(recd.recorderHash) + "_" + str(recd.time)
        mediaFilename = mediaThumbFilename
        mediaFilename = mediaFilename + "." + constants.MEDIA_INFO[type]['ext']
        mediaFilepath = os.path.join(Instance.instancePath,
                                     mediaFilename)
        mediaFilepath = utils.getUniqueFilepath(mediaFilepath, 0)
        recd.mediaFilename = os.path.basename(mediaFilepath)

        stringType = constants.MEDIA_INFO[type]['istr']

        # Translators: photo by photographer, e.g. "Photo by Mary"
        recd.title = _('%(type)s by %(name)s') % \
            {'type': stringType, 'name': recd.recorderName}

        color = sugar3.profile.get_color()
        recd.colorStroke = color.get_stroke_color()
        recd.colorFill = color.get_fill_color()

        logger.debug('createNewRecorded: ' + str(recd))
        return recd
Пример #3
0
    def _new_recd_cb(self, remote_object, recorder, xmlstr):
        logger.debug('new_recd_cb')
        dom = None
        try:
            dom = xml.dom.minidom.parseString(xmlstr)
        except:
            logger.error('Unable to parse mesh xml')
        if not dom:
            return

        recd = Recorded()
        recd = serialize.fillRecdFromNode(recd, dom.documentElement)
        if not recd:
            logger.debug('_newRecdCb: recd is None. Unable to parse XML')
            return

        logger.debug('_newRecdCb: adding new recd thumb')
        recd.buddy = True
        recd.downloadedFromBuddy = False
        self.model.add_recd(recd)
Пример #4
0
    def _new_recd_cb(self, remote_object, recorder, xmlstr):
        logger.debug('new_recd_cb')
        dom = None
        try:
            dom = xml.dom.minidom.parseString(xmlstr)
        except:
            logger.error('Unable to parse mesh xml')
        if not dom:
            return

        recd = Recorded()
        recd = serialize.fillRecdFromNode(recd, dom.documentElement)
        if not recd:
            logger.debug('_newRecdCb: recd is None. Unable to parse XML')
            return

        logger.debug('_newRecdCb: adding new recd thumb')
        recd.buddy = True
        recd.downloadedFromBuddy = False
        self.model.add_recd(recd)
Пример #5
0
    def addMedia(self, lat, lon, datastoreOb):
        rec = Recorded()

        #default photo
        rec.type = Constants.TYPE_PHOTO
        if ((datastoreOb.metadata['mime_type'] == "video/ogg")
                or (datastoreOb.metadata['mime_type'] == "audio/ogg")):
            rec.type = Constants.TYPE_VIDEO

        rec.source = Recorded.SOURCE_DATASTORE
        rec.datastoreOb = datastoreOb
        rec.datastoreId = datastoreOb.object_id

        rec.tags = ""
        if (datastoreOb.metadata.has_key("tags")):
            rec.tags = datastoreOb.metadata['tags']

        rec.latitude = lat
        rec.longitude = lon

        colors = datastoreOb.metadata['icon-color']
        colorStroke, colorFill = colors.split(",")
        rec.colorStroke = Color()
        rec.colorStroke.init_hex(colorStroke)
        rec.colorFill = Color()
        rec.colorFill.init_hex(colorFill)

        thumbPixbuf = None
        if (datastoreOb.metadata.has_key("preview")):
            try:
                thumb = datastoreOb.metadata['preview']
                if thumb[1:4] == 'PNG':
                    pbl = gtk.gdk.PixbufLoader()
                    pbl.write(thumb)
                    pbl.close()
                    thumbPixbuf = pbl.get_pixbuf()
                else:
                    thumbPixbuf = utils.getPixbufFromString(thumb)
            except:
                pass

        if (thumbPixbuf == None):
            #try to create the thumbnail yourself...
            if (rec.type == Constants.TYPE_PHOTO):
                try:
                    #load in the image, make a thumbnail
                    thumbPixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                        rec.getFilepath(), 320, 240)
                except:
                    pass

        if (thumbPixbuf == None):
            #i give up.  load in a blank image from the activity itself.
            thumbPath = os.path.join(self.ca.htmlPath, "1.jpg")
            thumbPixbuf = gtk.gdk.pixbuf_new_from_file(thumbPath)

        thumbFilepath = os.path.join(Instance.instancePath, "thumb.png")
        thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0)
        thumbPixbuf.save(thumbFilepath, "png", {})
        rec.thumbFilename = os.path.basename(thumbFilepath)

        self.recs.append(rec)

        return rec
Пример #6
0
	def addMedia(self, lat, lon, datastoreOb):
		rec = Recorded()

		#default photo
		rec.type = Constants.TYPE_PHOTO
		if((datastoreOb.metadata['mime_type'] == "video/ogg") or (datastoreOb.metadata['mime_type'] == "audio/ogg")):
			rec.type = Constants.TYPE_VIDEO

		rec.source = Recorded.SOURCE_DATASTORE
		rec.datastoreOb = datastoreOb
		rec.datastoreId = datastoreOb.object_id

		rec.tags = ""
		if (datastoreOb.metadata.has_key("tags")):
			rec.tags = datastoreOb.metadata['tags']

		rec.latitude = lat
		rec.longitude = lon
		

		colors = datastoreOb.metadata['icon-color']
		colorStroke, colorFill = colors.split(",")
		rec.colorStroke = Color()
		rec.colorStroke.init_hex(colorStroke)
		rec.colorFill = Color()
		rec.colorFill.init_hex(colorFill)

		thumbPixbuf = None
		if (datastoreOb.metadata.has_key("preview")):
			try:
				thumb = datastoreOb.metadata['preview']
				if thumb[1:4] == 'PNG':
					pbl = GdkPixbuf.PixbufLoader()
					pbl.write(thumb)
					pbl.close()
					thumbPixbuf = pbl.get_pixbuf()
				else:
					thumbPixbuf = utils.getPixbufFromString(thumb)
			except:
				pass

		if (thumbPixbuf == None):
			#try to create the thumbnail yourself...
			if (rec.type == Constants.TYPE_PHOTO):
				try:
					#load in the image, make a thumbnail
					thumbPixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(rec.getFilepath(), 320, 240)
				except:
					pass

		if (thumbPixbuf == None):
			#i give up.  load in a blank image from the activity itself.
			thumbPath = os.path.join(self.ca.htmlPath, "1.jpg")
			thumbPixbuf = GdkPixbuf.Pixbuf.new_from_file(thumbPath)


		thumbFilepath = os.path.join(Instance.instancePath, "thumb.png")
		thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0)
		thumbPixbuf.save( thumbFilepath, "png", {} )
		rec.thumbFilename = os.path.basename(thumbFilepath)

		self.recs.append(rec)

		return rec