Philipp Hörist pushed to branch master at gajim / gajim
Commits: 90c796c5 by lovetox at 2022-08-20T15:41:21+02:00 imprv: WorkspaceSidebar: Allow removing workspace from context menu
- - - - - 287ef4f7 by lovetox at 2022-08-20T20:06:32+02:00 cq: Use correct cairo.Surface type
- - - - - b14c590d by lovetox at 2022-08-20T20:23:07+02:00 cq: Avatar: Fix type check errors
- - - - -
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:
===================================== gajim/common/types.py ===================================== @@ -25,9 +25,12 @@ from gi.repository import GdkPixbuf
import nbxmpp +from nbxmpp.const import PresenceShow from nbxmpp.protocol import JID from nbxmpp.structs import BookmarkData
+from gajim.common.const import PresenceShowExt + if TYPE_CHECKING: from gajim.common.client import Client from nbxmpp.client import Client as xmppClient # noqa: F401 @@ -49,7 +52,6 @@ GroupchatContact, GroupchatParticipant]
- InterfaceT = Union['Interface'] PluginManagerT = Union['PluginManager'] PluginRepositoryT = Union['PluginRepository'] @@ -78,3 +80,5 @@ ChatContactT = Union['BareContact', 'GroupchatContact', 'GroupchatParticipant'] OneOnOneContactT = Union['BareContact', 'GroupchatParticipant'] GroupchatContactT = Union['GroupchatContact'] + +PresenceShowT = Union[PresenceShowExt, PresenceShow]
===================================== gajim/gtk/avatar.py ===================================== @@ -102,7 +102,7 @@ def generate_avatar(letters: str, context.set_operator(cairo.Operator.OVER) context.show_text(letters)
- return context.get_target() + return context.get_target() # pyright: ignore
@lru_cache(maxsize=None) @@ -132,7 +132,8 @@ def make_workspace_avatar(letter: str,
def add_status_to_avatar(surface: cairo.ImageSurface, - show: str) -> cairo.ImageSurface: + show: str + ) -> cairo.ImageSurface:
width = surface.get_width() height = surface.get_height() @@ -179,11 +180,15 @@ def add_status_to_avatar(surface: cairo.ImageSurface, context.set_line_width(clip_radius / 4) context.stroke()
- return context.get_target() + return context.get_target() # pyright: ignore
@lru_cache(maxsize=128) -def get_show_circle(show, size: int, scale: int) -> cairo.ImageSurface: +def get_show_circle(show: Union[str, types.PresenceShowT], + size: int, + scale: int + ) -> cairo.ImageSurface: + if not isinstance(show, str): show = show.value
@@ -212,7 +217,7 @@ def get_show_circle(show, size: int, scale: int) -> cairo.ImageSurface: context.set_line_width(size / 10) context.stroke()
- return context.get_target() + return context.get_target() # pyright: ignore
def fit(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface: @@ -235,7 +240,7 @@ def fit(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface: context.scale(factor, factor) context.set_source_surface(square_surface, 0, 0) context.paint() - return context.get_target() + return context.get_target() # pyright: ignore
def square(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface: @@ -259,7 +264,7 @@ def square(surface: cairo.ImageSurface, size: int) -> cairo.ImageSurface:
context.set_source_surface(surface, x_pos, y_pos) context.paint() - return context.get_target() + return context.get_target() # pyright: ignore
def clip(surface: cairo.ImageSurface, mode: str) -> cairo.ImageSurface: @@ -289,7 +294,7 @@ def clip_circle(surface: cairo.ImageSurface) -> cairo.ImageSurface: context.clip() context.paint()
- return context.get_target() + return context.get_target() # pyright: ignore
def round_corners(surface: cairo.ImageSurface) -> cairo.ImageSurface: @@ -320,7 +325,7 @@ def round_corners(surface: cairo.ImageSurface) -> cairo.ImageSurface:
context.paint()
- return context.get_target() + return context.get_target() # pyright: ignore
def convert_to_greyscale(surface: cairo.ImageSurface) -> cairo.ImageSurface: @@ -333,7 +338,7 @@ def convert_to_greyscale(surface: cairo.ImageSurface) -> cairo.ImageSurface: context.set_source_rgba(1, 1, 1, 0.5) context.rectangle(0, 0, surface.get_width(), surface.get_height()) context.fill() - return context.get_target() + return context.get_target() # pyright: ignore
class AvatarStorage(metaclass=Singleton): @@ -373,6 +378,7 @@ def get_surface(self,
if transport_icon is not None: surface = load_icon_surface(transport_icon, size, scale) + assert surface is not None if show is not None: surface = add_status_to_avatar(surface, show) self._cache[jid][(size, scale, show)] = surface @@ -412,6 +418,7 @@ def get_muc_surface(self,
if transport_icon is not None: surface = load_icon_surface(transport_icon, size, scale) + assert surface is not None self._cache[jid][(size, scale, None)] = surface return surface
@@ -483,6 +490,7 @@ def _load_for_publish(path: str) -> Optional[tuple[bool, bytes]]: height, GdkPixbuf.InterpType.BILINEAR)
+ assert pixbuf is not None return pixbuf.save_to_bufferv('png', [], [])
@staticmethod
===================================== gajim/gtk/avatar_selector.py ===================================== @@ -178,7 +178,9 @@ def _scale_for_publish(pixbuf: GdkPixbuf.Pixbuf return scaled_pixbuf, width, height return pixbuf, width, height
- def get_avatar_surface(self) -> Optional[tuple[cairo.Surface, int, int]]: + def get_avatar_surface(self) -> Optional[tuple[cairo.ImageSurface, + int, + int]]: pixbuf = self._crop_area.get_pixbuf() if pixbuf is None: return None
===================================== gajim/gtk/chat_banner.py ===================================== @@ -236,7 +236,7 @@ def _update_avatar(self) -> None: scale = app.window.get_scale_factor() assert self._contact surface = self._contact.get_avatar(AvatarSize.CHAT, scale) - assert isinstance(surface, cairo.Surface) + assert isinstance(surface, cairo.ImageSurface) self._ui.avatar_image.set_from_surface(surface)
def _update_content(self) -> None:
===================================== gajim/gtk/main.py ===================================== @@ -305,7 +305,7 @@ def _add_actions(self) -> None: actions = [ ('add-workspace', 's', self._add_workspace), ('edit-workspace', 's', self._edit_workspace), - ('remove-workspace', None, self._remove_workspace), + ('remove-workspace', 's', self._remove_workspace), ('activate-workspace', 's', self._activate_workspace), ('add-chat', 'a{sv}', self._add_chat), ('add-group-chat', 'as', self._add_group_chat), @@ -616,9 +616,12 @@ def _edit_workspace(self,
def _remove_workspace(self, _action: Gio.SimpleAction, - _param: Optional[GLib.Variant]) -> None: + param: GLib.Variant) -> None: + + workspace_id = param.get_string() or None + if workspace_id is None: + workspace_id = self.get_active_workspace()
- workspace_id = self.get_active_workspace() if workspace_id is not None: self.remove_workspace(workspace_id)
===================================== gajim/gtk/menus.py ===================================== @@ -577,6 +577,7 @@ def get_format_menu() -> GajimMenu: def get_workspace_menu(workspace_id: str) -> GajimMenu: menuitems: MenuItemListT = [ (_('Edit…'), 'win.edit-workspace', f'"{workspace_id}"'), + (_('Remove'), 'win.remove-workspace', f'"{workspace_id}"'), ]
return GajimMenu.from_list(menuitems)
===================================== gajim/gtk/profile.py ===================================== @@ -94,7 +94,7 @@ def __init__(self, account: str) -> None: self._add_actions()
self._avatar_selector: Optional[AvatarSelector] = None - self._current_avatar: Optional[cairo.Surface] = None + self._current_avatar: Optional[cairo.ImageSurface] = None self._current_vcard: Optional[VCard] = None self._avatar_nick_public: Optional[bool] = None
===================================== gajim/gtk/util.py ===================================== @@ -106,7 +106,7 @@ def load_icon_surface( size: int = 16, scale: Optional[int] = None, flags: Gtk.IconLookupFlags = Gtk.IconLookupFlags.FORCE_SIZE -) -> Optional[cairo.Surface]: +) -> Optional[cairo.ImageSurface]:
icon_info = load_icon_info(icon_name, size, scale, flags) if icon_info is None:
===================================== pyrightconfig.json ===================================== @@ -51,6 +51,7 @@ "gajim/gtk/app_side_bar.py", "gajim/gtk/application.py", "gajim/gtk/apply_button_box.py", + "gajim/gtk/avatar.py", "gajim/gtk/avatar_selector.py", "gajim/gtk/blocking.py", "gajim/gtk/bookmarks.py",
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/923a07f4b5084b9cf38d63739ae51d6f...