Esempio n. 1
0
        def GetData(self):
            if isinstance(self.node, conman.conman.ConNode):
                filename = self.node.content.filename
            
            elif isinstance(self.node, ims.contentpackage.Item):
                resource = ims.utils.getIMSResourceForIMSItem(appdata.currentPackage, self.node)
                filename = eclassutils.getEClassPageForIMSResource(resource)
                if not filename:
                    filename = resource.getFilename()
            
            filename = os.path.join(settings.ProjectDir, filename)
            
            if os.path.exists(filename):
                myfile = None
                myfile = utils.openFile(filename, 'r')
                
                #if myfile:
                myhtml = GetBodySoup(myfile)
                myfile.close()
                #else:
                #   myhtml = ""
            else:
                myhtml = ""

            self.data['content'] = myhtml
Esempio n. 2
0
        def ShowModal(self):
            if isinstance(self.node, conman.conman.ConNode):
                filename = self.node.content.filename
            
            elif isinstance(self.node, ims.contentpackage.Item):
                resource = ims.utils.getIMSResourceForIMSItem(appdata.currentPackage, self.node)
                filename = eclassutils.getEClassPageForIMSResource(resource)
                if not filename:
                    filename = resource.getFilename()

            self.filename = os.path.join(settings.ProjectDir, filename)
            if not os.path.exists(self.filename):
                global htmlpage
                file = utils.openFile(self.filename, "w")
                file.write(htmlpage)
                file.close()

            
            if False:
                size = wx.Display().ClientArea.Size
                size.x = size.x / 2
                size.y = size.y / 2
                print "size is %s" % size
                self.frame = EditorFrame(self.parent, self.filename, size=size)
                #self.frame.currentItem = self.currentItem
                self.frame.Show()
                self.frame.CentreOnScreen()
            else:
                guiutils.openInHTMLEditor(self.filename)
                
            return wx.ID_OK
Esempio n. 3
0
    def GetData(self):
        self.quiz = QuizPage()
        filename = ""

        self.content = ims.utils.getIMSResourceForIMSItem(appdata.currentPackage, self.node)
        filename = eclassutils.getEClassPageForIMSResource(self.content)
        if not filename:
            filename = self.content.getFilename()
        
        self.quiz.LoadPage(os.path.join(settings.ProjectDir, filename))

        self.data['content'] = u'<h1 align="center">%s</h1>' % self.node.title.text
        self.data['content'] += self._ItemsAsHTML()
        #self.data['credit'] = ""

        try:        
            #copy the correct/incorrect graphics if they don't exist
            if not os.path.exists(os.path.join(self.dir, "Graphics", "Quiz")):
                os.mkdir(os.path.join(self.dir, "Graphics", "Quiz"))
            
            CopyFiles(os.path.join(settings.AppDir, "plugins", "Quiz", "Files", "Graphics"), os.path.join(self.dir, "Graphics", "Quiz"), 1)

        except: 
            global log
            message = _("Could not copy Quiz files from %(directory)s to your EClass. Please check that you have enough hard disk space to write this file and that you have permission to write to the directory.") % {"directory":os.path.join(settings.AppDir, "plugins", "Quiz", "Files")}
            log.error(message)
            raise IOError, message
            return ""   
        return ""
Esempio n. 4
0
    def GeneralPanel(self): 
        mypanel = sc.SizedPanel(self.notebook, -1)
        mypanel.SetSizerType("form")
        
        name = ""
        description = ""
        keywords = ""
        filename = ""
        
        if isinstance(self.node, conman.conman.ConNode):
            name = self.content.metadata.name
            description = self.content.metadata.description
            keywords = self.content.metadata.keywords
            filename = self.content.filename
            
        elif isinstance(self.node, ims.contentpackage.Item):
            lang = appdata.projectLanguage
            
            name = self.node.title.text
            description = self.content.metadata.lom.general.description.getKeyOrEmptyString(lang)
            keywords = self.content.metadata.lom.general.keyword.getKeyOrEmptyString(lang)
            filename = eclassutils.getEClassPageForIMSResource(self.content)
            if not filename:
                filename = self.content.getFilename()
        
        wx.StaticText(mypanel, -1, _("Name"))
        self.txtTitle = wx.TextCtrl(mypanel, -1, name)
        self.txtTitle.SetSizerProp("expand", True)
        
        wx.StaticText(mypanel, -1, _("Description"))
        self.txtDescription = wx.TextCtrl(mypanel, -1, description, style=wx.TE_MULTILINE)
        self.txtDescription.SetSizerProp("expand", True)
        
        wx.StaticText(mypanel, -1, _("Keywords"))
        self.txtKeywords = wx.TextCtrl(mypanel, -1, keywords, size=wx.Size(160, -1))
        self.txtKeywords.SetSizerProp("expand", True)

        wx.StaticText(mypanel, -1, _("Page Content:"))
        self.txtExistingFile = picker.SelectBox(mypanel, filename)

        self.txtTitle.SetFocus()
        self.txtTitle.SetSelection(-1, -1)
  
        #wx.EVT_BUTTON(self.btnSelectFile, self.btnSelectFile.GetId(), self.btnSelectFileClicked)
        picker.EVT_FILE_SELECTED(self.txtExistingFile, self.btnSelectFileClicked)

        return mypanel
Esempio n. 5
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)
Esempio n. 6
0
    def Publish(self, parent=None, node=None, dir=None):
        """
        This function prepares the Page to be converted by putting variables into self.data
        and then calling ApplyTemplate to insert the data into the template.

        In many cases, the GetData function (and possibly the GetFilename function) will be 
        all that needs to be overridden in the plugin. 
        """
        self.parent = parent
        self.node = node
        self.dir = dir
        
        name = ""
        description = ""
        keywords = ""
        filename = ""
        
        if isinstance(self.node, conman.conman.ConNode):
            name = node.content.metadata.name
            description = node.content.description
            keywords = node.content.keywords
            filename = node.content.filename
            
        elif isinstance(self.node, ims.contentpackage.Item):
            lang = appdata.projectLanguage
            name = self.node.title.text
            resource = ims.utils.getIMSResourceForIMSItem(appdata.currentPackage, self.node)
            
            description = resource.metadata.lom.general.description.getKeyOrEmptyString(lang) 
            keywords = resource.metadata.lom.general.keyword.getKeyOrEmptyString(lang)
            filename = eclassutils.getEClassPageForIMSResource(resource)
            if not filename:
                filename = resource.getFilename()
        
        self.data['name'] = TextToXMLChar(name)
        self.data['description'] = TextToXMLAttr(description)
        self.data['keywords'] = TextToXMLAttr(keywords)
        self.data['URL'] = self.GetFileLink(filename)
        self.data['SourceFile'] = filename
        filename = os.path.join(self.dir, "Text", filename)
        filename = self.GetFilename(filename)
        self.GetLinks()
        self.GetData()
        
        templatedir = os.path.join(settings.AppDir, "themes", themes.FindTheme(settings.ProjectSettings["Theme"]).themename)
        templatefile = os.path.join(templatedir, "default.meld")
        self.data['charset'] = self.GetConverterEncoding()

        myhtml = self.ApplyTemplate(templatefile, self.data)
        myhtml = self.EncodeHTMLToCharset(myhtml, "utf8") 

        try:        
            myfile = open(os.path.join(self.dir, "pub", os.path.basename(filename)), "wb")
            myfile.write(myhtml)
            myfile.close()
        except IOError: 
            message = "There was an error writing the file", filename + " to disk. Please check that you have enough hard disk space to write this file and that you have permission to write to the file."
            import traceback
            print `traceback.print_exc()`
            print `message`
            raise IOError, message
            return false
        except:
            raise
        return myhtml