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.
Another newbie question: How to get a view created on the iPad to resize or scroll around on iPhone
-
I just got an iPhone, and have a bunch of scripts with UIs that I developed on the iPad. When I brought them over to the iPhone, they don't resize or scroll, so many of the entry fields and buttons are not accessible. Is there a way to fix this without recreating the pyui file from scratch?
Thanks!
-
One way may be to set the resizing behavior of each sub view. This can be done in the 'Frame / Auto-Resize' section of the attributes for each sub view.
-
@michael_rechione - I don't have an iPhone but am also interested in what the best practices are for ui development of a script using Pythonista. I would like to package my scripts that have ui in a way that adapts to either iPad or iPhone and also deal with rotation between portrait and landscape. I have not yet seen an example script that does all of this and most users seem to be completely cloning their apps in order to supply a unique ui for each situation. The latest example of this is FileViewer that got cloned and turned into PhoneViewer (nice and usefull apps by the way).
RANT: It pisses me off that we are in the year 2015 and we still have not figured out how to write apps with scalable user intterfaces that adapt to different screen sizes and orientations automatically. Of all platforms - the Apple platform should have nailed this using vector graphics IMHO - but it did not happen.
NOTE: This has probably been discussed before and I expect @ccc will jump in with a reference to a thread that covers this :-)
-
ui.Scrollview allows a view that is larger that the available screen real estate. You could wrap your existing code in that. Probably better to determine the size and have a dirent layout that is more in line with iPhone. I am facing this with one of my apps.
-
I just spent an hour moving controls around, changing font sizes, resizing things so the UI would fit on the phone. As porting an app goes, an hour isn't that bad, I guess. But still - it would be nice if there were a more elegant way to do this, and I'll bet their probably is...
For example, the phone I got was an iPhone6. Would I need to mess around with the UI for each different screen size?
-
@RANT, the main issue is that the more easy or automatic compatibility you get, the less freedom and possibilities you have. If you wrote a (web) app using minimal HTML and forms, you could run that on many platforms without problems - phones, tablets, desktop computers or text-only terminals even - all the text and form elements would somehow wrap properly. Apple's UI framework is much more powerful than that - you have a variety of elements that can be arranged freely - but because of that freedom the framework can't tell right away how the layout is supposed to be on different screen sizes, so it just leaves everything unchanged by default.
The easiest way to fix this is to first of all set proper flexing behavior for all elements - that way small changes in screen size (iPhone 4/5/6/6+) won't be an issue anymore. If you're lucky that might be all that you need to do, but in most cases you'll want to have a "small screen" and "large screen" version of your UI, both with proper flexing configuration. Then add a simple screen width check to determine which version to use (width < 700 generally means you're on an iPhone) and the rest is scaled automatically.
-
@dgelessus - your response is quite practical and greatly appreciated. I probably should not rant on Apple for these difficulties since I do not really know enough about the Framework that the ui module is based on. I have recently been assuming that @omz has put a fairly thin Python binding over the native gui development tools except for the pyui file thing which does not seem to be based on an Apple/objc framework class. I should probably take the time to read about their architecture and how they deal with flexible layouts and widgets in order to see how this maps onto his implementation.
If you have a pointer to a good developer reference that would be good for a Pythonista ui module user - please pass it along. I found this site http://www.raywenderlich.com, which has a 12 part video tutorial on a "autolayout" library. Bad sign that it is a library AND takes 12 videos to say how use it, but it seems very well done.
I think it is worthwhile to explore this from the HTML5/JS angle at this time. There are some Python based projects already out there that attempt to use webviews for their entire UI. @JonB and @ccc have recently enumerated some pain points with doing this in Pythonista in the recent worldmap thread. It is still pretty compelling.
I ran into a project called device.js (https://github.com/borismus/device.js) that gets into many of the issues you mention above and has a sample app "todo list" that works in the webview and changes based on whether you are on a desktop - tablet - phone. The author is currently exploring what this may look like when we have 3D VR glasses as part of our user interfaces - which looks like it may be coming quite soon :-)
-
@wradcliffe, I know almost nothing about the real UIKit either and have only used the Pythonista interfaces in the
ui
module. The concept applies to a lot of things though, convenient "magic" always comes with some restrictions.Low-level vs. high-level programming languages have the same problem. Using C you can somehow control almost any part of your computer, both hardware and software, but you better be sure that ints are as long as you expect them to or things will go wrong. Higher-level languages like Java, Python, Ruby, etc. take care of many compatibility issues for you, but some things can only be done with C extensions and you most certainly can't write device drivers. Brainfuck is perhaps the most portable and platform-independent language out there, but it lacks any features beyond basic memory operations and standard input/output access.