Skip to content

Commit

Permalink
more type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Aug 12, 2024
1 parent 7c56e65 commit 1893aad
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion xpra/client/gtk3/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ClientWindow(GTKClientWindowBase):
GTK3 version of the ClientWindow class
"""

def init_window(self, metadata: typedict):
def init_window(self, metadata: typedict) -> None:
super().init_window(metadata)
self.header_bar_image = None
if self.can_use_header_bar(metadata):
Expand Down
18 changes: 9 additions & 9 deletions xpra/client/gui/keyboard_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def reset_state(self) -> None:
def cleanup(self) -> None:
self.reset_state()

def nosend(*_args):
def nosend(*_args) -> None:
""" make sure we don't send keyboard updates during cleanup """

self.send = nosend
Expand Down Expand Up @@ -231,7 +231,7 @@ def get_layout_spec(self) -> tuple[str, list[str], str, list[str], str]:
layout, layouts, variant, variants, options = self.keyboard.get_layout_spec()
log("%s.get_layout_spec()=%s", self.keyboard, (layout, layouts, variant, variants, options))

def inl(v, l):
def inl(v, l) -> list:
try:
if v in l or v is None:
return l
Expand Down Expand Up @@ -295,29 +295,29 @@ def query_xkbmap(self):
log(f"mod pointermissing: {self.mod_pointermissing}")
log(f"hash={self.hash}")

def update(self):
def update(self) -> None:
if not self.locked:
self.query_xkbmap()
self.parse_shortcuts()

def layout_str(self):
def layout_str(self) -> str:
return " / ".join(str(x) for x in (
self.layout_option or self.layout, self.variant_option or self.variant) if bool(x))

def send_layout(self):
def send_layout(self) -> None:
log("send_layout() layout_option=%s, layout=%s, variant_option=%s, variant=%s, options=%s",
self.layout_option, self.layout, self.variant_option, self.variant, self.options)
self.send("layout-changed",
self.layout_option or self.layout or "",
self.variant_option or self.variant or "",
self.options or "")

def send_keymap(self):
def send_keymap(self) -> None:
log("send_keymap()")
props = {"keymap": self.get_keymap_properties()}
self.send("keymap-changed", props)

def update_hash(self):
def update_hash(self) -> None:
import hashlib
h = hashlib.sha256()

Expand All @@ -335,7 +335,7 @@ def hashadd(v) -> None:
def get_full_keymap(self) -> Sequence[tuple[int, str, int, int, int]]:
return ()

def get_keymap_properties(self, skip=()):
def get_keymap_properties(self, skip=()) -> dict[str, Any]:
props = {}
for x in (
"layout", "layouts", "variant", "variants",
Expand All @@ -350,7 +350,7 @@ def get_keymap_properties(self, skip=()):
props[x] = v
return props

def log_keyboard_info(self):
def log_keyboard_info(self) -> None:
# show the user a summary of what we have detected:
kb_info = {}
if self.query_struct:
Expand Down
10 changes: 5 additions & 5 deletions xpra/client/gui/paint_colors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python3
# This file is part of Xpra.
# Copyright (C) 2017,2018 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2017 - 2024 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.


# noinspection PyPep8
DEFAULT_BOX_COLORS = {
DEFAULT_BOX_COLORS: dict[str, str] = {
"png" : "yellow",
"h264" : "blue",
"vp8" : "green",
Expand All @@ -28,7 +28,7 @@
ALPHA = 0.6
# converted from gtk lookups using `Gdk.Color.parse`:
# noinspection PyPep8
BOX_COLORS = {
BOX_COLORS: dict[str, tuple[float, float, float, float]] = {
"h264" : (0.0, 0.0, 0.9999847412109375, ALPHA),
"h265" : (0.941162109375, 0.901947021484375, 0.54901123046875, ALPHA),
"jpeg" : (0.501953125, 0.0, 0.501953125, ALPHA),
Expand All @@ -50,9 +50,9 @@
BLACK = 0, 0, 0, 0


def get_default_paint_box_color():
def get_default_paint_box_color() -> tuple[float, float, float, float]:
return BLACK


def get_paint_box_color(encoding):
def get_paint_box_color(encoding) -> tuple[float, float, float, float]:
return BOX_COLORS.get(encoding, BLACK)
2 changes: 1 addition & 1 deletion xpra/client/gui/spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# later version. See the file COPYING for details.

class cv:
trs = (
trs: tuple[tuple[float, float, float, float, float, float, float, float]] = (
(0.00, 0.15, 0.30, 0.50, 0.65, 0.80, 0.90, 1.00),
(1.00, 0.00, 0.15, 0.30, 0.50, 0.65, 0.80, 0.90),
(0.90, 1.00, 0.00, 0.15, 0.30, 0.50, 0.65, 0.80),
Expand Down
48 changes: 24 additions & 24 deletions xpra/client/gui/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def init(self, opts) -> None:
def client_toolkit(self) -> str:
raise NotImplementedError()

def init_ui(self, opts):
def init_ui(self, opts) -> None:
""" initialize user interface """

def noauto(val):
Expand Down Expand Up @@ -379,7 +379,7 @@ def server_disconnect(self, reason: str, *info) -> None:

######################################################################
# hello:
def make_hello(self):
def make_hello(self) -> dict[str, Any]:
caps = XpraClientBase.make_hello(self)
# don't try to find the server uuid if this platform cannot run servers..
# (doing so causes lockups on win32 and startup errors on osx)
Expand Down Expand Up @@ -432,7 +432,7 @@ def setup_connection(self, conn):
c.setup_connection(self, conn)
return protocol

def server_connection_established(self, caps: typedict):
def server_connection_established(self, caps: typedict) -> bool:
if not XpraClientBase.server_connection_established(self, caps):
return False
# process the rest from the UI thread:
Expand Down Expand Up @@ -517,7 +517,7 @@ def nosend(*_args):
log.info(msg)
return True

def process_ui_capabilities(self, caps: typedict):
def process_ui_capabilities(self, caps: typedict) -> None:
for c in CLIENT_BASES:
if c != XpraClientBase:
c.process_ui_capabilities(self, caps)
Expand All @@ -529,7 +529,7 @@ def process_ui_capabilities(self, caps: typedict):
self.key_repeat_delay, self.key_repeat_interval = caps.intpair("key_repeat", (-1, -1))
self.handshake_complete()

def _process_startup_complete(self, packet: PacketType):
def _process_startup_complete(self, packet: PacketType) -> None:
log("all the existing windows and system trays have been received")
super()._process_startup_complete(packet)
gui_ready()
Expand Down Expand Up @@ -562,14 +562,14 @@ def _process_new_window(self, packet: PacketType):
log("fullscreen_on_monitor: %i", monitor)
return window

def handshake_complete(self):
def handshake_complete(self) -> None:
oh = self._on_handshake
self._on_handshake = None
for cb, args in oh:
with log.trap_error("Error processing handshake callback %s", cb):
cb(*args)

def after_handshake(self, cb: Callable, *args):
def after_handshake(self, cb: Callable, *args) -> None:
log("after_handshake(%s, %s) on_handshake=%s", cb, args, Ellipsizer(self._on_handshake))
if self._on_handshake is None:
# handshake has already occurred, just call it:
Expand All @@ -580,13 +580,13 @@ def after_handshake(self, cb: Callable, *args):
######################################################################
# server messages:
# noinspection PyMethodMayBeStatic
def _process_server_event(self, packet: PacketType):
def _process_server_event(self, packet: PacketType) -> None:
log(": ".join(str(x) for x in packet[1:]))

def on_server_setting_changed(self, setting: str, cb: Callable):
def on_server_setting_changed(self, setting: str, cb: Callable) -> None:
self._on_server_setting_changed.setdefault(setting, []).append(cb)

def _process_setting_change(self, packet: PacketType):
def _process_setting_change(self, packet: PacketType) -> None:
setting = str(packet[1])
value = packet[2]
# convert "hello" / "setting" variable names to client variables:
Expand All @@ -613,7 +613,7 @@ def _process_setting_change(self, packet: PacketType):
log.info("server setting changed: %s=%s", setting, repr_ellipsized(value))
self.server_setting_changed(setting, value)

def server_setting_changed(self, setting, value):
def server_setting_changed(self, setting: str, value) -> None:
log("setting_changed(%s, %s)", setting, Ellipsizer(value, limit=200))
cbs = self._on_server_setting_changed.get(setting)
if cbs:
Expand All @@ -631,7 +631,7 @@ def get_control_commands(self) -> list[str]:
log("get_control_commands()=%s", commands)
return commands

def _process_control(self, packet: PacketType):
def _process_control(self, packet: PacketType) -> None:
command = str(packet[1])
args = packet[2:]
log("_process_control(%s)", packet)
Expand Down Expand Up @@ -711,42 +711,42 @@ def _process_control(self, packet: PacketType):
else:
log.warn("received invalid control command from server: %s", command)

def may_notify_audio(self, summary, body):
def may_notify_audio(self, summary: str, body: str) -> None:
self.may_notify(NotificationID.AUDIO, summary, body, icon_name="audio")

######################################################################
# features:
def send_sharing_enabled(self):
def send_sharing_enabled(self) -> None:
assert self.server_sharing and self.server_sharing_toggle
self.send("sharing-toggle", self.client_supports_sharing)

def send_lock_enabled(self):
def send_lock_enabled(self) -> None:
assert self.server_lock_toggle
self.send("lock-toggle", self.client_lock)

def send_notify_enabled(self):
def send_notify_enabled(self) -> None:
assert self.client_supports_notifications, "cannot toggle notifications: the feature is disabled by the client"
self.send("set-notify", self.notifications_enabled)

def send_bell_enabled(self):
def send_bell_enabled(self) -> None:
assert self.client_supports_bell, "cannot toggle bell: the feature is disabled by the client"
assert self.server_bell, "cannot toggle bell: the feature is disabled by the server"
self.send("set-bell", self.bell_enabled)

def send_cursors_enabled(self):
def send_cursors_enabled(self) -> None:
assert self.client_supports_cursors, "cannot toggle cursors: the feature is disabled by the client"
assert self.server_cursors, "cannot toggle cursors: the feature is disabled by the server"
self.send("set-cursors", self.cursors_enabled)

def send_force_ungrab(self, wid):
def send_force_ungrab(self, wid: int) -> None:
self.send("force-ungrab", wid)

def send_keyboard_sync_enabled_status(self, *_args):
def send_keyboard_sync_enabled_status(self, *_args) -> None:
self.send("set-keyboard-sync-enabled", self.keyboard_sync)

######################################################################
# keyboard:
def get_keyboard_caps(self):
def get_keyboard_caps(self) -> dict[str, Any]:
caps = {}
kh = self.keyboard_helper
if self.readonly or not kh:
Expand All @@ -770,11 +770,11 @@ def get_keyboard_caps(self):
log("keyboard capabilities: %s", caps)
return caps

def next_keyboard_layout(self, update_platform_layout):
def next_keyboard_layout(self, update_platform_layout) -> None:
if self.keyboard_helper:
self.keyboard_helper.next_layout(update_platform_layout)

def window_keyboard_layout_changed(self, window=None):
def window_keyboard_layout_changed(self, window=None) -> None:
# win32 can change the keyboard mapping per window...
keylog("window_keyboard_layout_changed(%s)", window)
if self.keyboard_helper:
Expand Down Expand Up @@ -818,7 +818,7 @@ def server_connection_state_change(self) -> None:
if not self._server_ok and hasattr(self, "redraw_spinners"):
log.info("server is not responding, drawing spinners over the windows")

def timer_redraw():
def timer_redraw() -> bool:
if self._protocol is None:
# no longer connected!
return False
Expand Down
2 changes: 1 addition & 1 deletion xpra/client/gui/window_border.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, shown: bool = True,
self.alpha: float = alpha
self.size: int = size

def toggle(self):
def toggle(self) -> None:
self.shown = not self.shown

def clone(self):
Expand Down

0 comments on commit 1893aad

Please sign in to comment.