Forum Archive

Can't yet grasp the process how Pythonista works with exporting app into Xcode and making iOS app?

idchlife

I'm using Pythonista now to make iOS app with several requests, asyncio, sqlalchemy and image parts working together.

Simple interface, several images fpr design of app, etc

I did not yet try to export it to Xcode and I wanted to ask if someone knows how this whole thing works?

I have default folder for application. I can open("filename") there and create a file.

I create .sql file for sqlite via sqlalchemy
I save files into this app folder when I download them from the internet.

Will all of those things work after making it into iOS app?
Does iOS allow for such things as saving your app files there, in the app folder?

Or should I be aware of some major constraints for making iOS apps in Pythonista?

It's very convinient for me to write in Pythonista iOS app since my backend is in Python also.

Thanks!

Gadgettyke

I’m in the same boat. Have had my app tested by friends and ready to go. If someone has a good tutorial on the process for pythonista (python 3.6) I’d find it of great help and interest.

RomSpy

You will need to download the Pythonista Xcode template from github
https://github.com/omz/PythonistaAppTemplate

Then you will have to modify it to meet apples current restrictions
https://forum.omz-software.com/topic/3744/xcode-template-for-pythonista

Your script goes in the script folder of the template. I have an app in the store that uses sql and downloading files with no problems.

mikael

@Gadgettyke, looks like there is still no solution for Python 3, so you would need to downgrade to Python 2 to make this work.

Gadgettyke

Ah ha I see says the blind man!

No wonder I've had no luck... Right, anyone know of a 3 to 2 translator :-):-):-)

The program is simple enough so I'll give it a go.

Cheers
and many thanks.

dgelessus

@Gadgettyke https://pypi.org/project/3to2/

Gadgettyke

Update

I have down graded my code to 2.7 (many thanks mikael ) and have it sitting in Xcode and working on simulator and my iPhone, with a helping hand from jonB to get the TextField behaving properly so I’m ready to upload to the App Store apart from two persistent errors in Xcode which say
1, I’m calling to ui from not main thread, I have moved all calls into the main but still have one error remaining.
2 calling console time out disabled from outside main thread

Annoyingly I can’t get rid of them, any ideas

mikael

@Gadgettyke, ”I have moved all calls into the main” – just to be sure: do you mean you have moved them to a main() function in your code, or are using the objc_util decorator on all functions?

Gadgettyke

Errr.. moved into main() which stopped most of the original errors except this one. Sounds like I’ve now gotta learn objtc_utils.

Any good pointers to an idiots guide? Or an example please.😁

JonB

So, anything which updates the ui should be on the ui thread. Callbacks happen automatically, but if you have some knd of timer which updates the ui, you may need to use objc_util.on_main_thread.

if you gist your code we can take a look

Gadgettyke

https://gist.github.com/2dda361f2c076e2c584d8e93012cfdb2

If I’ve done it correctly it should be there. For some reason I kept getting status code 0 like last time and then it sailed through.

It might have a few decorators in the wrong places as I’ve been experimenting.

JonB

@Gadgettyke said:

calling console time out disabled from outside main thread

It would be helpful if you copy/paste the full and exact error message...

your labelN_update methods should have on_main_thread decorators.
Any place you change colors or set text should also be so decorated.

Gadgettyke

so before every def addressing the ui use the on_main_thread decoration. 👍

The console commands I had #’d out that’s why it’s not faulting in that version I sent but I’ll post the screenshot tomorrow.

Many thanks for you help guys.

Gadgettyke

HI Gents

Right I've played with the on_main_thread and the ui.in)background and its made no difference.

what I have found is that its the v.present('sheet') command that's causing the problem, I have printed the error messages below

=================================================================
Main Thread Checker: UI API called on a background thread: -[UIView subviews]
PID: 11972, TID: 374078, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   PythonistaKit                       0x00000001047e1247 View_get_view + 214
5   PythonistaKit                       0x00000001047ecb1f View_mapping_get_item + 61
6   PythonistaKit                       0x00000001046e1c25 PyEval_EvalFrameEx + 15881
7   PythonistaKit                       0x00000001046e4159 fast_function + 282
8   PythonistaKit                       0x00000001046de3de PyEval_EvalFrameEx + 1474
9   PythonistaKit                       0x00000001046ddbda PyEval_EvalCodeEx + 1576
10  PythonistaKit                       0x00000001046dd5ac PyEval_EvalCode + 54
11  PythonistaKit                       0x0000000104773710 run_mod + 53
12  PythonistaKit                       0x00000001047737b3 PyRun_FileExFlags + 133
13  PythonistaKit                       0x0000000104773302 PyRun_SimpleFileExFlags + 698
14  PythonistaKit                       0x00000001046b203a -[PythonInterpreter runWithOptions:] + 2265
15  PythonistaKit                       0x00000001046b2363 -[PythonInterpreter doDispatchBlockOnInterpreterThread:] + 97
16  Foundation                          0x00000001052acc7b __NSThreadPerformPerform + 330
17  CoreFoundation                      0x00000001061da721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18  CoreFoundation                      0x00000001061d9f93 __CFRunLoopDoSources0 + 243
19  CoreFoundation                      0x00000001061d463f __CFRunLoopRun + 1263
20  CoreFoundation                      0x00000001061d3e11 CFRunLoopRunSpecific + 625
21  Foundation                          0x0000000105297322 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 277
22  Foundation                          0x0000000105297534 -[NSRunLoop(NSRunLoop) runUntilDate:] + 143
23  Foundation                          0x00000001052ac732 __NSThread__start__ + 1221
24  libsystem_pthread.dylib             0x000000010d19633d _pthread_body + 126
25  libsystem_pthread.dylib             0x000000010d1992a7 _pthread_start + 70
26  libsystem_pthread.dylib             0x000000010d195425 thread_start + 13
2018-11-15 16:21:54.014317+0000 My App[11972:374078] [reports] Main Thread Checker: UI API called on a background thread: -[UIView subviews]
PID: 11972, TID: 374078, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   PythonistaKit                       0x00000001047e1247 View_get_view + 214
5   PythonistaKit                       0x00000001047ecb1f View_mapping_get_item + 61
6   PythonistaKit                       0x00000001046e1c25 PyEval_EvalFrameEx + 15881
7   PythonistaKit                       0x00000001046e4159 fast_function + 282
8   PythonistaKit                       0x00000001046de3de PyEval_EvalFrameEx + 1474
9   PythonistaKit                       0x00000001046ddbda PyEval_EvalCodeEx + 1576
10  PythonistaKit                       0x00000001046dd5ac PyEval_EvalCode + 54
11  PythonistaKit                       0x0000000104773710 run_mod + 53
12  PythonistaKit                       0x00000001047737b3 PyRun_FileExFlags + 133
13  PythonistaKit                       0x0000000104773302 PyRun_SimpleFileExFlags + 698
14  PythonistaKit                       0x00000001046b203a -[PythonInterpreter runWithOptions:] + 2265
15  PythonistaKit                       0x00000001046b2363 -[PythonInterpreter doDispatchBlockOnInterpreterThread:] + 97
16  Foundation                          0x00000001052acc7b __NSThreadPerformPerform + 330
17  CoreFoundation                      0x00000001061da721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18  CoreFoundation                      0x00000001061d9f93 __CFRunLoopDoSources0 + 243
19  CoreFoundation                      0x00000001061d463f __CFRunLoopRun + 1263
20  CoreFoundation                      0x00000001061d3e11 CFRunLoopRunSpecific + 625
21  Foundation                          0x0000000105297322 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 277
22  Foundation                          0x0000000105297534 -[NSRunLoop(NSRunLoop) runUntilDate:] + 143
23  Foundation                          0x00000001052ac732 __NSThread__start__ + 1221
24  libsystem_pthread.dylib             0x000000010d19633d _pthread_body + 126
25  libsystem_pthread.dylib             0x000000010d1992a7 _pthread_start + 70
26  libsystem_pthread.dylib             0x000000010d195425 thread_start + 13

and its saying that there is no thread name and its therefore calling it a background call. I put the call into a def and on_main_thread but the message does not change.

@on_main_thread
def setscreen(v,stdtime):
    #v=ui.load_view('cql.pyui')
    v.present('sheet')
    v.background_color = '#00ffff'
    label4 = v['label4']
    label5 = v['label5']
    console.set_idle_timer_disabled(True)


def main():
    state=load_state('setup.json')  
    stdtime = state
    load_timers(timer1,timer2,stdtime)
    # print timer1,timer2
    v = ui.load_view('cql')
    v.background_color = '#00ffff'
    .
        .
    #v.present('sheet')
    setscreen(v,stdtime)
    onscreen = v.on_screen
    if onscreen is False:
            console.set_idle_timer_disabled(False)
            return False

Note not full code shown see previous post for gist.

Any thoughts? The code works - its just this error I can't get rid of!

JonB

It is complaining about subviews, not present. So search your code for whenever you call subviews, or do v[name], and wrap that in on_main_thread.

Are you sure this is an error, and not just a warning? From what I read, you can disable ThreadChecker.. these warnings are telling you that this is a bad practice... But if you are not adding/removing views, this seems low risk in this case.

JonB

Setvaluesonscreen definitely needs to be wrapped. And all of that business in main where you do v[...]

JonB

https://stackoverflow.com/questions/44943995/what-is-main-thread-checker-in-xcode-9

You can just disable main thread checker in XCode. There isn't really a problem with what you are doing, it will work fine as is.

Gadgettyke

Thanks

Ive wrapped set values and a few others, I'm pulling most of the v[..] stuff out of main and wrapping them. I think you're right about it being a warning as I messed up a cut and paste and got a completely different response all in red.

if the wrapping don't work I'll disable mtc and get it on test pilot. they can only complain lol.

Many thanks jonB.

Gadgettyke

Hi Gents

Well its still an ongoing saga.. I seem to have got something wrong. The app worked well until I archived it and then when I pushed up to apple it came back with a bunch of errors. So started to look through the code and tried to build it again and then it started giving the following error and failing the build.

ld: warning: ignoring file /Users/schilds/Desktop/PythonistaAppTemplate- Master/PythonistaAppTemplate/PythonistaKit.framework/PythonistaKit, missing required architecture x86_64 in file /Users/schilds/Desktop/PythonistaAppTemplate- Master/PythonistaAppTemplate/PythonistaKit.framework/PythonistaKit (2 slices)
Undefined symbols for architecture x86_64:
"OBJC_CLASS$PAConsoleImageView", referenced from:
objc-class-ref in libpythonista_appui.a(PAStandaloneOutputView.o)
"_CanvasGetImage", referenced from:
-[PAStandaloneOutputView canvasFlushed:] in libpythonista_appui.a(PAStandaloneOutputView.o)
"_IsWaiting", referenced from:
-[PAStandaloneOutputView textFieldShouldReturn:] in libpythonista_appui.a(PAStandaloneOutputView.o)
"_LineRead", referenced from:
-[PAStandaloneOutputView textFieldShouldReturn:] in libpythonista_appui.a(PAStandaloneOutputView.o)
"_OBJC_CLASS
$PythonInterpreter", referenced from:
objc-class-ref in PAAppDelegate.o
objc-class-ref in libpythonista_appui.a(PAStandaloneOutputView.o)
"_OBJC_CLASS
$_PAEExtensionContext", referenced from:
objc-class-ref in PAAppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't think its the template but any suggestions please...