They are bitwise flags. Each value in a given enum is incremented by
shifting bits. Then you are able to use bitwise operators to combine
multiple values and test their membership:
https://wiki.python.org/moin/BitwiseOperators

A = 1 << 0
B = 1 << 1
C = 1 << 2
D = 1 << 3
print A,B,C,D
# 1 2 4 8
print A | B
# 3
print A | B | B | B
# 3
flag = A|B
if flag & A: print True
# True
if flag & B: print True
# True
if flag & C: print True
#
flag ^ B    # toggle off B
# 5
flag ^ B ^ B  # toggle off and on B
# 7
flag & ~B  # subtract B
# 5
flag & ~B & ~B  # maintains the subtraction (not toggle)
# 5
flag &= ~B  # unary subtraction; assignment
# 5

Basically, once you define a set of flags, you have AND, OR, XOR, NOT
operators to test and modify the flags. It lets you represent a number of
states in a single value.





On Wed, Dec 18, 2013 at 9:00 PM, Marcus Ottosson <[email protected]>wrote:

> Hi all,
>
> What's a Pythonic way of parsing a set of flags, similar to how Qt does it.
>
> E.g. layout.setAlignment(Qt.AlignTop | Qt.AlignLeft)
>
> Both AlignTop and AlignLeft seem to be hex numbers (docs 
> here<http://qt-project.org/doc/qt-5.1/qtcore/qt.html>)
> that seem to get combined into a third number via the | operator. Where's
> the logic behind that and how can I derive such logic myself?
>
> Thanks,
> Marcus
>
> --
> *Marcus Ottosson*
> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBUGHyG9vrny_BqWcdvcD3ezM-VHM_jNJYA70Rv4DTNug%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1sQCWRnfP5LVZRNFpRM1uPMmNZYEikOLSFRZ%3DUGE16ig%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to