Randall's Blog

a place for my thoughts

wxPython flags

written by randall, on Sep 16, 2009 12:11:00 AM.

I needed to use the wx.FindReplaceDialog from wxPython and got stumped when I wanted to see if a particular flag was set from a FIND/FIND_NEXT event. The flags to check are wx.FR_MATCHCASE, wx.FR_DOWN and wx.FR_WHOLEWORD. I've set flags many times for styles and such, but never before needed to check one.

Flags in wxPython (and wxWidgets of course) are set by applying a bitwise or to them. Example:

wx.FR_MATCHCASE | wx.FR_WHOLEWORD

This would include both wx.FR_MATCHCASE and wx.FR_WHOLEWORD, but exclude wx.FR_DOWN. The flags are retrieved using the evt.GetFlags method. So how do you know if a particular flag is set? Use bitwise and on evt.GetFlags() and the flag you are checking.

evt.GetFlags() & wx.FR_WHOLEWORD

This will return 0 if the wx.FR_WHOLEWORD flag is not set or a positive integer otherwise.

Comments

Leave a Reply