Skip to content
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

Add types for Gdk.Display and Gdk.Monitor #60

Merged
merged 1 commit into from
Jul 15, 2022
Merged

Add types for Gdk.Display and Gdk.Monitor #60

merged 1 commit into from
Jul 15, 2022

Conversation

mswiger
Copy link
Contributor

@mswiger mswiger commented Jul 14, 2022

I added the typing information using these docs:

https://lazka.github.io/pgi-docs/#Gdk-3.0/classes/Display.html#Gdk.Display
https://lazka.github.io/pgi-docs/#Gdk-3.0/classes/Monitor.html#Gdk.Monitor

I wasn't sure exactly how to type the return values for Gdk.Display.get_maximal_cursor_size or Gdk.Display.get_pointer, so I did not update the typings. Maybe they should be NamedTuples?

@cal0pteryx
Copy link
Contributor

Both methods return a Tuple. For example: def get_maximal_cursor_size(self) -> tuple[int, int]

@mswiger
Copy link
Contributor Author

mswiger commented Jul 14, 2022

The fields of the returned tuple have names though:

(Pdb) p display.get_maximal_cursor_size()
(width=256, height=256)

Fields are width and height.

(Pdb) p display.get_pointer()
(screen=<__gi__.GdkWaylandScreen object at 0x7fc1645abf80 (GdkWaylandScreen at 0x563452d42010)>, x=0, y=0, mask=<flags 0 of type Gdk.ModifierType>)

Fields are screen, x, y, and mask.

Using a regular tuple would work, but it might be nice to keep these field names. It's just not clear to me what the best way to do this would be. We could explicitly create new types to support these return types, but I'm not sure if that's the right approach. For example:

class Size(NamedTuple):
    width: int
    height: int

def get_maximal_cursor_size(self) -> Size: ...

@lovetox
Copy link
Collaborator

lovetox commented Jul 14, 2022

Its a ResultTuple object, but i think it only exists in C code.

A namedtuple would be a bit too misleading as it has many methods that this object does not have

something like this would be more fitting

class Size(Tuple[int, int]):
    width: int
    height: int

@mswiger
Copy link
Contributor Author

mswiger commented Jul 14, 2022

Makes sense! I've updated this branch with Size and Pointer return types for the Gdk.Display.get_maximal_cursor_size and Gdk.Display.get_pointer. Does this look like what you were thinking?

As a side note, is there a recommended way of testing these changes? The instructions in CONTRIBUTING.md seem incomplete/did not work for me.

@lovetox
Copy link
Collaborator

lovetox commented Jul 15, 2022

what did not work?

There is no way to test your changes, we just do a test that you dont introduce syntax errors, thats why we run mypy on the examples folder.

@lovetox lovetox merged commit 4676e3e into pygobject:master Jul 15, 2022
@mswiger
Copy link
Contributor Author

mswiger commented Jul 15, 2022

I see, thanks for the explanation!

@mswiger mswiger deleted the add_gdk_display_and_monitor_types branch July 15, 2022 18:59
@principis principis mentioned this pull request Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants