Skip to content

Instantly share code, notes, and snippets.

@jsbain jsbain/kbtest.py
Created Oct 31, 2015

Embed
What would you like to do?
kbtest.py
# coding: utf-8
import console,ui
ptype=console.alert('select present type','select one','fullscreen','panel','sheet')
ptypes=('fullscreen','panel','sheet')
class KBTest(ui.View):
def __init__(self):
self.kb_callback=None
self.frame=(0,0,768,768)
self.flex='wh'
self.add_subview(ui.TextField(frame=(25,100,200,200)))
def draw(self):
'''draw a green box around kb frame, padded by 10 pixels'''
kb=ui.get_keyboard_frame()
kb_self=ui.convert_rect(kb,None,self)
ui.set_color((0,1,0,0.5))
ui.fill_rect(kb_self[0]-10,kb_self[1]-10, kb_self[2]+20,kb_self[3]+20)
ui.draw_string('get_keyboard_frame: {}\n'
'converted to view {}\n'
'converted back to root {}\n'
'kb frame did change{}\n'
'convert((0,0,10,10),self,None)={}\n'.format(kb,kb_self,ui.convert_rect(kb_self,self,None),self.kb_callback,ui.convert_rect((0,0,10,10),self,None)),(10,10,450,120))
def keyboard_frame_did_change(self,frame):
ui.delay(self.set_needs_display,0.2)
self.kb_callback=frame
V=KBTest()
V.present(ptypes[ptype-1],hide_title_bar=False ) #works if hide is True too
V.bg_color=(1,1,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.