There’s something pretty sucky about the way I’ve been structuring tinypapers. It’s getting too spaghettti-code-like. A line I wrote a few days ago to solve a problem made me feel uneasy (I think I mentioned this already somewhere?) and I couldn’t find a different approach. Then there are these more recent issues that have been making me twitchy. My design sense finally put two and two together… there’s some funky stuff going on I need to fix.
Anyway, I’m going to have to spend a day or two refactoring (and, where possible, minimizing) the “power” structure before it gets any more complicated. I just sat down with an actual pen and paper (magical tools) and it’s pretty obvious that something isn’t right. Hopefully the visual aid will help kick me into solving what’s wrong.
(several hours later)
Kivy is really confusing about this, though. Because child structures and inheritance are mostly defined in KVlang rather than Python, ordinary design patterns don’t… quite work. I’m in a better position to figure this out now than before I wrote any code, of course.
Here’s the structure.
I’ve got one class (widget if you’re speaking KVlang) which controls which of the other classes is being displayed. I’m calling it a window manager. Of course, in each of the “child” classes (which don’t actually inherit anything from the window manager), there’s at least one button that’s supposed to trigger the window manager and make it display a different page.
You can’t just randomly call them from other classes. The page-switcher methods need an instance of the window manager to work. And I can’t just put the page-switcher methods in the child classes. The reason the window manager exists is that it’s the only part of the program that knows how to do that sort of thing.
So, there isn’t… really a hierarchy in the Python file. It’s mostly just there to define any logical back-end that the KVlang file might need.
The KVlang file has hierarchy all over the place. It basically declares everything.
Anyway, I’ve got this window manager. Underneath it I have the main page that lists categories of documents (“Business Cards”, etc) and each of those categories has (will have; I’m only working with one right now) its own instance of IndexPage to display the documents in that category. Each category also has an Add page for new entries.
It’s not that complicated! It shouldn’t be this complicated! It’s still complicated!
(an hour later)
As you can tell, I’m still getting my head around Kivy.
Basically, whenever you need to do stuff that crosses over different classes, you have to make your method calls in Kivy. Kivy keeps basically all the class instances in memory. This gets kinda tricky if you lose track of things though.
I do need to clean up the Kivy inheritance… and then stop bashing my head against trying to make things happen in the Python file that just can’t happen in the Python file. Sigh.