Page 1 of 1

styles and theme colors

Posted: Sun Jul 05, 2015 12:18 pm
by korova
In the options.rpy file, the user defines several colors for the theme used by the game.

Let's imagine that I want to define new styles, using the same colors as the theme colors.

How can I access the variables where theme colors are stored ?

like, for example

Code: Select all

style my_style:
    color the_widget_text_color_of_the_theme

Where is the widget_text color stored, and how to access it ?

I don't want to copy paste the "#" string, so that if I change the theme colors, the colors of my new styles change too.

Thanks for your help.

Re: styles and theme colors

Posted: Sun Jul 05, 2015 7:59 pm
by nyaatrap
Theme is a function that initializes styles, so it isn't stored.

Re: styles and theme colors

Posted: Mon Jul 06, 2015 2:50 am
by korova
Fine, but the values themselves must be stored "somewhere", because the writing and widget colors change according to theme...

I tried to use the styles values (I got them from the style inspector), but this doesn't work.

For example, I want my new style to have the same text color as the selected button text color.

Here is what I get from style inspector
Style inspector
Style inspector
So, style button_text has a "selected_color" attribute, according to style inspector

But if I try to use this attribute when defining my style like this

Code: Select all

style my_style:
    color style.button_text.selected_color
I get this error :

Code: Select all

While running game code:
  File "game/screens.rpy", line 256, in script
    style accueil_hover is button_text:
  File "game/screens.rpy", line 257, in <module>
    color style.button_text.selected_color #style.default.selected_color
AttributeError: 'renpy.styledata.styleclass.Style' object has no attribute 'selected_color'
Suggestions ?

Re: styles and theme colors

Posted: Mon Jul 06, 2015 3:34 am
by nyaatrap
This works.

Code: Select all

style.selected_text_button.color
Though I don't recommend to access style itself to initialize styles. It's more safe to create a new variable for it.

Code: Select all

init -3 python:
    WIDGET_COLOR = "#fff"
style button_text:
     color WIDGET_COLOR

Re: styles and theme colors

Posted: Mon Jul 06, 2015 5:16 am
by korova
nyaatrap wrote:This works.

Code: Select all

style.selected_text_button.color
Nope.

No error, right, but it gives me pure white, and button_text.selected.color is supposed to be "#7a4229" (kind of marron)

I tried several syntax : style.selected_button_text.color / style.button_selected_text.color, etc.
At best I have no error, but either white or same color as style.button_text.color (dark orange) which is not what I want.
nyaatrap wrote: Though I don't recommend to access style itself to initialize styles. It's more safe to create a new variable for it.

Code: Select all

init -3 python:
    WIDGET_COLOR = "#fff"
style button_text:
     color WIDGET_COLOR
Mmmmm. I see what you mean, but I have no intention to re-define button_text style, less all my styles. I just want my new styles to be consistent with my pre-existing theme. I want to extract pre-existing values of my theme to use in my new custom styles.

Re: styles and theme colors

Posted: Mon Jul 06, 2015 7:59 am
by nyaatrap
That's way I don't recommend it. Theme isn't pre-exisited before styles - It's a modifier of styles in init -1 order. When you access to styles, there are many thing you have to investigate (init order, style group, etc) which is more work than just copy & paste.

Re: styles and theme colors

Posted: Mon Jul 06, 2015 8:14 am
by korova
So, I know what I shouldn't do. (Which doesn't help me very much...)

Now, what SHOULD I do if I want to create new styles that uses the same colors as the theme colors ?

Re: styles and theme colors

Posted: Mon Jul 06, 2015 8:48 am
by nyaatrap
Usually, is statement or take statement works enough.

Code: Select all

style new_button is button:
style new_button take button:
If it's not enough, create a new variable then copy & paste the theme color like the above.

Re: styles and theme colors

Posted: Mon Jul 06, 2015 9:16 am
by korova
Thanks for your help. I really appreciate your interest.
nyaatrap wrote:Usually, is statement or take statement works enough.

Code: Select all

style new_button is button:
style new_button take button:
Except I'm not trying to create a new button style.
I try to create a new text style, for example, that's gonna use same color set as the theme, but not same distribution of colors as the predefined button or predefined text style.
(Sorry, I'm a very complicated person)
nyaatrap wrote:If it's not enough, create a new variable then copy & paste the theme color like the above.
Which is precisely what I'm trying to avoid.

If I suddenly decide to change theme colors (with ren'py launcher for example, or directly in options.rpy) - and believe me, this might happen - , I'll have to remember to change that new variable too.
This is why I'm trying to access somehow, from code, to the theme color values.

Re: styles and theme colors

Posted: Tue Jan 30, 2018 4:54 pm
by Enerccio
Bumping this post with an answer, because frankly, I had similar issue and this was google hit for it.

So my solution to accessing

Code: Select all

style.stylename.property
is via this small function

Code: Select all

def search_style(s, f):
        for p in s.properties:
            if f in p:
                 return p[f]
and is used with

Code: Select all

search_style(style.stylename, "proprety")
Terribly inefficient but seems to work!