def MakeT9Keyboard(alphabetStr='abcdefghijklmnopqrstuvwxyz', scale=0.9): shift = (1, -1) h = core.Polygon() pad = (1.0 - scale) / 2.0 h.AddVertex(pad, -pad) h.AddVertex(1 - pad, -pad) h.AddVertex(1 - pad, pad - 1) h.AddVertex(pad, pad - 1) h.Translate(-2.5, 1.5) l = [] for j in range(3): oldp = h for i in range(3): p = deepcopy(oldp) p.Translate(shift[0], 0) if not (i == 0 and j == 0): for k in range(3): l.append(p) if j == 2 and (i != 1): l.append(p) oldp = p h.Translate(0, shift[1]) k = core.Keyboard() for i in range(26): k.AddKey(alphabetStr[i], l[i]) return k
def MakeHexagonalKeyboard(alphabetStr='qwertyuiopasdfghjklzxcvbnm.', scale=0.9): shift = (sqrt(3), -1.5) a, b, c = scale, scale / 2.0, sqrt(3) * scale / 2 h = core.Polygon() h.AddVertex(0, -a) h.AddVertex(c, -b) h.AddVertex(c, b) h.AddVertex(0, a) h.AddVertex(-c, b) h.AddVertex(-c, -b) h.Translate(-shift[0] / 2.0, 0) l = [] for j in range(3): oldp = h for i in range(10 - j): p = deepcopy(oldp) p.Translate(shift[0], 0) l.append(p) oldp = p h.Translate(0.5 * shift[0], shift[1]) k = core.Keyboard() for i in range(27): k.AddKey(alphabetStr[i], l[i]) return k
def MakeLetterEaseKeyboard(alphabetStr='elzowsktmqagrfnbicyxuphvdj', scale=0.9): shift = (1, -1) h = core.Polygon() pad = (1.0 - scale) / 2.0 h.AddVertex(pad, -pad) h.AddVertex(1 - pad, -pad) h.AddVertex(1 - pad, pad - 1) h.AddVertex(pad, pad - 1) h.Translate(-2.5, 1.5) l = [] for j in range(4): oldp = h for i in range(3): p = deepcopy(oldp) p.Translate(shift[0], 0) if (i == 0): if (j == 0 or j == 1): l.append(p) for k in range(2): l.append(p) oldp = p h.Translate(0, shift[1]) k = core.Keyboard() for i in range(26): k.AddKey(alphabetStr[i], l[i]) return k
def RandomKeyboard(keyboard=None): if keyboard == None: keyboard = MakeStandardKeyboard() d = keyboard.PolygonDict() letters = keyboard.OrderedKeyList() polygons = [keyboard.GetKey(k) for k in letters] indices = list(range(len(letters))) shuffle(indices) newk = core.Keyboard() for i, idx in enumerate(indices): newk.AddKey(letters[idx], polygons[i]) return newk
def RandomSwap(keyboard, Nswaps=1): d = keyboard.PolygonDict() letters = keyboard.OrderedKeyList() polygons = [keyboard.GetKey(k) for k in letters] indices = list(range(len(letters))) for swap in range(Nswaps): c = (choice(indices), choice(indices)) # print("choices:", c) indices[c[0]], indices[c[1]] = indices[c[1]], indices[c[0]] newk = core.Keyboard() for i, idx in enumerate(indices): newk.AddKey(letters[idx], polygons[i]) return newk
def MakeDvorakKeyboard(alphabetStr='.pyfgcrlaoeuidhtnsqjkxbmwvz'): width = 1.0 height = 1.5 gap = 0.2 starty = 0.0 #Dvorak specific start points startx = 1.5 * (width + gap) l = [] for i in range(8): p = core.Polygon() p.AddVertex(startx + float(i) * (width + gap), starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty - height) p.AddVertex(startx + float(i) * (width + gap), starty - height) l.append(p) startx = 0.0 starty -= height + gap for i in range(10): p = core.Polygon() p.AddVertex(startx + float(i) * (width + gap), starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty - height) p.AddVertex(startx + float(i) * (width + gap), starty - height) l.append(p) startx = 1.5 * (width + gap) starty -= height + gap for i in range(9): p = core.Polygon() p.AddVertex(startx + float(i) * (width + gap), starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty - height) p.AddVertex(startx + float(i) * (width + gap), starty - height) l.append(p) starty -= height + gap p = core.Polygon() p.AddVertex(startx + float(6) * (width + gap), starty) p.AddVertex(startx + float(6) * (width + gap) + width, starty) p.AddVertex(startx + float(6) * (width + gap) + width, starty - height) p.AddVertex(startx + float(6) * (width + gap), starty - height) l.append(p) k = core.Keyboard() for i in range(len(alphabetStr)): k.AddKey(alphabetStr[i], l[i]) return k
def MakeStandardKeyboard(alphabetStr='qwertyuiopasdfghjklzxcvbnm.'): width = 1.0 height = 1.5 gap = 0.2 startx = 0.0 starty = 0.0 l = [] for i in range(10): p = core.Polygon() p.AddVertex(startx + float(i) * (width + gap), starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty - height) p.AddVertex(startx + float(i) * (width + gap), starty - height) l.append(p) startx += 0.5 * width starty -= height + gap for i in range(9): p = core.Polygon() p.AddVertex(startx + float(i) * (width + gap), starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty - height) p.AddVertex(startx + float(i) * (width + gap), starty - height) l.append(p) startx += width + gap starty -= height + gap for i in range(7): p = core.Polygon() p.AddVertex(startx + float(i) * (width + gap), starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty) p.AddVertex(startx + float(i) * (width + gap) + width, starty - height) p.AddVertex(startx + float(i) * (width + gap), starty - height) l.append(p) starty -= height + gap p = core.Polygon() p.AddVertex(startx + float(6) * (width + gap), starty) p.AddVertex(startx + float(6) * (width + gap) + width, starty) p.AddVertex(startx + float(6) * (width + gap) + width, starty - height) p.AddVertex(startx + float(6) * (width + gap), starty - height) l.append(p) k = core.Keyboard() for i in range(len(alphabetStr)): k.AddKey(alphabetStr[i], l[i]) return k