Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
90c796c5
by lovetox at 2022-08-20T15:41:21+02:00
-
287ef4f7
by lovetox at 2022-08-20T20:06:32+02:00
-
b14c590d
by lovetox at 2022-08-20T20:23:07+02:00
9 changed files:
- gajim/common/types.py
- gajim/gtk/avatar.py
- gajim/gtk/avatar_selector.py
- gajim/gtk/chat_banner.py
- gajim/gtk/main.py
- gajim/gtk/menus.py
- gajim/gtk/profile.py
- gajim/gtk/util.py
- pyrightconfig.json
Changes:
| ... | ... | @@ -25,9 +25,12 @@ |
| 25 | 25 | from gi.repository import GdkPixbuf
|
| 26 | 26 | |
| 27 | 27 | import nbxmpp
|
| 28 | +from nbxmpp.const import PresenceShow
|
|
| 28 | 29 | from nbxmpp.protocol import JID
|
| 29 | 30 | from nbxmpp.structs import BookmarkData
|
| 30 | 31 | |
| 32 | +from gajim.common.const import PresenceShowExt
|
|
| 33 | + |
|
| 31 | 34 | if TYPE_CHECKING:
|
| 32 | 35 | from gajim.common.client import Client
|
| 33 | 36 | from nbxmpp.client import Client as xmppClient # noqa: F401
|
| ... | ... | @@ -49,7 +52,6 @@ |
| 49 | 52 | GroupchatContact,
|
| 50 | 53 | GroupchatParticipant]
|
| 51 | 54 | |
| 52 | - |
|
| 53 | 55 | InterfaceT = Union['Interface']
|
| 54 | 56 | PluginManagerT = Union['PluginManager']
|
| 55 | 57 | PluginRepositoryT = Union['PluginRepository']
|
| ... | ... | @@ -78,3 +80,5 @@ |
| 78 | 80 | ChatContactT = Union['BareContact', 'GroupchatContact', 'GroupchatParticipant']
|
| 79 | 81 | OneOnOneContactT = Union['BareContact', 'GroupchatParticipant']
|
| 80 | 82 | GroupchatContactT = Union['GroupchatContact']
|
| 83 | + |
|
| 84 | +PresenceShowT = Union[PresenceShowExt, PresenceShow] |
| ... | ... | @@ -102,7 +102,7 @@ def generate_avatar(letters: str, |
| 102 | 102 | context.set_operator(cairo.Operator.OVER)
|
| 103 | 103 | context.show_text(letters)
|
| 104 | 104 | |
| 105 | - return context.get_target()
|
|
| 105 | + return context.get_target() # pyright: ignore
|
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | @lru_cache(maxsize=None)
|
| ... | ... | @@ -132,7 +132,8 @@ def make_workspace_avatar(letter: str, |
| 132 | 132 | |
| 133 | 133 | |
| 134 | 134 | def add_status_to_avatar(surface: cairo.ImageSurface,
|
| 135 | - show: str) -> cairo.ImageSurface:
|
|
| 135 | + show: str
|
|
| 136 | + ) -> cairo.ImageSurface:
|
|
| 136 | 137 | |
| 137 | 138 | width = surface.get_width()
|
| 138 | 139 | height = surface.get_height()
|
| ... | ... | @@ -179,11 +180,15 @@ def add_status_to_avatar(surface: cairo.ImageSurface, |
| 179 | 180 | context.set_line_width(clip_radius / 4)
|
| 180 | 181 | context.stroke()
|
| 181 | 182 | |
| 182 | - return context.get_target()
|
|
| 183 | + return context.get_target() # pyright: ignore
|
|
| 183 | 184 | |
| 184 | 185 | |
| 185 | 186 | @lru_cache(maxsize=128)
|
| 186 | -def get_show_circle(show, size: int, scale: int) -> cairo.ImageSurface:
|
|
| 187 | +def get_show_circle(show: Union[str, types.PresenceShowT],
|
|
| 188 | + size: int,
|
|
| 189 | + scale: int
|
|
| 190 | + ) -> cairo.ImageSurface:
|
|
| 191 | + |
|
| 187 | 192 | if not isinstance(show, str):
|
| 188 | 193 | show = show.value
|
| 189 | 194 | |
| ... | ... | @@ -212,7 +217,7 @@ def get_show_circle(show, size: int, scale: int) -> cairo.ImageSurface: |
| 212 | 217 | context.set_line_width(size / 10)
|
| 213 | 218 | context.stroke()
|
| 214 | 219 | |
| 215 | - return context.get_target()
|
|
| 220 | + return context.get_target() # pyright: ignore
|
|
| 216 | 221 | |
| 217 | 222 | |
| 218 | 223 | def fit(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface:
|
| ... | ... | @@ -235,7 +240,7 @@ def fit(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface: |
| 235 | 240 | context.scale(factor, factor)
|
| 236 | 241 | context.set_source_surface(square_surface, 0, 0)
|
| 237 | 242 | context.paint()
|
| 238 | - return context.get_target()
|
|
| 243 | + return context.get_target() # pyright: ignore
|
|
| 239 | 244 | |
| 240 | 245 | |
| 241 | 246 | def square(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface:
|
| ... | ... | @@ -259,7 +264,7 @@ def square(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface: |
| 259 | 264 | |
| 260 | 265 | context.set_source_surface(surface, x_pos, y_pos)
|
| 261 | 266 | context.paint()
|
| 262 | - return context.get_target()
|
|
| 267 | + return context.get_target() # pyright: ignore
|
|
| 263 | 268 | |
| 264 | 269 | |
| 265 | 270 | def clip(surface: cairo.ImageSurface, mode: str) -> cairo.ImageSurface:
|
| ... | ... | @@ -289,7 +294,7 @@ def clip_circle(surface: cairo.ImageSurface) -> cairo.ImageSurface: |
| 289 | 294 | context.clip()
|
| 290 | 295 | context.paint()
|
| 291 | 296 | |
| 292 | - return context.get_target()
|
|
| 297 | + return context.get_target() # pyright: ignore
|
|
| 293 | 298 | |
| 294 | 299 | |
| 295 | 300 | def round_corners(surface: cairo.ImageSurface) -> cairo.ImageSurface:
|
| ... | ... | @@ -320,7 +325,7 @@ def round_corners(surface: cairo.ImageSurface) -> cairo.ImageSurface: |
| 320 | 325 | |
| 321 | 326 | context.paint()
|
| 322 | 327 | |
| 323 | - return context.get_target()
|
|
| 328 | + return context.get_target() # pyright: ignore
|
|
| 324 | 329 | |
| 325 | 330 | |
| 326 | 331 | def convert_to_greyscale(surface: cairo.ImageSurface) -> cairo.ImageSurface:
|
| ... | ... | @@ -333,7 +338,7 @@ def convert_to_greyscale(surface: cairo.ImageSurface) -> cairo.ImageSurface: |
| 333 | 338 | context.set_source_rgba(1, 1, 1, 0.5)
|
| 334 | 339 | context.rectangle(0, 0, surface.get_width(), surface.get_height())
|
| 335 | 340 | context.fill()
|
| 336 | - return context.get_target()
|
|
| 341 | + return context.get_target() # pyright: ignore
|
|
| 337 | 342 | |
| 338 | 343 | |
| 339 | 344 | class AvatarStorage(metaclass=Singleton):
|
| ... | ... | @@ -373,6 +378,7 @@ def get_surface(self, |
| 373 | 378 | |
| 374 | 379 | if transport_icon is not None:
|
| 375 | 380 | surface = load_icon_surface(transport_icon, size, scale)
|
| 381 | + assert surface is not None
|
|
| 376 | 382 | if show is not None:
|
| 377 | 383 | surface = add_status_to_avatar(surface, show)
|
| 378 | 384 | self._cache[jid][(size, scale, show)] = surface
|
| ... | ... | @@ -412,6 +418,7 @@ def get_muc_surface(self, |
| 412 | 418 | |
| 413 | 419 | if transport_icon is not None:
|
| 414 | 420 | surface = load_icon_surface(transport_icon, size, scale)
|
| 421 | + assert surface is not None
|
|
| 415 | 422 | self._cache[jid][(size, scale, None)] = surface
|
| 416 | 423 | return surface
|
| 417 | 424 | |
| ... | ... | @@ -483,6 +490,7 @@ def _load_for_publish(path: str) -> Optional[tuple[bool, bytes]]: |
| 483 | 490 | height,
|
| 484 | 491 | GdkPixbuf.InterpType.BILINEAR)
|
| 485 | 492 | |
| 493 | + assert pixbuf is not None
|
|
| 486 | 494 | return pixbuf.save_to_bufferv('png', [], [])
|
| 487 | 495 | |
| 488 | 496 | @staticmethod
|
| ... | ... | @@ -178,7 +178,9 @@ def _scale_for_publish(pixbuf: GdkPixbuf.Pixbuf |
| 178 | 178 | return scaled_pixbuf, width, height
|
| 179 | 179 | return pixbuf, width, height
|
| 180 | 180 | |
| 181 | - def get_avatar_surface(self) -> Optional[tuple[cairo.Surface, int, int]]:
|
|
| 181 | + def get_avatar_surface(self) -> Optional[tuple[cairo.ImageSurface,
|
|
| 182 | + int,
|
|
| 183 | + int]]:
|
|
| 182 | 184 | pixbuf = self._crop_area.get_pixbuf()
|
| 183 | 185 | if pixbuf is None:
|
| 184 | 186 | return None
|
| ... | ... | @@ -236,7 +236,7 @@ def _update_avatar(self) -> None: |
| 236 | 236 | scale = app.window.get_scale_factor()
|
| 237 | 237 | assert self._contact
|
| 238 | 238 | surface = self._contact.get_avatar(AvatarSize.CHAT, scale)
|
| 239 | - assert isinstance(surface, cairo.Surface)
|
|
| 239 | + assert isinstance(surface, cairo.ImageSurface)
|
|
| 240 | 240 | self._ui.avatar_image.set_from_surface(surface)
|
| 241 | 241 | |
| 242 | 242 | def _update_content(self) -> None:
|
| ... | ... | @@ -305,7 +305,7 @@ def _add_actions(self) -> None: |
| 305 | 305 | actions = [
|
| 306 | 306 | ('add-workspace', 's', self._add_workspace),
|
| 307 | 307 | ('edit-workspace', 's', self._edit_workspace),
|
| 308 | - ('remove-workspace', None, self._remove_workspace),
|
|
| 308 | + ('remove-workspace', 's', self._remove_workspace),
|
|
| 309 | 309 | ('activate-workspace', 's', self._activate_workspace),
|
| 310 | 310 | ('add-chat', 'a{sv}', self._add_chat),
|
| 311 | 311 | ('add-group-chat', 'as', self._add_group_chat),
|
| ... | ... | @@ -616,9 +616,12 @@ def _edit_workspace(self, |
| 616 | 616 | |
| 617 | 617 | def _remove_workspace(self,
|
| 618 | 618 | _action: Gio.SimpleAction,
|
| 619 | - _param: Optional[GLib.Variant]) -> None:
|
|
| 619 | + param: GLib.Variant) -> None:
|
|
| 620 | + |
|
| 621 | + workspace_id = param.get_string() or None
|
|
| 622 | + if workspace_id is None:
|
|
| 623 | + workspace_id = self.get_active_workspace()
|
|
| 620 | 624 | |
| 621 | - workspace_id = self.get_active_workspace()
|
|
| 622 | 625 | if workspace_id is not None:
|
| 623 | 626 | self.remove_workspace(workspace_id)
|
| 624 | 627 |
| ... | ... | @@ -577,6 +577,7 @@ def get_format_menu() -> GajimMenu: |
| 577 | 577 | def get_workspace_menu(workspace_id: str) -> GajimMenu:
|
| 578 | 578 | menuitems: MenuItemListT = [
|
| 579 | 579 | (_('Edit…'), 'win.edit-workspace', f'"{workspace_id}"'),
|
| 580 | + (_('Remove'), 'win.remove-workspace', f'"{workspace_id}"'),
|
|
| 580 | 581 | ]
|
| 581 | 582 | |
| 582 | 583 | return GajimMenu.from_list(menuitems)
|
| ... | ... | @@ -94,7 +94,7 @@ def __init__(self, account: str) -> None: |
| 94 | 94 | self._add_actions()
|
| 95 | 95 | |
| 96 | 96 | self._avatar_selector: Optional[AvatarSelector] = None
|
| 97 | - self._current_avatar: Optional[cairo.Surface] = None
|
|
| 97 | + self._current_avatar: Optional[cairo.ImageSurface] = None
|
|
| 98 | 98 | self._current_vcard: Optional[VCard] = None
|
| 99 | 99 | self._avatar_nick_public: Optional[bool] = None
|
| 100 | 100 |
| ... | ... | @@ -106,7 +106,7 @@ def load_icon_surface( |
| 106 | 106 | size: int = 16,
|
| 107 | 107 | scale: Optional[int] = None,
|
| 108 | 108 | flags: Gtk.IconLookupFlags = Gtk.IconLookupFlags.FORCE_SIZE
|
| 109 | -) -> Optional[cairo.Surface]:
|
|
| 109 | +) -> Optional[cairo.ImageSurface]:
|
|
| 110 | 110 | |
| 111 | 111 | icon_info = load_icon_info(icon_name, size, scale, flags)
|
| 112 | 112 | if icon_info is None:
|
| ... | ... | @@ -51,6 +51,7 @@ |
| 51 | 51 | "gajim/gtk/app_side_bar.py",
|
| 52 | 52 | "gajim/gtk/application.py",
|
| 53 | 53 | "gajim/gtk/apply_button_box.py",
|
| 54 | + "gajim/gtk/avatar.py",
|
|
| 54 | 55 | "gajim/gtk/avatar_selector.py",
|
| 55 | 56 | "gajim/gtk/blocking.py",
|
| 56 | 57 | "gajim/gtk/bookmarks.py",
|