質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

995閲覧

pythonisra UI

shinya-ta

総合スコア31

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2018/10/01 10:20

編集2018/10/06 07:14

pythonista UIで簡単なキーボードアプリを作ろうとしています。

textviewでのカーソルの移動(→、←、↑、↓、文末まで戻る、文字の削除)だけをできるアプリを考え中です。

UIでのコードの紐付けと、カーソル自体のコードが判らなくて困っています。

このアプリは、全盲の嫁が使用するiPhoneでの使用予定です。

iPhoneでは、テキスト入力の際、カーソルの移動(進む、戻る)がない為に、アクセシビリティの音声機能を使用すると、文字入力を間違えてしまうと、そこまで削除しないといけないという状態になり、(音声がかかった状態では、3DTouchの機能が使いにくい)それでは、キーボードを切り替えて、カーソルを移動すれば?と思いついた次第です。

制作は主にiPad上での、pythonistaでの制作が主となっていますり

週末での僅かな時間での勉強、制作ですので、なかなか思うようにいかず、困っています。

どなたか、教えて頂けないでしょうか?

宜しくお願いします。

以前、こういうのを探しだして試したところ、buttonが定義されていないとのないようのエラーが出ました。

出先からの投稿ですので、詳細なエラーメッセージは後で載せますが、どこが悪いのかが、さっぱりわかりません。

-- coding: utf-8 --

import ui

DEFAULT_TEXT = "w\n\nw w WWWW w w\n\nw"
DEFAULT_LEN = len(DEFAULT_TEXT)
DEFAULT_MID = DEFAULT_LEN/2
DEFAULT_RNG = (DEFAULT_MID, DEFAULT_MID)

class KBControlDelegate(object):
def init(self):
self.bksp = False

def keypress(self, key): out.text += key + " " def textview_should_change(self, textview, range, replacement): if replacement == "": # some deletion if range == (DEFAULT_MID-1, DEFAULT_MID): self.keypress("bksp") elif len(replacement) > 1: # paste self.keypress("cmd-v") else: self.keypress(replacement) return False def textview_did_change_selection(self, textview): nop = False if len(ctrl.text) == DEFAULT_LEN: # no change to text, only selection if ctrl.selected_range == DEFAULT_RNG: # no important changes, cursor was likely reset by script nop = True elif ctrl.selected_range[0] == ctrl.selected_range[1]: # shift was not used if ctrl.selected_range == (0, 0): # cursor is at the top self.keypress("cmd-up") elif ctrl.selected_range in ((1, 1), (2, 2)): # cursor is near the top self.keypress("up") elif ctrl.selected_range == (3, 3): # cursor is at the left self.keypress("cmd-left") elif ctrl.selected_range == (DEFAULT_LEN/2-2, DEFAULT_LEN/2-2): # cursor is exactly two chars to the left self.keypress("alt-left") elif ctrl.selected_range == (DEFAULT_LEN/2-1, DEFAULT_LEN/2-1): # cursor is exactly one char to the left self.keypress("left") elif ctrl.selected_range == (DEFAULT_LEN/2+1, DEFAULT_LEN/2+1): # cursor is exactly one char to the right self.keypress("right") elif ctrl.selected_range == (DEFAULT_LEN/2+2, DEFAULT_LEN/2+2): # cursor is exactly two chars to the right self.keypress("alt-right") elif ctrl.selected_range == (DEFAULT_LEN-3, DEFAULT_LEN-3): # cursor is at the right self.keypress("cmd-right") elif ctrl.selected_range in ((DEFAULT_LEN-2, DEFAULT_LEN-2), (DEFAULT_LEN-1, DEFAULT_LEN-1)): # cursor is near the bottom self.keypress("down") elif ctrl.selected_range == (DEFAULT_LEN, DEFAULT_LEN): # cursor is at the bottom self.keypress("cmd-down") else: # some unhandled movement nop = True self.keypress(str(ctrl.selected_range)) else: # shift was used if ctrl.selected_range == (0, DEFAULT_MID): # cursor is at the top self.keypress("shift-cmd-up") elif ctrl.selected_range in ((1, DEFAULT_MID), (2, DEFAULT_MID)): # cursor is near the top self.keypress("shift-up") elif ctrl.selected_range == (3, DEFAULT_MID): # cursor is at the left self.keypress("shift-cmd-left") elif ctrl.selected_range == (DEFAULT_LEN/2-2, DEFAULT_MID): # cursor is exactly two chars to the left self.keypress("shift-alt-left") elif ctrl.selected_range == (DEFAULT_LEN/2-1, DEFAULT_MID): # cursor is exactly one char to the left self.keypress("shift-left") elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN/2+1): # cursor is exactly one char to the right self.keypress("shift-right") elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN/2+2): # cursor is exactly two chars to the right self.keypress("shift-alt-right") elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN-3): # cursor is at the right self.keypress("shift-cmd-right") elif ctrl.selected_range in ((DEFAULT_MID, DEFAULT_LEN-2), (DEFAULT_MID, DEFAULT_LEN-1)): # cursor is near the bottom self.keypress("shift-down") elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN): # cursor is at the bottom self.keypress("shift-cmd-down") else: # some unhandled movement nop = True self.keypress(str(ctrl.selected_range)) elif len(ctrl.text) == DEFAULT_LEN - 1: # exactly one character was removed # due to the nature of bksp, this is only triggered for delete (fn-bksp) self.keypress("del") elif len(ctrl.text) < DEFAULT_LEN: # more than one character was deleted, i. e. alt-bksp self.keypress("alt-bksp") elif len(ctrl.text) > DEFAULT_LEN: # one or more characters were added and not handled by should_change # i. e. sticky key/accentuation character, need manual reset of control field # accented chars can still be typed pass else: # some unknown situation out.text += "\nSome unhandled situation: " + ctrl.selected_range + "\n" + ctrl.text + "\n\n" if not nop: ctrl.text = DEFAULT_TEXT ctrl.selected_range = DEFAULT_RNG

def run():
global root
global ctrl
global out
root = ui.load_view()
ctrl = root["ctrl"]
out = root["out"]
ctrl.delegate = KBControlDelegate()

root.present("sheet")

if name == "main":
run()

このようなエラーメッセージがでました。
しかも、2つ同時にです。

Warning: Could not bind action: name 'buttontap_up' is not defined
Warning: Could not bind action: name 'buttontap_left' is not defined
Warning: Could not bind action: name 'buttontap_right' is not defined
Warning: Could not bind action: name 'buttontap_return' is not defined
Warning: Could not bind action: name 'buttontap_down' is not defined
Warning: Could not bind action: name 'bottontap_backspace' is not defined
Warning: Could not bind action: unexpected EOF while parsing (<string>, line 1)
Warning: Could not bind action: name 'buttontap_up' is not defined
Warning: Could not bind action: name 'buttontap_left' is not defined
Warning: Could not bind action: name 'buttontap_right' is not defined
Warning: Could not bind action: name 'buttontap_return' is not defined
Warning: Could not bind action: name 'buttontap_down' is not defined
Warning: Could not bind action: name 'bottontap_backspace' is not defined
Warning: Could not bind action: unexpected EOF while parsing (<string>, line 1)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tiitoi

2018/10/01 10:34

まずご自身で取り組まれて、具体的に困っている点を提示していただけないと回答できないと思います。
shinya-ta

2018/10/02 10:18

返答ありがとうございます。文章で具体的に書いたつもりでしたが、ちゃんと伝わらなかったようで、申し訳ありませんでした。
guest

回答1

0

ベストアンサー

pythonistaマニュアルも読んでいませんが、textviewというコントロールがあるのであれば、それに関するドキュメントを読み、カーソル関連の制御ができそうなものをピックアップなさそうであれば、その親のコントロールにないかを探す

あたりをつけたら、そのAPIなどの名称でググり、使い方が出ていないか確認
自分で試して見て、所望の動作をするか確認
このタイミングでまだ解決できなければ、自分で確認した内容を提示した上でご質問されるとよろしいのではないでしょうか。

ちなみに、ネイティブであれば、Keyboard Extensionや、adjustTextPositionByCharacterOffsetがキーワードになりそうです。
pythonistaに当該APIの代替ができればできるかもしれませんね。

投稿2018/10/02 00:36

t_obara

総合スコア5488

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shinya-ta

2018/10/02 10:21

返答ありがとうございます。ググるキーワードすら、どうしていいか判らず、とりあえず思いつくキーワードでググりながら、書籍を読んでました。 早速、ヒントになりそうな項目を探してみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問