omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello โ€” I'm @olemoritz on Twitter.


    New button addition.

    Pythonista
    5
    50
    14244
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp @ccc last edited by

      @ccc it's not his fault, this is my code and, at the time, he requested one button at a time ...

      1 Reply Last reply Reply Quote 1
      • cvp
        cvp @shinya.ta last edited by

        @shinya.ta said:

        I want to add a new button.
        All Text Reading Buttons.
        Then, from the beginning of the text, it is the button to read the position of the cursor.
        Is it possible?

        I understand you want a new button, but I don't understand its function.

        What is "all text reading buttons"?

        Do you want that the button action displays the position of the cursor? Like row,column?
        And, if yes, where to display it?

        JonB 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @ccc last edited by

          @ccc said:

          reduce repetitive code by adding a self.make_button() method

          But you're right, I'll do it

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by ccc

            My sense was that this was cursor up, down, left, right buttons on the top row of the on-screen keyboard to the right of cut, copy, paste.

            cvp 1 Reply Last reply Reply Quote 0
            • JonB
              JonB @cvp last edited by

              @cvp I gather he wants something to read (text to speech) starting from the cursor...

              1 Reply Last reply Reply Quote 0
              • cvp
                cvp @ccc last edited by

                @ccc @JonB you could be right, but, please, I want to be sure...

                1 Reply Last reply Reply Quote 0
                • shinya.ta
                  shinya.ta last edited by

                  I'm sorry, I'm not good at English, so I couldn't write well.

                  I would like you to read the text at the cursor position.
                  And I want you to read all the text fields in the text field.

                  cvp 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @shinya.ta last edited by

                    @shinya.ta I understand your language problem, English is not my mother language and I also have a lot of problems of comprehension ๐Ÿ˜…
                    Thus, do you want to have two buttons?
                    One to read the text at the cursor (only one character? One word? All from the cursor?)
                    A second button to read the entire text?

                    1 Reply Last reply Reply Quote 0
                    • shinya.ta
                      shinya.ta last edited by

                      All from the cursor.
                      And the whole text.

                      cvp 2 Replies Last reply Reply Quote 0
                      • cvp
                        cvp @shinya.ta last edited by

                        @shinya.ta ok, last (I hope) questions: where do you want these buttons and which title on them?

                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @shinya.ta last edited by cvp

                          @shinya.ta first of all, @ccc advice followed here Emojis Keyboard.py
                          Please try it, thanks

                          1 Reply Last reply Reply Quote 0
                          • shinya.ta
                            shinya.ta last edited by

                            Yes, it's necessary for me.

                            cvp 2 Replies Last reply Reply Quote 0
                            • cvp
                              cvp @shinya.ta last edited by

                              @shinya.ta said:

                              Yes, it's necessary for me.

                              sorry, I don't understand to which questions you answer ๐Ÿค”

                              1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @shinya.ta last edited by

                                @shinya.ta I have still an important question: do you use this keyboard in a text field of more than one line? Because Pythonista keyboard module does not support it easily.

                                1 Reply Last reply Reply Quote 0
                                • shinya.ta
                                  shinya.ta last edited by

                                  I need this reading button for my wife.

                                  cvp 1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp @shinya.ta last edited by

                                    @shinya.ta i understand why you need it but you don't answer to my questions:

                                    1. where do you want these buttons?
                                    2. which title?
                                      3 ) do you use it in a text field of multiple lines?

                                    Ex:

                                    1 Reply Last reply Reply Quote 0
                                    • shinya.ta
                                      shinya.ta last edited by

                                      1. I want to have a button here.
                                      2. It's okay with the title of the picture.
                                      3. I use it in multiple lines.
                                      cvp 3 Replies Last reply Reply Quote 0
                                      • cvp
                                        cvp @shinya.ta last edited by

                                        @shinya.ta said:

                                        I want to have a button here.

                                        Sorry, but one more time I don't understand. For the moment, I'll keep "my" positions

                                        1 Reply Last reply Reply Quote 0
                                        • cvp
                                          cvp @shinya.ta last edited by

                                          @shinya.ta said:

                                          I use it in multiple lines.

                                          Let us begin with one line at once because Pythonista's keyboard module does not support multiple lines in keyboard.get_input_context() module

                                          1 Reply Last reply Reply Quote 0
                                          • cvp
                                            cvp @shinya.ta last edited by

                                            @shinya.ta I've problems with uploading to GitHub, just now, thus, please try this, it works for me in English and for one line, that's just the beginning.

                                            import keyboard
                                            import ui
                                            from objc_util import *
                                            import clipboard
                                            import speech
                                            import sys
                                            
                                            import time
                                            import threading
                                            			  
                                            class MyView(ui.View):
                                            	def __init__(self, *args, **kwargs):
                                            		super().__init__(self, *args, **kwargs)
                                            		self.background_color = 'lightgray'
                                            		
                                            		# bounds not yet known in init, let some delay		
                                            		ui.delay(self.dimensions,0.1)
                                            		
                                            	def dimensions(self):				
                                            		w,h = self.bounds.size
                                            		
                                            		h_icons = 40
                                            		
                                            		dd = 2
                                            		d = (h-4*dd-h_icons)/3
                                            		x0 = (w -3*d - 2*dd)/2
                                            
                                            		x = x0 - d/2
                                            		y = h_icons + dd		
                                            		def b_top_action(sender):
                                            			t = keyboard.get_input_context()	# current line
                                            			l = len(t[0])
                                            			keyboard.move_cursor(-l)
                                            		self.d = d
                                            		self.make_button(x,y,d,'ๆ–‡้ ญ',b_top_action) # begin of sentence
                                            
                                            		x = x0 + 1 * (d + dd)
                                            		y = h_icons + dd
                                            		def b_up_action(sender):
                                            			t = keyboard.get_input_context()	# current line
                                            			l0 = len(t[0])
                                            			l1 = len(t[1])
                                            			keyboard.move_cursor(-l0)
                                            			keyboard.move_cursor(-1)					# end of previous line
                                            			t = keyboard.get_input_context()	# previous line
                                            			l2 = len(t[0])
                                            			l3 = len(t[1])
                                            			#sender.title = str(l0)+' '+str(l1)+' '+str(l2)+' '+str(l3)
                                            			if l2 >= l0:
                                            				keyboard.move_cursor(-(l2-l0))
                                            			else:
                                            				pass											# line is shorter than l0, thus stay at end
                                            		self.make_button(x,y,d,'โฌ†๏ธ',b_up_action)
                                            		
                                            		x = x0 + 2 * (d + dd)
                                            		y = h_icons + dd
                                            		def b_read_from_action(sender):
                                            			t = keyboard.get_input_context()
                                            			speech.say(t[1],'jp-JP')
                                            			#speech.say(t[1],'en-EN')
                                            		self.make_button(x,y,d,'read\nfrom',b_read_from_action)
                                            		
                                            		x = x0 + 3 * (d + dd)
                                            		y = h_icons + dd
                                            		def b_read_all_action(sender):
                                            			keyboard.move_cursor(-1000)
                                            			t = keyboard.get_input_context()
                                            			speech.say(t[1],'jp-JP')
                                            			#speech.say(t[1],'en-EN')
                                            		self.make_button(x,y,d,'read\nall',b_read_all_action)
                                            
                                            		x = x0
                                            		y = h_icons + dd + 1 * (d + dd)
                                            		def b_left_action(sender):
                                            			keyboard.move_cursor(-1)
                                            		self.make_button(x,y,d,'โฌ…๏ธ',b_left_action)
                                            		
                                            		x = x0 + 1 * (d + dd)
                                            		y = h_icons + dd + 1 * (d + dd)
                                            		def b_bottom_action(sender):
                                            			t = keyboard.get_input_context()	# current line
                                            			l = len(t[1])
                                            			keyboard.move_cursor(+l)
                                            			move = my_thread(1)
                                            			move.start()
                                            		self.make_button(x,y,d,'ๆ–‡ๆœซ',b_bottom_action)   # end of sentence
                                            
                                            		x = x0 + 2 * (d + dd)
                                            		y = h_icons + dd + 1 * (d + dd)
                                            		def b_right_action(sender):
                                            			keyboard.move_cursor(+1)
                                            		self.make_button(x,y,d,'โžก๏ธ',b_right_action)
                                            
                                            		x = x0 - d/2
                                            		y = h_icons + dd + 2 * (d + dd)		
                                            		def b_copy_action(sender):
                                            			context = keyboard.get_input_context()
                                            			t = keyboard.get_selected_text()
                                            			clipboard.set(t)
                                            		if keyboard.has_full_access():
                                            			self.make_button(x,y,d,'copy',b_copy_action)
                                            		else:
                                            			self.make_button(x,y,d,'no full',b_copy_action)    
                                            
                                            		x = x0 + 1 * (d + dd)
                                            		y = h_icons + dd + 2 * (d + dd)
                                            		def b_down_action(sender):
                                            			t = keyboard.get_input_context()	# current line
                                            			l0 = len(t[0])
                                            			l1 = len(t[1])
                                            			keyboard.move_cursor(l1)
                                            			keyboard.move_cursor(1)						# begin of next line
                                            			t = keyboard.get_input_context()	# next line
                                            			l2 = len(t[0])
                                            			l3 = len(t[1])
                                            			if (l2+l3) >= l0:
                                            				keyboard.move_cursor(l0)
                                            			else:
                                            				pass
                                            				#keyboard.move_cursor(2)#l0-l2)
                                            		self.make_button(x,y,d,'โฌ‡๏ธ',b_down_action)
                                            		
                                            		x = x0 + 2 * (d + dd) + dd + d/2
                                            		y = h_icons + dd + 2 * (d + dd)
                                            		def b_delete_action(sender):
                                            			keyboard.backspace(times=1)
                                            		self.make_button(x,y,d,'ๅทฆๅ‰Š้™ค',b_delete_action)  # delete
                                            		
                                            		d = 32
                                            		dd = 4
                                            		w_buttons = 0
                                            
                                            		#create normal keys
                                            		emojis = '๐Ÿ˜Š๐Ÿ˜œ๐Ÿ˜ฑ๐Ÿ’ฆโ˜”๏ธ(็ฌ‘)โ˜€๏ธโ˜๏ธโ˜ƒ๏ธโ„๏ธ๐Ÿ™๐Ÿ”๐Ÿš—๐ŸŒˆโญ๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜๐Ÿ˜†๐Ÿ˜…๐Ÿ˜‚๐Ÿคฃโ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜‡๐Ÿ™‚๐Ÿ™ƒ๐Ÿ˜‰๐Ÿ˜Œ๐Ÿ˜๐Ÿฅฐ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜‹๐Ÿ˜›๐Ÿ˜๐Ÿ˜œ๐Ÿคช๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜Ž๐Ÿคฉ๐Ÿฅณ๐Ÿ˜๐Ÿ˜’๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜Ÿ๐Ÿ˜•๐Ÿ™โ˜น๏ธ๐Ÿ˜ฃ๐Ÿ˜–๐Ÿ˜ซ๐Ÿ˜ฉ๐Ÿฅบ๐Ÿ˜ข๐Ÿ˜ญ๐Ÿ˜ค๐Ÿ˜ ๐Ÿ˜ก๐Ÿคฌ๐Ÿคฏ๐Ÿ˜ณ๐Ÿฅต๐Ÿฅถ๐Ÿ˜จ๐Ÿ˜ฐ๐Ÿ˜ฅ๐Ÿ˜“๐Ÿค—๐Ÿค”๐Ÿคญ๐Ÿคซ๐Ÿคฅ๐Ÿ˜ถ๐Ÿ˜๐Ÿ˜‘๐Ÿ˜ฌ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜ฎ๐Ÿ˜ฒ๐Ÿ˜ด'
                                            		n_emojis_in_set = 10
                                            		n_sets = 1 + int((len(emojis)-1)/n_emojis_in_set)
                                            		self.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 = self.nextSet
                                            					b.i_set = i_set
                                            					b.n_sets = n_sets
                                            					b.name = 'nextSet'
                                            				else:
                                            					b_action = self.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 = (w_buttons,0,w-w_buttons,h)
                                            			self.vv_array.append(vv)
                                            			self.add_subview(vv)  
                                            			
                                            		i_set = 0
                                            		self.nextSet(self.vv_array[n_sets-1]['nextSet'])  # display 1st set
                                            		
                                            	def make_button(self,x,y,d,title,action):
                                            		b = ui.Button()
                                            		b.frame = (x,y,d,d)
                                            		b.background_color = 'white'
                                            		b.border_width = 1
                                            		b.corner_radius = self.d/4
                                            		b.title = title
                                            		if '\n' in title:
                                            			bo = ObjCInstance(b)
                                            			for sv in bo.subviews(): 
                                            				if hasattr(sv,'titleLabel'):
                                            					tl = sv.titleLabel()
                                            					tl.numberOfLines = 0
                                            		b.action = action
                                            		self.add_subview(b)
                                            		
                                            	def typeChar(self,sender):
                                            		keyboard.insert_text(sender.title)
                                            
                                            	def nextSet(self,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 = self.vv_array[i_set]
                                            		ww.bring_to_front()
                                            		
                                            def main():
                                            	if not keyboard.is_keyboard():
                                            		return
                                            	v = MyView()
                                            	keyboard.set_view(v, 'expanded')
                                            	
                                            if __name__ == '__main__':
                                            	main()
                                            
                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors