Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[Share] Cancel - OK btn view
-
A lazy Sunday :) I just thought I would share this small thing I did. It's very simple. It's just a function that returns a view that has a Cancel and OK button. When making a ui is a good chance you will need something like this over and over again. My implementation may not be to your liking, but it makes sense to me to have some code like this in a snippet for example.
I didn't go for super flexibility, just the basics of what I would normally require. Stupidity enough, I didn't have a function like this as a snippet, but i will do now. I probably should have made the padding numbers variables.import ui def cancel_ok_view(action=None, **kwargs): ''' returns a ui.View with a Cancel and OK buttons. The action is shared, so you will have to check the name or title for the logic -Note the **kwargs age passed to the ui.View ''' def make_btn(name, title, action=None, **kwargs): btn = ui.Button(name=name, title=title, border_width=.5, corner_radius=6, bg_color='white', action=action ) btn.width = 100 return btn v = ui.View(frame=(0, 0, 215, 40), **kwargs) ok_cancel = make_btn('cancel', 'Cancel', action=action) v.add_subview(ok_cancel) ok_cancel.x = 5 ok_cancel.y = 4 ok_btn = make_btn('ok', 'OK', action=action) v.add_subview(ok_btn) ok_btn.x = ok_cancel.frame.max_x + 5 ok_btn.y = 4 return v class MyClass(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.make_view() def make_view(self): v = cancel_ok_view(bg_color=None, action=self.btn_action) v.y = self.height - v.height v.x = self.width - v.width self.add_subview(v) def btn_action(self, sender): print('Button named {} pressed'.format(sender.name)) self.close() if __name__ == '__main__': f = (0, 0, 320, 480) mc = MyClass(frame=f) mc.present('sheet')