@ccc I'm trying to implement the best practices you set out. I have some queries please...
1 init() with no parameters and no final pass to View.init() is because all params are optional, right? And we know that View does nothing there other than initialise the options?
7/8 I find the act of adding a subview already makes it a member variable?
9/10 when making View the target/delegate of its subviews what style do you recommend to identify which sender/delegator of possibly many of the same class? (the neatest I've found is below)
Before making View the target/delegate:
class wvDelegate (object):
def webview_did_finish_load(self, webview):
if id(webview) == id(webview.superview.wv1):
console.hud_alert('1')
elif id(webview) == id(webview.superview.wv2):
console.hud_alert('2')
elif id(webview) == id(webview.superview.wv3):
console.hud_alert('3')
Or... after:
def webview_did_finish_load(self, webview):
if id(webview) == id(self.wv1):
console.hud_alert('1')
elif id(webview) == id(self.wv2):
console.hud_alert('2')
elif id(webview) == id(self.wv3):
console.hud_alert('3')
Or... put more simply:
def webview_did_finish_load(self, webview):
if webview is self.wv1:
console.hud_alert('1')
elif webview is self.wv2:
console.hud_alert('2')
elif webview is self.wv3:
console.hud_alert('3')
Best practices:
1 ui.View is the only class in ui module that can be subclassed so take advantage of it. Every time you create a ui.View, consider making it a custom subclass of ui.View. It will give you the ability to build more complex yet comprehensible apps.
2 Each ui element that gets added as a subview to your ui.View should have its own make_xxx() method.
3 Consider what method parameters will maximize the reusability of your make_xxx() method.
4 Near the beginning of the make_xxx() method, there should be a local_variable = ui.xxx() type of call.
5 The make_xxx() method should not assume that the ui element will be a member variable of your ui.View.
6 The make_xxx() method should only focus on the xxx element and should not mention other ui elements.
7 Near the end of the make_xxx() method, the ui element should be attached as a subview via self.add_subview(xxx) or similar.
8 make_xxx() should return the xxx object created so your ui.View can make it a member variable if it wishes to.
9 Consider making your ui.View the target of all .actions of its subviews.
10 Consider making your ui.View the delegate of its subviews.
11 Try to keep the complexity of view logic inside the class and keep everything else (reading files, networks, complex formatting) outside the class