Skip to content

Commit

Permalink
fix more linter warnings and add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jun 1, 2023
1 parent 7ff311b commit 6b919a7
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 91 deletions.
2 changes: 1 addition & 1 deletion xpra/client/auth/u2f_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ def get_key_handle(self) -> bytes:
break
if not key_handle_str:
log.warn("Warning: no U2F key handle found")
return None
return b""
log("process_challenge_u2f key_handle=%s", key_handle_str)
return binascii.unhexlify(key_handle_str)
2 changes: 1 addition & 1 deletion xpra/client/auth/uri_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __repr__(self):
return "uri"

def get_digest(self) -> str:
return None
return ""

def handle(self, challenge, digest, prompt): # pylint: disable=unused-argument
return self.client.password
4 changes: 2 additions & 2 deletions xpra/client/gtk3/cairo_backing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __repr__(self):

def _do_paint_rgb(self, cairo_format, has_alpha, img_data,
x : int, y : int, width : int, height : int, render_width : int, render_height : int,
rowstride : int, options):
rowstride : int, options) -> bool:
""" must be called from UI thread """
log("cairo._do_paint_rgb%s set_image_surface_data=%s, use pixbuf=%s",
(FORMATS.get(cairo_format, cairo_format), has_alpha, len(img_data),
Expand Down Expand Up @@ -89,6 +89,6 @@ def _do_paint_rgb(self, cairo_format, has_alpha, img_data,
self.nasty_rgb_via_png_paint(cairo_format, has_alpha, img_data, x, y, width, height, rowstride, rgb_format)
return True

def update_fps_buffer(self, width, height, pixels):
def update_fps_buffer(self, width, height, pixels) -> None:
self.fps_image = ImageSurface(FORMAT_ARGB32, width, height)
set_image_surface_data(self.fps_image, "RGBA", pixels, width, height, width*4)
43 changes: 23 additions & 20 deletions xpra/client/gtk3/cairo_backing_base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# This file is part of Xpra.
# Copyright (C) 2008 Nathaniel Smith <njs@pobox.com>
# Copyright (C) 2012-2022 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2012-2023 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.

from time import monotonic
from typing import Dict, Any
import cairo
from cairo import ( #pylint: disable=no-name-in-module
Context, ImageSurface, # @UnresolvedImport
Expand All @@ -29,7 +30,7 @@
FORMATS[getattr(cairo, attr)] = attr.replace("FORMAT_", "")


def cairo_paint_pointer_overlay(context, cursor_data, px : int, py : int, start_time):
def cairo_paint_pointer_overlay(context, cursor_data, px : int, py : int, start_time) -> None:
if not cursor_data:
return
elapsed = max(0, monotonic()-start_time)
Expand Down Expand Up @@ -69,14 +70,14 @@ def __init__(self, wid, window_alpha, _pixel_depth=0):
self.render_size = 0, 0
self.fps_image = None

def init(self, ww : int, wh : int, bw : int, bh : int):
def init(self, ww : int, wh : int, bw : int, bh : int) -> None:
mod = self.size!=(bw, bh) or self.render_size!=(ww, wh)
self.size = bw, bh
self.render_size = ww, wh
if mod:
self.create_surface()

def get_info(self):
def get_info(self) -> Dict[str,Any]:
info = super().get_info()
info.update({
"type" : "Cairo",
Expand Down Expand Up @@ -116,21 +117,21 @@ def create_surface(self):
backing.flush()
return cr

def close(self):
def close(self) -> None:
backing = self._backing
if backing:
backing.finish()
self._backing = None
super().close()


def cairo_paint_pixbuf(self, pixbuf, x : int, y : int, options):
def cairo_paint_pixbuf(self, pixbuf, x : int, y : int, options) -> None:
""" must be called from UI thread """
log("source pixbuf: %s", pixbuf)
w, h = pixbuf.get_width(), pixbuf.get_height()
self.cairo_paint_from_source(Gdk.cairo_set_source_pixbuf, pixbuf, x, y, w, h, w, h, options)

def cairo_paint_surface(self, img_surface, x : int, y : int, width : int, height : int, options):
def cairo_paint_surface(self, img_surface, x : int, y : int, width : int, height : int, options) -> None:
iw, ih = img_surface.get_width(), img_surface.get_height()
log("source image surface: %s",
(img_surface.get_format(), iw, ih, img_surface.get_stride(), img_surface.get_content(), ))
Expand All @@ -139,7 +140,7 @@ def set_source_surface(gc, surface, sx, sy):
self.cairo_paint_from_source(set_source_surface, img_surface, x, y, iw, ih, width, height, options)

def cairo_paint_from_source(self, set_source_fn, source,
x : int, y : int, iw : int, ih : int, width : int, height : int, options):
x : int, y : int, iw : int, ih : int, width : int, height : int, options) -> None:
""" must be called from UI thread """
backing = self._backing
log("cairo_paint_surface%s backing=%s, paint box line width=%i",
Expand Down Expand Up @@ -175,50 +176,52 @@ def cairo_paint_from_source(self, set_source_fn, source,
if flush==0:
self.record_fps_event()

def cairo_paint_box(self, gc, encoding, x, y, w, h):
def cairo_paint_box(self, gc, encoding:str, x:int, y:int, w:int, h:int) -> None:
color = get_paint_box_color(encoding)
gc.set_line_width(self.paint_box_line_width)
gc.set_source_rgba(*color)
gc.rectangle(x, y, w, h)
gc.stroke()

def _do_paint_rgb16(self, img_data, x, y, width, height, render_width, render_height, rowstride, options):
def _do_paint_rgb16(self, img_data, x:int, y:int, width:int, height:int,
render_width:int, render_height:int, rowstride:int, options) -> bool:
return self._do_paint_rgb(FORMAT_RGB16_565, False, img_data,
x, y, width, height, render_width, render_height, rowstride, options)

def _do_paint_rgb24(self, img_data, x : int, y : int, width : int, height : int,
render_width : int, render_height : int, rowstride : int, options):
def _do_paint_rgb24(self, img_data, x:int, y:int, width:int, height:int,
render_width:int, render_height:int, rowstride:int, options) -> bool:
return self._do_paint_rgb(FORMAT_RGB24, False, img_data,
x, y, width, height, render_width, render_height, rowstride, options)

def _do_paint_rgb30(self, img_data, x, y, width, height, render_width, render_height, rowstride, options):
def _do_paint_rgb30(self, img_data, x:int, y:int, width:int, height:int,
render_width:int, render_height:int, rowstride:int, options) -> bool:
return self._do_paint_rgb(FORMAT_RGB30, True, img_data,
x, y, width, height, render_width, render_height, rowstride, options)

def _do_paint_rgb32(self, img_data, x : int, y : int, width : int, height : int,
render_width : int, render_height : int, rowstride : int, options):
def _do_paint_rgb32(self, img_data, x:int, y:int, width:int, height:int,
render_width:int, render_height:int, rowstride:int, options) -> bool:
if self._alpha_enabled:
cformat = FORMAT_ARGB32
else:
cformat = FORMAT_RGB24
return self._do_paint_rgb(cformat, True, img_data,
x, y, width, height, render_width, render_height, rowstride, options)

def _do_paint_rgb(self, *args):
def _do_paint_rgb(self, *args) -> bool:
raise NotImplementedError()


def get_encoding_properties(self):
def get_encoding_properties(self) -> Dict[str,Any]:
props = super().get_encoding_properties()
if SCROLL_ENCODING:
props["encoding.scrolling"] = True
return props


def paint_scroll(self, img_data, options, callbacks):
def paint_scroll(self, img_data, options, callbacks) -> None:
self.idle_add(self.do_paint_scroll, img_data, callbacks)

def do_paint_scroll(self, scrolls, callbacks):
def do_paint_scroll(self, scrolls, callbacks) -> None:
old_backing = self._backing
if not old_backing:
fire_paint_callbacks(callbacks, False, message="no backing")
Expand Down Expand Up @@ -276,7 +279,7 @@ def nasty_rgb_via_png_paint(self, cairo_format, has_alpha : bool, img_data,
return True


def cairo_draw(self, context):
def cairo_draw(self, context) -> None:
backing = self._backing
log("cairo_draw: backing=%s, size=%s, render-size=%s, offsets=%s, pointer_overlay=%s",
backing, self.size, self.render_size, self.offsets, self.pointer_overlay)
Expand Down
8 changes: 3 additions & 5 deletions xpra/client/gtk3/gtk_client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,9 @@ def do_xpra_focus_out_event(self, event) -> bool:
detail = getattr(event, "detail", None)
if detail==NotifyInferior:
focuslog("dropped NotifyInferior focus event")
return True
return
self._focus_latest = False
self.schedule_recheck_focus()
return True

def do_xpra_focus_in_event(self, event) -> bool:
focuslog("do_xpra_focus_in_event(%s) been_mapped=%s", event, self._been_mapped)
Expand Down Expand Up @@ -1513,7 +1512,6 @@ def keyboard_ungrab(self, *args) -> None:
if seat:
seat.ungrab()
self._client.keyboard_grabbed = False
return True

def keyboard_grab(self, *args) -> None:
grablog("keyboard_grab%s", args)
Expand Down Expand Up @@ -2317,7 +2315,7 @@ def do_unmap_event(self, event) -> None:
if not self._override_redirect:
self.send("unmap-window", self.wid, False)

def do_delete_event(self, event) -> None:
def do_delete_event(self, event) -> bool:
#Gtk.Window.do_delete_event(self, event)
eventslog("do_delete_event(%s)", event)
self._client.window_close_event(self.wid)
Expand Down Expand Up @@ -2357,7 +2355,7 @@ def adjusted_pointer_data(self, x:int, y:int, rx:int=0, ry:int=0) -> Tuple[int,i
data = list(data) + list(self.cp(rx, ry))
return data

def _pointer_modifiers(self, event) -> List[str]:
def _pointer_modifiers(self, event) -> Tuple[Tuple[int,int,int,int],List[str],List[int]]:
pointer_data = self.get_pointer_data(event)
#FIXME: state is used for both mods and buttons??
modifiers = self._client.mask_to_names(event.state)
Expand Down
Loading

0 comments on commit 6b919a7

Please sign in to comment.