コード例 #1
0
    def currentItemChanged(self):
        item = self.lessonsTree.currentItem()
        if item:
            if hasattr(item, "lesson"):
                self.btnRemove.setText("Uninstall lesson")
                self.btnRemove.setEnabled(True)
                self.btnRunLesson.setEnabled(True)
                if os.path.exists(item.lesson.description):
                    with codecs.open(item.lesson.description, encoding="utf-8") as f:
                        html = "".join(f.readlines())
                        if item.lesson.description.endswith(".md"):
                            html = markdown.markdown(html)
                    self.webView.document().setMetaInformation(QTextDocument.DocumentUrl,
                                                               QUrl.fromUserInput(item.lesson.description).toString())
                    self.webView.setHtml(html)
                else:
                    self.webView.setHtml("<p>{}</p>".format(item.lesson.description))
            else:
                self.btnRunLesson.setEnabled(False)
                self.btnRemove.setText("Uninstall lessons group")
                self.btnRemove.setEnabled(True)
                if os.path.exists(item.description):
                    with codecs.open(item.description, encoding="utf-8") as f:
                        html = "".join(f.readlines())
                    if item.description.endswith(".md"):
                        html = markdown.markdown(html)
                    self.webView.document().setMetaInformation(QTextDocument.DocumentUrl,
                                                               QUrl.fromUserInput(item.description).toString())
                else:
                    html = item.description
                self.webView.setHtml(html)

        else:
            self.btnRemove.setEnabled(False)
            self.btnRunLesson.setEnabled(False)
コード例 #2
0
    def currentItemChanged(self):
        item = self.lessonsTree.currentItem()
        if item:
            if hasattr(item, "lesson"):
                self.btnRemove.setText("Uninstall lesson")
                self.btnRemove.setEnabled(True)
                self.btnRunLesson.setEnabled(True)
                if os.path.exists(item.lesson.description):
                    with codecs.open(item.lesson.description, encoding="utf-8") as f:
                        html = "".join(f.readlines())
                        if item.lesson.description.endswith(".md"):
                            html = markdown.markdown(html)
                    self.webView.document().setMetaInformation(QTextDocument.DocumentUrl,
                                                               QUrl.fromUserInput(item.lesson.description).toString())
                    self.webView.setHtml(html)
                else:
                    self.webView.setHtml("<p>{}</p>".format(item.lesson.description))
            else:
                self.btnRunLesson.setEnabled(False)
                self.btnRemove.setText("Uninstall lessons group")
                self.btnRemove.setEnabled(True)
                if os.path.exists(item.description):
                    with codecs.open(item.description, encoding="utf-8") as f:
                        html = "".join(f.readlines())
                    if item.description.endswith(".md"):
                        html = markdown.markdown(html)
                    self.webView.document().setMetaInformation(QTextDocument.DocumentUrl,
                                                               QUrl.fromUserInput(item.description).toString())
                else:
                    html = item.description
                self.webView.setHtml(html)

        else:
            self.btnRemove.setEnabled(False)
            self.btnRunLesson.setEnabled(False)
コード例 #3
0
    def moveToNextStep(self):
        if self.currentStep == len(self.lesson.steps):
            dlg = LessonFinishedDialog(self.lesson)
            dlg.exec_()
            if dlg.nextLesson is not None:
                self.init(dlg.nextLesson)
            else:
                self.finishLesson(dlg.reopen)
        else:
            if self.currentStep == len(self.lesson.steps) - 1:
                self.btnMove.setText(self.tr("Finish"))
                self.btnMove.setToolTip(self.tr("Finish the lesson"))

            step = self.lesson.steps[self.currentStep]
            if step.endsignals is not None:
                self.listeners  = []
                for i, sig in enumerate(step.endsignals):
                    self.listeners.append(self.endSignalEmitted(i))
                    sig.connect(self.listeners[-1])
            item = self.listSteps.item(self.currentStep)
            item.setBackground(Qt.green)
            self.listSteps.scrollToItem(item, QAbstractItemView.PositionAtCenter)
            if os.path.exists(step.description):
                with codecs.open(step.description, encoding="utf-8") as f:
                    html = f.read()
                if step.description.endswith(".md"):
                    html = markdown.markdown(html)
                html = self.lesson.style + html
                self.webView.document().setMetaInformation(QTextDocument.DocumentUrl,
                                                           QUrl.fromUserInput(step.description).toString())
                self.webView.setHtml(html)
            else:
                self.webView.setHtml(step.description)

            height = self.webView.document().size().height()
            if height > self.webView.height():
                self.listSteps.setFixedHeight(self.listHeight)
            else:
                self.listSteps.setFixedHeight(self.listSteps.minimumHeight())

            QCoreApplication.processEvents()
            if step.prestep is not None:
                step.runFunction("prestep")
            if step.function is not None:
                self.btnRunStep.setEnabled(step.steptype != Step.AUTOMATEDSTEP)
                self.btnMove.setEnabled(step.steptype != Step.AUTOMATEDSTEP and step.endsignals is None)
                if step.steptype == Step.AUTOMATEDSTEP:
                    self.runCurrentStepFunction()
            else:
                self.btnRunStep.setEnabled(False)
                self.btnMove.setEnabled(step.endsignals is None)
コード例 #4
0
    def moveToNextStep(self):
        if self.currentStep == len(self.lesson.steps):
            dlg = LessonFinishedDialog(self.lesson)
            dlg.exec_()
            if dlg.nextLesson is not None:
                self.init(dlg.nextLesson)
            else:
                self.finishLesson()
        else:
            if self.currentStep == len(self.lesson.steps) - 1:
                self.btnMove.setText(self.tr("Finish"))

            step = self.lesson.steps[self.currentStep]
            if step.endsignal is not None:
                step.endsignal.connect(self.endSignalEmitted)
            item = self.listSteps.item(self.currentStep)
            item.setBackground(Qt.green)
            self.listSteps.scrollToItem(item,
                                        QAbstractItemView.PositionAtCenter)
            if os.path.exists(step.description):
                with codecs.open(step.description, encoding="utf-8") as f:
                    html = "".join(f.readlines())
                if step.description.endswith(".md"):
                    html = markdown.markdown(html)
                html = self.lesson.style + html
                self.webView.document().setMetaInformation(
                    QTextDocument.DocumentUrl,
                    QUrl.fromUserInput(step.description).toString())
                self.webView.setHtml(html)
            else:
                self.webView.setHtml(step.description)
            QCoreApplication.processEvents()
            if step.prestep is not None:
                execute(step.prestep)
            if step.function is not None:
                self.btnRunStep.setEnabled(step.steptype != Step.AUTOMATEDSTEP)
                self.btnMove.setEnabled(step.steptype != Step.AUTOMATEDSTEP
                                        and step.endsignal is None)
                if step.steptype == Step.AUTOMATEDSTEP:
                    self.runCurrentStepFunction()
            else:
                self.btnRunStep.setEnabled(False)
                self.btnMove.setEnabled(step.endsignal is None)