Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: cfd2c525 by wurstsalat at 2022-01-20T19:52:31+01:00 AddContact: Typing
- - - - - 293ae9ef by wurstsalat at 2022-01-20T20:02:51+01:00 RemoveAccount: Typing
- - - - - ea8dba3a by wurstsalat at 2022-01-20T20:10:34+01:00 ChangePassword: Typing
- - - - -
3 changed files:
- gajim/gtk/add_contact.py - gajim/gtk/change_password.py - gajim/gtk/remove_account.py
Changes:
===================================== gajim/gtk/add_contact.py ===================================== @@ -12,11 +12,11 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from __future__ import annotations + from typing import Any -from typing import Dict -from typing import List +from typing import cast from typing import Optional -from typing import Tuple from typing import Union
import logging @@ -40,6 +40,7 @@ from .assistant import Assistant from .assistant import Page from .assistant import ErrorPage +from .assistant import ProgressPage from .groupchat_info import GroupChatInfoScrolled from .builder import get_builder from .util import open_window @@ -75,7 +76,7 @@ def __init__(self, 'gateway': Gateway(), })
- progress = self.add_default_page('progress') + progress = cast(ProgressPage, self.add_default_page('progress')) progress.set_title(_('Gathering information…')) progress.set_text(_('Trying to gather information on this address…'))
@@ -92,8 +93,8 @@ def _on_button_clicked(self, button_name: str ) -> None: page = self.get_current_page() - account, _ = self.get_page('address').get_account_and_jid() - assert account is not None + address_page = cast(Address, self.get_page('address')) + account, _ = address_page.get_account_and_jid()
if button_name == 'next': self._start_disco() @@ -102,13 +103,14 @@ def _on_button_clicked(self, if button_name == 'back': self.show_page('address', Gtk.StackTransitionType.SLIDE_RIGHT) - self.get_page('address').focus() + address_page.focus() return
if button_name == 'add': client = app.get_client(account) if page == 'contact': - data = self.get_page('contact').get_subscription_data() + contact_page = cast(Contact, self.get_page('contact')) + data = contact_page.get_subscription_data() client.get_module('Presence').subscribe( self._result.jid, msg=data['message'], @@ -124,7 +126,7 @@ def _on_button_clicked(self, return
if button_name == 'join': - _, jid = self.get_page('address').get_account_and_jid() + _, jid = address_page.get_account_and_jid() open_window('GroupchatJoin', account=account, jid=jid) self.destroy()
@@ -132,22 +134,25 @@ def _start_disco(self) -> None: self._result = None self.show_page('progress', Gtk.StackTransitionType.SLIDE_LEFT)
- account, jid = self.get_page('address').get_account_and_jid() + address_page = cast(Address, self.get_page('address')) + account, jid = address_page.get_account_and_jid() assert account is not None self._disco_info(account, jid)
@as_task - def _disco_info(self, account: str, address: str) -> None: + def _disco_info(self, account: str, address: str) -> Any: _task = yield
client = app.get_client(account)
result = yield client.get_module('Discovery').disco_info(address) if is_error(result): + assert isinstance(result, StanzaError) self._process_error(account, result) raise result
log.info('Disco Info received: %s', address) + assert isinstance(result, DiscoInfo) self._process_info(account, result)
def _process_error(self, account: str, result: StanzaError) -> None: @@ -160,10 +165,12 @@ def _process_error(self, account: str, result: StanzaError) -> None: ] if result.condition in contact_conditions: # It seems to be a contact - self.get_page('contact').prepare(account, result) + address_page = cast(Contact, self.get_page('contact')) + address_page.prepare(account, result) self.show_page('contact', Gtk.StackTransitionType.SLIDE_LEFT) else: - self.get_page('error').set_text(result.get_text()) + error_page = cast(ErrorPage, self.get_page('error')) + error_page.set_text(result.get_text()) self.show_page('error', Gtk.StackTransitionType.SLIDE_LEFT)
def _process_info(self, account: str, result: DiscoInfo) -> None: @@ -175,7 +182,8 @@ def _process_info(self, account: str, result: DiscoInfo) -> None: if identity.type == 'text' and result.jid.is_domain: # It's a group chat component advertising # category 'conference' - self.get_page('error').set_text( + error_page = cast(ErrorPage, self.get_page('error')) + error_page.set_text( _('This address does not seem to offer any gateway ' 'service.')) self.show_page('error') @@ -183,21 +191,25 @@ def _process_info(self, account: str, result: DiscoInfo) -> None:
if identity.type == 'irc' and result.jid.is_domain: # It's an IRC gateway advertising category 'conference' - self.get_page('gateway').prepare(account, result) + gateway_page = cast(Gateway, self.get_page('gateway')) + gateway_page.prepare(account, result) self.show_page( 'gateway', Gtk.StackTransitionType.SLIDE_LEFT) return
- self.get_page('groupchat').prepare(account, result) + groupchat_page = cast(GroupChat, self.get_page('groupchat')) + groupchat_page.prepare(account, result) self.show_page('groupchat', Gtk.StackTransitionType.SLIDE_LEFT) return
if result.is_gateway: - self.get_page('gateway').prepare(account, result) + gateway_page = cast(Gateway, self.get_page('gateway')) + gateway_page.prepare(account, result) self.show_page('gateway', Gtk.StackTransitionType.SLIDE_LEFT) return
- self.get_page('contact').prepare(account, result) + contact_page = cast(Contact, self.get_page('contact')) + contact_page.prepare(account, result) self.show_page('contact', Gtk.StackTransitionType.SLIDE_LEFT)
@@ -217,6 +229,7 @@ def __init__(self, account: Optional[str], jid: Optional[JID]) -> None:
accounts = app.get_enabled_accounts_with_labels(connected_only=True) liststore = self._ui.account_combo.get_model() + assert isinstance(liststore, Gtk.ListStore) for acc in accounts: liststore.append(acc)
@@ -238,13 +251,14 @@ def __init__(self, account: Optional[str], jid: Optional[JID]) -> None:
self.show_all()
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['next']
def get_default_button(self) -> str: return 'next'
- def get_account_and_jid(self) -> Tuple[str, str]: + def get_account_and_jid(self) -> tuple[str, str]: + assert self._account is not None return self._account, self._ui.address_entry.get_text()
def focus(self) -> None: @@ -316,7 +330,7 @@ def __init__(self) -> None: self.set_title(_('Add Contact')) self.set_heading(_('An Error Occurred'))
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['back']
def get_default_button(self) -> str: @@ -339,7 +353,7 @@ def __init__(self) -> None:
self.show_all()
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['back', 'add']
def get_default_button(self) -> str: @@ -357,7 +371,9 @@ def prepare(self, account: str, result: Union[DiscoInfo, StanzaError]): self._ui.contact_grid.set_sensitive(True)
def _update_groups(self, account: str) -> None: - self._ui.group_combo.get_model().clear() + model = self._ui.group_combo.get_model() + assert isinstance(model, Gtk.ListStore) + model.clear() client = app.get_client(account) for group in client.get_module('Roster').get_groups(): self._ui.group_combo.append_text(group) @@ -366,7 +382,7 @@ def _on_info_clicked(self, _button: Gtk.Button) -> None: open_window( 'ContactInfo', account=self._account, contact=self._contact)
- def get_subscription_data(self) -> Dict[str, Union[str, List[str], bool]]: + def get_subscription_data(self) -> dict[str, Union[str, list[str], bool]]: group = self._ui.group_combo.get_child().get_text() groups = [group] if group else [] return { @@ -392,7 +408,7 @@ def __init__(self) -> None:
self.show_all()
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['back', 'add']
def get_default_button(self) -> str: @@ -482,7 +498,7 @@ def __init__(self) -> None:
self.show_all()
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['back', 'join']
def get_default_button(self) -> str:
===================================== gajim/gtk/change_password.py ===================================== @@ -13,7 +13,7 @@ # along with Gajim. If not, see http://www.gnu.org/licenses/.
from typing import Any -from typing import List +from typing import cast
import logging
@@ -32,6 +32,7 @@ from .assistant import Assistant from .assistant import Page from .assistant import ErrorPage +from .assistant import ProgressPage from .assistant import SuccessPage from .dataform import DataFormWidget from .util import ensure_not_destroyed @@ -57,7 +58,7 @@ def __init__(self, account: str) -> None: 'error': Error(), 'success': Success()})
- progress = self.add_default_page('progress') + progress = cast(ProgressPage, self.add_default_page('progress')) progress.set_title(_('Changing Password...')) progress.set_text(_('Trying to change password...'))
@@ -83,11 +84,13 @@ def _on_button_clicked(self,
def _on_apply(self, next_stage: bool = False) -> None: if next_stage: - form = self.get_page('next_stage').get_submit_form() + next_stage_page = cast(NextStage, self.get_page('next_stage')) + form = next_stage_page.get_submit_form() self._client.get_module('Register').change_password_with_form( form, callback=self._on_change_password) else: - password = self.get_page('password').get_password() + password_page = cast(EnterPassword, self.get_page('password')) + password = password_page.get_password() self._client.get_module('Register').change_password( password, callback=self._on_change_password)
@@ -96,16 +99,19 @@ def _on_change_password(self, task: Task) -> None: try: task.finish() except ChangePasswordStanzaError as error: - self.get_page('next_stage').set_form(error.get_form()) + next_stage_page = cast(NextStage, self.get_page('next_stage')) + next_stage_page.set_form(error.get_form()) self.show_page('next_stage', Gtk.StackTransitionType.SLIDE_LEFT)
except StanzaError as error: error_text = to_user_string(error) - self.get_page('error').set_text(error_text) + error_page = cast(Error, self.get_page('error')) + error_page.set_text(error_text) self.show_page('error', Gtk.StackTransitionType.SLIDE_LEFT)
else: - password = self.get_page('password').get_password() + password_page = cast(EnterPassword, self.get_page('password')) + password = password_page.get_password() passwords.save_password(self.account, password) self.show_page('success')
@@ -190,7 +196,7 @@ def _set_complete(self, state: bool) -> None: def get_password(self) -> str: return self._password1_entry.get_text()
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['apply']
@@ -219,9 +225,10 @@ def set_form(self, form: SimpleDataForm) -> None: self._current_form.show_all()
def get_submit_form(self) -> SimpleDataForm: + assert self._current_form is not None return self._current_form.get_submit_form()
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['apply']
@@ -233,7 +240,7 @@ def __init__(self) -> None: self.set_text( _('An error occurred while trying to change your password.'))
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['back']
@@ -244,5 +251,5 @@ def __init__(self) -> None: self.set_heading(_('Password Changed')) self.set_text(_('Your password has successfully been changed.'))
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['close']
===================================== gajim/gtk/remove_account.py ===================================== @@ -13,7 +13,7 @@ # along with Gajim. If not, see http://www.gnu.org/licenses/.
from typing import Any -from typing import List +from typing import cast
import logging
@@ -24,12 +24,15 @@
from gajim.common import app from gajim.common import ged +from gajim.common.events import AccountConnected +from gajim.common.events import AccountDisonnected from gajim.common.i18n import _ from gajim.common.helpers import to_user_string from gajim.common.helpers import event_filter
from .assistant import Assistant from .assistant import Page +from .assistant import ProgressPage from .assistant import ErrorPage from .assistant import SuccessPage
@@ -58,7 +61,7 @@ def __init__(self, account: str) -> None: 'error': Error(), 'success': Success()})
- progress = self.add_default_page('progress') + progress = cast(ProgressPage, self.add_default_page('progress')) progress.set_title(_('Removing Account...')) progress.set_text(_('Trying to remove account...'))
@@ -75,12 +78,12 @@ def __init__(self, account: str) -> None: self.show_all()
@event_filter(['account']) - def _on_account_connected(self, _event): + def _on_account_connected(self, _event: AccountConnected) -> None: self._client = app.get_client(self.account) self._set_remove_from_server_checkbox()
@event_filter(['account']) - def _on_account_disconnected(self, _event): + def _on_account_disconnected(self, _event: AccountDisonnected) -> None: self._set_remove_from_server_checkbox()
if self._account_removed: @@ -89,7 +92,8 @@ def _on_account_disconnected(self, _event):
def _set_remove_from_server_checkbox(self) -> None: enabled = self._client is not None and self._client.state.is_available - self.get_page('remove_choice').set_remove_from_server(enabled) + remove_choice_page = cast(RemoveChoice, self.get_page('remove_choice')) + remove_choice_page.set_remove_from_server(enabled)
def _on_button_clicked(self, _assistant: Assistant, @@ -112,7 +116,9 @@ def _on_button_clicked(self, self.destroy()
def _on_remove(self, *args: Any) -> None: - if self.get_page('remove_choice').remove_from_server: + remove_choice_page = cast(RemoveChoice, self.get_page('remove_choice')) + if remove_choice_page.remove_from_server: + assert self._client is not None self._client.set_remove_account(True) self._client.get_module('Register').unregister( callback=self._on_remove_response) @@ -130,10 +136,12 @@ def _on_remove_response(self, task: Task) -> None: try: task.finish() except StanzaError as error: + assert self._client is not None self._client.set_remove_account(False)
error_text = to_user_string(error) - self.get_page('error').set_text(error_text) + error_page = cast(Error, self.get_page('error')) + error_page.set_text(error_text) self.show_page('error') return
@@ -194,7 +202,7 @@ def set_remove_from_server(self, enabled: bool) -> None: self._server.set_active(False) self._server.set_tooltip_text(_('Account has to be connected'))
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['remove']
@@ -204,7 +212,7 @@ def __init__(self) -> None: self.set_title(_('Account Removal Failed')) self.set_heading(_('Account Removal Failed'))
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['back']
@@ -216,5 +224,5 @@ def __init__(self) -> None: self.set_text( _('Your account has has been removed successfully.'))
- def get_visible_buttons(self) -> List[str]: + def get_visible_buttons(self) -> list[str]: return ['close']
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/5c8e01e6ef58d2b7d38228e701f993a7...