I just created a tiny package that can make responsive apps easier to build.
Using it is simple. You just add a decorator to your form like this
from responsive import responsive
@responsive.form
class Form1(Form1Template):
...
And then, you can add two methods, to your form, on_mobile
and on_pc
.
def on_mobile(self):
self.label_1.spacing_above='small'
#Any other changes to your components or general code
def on_pc(self):
self.label_1.spacing_above='large'
#Any other changes to your components or general code
That way, you can specify separate code to be run depending on whether the user is using mobile or a larger device (laptop, desktop, tablets). You can also specify the width threshold (Default is 768px)
from responsive import responsive
responsive.pc_width_threshold = 600
#Now, any device having more than 600px will be treated as pc
Bonus Feature
This package also makes it easier to modify the css of a component directly using python.
responsive.set_css(self.label_1, 'padding-top','10px', important = True)
Nothing that wasn’t already possible but saves you the effort of typing a few extra lines
Lastly, here is a short example app