On 12/14/2013 10:09 AM, Ricardo Aráoz wrote:
This class might be useful to someone.
In linux it works as I want it to. But in windows it seems F4 is
assigned to drop down the list. I am not able to change the key to
some other one (customers are used to F4). When the user keys F4 a
browse window comes up allowing him to choose a row and setting the
dropDown's selection to that row. In windows after the user has chosen
a row in the browse the list is left dangling. I want the control not
to show the list once the choice has been made, is there a way of
intercepting the key so that the list won't drop?
class SearchDropdown(dabo.ui.dDropdownList):
""" Searches what you type in the Dropdown, the first of the
Dropdown's
values that starts with what you typed will be selected.
searchDelay : delay before the search string is cleared. Default:
1 Sec.
onF4 : callable that returns a string, if the string can be found
in the
Dropdown it will be displayed.
"""
def __init__(self, *args, **kwarg):
searchDelay = kwarg.pop('SearchDelay', None)
onF4 = kwarg.pop('onF4', None)
super(SearchDropdown, self).__init__(*args, **kwarg)
oneSecond = datetime.timedelta(seconds=1)
self.SearchDelay = searchDelay if searchDelay else oneSecond
self.onF4 = onF4
self.Texts = []
def initProperties(self):
self.prevKey = None
self.lookingFor = ''
self.lastTime = datetime.datetime.now()
def onKeyChar(self, evt):
now = datetime.datetime.now()
char = evt.EventData['keyChar']
if evt.EventData['keyCode'] == 343: # F4
if self.onF4:
try:
self.StringValue = self.onF4()
except ValueError:
pass # If StringValue not found, do nothing
elif char:
char = char.upper()
if now - self.lastTime <= self.SearchDelay:
self.lookingFor += char
else:
self.lookingFor = char
self.lastTime = now
for pos, choice in enumerate(self.Choices):
if choice.upper().startswith(self.lookingFor):
self.PositionValue = pos
_______________________________________________
I'm sure if this will help you but Dabo has dKeys and for me it has
provided a complete cross platform solution (and I don't hard code any
values).
I do something like this:
from dabo.ui import dKeys as dKeys
if evt.keyCode in [dKeys.key_F7, dKeys.key_F4, dKeys.key_Return]:
thestr= self.Form.lookup(evt)
return
Johnf
_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/52aca08d.9060...@jfcomputer.com