Pythonista is convenient, isn't it? It's perfect for coding on the go, and it's easy to create a GUI, so it's very convenient for hacking iOS devices.
The custom keyboard is also good and I have almost no complaints, but I decided to use an action instead because I have a paste key but no copy key.
First, a brief introduction to Pythonista. Pythonista is a paid app for iOS and is a ** Python development environment ** for both iPhone and iPad.
It comes with real Python [^ 1], not an online compiler, and works locally.
In addition, the operability of the custom keyboard designed for iOS is sufficiently practical, and stress-free coding can be performed.
The included dedicated module is also powerful,
--Access to clipboard --Access to location information --Access to iOS camera features --Data transfer from shared sheet --Access to Objective-C classes
And so on, it is full of functions that can be pulled a little. It is a very recommended environment for fun development by using powerful modules.
Currently, due to the enthusiastic request of users, a beta version of Python 3 series Pythonista is currently under development.
As I did in the above video, in Pythonista you can change the selection range smoothly by swiping the keyboard with two fingers, but it was stressful that the Copy command did not come out after setting the range.
So, after studying Pythonista, I made an action to copy the character string of the selected range to the clipboard. Below is the work procedure.
The site-package directory is the directory provided by default in Pythonista, and the import path is in it. (It was written in Readme.txt)
As you said, let's create copy_text.py there. The function is divided into two methods, get_selected_text and copy_text, considering the purpose of acquiring and modifying the selected character string later. (Since it is a simple code, I will omit the explanation of the script)
copy_text.py
# coding: utf-8
import sys,editor,clipboard,console
reload(sys)
sys.setdefaultencoding('utf-8')
def get_selected_text():
text = editor.get_text()
selection = editor.get_selection()
selected_text = text[selection[0]:selection[1]]
return selected_text
def copy_text():
if get_selected_text():
clipboard.set(get_selected_text())
if __name__ == "__main__":
copy_text()
When you have finished writing the code, select the text on the edit screen of copy_text.py, execute the Run button, and the selected text should be copied to the clipboard.
Then register copy_text.py in the action. To register for an action, click the spanner button at the top right of the screen. Please refer to the video of the situation. (The resolution has been cut in half due to file size issues)
The procedure is as follows.
Just select the text you want to copy while editing any file, press the spanner button and execute Copy.
Of course, you don't need to import the copy_text module in the target file.
** Pythonista fun! !! ** **
[^ 1]: In Pythonista 2.0, the Python version is 2.7.5.
Recommended Posts