Forum Archive

Flick button keyboard.

shinya.ta

I want to make an iPhone-custom keyboard in pythonista.

I'm Japanese. I want to make a custom keyboard for my iPhone that is Japanese compatible.

I want to make a flick input button in Python, but I don't know how to make it.

Someone help me, please.

cvp

@shinya.ta a keyboard to be used in Pythonista only or by any app on your iPhone (like I did for you some years ago with the "Emojis keyboard.py" ?

shinya.ta

Dear cvp.

In Japan, we use iPhone like this.

https://m.youtube.com/watch?v=si_f5KzPZJA

Can this button be done in Python?

cvp

@shinya.ta sorry but as the YouTube explanation is in Japanese, I can't understand anything.
And which button is "this button"? And do you want a special keyboard only in Pythonista or in all apps where you use a keyboard, like mail, WhatsApp etc...?

Anyway, I think that you could develop any kind of keyboard in Pythonista but the problem is to have a good description of your requests

shinya.ta

"Flick input" is a way to input characters by placing your finger in the direction of the character you want to type. If you want to type "I", touch the "A" key. If you don't let go of your finger, the characters in the "A" line appear, such as "I", "U", "E", and "O".

う 
    いあえ
     お

shinya.ta

@cvp

Please tell me how to send photos or videos.

shinya.ta

@cvp

https://m.youtube.com/watch?v=KKHFWjBvIZw

shinya.ta

@cvp

https://m.youtube.com/watch?v=8_mnbM1f-_o

The language you use is different, but the button looks like this.

cvp

@shinya.ta said

"Flick input" is a way to input characters by placing your finger in the direction of the character you want to type. If you want to type "I", touch the "A" key. If you don't let go of your finger, the characters in the "A" line appear, such as "I", "U", "E", and "O".

Wow. Less easy but I guess it could be possible (but less sure). But I still have the same question.
Where do you want to use this keyboard?

shinya.ta

@cvp

That's good news.

I want to use it for e-mail and website search like the old keyboard.

cvp

@shinya.ta said

That's good news.

Don't be optimistic too quickly. I said that I'm no sure and, obviously, if it is possible, it would be not easy.

I didn't know this feature, seeming to exist as standard setting on Japanese iPad.
I guess that if Apple did not configure it on iPhone, there is a reason.

https://m.youtube.com/watch?v=KKHFWjBvIZw

This YouTube (you sent) shows such a keyboard on iPhone, thus why do want to create one yourself?

shinya.ta

@cvp

The reason why I want to make a custom keyboard is for my wife.

On the old keyboard, if you switch the keyboard when you need to move the cursor, the character being converted will be determined.

So, I want to combine the previous cursor movement application with this custom keyboard and make one that doesn't need to switch the keyboard.

cvp

@shinya.ta Sorry, I think that I become too old for this kind of stuff, I don't understand anything.
Believe me, you aren't responsible, I am.

shinya.ta

@cvp
I want to combine the previous keyboard and the new flick button keyboard.

Flick input button is essential.

cvp

@shinya.ta said

previous keyboard

What is that?

shinya.ta

@cvp
It is the cursor movement keyboard that you made before.

shinya.ta

@cvp
If there is a flick input button, it will be easier for my wife to use.

cvp

@shinya.ta said

It is the cursor movement keyboard that you made before.

If I remember, it is not a keyboard that I wrote but a particular script to use buttons for cursor movements in a TextView, but it uses a standard keyboard and you want a special keyboard with flick button keys?

Please, confirm both:

1) what you call "cursor movement keyboard" is the "Move cursor in TextView.py" script where you have to tap buttons to move the cursor. And thus is not a keyboard.
2) you want, in this script, to use a particular Japanese keyboard where keys can be used as flick buttons to generate vowels

shinya.ta

@cvp

I want a special keyboard.

The Japanese input button is a flick input button, and I want to equip other blank buttons, a new line button, and a cursor movement button.

  1. I don't quite understand what this
    means.
cvp

@shinya.ta Could you test this version of Emojis Keyboard.py, and tell me if the A button works as a flick button when you tap it with a long press.

Important: the modified script imports a gestures module that you have to download from https://github.com/mikaelho/pythonista-gestures/blob/master/gestures.py and to save in your site-packages folder.

Of course, this is only a test to check if I have correctly understood what you ask, thus don't hope to find here the solution.
If it is ok, you would have to give me a full description of wanted keys and their content when flicked.

Only tested on iPad

Long press on A key gives

Moving finger on E key gives

shinya.ta

@cvp
I'm sorry. I don't know how to download it.

cvp

@shinya.ta said

I don't know how to download it.

My script, Mikael's script, both? Never downloaded something from GitHub ? 😭

Some years ago, I wrote some scripts for you or your wife. Did I always post them in the forum, never in GitHub ?

Anyway, to download gestures.py into your site-packages folder, create and run, *once*, this little script

import os
import requests
url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py'
data = requests.get(url).content
dir  = os.path.expanduser('~/Documents/site-packages')  
file_name = url.split('/')[-1]
path = dir + '/' + file_name
with open(path,mode='wb') as out_file:
    out_file.write(data)

To download my little "Emojis keyboard .py" in your Pythonista's root, create and run once this little script

import os
import requests
#url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py'
url = 'https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Emojis%20Keyboard.py'
data = requests.get(url).content
dir  = os.path.expanduser('~/Documents/')   
file_name = url.split('/')[-1].replace('%20', ' ')
path = dir + '/' + file_name
with open(path,mode='wb') as out_file:
    out_file.write(data)

Then you have to replace the old keyboard script by this modified one... Please give me some feedback. Thanks

shinya.ta

@cvp

""" docgen-ignore """

This is "Indentation Error".

cvp

@shinya.ta Where? In one my both little scripts to download or in gestures.py or in Emojis Keyboard.py?

shinya.ta

@cvp
Can't I paste "gestures. py" into "Emoji Keyboard. py"?

shinya.ta

@cvp
When I pasted "gestures. py" into "Emoji Keyboard. py" and started it, I got the previous error.

shinya.ta

@cvp said:

```
import os
import requests

url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py'

url = 'https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Emojis%20Keyboard.py'
data = requests.get(url).content
dir = os.path.expanduser('~/Documents/')
file_name = url.split('/')[-1].replace('%20', ' ')
path = dir + '/' + file_name
with open(path,mode='wb') as out_file:
out_file.write(data)
```

This doesn't respond to anything.

cvp

@shinya.ta said

When I pasted "gestures. py" into "Emoji Keyboard. py" and started it, I got the previous error.

As Emojis Keyboard.py imports gestures.py, you don't have to paste it, thus don't do that.

This doesn't respond to anything.

The little script does not respond something, it copies/replaces the modified Emojis Keyboard.py in your root folder.

Thus, please run my both little scripts and you will find anew Emojis Keyboard.py in your root folder

shinya.ta

@cvp said:

@shinya.ta Could you test this version of Emojis Keyboard.py, and tell me if the A button works as a flick button when you tap it with a long press.

Important: the modified script imports a gestures module that you have to download from https://github.com/mikaelho/pythonista-gestures/blob/master/gestures.py and to save in your site-packages folder.

Of course, this is only a test to check if I have correctly understood what you ask, thus don't hope to find here the solution.
If it is ok, you would have to give me a full description of wanted keys and their content when flicked.

Only tested on iPad

Long press on A key gives

Moving finger on E key gives

Where is the package folder?

shinya.ta

@cvp
It's too difficult for me to understand.

cvp

@shinya.ta said

Where is the package folder?

you don't need to know it,

My script gets the gestures.py file from the Internet and copies it in your site-packages folder.
And the import gestures reads it there, all is automatic

Tap on Python Modules and you will see site-packages folder

cvp

@shinya.ta said

It's too difficult for me to understand.

The only thing to understand is that one of the two little scripts copy the Emojis Keyboard.py script in your root folder. The needed gestures.py is copied by the other little script in the folder where the import gets it.

shinya.ta

@cvp
I'm sorry.

The shame is that I don't really know how to use "GitHub".

I also downloaded "Emojis Keyboard. py" from GitHub and didn't use it.

I used to paste the script directly.

I'm ashamed to say that you need to learn from using GitHub first.

cvp

@shinya.ta No shame to not know something if you don't need it. I guess that you never needed to import a new module in Pythonista.

For GitHub, you don't need to really use it because I suppose that you never will post a source code but you need to learn the minimum to get a source code.

If you tap a link like https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Emojis%20Keyboard.py, you open Safari at the GitHub site where a script is available in raw mode, that will say that you are able to select all, copy and paste in Pythonista.

I guess that you can create a new empty script in Pythonista and paste in it some copied code.

Now, if you select, copy and paste this little script in a new empty script in Pythonista

import os
import requests
url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py'
data = requests.get(url).content
dir  = os.path.expanduser('~/Documents/')   
file_name = url.split('/')[-1].replace('%20', ' ')
path = dir + '/' + file_name
with open(path,mode='wb') as out_file:
    out_file.write(data)

And you run it, it will get the code of gestures.py from GitHub and copy it to your site-packages folder as gestures.py. And from now for ever, any script can import gestures. All is automatic after you have run the little script. Then no need to understand GitHub.

If you have run it and if you have already pasted the new Emojis Keyboard.py, as you are used to do, now the new code can run because you have imported the gestures module. At least, I hope.

This was the 1st lesson 🙂

cvp

@shinya.ta Please give me some feedback of until which step you are ok

shinya.ta

@cvp said:

@shinya.ta No shame to not know something if you don't need it. I guess that you never needed to import a new module in Pythonista.

For GitHub, you don't need to really use it because I suppose that you never will post a source code but you need to learn the minimum to get a source code.

If you tap a link like https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Emojis%20Keyboard.py, you open Safari at the GitHub site where a script is available in raw mode, that will say that you are able to select all, copy and paste in Pythonista.

I guess that you can create a new empty script in Pythonista and paste in it some copied code.

Now, if you select, copy and paste this little script in a new empty script in Pythonista
import os import requests url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py' data = requests.get(url).content dir = os.path.expanduser('~/Documents/') file_name = url.split('/')[-1].replace('%20', ' ') path = dir + '/' + file_name with open(path,mode='wb') as out_file: out_file.write(data)
And you run it, it will get the code of gestures.py from GitHub and copy it to your site-packages folder as gestures.py. And from now for ever, any script can import gestures. All is automatic after you have run the little script. Then no need to understand GitHub.

If you have run it and if you have already pasted the new Emojis Keyboard.py, as you are used to do, now the new code can run because you have imported the gestures module. At least, I hope.

This was the 1st lesson 🙂

The paste is done.
But nothing happens when you do it.

cvp

@shinya.ta said

The paste is done.
But nothing happens when you do it.

The paste of what and where?

Nothing happens when you do what?
If you speak of the run of the little script: when you run, nothing visible happens, but a script is invisibly downloaded from GitHub to your Pythonista.

If you go in the Pythonista console (I hope you know what it is), and you begin to type
"Import ges", do you see this

Please, explain always what you did before each question, I can't follow what you do

shinya.ta

@cvp
I pasted a small script into an empty file and ran it.

cvp

@shinya.ta hoping that you run the small script installing the gestures module, did you try to type "import ges" in the console and what's the result?

shinya.ta

@cvp

Where is "Pythonista console"?
I think I'm misunderstanding something.

cvp

@shinya.ta On iPad or iPhone, swipe right to left and console appears.
At the bottom, you can type Python line

shinya.ta

@cvp

I see ">>> import gesTraceback (most recent call last) : File" ", line one, in ModuleNotFoundError : No module named' ges'".

cvp

@shinya.ta ok, that will say that you have pressed the enter key. But without pressing the enter key, do you see

If yes, that will say that the copy of gestures.py from GitHub has been successful

shinya.ta

@cvp
It will say ">>> import gestures".

shinya.ta

@cvp said:

@shinya.ta ok, that will say that you have pressed the enter key. But without pressing the enter key, do you see

If yes, that will say that the copy of gestures.py from GitHub has been successful

It doesn't look like this.

cvp

@shinya.ta please, copy this script and paste in a new empty script, then run it

import os
import requests
url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py'
data = requests.get(url).content
dir  = os.path.expanduser('~/Documents/site-packages')  
file_name = url.split('/')[-1]
path = dir + '/' + file_name
with open(path,mode='wb') as out_file:
    out_file.write(data)

Then retry to type "import ges" in console

shinya.ta

@cvp
I entered "import ges" but the reaction is the same as before.

ccc

Try writing this as a text file (not bytes) to the local directory instead of site-packages

import os
import requests
url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py'
data = requests.get(url).text
dir  = os.path.expanduser('~/Documents/')  
file_name = url.split('/')[-1]
path = dir + '/' + file_name
with open(path,mode='w') as out_file:
    out_file.write(data)
shinya.ta

@ccc said:

Try writing this as a text file (not bytes) to the local directory instead of site-packages
import os import requests url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py' data = requests.get(url).text dir = os.path.expanduser('~/Documents/') file_name = url.split('/')[-1] path = dir + '/' + file_name with open(path,mode='w') as out_file: out_file.write(data)

I tried it.
The last line will say "UnicodeEncodeError".

ccc

data = requests.get(url).text # <-- text, not context?

with open(path,mode='w') as out_file: # 'w' not 'wb' ?

shinya.ta

@ccc

"out_file.write(data)"

There is an error here.

cvp

@shinya.ta @ccc believe me, I use my script very often and it works successfully each time, no reason to change it.

cvp

@shinya.ta last try in another way.

Go to https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py,
Long press on text, then “select all”, then “copy”
Then, in Pythonista, create an empty script named gestures.py (no uppercase) in the folder where your “Emojis keyboard,py” is, and paste the copied code

Danielpitts

Thanks. It's a helpful topic for me.

shinya.ta

@cvp
I copied and pasted it to a new folder.
Nothing special will happen.

shinya.ta

@cvp
Currently, "Emoji keyboard, py" works on iPhone but not on iPad.
Is it because of the OS version?
I've done all the tests on my iPhone.

shinya.ta

@cvp

Isn't it good to put "gestures. py" directly into "Emoji keyboard, py"?

cvp

@shinya.ta said

I copied and pasted it to a new folder

Why a new folder? This gestures.py has to be in the folder of your Emojis keyboard.py or in the site-packages folder, why do you want a new folder? Please, we have already so much difficulty to find a solution, when we propose something, please do it or we will never solve your problem

cvp

@shinya.ta Sid

Isn't it good to put "gestures. py" directly into "Emoji keyboard, py"?

No, please. In this case, every time I will modify Emojis keyboard.py, you will have to insert gestures module. That's the reason why Python has the "import" statement

cvp

@shinya.ta si

Nothing special will happen.

Nothing has to happen. But the new Emojis keyboard.py will only run ok if you have a gestures module able to be imported.

shinya.ta

@cvp
I'm sorry. I've got the wrong word.
I put it in the folder "Emoji keyboard. py".

shinya.ta

@cvp

When I opened "Emoji keyboard. py", only a few buttons were displayed, and when I closed the application, a sentence like this appeared.

“Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/ 263EB98D-49AC-45A8-9637-2EF523D820AC/Pythonista3/

Documents/custom-keyboard/Emojis Keyboard. py' line 119,
in dimensions

long_press (b, long_press_handler)
NameError: name
'long_press is not defined”

cvp

@shinya.ta when you say folder, you mean "file"? 😭

Please, let us be serious:
1) copy and paste Emojis keyboard.py in the same file name
2) copy and paste gestures.py in the same file name

And both files in th same folder, like the Pythonista's root

I've just tried to install both files on my iPhone and all is like I expect ...

cvp

@shinya.ta said

'long_press is not defined”

That will say that you did not create a gestures.py with the right content in the same folder

shinya.ta

@cvp said:

@shinya.ta Could you test this version of Emojis Keyboard.py, and tell me if the A button works as a flick button when you tap it with a long press.

Important: the modified script imports a gestures module that you have to download from https://github.com/mikaelho/pythonista-gestures/blob/master/gestures.py and to save in your site-packages folder.

Of course, this is only a test to check if I have correctly understood what you ask, thus don't hope to find here the solution.
If it is ok, you would have to give me a full description of wanted keys and their content when flicked.

Only tested on iPad

Long press on A key gives

Moving finger on E key gives

I've finally made it this far.
The test is OK.
The order of the buttons is "A" in the middle, "B" on the left, "C" on the top, "D" on the right, and "E" on the bottom.
In Japanese, "A", "あ", "B", "い", "C", "う", "D", "え", "E" and "お".

shinya.ta

@cvp
Also, "Voice Over" doesn't work after the text is displayed. It doesn't read out the button.
"Voice Over" is important. "A" is read aloud, but the following "B, C, D, E" is not read.

cvp

@shinya.ta said

I've finally made it this far.

Ok, we are a step more. Now, as gestures.py is installed, next steps would be easier with only several new versions of Emojis keyboard.py.

I'll display a version (at right, you will see) of the script so we will always be sure we speak about the same code.

Most important, at this stage, is to be sure I understood what flicking is for you.

cvp

@shinya.ta said

Also, "Voice Over" doesn't work after the text is displayed. It doesn't read out the button.
"Voice Over" is important. "A" is read aloud, but the following "B, C, D, E" is not read.

First bug of my side, I'm also authorized to do some bugs, not only you (joke 😂)

cvp

@shinya.ta new version V00.01, https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Emojis%20Keyboard.py

cvp

@shinya.ta said

Also, "Voice Over" doesn't work after the text is displayed. It doesn't read out the button.
"Voice Over" is important. "A" is read aloud, but the following "B, C, D, E" is not read.

I've to admit that I don't know anything about Voice Over and I don't remember all what I've eventually learned two years ago
Which settings I have to set on my IPhone.

Anyway, you say that "A" is read aloud. But there are two ways to generate the "A":
- when you tap the key
- when you have a long press and that your move ends on the "A"
Did you try both ways and which one(s) do Speech the "A"?

shinya.ta

@cvp
I'm sorry. English is too difficult for me to understand.

cvp

@shinya.ta which part of my message? Do you never copy an English text in Google Translate app and ask it to translate in Japanese.

Anyway, there is a new version of Emojis Keyboard.py with two flicking keys in Japanese

shinya.ta

@cvp
I read only the first tap. I don't read at all when I move.

shinya.ta

@cvp said:

@shinya.ta new version V00.01, https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Emojis%20Keyboard.py

I'm sorry. I understand it after I translate it on Google. There are times when I don't understand the meaning because it's too literal translation.

I have tried this version. Only the first letter is read aloud, and the moved letter is not read.

cvp

@shinya.ta Anyway, I don't remember how does voice over works. Do you need to type twice on a key? And how if long press?

shinya.ta

@cvp
You need to tap two times. After that, you need to select characters in a long press state, but you don't read during that time.

cvp

@shinya.ta after the long press and the move on a character, when the finger leaves the screen, the letter is inserted and readout . Do you want the letter becomes said when letter becomes blue?

shinya.ta

@cvp
Please do so. The flick input button in Japan is also like that.

cvp

@shinya.ta I try but I don't yet find a way to do that.

cvp

@shinya.ta VoiceOver is an IOS feature that automatically reads aloud the title of a tapped key but our flicked keys are generated by our script without iOS knows it is a simulated key, thus does not reads aloud them. I try without success to speech a key which becomes blue, but without success.

shinya.ta

@cvp
Do you mean you need the own reading function of Pythonista?

cvp

@shinya.ta yes but without success actually

shinya.ta

@cvp
Do I need a Japanese voice library?

cvp

@shinya.ta No, IOS speech module provides that but the problem I meet is that when I process the long_press handler, if I colorize the key in blue in moving, I try to speech the key title but either there is no sound, either the sound is repeated a big number of times. I have even tried to put the speech call in a thread, without success. I am not sure that keyboard process can handle several threads.

shinya.ta

@cvp
Do you still have a hope?
If you can do this, it will be a perfect keyboard for my wife.

cvp

@shinya.ta Yes, I still have an hope, to early to abandon, but don't ask me a delay

And the reason of your request, "for your wife" is my motivation 🙂

Edit: I just found in objectiveC Apple doc that there are some VoiceOver functionalities that developer (like I try to be 😉) may use to force VoiceOver to say something not foreseen in the standard process. But I don't know anything about that, thus wait, hope and see

Edit2: normally, I work wit sound off on my iPad and now, to test my code with VoiceOver on and sound on do annoy my wife, thus I postpone to later...

cvp

@shinya.ta Tried but not yet ok, does not work like I wait, not obvious, will try layer...

shinya.ta

@cvp
Dear cvp.
You are my savior. I wish you success.

cvp

@shinya.ta said

You are my savior. I wish you success.

Too optimistic and too early to say it , but thanks for the wish

My last try today: the last blue letter is read aloud when my finger leaves the screen but not when the key becomes blue, thus if you move your finger on a letter an then on another letter, the last is said when pression is ended, thus too late.

shinya.ta

@cvp
Is it difficult after all?

cvp

@shinya.I've to say that I didn't work on it for medical reasons, but, yes, it seems very difficult to read aloud the generated letter when its key becomes blue, that will say when the finger moving enters in the key frame. I don't abandon but I don't have a lot of free time actually. Chirurgical operation planned, sorry.

shinya.ta

@cvp
It's okay. I'll wait.

cvp

@shinya.ta I learned yesterday that I have lung cancer, I doubt that I still find, currently, the motivation and the energy necessary to solve this problem of VoiceOver, an area of ​​which I know nothing. Sorry about your wife.

shinya.ta

@cvp
What! Are you okay?
Don't worry about us. Just concentrate on your treatment.

My wife tested the flick input button, and it seems to be possible to use it at this stage.
If you type by moving your finger quickly, it seems that the selected characters are hardly read out.
My wife said that even if he can't read letters, he can tell the location of the button if he makes some kind of response sound to the button he moved.

shinya.ta

@cvp
There was an old problem that hasn't been solved yet.
When I press the voice reading button, the following error appears.

“Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/ 263EB98D-49AC-45A8-9637-2EF523D820AC/Pythonista3/
Documents/custom-keyboard/Emojis Keyboard 2.py", line 70, in b read from action
speech. say (t[1], 'jp-jp')
TypeError: argument 1 must be str, not None”
cvp

@shinya.ta could you try this new version (small modifications)
https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Emojis%20Keyboard.py

I've a lot of medical exams and I'm tired, thus don't hope a lot of updates