Forum Archive

Keyboard ui button.

shinya.ta

I've made a keyboard application. I want to make a list of Emoji by its development.

Can I use the ui button to create a different window?

cvp

@shinya.ta I want to help you but I don't understand your request.

shinya.ta

It is a window that replaces the task bar.

If you register a lot of Emoji on the task bar, the text field is filled and it becomes difficult to check the sentence.

In the Emoji list of emoji on the iPhone, there are too many emoji to use, so I want to open the window that I can go on a screen with a button.

cvp

@shinya.ta Sorry, I still don't understand. You speak about a keyboard application, what is the textfield? How is it filled?

cvp

@shinya.ta Do you want to say, in my little script using setInputAccessoryView, you want to display emojis not all in one shot but in several parts with a button to get the next set?

cvp

@shinya.ta If I correctly understood, try this at the end of your script (if based on mine)

def nextSet(sender):
    i_set = sender.i_set + 1
    if i_set == sender.n_sets:
        i_set = 0
    #attach our accessory to the textfield, and textview
    ww = vv_array[i_set]
    tvo = tv.objc_instance
    #print(dir(tvo))
    tvo.setInputAccessoryView_(ObjCInstance(ww))
    tvo.reloadInputViews()

#create normal keys
d = 32
dd = 4
emojis = '๐Ÿ˜Š๐Ÿ˜œ๐Ÿ˜ฑ๐Ÿ’ฆโ˜”๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜๐Ÿ˜†๐Ÿ˜…๐Ÿ˜‚๐Ÿคฃโ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜‡๐Ÿ™‚๐Ÿ™ƒ๐Ÿ˜‰๐Ÿ˜Œ๐Ÿ˜๐Ÿฅฐ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜‹๐Ÿ˜›๐Ÿ˜๐Ÿ˜œ๐Ÿคช๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜Ž๐Ÿคฉ๐Ÿฅณ๐Ÿ˜๐Ÿ˜’๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜Ÿ๐Ÿ˜•๐Ÿ™โ˜น๏ธ๐Ÿ˜ฃ๐Ÿ˜–๐Ÿ˜ซ๐Ÿ˜ฉ๐Ÿฅบ๐Ÿ˜ข๐Ÿ˜ญ๐Ÿ˜ค๐Ÿ˜ ๐Ÿ˜ก๐Ÿคฌ๐Ÿคฏ๐Ÿ˜ณ๐Ÿฅต๐Ÿฅถ๐Ÿ˜ฑ๐Ÿ˜จ๐Ÿ˜ฐ๐Ÿ˜ฅ๐Ÿ˜“๐Ÿค—๐Ÿค”๐Ÿคญ๐Ÿคซ๐Ÿคฅ๐Ÿ˜ถ๐Ÿ˜๐Ÿ˜‘๐Ÿ˜ฌ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜ฎ๐Ÿ˜ฒ๐Ÿ˜ด๐Ÿคค๐Ÿ˜ช๐Ÿ˜ต๐Ÿค๐Ÿฅด๐Ÿคข๐Ÿคฎ๐Ÿคง๐Ÿ˜ท๐Ÿค’๐Ÿค•๐Ÿค‘๐Ÿค ๐Ÿ˜ˆ'
n_sets = 4
vv_array = []
for i_set in range(0,n_sets):
    l = int(len(emojis)/n_sets)
    i = i_set * l
    set_emojis = emojis[i:i+l] + 'โฉ'
    w, h = ui.get_screen_size() 
    vv = ui.View(name='set'+str(i_set))
    vv.background_color = 'lightgray'
    h = 0
    x = dd
    y = dd
    for button_title in set_emojis:
        b = ui.Button(title=button_title)
        if button_title == 'โฉ':
            b_action = nextSet
            b.i_set = i_set
            b.n_sets = n_sets
            b.name = 'nextSet'
        else:
            b_action = typeChar
        b.action=b_action
        b.frame = (x,y,d,d)
        b.font = ('.SFUIText', d)
        if (y+d+dd) > h:
            h = y + d + dd
        vv.add_subview(b)
        x = x + d + dd
        if (x+d+dd) > w:
            x = dd
            y = y + d + dd
    vv.frame = (0,0,w,h)
    vv_array.append(vv)

i_set = 0
nextSet(vv_array[n_sets-1]['nextSet'])  # display 1st set

v.present('sheet')
tv.selected_range = (0,0)
tv.begin_editing()

shinya.ta

@cvp

It's a little different from what I was thinking, but that's a good idea.

b_action = typeChar

Here is a name error.
Why?

cvp

@shinya.ta It was the action of my old script

def typeChar(sender):
    '''finds active textinput, and types the button's title'''
    tf=sender.objc_instance.firstResponder()
    tf.insertText_(sender.title)

But I don't know what your script became....

cvp

@shinya.ta And it is only an example of what you could do. You could have any button with the title or image you want to display next set of emojis.

shinya.ta

@cvp

Dear.cvp

I'll try it again.

shinya.ta

@cvp

It was successful.

I want to use this application vertically, so I hope the display of emoji is less.

How can I adjust the number of emoji?

cvp

@shinya.ta Hello
The n_sets sets the number of sets
You could set the number of emojis you want per set and then compute the number of sets

n_emojis_in_set = 20
n_sets = 1 + int((len(emojis)-1)/n_emojis_in_set)

cvp

@shinya.ta please let me know if it is ok and if you want to put the "next set" button at another place

shinya.ta

@cvp

Dear.cvp

n_emojis_in_set = 20
n_sets = 1 + int((len(emojis)-1)/n_emojis_in_set)

Where should I put this code in?
I tried to put it in the last line, but there was no change.

shinya.ta

@cvp

It is the best if I can set this emoji to the task bar only by the operation of my wife who is visually impaired.

Is Pythonisa possible to set up a button only with buttons, not in the operation of the program?

cvp

@shinya.ta instead of

emojis = '๐Ÿ˜Š๐Ÿ˜œ๐Ÿ˜ฑ๐Ÿ’ฆโ˜”๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜๐Ÿ˜†๐Ÿ˜…๐Ÿ˜‚๐Ÿคฃโ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜‡๐Ÿ™‚๐Ÿ™ƒ๐Ÿ˜‰๐Ÿ˜Œ๐Ÿ˜๐Ÿฅฐ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜‹๐Ÿ˜›๐Ÿ˜๐Ÿ˜œ๐Ÿคช๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜Ž๐Ÿคฉ๐Ÿฅณ๐Ÿ˜๐Ÿ˜’๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜Ÿ๐Ÿ˜•๐Ÿ™โ˜น๏ธ๐Ÿ˜ฃ๐Ÿ˜–๐Ÿ˜ซ๐Ÿ˜ฉ๐Ÿฅบ๐Ÿ˜ข๐Ÿ˜ญ๐Ÿ˜ค๐Ÿ˜ ๐Ÿ˜ก๐Ÿคฌ๐Ÿคฏ๐Ÿ˜ณ๐Ÿฅต๐Ÿฅถ๐Ÿ˜ฑ๐Ÿ˜จ๐Ÿ˜ฐ๐Ÿ˜ฅ๐Ÿ˜“๐Ÿค—๐Ÿค”๐Ÿคญ๐Ÿคซ๐Ÿคฅ๐Ÿ˜ถ๐Ÿ˜๐Ÿ˜‘๐Ÿ˜ฌ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜ฎ๐Ÿ˜ฒ๐Ÿ˜ด๐Ÿคค๐Ÿ˜ช๐Ÿ˜ต๐Ÿค๐Ÿฅด๐Ÿคข๐Ÿคฎ๐Ÿคง๐Ÿ˜ท๐Ÿค’๐Ÿค•๐Ÿค‘๐Ÿค ๐Ÿ˜ˆ'
n_sets = 4
vv_array = []

Do

emojis = '๐Ÿ˜Š๐Ÿ˜œ๐Ÿ˜ฑ๐Ÿ’ฆโ˜”๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜๐Ÿ˜†๐Ÿ˜…๐Ÿ˜‚๐Ÿคฃโ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜‡๐Ÿ™‚๐Ÿ™ƒ๐Ÿ˜‰๐Ÿ˜Œ๐Ÿ˜๐Ÿฅฐ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜‹๐Ÿ˜›๐Ÿ˜๐Ÿ˜œ๐Ÿคช๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜Ž๐Ÿคฉ๐Ÿฅณ๐Ÿ˜๐Ÿ˜’๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜Ÿ๐Ÿ˜•๐Ÿ™โ˜น๏ธ๐Ÿ˜ฃ๐Ÿ˜–๐Ÿ˜ซ๐Ÿ˜ฉ๐Ÿฅบ๐Ÿ˜ข๐Ÿ˜ญ๐Ÿ˜ค๐Ÿ˜ ๐Ÿ˜ก๐Ÿคฌ๐Ÿคฏ๐Ÿ˜ณ๐Ÿฅต๐Ÿฅถ๐Ÿ˜ฑ๐Ÿ˜จ๐Ÿ˜ฐ๐Ÿ˜ฅ๐Ÿ˜“๐Ÿค—๐Ÿค”๐Ÿคญ๐Ÿคซ๐Ÿคฅ๐Ÿ˜ถ๐Ÿ˜๐Ÿ˜‘๐Ÿ˜ฌ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜ฎ๐Ÿ˜ฒ๐Ÿ˜ด๐Ÿคค๐Ÿ˜ช๐Ÿ˜ต๐Ÿค๐Ÿฅด๐Ÿคข๐Ÿคฎ๐Ÿคง๐Ÿ˜ท๐Ÿค’๐Ÿค•๐Ÿค‘๐Ÿค ๐Ÿ˜ˆ'
n_emojis_in_set = 20
n_sets = 1 + int((len(emojis)-1)/n_emojis_in_set)
vv_array = []
cvp

@shinya.ta Sorry, I don't understand this

It is the best if I can set this emoji to the task bar only by the operation of my wife who is visually impaired.

Is Pythonisa possible to set up a button only with buttons, not in the operation of the program?

If I correctly understand, you want to ask this "next set of emojis" by a normal button.
But where do you want this button?

shinya.ta

@cvp

Sorry for the poor English.

It is a button that my wife can set emoji by herself.

The location of the button is okay anywhere.

cvp

@shinya.ta Try

#create normal keys
d = 32
dd = 4
emojis = '๐Ÿ˜Š๐Ÿ˜œ๐Ÿ˜ฑ๐Ÿ’ฆโ˜”๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜๐Ÿ˜†๐Ÿ˜…๐Ÿ˜‚๐Ÿคฃโ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜‡๐Ÿ™‚๐Ÿ™ƒ๐Ÿ˜‰๐Ÿ˜Œ๐Ÿ˜๐Ÿฅฐ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜‹๐Ÿ˜›๐Ÿ˜๐Ÿ˜œ๐Ÿคช๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜Ž๐Ÿคฉ๐Ÿฅณ๐Ÿ˜๐Ÿ˜’๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜Ÿ๐Ÿ˜•๐Ÿ™โ˜น๏ธ๐Ÿ˜ฃ๐Ÿ˜–๐Ÿ˜ซ๐Ÿ˜ฉ๐Ÿฅบ๐Ÿ˜ข๐Ÿ˜ญ๐Ÿ˜ค๐Ÿ˜ ๐Ÿ˜ก๐Ÿคฌ๐Ÿคฏ๐Ÿ˜ณ๐Ÿฅต๐Ÿฅถ๐Ÿ˜ฑ๐Ÿ˜จ๐Ÿ˜ฐ๐Ÿ˜ฅ๐Ÿ˜“๐Ÿค—๐Ÿค”๐Ÿคญ๐Ÿคซ๐Ÿคฅ๐Ÿ˜ถ๐Ÿ˜๐Ÿ˜‘๐Ÿ˜ฌ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜ฎ๐Ÿ˜ฒ๐Ÿ˜ด๐Ÿคค๐Ÿ˜ช๐Ÿ˜ต๐Ÿค๐Ÿฅด๐Ÿคข๐Ÿคฎ๐Ÿคง๐Ÿ˜ท๐Ÿค’๐Ÿค•๐Ÿค‘๐Ÿค ๐Ÿ˜ˆ'
n_emojis_in_set = 20
n_sets = 1 + int((len(emojis)-1)/n_emojis_in_set)
vv_array = []
for i_set in range(0,n_sets):
    l = int(len(emojis)/n_sets)
    i = i_set * l
    set_emojis = emojis[i:i+l]
    w, h = ui.get_screen_size() 
    vv = ui.View(name='set'+str(i_set))
    vv.background_color = 'lightgray'
    h = 0
    x = dd
    y = dd
    for button_title in set_emojis:
        b = ui.Button(title=button_title)
        b_action = typeChar
        b.action=b_action
        b.frame = (x,y,d,d)
        b.font = ('.SFUIText', d)
        if (y+d+dd) > h:
            h = y + d + dd
        vv.add_subview(b)
        x = x + d + dd
        if (x+d+dd) > w:
            x = dd
            y = y + d + dd
    vv.frame = (0,0,w,h)
    vv_array.append(vv)

tv.i_set = 0
tv.n_sets = n_sets
def nextSet(sender):
    tv.i_set = tv.i_set + 1
    if tv.i_set == tv.n_sets:
        tv.i_set = 0
    #attach our accessory to the textfield, and textview
    ww = vv_array[tv.i_set]
    tvo = tv.objc_instance
    #print(dir(tvo))
    tvo.setInputAccessoryView_(ObjCInstance(ww))
    tvo.reloadInputViews()

nextSet(vv_array[n_sets-1]['nextSet'])  # display 1st set

# add a button at right of "typing suggestions", just above the keyboard
bb_target = ui.Button()
bb_target.action = nextSet
UIBarButtonItem = ObjCClass('UIBarButtonItem').alloc().initWithTitle_style_target_action_('Next Emojis',0,bb_target,sel('invokeAction:')).autorelease()
#UIBarButtonItem = ObjCClass('UIBarButtonItem').alloc().initWithImage_style_target_action_(ns(ui.Image.named('emj:Bicycle').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)),0,bb_target,sel('invokeAction:')).autorelease()

UIBarButtonItemGroup = ObjCClass('UIBarButtonItemGroup').alloc().initWithBarButtonItems_representativeItem_([UIBarButtonItem],None)

tvo = tv.objc_instance
tvo.inputAssistantItem().setTrailingBarButtonGroups([UIBarButtonItemGroup])

v.present('sheet')
tv.selected_range = (0,0)
tv.begin_editing()

shinya.ta

@cvp

Dear.cvp

I didn't have a test because I didn't have time to try it.
I'll take a test on the weekend.

shinya.ta

@cvp

Dear.cvp

When I tried the program, I got a Syntaxerror. Why is that?

cvp

@shinya.ta If the syntax error comes from the last line, I had made a copy/paste error, please check the two last lines versus the edit script above

shinya.ta

@cvp

Dear.cvp

I tried it, but iPad can show next emji, but I couldn't display it on iPhone.

shinya.ta

@cvp

I would like to display multiple windows at the same time and edit the text.

Can I make it with Pythonisa?

I don't know how to send pictures here.
If you see the picture, I think you can see the image.

cvp

@shinya.ta To post here a picture, I use this little script:

import pyimgur,photos,clipboard,os,console
i=photos.pick_image()
if i:
    print(i.format)
    format = 'gif' if (i.format == 'GIF') else 'jpg'
    i.save('img.'+format)
    clipboard.set(pyimgur.Imgur("303d632d723a549").upload_image('img.'+format, title="Uploaded-Image").link)
    console.hud_alert("link copied!")
    os.remove('img.'+format)

You have to
- run this script
- the program will ask you to pick a picture from your camera roll
- the program sends the picture to imgur site and copy the url in the clipboard
- here, in the forum, you paste this url from the clipboard in a post
- that's all, it takes some seconds

cvp

@shinya.ta If the 'next emoji' is not displayed on iPhone, it is perhaps a problem of screen width (sorry, I can't test it), you could try to put a shorter title to this button, like

UIBarButtonItem = ObjCClass('UIBarButtonItem').alloc().initWithTitle_style_target_action_('โฉ',0,bb_target,sel('invokeAction:')).autorelease()

If you parametrized big characters in your iPhone settings, the system does not have sufficient room to display this button

shinya.ta

@cvp

It was difficult to send a photo to me because it was difficult to send.
So, I will explain in writing.

Can I open multiple windows at the same time with Pythonisa so that I can open multiple tasks with a computer?

cvp

@shinya.ta you can run multiple threads to process several tasks at once but you will have only one UI, user interface, thus not really multiple windows active at the same time.

cvp

@shinya.ta Apple's doc says:

Custom items can be added to the shortcuts bar on iPad only. On iPhone, the contents of the UITextInputAssistantItem object are ignored.

here

cvp

@shinya.ta You can find a version running on iPhone and iPad here

shinya.ta

@cvp

I see, I'll try to open it on GitHub.

cvp

@shinya.ta you can always
- tap raw
- select all
- copy
- paste it into your (new) script in Pythonista

shinya.ta

@cvp

Thank you. I'll try it on the weekend.

You are God.

cvp

@shinya.ta Try it before saying that, you'll perhaps regret it ๐Ÿ˜‡

shinya.ta

@cvp

I am not sure if it is related to this program, but if you use voiceover on Pythonisa, there will be a sound that is irrelevant to the prediction conversion.

Why is this?

cvp

@shinya.ta I'm really sorry but I don't understand your post.
First of all, if your problem occurs when you start Pythonista, even outside my script, please try to describe with a maximum of details the problem in a new topic,assuming it is a Pythonista bug, thus for @omz
If the problem occurs only in my script, stay in this topic but give, please , more info's.

shinya.ta

@cvp

The same thing happened in the script on GitHub.

Is it better to make a topic with another topic?

cvp

@shinya.ta Ok, try first in this topic, but, please, give a maximum infos about the problem

shinya.ta

@cvp

Dear.cvp

I tried the spractin.
I was able to do it well both on iPhone and iPad.

Thank you very much.

shinya.ta

@cvp

I'm a little greedy, but is it possible to use the following programs mixed?

import ui
from objc_util import *

def NextFieldKeyInTextFieldKeyboard(view, button, background_color='lightgray'):
    # parameters: view = main view of textfields
    #                           button = ui.Button designed by user (size, title, image...)
    #                           background_color = background_color of InputAccessoryView
    # create ui.View for InputAccessoryView above keyboard
    v = ui.View()                                                   # view above keyboard
    v.background_color = background_color   # background_color of user choice
    v.width = ui.get_screen_size()[0]           # width of screen, thus of keyboard
    v.height = button.height + 4                    # only for Next button

    # code executed when Next key is tapped
    def Next_tapped(sender):
        s = sender.objc_instance.firstResponder()._nextKeyResponder().becomeFirstResponder()    
    button.action = Next_tapped                     # code to be executed if button tapped
    v.add_subview(button)                                   # set as subview of view

    vo = ObjCInstance(v)                                    # get ObjectiveC object of v
    # attach to each textfield an InputAccessoryView abobe the keyboard
    for sv in view.subviews:                            # loop on all subviews of main view
        if 'TextField' in str(type(sv)):        # subview is a TextField
            tfo = ObjCInstance(sv).textField()# get ObjectiveC object of sv
            tfo.setInputAccessoryView_(vo)      # attach our accessory to textfield

if __name__ == '__main__':
    main_view = ui.View()
    main_view.name = 'NextFieldKeyInTextFieldKeyboard'
    main_view.frame = (0,0,380,140)
    main_view.add_subview(ui.TextField(frame=(10,  2,360,32)))
    main_view.add_subview(ui.TextField(frame=(10, 36,360,32)))
    main_view.add_subview(ui.TextField(frame=(10, 70,360,32)))
    main_view.add_subview(ui.TextField(frame=(10,104,360,32)))
    button = ui.Button()                                # Button for Next key
    button.frame = (0,0,32,32)
    button.font = ('<System-Bold>',24)
    button.title = 'โฏ'                                  #  emoji as title
    NextFieldKeyInTextFieldKeyboard(main_view,button)#,background_color='green')
    main_view.present('sheet')
shinya.ta

@cvp

If possible, I would like to edit multiple Text views.

cvp

@shinya.ta Just to be sure: multiple TextViews but with buttons only once?
Button should process on TextView where the cursor is? Please confirm before I begin. Thanks

cvp

@shinya.ta Could you try/test this version and give me your feedback, thanks
script with multiple TextViews

shinya.ta

@cvp

Dear.cvp

Wonderful. I was looking for this.
It's perfect.

You are God.
Thank you very much.
Thank you very much.

cvp

@shinya.ta Hello, I'm happy it's ok for you, but, believe me, I'm very far to be a god of Python, or even of anything else, like my wife says ๐Ÿ˜‚

shinya.ta

@cvp

Dear.cvp

Finally, there was one problem.
Even though the speech is written, they don't read the letters.

Is there any problem?

shinya.ta

@cvp

I haven't checked the iPad yet, but the Emoji task bar doesn't show it on the iPhone.

cvp

@shinya.ta the button Next Emojis will not appear on iPad.
see Apple doc

But it should appear in the emojis rows.

cvp

@shinya.ta You were right, I had a bug for an iPhone, I'm sorry, sincerely

correction here

About the speech problem, is this one occurring since your update?

shinya.ta

@cvp

The Emoji task bar was displayed on iPhone, too.
I didn't speak the speech on the iPhone.
I speak properly with iPad.

cvp

@shinya.ta You have to check of your general settings are the same on your iPad and your iPhone

shinya.ta

@cvp

How can I confirm that?

cvp

@shinya.ta check one y one your settings in general/accessibility

shinya.ta

@cvp

I checked the accessibility.
But all of them were set in the same way.

My wife's iPhone has a home button. There is a home button on iPad, too.
But mine is iPhone XS Max, so there is no home button.

Is it because of the difference in the device?

cvp

@shinya.ta Sorry but I don't know that. Hoping somebody else in the forum could help you