Skip to content
This repository has been archived by the owner on Nov 23, 2019. It is now read-only.

api to read key by enum #59

Open
ensonic opened this issue Jul 17, 2015 · 2 comments
Open

api to read key by enum #59

ensonic opened this issue Jul 17, 2015 · 2 comments

Comments

@ensonic
Copy link

ensonic commented Jul 17, 2015

Not sure if it is already possible. At least there is not example in the test and I can't figure it out.

RIght now one can do:

  k = Key()
  if k.enter:

but there is no way to pass e.g. Key.CODE.ENTER to a function and then e.g. do

def check_key(key):
  k = Key()
  return k.status(key)

I can do

getattr(k, 'enter')

and there is

print Key.CODE.enum_dict
{'RIGHT': 106, 'UP': 103, 'DOWN': 108, 'BACKSPACE': 14, 'ENTER': 28, 'LEFT': 105}

but

print Key.CODE.ENTER.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'name'

I first thought that should work: https://docs.python.org/3/library/enum.html#creating-an-enum, but you are not using enum34, but your own.

Regarding more key api, see also
ev3dev/ev3dev-lang#90

@ensonic
Copy link
Author

ensonic commented Jul 21, 2015

I am using this for now:

getattr(k, Key.CODE.enum_dict.keys()[0].lower())

@topikachu
Copy link
Owner

Would you please create a pull request?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants