class TurtleODP: def __init__(self): self.doc = None self.path = None self.width = 0 self.height = 0 def create_presentation(self, path, width, height): self.path = path self.width = width self.height = height # Create memory Open Document Presentation in memory self.doc = OpenDocumentPresentation() pagelayout = PageLayout(name='MyLayout') self.doc.automaticstyles.addElement(pagelayout) # Define the basic measures of a page of the presentation pagelayout.addElement( PageLayoutProperties(margin='0pt', pagewidth='%fpt' % width, pageheight='%fpt' % height, printorientation='landscape')) self.photostyle = Style(name='MyMaster-photo', family='presentation') self.doc.styles.addElement(self.photostyle) self.masterpage = MasterPage(name='MyMaster', pagelayoutname=pagelayout) self.doc.masterstyles.addElement(self.masterpage) def add_image(self, path): page = Page(masterpagename=self.masterpage) photoframe = Frame(stylename=self.photostyle, width='%fpt' % self.width, height='%fpt' % self.height, x='0pt', y='0pt') self.doc.presentation.addElement(page) page.addElement(photoframe) href = self.doc.addPicture(path) photoframe.addElement(Image(href=href)) #print 'added image successfully' def save_presentation(self): #print self.path self.doc.save(self.path) #print 'presentation saved successfully' def get_output_path(self): return self.path
class TurtleODP: def __init__(self): self.doc = None self.path = None self.width = 0 self.height = 0 def create_presentation(self, path, width, height): self.path = path self.width = width self.height = height # Create memory Open Document Presentation in memory self.doc = OpenDocumentPresentation() pagelayout = PageLayout(name='MyLayout') self.doc.automaticstyles.addElement(pagelayout) # Define the basic measures of a page of the presentation pagelayout.addElement(PageLayoutProperties( margin='0pt', pagewidth='%fpt' % width, pageheight='%fpt' % height, printorientation='landscape')) self.photostyle = Style(name='MyMaster-photo', family='presentation') self.doc.styles.addElement(self.photostyle) self.masterpage = MasterPage(name='MyMaster', pagelayoutname=pagelayout) self.doc.masterstyles.addElement(self.masterpage) def add_image(self, path): page = Page(masterpagename=self.masterpage) photoframe = Frame( stylename=self.photostyle, width='%fpt' % self.width, height='%fpt' % self.height, x='0pt', y='0pt') self.doc.presentation.addElement(page) page.addElement(photoframe) href = self.doc.addPicture(path) photoframe.addElement(Image(href=href)) # print 'added image successfully' def save_presentation(self): # print self.path self.doc.save(self.path) # print 'presentation saved successfully' def get_output_path(self): return self.path
if w > 720: h = float(h) * 720.0 / float(w) w = 720.0 if h > 540.0: w = float(w) * 540.0 / float(h) h = 540.0 page = Page(stylename=dpstyle, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement(P(text=picture)) offsetx = 400.0 - w / 2.0 photoframe = Frame(stylename=photostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="56pt") page.addElement(photoframe) href = doc.addPicture(pict_dir + "/" + picture) photoframe.addElement(Image(href=href)) doc.save(outputfile)
def do_job(job): """Do something""" warnings = get_warnings(job['sts'], job['ets'], job['wfo'], job['wtype']) mydir = "%s/%s" % (TMPDIR, job['jobid']) if not os.path.isdir(mydir): os.makedirs(mydir) os.chdir(mydir) basefn = "%s-%s-%s-%s-%s" % (job['wfo'], job['wtype'].replace( ",", "_"), job['radar'], job['sts'].strftime("%Y%m%d%H"), job['ets'].strftime("%Y%m%d%H")) outputfile = "%s.odp" % (basefn, ) doc = OpenDocumentPresentation() # We must describe the dimensions of the page pagelayout = PageLayout(name="MyLayout") doc.automaticstyles.addElement(pagelayout) pagelayout.addElement( PageLayoutProperties(margin="0pt", pagewidth="800pt", pageheight="600pt", printorientation="landscape")) # Style for the title frame of the page # We set a centered 34pt font with yellowish background titlestyle = Style(name="MyMaster-title2", family="presentation") titlestyle.addElement(ParagraphProperties(textalign="center")) titlestyle.addElement(TextProperties(fontsize="34pt")) titlestyle.addElement(GraphicProperties(fillcolor="#ffff99")) doc.styles.addElement(titlestyle) # Style for the title frame of the page # We set a centered 34pt font with yellowish background indexstyle = Style(name="MyMaster-title", family="presentation") indexstyle.addElement(ParagraphProperties(textalign="center")) indexstyle.addElement(TextProperties(fontsize="28pt")) indexstyle.addElement(GraphicProperties(fillcolor="#ffffff", stroke="none")) doc.styles.addElement(indexstyle) # Style for the photo frame photostyle = Style(name="MyMaster-photo", family="presentation") doc.styles.addElement(photostyle) # Every drawing page must have a master page assigned to it. masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout) doc.masterstyles.addElement(masterpage) dpstyle = Style(name="dp1", family="drawing-page") # dpstyle.addElement(DrawingPageProperties(transitiontype="automatic", # transitionstyle="move-from-top", duration="PT5S")) doc.automaticstyles.addElement(dpstyle) # Title slide page = Page(masterpagename=masterpage) doc.presentation.addElement(page) frame = Frame(stylename=indexstyle, width="720pt", height="500pt", x="40pt", y="10pt") page.addElement(frame) textbox = TextBox() frame.addElement(textbox) textbox.addElement(P(text="IEM Raccoon Report")) frame = Frame(stylename=indexstyle, width="720pt", height="500pt", x="40pt", y="150pt") page.addElement(frame) textbox = TextBox() frame.addElement(textbox) textbox.addElement(P(text="WFO: %s" % (job['wfo'], ))) textbox.addElement( P(text=("Radar: %s Product: %s" "") % (job['radar'], job['nexrad_product']))) textbox.addElement(P(text="Phenomenas: %s" % (job['wtype'], ))) textbox.addElement( P(text="Start Time: %s UTC" % (job['sts'].strftime("%d %b %Y %H"), ))) textbox.addElement( P(text="End Time: %s UTC" % (job['ets'].strftime("%d %b %Y %H"), ))) textbox.addElement(P(text="")) textbox.addElement(P(text="Raccoon Version: %s" % (__REV__, ))) textbox.addElement( P(text="Generated on: %s" % (datetime.datetime.utcnow().strftime("%d %b %Y %H:%M %Z")))) textbox.addElement(P(text="")) textbox.addElement( P(text="Bugs/Comments/Yelling?: daryl herzmann [email protected]")) i = 0 for warning in warnings: # Make Index page for the warning page = Page(masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=indexstyle, width="700pt", height="500pt", x="10pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement( P(text="%s.O.NEW.K%s.%s.W.%04i" % (job['sts'].year, job['wfo'], warning['phenomena'], warning['eventid']))) textbox.addElement( P(text="Issue: %s UTC" % (warning['issue'].strftime("%d %b %Y %H:%M"), ))) textbox.addElement( P(text="Expire: %s UTC" % (warning['expire'].strftime("%d %b %Y %H:%M"), ))) textbox.addElement( P(text="Poly Area: %.1f sq km (%.1f sq mi) [%.1f%% vs County]" % (warning['polyarea'], warning['polyarea'] * 0.386102, warning['polyarea'] / warning['countyarea'] * 100.0))) textbox.addElement( P(text="County Area: %.1f square km (%.1f square miles)" % (warning['countyarea'], warning['countyarea'] * 0.386102))) url = ("http://iem.local/GIS/radmap.php?" "layers[]=places&layers[]=legend&layers[]=ci&layers[]=cbw" "&layers[]=sbw&layers[]=uscounties&layers[]=bufferedlsr" "&lsrbuffer=15") url += "&vtec=%s.O.NEW.K%s.%s.W.%04i" % (job['sts'].year, job['wfo'], warning['phenomena'], warning['eventid']) cmd = "wget -q -O %i.png '%s'" % (i, url) os.system(cmd) photoframe = Frame(stylename=photostyle, width="480pt", height="360pt", x="160pt", y="200pt") page.addElement(photoframe) href = doc.addPicture("%i.png" % (i, )) photoframe.addElement(Image(href=href)) i += 1 times = [] now = warning['issue'] while now < warning['expire']: times.append(now) now += datetime.timedelta(minutes=15) times.append(warning['expire'] - datetime.timedelta(minutes=1)) for now in times: page = Page(stylename=dpstyle, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement( P(text="%s.W.%04i Time: %s UTC" % (warning['phenomena'], warning['eventid'], now.strftime("%d %b %Y %H%M")))) if job['nexrad_product'] == 'N0U': if now < SUPER_RES: n0qn0r = 'N0V' else: n0qn0r = 'N0U' else: if now < SUPER_RES: n0qn0r = 'N0R' else: n0qn0r = 'N0Q' url = "http://iem.local/GIS/radmap.php?" url += "layers[]=ridge&ridge_product=%s&ridge_radar=%s&" % ( n0qn0r, job['radar']) url += "layers[]=sbw&layers[]=sbwh&layers[]=uscounties&" url += "layers[]=lsrs&ts2=%s&" % (( now + datetime.timedelta(minutes=15)).strftime("%Y%m%d%H%M"), ) url += "vtec=%s.O.NEW.K%s.%s.W.%04i&ts=%s" % ( job['sts'].year, job['wfo'], warning['phenomena'], warning['eventid'], now.strftime("%Y%m%d%H%M")) cmd = "wget -q -O %i.png '%s'" % (i, url) os.system(cmd) photoframe = Frame(stylename=photostyle, width="640pt", height="480pt", x="80pt", y="70pt") page.addElement(photoframe) href = doc.addPicture("%i.png" % (i, )) photoframe.addElement(Image(href=href)) i += 1 doc.save(outputfile) del doc cmd = "unoconv -f ppt %s" % (outputfile, ) subprocess.call(cmd, shell=True) pptfn = "%s.ppt" % (basefn, ) print("Generated %s with %s slides" % (pptfn, i)) if os.path.isfile(pptfn): print('...copied to webfolder') shutil.copyfile(pptfn, "/mesonet/share/pickup/raccoon/%s" % (pptfn, )) # Cleanup os.chdir(TMPDIR) subprocess.call("rm -rf %s" % (job['jobid'], ), shell=True) else: print("Uh oh, no output file, lets kill soffice.bin") subprocess.call("pkill --signal 9 soffice.bin", shell=True) add_job(job)
def do_job(job): warnings = get_warnings(job['sts'], job['ets'], job['wfo'], job['wtype']) os.makedirs("/tmp/%s" % (job['jobid'],)) os.chdir("/tmp/%s" % (job['jobid'],)) basefn = "%s-%s-%s-%s-%s" % (job['wfo'], job['wtype'].replace(",", "_"), job['radar'], job['sts'].strftime("%Y%m%d%H"), job['ets'].strftime("%Y%m%d%H")) outputfile = "%s.odp" % (basefn,) doc = OpenDocumentPresentation() # We must describe the dimensions of the page pagelayout = PageLayout(name="MyLayout") doc.automaticstyles.addElement(pagelayout) pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt", pageheight="600pt", printorientation="landscape")) # Style for the title frame of the page # We set a centered 34pt font with yellowish background titlestyle = Style(name="MyMaster-title2", family="presentation") titlestyle.addElement(ParagraphProperties(textalign="center")) titlestyle.addElement(TextProperties(fontsize="34pt")) titlestyle.addElement(GraphicProperties(fillcolor="#ffff99")) doc.styles.addElement(titlestyle) # Style for the title frame of the page # We set a centered 34pt font with yellowish background indexstyle = Style(name="MyMaster-title", family="presentation") indexstyle.addElement(ParagraphProperties(textalign="center")) indexstyle.addElement(TextProperties(fontsize="28pt")) indexstyle.addElement(GraphicProperties(fillcolor="#ffffff", stroke="none")) doc.styles.addElement(indexstyle) # Style for the photo frame photostyle = Style(name="MyMaster-photo", family="presentation") doc.styles.addElement(photostyle) # Every drawing page must have a master page assigned to it. masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout) doc.masterstyles.addElement(masterpage) dpstyle = Style(name="dp1", family="drawing-page") #dpstyle.addElement(DrawingPageProperties(transitiontype="automatic", # transitionstyle="move-from-top", duration="PT5S")) doc.automaticstyles.addElement(dpstyle) # Title slide page = Page(masterpagename=masterpage) doc.presentation.addElement(page) frame = Frame(stylename=indexstyle, width="720pt", height="500pt", x="40pt", y="10pt") page.addElement( frame ) textbox = TextBox() frame.addElement(textbox) textbox.addElement(P(text="IEM Raccoon Report")) frame = Frame(stylename=indexstyle, width="720pt", height="500pt", x="40pt", y="150pt") page.addElement( frame ) textbox = TextBox() frame.addElement(textbox) textbox.addElement(P(text="WFO: %s" % (job['wfo'],))) textbox.addElement(P(text="Radar: %s Product: %s" % (job['radar'], job['nexrad_product']))) textbox.addElement(P(text="Phenomenas: %s" % (job['wtype'], ))) textbox.addElement(P(text="Start Time: %s UTC" % (job['sts'].strftime("%d %b %Y %H"),))) textbox.addElement(P(text="End Time: %s UTC" % (job['ets'].strftime("%d %b %Y %H"),))) textbox.addElement(P(text="")) textbox.addElement(P(text="Raccoon Version: %s" % (__REV__,))) textbox.addElement(P(text="Generated on: %s" % ( datetime.datetime.utcnow().strftime("%d %b %Y %H:%M %Z")))) textbox.addElement(P(text="")) textbox.addElement(P(text="Bugs/Comments/Yelling?: daryl herzmann [email protected]")) i = 0 for warning in warnings: # Make Index page for the warning page = Page(masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=indexstyle, width="700pt", height="500pt", x="10pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement(P(text="%s.O.NEW.K%s.%s.W.%04i" % ( job['sts'].year, job['wfo'], warning['phenomena'],warning['eventid']))) textbox.addElement(P(text="Issue: %s UTC" % ( warning['issue'].strftime("%d %b %Y %H:%M"),))) textbox.addElement(P(text="Expire: %s UTC" % ( warning['expire'].strftime("%d %b %Y %H:%M"),))) textbox.addElement(P(text="Poly Area: %.1f sq km (%.1f sq mi) [%.1f%% vs County]" % ( warning['polyarea'], warning['polyarea'] * 0.386102, warning['polyarea'] / warning['countyarea'] * 100.0))) textbox.addElement(P(text="County Area: %.1f square km (%.1f square miles)" % ( warning['countyarea'], warning['countyarea'] * 0.386102))) url = "http://iem21.local/GIS/radmap.php?" url += "layers[]=places&layers[]=legend&layers[]=ci&layers[]=cbw&layers[]=sbw" url += "&layers[]=uscounties&layers[]=bufferedlsr&lsrbuffer=15" url += "&vtec=%s.O.NEW.K%s.%s.W.%04i" % ( job['sts'].year, job['wfo'], warning['phenomena'],warning['eventid']) cmd = "wget -q -O %i.png '%s'" % (i, url) os.system(cmd) photoframe = Frame(stylename=photostyle, width="480pt", height="360pt", x="160pt", y="200pt") page.addElement(photoframe) href = doc.addPicture("%i.png" % (i,)) photoframe.addElement(Image(href=href)) i += 1 times = [] now = warning['issue'] while now < warning['expire']: times.append( now ) now += datetime.timedelta(minutes=15) times.append( warning['expire'] - datetime.timedelta(minutes=1)) for now in times: page = Page(stylename=dpstyle, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement(P(text="%s.W.%04i Time: %s UTC" % ( warning['phenomena'],warning['eventid'], now.strftime("%d %b %Y %H%M")))) if job['nexrad_product'] == 'N0U': if now < SUPER_RES: n0qn0r = 'N0V' else: n0qn0r = 'N0U' else: if now < SUPER_RES: n0qn0r = 'N0R' else: n0qn0r = 'N0Q' url = "http://iem21.local/GIS/radmap.php?" url += "layers[]=ridge&ridge_product=%s&ridge_radar=%s&" % (n0qn0r, job['radar']) url += "layers[]=sbw&layers[]=sbwh&layers[]=uscounties&" url += "layers[]=lsrs&ts2=%s&" % ( (now + datetime.timedelta(minutes=15)).strftime("%Y%m%d%H%M"),) url += "vtec=%s.O.NEW.K%s.%s.W.%04i&ts=%s" % ( job['sts'].year, job['wfo'], warning['phenomena'],warning['eventid'], now.strftime("%Y%m%d%H%M")) cmd = "wget -q -O %i.png '%s'" % (i, url) os.system(cmd) photoframe = Frame(stylename=photostyle, width="640pt", height="480pt", x="80pt", y="70pt") page.addElement(photoframe) href = doc.addPicture("%i.png" % (i,)) photoframe.addElement(Image(href=href)) i += 1 doc.save(outputfile) del doc cmd = "unoconv -f ppt %s" % (outputfile,) os.system( cmd ) print "%s.ppt" % (basefn,) if os.path.isfile("%s.ppt" % (basefn,)): print 'Here!' shutil.copyfile("%s.ppt" % (basefn,), "/mesonet/share/pickup/raccoon/%s.ppt" % (basefn,))
def export_presentation(photos, destination, openafter=False): if destination[-4:] != ".odp": destination += ".odp" doc = OpenDocumentPresentation() # We must describe the dimensions of the page pagelayout = PageLayout(name="Layout") doc.automaticstyles.addElement(pagelayout) pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt", pageheight="600pt", printorientation="landscape")) # Style for the title frame of the page # We set a centered 34pt font with yellowish background titlestyle = Style(name="Master-title", family="presentation") titlestyle.addElement(ParagraphProperties(textalign="center")) titlestyle.addElement(TextProperties(fontsize="34pt")) titlestyle.addElement(GraphicProperties(fillcolor="#ffffff")) doc.styles.addElement(titlestyle) # Style for the photo frame photostyle = Style(name="Master-photo", family="presentation") doc.styles.addElement(photostyle) # Create automatic transition dpstyle = Style(name="dp1", family="drawing-page") # dpstyle.addElement(DrawingPageProperties(transitiontype="automatic", transitionstyle="move-from-top", duration="PT5S")) doc.automaticstyles.addElement(dpstyle) # Every drawing page must have a master page assigned to it. masterpage = MasterPage(name="Master", pagelayoutname=pagelayout) doc.masterstyles.addElement(masterpage) for p in photos: path = p.getData() image = QImage(path) if(image.isNull()): continue w = image.width() h = image.height() if w > 720: h = float(h) * 720.0 / float(w) w = 720.0 if h > 540.0: w = float(w) * 540.0 / float(h) h = 540.0 page = Page(stylename=dpstyle, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement(P(text=p.name)) offsetx = 400.0 - w/2.0 photoframe = Frame(stylename=photostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="56pt") page.addElement(photoframe) href = doc.addPicture(path) photoframe.addElement(Image(href=href)) os.remove(destination) doc.save(destination) if sys.platform.startswith('darwin'): subprocess.call(('open', destination)) elif os.name == 'nt': os.startfile(destination) elif os.name == 'posix': subprocess.call(('xdg-open', destination))
def process_user_image_files(emailaddr): pagewidth = 800 pageheight = 600 logging.debug("cur_path %s" % (os.path.realpath('.'),) ) odpfile = 'frieda_%s_%s.odp' % (emailaddr, time.strftime('%b_%d_%Y_%I%M%P')) ppt_content = [] file_list = [] for wroot, wsubdir, wfiles in os.walk('.'): wfiles = sort_files_by_time(wfiles, wroot) wsubdir = sort_files_by_time(wsubdir, wroot) cnt = 0 for f in wfiles: cnt += 1 file_list.append(os.path.join(wroot, f)) if cnt != 0: wroot2 = '/' if len(wroot) < 2 else wroot[1:] ppt_content.append((wroot2, cnt)) logging.debug('file_list: %r' % file_list) doc = OpenDocumentPresentation() pagelayout = PageLayout(name="MyLayout") pagelayout.addElement(PageLayoutProperties(backgroundcolor="#000000", margin="0pt", pagewidth="%dpt" %pagewidth, pageheight="%dpt" % pageheight, printorientation="landscape")) doc.automaticstyles.addElement(pagelayout) photostyle = Style(name="RadTeaching-photo", family="presentation") doc.styles.addElement(photostyle) dstyle = Style(name="d", family="drawing-page") dstyle.addElement(GraphicProperties(fillcolor="#000000")) dstyle.addElement(DrawingPageProperties(fill=True, fillcolor="#000000")) doc.automaticstyles.addElement(dstyle) masterpage = MasterPage(name="RadTeaching", pagelayoutname=pagelayout) doc.masterstyles.addElement(masterpage) images_added = 0 # os.chdir(subdir) for picture in file_list: try: pictdata = open(picture).read() logging.debug("Adding %s" % (picture)) except: logging.debug("Skipping %s" % (picture)) continue ct,w,h = getImageInfoFileName(picture) if ct == 'not image': if picture[-4:] == '.dcm': png_picture = picture.replace('.dcm','.png') logging.debug("Converting %s to %s" % (picture, png_picture) ) run_command(""" dcmj2pnm +on +Wi 1 %s %s """ % (picture, png_picture)) picture = png_picture ct,w,h = getImageInfoFileName(picture) if ct not in ("jpeg", "jpg", "tiff", "png", "bmp", "gif", "tif"): logging.debug("Skipping %s unrecognized type %s" % (picture,ct) ) continue if ct == "tiff" or ct == "tif": png_picture = picture.replace(".tiff",".tif").replace(".tif", ".png") logging.debug("Converting %s to %s" % (picture, png_picture)) img = PythonMagick.Image() img.read(picture) if img.depth() > 8: # powerpoint can't handle 16 bit TIFF images. img.write(png_picture) del img picture = png_picture ct,w,h = getImageInfoFileName(picture) images_added += 1 if w*pageheight > h*pagewidth: #check if width or height is limit to zooming h = float(h) * (pagewidth-2.0)/float(w) w = pagewidth - 2.0 else: w = float(w)*(pageheight-2.0) / float(h) h = pageheight -2.0 page = Page(stylename=dstyle, masterpagename=masterpage) doc.presentation.addElement(page) offsetx = (pagewidth - w)/2.0 offsety = (pageheight - h)/2.0 photoframe = Frame(stylename=photostyle, width='%fpt' % w, height='%fpt' % h, x = '%fpt' % offsetx, y='%fpt' % offsety) page.addElement(photoframe) href = doc.addPicture(picture) photoframe.addElement(Image(href=href)) if images_added > 0: logging.debug('Saving ODP as %s/%s' % (os.path.realpath('.'), odpfile)) doc.save(odpfile) return (odpfile, images_added, ppt_content) if images_added > 0 else (False, 0, None)
def create_presentation(sura_number, outputfile, start=None, end=None, arabic_font="Calibri"): suras = load_suras("quran-uthmani.xml", "shakir_table.csv") doc = OpenDocumentPresentation() # We must describe the dimensions of the page pagelayout = PageLayout(name="MyLayout") dp = Style(name="dp1", family="drawing-page") dp.addElement(DrawingPageProperties(backgroundvisible="true", backgroundobjectsvisible="true")) doc.automaticstyles.addElement(pagelayout) doc.automaticstyles.addElement(dp) pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt", pageheight="600pt", printorientation="landscape", backgroundcolor="#000000")) ls = LayerSet() ls.addElement(Layer(name="layout")) ls.addElement(Layer(name="background")) ls.addElement(Layer(name="backgroundobjects")) ls.addElement(Layer(name="title")) doc.masterstyles.addElement(ls) titlestyle = Style(name="MyMaster-title", family="presentation") titlestyle.addElement(ParagraphProperties(textalign="center")) titlestyle.addElement(TextProperties(fontsize="60pt", fontsizeasian="96pt", fontsizecomplex="96pt", color="#ffffff", fontfamily="Calibri", fontfamilyasian=arabic_font, fontfamilycomplex=arabic_font)) titlestyle.addElement(GraphicProperties(fillcolor="#000000")) doc.styles.addElement(titlestyle) masterstyle = Style(name="MyMaster-dp", family="drawing-page") masterstyle.addElement(DrawingPageProperties(fill="solid", fillcolor="#000000", backgroundsize="border", fillimagewidth="0cm", fillimageheight="0cm")) doc.styles.addElement(masterstyle) # Every drawing page must have a master page assigned to it. masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout, stylename=masterstyle) doc.masterstyles.addElement(masterpage) # add title page page = Page(stylename=dp, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="800pt", height="300pt", x="0pt", y="200pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) titletext = "Sura %s" % (SURA_NAMES[sura_number],) if start: titletext += "\nAyat %s to %s" % (start, end) textbox.addElement(P(stylename=titlestyle, text=titletext)) if sura_number != 9 and not (sura_number == 1 and (start is None or int(start) == 1)): # add bismillah page = Page(stylename=dp, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="30pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) ayat = suras[1][1] textbox.addElement(P(stylename=titlestyle, text=ayat["arabic"])) secondframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="300pt") page.addElement(secondframe) secondbox = TextBox() secondframe.addElement(secondbox) secondbox.addElement(P(stylename=titlestyle, text=ayat["english"])) for number, ayat in suras[sura_number].iteritems(): if start is None or (number >= int(start) and number <= int(end)): page = Page(stylename=dp, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="30pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement(P(stylename=titlestyle, text=ayat["arabic"])) secondframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="300pt") page.addElement(secondframe) secondbox = TextBox() secondframe.addElement(secondbox) secondbox.addElement(P(stylename=titlestyle, text=ayat["english"])) doc.save(outputfile)
doc.presentation.addElement(page) note = Notes(stylename=dpstyle) page.addElement(note) noteframe = Frame(stylename=prstyle, layer="layout", width="16.799cm", height="13.364cm", x="2.1cm", y="14.107cm", placeholder="true", classname="notes") note.addElement(noteframe) notetextbox = TextBox() notetextbox.addElement(P(text=notes[i] if (i in notes) else "")) noteframe.addElement(notetextbox) photoframe = Frame(stylename=photostyle, width=str(w) + "pt", height=str(h) + "pt", x="0pt", y="0pt") page.addElement(photoframe) href = doc.addPicture(fname) photoframe.addElement(Image(href=href)) i += 1 doc.save(args["<output>"]) shutil.rmtree(pict_dir)
def odpRender(dic_slides_odp, nomePrj): lista_slides = dic_slides_odp.keys() lista_slides.sort() manualODP = OpenDocumentPresentation() # We must describe the dimensions of the page pagelayout = PageLayout(name="MyLayout") manualODP.automaticstyles.addElement(pagelayout) pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt", pageheight="600pt", printorientation="landscape")) # Style for the title frame of the page # We set a centered 34pt font with yellowish background titlestyle = Style(name="MyMaster-title", family="presentation") titlestyle.addElement(ParagraphProperties(textalign="center")) titlestyle.addElement(TextProperties(fontsize="42pt")) titlestyle.addElement(GraphicProperties(fillcolor="#ffffff", stroke="none")) manualODP.styles.addElement(titlestyle) # Style for the text frame of the page textostyle = Style(name="standard", family="graphic") textostyle.addElement(ParagraphProperties(textalign="left")) textostyle.addElement(TextProperties(attributes={"fontsize":"24pt" })) textostyle.addElement(GraphicProperties(fillcolor="#ffffff", stroke="none")) manualODP.styles.addElement(textostyle) # Style for the photo frame photostyle = Style(name="MyMaster-photo", family="presentation") manualODP.styles.addElement(photostyle) # Create automatic transition dpstyle = Style(name="dp1", family="drawing-page") dpstyle.addElement(DrawingPageProperties(transitiontype="automatic", transitionstyle="move-from-top", duration="PT2S")) manualODP.automaticstyles.addElement(dpstyle) # Every drawing page must have a master page assigned to it. masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout) manualODP.masterstyles.addElement(masterpage) pict_dir = "./%s/img" % nomePrj altura_h = 540 largura_w = 720 base_X = 40 base_Y = 70 corr_Y = 60 for x in lista_slides[1:]: titulo = dic_slides_odp[x]["titulo"] lista_conteudo = dic_slides_odp[x]['conteudo'].keys() lista_conteudo.sort() page = Page(stylename=dpstyle, masterpagename=masterpage) manualODP.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="720pt", height="80pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement(P(text=titulo)) w = largura_w h = altura_h - base_Y offsetx = base_X offsety = base_Y espacamento_lin = 20 for num in lista_conteudo: if dic_slides_odp[x]['conteudo'][num]['tipo'] == 'par': if w == 355: offsety = offsety + espacamento_lin texto_capitulo = dic_slides_odp[x]['conteudo'][num]['valor'] textoSlide = Frame(stylename=textostyle, width="%fpt" % w, height="%fpt" % h , x="%fpt" % offsetx, y="%fpt" % offsety) page.addElement(textoSlide) textbox = TextBox() textoSlide.addElement(textbox) textbox.addElement(P(text=texto_capitulo)) offsety = base_Y + offsety if dic_slides_odp[x]['conteudo'][num]['tipo'] == 'ite': texto_capitulo = " - " + dic_slides_odp[x]['conteudo'][num]['valor'] if w == 355: offsety = offsety + espacamento_lin textoSlide = Frame(stylename=textostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="%fpt" % offsety) page.addElement(textoSlide) textbox = TextBox() textoSlide.addElement(textbox) textbox.addElement(P(text=texto_capitulo)) offsety = base_Y + offsety if dic_slides_odp[x]['conteudo'][num]['tipo'] == 'img': picture = dic_slides_odp[x]['conteudo'][num]['valor'] estilo_picture = dic_slides_odp[x]['conteudo'][num]['estilo'] pictdata = open(pict_dir+'/'+picture).read() ct,w,h = getImageInfo(pictdata) # Get dimensions in pixels offsetx = base_X w = largura_w h = altura_h - offsety if estilo_picture == 'imagem_dir': offsetx = 400 w = 355 if estilo_picture == 'imagem_esq': offsetx = 40 w = 355 if estilo_picture == 'imagem_base': offsety = offsety + 10 photoframe = Frame(stylename=photostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="%fpt" % offsety) page.addElement(photoframe) href = manualODP.addPicture(pict_dir + "/" + picture) photoframe.addElement(Image(href=href)) # corrige para posicionar o texto que existe na página # observando se imagem_full ou não if estilo_picture <> 'imagem_base': if offsetx == 40 : offsetx = 400 else: offsetx = 40 offsety = base_Y + offsety manualODP.save("%s/t%s" % (nomePrj,nomePrj), True) return
def create_function(full_path): textdoc = OpenDocumentPresentation() textdoc.styles.addElement(self.build_default_style()) textdoc.save(full_path)
for picture in os.listdir(pict_dir): try: pictdata = open(pict_dir + "/" + picture).read() except: continue ct,w,h = getImageInfo(pictdata) # Get dimensions in pixels if ct != 'image/jpeg': continue if w > 720: h = float(h) * 720.0 / float(w) w = 720.0 if h > 540.0: w = float(w) * 540.0 / float(h) h = 540.0 page = Page(stylename=dpstyle, masterpagename=masterpage) doc.presentation.addElement(page) titleframe = Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = TextBox() titleframe.addElement(textbox) textbox.addElement(P(text=picture)) offsetx = 400.0 - w/2.0 photoframe = Frame(stylename=photostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="56pt") page.addElement(photoframe) href = doc.addPicture(pict_dir + "/" + picture) photoframe.addElement(Image(href=href)) doc.save(outputfile)