예제 #1
0
    def PublishPages(self, node):
        page = ""
        if self.cancelled:
            return
        keepgoing = True #assuming no dialog to cancel, this must always be the case
        if self.progress:
            keepgoing = self.progress.Update(self.counter, _("Updating page %(page)s") % {"page":node.title.text})
        if not keepgoing:
            result = wx.MessageDialog(self.parent, "Are you sure you want to cancel publishing this EClass?", "Cancel Publishing?", wx.YES_NO).ShowModal()
            if result == wx.ID_NO:
                self.cancelled = False
                self.progress.Resume()
            else:
                self.cancelled = true
                return
        self.counter = self.counter + 1

        if node != None:
            filename = eclassutils.getEditableFileForIMSItem(self.parent.imscp, node)
            publisher = plugins.GetPublisherForFilename(filename)
            if publisher:
                publisher.Publish(self.parent, node, settings.ProjectDir)
            
        if len(node.items) > 0:
            for child in node.items:
                self.PublishPages(child)
예제 #2
0
    def PublishPages(self, node):
        page = ""
        if self.cancelled:
            return
        keepgoing = True #assuming no dialog to cancel, this must always be the case
        if self.progress:
            keepgoing = self.progress.Update(self.counter, _("Updating ") + node.title.text)
        if not keepgoing:
            result = wx.MessageDialog(self.parent, _("Are you sure you want to cancel publishing this EClass?"), 
                                       _("Cancel Publishing?"), wx.YES_NO).ShowModal()
            if result == wx.ID_NO:
                self.cancelled = False
                self.progress.Resume()
            else:
                self.cancelled = True
                return
        self.counter = self.counter + 1
      
        filename = eclassutils.getEditableFileForIMSItem(appdata.currentPackage, node)
        publisher = plugins.GetPublisherForFilename(filename)
        
        if publisher:
            resource = ims.utils.getIMSResourceForIMSItem(appdata.currentPackage, node)
            if resource:
                filename = resource.getFilename()
            try:
                publisher.node = node
                publisher.data['name'] = TextToHTMLChar(node.title.text)
                publisher.GetData()
                templatefile = os.path.join(settings.AppDir, "convert", "PDF.tpl")
                publisher.data['charset'] = publisher.GetConverterEncoding()
                
                myhtml = publisher.ApplyTemplate(templatefile, publisher.data)
                
                myhtml = publisher.EncodeHTMLToCharset(myhtml, publisher.data['charset'])
                
                #myhtml = publisher.Publish(self.parent, node, self.dir)
                #myhtml = GetBody(StringIO(myhtml))
                #print "in PDF plugin, myhtml = " + myhtml[:100]
                if not myhtml == "":
                    myfile = utils.openFile(os.path.join(self.tempdir, filename), "w")
                    myfile.write(myhtml)
                    myfile.close()
                    self.files.append(os.path.join(self.tempdir, filename))
            except:
                message = _("Could not publish page '%(page)s'") % {"page": os.path.join(self.tempdir, filename)}
                global log
                log.error(message)
                if "--debug" in sys.argv:
                    raise

        if len(node.items) > 0:
            for child in node.items:
                self.PublishPages(child)