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.


    How to get key pressing in scene module?

    Pythonista
    ui module scene module
    3
    40
    4828
    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.
    • cvp
      cvp @JonB last edited by cvp

      @JonB

      def pressesBegan_withEvent_(_self, _cmd, presses, Event):
      

      is not refused but not called when I press a key on my Bluetooth keyboard

      		print(cvc.touchesBegan_withEvent_.encoding)
      

      Gives b'v32@0:8@16@24'

      		print(cvc.pressesBegan_withEvent_.encoding)
      

      Gives the same

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

        @JonB @cvp thanks for your helping and I will never forget your helpings

        1 Reply Last reply Reply Quote 0
        • yaley
          yaley @yaley last edited by

          @JonB do you have your ios device now?

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

            @cvp @JonB
            Finally!!!
            i run this code with SUCCESS!
            thank you for your helpings!

            from objc_util import *
            import ui
            
            UIViewController = ObjCClass('UIViewController')
            
            
            # Some callback definitions used by create_objc_class
            def CustomViewController_pressesBegan_withEvent_(_self, _cmd, _presses, _event):
            	print('pressesBegan_withEvent')
            	presses = ObjCInstance(_presses)
            
            
            # The main class...
            class MyView(ui.View):
            	def __init__(self):
            		super().__init__(self)
            		self.background_color = 'gray'
            
            	@on_main_thread
            	def init(self):
            		v = ui.View()
            		v.frame = self.frame
            		tf = ui.TextField()
            		tf.frame = (10, 10, 200, 32)
            		v.add_subview(tf)
            		vo = ObjCInstance(v)
            		#print(vo)
            		#print(dir(vo))
            
            		# set up the custom view controller
            		methods = [CustomViewController_pressesBegan_withEvent_]
            		protocols = []
            		CustomViewController = create_objc_class(
            			'CustomViewController',
            			UIViewController,
            			methods=methods,
            			protocols=protocols)
            		cvc = CustomViewController.alloc().init()
            		cvc.view = vo
            
            		# internal scheming...
            		self_objc = ObjCInstance(self)
            		self_objc.nextResponder().addChildViewController_(cvc)
            		self_objc.addSubview_(vo)
            		cvc.didMoveToParentViewController_(self_objc)
            
            		tf.begin_editing()
            
            if __name__ == '__main__':
            	v = MyView()
            	v.present('fullscreen')
            	v.init()
            
            cvp 1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

              I was wondering if the issue was lack of focus. Some documentation says the view must be in the responder chain of the focused view. It might be possible to do without the textfield, if we create a custom view that implements canBecomeFocused(), though I'm not sure how to then force it to take focus.
              By having a textview, I guess that's taken care of, although I'm a little surprised that the textview doesn't eat the event itself.

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @yaley last edited by

                @yaley πŸ‘

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

                  @cvp @JonB Again thank you for helping me a lot :D i was a python coder before, and i started learn js, nodejs, html for web development. But after my friend introduced Pythonista to me, i started to code python again, but i was using pygame module before (xD) and i was puzzled when using scene module, but now, it’s not, but ofc questions cannot be avoided, so i asked you @JonB and @cvp you both helped me a lot!

                  ( lastly, i want to tell you that i am 10 years old, i think you are confused and amazed, XD )

                  cvp 2 Replies Last reply Reply Quote 0
                  • cvp
                    cvp @yaley last edited by

                    @yaley said

                    i am 10 years old

                    I'am 70 and at 10, I only was playing with Lego, you're an happy guy to have such tools πŸ˜‚

                    1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @yaley last edited by

                      @yaley said

                      i was a python coder before

                      as you are only 10 years old, when you say "before", do you mean in another life? Reincarnation? πŸ˜‚

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

                        @JonB said

                        I'm a little surprised that the textview doesn't eat the event itself.

                        Is an ui.TextField an UIViewController? Because the called method is only for such an object

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