Skip to content

Commit

Permalink
#4086 flake8 fixes for 'gtk'
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Dec 26, 2023
1 parent 70f663f commit 5abc26a
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 116 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ ignore = ["E741"]

[tool.flake8]
max-line-length = 120
exclude = ["xpra/gtk/examples/*.py"]
ignore = ["E203", "E231", "E225", "E226", "E252", "E221", "E741", ]
per-file-ignores = "xpra/audio/gstreamer_util.py:E241 xpra/keyboard/layouts.py:E241,E501 xpra/x11/gtk_x11/wm_check.py:E241 xpra/x11/server/seamless.py:E241 xpra/codecs/nvidia/util.py:E241 xpra/codecs/loader.py:E241 xpra/codecs/checks.py:E501"
per-file-ignores = "xpra/audio/gstreamer_util.py:E241 xpra/keyboard/layouts.py:E241,E501 xpra/x11/gtk_x11/wm_check.py:E241 xpra/x11/server/seamless.py:E241 xpra/codecs/nvidia/util.py:E241 xpra/codecs/loader.py:E241 xpra/codecs/checks.py:E501 xpra/gtk/versions.py:E241"
4 changes: 2 additions & 2 deletions tests/xpra/test_apps/test_system_tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self, name="test", tooltip="StatusIcon Example"):
if envbool("XPRA_NATIVE_NOTIFIER", True):
from xpra.platform.gui import get_native_notifier_classes
nc += get_native_notifier_classes()
from xpra.gtk.notifier import GTK_Notifier
nc.append(GTK_Notifier)
from xpra.gtk.notifier import GTKNotifier
nc.append(GTKNotifier)
self.notifier = nc[0](self.notification_closed, self.notification_action)
self.notifier.app_name_format = "%s"
#ensure we can send the image-path hint with the dbus backend:
Expand Down
4 changes: 2 additions & 2 deletions xpra/client/gtk3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def nwarn(notifier_name: str, e: Exception):
except Exception as e:
nwarn("GObject", e)
try:
from xpra.gtk.notifier import GTK_Notifier
ncs.append(GTK_Notifier)
from xpra.gtk.notifier import GTKNotifier
ncs.append(GTKNotifier)
except Exception as e:
nwarn("GTK", e)
return ncs
Expand Down
16 changes: 11 additions & 5 deletions xpra/gtk/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def __str__(self):


xerror_to_name : dict[int,str] = {}


def get_X_error(xerror) -> str:
global xerror_to_name
if not isinstance(xerror, int):
Expand Down Expand Up @@ -181,6 +183,7 @@ def swallow_synced(self, fun, *args, **kwargs):
def assert_out(self):
assert self.depth == 0


trap = _ErrorManager()


Expand All @@ -194,12 +197,13 @@ def __exit__(self, e_typ, _e_val, trcbak):
trap.Xexit()
except XError as e:
if e_typ is None:
#we are not handling an exception yet, so raise this one:
# we are not handling an exception yet, so raise this one:
raise
log(f"Ignoring {e_typ} during Xexit, {e_typ} will be raised instead", exc_info=e)
#raise the original exception:
# raise the original exception:
return False


xsync = XSyncContext()


Expand All @@ -212,9 +216,10 @@ def __exit__(self, e_typ, e_val, trcbak):
if e_typ:
log("XError swallowed: %s, %s", e_typ, e_val, exc_info=trcbak)
trap.safe_x_exit()
#don't raise exceptions:
# don't raise exceptions:
return True


xswallow = XSwallowContext()


Expand All @@ -227,9 +232,10 @@ def __exit__(self, e_typ, e_val, trcbak):
if e_typ:
log.error("Error: %s, %s", e_typ, e_val, exc_info=trcbak)
trap.safe_x_exit()
#don't raise exceptions:
# don't raise exceptions:
return True


xlog = XLogContext()


Expand All @@ -243,4 +249,4 @@ def verify_sync(*args):
for x in s:
for v in x.splitlines():
log.error(" %s", v)
#raise Exception("unmanaged context")
# raise Exception("unmanaged context")
53 changes: 27 additions & 26 deletions xpra/gtk/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ def round_up_unit(i, rounding=10):
return v*x
return v * rounding


def make_graph_imagesurface(data, labels=None, width=320, height=200, title=None,
show_y_scale=True, show_x_scale=False,
min_y_scale=None, rounding=10,
start_x_offset = 0.0,
colours=DEFAULT_COLOURS, dots=False, curves=True):
#print("make_graph_pixmap(%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (data, labels, width, height, title,
show_y_scale=True, show_x_scale=False,
min_y_scale=None, rounding=10,
start_x_offset=0.0,
colours=DEFAULT_COLOURS, dots=False, curves=True):
# print("make_graph_pixmap(%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (data, labels, width, height, title,
# show_y_scale, show_x_scale, min_y_scale, colours))
surface = cairo.ImageSurface(cairo.Format.RGB24, width, height) #pylint: disable=no-member
surface = cairo.ImageSurface(cairo.Format.RGB24, width, height) # pylint: disable=no-member
y_label_chars = 4
x_offset = y_label_chars*8
y_offset = 20
over = 2
radius = 2
#inner dimensions (used for graph only)
# inner dimensions (used for graph only)
w = width - x_offset
h = height - y_offset*2
context = cairo.Context(surface) #pylint: disable=no-member
#fill with white:
context = cairo.Context(surface) # pylint: disable=no-member
# fill with white:
context.rectangle(0, 0, width, height)
context.set_source_rgb(1, 1, 1)
context.fill()
#find ranges:
# find ranges:
max_y = 0
max_x = 0
for line_data in data:
Expand All @@ -49,44 +50,44 @@ def make_graph_imagesurface(data, labels=None, width=320, height=200, title=None
max_y = max(max_y, y)
x += 1
max_x = max(max_x, x)
#round up the scales:
# round up the scales:
scale_x = max_x
if min_y_scale is not None:
max_y = max(max_y, min_y_scale)
scale_y = round_up_unit(max_y, rounding)
#use black:
# use black:
context.set_source_rgb(0, 0, 0)
#border:
# border:
context.move_to(0, 0)
context.line_to(width, 0)
context.line_to(width, height)
context.line_to(0, height)
context.line_to(0, 0)
context.stroke()
#show vertical line:
# show vertical line:
context.move_to(x_offset, y_offset-over)
context.line_to(x_offset, height-y_offset+over)
#show horizontal line:
# show horizontal line:
context.move_to(x_offset-over, height-y_offset)
context.line_to(width, height-y_offset)
#units:
# units:
context.select_font_face('Sans')
context.set_font_size(10)
#scales
# scales
for i in range(0, 11):
if show_y_scale:
context.set_source_rgb(0, 0, 0)
context.set_line_width(1)
#vertical:
# vertical:
y = height-y_offset-h*i/10
#text
# text
if scale_y<10:
unit = str(int(scale_y*i)/10.0)
else:
unit = str(int(scale_y*i/10))
context.move_to(x_offset-3-(x_offset-6)/y_label_chars*min(y_label_chars, len(unit)), y+3)
context.show_text(unit)
#line indicator
# line indicator
context.move_to(x_offset-over, y)
context.line_to(x_offset+over, y)
context.stroke()
Expand All @@ -100,25 +101,25 @@ def make_graph_imagesurface(data, labels=None, width=320, height=200, title=None
if show_x_scale:
context.set_source_rgb(0, 0, 0)
context.set_line_width(1)
#horizontal:
# horizontal:
x = x_offset+w*i/10
#text
# text
context.move_to(x-2, height-2)
unit = str(int(scale_x*i/10))
context.show_text(unit)
#line indicator
# line indicator
context.move_to(x, height-y_offset-over)
context.line_to(x, height-y_offset+over)
context.stroke()
#title:
# title:
if title:
context.set_source_rgb(0.2, 0.2, 0.2)
context.select_font_face('Serif')
context.set_font_size(14)
context.move_to(x_offset+w/2-len(title)*14/2, 14)
context.show_text(title)
context.stroke()
#now draw the actual data, clipped to the graph region:
# now draw the actual data, clipped to the graph region:
context.save()
context.new_path()
context.set_line_width(0.0)
Expand Down Expand Up @@ -161,7 +162,7 @@ def make_graph_imagesurface(data, labels=None, width=320, height=200, title=None
context.stroke()
context.restore()
for i, line_data in enumerate(data):
#show label:
# show label:
if labels and len(labels)>i:
label = labels[i]
colour = colours[i % len(colours)]
Expand Down
Loading

0 comments on commit 5abc26a

Please sign in to comment.