-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPromtingChoice.py
66 lines (58 loc) · 2.23 KB
/
PromtingChoice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: UTF-8 -*-
#
# DAE (Dialogue Act Editor) is program for doing semantic and dialogue act annotation
# for dialogs stored in XML format, compatible with DATE format.
#
# Copyright (c) 2005 by Filip Jurcicek and Jiri Zahradil, Department of Cybernetics,
# University of West Bohemia, Czech Republic
#
# See LICENSE.TXT for license details
import xml.dom.minidom
import xml.parsers.expat
import os, wx, re
import wx.lib.dialogs, wx.lib.layoutf, wx.lib.scrolledpanel
class PromptingChoice(wx.Choice):
def __init__(self, parent, id, size, choices = [], style = 0):
self.choices = choices
self.phrase = ''
self.circle = 0
self.oldSelection = -1
wx.Choice.__init__(self, parent, id, size, choices = choices, style = style)
self.Bind(wx.EVT_CHAR, self.EvtChar, self)
def EvtChar(self, event):
keycode = event.GetKeyCode()
if keycode == 32:
# Do the default action for space keycodes
event.Skip()
return 0
elif keycode not in range(28,256):
# Do the default action for nonascii keycodes
event.Skip()
return 0
else:
self.phrase = chr(keycode).lower()
if self.phrase == '':
# Don't select 1st item if phrase is blank
return 0
for choice in self.choices:
choice = choice.lower()
if choice.startswith(self.phrase):
self.SetStringSelection(choice)
newSelection = self.GetSelection()
if self.oldSelection == newSelection:
self.circle += 1
self.SetSelection(self.oldSelection + self.circle)
if self.GetStringSelection()[0] != self.phrase[0]:
self.circle = 0
self.SetSelection(self.oldSelection + self.circle)
self.oldSelection = newSelection
break
return 0
def Select(self, arg):
wx.Choice.Select(self, arg)
self.oldSelection = self.GetSelection()
def Set(self, choices):
self.choices = choices
self.phrase = ''
wx.Choice.Set(self, choices)
return 0