Пример #1
0
    def Activated(self):
        """Execute when the command is called.

        The document attribute is set here by the parent class.
        """
        super(AnnotationStyleEditor, self).Activated()
        # reset rename table
        self.renamed = {}

        # load dialog
        ui_file = ":/ui/dialog_AnnotationStyleEditor.ui"
        self.form = Gui.PySideUic.loadUi(ui_file)

        # restore stored size
        w = param.GetInt("AnnotationStyleEditorWidth", 450)
        h = param.GetInt("AnnotationStyleEditorHeight", 450)
        self.form.resize(w, h)

        # center the dialog over FreeCAD window
        mw = Gui.getMainWindow()
        self.form.move(mw.frameGeometry().topLeft()
                       + mw.rect().center()
                       - self.form.rect().center())

        # set icons
        self.form.setWindowIcon(QtGui.QIcon(":/icons/Draft_Annotation_Style.svg"))
        self.form.pushButtonDelete.setIcon(QtGui.QIcon(":/icons/edit_Cancel.svg"))
        self.form.pushButtonRename.setIcon(QtGui.QIcon(":/icons/accessories-text-editor.svg"))
        self.form.pushButtonDelete.resize(self.form.pushButtonDelete.sizeHint())
        self.form.pushButtonRename.resize(self.form.pushButtonRename.sizeHint())

        # fill the styles combo
        self.styles = self.read_meta()
        for style in self.styles.keys():
            self.form.comboBoxStyles.addItem(style)

        # connect signals/slots
        self.form.comboBoxStyles.currentIndexChanged.connect(self.on_style_changed)
        self.form.pushButtonDelete.clicked.connect(self.on_delete)
        self.form.pushButtonRename.clicked.connect(self.on_rename)
        for attr in DEFAULT.keys():
            control = getattr(self.form, attr)
            for signal in ("clicked", "textChanged",
                           "valueChanged", "stateChanged",
                           "currentIndexChanged"):
                if hasattr(control, signal):
                    getattr(control, signal).connect(self.update_style)
                    break

        # show editor dialog
        result = self.form.exec_()

        # process if OK was clicked
        if result:
            self.save_meta(self.styles)

        # store dialog size
        param.SetInt("AnnotationStyleEditorWidth", self.form.width())
        param.SetInt("AnnotationStyleEditorHeight", self.form.height())
Пример #2
0
 def update_style(self, arg=None):
     """Update the current style with the values from the editor."""
     index = self.form.comboBoxStyles.currentIndex()
     if index > 1:
         values = {}
         style = self.form.comboBoxStyles.itemText(index)
         for key in DEFAULT.keys():
             control = getattr(self.form, key)
             if DEFAULT[key][0] == "str":
                 values[key] = control.text()
             elif DEFAULT[key][0] == "font":
                 values[key] = control.currentFont().family()
             elif DEFAULT[key][0] == "color":
                 values[key] = control.property("color").rgb() << 8
             elif DEFAULT[key][0] in ["int", "float"]:
                 values[key] = control.value()
             elif DEFAULT[key][0] == "bool":
                 values[key] = control.isChecked()
             elif DEFAULT[key][0] == "index":
                 values[key] = control.currentIndex()
         self.styles[style] = values