GNOME Bugzilla – Bug 456750
gtksourceview.SourceTagStyle().mask is not writable
Last modified: 2007-07-29 12:36:05 UTC
[ forwarded from http://bugs.debian.org/431962 by Adeodato Simó ] It seems that the 'mask' attribute of gtksourceview.SourceTagStyle objects is not writable, but instead derived whenever SourceTagSytle.foreground or SourceTagStyle.background are set (see gtksourceview.override). I see no reason for this to be this way, since it breaks setting all three foreground, background and mask, letting the TagStyle object figure out which colors to finally use. Which works from C (it's what gedit does, see string_to_tag_style() in gedit-languages-manager.c). All this makes it necessary when working in Python code to check the value of mask, and refraining from setting foreground or background colors according to its value, which seems more unpythonic to me than having the attribute writable. Thanks.
I disagree. The 'mask' field only exists because of limitations in the C language. In Python we can instead automatically compute mask based on the attributes that have been actually set, which is more intuitive and less error prone. I don't know why you'd ever want to e.g. modify style.background but not set the flag in style.mask saying background was set.
The original submitter added: > > it breaks setting all > > three foreground, background and mask, letting the TagStyle object > > figure out which colors to finally use. Which works from C (it's what > > gedit does, see string_to_tag_style() in gedit-languages-manager.c). If you read from gedit's configuration files, background and foreground are stored, even if only the foreground was configured (the background is set to #000). So what gedit does is set both colors, plus the mask (which is also stored), and let the tagstyle code figure out what to use. That is not possible from Python. 8< --- 8< --- 8< --- This is to show you the actual use case the user is facing. I'm not really agreeing with this idea, as it is definitely not something you'd use in the general case. You could make it so that the automatically computed mask can be overriden, but I'm afraid it would make the API confusing.