[PyKDE] SIP-20041231 enum issue
Phil Thompson
phil at riverbankcomputing.co.uk
Sun Jan 9 14:10:10 GMT 2005
On Tuesday 04 January 2005 9:52 pm, Gerard Vermeulen wrote:
> Would it be to relax the type checking of enum parameters in SIP generated
> wrappers, so that both an int argument and an enum argument are accepted?
>
> I have to change two PyQwt examples to make them work with the current
> behaviour. Python pseudo code follows: ...
> FIXME = True # Set to True when explicit casts of a 'Python int' to a
> 'SIP-4.2 enum' are required. ...
> # Example 1
> # Translation of C++:
> # for (int c=0; c<QColorGroup::NColorRoles; c++)
> # colorGroup.setColor(c, QColor());
> for c in range(QColorGroup.NColorRoles):
> if FIXME:
> c = QColorGroup.ColorRole(c) # SIP-4.2 needs this "cast"
> :-/ colorGroup.setColor(c, QColor())
> ...
> # Example 2
> # make sliders
> # QwtSlider.BgSlot and QwtSlider.BgTrough are enums, and accepted as such
> sldV1 = QwtSlider(self, "", Qt.Vertical, QwtSlider.Left,
> QwtSlider.BgSlot)
> sldV2 = QwtSlider(self, "", Qt.Vertical, QwtSlider.None,
> QwtSlider.BgTrough)
> if FIXME:
> # Apparently QwtSlider.BgSlot | QwtSlider.BgTrough is not seen
> as an enum by SIP-4.2. # Therefore a cast is required :-(
> sldV3 = QwtSlider(
> self, "", Qt.Vertical, QwtSlider.Right,
> QwtSlider.BGSTYLE(QwtSlider.BgSlot | QwtSlider.BgTrough))
> else:
> # SIP <= 4.1.1 is happy with the next statement
> sldV3 = QwtSlider(self, "", Qt.Vertical, QwtSlider.Right,
> QwtSlider.BgSlot | QwtSlider.BgTrough)
>
> I would expect that one can pass a Python int as well as a SIP-4.2 enum
> argument into an enum parameter of a function wrapped by SIP (a C++
> function with a C++ enum parameter accepts C++ int arguments).
Ok, I've had second thoughts about this - the idiom of oring enum values is
too common. Tonight's SIP snapshot will allow an integer whereever an enum is
expected. I can still get QListBox.setColumnMode() to work properly, which
was the original intent of the change.
You will need to re-build PyQt as there is a code generation change.
Phil
More information about the PyQt
mailing list