Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 4319f263 by wurstsalat at 2022-01-11T15:52:29+01:00 GroupChatInvitation: Typing
- - - - - 8826ebdf by wurstsalat at 2022-01-11T16:06:54+01:00 GroupchatJoin: Typing
- - - - - c07f5294 by wurstsalat at 2022-01-11T16:19:20+01:00 GroupChatInfoScrolled: Typing
- - - - -
3 changed files:
- gajim/gtk/groupchat_info.py - gajim/gtk/groupchat_invitation.py - gajim/gtk/groupchat_join.py
Changes:
===================================== gajim/gtk/groupchat_info.py ===================================== @@ -104,8 +104,8 @@ class GroupChatInfoScrolled(Gtk.ScrolledWindow): def __init__(self, account: Optional[str] = None, - width: Optional[int] = 300, - minimal: Optional[bool] = False + width: int = 300, + minimal: bool = False ) -> None: Gtk.ScrolledWindow.__init__(self) self.set_size_request(width, -1) @@ -131,7 +131,7 @@ def __init__(self, self._ui.connect_signals(self) self.show_all()
- def get_account(self) -> str: + def get_account(self) -> Optional[str]: return self._account
def set_account(self, account: str) -> None: @@ -166,20 +166,19 @@ def set_from_disco_info(self, info: DiscoInfo) -> None: if self._account is None: name = info.muc_name else: - con = app.connections[self._account] - name = get_groupchat_name(con, info.jid) + client = app.get_client(self._account) + name = get_groupchat_name(client, info.jid) + + contact = client.get_module('Contacts').get_contact( + info.jid, groupchat=True) + surface = contact.get_avatar( + AvatarSize.GROUP_INFO, + self.get_scale_factor()) + self._ui.avatar_image.set_from_surface(surface) + self._ui.name.set_text(name) self._ui.name.set_visible(True)
- # Set avatar - client = app.get_client(self._account) - contact = client.get_module('Contacts').get_contact( - info.jid, groupchat=True) - surface = contact.get_avatar( - AvatarSize.GROUP_INFO, - self.get_scale_factor()) - self._ui.avatar_image.set_from_surface(surface) - # Set description has_desc = bool(info.muc_description) self._ui.description.set_text(info.muc_description or '') @@ -230,7 +229,7 @@ def set_from_disco_info(self, info: DiscoInfo) -> None:
self._add_features(info.features)
- def _add_features(self, features: List[str]) -> None: + def _add_features(self, features: list[str]) -> None: grid = self._ui.info_grid for row in range(30, 9, -1): # Remove everything from row 30 to 10 @@ -260,23 +259,23 @@ def _on_copy_address(self, _button: Gtk.Button) -> None: clipboard.set_text(f'xmpp:{self._info.jid}?join', -1)
@staticmethod - def _on_activate_log_link(button): + def _on_activate_log_link(button: Gtk.LinkButton) -> int: open_uri(button.get_uri()) return Gdk.EVENT_STOP
- def _on_activate_contact_link(self, button): + def _on_activate_contact_link(self, button: Gtk.LinkButton) -> int: open_uri(f'xmpp:{button.get_uri()}?message', account=self._account) return Gdk.EVENT_STOP
@staticmethod - def _on_activate_subject_link(_label, uri): + def _on_activate_subject_link(_label: Gtk.Label, uri: str) -> int: # We have to use this, because the default GTK handler # is not cross-platform compatible open_uri(uri) return Gdk.EVENT_STOP
@staticmethod - def _get_feature_icon(icon, tooltip: str) -> Gtk.Image: + def _get_feature_icon(icon: str, tooltip: str) -> Gtk.Image: image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU) image.set_valign(Gtk.Align.CENTER) image.set_halign(Gtk.Align.END) @@ -291,7 +290,7 @@ def _get_feature_label(text: str) -> Gtk.Label: return label
def _get_contact_button(self, contact: str) -> Gtk.Button: - button = Gtk.LinkButton.new(contact) + button = Gtk.LinkButton(label=contact) button.set_halign(Gtk.Align.START) button.get_style_context().add_class('link-button') button.connect('activate-link', self._on_activate_contact_link)
===================================== gajim/gtk/groupchat_invitation.py ===================================== @@ -16,6 +16,7 @@ from gi.repository import Gtk
from gajim.common import app +from gajim.common.events import MucInvitation from gajim.common.i18n import _ from gajim.common.helpers import get_group_chat_nick
@@ -25,7 +26,7 @@
class GroupChatInvitation(Gtk.ApplicationWindow): - def __init__(self, account, event): + def __init__(self, account: str, event: MucInvitation) -> None: Gtk.ApplicationWindow.__init__(self) self.set_name('GroupChatInvitation') self.set_application(app.app) @@ -100,7 +101,7 @@ def __init__(self, account, event):
main_box.add(button_box)
- self.connect('key-press-event', self._on_key_press_event) + self.connect('key-press-event', self._on_key_press)
self.add(main_box)
@@ -109,16 +110,16 @@ def __init__(self, account, event):
self.show_all()
- def _on_key_press_event(self, _widget, event): + def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None: if event.keyval == Gdk.KEY_Escape: self.destroy()
- def _on_join(self, _widget): + def _on_join(self, _button: Gtk.Button) -> None: nickname = self._nick_chooser.get_text() app.interface.show_add_join_groupchat( self.account, self._room_jid, nickname=nickname) self.destroy()
- def _on_decline(self, _widget): + def _on_decline(self, _button: Gtk.Button) -> None: self._client.get_module('MUC').decline(self._room_jid, self._from) self.destroy()
===================================== gajim/gtk/groupchat_join.py ===================================== @@ -12,6 +12,9 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from typing import cast +from typing import Any + import logging
from gi.repository import Gtk @@ -19,6 +22,7 @@ from gi.repository import Pango
from nbxmpp.errors import StanzaError +from nbxmpp.task import Task
from gajim.common import app from gajim.common.i18n import _ @@ -35,7 +39,7 @@
class GroupchatJoin(Gtk.ApplicationWindow): - def __init__(self, account, jid): + def __init__(self, account: str, jid: str) -> None: Gtk.ApplicationWindow.__init__(self) self.set_name('GroupchatJoin') self.set_application(app.app) @@ -61,7 +65,8 @@ def __init__(self, account, jid): self._stack.add_named(ErrorPage(), 'error')
self._stack.set_visible_child_name('progress') - self._stack.get_visible_child().start() + progress_page = cast(ProgressPage, self._stack.get_visible_child()) + progress_page.start()
self._stack.connect('notify::visible-child-name', self._on_page_changed) @@ -84,7 +89,7 @@ def __init__(self, account, jid):
self._main_box.add(join_box)
- self.connect('key-press-event', self._on_key_press_event) + self.connect('key-press-event', self._on_key_press) self.connect('destroy', self._on_destroy)
self.add(self._main_box) @@ -97,13 +102,13 @@ def __init__(self, account, jid): request_vcard=True, callback=self._disco_info_received)
- def _on_page_changed(self, stack, _param): + def _on_page_changed(self, stack: Gtk.Stack, _param: Any) -> None: name = stack.get_visible_child_name() self._join_button.set_sensitive(name == 'info') self._nick_chooser.set_sensitive(name == 'info')
@ensure_not_destroyed - def _disco_info_received(self, task): + def _disco_info_received(self, task: Task) -> None: try: result = task.finish() except StanzaError as error: @@ -124,11 +129,12 @@ def _disco_info_received(self, task): else: self._set_error_from_code('not-muc-service')
- def _show_error_page(self, text): - self._stack.get_child_by_name('error').set_text(text) + def _show_error_page(self, text: str) -> None: + error_page = cast(ErrorPage, self._stack.get_child_by_name('error')) + error_page.set_text(text) self._stack.set_visible_child_name('error')
- def _set_error(self, error): + def _set_error(self, error: StanzaError) -> None: text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error)) if error.condition == 'gone': reason = error.get_text(get_rfc5646_lang()) @@ -136,26 +142,26 @@ def _set_error(self, error): text = '%s:\n%s' % (text, reason) self._show_error_page(text)
- def _set_error_from_code(self, error_code): + def _set_error_from_code(self, error_code: str) -> None: self._show_error_page(MUC_DISCO_ERRORS[error_code])
- def _on_join(self, *args): + def _on_join(self, _button: Gtk.Button) -> None: nickname = self._nick_chooser.get_text()
app.interface.show_add_join_groupchat( self.account, self.jid, nickname=nickname) self.destroy()
- def _on_destroy(self, *args): + def _on_destroy(self, _widget: Gtk.Widget) -> None: self._destroyed = True
- def _on_key_press_event(self, _widget, event): + def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None: if event.keyval == Gdk.KEY_Escape: self.destroy()
class ErrorPage(Gtk.Box): - def __init__(self): + def __init__(self) -> None: Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=18) @@ -177,12 +183,12 @@ def __init__(self): self.add(self._error_label) self.show_all()
- def set_text(self, text): + def set_text(self, text: str) -> None: self._error_label.set_text(text)
class ProgressPage(Gtk.Box): - def __init__(self): + def __init__(self) -> None: Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=18) @@ -193,8 +199,8 @@ def __init__(self): self.add(self._spinner) self.show_all()
- def start(self): + def start(self) -> None: self._spinner.start()
- def stop(self): + def stop(self) -> None: self._spinner.stop()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/024433fba5f8a27d5ad4fca97bb70ebd...