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.


    Pythonista special key row problems in IOS 14

    Pythonista
    ipados14
    6
    26
    9149
    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 @Enez Houad last edited by cvp

      @Enez-Houad Good job. I let real Python specialists like @ccc, @mikael and other ones advice you about Python it-self, they are far ahead of me

      For those who want to see the keyboard

      And even horizontally scroll this first row, whaaaa

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

        @cvp I learn a lot adapting your scripts to my needs !
        You will find after this message my/your script to add a keyboard icon in the titlebar to call my script to add my special key row to the keyboard.
        The system is rather practical, but to make the handling as transparent as possible : when I add my key row, I hide the keyboard with tv.endEditing(True), and I would like to make it reappear with my special key row : but I’ve not found a command as simple as tv.startEditing 🙁 ; it’s perharps possible to simulate a touch in the TextView, but I neither can’t find a solution to do it 🥶
        After several hours of searching, I throw in the towel and ask for help…🥵

        from objc_util import *
        import ui
        from ui3.sfsymbol import *
        
        w = ObjCClass('UIApplication').sharedApplication().keyWindow()
        main_view = w.rootViewController().view()
        
        def get_toolbar(view):
        	# get main editor toolbar, by recursively walking the view
        	sv = view.subviews()
        	for v in sv:
        		if v._get_objc_classname().startswith(b'OMTabViewToolbar'):
        			return v
        		tb = get_toolbar(v)
        		if tb:
        			return tb
        			
        # ———————————————————————————————————————————————————————————————————
        
        def keyboard_btn_action(sender):
        	
        	def run_script(scriptPath):
        		import os
        		from objc_util import ObjCInstance,ObjCClass
        	
        		dir = os.path.expanduser(scriptPath)
        		I3=ObjCClass('PYK3Interpreter').sharedInterpreter()
        		I3.runScriptAtPath_argv_resetEnvironment_(dir, [''], True)
        
        	iCloudPath = "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/"
        	iPadPath = '~/Documents/'
        	scriptPath = 'PROJETS/KEYBOARD/my_special_key_row.py'
        	run_script(iCloudPath + scriptPath)
        			
        # ———————————————————————————————————————————————————————————————————
        
        def create_keyboard_button(action,index=0):
        	global __persistent_views
        	
        	assert(callable(action))
        	tb = get_toolbar(main_view)
        		
        	try:
        		__persistent_views
        	except NameError:
        		__persistent_views={}
        		
        	#check for existing button in this index and delete if needed
        	remove_toolbar_button(index)	
        	btn = ui.Button()
        	btn.frame = (110, 24, 40, 40)
        	
        	if ui.get_ui_style() == 'dark':
        		btn.tint_color = 'white' 
        	else:
        		btn.tint_color = '#0D89B5' 
        	btn.image = SymbolImage('keyboard', point_size=14, weight=THIN, scale=SMALL)
        	btn.image = btn.image.with_rendering_mode(ui.RENDERING_MODE_AUTOMATIC)
        			
        	btn.action=action
        	btn_obj=ObjCInstance(btn)
        	__persistent_views[index]=(btn,action)
        	tb.superview().superview().addSubview_(btn_obj) # in front of all buttons
        	
        	return btn
        	
        # ———————————————————————————————————————————————————————————————————
        	
        def remove_toolbar_button(index):
        	global __persistent_views
        	
        	try:
        		btn,action = __persistent_views.pop(index)
        		btn.action= None
        		ObjCInstance(btn).removeFromSuperview()
        	except KeyError:
        		pass
        
        # ===================================================================
        
        #if __name__=='__main__': # if imported by pythonista startup	
        		
        create_keyboard_button(keyboard_btn_action)	
        		
        create_keyboard_button(keyboard_btn_action)
        
        
        cvp 2 Replies Last reply Reply Quote 0
        • cvp
          cvp @Enez Houad last edited by

          @Enez-Houad try

          def keyboard_btn_action(sender):
              
              def run_script(scriptPath):
                  import os
                  from objc_util import ObjCInstance,ObjCClass
              
                  dir = os.path.expanduser(scriptPath)
                  I3=ObjCClass('PYK3Interpreter').sharedInterpreter()
                  I3.runScriptAtPath_argv_resetEnvironment_(dir, [''], True)
          
              iCloudPath = "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/"
              iPadPath = '~/Documents/'
              scriptPath = 'PROJETS/KEYBOARD/my_special_key_row.py'
              run_script(iCloudPath + scriptPath)
              
              @on_main_thread
              def disp_kbd():
                from editor import _get_editor_tab
                tab = _get_editor_tab()
                if tab:
                  tab.editorView().textView().becomeFirstResponder()
              disp_kbd()
          
          1 Reply Last reply Reply Quote 0
          • cvp
            cvp @Enez Houad last edited by cvp

            @Enez-Houad said:

            my/your script to add a keyboard icon in the titlebar

            I must admit with humulity that the most complex part of this code comes from @JonB 🤫

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

              @cvp Thanks a lot ! I’m happy to see that I progress slowly…
              I had found textView().becomeFirstResponder() but couldn’t find to witch element it had to be applied. The _get_editor_tab is not documented ! To find it, do you open editor.py in the site-packages of Standard Library ?
              It's very instructive 🤓, I'm going to end up managing on my own. 😉

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

                @Enez-Houad said:

                do you open editor.py in the site-packages of Standard Library ?

                Yes sir

                1 Reply Last reply Reply Quote 1
                • cvp
                  cvp last edited by

                  the problem gets worse, and don't ask me how it happens...

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

                    I begin to panic

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

                      With me on iOS 14.3 / iPad it seems to have something to do with the “darkmode” setting. When running in “light” mode the problem did not occur yet. When I switch back to dark mode, the extra keyboard row splits again after switching between file tabs in the editor.
                      so, maybe use light mode for Pythonista?

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

                        @janplxt said:

                        iPad it seems to have something to do with the “darkmode” setting.

                        I don't think so, see my first examples in the topic.

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