Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: f5069e82 by wurstsalat at 2022-01-11T15:19:17+01:00 Preferences: Typing
- - - - - 57525a54 by wurstsalat at 2022-01-11T15:26:22+01:00 NotificationManager: Typing
- - - - - fe4e4d2a by wurstsalat at 2022-01-11T15:32:50+01:00 PasswordDialog: Typing
- - - - - 024433fb by wurstsalat at 2022-01-11T15:34:33+01:00 SSLErrorDialog: Typing
- - - - -
7 changed files:
- gajim/common/helpers.py - gajim/gtk/notification_manager.py - gajim/gtk/password_dialog.py - gajim/gtk/preferences.py - gajim/gtk/ssl_error_dialog.py - gajim/gtk/themes.py - gajim/gui_interface.py
Changes:
===================================== gajim/common/helpers.py ===================================== @@ -1053,7 +1053,7 @@ def open_uri(uri: Union[URI, str], account: Optional[str] = None) -> None:
@catch_exceptions -def open_file(path: str) -> None: +def open_file(path: Union[str, Path]) -> None: if os.name == 'nt': os.startfile(path) else:
===================================== gajim/gtk/notification_manager.py ===================================== @@ -16,6 +16,7 @@ from typing import Any from typing import Optional from typing import Union +from typing import cast
from gi.repository import Gio from gi.repository import GLib @@ -153,7 +154,8 @@ def _deny_request(self, jid: str) -> None: self._client.get_module('Presence').unsubscribed(jid)
def _get_notification_row(self, jid: str) -> Optional[NotificationRow]: - for row in self.get_children(): + rows = cast(list[NotificationRow], self.get_children()) + for row in rows: if row.jid == jid: return row return None @@ -291,7 +293,7 @@ def __init__(self, accept_button.set_valign(Gtk.Align.CENTER) accept_button.set_action_name( f'win.subscription-accept-{self._account}') - accept_button.set_action_target_value(GLib.Variant('s', str(self.jid))) + accept_button.set_action_target_value(GLib.Variant('s', self.jid)) self.grid.attach(accept_button, 3, 1, 1, 2)
more_image = Gtk.Image.new_from_icon_name( @@ -299,7 +301,8 @@ def __init__(self, more_button = Gtk.MenuButton() more_button.set_valign(Gtk.Align.CENTER) more_button.add(more_image) - subscription_menu = get_subscription_menu(self._account, self.jid) + subscription_menu = get_subscription_menu( + self._account, JID.from_string(self.jid)) more_button.set_menu_model(subscription_menu) self.grid.attach(more_button, 4, 1, 1, 2)
===================================== gajim/gtk/password_dialog.py ===================================== @@ -18,6 +18,7 @@ from gi.repository import Gdk
from gajim.common import app +from gajim.common.events import PasswordRequired from gajim.common.i18n import _ from gajim.common.passwords import save_password from gajim.common.passwords import KEYRING_AVAILABLE @@ -28,7 +29,7 @@
class PasswordDialog(Gtk.ApplicationWindow): - def __init__(self, account, event): + def __init__(self, account: str, event: PasswordRequired) -> None: Gtk.ApplicationWindow.__init__(self) self.set_application(app.app) self.set_type_hint(Gdk.WindowTypeHint.DIALOG) @@ -43,7 +44,7 @@ def __init__(self, account, event):
self.account = account self._client = app.get_client(account) - self.event = event + self._event = event
self.connect('key-press-event', self._on_key_press) self._ui.connect_signals(self) @@ -52,16 +53,16 @@ def __init__(self, account, event):
self._process_event()
- def _on_key_press(self, _widget, event): + def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None: if event.keyval == Gdk.KEY_Escape: self.destroy()
- def _process_event(self): + def _process_event(self) -> None: own_jid = self._client.get_own_jid().bare account_name = app.settings.get_account_setting( self.account, 'name')
- if self.event.name == 'password-required': + if self._event.name == 'password-required': self._ui.header.set_text(_('Password Required')) self._ui.message_label.set_text( _('Please enter your password for\n' @@ -74,7 +75,7 @@ def _process_event(self): if not KEYRING_AVAILABLE: self._ui.keyring_hint.show()
- if self.event.name == 'client-cert-passphrase': + if self._event.name == 'client-cert-passphrase': self._ui.header.set_text(_('Certificate Password Required')) self._ui.message_label.set_text( _('Please enter your certificate password for ' @@ -82,32 +83,32 @@ def _process_event(self): 'jid': own_jid, 'account': account_name})
- def _on_ok(self, _button): + def _on_ok(self, _button: Gtk.Button) -> None: password = self._ui.pass_entry.get_text()
- if self.event.name == 'password-required': + if self._event.name == 'password-required': app.settings.set_account_setting( self.account, 'savepass', self._ui.save_pass_checkbutton.get_active()) save_password(self.account, password) - self.event.on_password(password) + self._event.on_password(password) self.destroy()
- if self.event.name == 'client-cert-passphrase': - self.event.conn.on_client_cert_passphrase( + if self._event.name == 'client-cert-passphrase': + self._event.conn.on_client_cert_passphrase( password, - self.event.con, - self.event.port, - self.event.secure_tuple) + self._event.con, + self._event.port, + self._event.secure_tuple) self.destroy()
- def _on_cancel(self, _button): - if self.event.name == 'client-cert-passphrase': - self.event.conn.on_client_cert_passphrase( + def _on_cancel(self, _button: Gtk.Button) -> None: + if self._event.name == 'client-cert-passphrase': + self._event.conn.on_client_cert_passphrase( '', - self.event.con, - self.event.port, - self.event.secure_tuple) + self._event.con, + self._event.port, + self._event.secure_tuple)
self.destroy()
===================================== gajim/gtk/preferences.py ===================================== @@ -12,6 +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 Optional +from typing import cast + import logging import sys
@@ -49,7 +54,7 @@
class Preferences(Gtk.ApplicationWindow): - def __init__(self): + def __init__(self) -> None: Gtk.ApplicationWindow.__init__(self) self.set_application(app.app) self.set_position(Gtk.WindowPosition.CENTER) @@ -61,7 +66,7 @@ def __init__(self):
self._ui = get_builder('preferences.ui')
- self._video_preview = None + self._video_preview: Optional[VideoPreview] = None self._prefs = {}
side_bar_switcher = SideBarSwitcher() @@ -116,44 +121,46 @@ def _add_prefs(self, prefs): pref_box.add(pref) self._prefs[ui_name] = pref
- def _add_video_preview(self): + def _add_video_preview(self) -> None: if sys.platform == 'win32': return self._video_preview = VideoPreview() self._ui.video.add(self._video_preview.widget)
- def _on_key_press(self, _widget, event): + def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None: if event.keyval == Gdk.KEY_Escape: self.destroy()
- def get_video_preview(self): + def get_video_preview(self) -> Optional[VideoPreview]: return self._video_preview
@staticmethod - def _on_features_clicked(_widget, _response): + def _on_features_clicked(_widget: Gtk.InfoBar, + _response: Gtk.ResponseType + ) -> None: open_window('Features')
- def update_theme_list(self): + def update_theme_list(self) -> None: self._prefs['themes'].update_theme_list()
- def update_proxy_list(self): + def update_proxy_list(self) -> None: self._prefs['miscellaneous'].update_proxy_list()
@staticmethod - def _check_emoji_theme(): + def _check_emoji_theme() -> None: # Ensure selected emoji theme is valid emoji_themes = helpers.get_available_emoticon_themes() settings_theme = app.settings.get('emoticons_theme') if settings_theme not in emoji_themes: app.settings.set('emoticons_theme', 'font')
- def _on_destroy(self, _widget): + def _on_destroy(self, _widget: Gtk.Widget) -> None: self._prefs.clear() app.check_finalize(self)
class PreferenceBox(SettingsBox): - def __init__(self, settings): + def __init__(self, settings: list[Setting]) -> None: SettingsBox.__init__(self, None) self.get_style_context().add_class('settings-border') self.set_selection_mode(Gtk.SelectionMode.NONE) @@ -166,7 +173,7 @@ def __init__(self, settings):
class WindowBehaviour(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
main_window_on_startup_items = { 'always': _('Always'), @@ -193,7 +200,7 @@ def __init__(self, *args):
class Chats(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
speller_desc = None if not app.is_installed('GSPELL'): @@ -243,11 +250,11 @@ def __init__(self, *args): PreferenceBox.__init__(self, settings)
@staticmethod - def _speller_available(): + def _speller_available() -> bool: return app.is_installed('GSPELL')
@staticmethod - def _on_use_speller(value, *args): + def _on_use_speller(value: bool, *args: Any) -> None: if not value: return
@@ -261,7 +268,7 @@ def _on_use_speller(value, *args):
class GroupChats(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
settings = [ Setting(SettingKind.POPOVER, @@ -320,30 +327,30 @@ def __init__(self, *args): PreferenceBox.__init__(self, settings)
@staticmethod - def _on_sort_by_show_in_muc(*args): + def _on_sort_by_show_in_muc(_value: bool, *args: Any) -> None: for ctrl in app.window.get_controls(): if ctrl.is_groupchat: ctrl.roster.invalidate_sort()
@staticmethod - def _on_show_status_in_roster(*args): + def _on_show_status_in_roster(_value: bool, *args: Any) -> None: for ctrl in app.window.get_controls(): if ctrl.is_groupchat: ctrl.roster.draw_contacts()
@staticmethod - def _reset_join_left(button): + def _reset_join_left(button: Gtk.Button) -> None: button.set_sensitive(False) app.settings.set_group_chat_settings('print_join_left', None)
@staticmethod - def _reset_print_status(button): + def _reset_print_status(button: Gtk.Button) -> None: button.set_sensitive(False) app.settings.set_group_chat_settings('print_status', None)
class FilePreview(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None: sizes = { 262144: '256 KiB', 524288: '512 KiB', @@ -407,7 +414,7 @@ def __init__(self, *args):
class VisualNotifications(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None: trayicon_items = { 'never': _('Hide icon'), 'on_event': _('Only show for pending events'), @@ -431,7 +438,7 @@ def __init__(self, *args): PreferenceBox.__init__(self, settings)
@staticmethod - def _on_trayicon(value, *args): + def _on_trayicon(value: str, *args: Any) -> None: if value == 'never': app.interface.hide_systray() elif value == 'on_event': @@ -441,7 +448,7 @@ def _on_trayicon(value, *args):
class NotificationsDialog(SettingsDialog): - def __init__(self, account, parent): + def __init__(self, account: str, parent: Preferences) -> None:
settings = [ Setting(SettingKind.SWITCH, @@ -463,7 +470,7 @@ def __init__(self, account, parent):
class Sounds(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
settings = [ Setting(SettingKind.SWITCH, @@ -484,12 +491,12 @@ def __init__(self, *args):
PreferenceBox.__init__(self, settings)
- def _on_manage_sounds(self, *args): + def _on_manage_sounds(self, _button: Gtk.Button) -> None: open_window('ManageSounds', transient_for=self.get_toplevel())
class StatusMessage(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
settings = [ Setting(SettingKind.SWITCH, @@ -512,7 +519,7 @@ def __init__(self, *args):
class AutomaticStatus(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
settings = [ Setting(SettingKind.AUTO_AWAY, @@ -534,16 +541,16 @@ def __init__(self, *args): PreferenceBox.__init__(self, settings)
@staticmethod - def _get_auto_away(): + def _get_auto_away() -> bool: return app.settings.get('autoaway')
@staticmethod - def _get_auto_xa(): + def _get_auto_xa() -> bool: return app.settings.get('autoxa')
class AutoAwayDialog(SettingsDialog): - def __init__(self, account, parent): + def __init__(self, account: str, parent: Preferences) -> None:
settings = [ Setting(SettingKind.SWITCH, @@ -571,7 +578,7 @@ def __init__(self, account, parent):
class AutoExtendedAwayDialog(SettingsDialog): - def __init__(self, account, parent): + def __init__(self, account: str, parent: Preferences) -> None:
settings = [ Setting(SettingKind.SWITCH, @@ -599,7 +606,7 @@ def __init__(self, account, parent):
class Themes(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
theme_items = self._get_theme_items()
@@ -631,37 +638,37 @@ def __init__(self, *args): PreferenceBox.__init__(self, settings)
@staticmethod - def _get_theme_items(): + def _get_theme_items() -> list[str]: theme_items = ['default'] for settings_theme in app.css_config.themes: theme_items.append(settings_theme) return theme_items
- def update_theme_list(self): + def update_theme_list(self) -> None: self.get_setting('roster_theme').update_entries(self._get_theme_items())
- def _on_edit_themes(self, *args): + def _on_edit_themes(self, _button: Gtk.Button) -> None: open_window('Themes', transient=self.get_toplevel())
@staticmethod - def _on_theme_changed(value, *args): + def _on_theme_changed(value: str, *args: Any) -> None: app.css_config.change_theme(value) app.ged.raise_event(ThemeUpdate()) app.ged.raise_event(StyleChanged())
@staticmethod - def _on_dark_theme(value, *args): + def _on_dark_theme(value: str, *args: Any) -> None: app.css_config.set_dark_theme(int(value)) app.ged.raise_event(StyleChanged())
class Emoji(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None: if sys.platform not in ('win32', 'darwin'): PreferenceBox.__init__(self, []) return
- emoji_themes_items = [] + emoji_themes_items: list[str] = [] for theme in helpers.get_available_emoticon_themes(): emoji_themes_items.append(theme)
@@ -677,18 +684,18 @@ def __init__(self, *args):
PreferenceBox.__init__(self, settings)
- def _on_emoticons_theme(self, *args): + def _on_emoticons_theme(self, *args: Any) -> None: emoji_chooser.load() self._toggle_emoticons()
@staticmethod - def _toggle_emoticons(): + def _toggle_emoticons() -> None: for ctrl in app.window.get_controls(): ctrl.toggle_emoticons()
class Server(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
settings = [
@@ -705,7 +712,7 @@ def __init__(self, *args):
class StunServerDialog(SettingsDialog): - def __init__(self, account, parent): + def __init__(self, account: str, parent: Preferences) -> None:
settings = [ Setting(SettingKind.SWITCH, @@ -725,7 +732,7 @@ def __init__(self, account, parent):
class Audio(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
deps_installed = app.is_installed('AV')
@@ -760,18 +767,18 @@ def __init__(self, *args): self.set_sensitive(deps_installed)
@staticmethod - def _create_av_combo_items(items_dict): + def _create_av_combo_items(items_dict: dict[str, str]) -> dict[str, str]: items = enumerate(sorted( items_dict.items(), key=lambda x: '' if x[1].startswith('auto') else x[0].lower())) - combo_items = {} + combo_items: dict[str, str] = {} for _index, (name, value) in items: combo_items[value] = name return combo_items
class Video(PreferenceBox): - def __init__(self, *args): + def __init__(self, *args: Any) -> None:
deps_installed = app.is_installed('AV')
@@ -836,31 +843,33 @@ def __init__(self, *args): self.set_sensitive(deps_installed)
@staticmethod - def _on_video_input_changed(_value, *args): - preview = get_app_window('Preferences').get_video_preview() + def _on_video_input_changed(_value: str, *args: Any) -> None: + pref_win = cast(Preferences, get_app_window('Preferences')) + preview = pref_win.get_video_preview() if preview is None or not preview.is_active: # changed signal gets triggered when we fill the combobox return preview.refresh()
@staticmethod - def _toggle_live_preview(value, *args): - preview = get_app_window('Preferences').get_video_preview() + def _toggle_live_preview(value: bool, *args: Any) -> None: + pref_win = cast(Preferences, get_app_window('Preferences')) + preview = pref_win.get_video_preview() preview.toggle_preview(value)
@staticmethod - def _create_av_combo_items(items_dict): + def _create_av_combo_items(items_dict: dict[str, str]) -> dict[str, str]: items = enumerate(sorted( items_dict.items(), key=lambda x: '' if x[1].startswith('auto') else x[0].lower())) - combo_items = {} + combo_items: dict[str, str] = {} for _index, (name, value) in items: combo_items[value] = name return combo_items
class Miscellaneous(PreferenceBox): - def __init__(self, pref_window): + def __init__(self, pref_window: Preferences) -> None: self._hints_list = [ 'start_chat', ] @@ -898,30 +907,30 @@ def __init__(self, pref_window): reset_button.set_sensitive(self._check_hints_reset)
@staticmethod - def _get_proxies(): + def _get_proxies() -> dict[str, str]: return {proxy: proxy for proxy in app.settings.get_proxies()}
@staticmethod - def _on_proxy_edit(*args): + def _on_proxy_edit(*args: Any) -> None: open_window('ManageProxies')
- def update_proxy_list(self): + def update_proxy_list(self) -> None: self.get_setting('global_proxy').update_entries(self._get_proxies())
- def _check_hints_reset(self): + def _check_hints_reset(self) -> bool: for hint in self._hints_list: - if app.settings.get('show_help_%s' % hint) is False: + if app.settings.get(f'show_help_{hint}') is False: return True return False
- def _on_reset_hints(self, button): + def _on_reset_hints(self, button: Gtk.Button) -> None: for hint in self._hints_list: - app.settings.set('show_help_%s' % hint, True) + app.settings.set(f'show_help_{hint}', True) button.set_sensitive(False)
class Advanced(PreferenceBox): - def __init__(self, pref_window): + def __init__(self, pref_window: Preferences) -> None:
settings = [ Setting(SettingKind.SWITCH, @@ -939,13 +948,13 @@ def __init__(self, pref_window): 'clicked', self._on_advanced_config_editor)
@staticmethod - def _on_debug_logging(value, *args): + def _on_debug_logging(value: bool, *args: Any) -> None: app.set_debug_mode(value)
@staticmethod - def _on_open_debug_logs(*args): + def _on_open_debug_logs(*args: Any) -> None: open_file(configpaths.get('DEBUG'))
@staticmethod - def _on_advanced_config_editor(*args): + def _on_advanced_config_editor(*args: Any) -> None: open_window('AdvancedConfig')
===================================== gajim/gtk/ssl_error_dialog.py ===================================== @@ -74,16 +74,18 @@ def _process_error(self) -> None: self._ui.connect_button.set_no_show_all(True) self._ui.connect_button.hide()
- def _on_view_cert_clicked(self, _button): + def _on_view_cert_clicked(self, _button: Gtk.Button) -> None: open_window('CertificateDialog', account=self.account, transient_for=self, cert=self._cert)
- def _on_add_certificate_toggled(self, checkbutton): + def _on_add_certificate_toggled(self, + checkbutton: Gtk.CheckButton + ) -> None: self._ui.connect_button.set_sensitive(checkbutton.get_active())
- def _on_connect_clicked(self, _button): + def _on_connect_clicked(self, _button: Gtk.Button) -> None: if self._ui.add_certificate_checkbutton.get_active(): app.cert_store.add_certificate(self._cert)
===================================== gajim/gtk/themes.py ===================================== @@ -16,8 +16,10 @@
from __future__ import annotations from typing import NamedTuple +from typing import Optional from typing import Any from typing import Union +from typing import cast
from enum import IntEnum
@@ -35,6 +37,7 @@ from .dialogs import DialogButton from .dialogs import ConfirmationDialog from .builder import get_builder +from .preferences import Preferences from .util import get_app_window
@@ -239,7 +242,7 @@ def _load_options(self) -> None: row = Option(option, value) self._ui.option_listbox.add(row)
- def _add_option(self, _listbox: Gtk.ListBox, row: Gtk.ListBoxRow) -> None: + def _add_option(self, _listbox: Gtk.ListBox, row: Option) -> None: # Add theme if there is none store, _ = self._ui.theme_treeview.get_selection().get_selected() first = store.get_iter_first() @@ -298,7 +301,7 @@ def _apply_theme(theme: str) -> None:
@staticmethod def _update_preferences_window() -> None: - window = get_app_window('Preferences') + window = cast(Optional[Preferences], get_app_window('Preferences')) if window is not None: window.update_theme_list()
===================================== gajim/gui_interface.py ===================================== @@ -76,6 +76,7 @@ from gajim.common.events import FileProgress from gajim.common.events import FileError from gajim.common.events import MucAdded +from gajim.common.events import PasswordRequired from gajim.common.zeroconf import connection_zeroconf from gajim.common.helpers import ask_for_status_message from gajim.common.structs import OutgoingMessage @@ -291,7 +292,7 @@ def handle_event_client_cert_passphrase(event): open_window('PasswordDialog', account=event.conn.name, event=event)
@staticmethod - def handle_event_password_required(event): + def handle_event_password_required(event: PasswordRequired) -> None: open_window('PasswordDialog', account=event.conn.name, event=event)
@staticmethod
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/c2feb0ef168698be519a6a711fe37dca...