4 ms·
Looks good. I have a suggestion for it, although it might be this library is too mature for such a dramatic change: use dictionaries (which, as of a recent Pyth
by quietbritishjim 3y ago
Looks good. I have a suggestion for it, although it might be this library is too mature for such a dramatic change: use dictionaries (which, as of a recent Python, remember which order the elements were inserted) instead of lists.
I did something like that in an old job, except it was a much thinner wrapper around PyQt (and surprisingly little code). A key difference is that setting properties/signals and nesting widgets was done together. One benefit of that over setting properties in the constructor is that, if you need a name for a widget (e.g., to set the text later), you can still set the properties of it in the main bulk of the view.
self.mytext = QTextEdit()
view = {
"title": "My Window Title",
QVBoxLayout(): {
self.mytext: {
"text": "Initial text",
},
QPushButton(): {
"text": "copy from self.mytext",
"clicked": self.copy_text,
}
}
}
setup_view(self, view)
The "setup_view" function was the whole API. They talked about opening sourcing it as part of something else – I hope they do because I found it really handy for quickly knocking together simple GUIs. But this library looks like a good alternative, so thanks for posting.
- JimDabell 3y ago> use dictionaries (which, as of a recent Python, remember which order the elements were inserted) instead of lists. It feels that way to me too but that change was introduced in Python 3.7, which is over five years old now! https://docs.python.org/3/whatsnew/3.7.html#summary-release-highlights https://docs.python.org/3/whatsnew/3.7.html#summary-release-...
- ape4 3y agoFrom the github page: "The window definition is simplified by using Python core data types understood by beginners (lists and dictionaries)."
- quietbritishjim 3y agoWhy do you post that quote? I think there must be some implied meaning I'm not getting. Is there a way to use dictionaries to set properties and nest widgets in a similar way to my code example?
- Izkata 3y agoThe second example shows setting text through a dictionary.
- quietbritishjim 3y agoNo, it showed setting text through a different method that does not use a dictionary. (Maybe it uses one in its implementation, but we're taking about the interface here.) There is no usage of Python dictionaries anywhere on the whole page. I have to admit, the alternative method used in the second example is interesting, it's probably just as good as my suggestion in most ways. But ape4's quote about dictionaries still doesn't make sense to me (both on its own or in context in this conversation).
- Too 3y agoLooking at the latest trends of GUI frameworks, decoupling the layout from the data gives much cleaner code. Let the framework take care of all the data binding for you. Both web and desktop go more and more in this direction. Nobody does That means, avoid mutating widgets directly. Instead bind their properties to some data store that rerenders automatically on change. The input/output example on their page demonstrates something like this. Nobody does getElementById() any more.