Skip to content

Commit

Permalink
fixing pycharm linter warnings fixes (minor) bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Nov 10, 2023
1 parent 286b14e commit 7360983
Show file tree
Hide file tree
Showing 44 changed files with 281 additions and 260 deletions.
1 change: 0 additions & 1 deletion xpra/client/gl/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ def unsafe(warning:str):
msg = "failed to parse gl version '%s': %s" % (bytestostr(gl_version_str), e)
unsafe(msg)
log(" assuming this is at least 1.1 to continue")
gl_major = gl_minor = 0
else:
props["opengl"] = gl_major, gl_minor
MIN_VERSION = (1, 1)
Expand Down
1 change: 1 addition & 0 deletions xpra/client/gl/gtk3/glarea_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def repaint(self, x:int, y:int, w:int, h:int) -> None:
if widget:
widget.queue_render()


GObject.type_register(GLClientWindow)


Expand Down
44 changes: 23 additions & 21 deletions xpra/client/gtk3/cairo_backing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,42 @@
# 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 cairo import ImageSurface, FORMAT_ARGB32 #pylint: disable=no-name-in-module
from cairo import ImageSurface, FORMAT_ARGB32 # pylint: disable=no-name-in-module
from gi.repository import GLib
from gi.repository import GdkPixbuf

from xpra.common import noop
from xpra.util.env import envbool
from xpra.client.gtk3.cairo_backing_base import CairoBackingBase, FORMATS

from xpra.log import Logger
log = Logger("paint", "cairo")

CAIRO_USE_PIXBUF = envbool("XPRA_CAIRO_USE_PIXBUF", False)
set_image_surface_data = noop
CAIRO_FORMATS = {}
try:
from xpra.client.gtk3.cairo_workaround import set_image_surface_data, CAIRO_FORMATS
from xpra.client.gtk3 import cairo_workaround
set_image_surface_data = cairo_workaround.set_image_surface_data
CAIRO_FORMATS.update(cairo_workaround.CAIRO_FORMATS)
except ImportError as e:
log.warn("Warning: failed to load the bindings cairo workaround:")
log.warn(" %s", e)
log.warn(" rendering will be slow!")
CAIRO_USE_PIXBUF = True
del e
set_image_surface_data = None
CAIRO_FORMATS = {}


CAIRO_USE_PIXBUF = envbool("XPRA_CAIRO_USE_PIXBUF", False)


"""
An area we draw onto with cairo
This must be used with bindings since bindings no longer supports gdk pixmaps

/RANT: ideally we would want to use pycairo's create_for_data method:
#surf = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_RGB24, width, height)
but this is disabled in most cases, or does not accept our rowstride, so we cannot use it.
Instead we have to use PIL to convert via a PNG or Pixbuf!
"""
class CairoBacking(CairoBackingBase):
"""
An area we draw onto with cairo
This must be used with bindings since bindings no longer supports gdk pixmaps
/RANT: ideally we would want to use pycairo's create_for_data method:
#surf = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_RGB24, width, height)
but this is disabled in most cases, or does not accept our rowstride, so we cannot use it.
Instead we have to use PIL to convert via a PNG or Pixbuf!
"""

RGB_MODES = ["BGRA", "BGRX", "RGBA", "RGBX", "BGR", "RGB", "r210", "BGR565"]

Expand All @@ -55,10 +57,10 @@ def _do_paint_rgb(self, cairo_format, has_alpha, img_data,
""" 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),
type(img_data), x, y, width, height, render_width, render_height,
rowstride, options), set_image_surface_data, CAIRO_USE_PIXBUF)
type(img_data), x, y, width, height, render_width, render_height,
rowstride, options), set_image_surface_data, CAIRO_USE_PIXBUF)
rgb_format = options.strget("rgb_format", "RGB")
if set_image_surface_data and not CAIRO_USE_PIXBUF:
if not CAIRO_USE_PIXBUF:
rgb_formats = CAIRO_FORMATS.get(cairo_format)
if rgb_format in rgb_formats:
img_surface = ImageSurface(cairo_format, width, height)
Expand All @@ -72,9 +74,9 @@ def _do_paint_rgb(self, cairo_format, has_alpha, img_data,
data = GLib.Bytes(img_data)
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
has_alpha, 8, width, height, rowstride)
if render_width!=width or render_height!=height:
if render_width != width or render_height != height:
resample = options.strget("resample", "bilinear")
if resample=="NEAREST":
if resample == "NEAREST":
interp_type = GdkPixbuf.InterpType.NEAREST
elif resample in ("BICUBIC", "LANCZOS"):
interp_type = GdkPixbuf.InterpType.HYPER
Expand Down
12 changes: 6 additions & 6 deletions xpra/client/gtk3/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,22 +538,22 @@ def accept_data(self, send_id, dtype, url, printit, openit):
return FileTransferHandler.accept_data(self, send_id, dtype, url, printit, openit)
edtype = r[0]
eurl = r[1]
if edtype!=dtype or eurl!=url:
if edtype != dtype or eurl != url:
filelog.warn("Warning: the file attributes are different")
filelog.warn(" from the ones that were used to accept the transfer")
s = bytestostr
if edtype!=dtype:
if edtype != dtype:
filelog.warn(" expected data type '%s' but got '%s'", s(edtype), s(dtype))
if eurl!=url:
if eurl != url:
filelog.warn(" expected url '%s',", s(eurl))
filelog.warn(" but got url '%s'", s(url))
return None
#return the printit and openit flag we got from the UI:
return (r[2], r[3])
# return the printit and openit flag we got from the UI:
return r[2], r[3]

def file_size_warning(self, action, location, basefilename, filesize, limit):
if self.file_size_dialog:
#close previous warning
# close previous warning
self.file_size_dialog.close()
self.file_size_dialog = None
parent = None
Expand Down
2 changes: 1 addition & 1 deletion xpra/client/gtk3/menu_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
30 : "Low",
}
MIN_QUALITY_OPTIONS = QUALITY_OPTIONS_COMMON.copy()
MIN_QUALITY_OPTIONS | {
MIN_QUALITY_OPTIONS |= {
0 : "None",
75 : "High",
}
Expand Down
2 changes: 1 addition & 1 deletion xpra/client/gtk3/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_drawing_area_geometry(self) -> tuple[int,int,int,int]:
else:
x, y = self.get_position()
w, h = self.get_size()
return (x, y, w, h)
return x, y, w, h

def apply_geometry_hints(self, hints:typedict) -> None:
""" we convert the hints as a dict into a gdk.Geometry + gdk.WindowHints """
Expand Down
4 changes: 1 addition & 3 deletions xpra/client/gtk3/window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ def use_x11_bindings() -> bool:
log.error(f"Error loading X11 bindings: {e}")
else:
set_context_check(verify_sync)
X11Window = X11WindowBindings()
X11Core = X11CoreBindings()
NotifyInferior = constants["NotifyInferior"]
HAS_X11_BINDINGS = True

Expand Down Expand Up @@ -675,7 +673,7 @@ def _is_popup(self, metadata) -> bool:
if UNDECORATED_TRANSIENT_IS_OR>0:
transient_for = metadata.intget("transient-for", -1)
decorations = metadata.intget("decorations", 0)
if transient_for>0 and decorations<=0:
if transient_for > 0 and decorations <= 0:
if UNDECORATED_TRANSIENT_IS_OR>1:
metalog("forcing POPUP type for window transient-for=%s", transient_for)
return True
Expand Down
44 changes: 22 additions & 22 deletions xpra/client/gui/tray_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class TrayBase:
Utility superclass for all tray implementations
"""

def __init__(self, _client, app_id, menu, tooltip:str="", icon_filename:str="",
size_changed_cb:Callable=noop, click_cb:Callable=noop, mouseover_cb:Callable=noop, exit_cb:Callable=noop):
#we don't keep a reference to client,
#because calling functions on the client directly should be discouraged
def __init__(self, _client, app_id, menu, tooltip: str = "", icon_filename: str = "",
size_changed_cb: Callable = noop, click_cb: Callable = noop,
mouseover_cb: Callable = noop, exit_cb: Callable = noop):
# we don't keep a reference to client,
# because calling functions on the client directly should be discouraged
self.app_id = app_id
self.menu = menu
self.tooltip = tooltip
Expand All @@ -33,8 +34,8 @@ def __init__(self, _client, app_id, menu, tooltip:str="", icon_filename:str="",
self.mouseover_cb = mouseover_cb
self.exit_cb = exit_cb
self.tray_widget = None
self.default_icon_filename = icon_filename #ie: "xpra" or "/path/to/xpra.png"
#some implementations need this for guessing the geometry (see recalculate_geometry):
self.default_icon_filename = icon_filename # ie: "xpra" or "/path/to/xpra.png"
# some implementations need this for guessing the geometry (see recalculate_geometry):
self.geometry_guess : tuple[int,int,int,int] | None = None
self.tray_event_locations : Deque[tuple[int,int]] = deque(maxlen=512)
self.default_icon_extension = "png"
Expand Down Expand Up @@ -64,7 +65,7 @@ def get_screen(self) -> int:
return -1

def get_orientation(self):
return None #assume "HORIZONTAL"
return None # assume "HORIZONTAL"

def get_geometry(self):
raise NotImplementedError
Expand All @@ -75,15 +76,14 @@ def get_size(self) -> tuple[int,int] | None:
return None
return g[2:4]

def set_tooltip(self, tooltip:str="") -> None:
def set_tooltip(self, tooltip: str = "") -> None:
self.tooltip = tooltip
raise NotImplementedError

def set_blinking(self, on:bool) -> None:
def set_blinking(self, on: bool) -> None:
raise NotImplementedError


def set_icon_from_data(self, pixels, has_alpha:bool, w:int, h:int, rowstride:int, options=None):
def set_icon_from_data(self, pixels, has_alpha: bool, w: int, h: int, rowstride: int, options= None):
raise NotImplementedError

def get_icon_filename(self, basename="") -> str:
Expand Down Expand Up @@ -116,37 +116,37 @@ def recalculate_geometry(self, x:int, y:int, width:int, height:int) -> None:
if x is None or y is None:
return
if self.geometry_guess is None:
#better than nothing!
# better than nothing!
self.geometry_guess = x, y, width, height
if self.tray_event_locations and self.tray_event_locations[-1]==(x,y):
#unchanged
if self.tray_event_locations and self.tray_event_locations[-1] == (x, y):
# unchanged
log("tray event location unchanged")
return
self.tray_event_locations.append((x, y))
#sets of locations that can fit together within (size,size) distance of each other:
# sets of locations that can fit together within (size,size) distance of each other:
xs, ys = set(), set()
xs.add(x)
ys.add(y)
#walk through all of them in reverse (and stop when one does not fit):
# walk through all of them in reverse (and stop when one does not fit):
for tx, ty in reversed(self.tray_event_locations):
minx = min(xs)
miny = min(ys)
maxx = max(xs)
maxy = max(ys)
if (tx<minx and tx<(maxx-width)) or (tx>maxx and tx>(minx+width)):
break #cannot fit...
if (ty<miny and ty<(maxy-height)) or (ty>maxy and ty>(miny+height)):
break #cannot fit...
if (tx < minx and tx < (maxx-width)) or (tx > maxx and tx > (minx+width)):
break # cannot fit...
if (ty < miny and ty < (maxy-height)) or (ty > maxy and ty > (miny+height)):
break # cannot fit...
xs.add(tx)
ys.add(ty)
#now add some padding if needed:
# now add some padding if needed:
minx = min(xs)
miny = min(ys)
maxx = max(xs)
maxy = max(ys)
padx = width-(maxx-minx)
pady = height-(maxy-miny)
assert padx>=0 and pady>=0
assert padx >= 0 and pady >= 0
minx -= padx//2
miny -= pady//2
oldgeom = self.geometry_guess
Expand Down
4 changes: 2 additions & 2 deletions xpra/client/mixins/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ def _process_sound_data(self, packet : PacketType) -> None:
ss.add_data(data, metadata, packet_metadata)
if self.av_sync and self.server_av_sync:
qinfo = typedict(ss.get_info()).dictget("queue")
queue_used = typedict(qinfo or {}).intget("cur", None)
if queue_used is None:
queue_used = typedict(qinfo or {}).intget("cur", -1)
if queue_used<0:
return
delta = (self.queue_used_sent or 0)-queue_used
#avsynclog("server audio sync: queue info=%s, last sent=%s, delta=%s",
Expand Down
2 changes: 1 addition & 1 deletion xpra/client/mixins/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def get_screen_settings(self) -> tuple:
rrate = (get_refresh_rate_for_value(self.refresh_rate, vrefresh) or 0)//1000
log("get_screen_settings() vrefresh=%s (from %s)", rrate, vrefresh)
monitors = self.get_monitors_info()
return (root_w, root_h, sss, ndesktops, desktop_names, u_root_w, u_root_h, xdpi, ydpi, rrate, monitors)
return root_w, root_h, sss, ndesktops, desktop_names, u_root_w, u_root_h, xdpi, ydpi, rrate, monitors

def update_screen_size(self) -> None:
self.screen_size_change_timer = 0
Expand Down
Loading

0 comments on commit 7360983

Please sign in to comment.