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.
Simple UI tutorial?
-
@PeterG http://omz-software.com/pythonista/docs/ios/ui.html#view Under View Attributes see View.flex... Hint, 'wh' is not a name.
-
@ihf, for the font you could just use Menlo or another mono spaced font (Menlo, is what is used in the console by default I think) . Anyway, I was not critising you at all. I just has similar problems when I started. There is a smalll bump to get over using the ui module, but it does fall into place pretty quickly. I did not try writing from prettytable into the TextField , However I can't see why it should not work. The only think that comes to mind could be you getting extra line feed chars in the text. If that were to happen you could do a replace on those chars either in the write_line method, or before you pass the string to write_line. Anyway, let me know if you have a problem, If will help if I can
tv = ui.TextView(frame=self.bounds, flex='wh', font=('Menlo', 24), editable=False, ) ```python
-
@ihf, I just updated the example to have a copy to clipboard and clear methods and menu items. Not sure they are useful, but good to see how to add menu Items anyway, if you haven't played with them yet.
My example is not as compact looking as it could be, but I try and following the PEP8 style now. Eg, only one import per line, 2 lines after the imports etc.import ui import clipboard import console class MyConsole(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.tv = None self.make_view() def make_view(self): tv = ui.TextView(frame=self.bounds, flex='wh', font=('Menlo', 24), editable=False, ) self.tv = tv self.add_subview(self.tv) ''' Create 2 ui.ButtonItem to insert into the menubar. ButtonItem's are one of those pesky ui Items that are not subclassed from ui.View Its not a big deal, just good to know they differ from ui.Button. You can see in the docs. Below, I am adding the 2 menu buttons to the right side as it seems to make sense. There is a method left_button_items also. ''' mbtn_clear = ui.ButtonItem(title='Clear', action=self.clear_console, tint_color='red') mbtn_copy = ui.ButtonItem(title='Copy', action=self.copy_console) self.right_button_items = (mbtn_clear, mbtn_copy) def write_line(self, txt): self.tv.text += "{}\n".format(txt) def clear_console(self, sender=None): ''' sender is set to None so sender is not required to call this method. The action from the menu ButtonItem needs to see it there though. But it means you can call this method on the object withouut having to pass a sender. i.e if youwanted to clear the console from your code rather than the menu button action. ie. obj.clear_console() will work. Same goes for the copy_console method below. ''' self.tv.text = "" def copy_console(self, sender=None): clipboard.set(self.tv.text) console.hud_alert('{} characters copied.'.format(len(self.tv.text))) if __name__ == '__main__': f = (0, 0, ui.get_screen_size()[0], ui.get_screen_size()[1]) v = MyConsole(frame=f, name='My Full Sceen Console') v.present(style='', animated=False) for i in range(100): v.write_line('line-{}'.format(i))