Skip to content

Commit

Permalink
minor type hint fix and other warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Nov 14, 2023
1 parent 4311115 commit 857a5e4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 37 deletions.
8 changes: 4 additions & 4 deletions xpra/client/gtk3/keyboard_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class GTKKeyboardHelper(KeyboardHelper):

def __init__(self, *args):
KeyboardHelper.__init__(self, *args)
#used for delaying the sending of keymap changes
#(as we may be getting dozens of such events at a time)
# used for delaying the sending of keymap changes
# (as we may be getting dozens of such events at a time)
self._keymap_changing = False
self._keymap_change_handler_id = None
self._keymap = None
Expand Down Expand Up @@ -55,11 +55,11 @@ def keymap_changed(self, *args):
display = Gdk.Display.get_default()
self._keymap = Gdk.Keymap.get_for_display(display)
if self._keymap_changing:
#timer due already
# timer is already due
return
self._keymap_changing = True
def do_keys_changed():
#re-register the change handler:
# re-register the change handler:
self._keymap_change_handler_id = self._keymap.connect("keys-changed", self.keymap_changed)
self._keymap_changing = False
if self.locked:
Expand Down
2 changes: 1 addition & 1 deletion xpra/client/mixins/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def make_clipboard_helper(self):
for helperclass in clipboard_options:
try:
return self.setup_clipboard_helper(helperclass)
except ImportError as e:
except (ImportError, AttributeError) as e:
log.error("Error: cannot instantiate %s:", helperclass)
log.estr(e)
del e
Expand Down
3 changes: 2 additions & 1 deletion xpra/gtk/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ def main():


if __name__ == "__main__":
main()
main()

26 changes: 13 additions & 13 deletions xpra/gtk/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_screen_info(display, screen) -> dict[str,Any]:
for i in range(screen.get_n_monitors()):
m_info[i] = get_screen_monitor_info(screen, i)
fo = screen.get_font_options()
#win32 and osx return nothing here...
# win32 and osx return nothing here...
if fo:
fontoptions = info.setdefault("fontoptions", {})
fontoptions.update(get_font_info(fo))
Expand All @@ -59,7 +59,7 @@ def visual(name, v):
if SHOW_ALL_VISUALS:
for i, v in enumerate(screen.list_visuals()):
visual(i, v)
#Gtk.settings
# Gtk.settings
def get_setting(key, gtype):
v = GObject.Value()
v.init(gtype)
Expand All @@ -68,12 +68,12 @@ def get_setting(key, gtype):
return None
sinfo = info.setdefault("settings", {})
for x, gtype in {
#NET:
# NET:
"enable-event-sounds" : GObject.TYPE_INT,
"icon-theme-name" : GObject.TYPE_STRING,
"sound-theme-name" : GObject.TYPE_STRING,
"theme-name" : GObject.TYPE_STRING,
#Xft:
# Xft:
"xft-antialias" : GObject.TYPE_INT,
"xft-dpi" : GObject.TYPE_INT,
"xft-hinting" : GObject.TYPE_INT,
Expand Down Expand Up @@ -156,14 +156,14 @@ def get_font_info(font_options) -> dict[str,Any]:
}


def get_visual_info(v) -> dict[str,Any]:
def get_visual_info(v) -> dict[str, Any]:
if not v:
return {}
vinfo : dict[str,Any] = {}
vinfo : dict[str, Any] = {}
for x, vdict in VINFO_CONV.items():
val = None
try:
#ugly workaround for "visual_type" -> "type" for GTK2...
# ugly workaround for "visual_type" -> "type" for GTK2...
val = getattr(v, x.replace("visual_", ""))
except AttributeError:
try:
Expand All @@ -177,8 +177,8 @@ def get_visual_info(v) -> dict[str,Any]:
return vinfo


def get_screen_monitor_info(screen, i) -> dict[str,Any]:
info : dict[str,Any] = {}
def get_screen_monitor_info(screen, i) -> dict[str, Any]:
info : dict[str, Any] = {}
geom = screen.get_monitor_geometry(i)
for x in ("x", "y", "width", "height"):
info[x] = getattr(geom, x)
Expand All @@ -195,7 +195,7 @@ def get_screen_monitor_info(screen, i) -> dict[str,Any]:
return info


def get_monitors_info(xscale:float=1, yscale:float=1) -> dict[int,Any]:
def get_monitors_info(xscale: float=1, yscale: float=1) -> dict[int, Any]:
display = Gdk.Display.get_default()
info : dict[int,Any] = {}
n = display.get_n_monitors()
Expand Down Expand Up @@ -237,9 +237,9 @@ def get_monitors_info(xscale:float=1, yscale:float=1) -> dict[int,Any]:

def get_display_info(xscale=1, yscale=1) -> dict[str,Any]:
display = Gdk.Display.get_default()
def xy(v):
def xy(v) -> tuple[int, int]:
return round(xscale*v[0]), round(yscale*v[1])
def avg(v):
def avg(v) -> int:
return round((xscale*v+yscale*v)/2)
root_size = get_root_size()
info : dict[str, Any] = {
Expand Down Expand Up @@ -297,7 +297,7 @@ def swork(*workarea):
return xs(workarea[0]), ys(workarea[1]), xs(workarea[2]), ys(workarea[3])
display = Gdk.Display.get_default()
if not display:
return ()
return []
MIN_DPI = envint("XPRA_MIN_DPI", 10)
MAX_DPI = envint("XPRA_MIN_DPI", 500)
def dpi(size_pixels, size_mm):
Expand Down
13 changes: 7 additions & 6 deletions xpra/gtk/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,26 @@ def get_default_root_window() -> Gdk.Window | None:
return None
return screen.get_root_window()


def get_root_size(default:None|tuple[int,int]=(1920, 1024)) -> tuple[int,int] | None:
if OSX:
#the easy way:
# the easy way:
root = get_default_root_window()
if not root:
return default
w, h = root.get_geometry()[2:4]
else:
#GTK3 on win32 triggers this warning:
#"GetClientRect failed: Invalid window handle."
#if we try to use the root window,
#and on Linux with Wayland, we get bogus values...
# GTK3 on win32 triggers this warning:
# "GetClientRect failed: Invalid window handle."
# if we try to use the root window,
# and on Linux with Wayland, we get bogus values...
screen = Gdk.Screen.get_default()
if screen is None:
return default
with IgnoreWarningsContext():
w = screen.get_width()
h = screen.get_height()
if w<=0 or h<=0 or w>32768 or h>32768:
if w <= 0 or h <= 0 or w > 32768 or h > 32768:
if first_time("Gtk root window dimensions"):
log = Logger("gtk", "screen")
log.warn(f"Warning: Gdk returned invalid root window dimensions: {w}x{h}")
Expand Down
24 changes: 12 additions & 12 deletions xpra/gtk/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def scaled_image(pixbuf, icon_size:int=0) -> Gtk.Image | None:
return Gtk.Image.new_from_pixbuf(pixbuf)


def imagebutton(title, icon=None, tooltip="", clicked_callback:Callable|None=None, icon_size=32,
default=False, min_size=None, label_color=None, label_font:str="") -> Gtk.Button:
def imagebutton(title, icon=None, tooltip="", clicked_callback:Callable|None = None, icon_size=32,
default=False, min_size=None, label_color=None, label_font="") -> Gtk.Button:
button = Gtk.Button(label=title)
settings = button.get_settings()
settings.set_property('gtk-button-images', True)
Expand Down Expand Up @@ -81,7 +81,7 @@ def menuitem(title, image=None, tooltip=None, cb=None) -> Gtk.ImageMenuItem:
return menu_item


def label(text:str="", tooltip:str="", font:str="") -> Gtk.Label:
def label(text="", tooltip="", font="") -> Gtk.Label:
l = Gtk.Label(label=text)
if font:
setfont(l, font)
Expand Down Expand Up @@ -134,15 +134,15 @@ def pack_start(self, child, expand=True, fill=True, padding=0):
Gtk.Box.pack_start = pack_start


def slabel(text:str="", tooltip:str="", font:str="") -> Gtk.Label:
l = label(text, tooltip, font)
l.set_margin_start(5)
l.set_margin_end(5)
l.set_margin_top(2)
l.set_margin_bottom(2)
l.set_selectable(True)
l.set_line_wrap(True)
return l
def slabel(text="", tooltip="", font="") -> Gtk.Label:
lw = label(text, tooltip, font)
lw.set_margin_start(5)
lw.set_margin_end(5)
lw.set_margin_top(2)
lw.set_margin_bottom(2)
lw.set_selectable(True)
lw.set_line_wrap(True)
return lw


def title_box(label_str:str, tooltip="") -> Gtk.EventBox:
Expand Down

0 comments on commit 857a5e4

Please sign in to comment.