gajim.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2026
October
September
August
July
June
May
April
March
February
January
2025
December
November
October
September
August
July
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
List overview
Download
Commits
----- 2026 -----
October 2026
September 2026
August 2026
July 2026
June 2026
May 2026
April 2026
March 2026
February 2026
January 2026
----- 2025 -----
December 2025
November 2025
October 2025
September 2025
August 2025
July 2025
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
commits@gajim.org
17632 discussions
Start a n
N
ew thread
[Git][gajim/gajim][master] 8 commits: Exceptions: Remove unused exceptions
by Philipp Hörist (ï¼ lovetox)
27 Dec '21
27 Dec '21
Philipp Hörist pushed to branch master at gajim / gajim Commits: 72d8c294 by lovetox at 2021-12-27T17:54:17+01:00 Exceptions: Remove unused exceptions - - - - - 86fb7962 by lovetox at 2021-12-27T19:02:42+01:00 Typing: Add AppKit stubs - - - - - 5454a2d5 by lovetox at 2021-12-27T19:05:24+01:00 i18n: Refactor - Make dedicated functions for getting the default langauge for every platform - Don’t assume get_default_lang() can fail - Add type annotations - - - - - 2a6181d1 by lovetox at 2021-12-27T19:14:40+01:00 Regex: Add type annotations - - - - - 1acccaad by lovetox at 2021-12-27T19:14:58+01:00 EmojiData: Add type annotations - - - - - 6e8a16ca by lovetox at 2021-12-27T20:15:05+01:00 Typing: Add keyring stubs - - - - - 6c1ec6bd by lovetox at 2021-12-27T20:15:40+01:00 Passwords: Add type annotations - - - - - c903a813 by lovetox at 2021-12-27T20:15:50+01:00 Update pyrightconfig.json - - - - - 11 changed files: - gajim/common/exceptions.py - gajim/common/i18n.py - gajim/common/passwords.py - gajim/common/regex.py - gajim/gtk/emoji_data.pyi - pyrightconfig.json - + typings/AppKit/__init__.py - + typings/keyring/__init__.pyi - + typings/keyring/backend.pyi - + typings/keyring/core.pyi - + typings/keyring/errors.pyi Changes: ===================================== gajim/common/exceptions.py ===================================== @@ -20,33 +20,6 @@ from gajim.common.i18n import _ -class PysqliteOperationalError(Exception): - """ - Sqlite2 raised pysqlite2.dbapi2.OperationalError - """ - - def __init__(self, text=''): - Exception.__init__(self) - self.text = text - - def __str__(self): - return self.text - -class DatabaseMalformed(Exception): - """ - The database can't be read - """ - - def __init__(self, path=''): - Exception.__init__(self) - self.path = path - - def __str__(self): - return _('The database file (%s) cannot be read. ' - 'Try to repair it (see ' - '
https://dev.gajim.org/gajim/gajim/wikis/help/DatabaseBackup
)' - ' or remove it (all history will be lost).') % self.path - class ServiceNotAvailable(Exception): """ This exception is raised when we cannot use Gajim remotely' @@ -58,16 +31,6 @@ def __init__(self): def __str__(self): return _('Service not available: Gajim is not running, or remote_control is False') -class DbusNotSupported(Exception): - """ - D-Bus is not installed or python bindings are missing - """ - - def __init__(self): - Exception.__init__(self) - - def __str__(self): - return _('D-Bus is not present on this machine or python module is missing') class SessionBusNotPresent(Exception): """ @@ -81,39 +44,6 @@ def __str__(self): return _('Session bus is not available.\nTry reading %(url)s') % \ {'url': '
https://dev.gajim.org/gajim/gajim/wikis/help/GajimDBus
'} -class SystemBusNotPresent(Exception): - """ - This exception indicates that there is no session daemon - """ - - def __init__(self): - Exception.__init__(self) - - def __str__(self): - return _('System bus is not available.\nTry reading %(url)s') % \ - {'url': '
https://dev.gajim.org/gajim/gajim/wikis/help/GajimDBus
'} - -class NegotiationError(Exception): - """ - A session negotiation failed - """ - -class Cancelled(Exception): - """ - The user cancelled an operation - """ - -class LatexError(Exception): - """ - LaTeX processing failed for some reason - """ - - def __init__(self, text=''): - Exception.__init__(self) - self.text = text - - def __str__(self): - return self.text class GajimGeneralException(Exception): """ @@ -127,6 +57,7 @@ def __init__(self, text=''): def __str__(self): return self.text + class PluginsystemError(Exception): """ Error in the pluginsystem @@ -139,19 +70,6 @@ def __init__(self, text=''): def __str__(self): return self.text -class StanzaMalformed(Exception): - """ - Malfromed Stanza - """ - def __init__(self, message, stanza=''): - Exception.__init__(self, message, stanza) - self._msg = '{}\n{}'.format(message, stanza) - def __str__(self): - return self._msg - -class SendMessageError(Exception): - pass - class FileError(Exception): pass ===================================== gajim/common/i18n.py ===================================== @@ -18,6 +18,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 Iterator +from typing import Optional + import os import sys import locale @@ -27,13 +32,12 @@ from gi.repository import GLib DOMAIN = 'gajim' -LANG = 'en' direction_mark = '\u200E' _translation = gettext.NullTranslations() -def get_locale_dirs(): - if os.name == 'nt': +def get_locale_dirs() -> Optional[list[Path]]: + if sys.platform == 'win32': return path = gettext.find(DOMAIN) @@ -50,7 +54,7 @@ def get_locale_dirs(): return [Path(dir_) for dir_ in data_dirs] -def iter_locale_dirs(): +def iter_locale_dirs() -> Iterator[Optional[str]]: locale_dirs = get_locale_dirs() if locale_dirs is None: yield None @@ -59,7 +63,7 @@ def iter_locale_dirs(): # gettext fallback locale_dirs.append(Path(sys.base_prefix) / 'share') - found_paths = [] + found_paths: list[Path] = [] for path in locale_dirs: locale_dir = path / 'locale' if locale_dir in found_paths: @@ -69,34 +73,42 @@ def iter_locale_dirs(): yield str(locale_dir) -def get_default_lang(): - if os.name == "nt": - import ctypes - windll = ctypes.windll.kernel32 - return locale.windows_locale[windll.GetUserDefaultUILanguage()] +def get_win32_default_lang() -> str: + import ctypes + windll = ctypes.windll.kernel32 + return locale.windows_locale[windll.GetUserDefaultUILanguage()] + + +def get_darwin_default_lang() -> str: + from AppKit import NSLocale + # FIXME: This returns a two letter language code (en, de, fr) + # We need a way to get en_US, de_DE etc. + return NSLocale.currentLocale().languageCode() + + +def get_default_lang() -> str: + if sys.platform == "win32": + return get_win32_default_lang() if sys.platform == "darwin": - from AppKit import NSLocale - # FIXME: This returns a two letter language code (en, de, fr) - # We need a way to get en_US, de_DE etc. - return NSLocale.currentLocale().languageCode() + return get_darwin_default_lang() return locale.getdefaultlocale()[0] or 'en' -def get_rfc5646_lang(lang=None): +def get_rfc5646_lang(lang: Optional[str] = None) -> str: if lang is None: lang = LANG return lang.replace('_', '-') -def get_short_lang_code(lang=None): +def get_short_lang_code(lang: Optional[str] = None) -> str: if lang is None: lang = LANG return lang[:2] -def initialize_direction_mark(): +def initialize_direction_mark() -> None: from gi.repository import Gtk global direction_mark @@ -105,7 +117,7 @@ def initialize_direction_mark(): direction_mark = '\u200F' -def paragraph_direction_mark(text): +def paragraph_direction_mark(text: str) -> str: """ Determine paragraph writing direction according to
http://www.unicode.org/reports/tr9/#The_Paragraph_Level
@@ -122,7 +134,7 @@ def paragraph_direction_mark(text): return '\u200E' -def Q_(text): +def Q_(text: str) -> str: """ Translate the given text, optionally qualified with a special construction, which will help translators to disambiguate between @@ -143,7 +155,11 @@ def Q_(text): return text -def ngettext(s_sing, s_plural, n, replace_sing=None, replace_plural=None): +def ngettext(s_sing: str, + s_plural: str, + n: int, + replace_sing: Optional[str] = None, + replace_plural: Optional[str] = None) -> str: """ Use as: i18n.ngettext( @@ -164,18 +180,13 @@ def ngettext(s_sing, s_plural, n, replace_sing=None, replace_plural=None): except locale.Error as error: print(error, file=sys.stderr) -try: - LANG = get_default_lang() - if os.name == 'nt': - # Set the env var on Windows because gettext.find() uses it to - # find the translation - # Use LANGUAGE instead of LANG, LANG sets LC_ALL and thus - # doesn't retain other region settings like LC_TIME - os.environ['LANGUAGE'] = LANG -except Exception as error: - print('Failed to determine default language', file=sys.stderr) - import traceback - traceback.print_exc() +LANG = get_default_lang() +if sys.platform == 'win32': + # Set the env var on Windows because gettext.find() uses it to + # find the translation + # Use LANGUAGE instead of LANG, LANG sets LC_ALL and thus + # doesn't retain other region settings like LC_TIME + os.environ['LANGUAGE'] = LANG # Search for the translation in all locale dirs for dir_ in iter_locale_dirs(): ===================================== gajim/common/passwords.py ===================================== @@ -20,16 +20,24 @@ # 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 Optional + import logging + import keyring from gajim.common import app -__all__ = ['get_password', 'save_password'] +__all__ = [ + 'get_password', + 'save_password', + 'delete_password' +] log = logging.getLogger('gajim.password') - backends = keyring.backend.get_all_keyring() for backend in backends: log.info('Found keyring backend: %s', backend) @@ -46,7 +54,7 @@ class SecretPasswordStorage: """ @staticmethod - def save_password(account_name, password): + def save_password(account_name: str, password: str) -> bool: if not KEYRING_AVAILABLE: log.warning('No recommended keyring backend available.' 'Passwords cannot be stored.') @@ -60,7 +68,7 @@ def save_password(account_name, password): return False @staticmethod - def get_password(account_name): + def get_password(account_name: str) -> Optional[str]: log.info('Request password from keyring') if not KEYRING_AVAILABLE: return @@ -73,10 +81,11 @@ def get_password(account_name): return @staticmethod - def delete_password(account_name): + def delete_password(account_name: str) -> None: log.info('Remove password from keyring') if not KEYRING_AVAILABLE: return + try: return keyring_backend.delete_password('gajim', account_name) except keyring.errors.PasswordDeleteError as error: @@ -91,27 +100,26 @@ class ConfigPasswordStorage: """ @staticmethod - def get_password(account_name): + def get_password(account_name: str) -> str: return app.settings.get_account_setting(account_name, 'password') @staticmethod - def save_password(account_name, password): + def save_password(account_name: str, password: str) -> bool: app.settings.set_account_setting(account_name, 'password', password) return True @staticmethod - def delete_password(account_name): + def delete_password(account_name: str) -> None: app.settings.set_account_setting(account_name, 'password', '') - return True -def get_password(account_name): +def get_password(account_name: str) -> Optional[str]: if app.settings.get('use_keyring'): return SecretPasswordStorage.get_password(account_name) return ConfigPasswordStorage.get_password(account_name) -def save_password(account_name, password): +def save_password(account_name: str, password: str) -> bool: if account_name in app.connections: app.connections[account_name].password = password @@ -123,7 +131,7 @@ def save_password(account_name, password): return ConfigPasswordStorage.save_password(account_name, password) -def delete_password(account_name): +def delete_password(account_name: str) -> None: if account_name in app.connections: app.connections[account_name].password = None ===================================== gajim/common/regex.py ===================================== @@ -54,7 +54,7 @@ def _get_basic_pattern(): r'(?<!\w)' r'_[^\s_]' r'([^_]*[^\s_])?' r'_(?!\w)' return basic_pattern + formatting -def _get_emot_and_basic_pattern(use_ascii_formatting=True): +def _get_emot_and_basic_pattern(use_ascii_formatting: bool = True) -> str: from gajim.gui.emoji_data import emoji_data # because emoticons match later (in the string) they need to be after # basic matches that may occur earlier ===================================== gajim/gtk/emoji_data.pyi ===================================== @@ -24,7 +24,7 @@ def is_emoji(codepoints: str) -> bool: ... def get_emoji_pixbuf(codepoints: str) -> GdkPixbuf.Pixbuf: ... class EmojiData(OrderedDict): - ... + def get_regex(self) -> str: ... class EmojiPixbufs(dict): ... ===================================== pyrightconfig.json ===================================== @@ -14,6 +14,12 @@ "typeCheckingMode": "strict", "include": [ "gajim/common/cert_store.py", + "gajim/common/ged.py", + "gajim/common/i18n.py", + "gajim/common/nec.py", + "gajim/common/passwords.py", + "gajim/common/regex.py", + "gajim/common/sound.py", "gajim/gtk/app_side_bar.py", "gajim/gtk/chat_filter.py", "gajim/gtk/chat_page.py", ===================================== typings/AppKit/__init__.py ===================================== @@ -0,0 +1,16 @@ + +from __future__ import annotations + +from typing import Any + + +class NSLocale: + @classmethod + def currentLocale(cls) -> Any: ... + + +class NSSound: + @classmethod + def alloc(cls) -> NSSound: ... + def initWithContentsOfFile_byReference_(self, url: str, byref: bool) -> None: ... + def play(self) -> None: ... ===================================== typings/keyring/__init__.pyi ===================================== @@ -0,0 +1,7 @@ + + +from . import backend as backend +from . import core as core +from . import errors as errors +from .core import get_keyring as get_keyring + ===================================== typings/keyring/backend.pyi ===================================== @@ -0,0 +1,13 @@ + + +from typing import Optional + + +class KeyringBackend: + + def get_password(self, service: str, username: str) -> Optional[str]: ... + def set_password(self, service: str, username: str, password: str) -> None: ... + def delete_password(self, service: str, username: str) -> None: ... + + +def get_all_keyring() -> list[KeyringBackend]: ... ===================================== typings/keyring/core.pyi ===================================== @@ -0,0 +1,11 @@ + +from typing import Optional + +from keyring.backend import KeyringBackend + + +def get_password(service_name: str, username: str) -> Optional[str]: ... +def set_password(service_name: str, username: str, password: str) -> None: ... +def delete_password(service_name: str, username: str) -> None: ... +def recommended(backend: KeyringBackend) -> bool: ... +def get_keyring() -> KeyringBackend: ... ===================================== typings/keyring/errors.pyi ===================================== @@ -0,0 +1,8 @@ + + +class KeyringError(Exception): ... +class PasswordSetError(KeyringError): ... +class PasswordDeleteError(KeyringError): ... +class InitError(KeyringError): ... +class KeyringLocked(KeyringError): ... +class NoKeyringError(KeyringError): ... View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/92023bb14bde8bed9867409331acade…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/92023bb14bde8bed9867409331acade…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Settings: Remove unused import
by Philipp Hörist (ï¼ lovetox)
27 Dec '21
27 Dec '21
Philipp Hörist pushed to branch master at gajim / gajim Commits: 92023bb1 by lovetox at 2021-12-27T17:38:23+01:00 Settings: Remove unused import - Sort imports - - - - - 1 changed file: - gajim/common/settings.py Changes: ===================================== gajim/common/settings.py ===================================== @@ -40,7 +40,11 @@ from gajim.common.helpers import get_muc_context from gajim.common.storage.base import Encoder from gajim.common.storage.base import json_decoder -from gajim.common.setting_values import APP_SETTINGS, AllWorkspaceSettings, AllWorkspaceSettingsT, ListWorkspaceSettings, OpenChatSettingT, StringWorkspaceSettings +from gajim.common.setting_values import APP_SETTINGS +from gajim.common.setting_values import AllWorkspaceSettings +from gajim.common.setting_values import AllWorkspaceSettingsT +from gajim.common.setting_values import OpenChatSettingT +from gajim.common.setting_values import StringWorkspaceSettings from gajim.common.setting_values import ACCOUNT_SETTINGS from gajim.common.setting_values import PROXY_SETTINGS from gajim.common.setting_values import PROXY_EXAMPLES View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/92023bb14bde8bed9867409331acade1…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/92023bb14bde8bed9867409331acade1…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 6 commits: MamPreferences: Add type annotations
by Philipp Hörist (ï¼ lovetox)
27 Dec '21
27 Dec '21
Philipp Hörist pushed to branch master at gajim / gajim Commits: 11873804 by lovetox at 2021-12-27T16:27:33+01:00 MamPreferences: Add type annotations - - - - - a2f922db by lovetox at 2021-12-27T16:27:33+01:00 Settings: Add type annotations - - - - - ce788ace by lovetox at 2021-12-27T16:27:33+01:00 ChatListStack: Add type annotations - - - - - eb475ff7 by lovetox at 2021-12-27T16:27:33+01:00 ChatPage: Add type annotations - - - - - 5e841923 by lovetox at 2021-12-27T16:27:33+01:00 ChatStack: Add type annotations - - - - - 24591d79 by lovetox at 2021-12-27T16:27:33+01:00 Update pyrightconfig.json - - - - - 7 changed files: - gajim/common/setting_values.py - gajim/common/settings.py - gajim/gtk/chat_list_stack.py - gajim/gtk/chat_page.py - gajim/gtk/chat_stack.py - gajim/gtk/mam_preferences.py - pyrightconfig.json Changes: ===================================== gajim/common/setting_values.py ===================================== @@ -1,9 +1,12 @@ from typing import Literal +from typing import TypedDict from typing import Union import uuid +from nbxmpp.protocol import JID + from gajim.common.i18n import _ class _DEFAULT: @@ -447,8 +450,25 @@ class _ACCOUNT_DEFAULT: }, } +StringWorkspaceSettings = Literal[ + 'name', + 'color', + 'avatar_sha' +] + +AllWorkspaceSettings = Literal[StringWorkspaceSettings, 'open_chats'] + +OpenChatSettingT = list[tuple[str, JID, str, bool]] +AllWorkspaceSettingsT = Union[str, OpenChatSettingT] + +class WorkspaceSettings(TypedDict): + name: str + color: str + avatar_sha: str + open_chats: OpenChatSettingT + -WORKSPACE_SETTINGS = { +WORKSPACE_SETTINGS: WorkspaceSettings = { 'name': _('My Workspace'), 'color': '', 'avatar_sha': '', ===================================== gajim/common/settings.py ===================================== @@ -12,7 +12,7 @@ # 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 Any +from typing import Any, Literal from typing import Optional from typing import Dict from typing import List @@ -40,7 +40,7 @@ from gajim.common.helpers import get_muc_context from gajim.common.storage.base import Encoder from gajim.common.storage.base import json_decoder -from gajim.common.setting_values import APP_SETTINGS +from gajim.common.setting_values import APP_SETTINGS, AllWorkspaceSettings, AllWorkspaceSettingsT, ListWorkspaceSettings, OpenChatSettingT, StringWorkspaceSettings from gajim.common.setting_values import ACCOUNT_SETTINGS from gajim.common.setting_values import PROXY_SETTINGS from gajim.common.setting_values import PROXY_EXAMPLES @@ -981,10 +981,21 @@ def remove_proxy(self, proxy_name: str) -> None: if self.get_account_setting(account, 'proxy') == proxy_name: self.set_account_setting(account, 'proxy', None) + @overload + def set_workspace_setting(self, + workspace_id: str, + setting: StringWorkspaceSettings, + value: str) -> None: ... + @overload + def set_workspace_setting(self, + workspace_id: str, + setting: Literal['open_chats'], + value: list[tuple[str, JID, str, bool]] + ) -> None: ... def set_workspace_setting(self, workspace_id: str, - setting: str, - value: SETTING_TYPE) -> None: + setting: AllWorkspaceSettings, + value: AllWorkspaceSettingsT) -> None: if setting not in WORKSPACE_SETTINGS: raise ValueError(f'Invalid workspace setting: {setting}') @@ -1000,9 +1011,19 @@ def set_workspace_setting(self, self._settings['workspaces'][workspace_id][setting] = value self._commit_settings('workspaces') + @overload + def get_workspace_setting(self, + workspace_id: str, + setting: Literal['open_chats'] + ) -> OpenChatSettingT: ... + @overload + def get_workspace_setting(self, + workspace_id: str, + setting: StringWorkspaceSettings) -> str: ... def get_workspace_setting(self, workspace_id: str, - setting: str) -> SETTING_TYPE: + setting: AllWorkspaceSettings + ) -> AllWorkspaceSettingsT: if setting not in WORKSPACE_SETTINGS: raise ValueError(f'Invalid workspace setting: {setting}') ===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -23,6 +23,7 @@ from nbxmpp import JID from gajim.common import app +from gajim.common.nec import NetworkEvent from .chat_filter import ChatFilter from .chat_list import ChatList @@ -287,7 +288,7 @@ def mark_as_read(self, account: str, jid: JID) -> None: for chat_list in self._chat_lists.values(): chat_list.mark_as_read(account, jid) - def process_event(self, event): + def process_event(self, event: NetworkEvent) -> None: if event.name not in HANDLED_EVENTS: return ===================================== gajim/gtk/chat_page.py ===================================== @@ -29,6 +29,7 @@ from nbxmpp import JID from gajim.common import app +from gajim.common.nec import NetworkEvent from .builder import get_builder from .chat_filter import ChatFilter @@ -215,12 +216,13 @@ def _on_chat_list_changed(self, *args: Any) -> None: chat_list = chat_list_stack.get_current_chat_list() + assert chat_list is not None name = app.settings.get_workspace_setting(chat_list.workspace_id, 'name') self._ui.workspace_label.set_text(name) self._ui.search_entry.set_text('') - def process_event(self, event): + def process_event(self, event: NetworkEvent): self._chat_stack.process_event(event) self._chat_list_stack.process_event(event) ===================================== gajim/gtk/chat_stack.py ===================================== @@ -27,6 +27,7 @@ from gajim.common import app from gajim.common import ged from gajim.common.i18n import _ +from gajim.common.nec import NetworkEvent from .controls.chat import ChatControl from .controls.groupchat import GroupchatControl @@ -112,7 +113,7 @@ def show_chat(self, account: str, jid: JID) -> None: GLib.idle_add(control.focus) - def is_chat_loaded(self, account, jid) -> bool: + def is_chat_loaded(self, account: str, jid: JID) -> bool: control = self.get_control(account, jid) if control is None: return False @@ -127,7 +128,7 @@ def unload_chat(self, account: str, jid: JID) -> None: def clear(self) -> None: self.set_visible_child_name('empty') - def process_event(self, event): + def process_event(self, event: NetworkEvent) -> None: control = self.get_control(event.account, event.jid) control.process_event(event) ===================================== gajim/gtk/mam_preferences.py ===================================== @@ -12,6 +12,8 @@ # 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 + import logging from gi.repository import Gtk @@ -19,6 +21,7 @@ from nbxmpp.errors import MalformedStanzaError from nbxmpp.errors import StanzaError +from nbxmpp.task import Task from gajim.common import app from gajim.common.i18n import _ @@ -33,7 +36,7 @@ class MamPreferences(Gtk.ApplicationWindow, EventHelper): - def __init__(self, account): + def __init__(self, account: str) -> None: Gtk.ApplicationWindow.__init__(self) EventHelper.__init__(self) self.set_application(app.app) @@ -48,7 +51,7 @@ def __init__(self, account): self._destroyed = False self._ui = get_builder('mam_preferences.ui') - self.add(self._ui.get_object('mam_box')) + self.add(self._ui.mam_box) self._spinner = Gtk.Spinner() self._ui.overlay.add_overlay(self._spinner) @@ -63,10 +66,10 @@ def __init__(self, account): self._con.get_module('MAM').request_preferences( callback=self._mam_prefs_received) - def _on_destroy(self, *args): + def _on_destroy(self, widget: MamPreferences) -> None: self._destroyed = True - def _mam_prefs_received(self, task): + def _mam_prefs_received(self, task: Task) -> None: try: result = task.finish() except (StanzaError, MalformedStanzaError) as error: @@ -84,7 +87,7 @@ def _mam_prefs_received(self, task): for jid in result.never: self._ui.preferences_store.append((str(jid), False)) - def _mam_prefs_saved(self, task): + def _mam_prefs_saved(self, task: Task) -> None: try: task.finish() except StanzaError as error: @@ -103,7 +106,7 @@ def _on_ok(): [DialogButton.make('OK', callback=_on_ok)]).show() - def _on_error(self, error): + def _on_error(self, error: str) -> None: self._disable_spinner() InformationDialog(_('Archiving Preferences Error'), @@ -111,32 +114,41 @@ def _on_error(self, error): self._set_mam_box_state(True) - def _set_mam_box_state(self, state): + def _set_mam_box_state(self, state: bool) -> None: self._ui.mam_box.set_sensitive(state) - def _jid_edited(self, _renderer, path, new_text): + def _jid_edited(self, + _renderer: Gtk.CellRendererText, + path: str, + new_text: str) -> None: + iter_ = self._ui.preferences_store.get_iter(path) self._ui.preferences_store.set_value(iter_, 0, new_text) - def _pref_toggled(self, _renderer, path): + def _pref_toggled(self, + _renderer: Gtk.CellRendererToggle, + path: str): + iter_ = self._ui.preferences_store.get_iter(path) current_value = self._ui.preferences_store[iter_][1] self._ui.preferences_store.set_value(iter_, 1, not current_value) - def _on_add(self, _button): + def _on_add(self, _button: Gtk.Button) -> None: self._ui.preferences_store.append(['', False]) - def _on_remove(self, _button): - mod, paths = self._ui.pref_view.get_selection().get_selected_rows() + def _on_remove(self, _button: Gtk.Button) -> None: + rows = self._ui.pref_view.get_selection().get_selected_rows() + assert rows is not None + mod, paths = rows for path in paths: iter_ = mod.get_iter(path) self._ui.preferences_store.remove(iter_) - def _on_save(self, _button): + def _on_save(self, _button: Gtk.Button) -> None: self._activate_spinner() self._set_mam_box_state(False) - always = [] - never = [] + always: list[str] = [] + never: list[str] = [] default = self._ui.default_combo.get_active_id() for item in self._ui.preferences_store: jid, archive = item @@ -147,14 +159,16 @@ def _on_save(self, _button): self._con.get_module('MAM').set_preferences( default, always, never, callback=self._mam_prefs_saved) - def _activate_spinner(self): + def _activate_spinner(self) -> None: self._spinner.show() self._spinner.start() - def _disable_spinner(self): + def _disable_spinner(self) -> None: self._spinner.hide() self._spinner.stop() - def _on_key_press(self, _widget, event): + def _on_key_press(self, + _widget: MamPreferences, + event: Gdk.EventKey) -> None: if event.keyval == Gdk.KEY_Escape: self.destroy() ===================================== pyrightconfig.json ===================================== @@ -16,6 +16,7 @@ "gajim/common/cert_store.py", "gajim/gtk/app_side_bar.py", "gajim/gtk/chat_filter.py", + "gajim/gtk/chat_page.py", "gajim/gtk/conversation/code_widget.py", "gajim/gtk/conversation/jump_to_end_button.py", "gajim/gtk/conversation/quote_widget.py", View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/2784a30e28517c8ca982c68e5854764…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/2784a30e28517c8ca982c68e5854764…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Conversation rows: Typing
by Daniel Brötzmann (ï¼ wurstsalat)
27 Dec '21
27 Dec '21
Daniel Brötzmann pushed to branch master at gajim / gajim Commits: 2784a30e by wurstsalat at 2021-12-27T15:29:22+01:00 Conversation rows: Typing - - - - - 8 changed files: - gajim/gtk/conversation/rows/base.py - gajim/gtk/conversation/rows/call.py - gajim/gtk/conversation/rows/file_transfer.py - gajim/gtk/conversation/rows/file_transfer_jingle.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/conversation/rows/read_marker.py - gajim/gtk/conversation/rows/widgets.py - gajim/gtk/types.py Changes: ===================================== gajim/gtk/conversation/rows/base.py ===================================== @@ -12,6 +12,7 @@ # 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 Optional from datetime import datetime @@ -21,11 +22,13 @@ from gi.repository import Pango from gajim.common import app +from gajim.common import types from gajim.common.i18n import _ from gajim.common.helpers import from_one_line from gajim.common.helpers import is_retraction_allowed from ...util import wrap_with_event_box +from ...types import MessageRowType class BaseRow(Gtk.ListBoxRow): @@ -96,7 +99,11 @@ def __destroy(widget: Gtk.Widget) -> None: @wrap_with_event_box class MoreMenuButton(Gtk.Button): - def __init__(self, row, contact, name): + def __init__(self, + row: MessageRowType, + contact: types.BareContact, + name: str + ) -> None: Gtk.Button.__init__(self) self.set_valign(Gtk.Align.START) self.set_halign(Gtk.Align.END) ===================================== gajim/gtk/conversation/rows/call.py ===================================== @@ -84,7 +84,7 @@ def update(self) -> None: self._event = None self._session = None - def _on_accept(self, button): + def _on_accept(self, button: Gtk.Button) -> None: button.set_sensitive(False) self._decline_button.set_sensitive(False) if self._event is not None: @@ -94,7 +94,7 @@ def _on_accept(self, button): else: self.get_parent().accept_call(self._session) - def _on_decline(self, _button): + def _on_decline(self, _button: Gtk.Button) -> None: if self._event is not None: session = self._client.get_module('Jingle').get_jingle_session( self._event.fjid, self._event.sid) ===================================== gajim/gtk/conversation/rows/file_transfer.py ===================================== @@ -12,6 +12,8 @@ # 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 Any + import time from datetime import datetime @@ -20,6 +22,7 @@ from gajim.common import app from gajim.common.const import AvatarSize +from gajim.common.const import FTState from gajim.common.i18n import _ from gajim.common.modules.httpupload import HTTPFileTransfer @@ -74,7 +77,7 @@ def __init__(self, account: str, transfer: HTTPFileTransfer) -> None: self.show_all() - def _on_destroy(self, *args): + def _on_destroy(self, *args: Any) -> None: self._destroyed = True if self._transfer.state.is_active: @@ -84,10 +87,13 @@ def _on_destroy(self, *args): if self._pulse is not None: GLib.source_remove(self._pulse) - def _on_cancel_clicked(self, _button): + def _on_cancel_clicked(self, _button: Gtk.Button) -> None: self.destroy() - def _on_transfer_state_change(self, transfer, _signal_name, state): + def _on_transfer_state_change(self, + transfer: HTTPFileTransfer, + _signal_name: str, + state: FTState) -> None: if self._destroyed: return @@ -109,7 +115,10 @@ def _pulse_progressbar(self): self._ui.progress_bar.pulse() return True - def _on_transfer_progress(self, transfer, _signal_name): + def _on_transfer_progress(self, + transfer: HTTPFileTransfer, + _signal_name: str + ) -> None: if self._destroyed: return if self._pulse is not None: @@ -121,7 +130,7 @@ def _on_transfer_progress(self, transfer, _signal_name): size_total = GLib.format_size_full(transfer.size, self._units) self._ui.file_size.set_text(size_total) - bytes_sec = round(transfer.seen / (time_now - self._start_time), 1) + bytes_sec = int(round(transfer.seen / (time_now - self._start_time), 1)) speed = f'{GLib.format_size_full(bytes_sec, self._units)}/s' self._ui.transfer_progress.set_tooltip_text(_('Speed: %s') % speed) ===================================== gajim/gtk/conversation/rows/file_transfer_jingle.py ===================================== @@ -250,7 +250,8 @@ def _update_progress(self, file_props: FileProp) -> None: if full_size == 0: return - bytes_sec = round(transferred_size / (time_now - self._start_time), 1) + bytes_sec = int( + round(transferred_size / (time_now - self._start_time), 1)) speed = f'{GLib.format_size_full(bytes_sec, self._units)}/s' self._ui.progress_label.set_tooltip_text(_('Speed: %s') % speed) @@ -285,38 +286,38 @@ def _show_completed(self) -> None: self._ui.action_stack.set_visible_child_name('complete') self._ui.transfer_action.set_text(_('File Transfer Completed')) - def _on_accept_file_request(self, _widget): + def _on_accept_file_request(self, _button: Gtk.Button) -> None: app.interface.instances['file_transfers'].on_file_request_accepted( self._account, self._contact, self._file_props) self._start_time = time.time() - def _on_reject_file_request(self, _widget): + def _on_reject_file_request(self, _button: Gtk.Button) -> None: self._client.get_module('Bytestream').send_file_rejection( self._file_props) self._file_props.stopped = True self._ui.action_stack.set_visible_child_name('rejected') self._ui.transfer_action.set_text(_('File Transfer Cancelled')) - def _on_open_file(self, _widget): + def _on_open_file(self, _button: Gtk.Button) -> None: if os.path.exists(self._file_props.file_name): open_file(self._file_props.file_name) - def _on_open_folder(self, _widget): + def _on_open_folder(self, _button: Gtk.Button) -> None: path = os.path.split(self._file_props.file_name)[0] if os.path.exists(path) and os.path.isdir(path): open_file(path) - def _on_bad_hash_retry(self, _widget): + def _on_bad_hash_retry(self, _button: Gtk.Button) -> None: app.interface.instances['file_transfers'].show_hash_error( self._contact.jid, self._file_props, self._account) - def _on_cancel_transfer(self, _widget): + def _on_cancel_transfer(self, _button: Gtk.Button) -> None: app.interface.instances['file_transfers'].cancel_transfer( self._file_props) - def _on_show_transfers(self, _widget): + def _on_show_transfers(self, _button: Gtk.Button) -> None: file_transfers = app.interface.instances['file_transfers'] if file_transfers.window.get_property('visible'): file_transfers.window.present() ===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -32,6 +32,7 @@ from gajim.common import app from gajim.common import types from gajim.common.const import AvatarSize +from gajim.common.const import Trust from gajim.common.const import TRUST_SYMBOL_DATA from gajim.common.helpers import AdditionalDataDict from gajim.common.helpers import get_group_chat_nick @@ -49,6 +50,7 @@ from ...dialogs import DialogButton from ...preview import PreviewWidget from ...types import ConversationRowType +from ...types import MessageRowType from ...util import format_fingerprint from ...util import get_cursor @@ -71,7 +73,7 @@ def __init__(self, display_marking: Optional[Displaymarking] = None, marker: Optional[str] = None, error: Optional[StanzaError] = None, - encryption_enabled: bool =False, + encryption_enabled: bool = False, log_line_id: Optional[str] = None) -> None: BaseRow.__init__(self, account) @@ -99,8 +101,10 @@ def __init__(self, # Keep original text for message correction self._original_text: str = text - is_previewable = app.interface.preview_manager.is_previewable( - text, additional_data) + is_previewable = False + if additional_data is not None: + is_previewable = app.interface.preview_manager.is_previewable( + text, additional_data) if is_previewable: context = None if self._is_groupchat: @@ -136,10 +140,11 @@ def __init__(self, self._meta_box.pack_end(timestamp_label, False, True, 0) if kind in ('incoming', 'incoming_queue', 'outgoing'): - encryption_img = self._get_encryption_image( - additional_data, encryption_enabled) - if encryption_img: - self._meta_box.pack_end(encryption_img, False, True, 0) + if additional_data is not None: + encryption_img = self._get_encryption_image( + additional_data, encryption_enabled) + if encryption_img: + self._meta_box.pack_end(encryption_img, False, True, 0) if display_marking and app.settings.get_account_setting( account, 'enable_security_labels'): @@ -237,19 +242,23 @@ def _get_avatar(self, kind: str, name: str) -> Optional[cairo.Surface]: return contact.get_avatar(AvatarSize.ROSTER, scale, add_show=False) - def _on_avatar_clicked(self, _widget, event, name): + def _on_avatar_clicked(self, + _widget: Gtk.Widget, + event: Gdk.EventButton, + name: str + ) -> int: if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 1: self.get_parent().on_mention(name) return Gdk.EVENT_STOP @staticmethod - def _on_realize(event_box): + def _on_realize(event_box: Gtk.EventBox) -> None: event_box.get_window().set_cursor(get_cursor('pointer')) - def is_same_sender(self, message): + def is_same_sender(self, message: MessageRowType) -> bool: return message.name == self.name - def is_same_encryption(self, message): + def is_same_encryption(self, message: MessageRowType) -> bool: message_details = self._get_encryption_details(message.additional_data) own_details = self._get_encryption_details(self.additional_data) if message_details is None and own_details is None: @@ -271,17 +280,17 @@ def is_mergeable(self, message: ConversationRowType) -> bool: return False return abs(message.timestamp - self.timestamp) < MERGE_TIMEFRAME - def on_copy_message(self, _widget): + def on_copy_message(self, _widget: Gtk.Widget) -> None: timestamp = self.timestamp.strftime('%x, %X') clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) text = self._message_widget.get_text() clip.set_text(f'{timestamp} - {self.name}: {text}', -1) - def on_quote_message(self, _widget): + def on_quote_message(self, _widget: Gtk.Widget) -> None: self.get_parent().on_quote(self._message_widget.get_text()) - def on_retract_message(self, _widget): - def _on_retract(reason): + def on_retract_message(self, _widget: Gtk.Widget) -> None: + def _on_retract(reason: str) -> None: self._client.get_module('MUC').retract_message( self._contact.jid, self.stanza_id, reason or None) @@ -296,7 +305,10 @@ def _on_retract(reason): input_str=_('Spam'), transient_for=app.window).show() - def _get_encryption_image(self, additional_data, encryption_enabled=None): + def _get_encryption_image(self, + additional_data: AdditionalDataDict, + encryption_enabled: bool = False + ) -> Optional[Gtk.Image]: details = self._get_encryption_details(additional_data) if details is None: # Message was not encrypted @@ -326,7 +338,8 @@ def _get_encryption_image(self, additional_data, encryption_enabled=None): return image @staticmethod - def _get_encryption_details(additional_data): + def _get_encryption_details(additional_data: AdditionalDataDict + ) -> Optional[tuple[str, str, Trust]]: name = additional_data.get_value('encrypted', 'name') if name is None: return None @@ -336,18 +349,18 @@ def _get_encryption_details(additional_data): return name, fingerprint, trust @property - def has_receipt(self): + def has_receipt(self) -> bool: return self._has_receipt @property - def has_displayed(self): + def has_displayed(self) -> bool: return self._has_displayed - def set_receipt(self): + def set_receipt(self) -> None: self._has_receipt = True self._message_icons.set_receipt_icon_visible(True) - def set_displayed(self): + def set_displayed(self) -> None: self._has_displayed = True def set_retracted(self, text: str) -> None: @@ -371,15 +384,15 @@ def set_correction(self, text: str) -> None: self._message_icons.set_correction_tooltip( _('Message corrected. Original message:\n%s') % original_text) - def set_error(self, tooltip): + def set_error(self, tooltip: str) -> None: self._message_icons.set_error_icon_visible(True) self._message_icons.set_error_tooltip(tooltip) - def update_avatar(self): + def update_avatar(self) -> None: avatar = self._get_avatar(self.kind, self.name) self._avatar_image.set_from_surface(avatar) - def set_merged(self, merged): + def set_merged(self, merged: bool) -> None: self._merged = merged if merged: self.get_style_context().add_class('merged') @@ -396,7 +409,7 @@ def set_merged(self, merged): class MessageIcons(Gtk.Box): - def __init__(self): + def __init__(self) -> None: Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL) self._correction_image = Gtk.Image.new_from_icon_name( @@ -418,7 +431,7 @@ def __init__(self): self.add(self._error_image) self.show_all() - def set_receipt_icon_visible(self, visible): + def set_receipt_icon_visible(self, visible: bool) -> None: if not app.settings.get('positive_184_ack'): return self._marker_image.set_visible(visible) @@ -426,14 +439,14 @@ def set_receipt_icon_visible(self, visible): 'feather-check-symbolic', Gtk.IconSize.MENU) self._marker_image.set_tooltip_text(Q_('?Message state:Received')) - def set_correction_icon_visible(self, visible): + def set_correction_icon_visible(self, visible: bool) -> None: self._correction_image.set_visible(visible) - def set_correction_tooltip(self, text): + def set_correction_tooltip(self, text: str) -> None: self._correction_image.set_tooltip_markup(text) - def set_error_icon_visible(self, visible): + def set_error_icon_visible(self, visible: bool) -> None: self._error_image.set_visible(visible) - def set_error_tooltip(self, text): + def set_error_tooltip(self, text: str) -> None: self._error_image.set_tooltip_markup(text) ===================================== gajim/gtk/conversation/rows/read_marker.py ===================================== @@ -12,18 +12,21 @@ # 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 datetime import datetime from datetime import timedelta from gi.repository import Gtk +from gajim.common import types from gajim.common.i18n import _ from .base import BaseRow class ReadMarkerRow(BaseRow): - def __init__(self, account, contact): + def __init__(self, account: str, contact: types.BareContact) -> None: BaseRow.__init__(self, account, widget='label') self.set_activatable(False) self.type = 'read_marker' @@ -42,7 +45,10 @@ def __init__(self, account, contact): self.grid.attach(self.label, 0, 0, 1, 1) self.set_no_show_all(True) - def _on_nickname_update(self, contact, _signal_name): + def _on_nickname_update(self, + contact: types.BareContact, + _signal_name: str + ) -> None: text = _('%s has read up to this point') % contact.name self.label.set_text(text) ===================================== gajim/gtk/conversation/rows/widgets.py ===================================== @@ -17,7 +17,7 @@ class SimpleLabel(Gtk.Label): - def __init__(self): + def __init__(self) -> None: Gtk.Label.__init__(self) self.set_selectable(True) self.set_line_wrap(True) ===================================== gajim/gtk/types.py ===================================== @@ -51,6 +51,8 @@ 'ScrollHintRow' ] +MessageRowType = Union['MessageRow'] + ControlType = Union [ 'ChatControl', 'PrivateChatControl', View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/2784a30e28517c8ca982c68e58547649…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/2784a30e28517c8ca982c68e58547649…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 3 commits: QuoteWidget: Add type annotations
by Philipp Hörist (ï¼ lovetox)
27 Dec '21
27 Dec '21
Philipp Hörist pushed to branch master at gajim / gajim Commits: 111dd675 by lovetox at 2021-12-27T15:13:05+01:00 QuoteWidget: Add type annotations - - - - - 8269253f by lovetox at 2021-12-27T15:17:06+01:00 JumpToEndButton: Add type annotations - - - - - 578979c7 by lovetox at 2021-12-27T15:17:29+01:00 Update pyrightconfig.json - - - - - 4 changed files: - gajim/gtk/conversation/jump_to_end_button.py - gajim/gtk/conversation/quote_widget.py - gajim/gtk/types.py - pyrightconfig.json Changes: ===================================== gajim/gtk/conversation/jump_to_end_button.py ===================================== @@ -12,9 +12,20 @@ # 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 Union + from gi.repository import GObject from gi.repository import Gtk +from gajim.common.modules.contacts import GroupchatContact +from gajim.common.modules.contacts import GroupchatParticipant +from gajim.common.modules.contacts import BareContact + + +ContactT = Union[BareContact, GroupchatContact, GroupchatParticipant] + class JumpToEndButton(Gtk.Overlay): @@ -25,7 +36,7 @@ class JumpToEndButton(Gtk.Overlay): ()), } - def __init__(self, contact): + def __init__(self, contact: ContactT) -> None: Gtk.Overlay.__init__(self) self.set_halign(Gtk.Align.END) self.set_valign(Gtk.Align.END) @@ -51,7 +62,7 @@ def __init__(self, contact): self._unread_label.get_style_context().add_class( 'unread-counter') - if contact.is_groupchat and not contact.can_notify(): + if isinstance(contact, GroupchatContact) and not contact.can_notify(): self._unread_label.get_style_context().add_class( 'unread-counter-silent') @@ -65,7 +76,7 @@ def __init__(self, contact): self._count = 0 self.set_no_show_all(True) - def _on_jump_clicked(self, _button): + def _on_jump_clicked(self, _button: Gtk.Button) -> None: self.emit('clicked') def toggle(self, visible: bool) -> None: ===================================== gajim/gtk/conversation/quote_widget.py ===================================== @@ -12,8 +12,12 @@ # 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 gi.repository import Gtk +from .. import types + class QuoteWidget(Gtk.Box): def __init__(self, account: str) -> None: @@ -30,7 +34,9 @@ def __init__(self, account: str) -> None: self._message_widget = None - def attach_message_widget(self, message_widget): + def attach_message_widget(self, + message_widget: types.MessageWidget) -> None: + # Purpose of this method is to prevent circular imports if self._message_widget is not None: raise ValueError( ===================================== gajim/gtk/types.py ===================================== @@ -21,6 +21,7 @@ from .controls.chat import ChatControl from .controls.private import PrivateChatControl from .controls.groupchat import GroupchatControl + from .conversation.message_widget import MessageWidget from .conversation.rows.call import CallRow from .conversation.rows.command_output import CommandOutputRow from .conversation.rows.date import DateRow ===================================== pyrightconfig.json ===================================== @@ -13,10 +13,22 @@ "pythonVersion": "3.9", "typeCheckingMode": "strict", "include": [ - "gajim/gtk/chat_filter.py", + "gajim/common/cert_store.py", "gajim/gtk/app_side_bar.py", - "gajim/gtk/status_selector.py", + "gajim/gtk/chat_filter.py", + "gajim/gtk/conversation/code_widget.py", + "gajim/gtk/conversation/jump_to_end_button.py", + "gajim/gtk/conversation/quote_widget.py", + "gajim/gtk/conversation/rows/command_output.py", + "gajim/gtk/conversation/rows/date.py", + "gajim/gtk/conversation/rows/info.py", + "gajim/gtk/conversation/rows/muc_join_left.py", + "gajim/gtk/conversation/rows/muc_subject.py", + "gajim/gtk/conversation/rows/muc_user_status.py", + "gajim/gtk/conversation/rows/scroll_hint.py", + "gajim/gtk/conversation/rows/widgets.py", + "gajim/gtk/conversation/scrolled.py", "gajim/gtk/status_message_selector.py", - "gajim/common/cert_store.py" + "gajim/gtk/status_selector.py", ], } View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/e78b5932f22e06228192185cfdbbe98…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/e78b5932f22e06228192185cfdbbe98…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 3 commits: Dialogs: Add type annotations
by Philipp Hörist (ï¼ lovetox)
27 Dec '21
27 Dec '21
Philipp Hörist pushed to branch master at gajim / gajim Commits: d368c121 by lovetox at 2021-12-27T14:37:06+01:00 Dialogs: Add type annotations - - - - - cb5e5984 by lovetox at 2021-12-27T14:37:06+01:00 Main: Add type annotations - - - - - e78b5932 by lovetox at 2021-12-27T14:37:06+01:00 Roster: Refactor - Add type annotations - Refactor code so it better works with annotations - - - - - 4 changed files: - gajim/gtk/dialogs.py - gajim/gtk/main.py - gajim/gtk/roster.py - gajim/gtk/tooltips.py Changes: ===================================== gajim/gtk/dialogs.py ===================================== @@ -12,12 +12,14 @@ # 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 NamedTuple from typing import List from typing import Optional -from collections import namedtuple - from gi.repository import Gtk from gi.repository import GdkPixbuf from gi.repository import Pango @@ -30,12 +32,20 @@ from .util import get_thumbnail_size -class DialogButton(namedtuple('DialogButton', ('response text callback args ' - 'kwargs action is_default'))): +class DialogButton(NamedTuple): + response: Gtk.ResponseType + text: str + callback: Any + args: Any + kwargs: Any + action: ButtonAction + is_default: bool + + @classmethod - def make(cls, type_=None, **kwargs): + def make(cls, type_: Optional[str] = None, **kwargs: Any) -> DialogButton: # Defaults - default_kwargs = { + default_kwargs: dict[str, Any] = { 'response': None, 'text': None, 'callback': None, ===================================== gajim/gtk/main.py ===================================== @@ -568,17 +568,17 @@ def _on_window_active(self, window, _param): self.mark_as_read(control.account, control.contact.jid) @staticmethod - def contact_info(account, jid): + def contact_info(account: str, jid: str) -> None: client = app.get_client(account) contact = client.get_module('Contacts').get_contact(jid) open_window('ContactInfo', account=account, contact=contact) @staticmethod - def execute_command(account, jid): + def execute_command(account: str, jid: str) -> None: # TODO: Resource? AdHocCommand(account, jid) - def block_contact(self, account, jid): + def block_contact(self, account: str, jid: str) -> None: client = app.get_client(account) contact = client.get_module('Contacts').get_contact(jid) ===================================== gajim/gtk/roster.py ===================================== @@ -1,6 +1,26 @@ +# This file is part of Gajim. +# +# Gajim is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; version 3 only. +# +# Gajim is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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 Literal +from typing import Optional + import locale import logging -from typing import Optional + from enum import IntEnum from collections import defaultdict @@ -14,11 +34,13 @@ from gajim.common import app from gajim.common import ged +from gajim.common import types from gajim.common.const import AvatarSize from gajim.common.const import StyleAttr from gajim.common.const import PresenceShowExt from gajim.common.helpers import event_filter from gajim.common.i18n import _ +from gajim.common.nec import NetworkEvent from gajim.gui_menu_builder import get_roster_menu @@ -46,7 +68,7 @@ class Column(IntEnum): class Roster(Gtk.ScrolledWindow, EventHelper): - def __init__(self, account): + def __init__(self, account: str) -> None: Gtk.ScrolledWindow.__init__(self) EventHelper.__init__(self) self.set_size_request(200, -1) @@ -62,10 +84,8 @@ def __init__(self, account): self._ui.roster_treeview.set_model(None) self.add(self._ui.roster_treeview) - # Holds the Gtk.TreeRowReference for each contact - self._contact_refs = defaultdict(list) - # Holds the Gtk.TreeRowReference for each group - self._group_refs = {} + self._contact_refs: dict[JID, list[Gtk.TreeRowReference]] = defaultdict(list) + self._group_refs: dict[str, Gtk.TreeRowReference] = {} self._store = self._ui.contact_store self._store.set_sort_func(Column.TEXT, self._tree_compare_iters) @@ -135,6 +155,7 @@ def _add_actions(self): GLib.Variant.new_boolean(app.settings.get('showoffline'))) action.connect('change-state', self._on_show_offline) app.window.add_action(action) + action = Gio.SimpleAction.new_stateful( f'sort-by-show-{self._account}', None, @@ -147,17 +168,16 @@ def update_actions(self): online = app.account_is_connected(self._account) blocking_support = self._client.get_module('Blocking').supported - app.window.lookup_action( - f'contact-info-{self._account}').set_enabled(online) - app.window.lookup_action( - f'modify-gateway-{self._account}').set_enabled(online) - app.window.lookup_action( - f'execute-command-{self._account}').set_enabled(online) - app.window.lookup_action( - f'block-contact-{self._account}').set_enabled( - online and blocking_support) - app.window.lookup_action( - f'remove-contact-{self._account}').set_enabled(online) + actions = [('contact-info', online), + ('modify-gateway', online), + ('execute-command', online), + ('block-contact', online and blocking_support), + ('remove-contact', online)] + + for action, enabled in actions: + act = app.window.lookup_action(f'{action}-{self._account}') + assert act is not None + act.set_enabled(enabled) def _remove_actions(self): actions = [ @@ -172,26 +192,37 @@ def _remove_actions(self): for action in actions: app.window.remove_action(f'{action}-{self._account}') - def _get_contact(self, jid): + def _get_contact(self, jid: str) -> types.BareContact: return self._client.get_module('Contacts').get_contact(jid) - def _on_account_state(self, _event): + def _on_account_state(self, _event: NetworkEvent) -> None: self.update_actions() - def _on_theme_update(self, _event): + def _on_theme_update(self, _event: NetworkEvent) -> None: self.redraw() @staticmethod - def _on_drag_drop(treeview, drag_context, _x_coord, _y_coord, - timestamp): + def _on_drag_drop(treeview: Gtk.TreeView, + drag_context: Gdk.DragContext, + _x_coord: int, + _y_coord: int, + timestamp: int) -> bool: + treeview.stop_emission_by_name('drag-drop') target_list = treeview.drag_dest_get_target_list() target = treeview.drag_dest_find_target(drag_context, target_list) treeview.drag_get_data(drag_context, target, timestamp) return True - def _on_drag_data_received(self, treeview, _drag_context, x_coord, - y_coord, _selection_data, _info, _timestamp): + def _on_drag_data_received(self, + treeview: Gtk.TreeView, + _drag_context: Gdk.DragContext, + x_coord: int, + y_coord: int, + _selection_data: Gtk.SelectionData, + _info: int, + _timestamp: int) -> None: + treeview.stop_emission_by_name('drag-data-received') if treeview.get_selection().count_selected_rows() == 0: # No selections, nothing dragged from treeview @@ -201,11 +232,13 @@ def _on_drag_data_received(self, treeview, _drag_context, x_coord, if not drop_info: return - model = treeview.get_model() - path_dest, _position = drop_info + path_dest, _ = drop_info # Source: the row being dragged - path_source = treeview.get_selection().get_selected_rows()[1][0] + rows = treeview.get_selection().get_selected_rows() + assert rows is not None + model, paths = rows + path_source = paths[0] iter_source = model.get_iter(path_source) iter_source_parent = model.iter_parent(iter_source) if iter_source_parent is None: @@ -215,7 +248,6 @@ def _on_drag_data_received(self, treeview, _drag_context, x_coord, source_group = model[iter_source_parent][Column.JID_OR_GROUP] jid = model[iter_source][Column.JID_OR_GROUP] - # name = model[iter_source][Column.TEXT] # Destination: the row receiving the drop iter_dest = model.get_iter(path_dest) @@ -237,63 +269,86 @@ def _on_drag_data_received(self, treeview, _drag_context, x_coord, source_group, dest_group) - def _on_query_tooltip(self, treeview, x_coord, y_coord, _keyboard_mode, - tooltip): - try: - path = treeview.get_path_at_pos(x_coord, y_coord) - row = path[0] - except TypeError: + def _on_query_tooltip(self, + treeview: Gtk.TreeView, + x_coord: int, + y_coord: int, + _keyboard_mode: bool, + tooltip: Gtk.Tooltip) -> bool: + + row = treeview.get_path_at_pos(x_coord, y_coord) + if row is None: self._roster_tooltip.clear_tooltip() return False - if not row: + path = row[0] + if path is None: self._roster_tooltip.clear_tooltip() return False - iter_ = None - try: - model = treeview.get_model() - iter_ = model.get_iter(row) - except Exception: + model = treeview.get_model() + if model is None: self._roster_tooltip.clear_tooltip() return False + iter_ = model.get_iter(path) if not model[iter_][Column.IS_CONTACT]: # It’s a group self._roster_tooltip.clear_tooltip() return False contact = self._get_contact(model[iter_][Column.JID_OR_GROUP]) - value, widget = self._roster_tooltip.get_tooltip(row, contact) + value, widget = self._roster_tooltip.get_tooltip(path, contact) tooltip.set_custom(widget) return value - def _on_show_offline(self, action, param): - action.set_state(param) - app.settings.set('showoffline', param.get_boolean()) + def _on_show_offline(self, + action: Gio.SimpleAction, + value: Optional[GLib.Variant]) -> None: + + assert value is not None + action.set_state(value) + app.settings.set('showoffline', value.get_boolean()) self._refilter() - def _on_sort_by_show(self, action, param): - action.set_state(param) - app.settings.set('sort_by_show_in_roster', param.get_boolean()) + def _on_sort_by_show(self, + action: Gio.SimpleAction, + value: GLib.Variant) -> None: + action.set_state(value) + app.settings.set('sort_by_show_in_roster', value.get_boolean()) self._refilter() - def _on_contact_info(self, _action, param): + def _on_contact_info(self, + _action: Gio.SimpleAction, + param: GLib.Variant) -> None: + app.window.contact_info(self._account, param.get_string()) - def _on_modify_gateway(self, _action, param): + def _on_modify_gateway(self, + _action: Gio.SimpleAction, + param: GLib.Variant) -> None: + open_window( 'ServiceRegistration', account=self._account, address=param.get_string()) - def _on_execute_command(self, _action, param): + def _on_execute_command(self, + _action: Gio.SimpleAction, + param: GLib.Variant) -> None: + app.window.execute_command(self._account, param.get_string()) - def _on_block_contact(self, _action, param): + def _on_block_contact(self, + _action: Gio.SimpleAction, + param: GLib.Variant): + app.window.block_contact(self._account, param.get_string()) - def _on_remove_contact(self, _action, param): + def _on_remove_contact(self, + _action: Gio.SimpleAction, + param: GLib.Variant): + jid = JID.from_string(param.get_string()) selected_contact = self._client.get_module('Contacts').get_contact(jid) if selected_contact.is_gateway: @@ -325,9 +380,14 @@ def _on_remove(): app.window.remove_contact(self._account, jid) - def _on_roster_row_activated(self, _treeview, path, _column): - path = self._modelfilter.convert_path_to_child_path(path) - iter_ = self._store.get_iter(path) + def _on_roster_row_activated(self, + _treeview: Gtk.TreeView, + path: Gtk.TreePath, + _column: Gtk.TreeViewColumn) -> None: + + converted_path = self._modelfilter.convert_path_to_child_path(path) + assert converted_path is not None + iter_ = self._store.get_iter(converted_path) if self._store.iter_parent(iter_) is None: # This is a group row return @@ -335,7 +395,10 @@ def _on_roster_row_activated(self, _treeview, path, _column): jid = JID.from_string(self._store[iter_][Column.JID_OR_GROUP]) app.window.add_chat(self._account, jid, 'contact', select=True) - def _on_roster_button_press_event(self, treeview, event): + def _on_roster_button_press_event(self, + treeview: Gtk.TreeView, + event: Gdk.EventButton) -> None: + if event.button not in (2, 3): return @@ -345,6 +408,7 @@ def _on_roster_button_press_event(self, treeview, event): path, _, _, _ = pos path = self._modelfilter.convert_path_to_child_path(path) + assert path is not None iter_ = self._store.get_iter(path) if self._store.iter_parent(iter_) is None: # Group row @@ -360,10 +424,14 @@ def _on_roster_button_press_event(self, treeview, event): app.window.add_chat(self._account, jid, 'contact', select=True) @staticmethod - def _on_focus_out(treeview, _param): + def _on_focus_out(treeview: Gtk.TreeView, _event: Gdk.EventFocus) -> None: treeview.get_selection().unselect_all() - def _show_contact_menu(self, jid, treeview, event): + def _show_contact_menu(self, + jid: str, + treeview: Gtk.TreeView, + event: Gdk.EventButton) -> None: + contact = self._client.get_module('Contacts').get_contact(jid) gateway_register = contact.is_gateway and contact.supports( Namespace.REGISTER) @@ -371,8 +439,8 @@ def _show_contact_menu(self, jid, treeview, event): self._account, jid, gateway=gateway_register) rectangle = Gdk.Rectangle() - rectangle.x = event.x - rectangle.y = event.y + rectangle.x = int(event.x) + rectangle.y = int(event.y) rectangle.width = rectangle.height = 1 popover = Gtk.Popover.new_from_model(self, menu) @@ -381,12 +449,16 @@ def _show_contact_menu(self, jid, treeview, event): popover.set_pointing_to(rectangle) popover.popup() - def set_search_string(self, text): + def set_search_string(self, text: str) -> None: self._filter_string = text.lower() self._filter_enabled = bool(text) self._refilter() - def _visible_func(self, model, iter_, *_data): + def _visible_func(self, + model: Gtk.TreeModelFilter, + iter_: Gtk.TreeIter, + *_data: Any) -> bool: + if not self._filter_enabled: return True @@ -395,7 +467,7 @@ def _visible_func(self, model, iter_, *_data): return self._filter_string in model[iter_][Column.TEXT].lower() - def _get_contact_visible(self, contact): + def _get_contact_visible(self, contact: types.BareContact) -> bool: if self._filter_enabled: return self._filter_string in contact.name.lower() @@ -407,31 +479,31 @@ def _get_contact_visible(self, contact): return True - def _set_model(self): + def _set_model(self) -> None: self._roster.set_model(self._modelfilter) - def _unset_model(self): + def _unset_model(self) -> None: self._roster.set_model(None) - def redraw(self): + def redraw(self) -> None: self._unset_model() self._set_model() self._roster.expand_all() - def _reset_roster(self): + def _reset_roster(self) -> None: self._unset_model() self._enable_sort(False) self._clear() self._initial_draw() - def _enable_sort(self, enable): + def _enable_sort(self, enable: bool) -> None: column = Gtk.TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID if enable: column = Column.TEXT self._store.set_sort_column_id(column, Gtk.SortType.ASCENDING) - def _initial_draw(self): + def _initial_draw(self) -> None: for contact in self._client.get_module('Roster').iter_contacts(): self._connect_contact_signals(contact) self._add_or_update_contact(contact) @@ -440,21 +512,24 @@ def _initial_draw(self): self._set_model() self._roster.expand_all() - def _connect_contact_signals(self, contact): + def _connect_contact_signals(self, contact: types.BareContact) -> None: contact.connect('presence-update', self._on_contact_update) contact.connect('caps-update', self._on_contact_update) contact.connect('avatar-update', self._on_contact_update) contact.connect('blocking-update', self._on_contact_update) - def _on_contact_update(self, contact, _signal_name): + def _on_contact_update(self, + contact: types.BareContact, + _signal_name: str) -> None: + self._draw_contact(contact) @event_filter(['account']) - def _on_roster_received(self, _event): + def _on_roster_received(self, _event: NetworkEvent) -> None: self._reset_roster() @event_filter(['account']) - def _on_roster_push(self, event): + def _on_roster_push(self, event: NetworkEvent) -> None: contact = self._get_contact(event.item.jid) if event.item.subscription == 'remove': @@ -465,40 +540,48 @@ def _on_roster_push(self, event): self._connect_contact_signals(contact) self._add_or_update_contact(contact) - def _get_current_groups(self, jid): - groups = set() + def _get_current_groups(self, jid: JID) -> set[str]: + groups: set[str] = set() for ref in self._contact_refs[jid]: iter_ = self._get_iter_from_ref(ref) group_iter = self._store.iter_parent(iter_) + assert group_iter is not None groups.add(self._store[group_iter][Column.JID_OR_GROUP]) return groups - def _add_group(self, group_name): + def _add_group(self, group_name: str) -> Gtk.TreeIter: group_iter = self._get_group_iter(group_name) if group_iter is not None: return group_iter group_iter = self._store.append( - None, (None, group_name, False, group_name, True)) + None, [None, group_name, False, group_name, True]) group_path = self._store.get_path(group_iter) group_ref = Gtk.TreeRowReference(self._store, group_path) self._group_refs[group_name] = group_ref return group_iter - def _add_contact_to_group(self, contact, group): + def _add_contact_to_group(self, + contact: types.BareContact, + group: str) -> None: + group_iter = self._add_group(group) iter_ = self._store.append( group_iter, - (None, contact.name, True, str(contact.jid), True)) + [None, contact.name, True, str(contact.jid), True]) ref = Gtk.TreeRowReference(self._store, self._store.get_path(iter_)) self._contact_refs[contact.jid].append(ref) - def _add_contact_to_groups(self, contact, groups): + def _add_contact_to_groups(self, + contact: types.BareContact, + groups: set[str]) -> None: for group in groups: self._add_contact_to_group(contact, group) - def _remove_contact_from_groups(self, contact, groups): + def _remove_contact_from_groups(self, + contact: types.BareContact, + groups: set[str]) -> None: if not groups: return @@ -506,15 +589,18 @@ def _remove_contact_from_groups(self, contact, groups): for ref in refs: iter_ = self._get_iter_from_ref(ref) group_iter = self._store.iter_parent(iter_) + assert group_iter is not None group = self._store[group_iter][Column.JID_OR_GROUP] if group in groups: - iter_ = self._store.get_iter(ref.get_path()) + path = ref.get_path() + assert path is not None + iter_ = self._store.get_iter(path) self._store.remove(iter_) self._contact_refs[contact.jid].remove(ref) self._check_for_empty_groups() - def _remove_contact(self, contact): + def _remove_contact(self, contact: types.BareContact) -> None: refs = self._contact_refs.pop(contact.jid) for ref in refs: iter_ = self._get_iter_from_ref(ref) @@ -522,7 +608,7 @@ def _remove_contact(self, contact): self._check_for_empty_groups() - def _check_for_empty_groups(self): + def _check_for_empty_groups(self) -> None: for ref in list(self._group_refs.values()): group_iter = self._get_iter_from_ref(ref) if self._store.iter_has_child(group_iter): @@ -531,7 +617,7 @@ def _check_for_empty_groups(self): self._store.remove(group_iter) del self._group_refs[group] - def _add_or_update_contact(self, contact): + def _add_or_update_contact(self, contact: types.BareContact) -> None: new_groups = set(contact.groups or [DEFAULT_GROUP]) groups = self._get_current_groups(contact.jid) @@ -544,11 +630,11 @@ def _add_or_update_contact(self, contact): self._draw_groups() self._draw_contact(contact) - def _draw_groups(self): + def _draw_groups(self) -> None: for group in self._group_refs: self._draw_group(group) - def _draw_group(self, group_name): + def _draw_group(self, group_name: str) -> None: group_iter = self._get_group_iter(group_name) if not group_iter: return @@ -563,7 +649,7 @@ def _draw_group(self, group_name): self._store[group_iter][Column.TEXT] = group_name - def _refilter(self): + def _refilter(self) -> None: if self._high_performance: self._modelfilter.refilter() self._roster.expand_all() @@ -581,12 +667,15 @@ def _refilter(self): group[Column.VISIBLE] = group_is_visible self._roster.expand_all() - def _draw_contact(self, contact): + def _draw_contact(self, contact: types.BareContact) -> None: for ref in self._contact_refs[contact.jid]: self._draw_contact_row(ref, contact) self._roster.expand_all() - def _draw_contact_row(self, ref, contact): + def _draw_contact_row(self, + ref: Gtk.TreeRowReference, + contact: types.BareContact): + iter_ = self._get_iter_from_ref(ref) name = GLib.markup_escape_text(contact.name) @@ -598,14 +687,16 @@ def _draw_contact_row(self, ref, contact): AvatarSize.ROSTER, self.get_scale_factor()) self._store[iter_][Column.AVATAR] = surface - def _get_total_user_count(self): + def _get_total_user_count(self) -> int: count = 0 for group_row in self._store: count += self._store.iter_n_children(group_row.iter) return count - def _get_iter_from_ref(self, ref): - return self._store.get_iter(ref.get_path()) + def _get_iter_from_ref(self, ref: Gtk.TreeRowReference) -> Gtk.TreeIter: + path = ref.get_path() + assert path is not None + return self._store.get_iter(path) def _get_group_iter(self, group_name: str) -> Optional[Gtk.TreeIter]: try: @@ -619,7 +710,12 @@ def _get_group_iter(self, group_name: str) -> Optional[Gtk.TreeIter]: return self._store.get_iter(path) @staticmethod - def _text_cell_data_func(_column, renderer, model, iter_, _user_data): + def _text_cell_data_func(_column: Gtk.TreeViewColumn, + renderer: Gtk.CellRenderer, + model: Gtk.TreeModel, + iter_: Gtk.TreeIter, + _user_data: Literal[None]) -> None: + has_parent = bool(model.iter_parent(iter_)) style = 'contact' if has_parent else 'group' @@ -638,7 +734,11 @@ def _text_cell_data_func(_column, renderer, model, iter_, _user_data): renderer.set_property('weight', 600) renderer.set_property('ypad', 6) - def _tree_compare_iters(self, model, iter1, iter2, _user_data): + def _tree_compare_iters(self, + model: Gtk.TreeModel, + iter1: Gtk.TreeIter, + iter2: Gtk.TreeIter, + _user_data: Literal[None]): """ Compare two iterators to sort them """ @@ -669,19 +769,19 @@ def _clear(self): self._group_refs.clear() self._store.clear() - def process_event(self, event): + def process_event(self, event: NetworkEvent) -> None: if event.name not in HANDLED_EVENTS: return - def _on_destroy(self, _roster): + def _on_destroy(self, _roster: Roster) -> None: self._remove_actions() self._contact_refs.clear() self._group_refs.clear() self._unset_model() - self._roster = None self._enable_sort(False) self._store.clear() - self._store = None - # self._tooltip.destroy() - # self._tooltip = None + self._roster_tooltip.destroy() + del self._roster + del self._store + del self._roster_tooltip app.check_finalize(self) ===================================== gajim/gtk/tooltips.py ===================================== @@ -262,6 +262,9 @@ def _append_pep_info(self, contact: types.BareContact) -> None: self._ui.location.show() self._ui.location_label.show() + def destroy(self): + self.clear_tooltip() + class FileTransfersTooltip: def __init__(self) -> None: View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/853f9ed5b3ca85ec1eacfec27854220…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/853f9ed5b3ca85ec1eacfec27854220…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 3 commits: MessageRow: Fix message moderation for preview widget
by Daniel Brötzmann (ï¼ wurstsalat)
27 Dec '21
27 Dec '21
Daniel Brötzmann pushed to branch master at gajim / gajim Commits: 5a45a254 by wurstsalat at 2021-12-27T12:48:58+01:00 MessageRow: Fix message moderation for preview widget - - - - - 7868af76 by wurstsalat at 2021-12-27T13:17:42+01:00 CodeWidget: Improve display of big snippets - - - - - 853f9ed5 by wurstsalat at 2021-12-27T14:25:23+01:00 CSSConfig: Typing - - - - - 3 changed files: - gajim/gtk/conversation/code_widget.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/css_config.py Changes: ===================================== gajim/gtk/conversation/code_widget.py ===================================== @@ -58,6 +58,7 @@ def __init__(self, account: str) -> None: Gtk.PolicyType.NEVER) self._scrolled.set_hexpand(True) self._scrolled.set_vexpand(True) + self._scrolled.set_propagate_natural_width(True) self._scrolled.set_propagate_natural_height(True) self._scrolled.set_max_content_height(400) self._scrolled.add(self._textview) @@ -95,7 +96,6 @@ def __init__(self) -> None: GtkSource.View.__init__(self) self.set_editable(False) self.set_cursor_visible(False) - self.set_wrap_mode(Gtk.WrapMode.WORD_CHAR) self.set_top_margin(2) self.set_bottom_margin(2) self.set_monospace(True) ===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -86,6 +86,7 @@ def __init__(self, self.text = text self.additional_data = additional_data + self._account = account self._contact = contact self._is_groupchat: bool = False @@ -192,17 +193,17 @@ def __init__(self, avatar_placeholder.set_valign(Gtk.Align.START) avatar_placeholder.add(self._avatar_image) - bottom_box = Gtk.Box(spacing=6) - bottom_box.add(self._message_widget) + self._bottom_box = Gtk.Box(spacing=6) + self._bottom_box.add(self._message_widget) more_menu_button = MoreMenuButton(self, self._contact, name) more_menu_button.set_hexpand(True) more_menu_button.set_halign(Gtk.Align.END) - bottom_box.pack_end(more_menu_button, False, True, 0) + self._bottom_box.pack_end(more_menu_button, False, True, 0) self.grid.attach(avatar_placeholder, 0, 0, 1, 2) self.grid.attach(self._meta_box, 1, 0, 1, 1) - self.grid.attach(bottom_box, 1, 1, 1, 1) + self.grid.attach(self._bottom_box, 1, 1, 1, 1) self.show_all() @@ -350,11 +351,16 @@ def set_displayed(self): self._has_displayed = True def set_retracted(self, text: str) -> None: + if isinstance(self._message_widget, PreviewWidget): + self._message_widget.destroy() + self._message_widget = MessageWidget(self._account) + self._bottom_box.pack_start(self._message_widget, True, True, 0) self._message_widget.add_with_styling(text) self.get_style_context().add_class('retracted-message') def set_correction(self, text: str) -> None: - self._message_widget.add_with_styling(text) + if not isinstance(self._message_widget, PreviewWidget): + self._message_widget.add_with_styling(text) self._has_receipt = False self._message_icons.set_receipt_icon_visible(False) ===================================== gajim/gtk/css_config.py ===================================== @@ -179,10 +179,9 @@ def _activate_css(self, css: str, priority: CSSPriority) -> None: log.exception('Error loading application css') @staticmethod - def _pango_to_css_weight(number: str) -> int: + def _pango_to_css_weight(number: int) -> int: # Pango allows for weight values between 100 and 1000 # CSS allows only full hundred numbers like 100, 200 .. - number = int(number) if number < 100: return 100 if number > 900: @@ -325,10 +324,10 @@ def set_font(self, def _get_attr_from_description(self, description: Pango.FontDescription - ) -> Tuple[Optional[str], int, str, int]: + ) -> Tuple[Optional[str], float, str, int]: size = description.get_size() / Pango.SCALE style = self._get_string_from_pango_style(description.get_style()) - weight = self._pango_to_css_weight(description.get_weight()) + weight = self._pango_to_css_weight(int(description.get_weight())) family = description.get_family() return family, size, style, weight View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/17e9923ae82142fb6b97cd1ba41e72a…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/17e9923ae82142fb6b97cd1ba41e72a…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim] Deleted branch set-secret-detection-config-2
by Philipp Hörist (ï¼ lovetox)
26 Dec '21
26 Dec '21
Philipp Hörist deleted branch set-secret-detection-config-2 at gajim / gajim -- You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim] Deleted branch set-secret-detection-config-1
by Philipp Hörist (ï¼ lovetox)
26 Dec '21
26 Dec '21
Philipp Hörist deleted branch set-secret-detection-config-1 at gajim / gajim -- You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim] Deleted branch set-sast-config-1
by Philipp Hörist (ï¼ lovetox)
26 Dec '21
26 Dec '21
Philipp Hörist deleted branch set-sast-config-1 at gajim / gajim -- You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
← Newer
1
...
207
208
209
210
211
212
213
...
1764
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
Results per page:
10
25
50
100
200