Arcade for Pythonista
Theoretically, you could use objc_util /OpenGLES/EAGL to implement the presentation layer of pyglet/pygame. It would be hard, and probably super slow.
I don't believe Pyto has yet included pygame either, despite a few requests. It is open source, so you could go for it, but I'm not sure if there is an iOS SDL library.
Arcade for Pythonista
Arcade depends on pyglet, which depends on pygame, which is mostly written in c. Pythonista is limited to installation of pure python modules (or those which only depend on moudles included with pythonista, like numpy)
Portions of pyglet, like the physics model, might be usable in pythonista with some work to disentangle it from the backend graphics, but it would be pretty complicated to replicate the pyglet graphics stuff using Pythonista scene constructs, or maybe the lower level iOS constructs.
How can I install and run pyglet?
Title says it all. I was trying to install it using stash. And it did work, but I had error about ctypes.macholib, which I fixed too, but now it says:
No Library found: GL
How can I install and run pyglet properly on Pythonista?
Possible to run Psychopy scripts?
Looking at setup.py:
install_requires =
requests[security]
numpy
scipy
matplotlib
pandas
pillow
pyglet
pyopengl
soundfile
sounddevice
python-bidi
arabic_reshaper
cffi
future
json_tricks
pyosf
xlrd
openpyxl
pyserial
pyyaml
gevent
msgpack-numpy
msgpack-python
psutil
tables
pyzmq
moviepy
opencv-python
python-gitlab
gitpython
astunparse
esprima
freetype-py
# Platform-specific dependencies.
imageio < 2.5; python_version < "3"
imageio >= 2.5; python_version >= "3"
imageio-ffmpeg; python_version >= "3"
pyparallel; platform_system == "Linux"
pyWinhook; platform_system == "Windows"
pyqmix >= 2018.12.13; platform_system == "Windows"
pyqt5; python_version >= "3"
wxPython != 4.0.2, != 4.0.3; platform_system != "Linux"
pypiwin32; platform_system == "Windows"
pyobjc-core; platform_system == "Darwin"
pyobjc-framework-Quartz;
A good fraction of these are incompatible with pythonista. For instance scipy.
Print Console in TextView or ScrollView
Thank you!
Is there a comparable simple ui module that works both in and out of pythonista? I had looked at pyglet but it requires pygame. I'd like to be able to work in pythonista but still have the program run elsewhere. I only need a very minimal UI... basically just a box to dump text in and a button or two to refresh it.
Running pythonista scene based programs (including shader) in mac and PC
@ccc, Did you try this tool? If you need an offline tool to run shadertoy examples( all the great fractal examples,
3D examples), just a six-line code snippet (excluding fragment shader code) in Pythonista (as in mandelbrot.py) would do that.
May be you can add this to your Ten-lines-or-less repository. There does not seem to be a simple wrapper on pyglet or any other tool to do similar thing on windows PC or Mac. (The current code available on internet directly uses opengl apis and they are not very flexible.)
Simulating Pythonista scene behavior on pyglet was straightforward but getting fragement shader working needed a lot of experimentation.
Running pythonista scene based programs (including shader) in mac and PC
Here is a utility to run pythonista scene based programs (including shader) in mac and PC using pyglet.
https://github.com/balachandrana/pythonista_pyglet_simulation
This is not 100 percent compatible but with slight changes (mainly for loading images) you can run most of the
pythonista scene based programs.The utility consists of three files, scene.py, shader.py and sound.py.
and the rest of the files are examples. You need to have python 2.7 and pyglet ("pip install pyglet"). There are no other dependencies.
The files mandelbrot.py and julia.py are fractal examples using fragment shader. The files slider.py and nqueen.py are simple games implemented using this utility. Rest of them are test examples. I have tried these examples on both mac and windows PC machines and they seem to work fine. Please let me know if there are any problems or questions.
I started this project to answer the question by @ccc whether his mandelbrot program can be run on Mac machine with
hardware graphic accelarators (shader support) from Python
(See the discussion in https://forum.omz-software.com/topic/3171/relative-performance-of-python2-vs-python3
from @ccc
Is there a similar way to use to the hardware of a Mac from Python?!? Your speedup is incredible!)
Relative performance of Python2 vs. Python3
@omz, @ccc Thanks for your suggestions.
Is there a similar way to use to the hardware of a Mac from Python?!?
Pyglet is supposed to be good for opengl. There seems to be simple wrapper for
GLSL (see the url below), but I have not tried it.
https://groups.google.com/forum/#!topic/pyglet-users/3x8rYF7pNC4
Setting button size using frame as parameter has no effect
@dgelessus - the recent addition of ctypes may allow us to inspect the ui classes now. I have been trying to write an object dumper/lister but it is slow going for me. Here is an example code of what is possible - dumping info about the core bluetooth classes and a few others.
from cocoapy.runtime import *
def list_methods(cls, type):
count = c_uint()
method_array = objc.class_copyMethodList(cls, byref(count))
print '---', count.value, type, 'methods','---'
names = []
for i in range(count.value):
method = c_void_p(method_array[i])
sel = c_void_p(objc.method_getName(method))
name = objc.sel_getName(sel)
encoding = objc.method_getTypeEncoding(method)
return_type = objc.method_copyReturnType(method)
names.append((name, encoding, return_type))
names.sort()
for x, y, z in names:
print x, y
def list_variables(cls, type):
count = c_uint()
ivar_array = objc.class_copyIvarList(cls, byref(count))
print '---', count.value, type, 'variables','---'
names = []
for i in range(count.value):
ivar = c_void_p(ivar_array[i])
name = objc.ivar_getName(ivar)
encoding = objc.ivar_getTypeEncoding(ivar)
names.append((name, encoding))
names.sort()
for x, y in names:
print x, y
CB_Classes = [
'CBATTRequest',
'CBAttribute',
'CBCentral',
'CBCentralManager',
'CBCharacteristic',
'CBDescriptor',
'CBMutableCharacteristic',
'CBMutableDescriptor',
'CBMutableService',
'CBPairingAgent',
'CBPeer',
'CBPeripheral',
'CBPeripheralManager',
'CBScalablePipe',
'CBScalablePipeManager',
'CBService',
'CBUUID',
'CBXpcConnection',
'AVAudioSession',
'AVAudioRecorder',
'NSMutableDictionary'
]
if __name__ == '__main__':
for class_name in CB_Classes:
cls = get_class(class_name)
print '--------------------------'
print 'class:', class_name
list_methods(cls, 'instance')
list_methods(get_object_class(cls), 'class')
list_variables(cls, 'instance')
print '--------------------------'
Uses a set of wrapper classes from cocoapy which is buried in pyglet, but the ByBee wrappers should also work.
I have not yet figured out how to look at any of the Pythonista App classes, only various frameworks that are linked in.