Best practise for multi-form app - looking for examples #2515
Replies: 2 comments 3 replies
-
So... there's so much extra content wrapped around this question that I'm not entirely sure I've understood it correctly - but if I have, you're asking "how do I build an app with multiple pages of content?". That's not really a question we can answer canonically, because it's a large project management question. There are multiple ways you could structure your code, each of which is just as valid as any other, and Toga doesn't really care one way or the other. Ultimately, a toga You could use a method on the app to construct and return the new layout. You could write a class that encompasses both the root content and its children; constructing an instance of the "content" class would yield a complete layout. You could factor your code at the level of the window. You could take a step back and write your app as it's own class independent of Toga, and treat the Toga app and class as "the things my app is managing". These (and more) are all valid approaches; and Toga doesn't really have any preferences one way or the other. Which one makes sense for you depends as much on your own code as it does anything to do with Toga. |
Beta Was this translation helpful? Give feedback.
-
You got my meaning so all good. As I've got as far as switching the I'll endeavour to split out my hacking thus far in to the four suggestions so I can see what I've achieved - although I suspect I've only got the method on app, class on app and code in the main class, I guess rather than asking what would best practise be, I could turn it around two ways: How would you or another competent Toga person do this? If you were teaching a class to people that could code but not necessarily Python experts, how would you present this - ie, introduce the minimum of Python constructs (classes, decorators, self (!) etc). The critical observation I'd make is that I really really have done the research & tried this out and without some examples being formed it is likely to limit the audience for Toga. As above, happy to do more work but I'm going to need some assistance please. |
Beta Was this translation helpful? Give feedback.
-
Hi, I end up creating mini-apps to support a variety of situations - either to simplify a complex app by making specific the users via APIs or CLI or some such - or to support my own software & hardware (I do some embedded sensors - IoT).
I've used Tkinter in the past and it is just too fuglly for todays audience to stomach. After looking at other Python based options I happened on Beeware. I realise it is early days but it makes sense to me, I've hacked on the examples, broken stuff and created a couple of simple forms and it's looking good.
Now I need to figure out a design pattern for a multi-forms app - that is one that has a layout that on selection of an item from a list or a press of a button changes the layout to fit the task at hand.
I got a basic version working by putting everything in to the main class - not very maintainable. So created a class per layout.
I've found https://github.com/Diegiwg/ssiql which does what I'm talking about. I suspect the templating system is breaking some core functionality like being able to tab between entry fields so I'm going to remove the builder and just feed it raw Toga. I'm OK with the MVC setup and I've got a test app going with a class supplying the layout but am tripping up on getting things like a info_dialog to open via the on_press, most likely due to me missing some concept in Python - competent, able to read the docs, will try things, but I also code PHP, JS & C/C++ (and have the grey hair to justify that) so not a Python Ninja.
So the first question is "has my Google Fu failed and there is a multi-layout example somewhere"?
If no, does anyone with more experience of Toga have a picture about how to structure code to do this?
If no, I'm happy to be the guinea pig to create a canon example but I'll need someone to assist consistently so I'm not summarising the problem from scratch with every issue - which I'd open a discussion for unless it is an actual issue/bug/error.
Keen to use Toga/Beeware rather than falling back on a web view based package as my current main client project is for bee hive monitoring and the emotional bit of this elder geek just loves the idea of using Beeware for actual Bees!
Beta Was this translation helpful? Give feedback.
All reactions