Ok, here is the gist:
https://gist.github.com/amdescombes/30839ae0280a5077b8669757e5efa75d
Cheers
Andre
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.
Ok, here is the gist:
https://gist.github.com/amdescombes/30839ae0280a5077b8669757e5efa75d
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
Hello everyone,
Here is a reworked script that adds the comments at the top but preservers coding= comments.
It is not perfect, but it helped me succesfully submit an app to the Appstore, I hope it is of help to every one.
#import pythonista
# Change the ********** to point to the directory containing the Pythonista framework :
project_path = '**********/PythonistaAppTemplate'
pylib_path1 = '%s/PythonistaKit.framework/pylib' % project_path
pylib_path2 = '%s/PythonistaKit.framework/pylib_ext' % project_path
MAX_REPEATS = 10
import shutil
import os
import subprocess
def check_is_executable(file_path):
file_output = subprocess.check_output(['file', file_path])
if 'executable' in file_output:
return True, file_output
return False, file_output
def fix_executable(file_path, dry_run=False):
with open(file_path, 'r') as f:
source = f.readlines()
if 'coding:' in source[0].lower():
firstline = source[0]
start = 1
else:
firstline = ''
start = 0
if dry_run:
if firstline:
print(firstline)
else:
with open(file_path, 'w') as f:
f.write(firstline + '#import pythonista\n' * MAX_REPEATS + ''.join(source[start:]))
is_executable, out = check_is_executable(file_path)
return not is_executable
def fix_pylib(pylib_path, dry_run=False):
print ("fixing", pylib_path)
for path, dirs, files in os.walk(pylib_path):
print(path, dirs, files)
for filename in files:
full_path = full_path = os.path.join(path, filename)
is_executable, file_output = check_is_executable(full_path)
if is_executable:
extension = os.path.splitext(full_path)[1].lower()
if extension in ['.py', '.pym'] or filename == 'command_template':
if dry_run:
print '### Executable found: %s' % (filename,)
fixed = fix_executable(full_path, dry_run)
else:
print 'Fixing %s...' % (filename,)
fixed = False
counter = 0
while not fixed:
fixed = fix_executable(full_path)
counter += MAX_REPEATS
print 'Fixed with '+str(counter)+' dummy lines.'
else:
print '### Executable found, but does not seem to be Python code: %s' % (full_path,)
if __name__ == '__main__':
fix_pylib(pylib_path1, False)
fix_pylib(pylib_path2, False)
Cheers
Andre
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
Thanks @mikashkin, I didn't think to look for them there :)
Andre
Thanks @ccc! now I can get those into PyCharm :-)
Andre
Hi Jon,
I think that is a very good question and a very interesting option to explore as it would avoid modifying the framework. I'll look into it as soon as I get a chance and report my findings back.
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
Hello everyone,
Here is a reworked script that adds the comments at the top but preservers coding= comments.
It is not perfect, but it helped me succesfully submit an app to the Appstore, I hope it is of help to every one.
#import pythonista
# Change the ********** to point to the directory containing the Pythonista framework :
project_path = '**********/PythonistaAppTemplate'
pylib_path1 = '%s/PythonistaKit.framework/pylib' % project_path
pylib_path2 = '%s/PythonistaKit.framework/pylib_ext' % project_path
MAX_REPEATS = 10
import shutil
import os
import subprocess
def check_is_executable(file_path):
file_output = subprocess.check_output(['file', file_path])
if 'executable' in file_output:
return True, file_output
return False, file_output
def fix_executable(file_path, dry_run=False):
with open(file_path, 'r') as f:
source = f.readlines()
if 'coding:' in source[0].lower():
firstline = source[0]
start = 1
else:
firstline = ''
start = 0
if dry_run:
if firstline:
print(firstline)
else:
with open(file_path, 'w') as f:
f.write(firstline + '#import pythonista\n' * MAX_REPEATS + ''.join(source[start:]))
is_executable, out = check_is_executable(file_path)
return not is_executable
def fix_pylib(pylib_path, dry_run=False):
print ("fixing", pylib_path)
for path, dirs, files in os.walk(pylib_path):
print(path, dirs, files)
for filename in files:
full_path = full_path = os.path.join(path, filename)
is_executable, file_output = check_is_executable(full_path)
if is_executable:
extension = os.path.splitext(full_path)[1].lower()
if extension in ['.py', '.pym'] or filename == 'command_template':
if dry_run:
print '### Executable found: %s' % (filename,)
fixed = fix_executable(full_path, dry_run)
else:
print 'Fixing %s...' % (filename,)
fixed = False
counter = 0
while not fixed:
fixed = fix_executable(full_path)
counter += MAX_REPEATS
print 'Fixed with '+str(counter)+' dummy lines.'
else:
print '### Executable found, but does not seem to be Python code: %s' % (full_path,)
if __name__ == '__main__':
fix_pylib(pylib_path1, False)
fix_pylib(pylib_path2, False)
Cheers
Andre
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
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
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
Hi Mark,
Synchronator seems great, unfortunately I keep getting this error when I run it on Pythonista 3 using Python 3.5.
I used StaSh pip install to install the latest dropbox and requests to no avail, here is the stack trace, it seems to be a timeout problem :(
Updating From Dropbox
Dropbox File Syncronization *
Loading Local State
Cannot Find State File -- Creating New Local State
Updating From Dropbox
Traceback (most recent call last):
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/urllib3/util/timeout.py", line 125, in _validate_timeout
float(value)
TypeError: float() argument must be a string or a number, not 'Timeout'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/895491B4-6F48-4CA2-AF6A-1A663749BD60/Pythonista3/Documents/bin/Utilities/Synchronator/Synchronator.py", line 425, in <module>
check_remote(dbx, state)
File "/private/var/mobile/Containers/Shared/AppGroup/895491B4-6F48-4CA2-AF6A-1A663749BD60/Pythonista3/Documents/bin/Utilities/Synchronator/Synchronator.py", line 333, in check_remote
state.execute_delta(dbx)
File "/private/var/mobile/Containers/Shared/AppGroup/895491B4-6F48-4CA2-AF6A-1A663749BD60/Pythonista3/Documents/bin/Utilities/Synchronator/Synchronator.py", line 174, in execute_delta
results = dbx.files_list_folder('', True)
File "/private/var/mobile/Containers/Shared/AppGroup/895491B4-6F48-4CA2-AF6A-1A663749BD60/Pythonista3/Documents/site-packages/dropbox/base.py", line 1336, in files_list_folder
None,
File "/private/var/mobile/Containers/Shared/AppGroup/895491B4-6F48-4CA2-AF6A-1A663749BD60/Pythonista3/Documents/site-packages/dropbox/dropbox.py", line 234, in request
timeout=timeout)
File "/private/var/mobile/Containers/Shared/AppGroup/895491B4-6F48-4CA2-AF6A-1A663749BD60/Pythonista3/Documents/site-packages/dropbox/dropbox.py", line 325, in request_json_string_with_retry
timeout=timeout)
File "/private/var/mobile/Containers/Shared/AppGroup/895491B4-6F48-4CA2-AF6A-1A663749BD60/Pythonista3/Documents/site-packages/dropbox/dropbox.py", line 409, in request_json_string
timeout=timeout,
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/requests/sessions.py", line 512, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/requests/sessions.py", line 469, in request
resp = self.send(prep, **send_kwargs)
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/requests/sessions.py", line 577, in send
r = adapter.send(request, **kwargs)
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/requests/adapters.py", line 377, in send
timeout=timeout
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/urllib3/connectionpool.py", line 547, in urlopen
timeout_obj = self._get_timeout(timeout)
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/urllib3/connectionpool.py", line 303, in _get_timeout
return Timeout.from_float(timeout)
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/urllib3/util/timeout.py", line 155, in from_float
return Timeout(read=timeout, connect=timeout)
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/urllib3/util/timeout.py", line 98, in init
self._connect = self._validate_timeout(connect, 'connect')
File "/var/containers/Bundle/Application/44E531D9-C860-4F8B-9A15-16BE6F3BE756/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/urllib3/util/timeout.py", line 128, in _validate_timeout
"int or float." % (name, value))
ValueError: Timeout value connect was Timeout(connect=30, read=30, total=None), but it must be an int or float.
Thank in advance
Cheers
Andre
HI @JonB,
I'll look into the AudioEngine, but for now I am using sound.Player() with some success.. I'm trying to determine what is the smallest wav file I can generate that will loop correctly, it's a lot of trial and error.
Cheers
Andre
Thanks @ccc,
I had seen those examples, but what I need to do is produce sound, I managed some, the problem is as soon as I leave pythonista in the background the sound stops :(
Cheers
Andre
Hello everyone,
I'd like to write an app to do tone generation in real time and I know the way to do it without glitches would be through CoreAudio. After going trough some of the very old posts discussing it, it is not clear to me wether this could be possible with Pythonista 3.0. Any ideas ?
Thanks in advance
Cheers
Andre