-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feedback on using ltk.Model #19
Comments
Additional related information: When changing a
Error message is:
This may all be classvar vs instancevar problems and not so easily solved. |
Also I have been caught out a few times as |
I have not succeeded in making a component style object using the Model class. A good solution would be to move to instance variables. I wonder if this is at all possible? |
A small side note - in Chrome - when using an IWBNI mouse scrolling on numeric inputs also did a live reactive update. |
Not sure what you mean here. There is a difference between str and repr in Python. I added the str for completeness. It calls str() on the underlying value. When would that fail? |
The class attributes for ltk.Model subclasses act as a template for creating instance. You do not directly set new values on the class fields, but set them on the instances. I updated the example in the Kitchensink to make this more obvious, hopefully. Does that clear up the confusion? See https://pyscript.github.io/ltk/?tab=3 |
Overrides in ltk.ModelAttribute iadd and similar methods were missing call to set_value. Updated the implementation and the sample to show working code. |
The Model IS instance based. The new example should clarify this a bit better? |
Ahh ok. I thought it was on the class variables because I could not set instance variables at all. (you have clarified why above) wrt the Possibly all my confusion will be cleaned up when I look again today. |
Do you have an example for the str problem? I still don't understand it 🤓 . |
Brilliant - now working very well. Got an approach working for fully encapsulating a UI component in a single python file (well except putting the css into its own block. Personally a separate css file still seems like a very good/manageable solution.) |
This is great to hear. |
OK. I am in the process of trying to make single file components. I think it would be useful to have a helper function for css use.
Where
This would help me to identify and create a css file for this component. The reasoning behind this is to make use of the I am thinking at the moment that each "single file component" is really two files (assuming no required imports). Then users can choose to manually amalgamate the css for efficiency but when initially building you'd just end up loading a few css files. Thoughts ?? |
A good place to put that would be ltk.Inspector:
https://github.com/pyscript/ltk/blob/334f874efff6c6c544d0582fda5eabe795f335fd/ltk/widgets.py#L40
It already shows details about the widget you hover over with Ctrl+Shift.
Adding more details such as classes and style values makes sense.
…On Fri, Feb 7, 2025 at 9:09 PM Neon22 ***@***.***> wrote:
OK. I am in the process of trying to make single file components.
I think it would be useful to have a helper function for css use.
Is something like this possible:
if __name__ == "__main__":
w= My_new_component()
widget = w.create()
widget.appendTo(ltk.window.document.body)
#
print(w.css_report())
Where .css_report() printed out a list/dictionary of:
- names of id attributes used (each.attr("id", foo))
- names of all classes added in .addClass()
- whether or not .css() was used
- Perhaps somomething like:
-
- {"ids": [], "classes": [], ".css": [] }
This would help me to identify and create a css file for this component.
The reasoning behind this is to make use of the __main__ python approach
to debug/visualise a component while developing it, or examining a
component you think you want to include.
I am thinking at the moment that each "single file component" is really
two files (assuming no required imports).
The py file and its associated css file. Presumably with the same name.
Then users can choose to manually amalgamate the css for efficiency but
when initially building you'd just end up loading a few css files.
Thoughts ??
—
Reply to this email directly, view it on GitHub
<#19 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE4XAKBAUABONMFQSG4Z3O32OUHG3AVCNFSM6AAAAABU25PV4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNBUGAZDQNJYGQ>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
See LTK v.2.22. The inspector now shows classes and css. |
OK. Thanks but :)
So its giving me this when I'm over an
When what I want to know is:
Like this |
So for my example here: I would like to know: I agree it would also be good to know the names of the ltk classes you used when you wrote them. So that I could easily override them if I needed to: So (ideally) something like:
|
I am removing the CSS parts as it adds no value to the inspector. The
classes I will look into.
To know if anyone set the CSS on a widget, I would suggest you monkey patch
the ltk.Widget class and replace the CSS method in it.
…On Sat, Feb 8, 2025 at 12:29 AM Neon22 ***@***.***> wrote:
So for my example here:
-
***@***.***/starter-04a-singlefile-component/latest?files=dimension_component.py
I would like to know:
{"ids": [], "classes": ["Item", "paramtitle", "measure", "short", "param",
"altlabel", "noborder"], ".css": True }
—
Reply to this email directly, view it on GitHub
<#19 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE4XAKAFTJM5MCZZOBNO6GL2OU6VNAVCNFSM6AAAAABU25PV4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNBUGMYTSNRRHA>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
Please try again with LTK 2.23
…On Sat, Feb 8, 2025 at 12:41 AM Chris Laffra ***@***.***> wrote:
I am removing the CSS parts as it adds no value to the inspector. The
classes I will look into.
To know if anyone set the CSS on a widget, I would suggest you monkey
patch the ltk.Widget class and replace the CSS method in it.
On Sat, Feb 8, 2025 at 12:29 AM Neon22 ***@***.***> wrote:
> So for my example here:
>
> -
> ***@***.***/starter-04a-singlefile-component/latest?files=dimension_component.py
>
> I would like to know:
> {"ids": [], "classes": ["Item", "paramtitle", "measure", "short",
> "param", "altlabel", "noborder"], ".css": True }
>
> —
> Reply to this email directly, view it on GitHub
> <#19 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AE4XAKAFTJM5MCZZOBNO6GL2OU6VNAVCNFSM6AAAAABU25PV4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNBUGMYTSNRRHA>
> .
> You are receiving this because you were assigned.Message ID:
> ***@***.***>
>
|
OK. Thanks for considering it.
and in
Then a post process could look to see if it was used... |
OK. Thanks Chris. looked at 2.23. I can work with that. |
MVP Feedback:
In trying to migrate to using the MVP (
ltk.Model
class) I have come across some issues.I will lay them out here in the hopes that it might help in future development.
To get around the potential memory leak in
widget()
I have successfully been using a global var. The MVP approach looks like it may supersede the need for the recently addedwidget()
I am also using a global var to make easy ref to the following reactive component. This is working well.
I am also using a global to deal with rippling updates, if I update two or more reactive variables. This is working well.
I.e.
ltk.Model
using class variables.Specifically:
self.Len_measure = "foo"
self.Len_measure
through a function header and try to assign it, then an instance variable is created and the class var is not updated.E.g.
So to get around this I send the name of the classvar through (as in
changed()
above and do a more complicated operation like so:In short:
I am using
self.__setattr__(primary_var, newvalue)
instead ofprimary_var = newvalue
because its a classvar.So I am ok with my solution and its as neat as I can work out how to make it (by using the expanding
*vars
parameter).But I wonder if there is another way to architect it so it works differently.
Working example here:
Cheers...
The text was updated successfully, but these errors were encountered: