Re: Problem with st_widget_set_theme()



> On Sun, Jul 22, 2012 at 1:35 PM, Michele <micxgx gmail com> wrote:
[snip]
>> As far as I know, the extension stylesheet has a lower priority than
>> the default or theme ones. This means that style cannot be easily
>> overwritten.
...
>> Any way to get over the problem? Applying the same theme to the stage
>> seems to work properly instead:
>>
>> themecontext = St.ThemeContext.get_for_stage(global.stage);
>> themeContext.set_theme(theme);

Hi Michele - I found a few ways to get around this (if you can't use
StWidget.set_theme):

1) use .set_style, which gets highest priority:
widget.set_style('border: 1px solid red; color: blue');
Caveat - if someone else has already called .set_style, your call will
override that one (this doesn't happen too often though, and if you
want you can always append your style to widget.get_style())
2) use the `themeContext.get_theme(theme)`, noting that
theme.application_stylesheet overrides .theme_stylesheet overrides
.default_stylesheet overrides .get_custom_stylesheets() (I think this
is where the extension stylesheets are usually put).

Just make sure (since you're setting a global theme) to re-add in the
existing theme/default/custom stylesheets into your new theme, so
essentially you put your extension stylesheet up the top at
application_stylesheet and demote all the others.

Otherwise (for example) any extension that loads after yours will not
get its styling because its stylesheet has not been added to the
theme.

e.g.:

let themeContext = St.ThemeContext.get_for_stage(global.stage);
let orig = themeContext.get_theme();

let myTheme = new St.Theme({
    application_stylesheet: my_stylesheet,
    theme_stylesheet: orig.application_stylesheet
    default_stylesheet: orig.theme_stylesheet
});
// don't forget original theme's default_stylesheet
theme.load_stylesheet(orig.default_stylesheet);
// add in all the custom stylesheets
let customs = orig.get_custom_stylesheets();
for (let i = 0; i < customs.length; ++i) {
    theme.load_stylesheet(customs[i]);
}

(I ran into a similar problem to you a while ago and explored both
options - I ended up taking the .set_style() option, but for no
particular reason).

HTH.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]