How do you use renpy.get_widget_properties?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

How do you use renpy.get_widget_properties?

#1 Post by Pyr0 »

I have written the simplest code possible:

Code: Select all

screen Hello():
    fixed id "fix":
        xsize 32
        ysize 32
    
    python:
        renpy.log("test log")
        widget = renpy.get_widget_properties("fix",None)
        for key in widget:
            renpy.log(key)
    
label start:
    call screen Hello()
Nothing, except 'test log' is ever printed.
Also, as far as displayables go, is there a way to access their properties?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How do you use renpy.get_widget_properties?

#2 Post by Remix »

I tend to use renpy.get_widget("screen_name_in_quotes", "widget_name_in_quotes") so you might find get_widget_properties uses the same syntax (yeah I know the documentation says it uses (id, screen, layer)... maybe try both ways (note: You would likely need the screen name "Hello" either way.

Failing that, maybe just dir the displayable and skip underscored prefixes...

Pseudo-fly-typed-untested-code...
widget = renpy.get_widget("Hello", "fix")
for k in [m for m in dir(widget) if m[0] != "_" and m not in ['list_of', 'ignored_attributes']]:
....renpy.log("{0} = {1}".format(k getattr(widget, k))

or somesuch
Frameworks & Scriptlets:

User avatar
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

Re: How do you use renpy.get_widget_properties?

#3 Post by Pyr0 »

Remix wrote: Wed Aug 09, 2017 5:54 pm I tend to use renpy.get_widget("screen_name_in_quotes", "widget_name_in_quotes") so you might find get_widget_properties uses the same syntax (yeah I know the documentation says it uses (id, screen, layer)... maybe try both ways (note: You would likely need the screen name "Hello" either way.

Failing that, maybe just dir the displayable and skip underscored prefixes...

Pseudo-fly-typed-untested-code...
widget = renpy.get_widget("Hello", "fix")
for k in [m for m in dir(widget) if m[0] != "_" and m not in ['list_of', 'ignored_attributes']]:
....renpy.log("{0} = {1}".format(k getattr(widget, k))

or somesuch
Using this I can get the attributes\variables of an object, while I thought that renpy.get_widget_properties would return the actual displayable properties (like xsize, ysize, etc). I suppose these are held in a dictionary which in turn is linked to one of these attribute names, but I have no idea which one.

User avatar
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

Re: How do you use renpy.get_widget_properties?

#4 Post by Pyr0 »

So, I've been playing with this for some time, using the dev console to traverse the screen and its children manually.
And, well, I simply can't understand what "widget properties" is supposed to be. At first I thought it was the actual widget's properties, like position and size, but that isn't the case. As far as I can see, there is no such thing as widget properties, even checking the widget_properties variable of any screen always returns an empty map (while checking for the widgets themselves return a map of those widgets as expected). Is this an old function that isn't supposed to be used anymore? Does "properties" mean something else?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How do you use renpy.get_widget_properties?

#5 Post by Remix »

Theoretically, it 'should' actually return a dict mapping properties together based upon the widget id within the screen...
It is defined in /renpy-{version}-source/renpy/display/screen.py around line 1200
and end with an output along the lines of:

Code: Select all

    rv = s.widget_properties.get(id, None) # s is the screen
    return rv if rv else {}
You might though, find more information scouting down from the actual screen and following attributes as you see fit
screen_props = get_screen('screen_name').widget_properties
(all screen based functions and classes are defined in the file mentioned, so maybe look around for anything useful)

Note though, a widget with a transform used upon it will rarely if ever have its own values for a parameter changed. Instead, the transform will wrap the widget and the transform parameters will be altered. In most transforms, other sibling and child transforms will also be spawned to handle before and after update changes... It gets pretty tricky to locate a transform that is altering a certain widget while still using ATL.
e.g.
Image A uses linear 1.0 xpos 200
A transform will be created wrapping Image A
This might just handle each movement step or it might create a new transform every time it is called and add/remove that new transform from the process stack for the next screen update
It gets pretty messy if you are dir() ing a transform while it plays and trying to guess which child transform is doing what...

If you manage to find how to get the positional properties of a widget while it undergoes a transform, please let me (and everyone else) know...
I was 'briefly' trying this on a self-aware directional sprite that ripped a spite-sheet and then was meant to just automatically display the correct individual sprite by working out where it was on the screen and where it was last... so if it had moved one pixel north, it would show the north sprite one step higher than previous

Good luck
Frameworks & Scriptlets:

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How do you use renpy.get_widget_properties?

#6 Post by Remix »

Just for info, I was using something like:

Code: Select all

init python:
    def move_arc(trans, st, at):
        rad = st / 10 * math.pi * 2
        trans.xalign = float(math.sin(rad)) / 4 + 0.5
        trans.yalign = float(math.cos(rad)) / 4 + 0.5
        # Set a variable to display info relating to this transform
        globals()['trans_data'] = ["{0}={1}\n".format(
            trans, getattr(trans, k)).replace("[","[[").replace("{","{{") for k in dir(trans) if k[0] != "_" and isinstance(getattr(trans, k), tuple)]
        return 0.02 # 50fps

screen track_data():
    vbox:
        text "Trans: {size=-5}[trans_data]{/size}"
    timer 0.2 action (renpy.restart_interaction) repeat True

label start:
    # scene bg 5
    $ trans_data = "None"
    show screen track_data()
    # show some image or displayable using the transform for basic basic at the moment circular-ish motion
    # $ my_img = Image .....
    show expression (my_img):
        function move_arc
You will see though, that even though we are 'only' tracking child transforms where the value is a tuple, we still have 6 or 8 of them just to move one image slowly around
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users