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.


    dialogs.text_dialog() size

    Pythonista
    3
    8
    1870
    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.
    • tbrown313
      tbrown313 last edited by

      Is there any way to control the size of the text_dialog?

      I have set a fixed width font for the dialog (Courier 12). On my iPad Pro the dialog width is 68 characters. However, on my iPhone 7, it is only 50.

      Is there a way to get the character size of the dialog that will be displayed?

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

        @tbrown313 text_dialog presents the view as a sheet of width=500 which can contain 68 characters with font Courier 12.
        But sheet does not exist on iPhone, doc says

        we call the View.present() method to get the main view on screen. 
        Views can be presented with different styles. 
        On the iPhone, all views are presented in full-screen, but on the iPad, 
        you can choose between 'sheet', 'popover' and 'fullscreen'. 
        

        So...for an iPhone, width will be

        ui.get_screen_size()[0] 
        
        1 Reply Last reply Reply Quote 0
        • Jenkins
          Jenkins last edited by Jenkins

          We can use alert dialog to pause the user interaction with the current screen and show some intermediate action to the user like show error, take user email to process next step kind of stuff upsers

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

            @tbrown313 you could try on your both devices:

            import dialogs
            from objc_util import *
            import ui
            
            def main():
            	device = ObjCClass('UIDevice').currentDevice()
            	if 'ipad' in str(device.model()).lower():
            		w = 500
            	else:
            		w = ui.get_screen_size()[0]
            	font = ('Courier',12)		
            	lc = ui.measure_string('A', font=font)[0]
            	
            	tvo = ObjCInstance(ui.TextView())
            	p = tvo.positionFromPosition_offset_(tvo.beginningOfDocument(), 0)
            	rge = tvo.textRangeFromPosition_toPosition_(p,p)
            	x = tvo.firstRectForRange_(rge).origin.x
            	#x = 5
            	
            	nc = int((w-2*x)/lc)	
            	f = dialogs.text_dialog(text='A'*nc, font=font)	
            	
            # Protect against import	
            if __name__ == '__main__':
            	main() 
            
            1 Reply Last reply Reply Quote 1
            • tbrown313
              tbrown313 last edited by

              Thanks a lot for the code example, @cvp. This helps a lot. It makes it simple to figure out the best combination of font size and characters per line.

              This is probably sufficient for my purposes on the iPad since the default size is big enough. I would be interested to know how to select 'sheet', 'popover', or 'fullscreen' however. The documentation on dialogs.text_dialog() doesn't show how to do this.

              Also, if I don't have an external keyboard connected (which I never have connected on my iPhone), is there any method to get rid of the onscreen keyboard when the dialog first shows? In this particular case, I don't want the dialog text to be editable. I thought I had seen something about setting editable to false, but can't find the reference.

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

                @tbrown313 don't use dialog if you want to

                • use sheet, popover, ....
                • decide the size of the view
                • make the text non editable
                from objc_util import *
                import ui
                
                def main():
                	device = ObjCClass('UIDevice').currentDevice()
                	if 'ipad' in str(device.model()).lower():
                		w = 500
                		h = 500
                	else:
                		w,h = ui.get_screen_size()
                	font = ('Courier',12)		
                	lc = ui.measure_string('A', font=font)[0]
                	
                	tv = ui.TextView()
                	tv.frame = (0,0,w,h)
                	tv.font = font
                	tv.editable = False
                	
                	tvo = ObjCInstance(tv)
                	p = tvo.positionFromPosition_offset_(tvo.beginningOfDocument(), 0)
                	rge = tvo.textRangeFromPosition_toPosition_(p,p)
                	x = tvo.firstRectForRange_(rge).origin.x
                	#x = 5
                	
                	nc = int((w-2*x)/lc)	
                	tv.text = 'A'*nc
                	tv.present('sheet')
                	
                # Protect against import	
                if __name__ == '__main__':
                	main() 
                
                1 Reply Last reply Reply Quote 0
                • tbrown313
                  tbrown313 last edited by

                  Again, @cvp, thanks a lot for the code. Using the GUI is problematic since much of what I do involves grabbing data from a server, doing something with it, then calling another app using web browser.open(url). When that is done within a Pythonista GUI script, it leaves the GUI window running in Pythonista. My flow is like this:

                  1. Run a shortcut from the Shortcuts app.
                  2. Shortcut calls a Pythonista script.
                  3. Pythonista script makes a remote server call to get data, perhaps display it, perhaps copy to clipboard.
                  4. Pythonista script calls another app using web browser.open(url)
                  5. Other app opens and I do some stuff.

                  I consider this operation done, but Pythonista still has the GUI on screen if you enter the Pythonista App. So, when I do this same operation again, and the shortcut calls Pythonista, I now have two GUI windows stacked in Pythonista. This does work, but it seems clumsy and fraught with unknown problems.

                  So, when I have a process like this, I have been making do with the dialogs module in Pythonista, which doesn't have this problem--but has other limitations.

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

                    @tbrown313 A last solution is to copy the standard dialogs source code and modify as you want in your own version.

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