예제 #1
0
 def _img(self, src):
     p = _upfile_path(src, None)
     if p.startswith(('http://', 'https://', 'ftp://')):
         obj = urllib.urlopen(p)
         ct = obj.headers['Content-Type'].lower()
         if ct[:6] == 'image/' and ct[6:] in ('png', 'jpg', 'jpeg', 'gif', 'bmp', 'tif'):
             t = ct[6:]
             fname = TMPFILE_PREFIX + '.png'
             open(fname, 'w+').write(obj.read())
             if t != 'png':
                 im = Image.open(fname)
                 im = im.convert('RGB')
                 im.save(fname, 'png')
             return PyRTF.Image(fname)
     return PyRTF.Image(p)
예제 #2
0
 def write_image(self, image):
     try:
         i = PyRTF.Image(write_image_tempfile(image))
         self.recsection.append(i)
         self.add_paragraph(" ")
     except AttributeError:
         # If PyRTF has no attribute Image, this is an old version
         # and we can't do anything with images.
         pass
예제 #3
0
    def exportRtf(self):
        infoString = QtCore.QString("estrazione anagrafiche in word")
        reply = QtGui.QMessageBox.question(
            self, infoString, "Esportare solo le anagrafiche selezionate?",
            QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
            | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.No)
        if reply == QtGui.QMessageBox.Yes:
            selected = self.selectSome(self.ui.tabella.selectedItems())
        elif reply == QtGui.QMessageBox.No:
            selected = self.selectAll()
        else:
            return
        filexl = QFileDialog(self)
        #setto filexl in anymode cioe' ritorna il path del file anche se non esiste
        filexl.setFileMode(0)  #
        filexl.setNameFilter("word(*.doc *.rtf)")
        nfile = filexl.getSaveFileName(self,
                                       "esporta anagrafiche in word",
                                       "",
                                       filter="(*.doc *.rtf)")

        DR = rtf.Renderer()
        doc = rtf.Document()

        ss = doc.StyleSheet

        n = 0
        thin_edge = rtf.BorderPropertySet(width=20,
                                          style=rtf.BorderPropertySet.SINGLE)
        thick_edge = rtf.BorderPropertySet(width=80,
                                           style=rtf.BorderPropertySet.DOUBLE)
        mixed_frame = rtf.FramePropertySet(thin_edge, thick_edge, thin_edge,
                                           thick_edge)
        for i in enumerate(selected):
            section = rtf.Section()
            table = rtf.Table(rtf.TabPropertySet.DEFAULT_WIDTH * 7,
                              rtf.TabPropertySet.DEFAULT_WIDTH * 3)

            #section.append(table)
            img = rtf.Image("pictures/logo.jpg")
            c1 = rtf.Cell(rtf.Paragraph(img))
            c2 = rtf.Cell(
                rtf.Paragraph(
                    ss.ParagraphStyles.Heading2,
                    "Scheda anagrafica	{0}".format(self.activeDb.getNameDb())))
            table.AddRow(c1, c2)
            section.Header.append(table)
            oggi = datetime.date.today()
            section.Footer.append(
                rtf.Paragraph(
                    ss.ParagraphStyles.Normal,
                    "® Copyright Marketing & Telematica mail: [email protected] Data Esportazione: {0}/{1}/{2}"
                    .format(oggi.day, oggi.month, oggi.year)))
            Id = i[1].data(1).toInt()[0]
            p = rtf.Paragraph(rtf.ParagraphPS().SetPageBreakBefore(True), '')
            section.append(p)
            doc = self.makeRtf(doc, section, Id, i[0] + 1, len((selected)))

        #doc=self.makeRtf(doc,section)
        ##print "scrivo",self.OpenFile( 'rtf/vero' )
        DR.Write(doc, self.OpenFile(nfile))