Exemple #1
0
 def btnOKClicked(self, event):
     try:
         self.quiz.SaveAsXML(self.filename)
         self.EndModal(wx.ID_OK)
     except IOError:
         message = utils.getStdErrorMessage("IOError", {"filename":self.filename, "type":"write"})
         global log
         log.error(message)
         wx.MessageBox(message, _("Cannot Save File"), wxICON_ERROR)
Exemple #2
0
    def SaveAsXML(self, filename="", encoding="ISO-8859-1"):
        """
        Function: SaveAsXML(filename)
        Last Updated: 9/24/02
        Description: Saves the Quiz to an XML file.

        Arguments:
        - filename: filename, including directory, of the XML file to save - if no value given, defaults to the filename used when loading the page

        Return values:
        Returns an error string if failed, or an empty string if successful.
        """
        global log
            
        if filename == "":
            filename = self.filename
        else:
            self.filename = filename

        try:
            myxml = """<?xml version="1.0"?>%s""" % (self.WriteDoc())
        except:
            message = _("There was an error updating the file %(filename)s. Please check to make sure you did not enter any invalid characters (i.e. Russian, Chinese/Japanese, Arabic) and try updating again.") % {"filename":filename}
            log.error(message)
            raise IOError, message
        try:
            import types
            if type(myxml) != types.UnicodeType:
                import locale
                encoding = locale.getdefaultlocale()[1]
                myxml = unicode(myxml, encoding)
            
            myxml = myxml.encode("utf-8")
            
            myfile = utils.openFile(filename, "w")
            myfile.write(myxml)
            myfile.close()
        except:
            message = utils.getStdErrorMessage("IOError", {"type":"write", "filename": filename})
            log.error(message)
            raise IOError(message)

        return ""
Exemple #3
0
    def __init__(self, parent, item):
        self.quiz = QuizPage()
        self.item = item
        self.parent = parent

        sc.SizedDialog.__init__(self, parent, -1, _("Quiz Editor"), wx.Point(100, 100),
                                    style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
        pane = self.GetContentsPane()

        wx.StaticText(pane, -1, _("Question List"))
        self.lstQuestions = wx.ListBox(pane, -1)
        self.lstQuestions.SetSizerProps({"expand":True, "proportion":1})
        btnPane = sc.SizedPanel(pane, -1)
        btnPane.SetSizerType("horizontal")
        btnPane.SetSizerProp("halign", "center")
        
        self.btnAdd = wx.Button(btnPane, -1, _("Add"))
        self.btnEdit = wx.Button(btnPane, -1, _("Edit"))
        self.btnRemove = wx.Button(btnPane, -1, _("Remove"))
        
        filename = None
        if isinstance(self.item, conman.conman.ConMan):
            filename = self.node.content.filename
        else:
            self.content = ims.utils.getIMSResourceForIMSItem(appdata.currentPackage, self.item)
            filename = eclassutils.getEClassPageForIMSResource(self.content)
            if not filename:
                filename = self.content.getFilename()
                
        if filename: 
            self.filename = os.path.join(settings.ProjectDir, filename)
            try:
                self.quiz.LoadPage(self.filename)
            except IOError, msg:
                message = utils.getStdErrorMessage("IOError", {"type":"write", "filename": self.filename})
                global log
                log.error(message)
                wx.MessageBox(message, _("Unable to create file."), wxICON_ERROR)
                return

            for item in self.quiz.items:
                self.lstQuestions.Append(item.presentation.text, item)
Exemple #4
0
 def handleError(self):
     import traceback
     info = sys.exc_info()
     lines = traceback.format_exception(info[0], info[1], info[2])
     name = str(info[0])
     print name
     message = ""
     if name.find("IOError") != -1:
         message = utils.getStdErrorMessage(name, {"filename":info[1].filename})
     elif name.find("ftplib") != -1:
         message = self.getFtpErrorMessage(info[1])
     elif name.find("socket") != -1:
         errortext = str(info[1])
         print "Type is: " + `type(info[1])`
         if len(info[1]) == 2:
             errortext = info[1][1]
         message = _("Socket Error: ") + errortext 
     else:
         message = str(info[1])
     
     wx.MessageBox(`message`)
     self.parent.log.error(`message`)
     self.ftpService.close()
     self.OnUploadCanceled()
Exemple #5
0
    def Publish(self):
        global log
        self.pdfdir = self.dir
        if os.path.exists(self.tempdir):
            try:
                shutil.rmtree(self.tempdir)
            except:
                log.error(_("Could not remove directory '%(dir)s'.") % {"dir": self.tempdir})

        try:
            if isinstance(self.parent, wx.Frame):
                self.progress = wx.ProgressDialog("Publishing PDF", "Publishing PDF", 
                              self.parent.projectTree.GetCount() + 1, None, 
                              wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_CAN_ABORT)
            self.counter = 1
            self.PublishPages(appdata.currentPackage.organizations[0].items[0])
        except:
            if self.progress:
                self.progress.Destroy()
            raise
          
        #self.myfile.close()
        lang = appdata.projectLanguage
        self.pdffile = os.path.join(self.pdfdir, MakeFileName2(appdata.currentPackage.metadata.lom.general.title[lang] + ".pdf"))
        bookfile = "#HTMLDOC\n"
        pdffile = self.pdffile
        if sys.platform == "win32":
            pdffile = string.replace(self.pdffile, "\\", "/")
        bookfile = bookfile + "-f \"" + pdffile + "\" -t pdf --no-toc --no-links --compression=9 --jpeg=90 --verbose\n" 
        for afile in self.files:
            if afile != "" and os.path.exists(afile):
                if sys.platform == "win32":
                    afile = afile.replace("\\", "/")
                bookfile = bookfile + afile + "\n"

        handle, bookpath = tempfile.mkstemp() #os.path.join(self.tempdir, "eclass.book")
        os.close(handle)
        
        try:
            book = utils.openFile(bookpath, "w")
            book.write(bookfile)
            book.close()
            os.rename(bookpath, bookpath + ".book")
        except:
            message = utils.getStdErrorMessage("IOError", {"type":"write", "filename":bookpath})
            log.error(message)
            return False
        
        if sys.platform == "win32":
            htmldoc = os.path.join(settings.ThirdPartyDir, "htmldoc", "htmldoc.exe")
        else:
            htmldoc = os.path.join(settings.ThirdPartyDir, "htmldoc", "bin", "htmldoc")

        try:
            datadir = os.path.dirname(htmldoc)
            if sys.platform == "win32":
                # use quotes to avoid issues with spaces in filenames
                htmldoc = '"' + htmldoc + '"'
                datadir = '"' + datadir + '"'
                bookpath = '"' + bookpath + '"' 
            else:
                bookpath = bookpath.replace(" ", "\\ ")
                datadir = datadir.replace(" ", "\\ ")
                
            #print 'Command is: ' + htmldoc + ' --datadir %s --batch %s' % (datadir, bookpath)
            command = htmldoc + " --datadir %s --batch %s" % (datadir, bookpath)
            result = wx.Execute(command, wx.EXEC_SYNC)
            if result == -1:
                message = _("Could not execute command '%(command)s'.") % {"command": command}
                log.error(message)
                wx.MessageBox(message)
        except:
            message = _("Could not publish PDF File.")
            log.error(message)
            if isinstance(self.parent, wx.Frame):
                wx.MessageBox(message  + constants.errorInfoMsg)
            self.cancelled = True
    
        if self.progress:
            self.progress.Destroy()

        return not self.cancelled