• sulcud

    @flipflap, I know this is not WebView based but I hope it also helps you to execute the JavaScript you need

    import objc_util
    class JavaScriptVM(object):
        def __init__(self):
            self._framework = objc_util.load_framework("JavaScriptCore")
            self._JSContext = objc_util.ObjCClass("JSContext")
            self._JSVirtualMachine = objc_util.ObjCClass("JSVirtualMachine")
            self.context = None
            self.javascript_vm = None
        def _prepare_vm(self):
            context = self._JSContext.new()
            self.javascript_vm = self._JSVirtualMachine.new()
            self.context = context.initWithVirtualMachine_(self.javascript_vm)
        def evaluate_script(self, script_code: str):
            if self.context is not None:
                if self.javascript_vm is not None:
                    return self.context.evaluateScript(script_code)
    code = """function test(a, b){
        return a + b;
    test(1+2, 3)+3"""
    vm = JavaScriptVM()
    r = vm.evaluate_script(code)

    posted in Pythonista read more
  • sulcud

    @ccc said:

    You would need compile it into the app. Which is not be possible without the source code to Pythonista. You would be able to do it with Pyto which is open source but it would be complicated.

    You are right. With the AppStore version of both apps is not possible, I need to compile my own, at least can test it with Pyto.

    In my last approach I ended by compiling a test C library for arm64 and then I signed it with codesign, Pythonista apparently accept the dynamic library but stops importing it as the identity used to signed it is not the same of the identity the owner of the app used (or at least that is what I think, really don’t know which other thing is preventing to load it)

    If you are interested in reading the traceback of Pythonista:

    Traceback (most recent call last):
      File "/private/var/mobile/Containers/Shared/AppGroup/HIDDEN/Pythonista3/Documents/hw.py", line 4, in <module>
        test_lib = ctypes.cdll.LoadLibrary("./test-lib_1.so")
      File "/var/containers/Bundle/Application/HIDDEN/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/ctypes/__init__.py", line 427, in LoadLibrary
        return self._dlltype(name)
      File "/var/containers/Bundle/Application/HIDDEN/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/ctypes/__init__.py", line 349, in __init__
        self._handle = _dlopen(self._name, mode)
    OSError: dlopen(/private/var/mobile/Containers/Shared/AppGroup/HIDDEN/Pythonista3/Documents/test-lib_1.so, 0x0006): code signature invalid (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x00008050, codeBlobSize=0x00004900 for '/private/var/mobile/Containers/Shared/AppGroup/HIDDEN/Pythonista3/Documents/test-lib_1.so'

    How apple encapsulates the apps is very interesting and I still believe that someone super skilled can archive this, anyway, thanks again @ccc for your quick answer

    posted in Pythonista read more
  • sulcud

    Hello everyone, I have this stupid question that has a high chance of receive a NO as answer.

    First the background.
    Recently I have testing the python feature of importing code written in C and compiled into dynamic libraries .so files on my PC, In my tests I could notice that I can import files with only the read and write permissions, so base on that I conclude that I don't need the execution permission in that kind of file to import them to python.

    All of those tests where made approaching

    import ctypes
    my_c_library = ctypes.cdll.LoadLibrary("/path/to/library")
    my_c_library.my_c_function(arg_1, arg_2)

    Now that I have access to a Mac I was trying to approach the Xcode tools to compile a dynamic library and import it to Pythonista, the problem is that it is extremely hard to setup the environment for the compilation to iOS, I mean, I could compile to arm64 but looks like iOS has other libraries that I have no access to (or at least I don't know where to find them)

    If anyone have a solution or have an alternative way to approach something similar I really will appreciate it

    posted in Pythonista read more
  • sulcud

    PyCharm could be a good alternative

    posted in Pythonista read more
  • sulcud

    Up to date pre-installed modules

    posted in Pythonista read more
  • sulcud

    I think that erasing a Pythonista build-in module is not possible, remember that python has a weird importing system so if you have a script/folder called speech in the same folder of your main script maybe you are importing it instead of the build in one. (python import order is: current dir, ... , site-packages, build-in) but If that is not the case, I think a fresh install of Pythonista could work

    posted in Pythonista read more
  • sulcud

    @cvp, you are right, using 0 fixes it, did you find anyway to fix the false positives that is_paused and is_speaking functions return?

    posted in Pythonista read more
  • sulcud

    @lyubomyr83, I made this class to make it easier to work with the reference @ccc is pointing to, all could be done thanks to the work of @JonB

    import objc_util
    import re
    class SpeechModule(object):
        def __init__(self):
            self.__AVSpeechUtterance = objc_util.ObjCClass('AVSpeechUtterance')
            self.__AVSpeechSynthesizer = objc_util.ObjCClass('AVSpeechSynthesizer')
            self.__AVSpeechSynthesisVoice = objc_util.ObjCClass('AVSpeechSynthesisVoice')
            self.__synthesizer = self.__AVSpeechSynthesizer.new()
        def get_synthesis_languages(self) -> list:
            return self.__AVSpeechSynthesisVoice.speechVoices()
        def say(self, msg: str, language: objc_util.ObjCInstance, rate=0.5):
            utterance = self.__AVSpeechUtterance.speechUtteranceWithString_(msg)
            utterance.rate = rate
            utterance.voice = voice
            utterance.useCompactVoice = False
        def is_speaking(self) -> bool:
            return self.__synthesizer.isSpeaking()
        def is_paused(self) -> bool:
            return self.__synthesizer.isPaused()
        def pause(self) -> bool:
            return self.__synthesizer.pauseSpeakingAtBoundary_(True)
        def stop(self) -> bool:
            return self.__synthesizer.stopSpeakingAtBoundary_(True)
        def continue_speaking(self):

    Here is an example how to use it

    import time
    speech_ = SpeechModule()
    available_voices = speech_.get_synthesis_languages()
    us_english_voices = tuple(filter(lambda voice: "en-US" in str(voice), available_voices))
    voice = us_english_voices[0]
    speech_.say('Hello friend! how are you?', voice, 0.3)
    speech_.say("nevermind", voice)

    For some reason I can’t make that pause function to work correctly, anyway, it is an idea for your project and maybe my class could be buggy, so objc gurus invocation (@cvp @mikael @JonB @ccc )

    posted in Pythonista read more
  • sulcud

    I don’t speak Russian so I can’t confirm is the Russian pronunciation Is wrong, but maybe you are running the “say” function with the language “en-US”; this function has this parameters:

    text -> text you want to say
    language -> (optional) the language that you want to speak with
    rate -> (optional) the speed of the voice

    Maybe you are trying this, I don’t know

    import speech

    You should try

    import speech
    speech.say("привет друг", "ru-RU")

    posted in Pythonista read more
  • sulcud

    This is not a solution for the installation but maybe it can help you, Pythonista has an already TTS module called “speech” and it works well

    import speech

    posted in Pythonista read more
  • sulcud

    Hello @Enez-Houad, you're solution is good, the clipboard is a good way to share information Pythonista => shortcuts the only two problems I saw in your scripts are first you are not setting the values to your clip board you can do it with:

    import clipboard
    import sys, webbrowser
    n1, n2 = int(sys.argv[1]), int(sys.argv[2])
    n3 = n1 + n2
    # I don't know what variable you want to use n1,n2 or n3?
    # This set the value n3 to the device clipboard

    Second you need a shortcut that can wrap your clipboard, the shortcuts app have a variable with that function, and with it you can use the correct url scheme

    # this will open your shortcut with as input the device clipboard
    url = "shortcuts://run-shortcut?name=[ShortcutName]&input=clipboard"

    shortcuts url scheme
    Pythonista clipboard

    example of the shortcut

    posted in Pythonista read more
  • sulcud

    @cvp said:

    @djl this works, tested with another app because I don't have gaiagps

    import webbrowser
    import clipboard
    with open(file_path,'rt',encoding='utf-8') as f:
    # my_shortcut only contains one command: open in one app

    Probably this is the simplest answer to your question
    But you are right, I download the app and I try that shortcut with that app, and the shortcut app create a txt file with the content of the original file

    posted in Pythonista read more
  • sulcud

    What is the content of that file? Latitude, longitude? I check that the url scheme can recieve

    posted in Pythonista read more
  • sulcud

    do you want to copy a file to gaiagps?
    Sorry but I don’t understand your question

    posted in Pythonista read more
  • sulcud

    You can see this for more help


    posted in Pythonista read more
  • sulcud

    It is easy, put the extension.py and the main.py file in a folder with a file called __init__.py, them in the main.py

    import extension

    I hope this work for you

    posted in Pythonista read more
  • sulcud

    @omz i solve it, i re install the app them i open it and them a install the beta

    posted in Pythonista read more
  • sulcud

    @omz I install Pythonista 3 from the backup them I install the beta, I try enabling and disabling pykeys

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!