| ... |
... |
@@ -275,9 +275,11 @@ def get_total_screen_geometry() -> tuple[int, int]: |
|
275
|
275
|
total_width = 0
|
|
276
|
276
|
total_height = 0
|
|
277
|
277
|
display = Gdk.Display.get_default()
|
|
|
278
|
+ assert display is not None
|
|
278
|
279
|
monitors = display.get_n_monitors()
|
|
279
|
280
|
for num in range(0, monitors):
|
|
280
|
281
|
monitor = display.get_monitor(num)
|
|
|
282
|
+ assert monitor is not None
|
|
281
|
283
|
geometry = monitor.get_geometry()
|
|
282
|
284
|
total_width += geometry.width
|
|
283
|
285
|
total_height = max(total_height, geometry.height)
|
| ... |
... |
@@ -358,6 +360,7 @@ def get_completion_liststore(entry: Gtk.Entry) -> Gtk.ListStore: |
|
358
|
360
|
|
|
359
|
361
|
def get_cursor(name: str) -> Gdk.Cursor:
|
|
360
|
362
|
display = Gdk.Display.get_default()
|
|
|
363
|
+ assert display is not None
|
|
361
|
364
|
cursor = Gdk.Cursor.new_from_name(display, name)
|
|
362
|
365
|
if cursor is not None:
|
|
363
|
366
|
return cursor
|
| ... |
... |
@@ -412,13 +415,6 @@ def get_image_button(icon_name: str, tooltip: str, |
|
412
|
415
|
return button
|
|
413
|
416
|
|
|
414
|
417
|
|
|
415
|
|
-def get_image_from_icon_name(icon_name: str, scale: int) -> Any:
|
|
416
|
|
- icon_theme = Gtk.IconTheme.get_default()
|
|
417
|
|
- icon = get_icon_name(icon_name)
|
|
418
|
|
- surface = icon_theme.load_surface(icon, 16, scale, None, 0)
|
|
419
|
|
- return Gtk.Image.new_from_surface(surface)
|
|
420
|
|
-
|
|
421
|
|
-
|
|
422
|
418
|
def python_month(month: int) -> int:
|
|
423
|
419
|
return month + 1
|
|
424
|
420
|
|
| ... |
... |
@@ -460,6 +456,7 @@ def make_rgba(color_string: str) -> Gdk.RGBA: |
|
460
|
456
|
|
|
461
|
457
|
def get_monitor_scale_factor() -> int:
|
|
462
|
458
|
display = Gdk.Display.get_default()
|
|
|
459
|
+ assert display is not None
|
|
463
|
460
|
monitor = display.get_primary_monitor()
|
|
464
|
461
|
if monitor is None:
|
|
465
|
462
|
log.warning('Could not determine scale factor')
|
| ... |
... |
@@ -477,6 +474,7 @@ def get_primary_accel_mod() -> Optional[Gdk.ModifierType]: |
|
477
|
474
|
|
|
478
|
475
|
def get_hardware_key_codes(keyval: int) -> list[int]:
|
|
479
|
476
|
display = Gdk.Display.get_default()
|
|
|
477
|
+ assert display is not None
|
|
480
|
478
|
keymap = Gdk.Keymap.get_for_display(display)
|
|
481
|
479
|
|
|
482
|
480
|
valid, key_map_keys = keymap.get_entries_for_keyval(keyval)
|
| ... |
... |
@@ -485,9 +483,9 @@ def get_hardware_key_codes(keyval: int) -> list[int]: |
|
485
|
483
|
return [key.keycode for key in key_map_keys]
|
|
486
|
484
|
|
|
487
|
485
|
|
|
488
|
|
-def ensure_not_destroyed(func):
|
|
|
486
|
+def ensure_not_destroyed(func: Any) -> Any:
|
|
489
|
487
|
@wraps(func)
|
|
490
|
|
- def func_wrapper(self, *args, **kwargs):
|
|
|
488
|
+ def func_wrapper(self: Any, *args: Any, **kwargs: Any):
|
|
491
|
489
|
if self._destroyed: # pylint: disable=protected-access
|
|
492
|
490
|
return None
|
|
493
|
491
|
return func(self, *args, **kwargs)
|
| ... |
... |
@@ -513,9 +511,9 @@ def get_account_tune_icon_name(account: str) -> Optional[str]: |
|
513
|
511
|
|
|
514
|
512
|
|
|
515
|
513
|
def format_location(location: LocationData) -> str:
|
|
516
|
|
- location = location._asdict()
|
|
|
514
|
+ location_dict = location._asdict()
|
|
517
|
515
|
location_string = ''
|
|
518
|
|
- for attr, value in location.items():
|
|
|
516
|
+ for attr, value in location_dict.items():
|
|
519
|
517
|
if value is None:
|
|
520
|
518
|
continue
|
|
521
|
519
|
text = GLib.markup_escape_text(value)
|
| ... |
... |
@@ -599,7 +597,7 @@ def text_to_color(text: str) -> tuple[float, float, float]: |
|
599
|
597
|
background = (0, 0, 0) # RGB (0, 0, 0) black
|
|
600
|
598
|
else:
|
|
601
|
599
|
background = (1, 1, 1) # RGB (255, 255, 255) white
|
|
602
|
|
- return nbxmpp.util.text_to_color(text, background)
|
|
|
600
|
+ return nbxmpp.util.text_to_color(text, background) # type: ignore
|
|
603
|
601
|
|
|
604
|
602
|
|
|
605
|
603
|
def get_color_for_account(account: str) -> str:
|
| ... |
... |
@@ -646,7 +644,7 @@ def get_pixbuf_from_data(file_data: bytes) -> Optional[GdkPixbuf.Pixbuf]: |
|
646
|
644
|
'convert avatar image using pillow')
|
|
647
|
645
|
try:
|
|
648
|
646
|
avatar = Image.open(BytesIO(file_data)).convert("RGBA")
|
|
649
|
|
- array = GLib.Bytes.new(avatar.tobytes())
|
|
|
647
|
+ array = GLib.Bytes.new(avatar.tobytes()) # type: ignore
|
|
650
|
648
|
width, height = avatar.size
|
|
651
|
649
|
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(
|
|
652
|
650
|
array, GdkPixbuf.Colorspace.RGB,
|
| ... |
... |
@@ -683,6 +681,7 @@ def scale_pixbuf_from_data(data: bytes, |
|
683
|
681
|
size: int
|
|
684
|
682
|
) -> Optional[GdkPixbuf.Pixbuf]:
|
|
685
|
683
|
pixbuf = get_pixbuf_from_data(data)
|
|
|
684
|
+ assert pixbuf is not None
|
|
686
|
685
|
return scale_pixbuf(pixbuf, size)
|
|
687
|
686
|
|
|
688
|
687
|
|
| ... |
... |
@@ -705,7 +704,7 @@ def load_pixbuf(path: Union[str, Path], |
|
705
|
704
|
log.debug('Error', exc_info=True)
|
|
706
|
705
|
return None
|
|
707
|
706
|
|
|
708
|
|
- array = GLib.Bytes.new(avatar.tobytes())
|
|
|
707
|
+ array = GLib.Bytes.new(avatar.tobytes()) # type: ignore
|
|
709
|
708
|
width, height = avatar.size
|
|
710
|
709
|
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(
|
|
711
|
710
|
array, GdkPixbuf.Colorspace.RGB, True,
|
| ... |
... |
@@ -746,7 +745,7 @@ def make_href_markup(string: str) -> str: |
|
746
|
745
|
assert isinstance(url_color, str)
|
|
747
|
746
|
color = convert_rgb_to_hex(url_color)
|
|
748
|
747
|
|
|
749
|
|
- def _to_href(match: Match) -> str:
|
|
|
748
|
+ def _to_href(match: Match[str]) -> str:
|
|
750
|
749
|
url = match.group()
|
|
751
|
750
|
if '://' not in url:
|
|
752
|
751
|
url = 'https://' + url
|
| ... |
... |
@@ -760,7 +759,7 @@ def get_app_windows(account: str) -> list[Gtk.Window]: |
|
760
|
759
|
windows: list[Gtk.Window] = []
|
|
761
|
760
|
for win in app.app.get_windows():
|
|
762
|
761
|
if hasattr(win, 'account'):
|
|
763
|
|
- if win.account == account:
|
|
|
762
|
+ if win.account == account: # type: ignore
|
|
764
|
763
|
windows.append(win)
|
|
765
|
764
|
return windows
|
|
766
|
765
|
|
| ... |
... |
@@ -774,11 +773,11 @@ def get_app_window(name: str, |
|
774
|
773
|
continue
|
|
775
|
774
|
|
|
776
|
775
|
if account is not None:
|
|
777
|
|
- if account != win.account:
|
|
|
776
|
+ if account != win.account: # type: ignore
|
|
778
|
777
|
continue
|
|
779
|
778
|
|
|
780
|
779
|
if jid is not None:
|
|
781
|
|
- if jid != win.jid:
|
|
|
780
|
+ if jid != win.jid: # type: ignore
|
|
782
|
781
|
continue
|
|
783
|
782
|
return win
|
|
784
|
783
|
return None
|
| ... |
... |
@@ -800,7 +799,7 @@ def open_window(name: str, **kwargs: Any) -> Any: |
|
800
|
799
|
class EventHelper(CommonEventHelper):
|
|
801
|
800
|
def __init__(self):
|
|
802
|
801
|
CommonEventHelper.__init__(self)
|
|
803
|
|
- self.connect('destroy', self.__on_destroy) # pylint: disable=no-member
|
|
|
802
|
+ self.connect('destroy', self.__on_destroy) # type: ignore
|
|
804
|
803
|
|
|
805
|
804
|
def __on_destroy(self, *args: Any) -> None:
|
|
806
|
805
|
self.unregister_events()
|
| ... |
... |
@@ -812,7 +811,12 @@ def _destroy(*args: Any) -> None: |
|
812
|
811
|
widget.connect('destroy', _destroy)
|
|
813
|
812
|
|
|
814
|
813
|
|
|
815
|
|
-def _connect_destroy(sender, func, detailed_signal, handler, *args, **kwargs):
|
|
|
814
|
+def _connect_destroy(sender: Any,
|
|
|
815
|
+ func: Any,
|
|
|
816
|
+ detailed_signal: str,
|
|
|
817
|
+ handler: Any,
|
|
|
818
|
+ *args: Any,
|
|
|
819
|
+ **kwargs: Any) -> int:
|
|
816
|
820
|
"""Connect a bound method to a foreign object signal and disconnect
|
|
817
|
821
|
if the object the method is bound to emits destroy (Gtk.Widget subclass).
|
|
818
|
822
|
Also works if the handler is a nested function in a method and
|
| ... |
... |
@@ -834,25 +838,27 @@ def _connect_destroy(sender, func, detailed_signal, handler, *args, **kwargs): |
|
834
|
838
|
|
|
835
|
839
|
handler_id = func(detailed_signal, handler, *args, **kwargs)
|
|
836
|
840
|
|
|
837
|
|
- def disconnect_cb(*args):
|
|
|
841
|
+ def disconnect_cb(*args: Any) -> None:
|
|
838
|
842
|
sender.disconnect(handler_id)
|
|
839
|
843
|
|
|
840
|
844
|
obj.connect('destroy', disconnect_cb)
|
|
841
|
845
|
return handler_id
|
|
842
|
846
|
|
|
843
|
847
|
|
|
844
|
|
-def connect_destroy(sender, *args, **kwargs):
|
|
|
848
|
+def connect_destroy(sender: Any, *args: Any, **kwargs: Any) -> int:
|
|
845
|
849
|
return _connect_destroy(sender, sender.connect, *args, **kwargs)
|
|
846
|
850
|
|
|
847
|
851
|
|
|
848
|
|
-def wrap_with_event_box(klass):
|
|
|
852
|
+def wrap_with_event_box(klass: Any) -> Any:
|
|
849
|
853
|
@wraps(klass)
|
|
850
|
|
- def klass_wrapper(*args, **kwargs):
|
|
|
854
|
+ def klass_wrapper(*args: Any, **kwargs: Any) -> Gtk.EventBox:
|
|
851
|
855
|
widget = klass(*args, **kwargs)
|
|
852
|
856
|
event_box = Gtk.EventBox()
|
|
853
|
857
|
|
|
854
|
|
- def _on_realize(*args):
|
|
855
|
|
- event_box.get_window().set_cursor(get_cursor('pointer'))
|
|
|
858
|
+ def _on_realize(*args: Any) -> None:
|
|
|
859
|
+ window = event_box.get_window()
|
|
|
860
|
+ assert window is not None
|
|
|
861
|
+ window.set_cursor(get_cursor('pointer'))
|
|
856
|
862
|
|
|
857
|
863
|
event_box.connect_after('realize', _on_realize)
|
|
858
|
864
|
event_box.add(widget)
|