omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Custom View Class - in pyui files.... [tip]

    Pythonista
    view custom tip class pyui
    2
    3
    4979
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Phuket2
      Phuket2 last edited by

      Ok, I feel foolish, I was after this functionality for a long time in pyui files and it's just been sitting there, God knows for how long. Maybe 1.6 😱

      So, if you create a pyui file in the designer. Add a Custom View Control from the add menu to it. Then in the Custom View Class (property sheet) for that view in designer, add the class name of a Custom uiView that you have defined in your code.

      Presto, that class is the class used as the ui.View.

      Look, I know many just know this. But there are so many things that are possible, hard to keep up with it all.

      Anyway, below is sample code. Just need to create a pyui file. Very simple one.

      import ui
      
      class OwnerDrawn(ui.View):
      	def __init__(self, *args, **kwargs):
      		super().__init__(*args, **kwargs)	
      		
      	def draw(self):
      		s = ui.Path.oval(*self.bounds)
      		ui.set_color('red')
      		s.fill()
      
      if __name__ == '__main__':
      	w, h = 600, 800
      	f = (0, 0, w, h)
      	# load a standard pyui file as normal. In the pyui file, there is
      	# a custom View Control. its Custom View Class property in the 
      	# pyui file is set to OwnerDrawn.  
      	v = ui.load_view('Search_bar')
      	v.present('sheet')
      
      1 Reply Last reply Reply Quote 0
      • Webmaster4o
        Webmaster4o last edited by

        This has been there since before 1.6. It was in 1.5, iirc.

        Phuket2 1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 @Webmaster4o last edited by

          @Webmaster4o , lol does not surprise me. But let's face it a lot of little treasures in Pythonista.
          I wish they could all be documented, but I understand why they are not. It would take a big chunk out of the development time. I can't remember how long I have had Pythonista now, but I am astounded how much it has evolved in that short time.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Powered by NodeBB Forums | Contributors