Macro MessageBox: Difference between revisions
m (minor) |
Renatorivo (talk | contribs) (<translate>) |
||
Line 1: | Line 1: | ||
<translate> |
|||
{{Macro|Icon=Text-x-python|Name=MessageBox|Description=Show how to give information to the user in macros|Author=Gaël Ecorchard}} |
{{Macro|Icon=Text-x-python|Name=MessageBox|Description=Show how to give information to the user in macros|Author=Gaël Ecorchard}} |
||
==Description== |
|||
Show how to give information to the user in macros |
Show how to give information to the user in macros |
||
Line 6: | Line 6: | ||
[[File:Macro MessageBox 00.png|480px|MessageBox]] |
[[File:Macro MessageBox 00.png|480px|MessageBox]] |
||
</translate> |
|||
<syntaxhighlight> |
<syntaxhighlight> |
||
Line 27: | Line 28: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<translate> |
|||
In order to use the accented characters in the text field from '''Qt''', using the tag ''' #-*-coding: utf-8-*- ''' must be added a '''u''' before the message to display |
In order to use the accented characters in the text field from '''Qt''', using the tag ''' #-*-coding: utf-8-*- ''' must be added a '''u''' before the message to display<br /> |
||
⚫ | |||
</translate> |
|||
⚫ | |||
<syntaxhighlight> |
<syntaxhighlight> |
||
diag = QtGui.QMessageBox(QtGui.QMessageBox.Warning, u'Trop d'éléments désignés', msg) |
diag = QtGui.QMessageBox(QtGui.QMessageBox.Warning, u'Trop d'éléments désignés', msg) |
||
Line 38: | Line 41: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<translate> |
|||
⚫ | |||
⚫ | |||
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. |
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.<br /> |
||
⚫ | |||
</translate> |
|||
⚫ | |||
<syntaxhighlight> |
<syntaxhighlight> |
||
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> |
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> |
||
Line 48: | Line 53: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{clear}} |
|||
<br> |
|||
<languages/> |
|||
{{languages | {{es|Macro_MessageBox/es}} {{fr|Macro_MessageBox/fr}} {{it|Macro_MessageBox/it}} }} |
Revision as of 18:21, 25 December 2013
File:Text-x-python MessageBox |
Description |
---|
Show how to give information to the user in macros Author: Gaël Ecorchard |
Author |
Gaël Ecorchard |
Download |
None |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
1.0 |
Date last modified |
None |
FreeCAD Version(s) |
None |
Default shortcut |
None |
See also |
None |
Show how to give information to the user in macros
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""Show how to give information to the user in macros
"""
from PyQt4 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))
In order to use the accented characters in the text field from Qt, using the tag #-*-coding: utf-8-*- must be added a u before the message to display
Example :
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))