Skip to content

Add tkinter Event class #4200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion stdlib/3/tkinter/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from enum import Enum
from types import TracebackType
from typing import Any, Optional, Dict, Callable, Tuple, Type, Union
from tkinter.constants import * # noqa: F403
Expand All @@ -11,7 +12,69 @@ READABLE: Any
WRITABLE: Any
EXCEPTION: Any

class Event: ...
if sys.version_info >= (3, 6):
class EventType(str, Enum):
Activate: str = ...
ButtonPress: str = ...
ButtonRelease: str = ...
Circulate: str = ...
CirculateRequest: str = ...
ClientMessage: str = ...
Colormap: str = ...
Configure: str = ...
ConfigureRequest: str = ...
Create: str = ...
Deactivate: str = ...
Destroy: str = ...
Enter: str = ...
Expose: str = ...
FocusIn: str = ...
FocusOut: str = ...
GraphicsExpose: str = ...
Gravity: str = ...
KeyPress: str = ...
KeyRelease: str = ...
Keymap: str = ...
Leave: str = ...
Map: str = ...
MapRequest: str = ...
Mapping: str = ...
Motion: str = ...
MouseWheel: str = ...
NoExpose: str = ...
Property: str = ...
Reparent: str = ...
ResizeRequest: str = ...
Selection: str = ...
SelectionClear: str = ...
SelectionRequest: str = ...
Unmap: str = ...
VirtualEvent: str = ...
Visibility: str = ...

class Event:
serial: int
num: int
focus: bool
height: int
width: int
keycode: int
state: Union[int, str]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you get the type for state? I'm not familiar with this module, but it might be just int: https://github.com/python/cpython/blob/d31b376bc85dded9d059259737b204e544707d07/Lib/tkinter/__init__.py#L1575
(note that calling repr on an Event will display the int by an or of bitmasks)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For events of type <Visibility>, state is a str (examples are VisibilityFullyObscured and VisibilityUnobscured). However for events of type <ButtonPress>, it is an int.

time: int
x: int
y: int
x_root: int
y_root: int
char: str
send_event: bool
keysym: str
keysym_num: int
if sys.version_info >= (3, 6):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are at least some code paths where type and widget end up as str, but maybe this doesn't actually happen in practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those just the ?? case? Or are there non-?? cases where that can happen too?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, not familiar with the module, but I was checking against: https://github.com/python/cpython/blob/d31b376bc85dded9d059259737b204e544707d07/Lib/tkinter/__init__.py#L1587-L1592 where if some lookups fail, we end up with the (presumably) str argument.
But seems possible this might not really happen in practice.

type: EventType
else:
type: str
widget: Misc
delta: int

def NoDefaultRoot(): ...

Expand Down