Macro MessageBox

From FreeCAD Documentation
Revision as of 16:11, 29 December 2018 by Mario52 (talk | contribs)

Icono de macro genérico. Crea tu icono personal con el mismo nombre de la macro MessageBox

Descripción
Muestra como dar información al usuario en las macros

Versión macro : 1.0
Fecha última modificación : 2011-09-19
Autor : Gaël Ecorchard
Autor
Gaël Ecorchard
Descargar
None
Enlace
Versión Macro
1.0
Fecha última modificación
2011-09-19
Versión(es) FreeCAD
None
Acceso directo predeterminado
None
Ver también
None

Descripción

Muestra como dar información al usuario en las macros

MessageBox

Script

Macro_MessageBox.FCMacro

#! /usr/bin/env python
# -*- coding: utf-8 -*-
 
"""Show how to give information to the user in macros
"""
from PySide import QtCore, QtGui
 
def errorDialog(msg):
    # Create a simple dialog QMessageBox
    # The first argument indicates the icon used: one of QtGui.QMessageBox.{NoIcon, Information, Warning, Critical, Question} 
    diag = QtGui.QMessageBox(QtGui.QMessageBox.Warning, 'Error in macro MessageBox', msg)
    diag.setWindowModality(QtCore.Qt.ApplicationModal)
    diag.exec_()
 
msg = 'Example of warning message'
errorDialog(msg)
raise(Exception(msg))


Para usar los caracteres acentuados en el campo de texto de Qt, usando la etiqueta # - * - codificación: utf-8 - * - debe agregarse una u antes del mensaje a mostrar
Ejemplo:

diag = QtGui.QMessageBox(QtGui.QMessageBox.Warning, u'Trop d'éléments désignés', msg)
    ...
    ...
msg = u'Élément sélectionnés affichés'


To display multiple lines in a dialog box Qt, must be added "\n" (quotation, valid also between apostrophes) between each line.
Valid also "\r\n" which correspond to CR carriage return, and LF end of line, valid also " \t" is a tab, characters should be between quotation marks (and apostrophes) as a character string, the tags can be found next to the text to display " \nRayon\t: ", the tag " \ " (reversed slash) defines the command.
Example :

diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,u"Coordonnées",u"Coordonnée X : "+str(x)+"\r\n"+u"Coordonnée Y : "+str(y)+"\n"+u"Coordonnée Z :<br>
 "+str(z)+"\nRayon\t     : "+str(r))