Пример #1
0
    def etiquette(self):
        select = self.canvas.select
        old_style = select.style().copy()
        old_label = select.style(u"label")
        if old_label is None:   # le style label n'existe pas pour l'objet
            return

        dlg = QDialog(self.canvas)
        dlg.setWindowTitle("Changer la légende de l'objet (texte quelconque)")

        sizer = QVBoxLayout()
        sizer.addWidget(QLabel(u"Note: le code LATEX doit etre entre $$. Ex: $\\alpha$"))

        dlg.text = QTextEdit(dlg)
        dlg.setPlainText(old_label)
        dlg.setMinimumSize(300, 50)
        sizer.addWidget(dlg.text)

        dlg.cb = QCheckBox(u"Interpréter la formule", dlg)
        dlg.cb.setChecked(select.style(u"legende") == FORMULE)
        sizer.addWidget(dlg.cb)

        line = QFrame(self)
        line.setFrameStyle(QFrame.HLine)
        sizer.addWidget(line)

        box = QHBoxLayout()
        btn = QPushButton('OK')
        btn.clicked.connect(dlg.accept)
        box.addWidget(btn)
        box.addStretch(1)
        btn = QPushButton(u"Annuler")
        btn.clicked.connect(dlg.reject)
        box.addWidget(btn)
        sizer.addLayout(box)

        dlg.setLayout(sizer)
        dlg.setWindowModality(Qt.WindowModal)

        while True:
            ok = dlg.exec_()
            if ok:
                try:
                    self.executer(u"%s.label(%s, %s)" %(select.nom, repr(dlg.text.toPlainText()), dlg.cb.isChecked()))
                except:
                    select.style(**old_style)
                    print_error()
                    continue
            else:
                select.label(old_label)
            break
Пример #2
0
    def etiquette(self):
        select = self.canvas.select
        old_style = select.style().copy()
        if isinstance(select, Texte_generique):
            old_label = select.texte
        elif select.etiquette is not None:
            old_label = select.etiquette.texte
        else:
            # L'objet n'a pas d'étiquette (Variable, etc.)
            return

        # ----------------
        # Cas particuliers
        # ----------------

        if isinstance(select, Champ):
            if select.style('choix'):
                choix = select.style('choix')
                try:
                    index = choix.index(select.texte)
                except ValueError:
                    index = 0
                text, ok = QInputDialog.getItem(self.canvas, u"Choisir une valeur",
                                u"Réponse :", choix, index, False)
            else:
                text, ok = QInputDialog.getText(self.canvas, u"Éditer le champ",
                            u"Réponse :", QLineEdit.Normal, select.texte)
            if ok:
                select.label(text)
            return


        # -----------
        # Cas général
        # -----------

        dlg = QDialog(self.canvas)
        dlg.setWindowTitle("Changer la légende de l'objet (texte quelconque)")

        sizer = QVBoxLayout()
        sizer.addWidget(QLabel(u"Note: le code LATEX doit etre entre $$. Ex: $\\alpha$"))

        dlg.text = QTextEdit(dlg)
        dlg.text.setPlainText(old_label)
        dlg.setMinimumSize(300, 50)
        sizer.addWidget(dlg.text)

        dlg.cb = QCheckBox(u"Interpréter la formule", dlg)
        dlg.cb.setChecked(select.mode_affichage == FORMULE)
        sizer.addWidget(dlg.cb)

        line = QFrame(self)
        line.setFrameStyle(QFrame.HLine)
        sizer.addWidget(line)

        box = QHBoxLayout()
        btn = QPushButton('OK')
        btn.clicked.connect(dlg.accept)
        box.addWidget(btn)
        box.addStretch(1)
        btn = QPushButton(u"Annuler")
        btn.clicked.connect(dlg.reject)
        box.addWidget(btn)
        sizer.addLayout(box)

        dlg.setLayout(sizer)
        dlg.setWindowModality(Qt.WindowModal)

        while True:
            ok = dlg.exec_()
            if ok:
                try:
                    nom = select.nom
                    txt = repr(dlg.text.toPlainText())
                    mode = (FORMULE if dlg.cb.isChecked() else TEXTE)
                    self.executer(u"%s.label(%s, %s)" %(nom, txt, mode))
                except:
                    select.style(**old_style)
                    print_error()
                    continue
            else:
                select.label(old_label)
            break