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.


    Intelli Sense for ui objects

    Pythonista
    3
    4
    1672
    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

      @omz, with the code below I was just exploring possibilities yet again. The below is not to bad.this or variations of this have been done before. Again, it's ok except the editor can not do its auto complete magic. As you can see it's a ui object wrapped in a class. A attr called ext is dynamically added to the ui object and points to the wrapping class.
      I have no idea if this is possible or not. But if a specific attr appeared in a ui class like ext or whatever you define, would it be possible to do the auto complete on the definitions that the attr was pointing to? And if you could do it, it's it something that you would consider doing?

      It's just a idea. Yeah, I know this has been tried to be solved many times over. I think the 2 step experiment below is ok. The major thing lacking is editor auto complete/ intelli sense support.

      '''
      	Pythonista Forum - @Phuket2
      '''
      import ui
      import math
      
      class UIObject(object):
      	def __init__(self, parent,  ui_type = ui.Button,  *args, **kwargs):
      		self.target = ui_type()
      		self.parent = parent
      		self.target.ext = self
      		self._rotate = 0
      		
      		self.do_kwargs(self.target, **kwargs)
      		parent.add_subview(self.target)
      		
      	@staticmethod
      	def do_kwargs(obj, **kwargs):
      		for k, v in kwargs.items():
      			if hasattr(obj, k):
      				setattr(obj, k, v)
      	@property
      	def me(self):
      		return self.target
      			
      	@property
      	def center(self):
      		self.target.center = self.parent.bounds.center()
      		
      	@property
      	def rotate(self):
      		return self._rotate
      		
      	@rotate.setter
      	def rotate(self, angle):
      		self.target.transform = self.rotatation_object(angle)
      		self._rotate = angle
      		
      	@staticmethod
      	def rotatation_object(angle):
      			return ui.Transform.rotation(math.radians(angle))
      	
      	@staticmethod
      	def get_ui_image(image_name):
      		return ui.Image.named(image_name)
      	
      	def set_image(self, image_name):
      		if not hasattr(self.target, 'image'):
      			print('Object does not have a image attr...')
      			return
      			
      		self.target.image = self.get_ui_image(image_name)
      		
      	def action_rotate_increment(self, sender):
      		# just a stupid test
      		self.rotate += 45
      		
      class MyClass(ui.View):
      	def __init__(self, *args, **kwargs):
      		super().__init__(*args, **kwargs)
      		
      		obj = UIObject(self, ui.Button, title = '', text_color ='deeppink')
      		btn = obj.me
      		btn.action = btn.ext.action_rotate_increment
      		btn.ext.set_image('iob:arrow_up_a_256')
      		btn.size_to_fit()
      		btn.ext.center
      		btn.ext.rotate = 90
      		
      		print(btn.ext.rotate)
      		
      		obj = UIObject(self, ui.Button, title = 'junk', text_color ='deeppink', border_width = .5)
      		btn2 = obj.me
      		btn2.size_to_fit()
      
      if __name__ == '__main__':
      	_use_theme = False
      	w, h = 600, 800
      	f = (0, 0, w, h)
      	
      	mc = MyClass(frame=f, bg_color='white')
      	mc.present('sheet', animated=False)
      

      No editor import 😱🎉

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

        @Phuket2 If not impossible, this turns out to be rather difficult. I spent some time experimenting with this a while back.. my solution effectively took a snapshot of your current python globals, then wrote a wrapper py file containing all of the in-use ObjCClasses to a special file which you have to import. Then you have to trigger a reload of that file in jedi.

        I forget how far I got, I think I had somethig partway functional, but decided it was not really worth the effort.

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

          @JonB , thanks. It was just a thought. If that issue could be bridged , it would see like one reasonable way fake subclassing ui elements. @omz has been quite for sometime. Personally I have a feeling he is going to give us a Big Bang soon. If not it does not matter I am happy with what we have... We will see I guess

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by ccc

            A Big Bang like golang on the iPad era what?

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