Support inherited signals #33
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is your feature request related to a problem? Please describe.
I would like to use the
changedsignal with the EntryRow widget.Describe the solution you'd like
Most widgets seem to only support some of the available signals available to them. It would be nice to add support for more signals that are inherited from their ancestors and interface implementations. For my specific use case I would like to use the
changedsignal on theAdw.EntryRowthat comes fromGtkEditable. On closer inspection, seems like there are even more signals available provided byGtkEditablesuch asinsert-textanddelete-textwhich also could be useful.I am not sure how much work is required to add support for more signals especially for all the widgets but something to consider going forwards!
Thank you again for all your work on this wonderful library ;)
PS1: I tried the newly added custom CSS support and is working great!
PS2: I am still relatively new to Swift, but eventually I would like to help out by contributing to your library. Maybe when we have some simple good first issue type of requests I will dive in ;)
Describe alternatives you've considered
I tried experimenting with the currently available signals for
EntryRowsuch asonSubmitand the more genericonUpdatebut unfortunately none of them provide the desired behaviour.Basically I would like to be able to respond to changes to the entry field as the user is interacting with the widget such as inserting or deleting text.
Additional context
I am not sure if it is related in any way, but my goal is to call an async function when the signal is emitted. As mentioned above, I tried experimenting with the
onUpdatesignal and while I had some success the program eventually crashes. From my debugging, I believe theonUpdatesignal is called is much more rapidly than I actually need it to and combining it with async leads to all kinds of issues.Thanks for opening the request. Cool that you're interested in contributing!
The support for inherited signals is definitely something sensible to add. I'll work on this.
In your specific case, you can also work with the text binding instead of explicitly calling the signal as the text is updated when the
changedsignal is emitted. The most elegant way might be using binding'sonSet:About the async problem: If I understand you correctly, you're updating the UI from an asynchronous context. For this, you should wrap the call updating the UI (e.g. an assignment to a state variable) with
Idle:Hello David thank you very much for the detailed response.
I was not aware of the
onSetfunctionality. After adjusting my entry rows to use that callback I was able to achieve the desired effect including the async part, so now all is working great!I guess this
onSetfunction should work with any widget that uses a binding of some form so it might be a good idea to make it a bit easier to discover. The current documentation does not mention this callback (in the widget pages), and you must specifically search about bindings to find it.One easy way might be to add an example in the Demo app. Maybe a more general
SignalDemoby showing how we can react to various widget events.I will be happy to help out with this so if you think it makes sense just let me know!
Thank you again for your work and support.
Did you use
Idlefor this? It seems that often, it works also without it, but then it crashes sometimes randomly, so I would really wrap it withIdle.I think in general some articles should be added to the docs as well, covering useful shortcuts such as
onSet, how to correctly update from asynchronous contexts, etc. A page in the demo app would also be cool!Hello David,
I tried both approaches, and although I could not actually replicate any of the previous crashes I did end up using
Idlejust to be safe. I did some reading up on the main GTK docs about the main event loop, and usingIdleseems like a reasonable thing to do.OK cool, I will see what I can do! I will work on this and ping you in a PR.
I have another question regarding onSet. I am not sure if it is a limitation of the current implementation or if I am doing something wrong but seems like
@Bindingvariables do not get updated in the context of theonSetfunction. Is that the case or?I will give a brief example to help you understand.
EntryFieldthat uses thetext binding onSet@Bindingfor a bool, let us just call itisValidisValidvariable is set as@Stateunder a different view A and is set to use a folder for storing its stateisValidthrough a toggleNow, when I load view B as a debug method I am printing the value of
isValidand that is correct based on the JSON value from the state folder param. Next, If open the preferences dialog and update its value, upon exiting (preferences window) the view B correctly updates the value automatically.The problem is the EntryField's text on set:
View A
View B
Seems like some sort of window refresh is needed for the new value to get picked up. Again as a debug test, I added a sort option to move widgets around, doing so refreshes the window after which if I try the EntryField the correct value is displayed.
Sorry for the long and convoluted example, but it is a bit difficult to explain.
Essentially, what I want to know is if there is a way to update
@Bindingvariables within the onSet function or maybe a way to force refresh a window or something.Thank you for your help in advance!
Very strange problem! Thanks for reporting!
I'm not able to reproduce this using a simple example. It should work because the
onSetclosure is reloaded in each update. The example I tried (I modified the counter demo):Unfortunately, I don't understand what you mean by loading a view. This might be important for solving the problem, as it did work for me in a "normal" context.
Hello David.
Thank you very much for following up.
Indeed, you are correct. After some more testing I verified that
@Bindingvariables do get updated in the onSet closure but unfortunately my issue still persists. I will need to do some more testing, but I believe it might have something to do with the number of times the property is being passed to child views. I will try to offer some more context just in case you see something that might be the cause.onSetclosure is part of a complex objectStructso I am accessing it as follows: $complex.isValidEntryField.onSetupdate@Statevariable both simple and complex(struct) declared in View D --> WORKS@Bindingvariable both simple and complex(struct) declared in View D --> WORKS@Statevariable both simple and complex(struct) declared in View C passed as a@Bindingin View D --> WORKS@Binding--> WORKS@Binding--> WORKSforceUpdates: trueon@Stateproperties that are deeply shared (maybe >3 times?) fail to update in all places not only inonSetclosures.Apologies for the confusion, what I meant by load view B is basically passing the property to a child view. In our example above we just used 2 views but in my actual app as described here is passing the property 4 times.
I will try to recreate the issue in a sample app of sorts and maybe provide a small demo so that we can look into it.
Thank you once more for your time!
Are there any plans on implementing signals? They're a fundamental part of the Adwaita (and by extension Gnome) ecosystem, and a lot of things are outright impossible through property bindings. (For example
mapandstate_flags_changedamong many others). Many of these signals are essential to apps that involves more logic than pressing buttons.I realise this is a big ask, but I'd thought I'd ask before starting a sizeable project with the library and running into missing essential features :D
Otherwise, the underlying API seems fantastic, excellent work! Thank you!
@Sylphrena There is support for signals. For example, take a look at the auto-generated implementation of the
toggledsignal on toggle buttons:That said, the current autogeneration script doesn't handle GLib's inheritance system very well. As a result, signals like
Gtk.Widget:maparen’t available, since they're defined onGtk.Widgetrather than on each individual widget.Improving support for GLib’s inheritance system is definitely on my radar, but it’s not a small task. I’ll look into it, as it would be a significant improvement, but I can’t give any concrete timeline just yet.
Thanks again for the kind words! If you need support for specific signals in the meantime, feel free to let me know - I can add them manually until the generation process is more robust.
Wonderful!
I'll give this library a whirl then and report back!
Once again, thank you for your work!