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.
Calling NSLog from Pythonista
-
Hi everybody,
I am trying to debug a Pythonista script which I'm using with the PythonistaAppTemplate in XCode. I would like to use NSLog to output messages to the XCode console but I don't know how to access it. Can anybody help ?
Thanks in advance
Cheers
Andre Descombes -
@amdescombes see
https://github.com/dimaqq/pios/blob/master/app_packages/nslog.pyThis is based in Rubicon which is similar but also a bit different from objc_util.
The basic idea:
NSLog shows up as objc_util.c.NSLog.
Set NSLog.argtypes =[c_void_p, c_void_p], NSLog.restype=None.When you call first argument must be ns('%@'), and second arg is ns('string I want to log'). You could create a wrapper as shown in this example which does that for you..
I have not tried, but something like:
def NSLog(msg): _nslog=c.NSLog _nslog.argtypes=[c_void_p, c_void_p] _nslog.restype = None _nslog( ns('%@'), ns(msg) )
-
Thank you so much Jon, that worked like a charm! Now I can debug within XCode.
I'm having difficulties with Custom ListViews that I hope to solve, they work fine within Pythonista but once they are on the simulator not anymore or the phone :(Cheers
Andre -
No prob. Do post back your findings if they might apply to others..
-
Hello everybody,
I found what was not working with the creation of my TableView using the PythonistaAppTemplate
When you use the following syntax it doesn't work:
tbl = ui.TableView(frame=(0, 0, 400, 600))
You have to do it in two lines and then it works, like so:
tbl = ui.TableView() tbl.frame = (0, 0, 400, 600)
I hope this can be useful, it took me a long time to find out what was wrong.
Cheers
Andre -
Hi again,
I changed Jon's NSLog function to make it a little bit more efficient:
from objc_util import c, ns, c_void_p, c_void_p _nslog = c.NSLog _nslog.argtypes = [c_void_p, c_void_p] _nslog.restype = None def NSLog(msg): _nslog(ns('%@'), ns(str(msg)))
I think it would be nice if it could be added to the objc_util package directly, as it has been very useful to me.
Notice I cast the msg parameter into a string, that way you can pass anything you want to it and it will output that to the XCode console.Cheers
Andre