Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
a5f1222b
by wurstsalat at 2022-01-20T22:39:34+01:00
-
ad699686
by wurstsalat at 2022-01-20T22:39:34+01:00
2 changed files:
Changes:
| ... | ... | @@ -20,15 +20,19 @@ |
| 20 | 20 |
from typing import Callable
|
| 21 | 21 |
from typing import NamedTuple
|
| 22 | 22 |
from typing import Optional
|
| 23 |
+from typing import Union
|
|
| 23 | 24 |
|
| 24 |
-from collections import namedtuple
|
|
| 25 | 25 |
from enum import Enum
|
| 26 | 26 |
from enum import IntEnum
|
| 27 | 27 |
from enum import unique
|
| 28 | 28 |
|
| 29 | 29 |
from gajim.common.setting_values import AllSettingsT
|
| 30 | 30 |
|
| 31 |
-Filter = namedtuple('Filter', 'name pattern default')
|
|
| 31 |
+ |
|
| 32 |
+class Filter(NamedTuple):
|
|
| 33 |
+ name: str
|
|
| 34 |
+ pattern: Union[str, list[str]]
|
|
| 35 |
+ default: bool
|
|
| 32 | 36 |
|
| 33 | 37 |
|
| 34 | 38 |
class Setting(NamedTuple):
|
| ... | ... | @@ -128,40 +132,40 @@ def __str__(self): |
| 128 | 132 |
|
| 129 | 133 |
WINDOW_MODULES = {
|
| 130 | 134 |
'AccountsWindow': 'gajim.gui.accounts',
|
| 131 |
- 'HistorySyncAssistant': 'gajim.gui.history_sync',
|
|
| 132 |
- 'ServerInfo': 'gajim.gui.server_info',
|
|
| 133 |
- 'MamPreferences': 'gajim.gui.mam_preferences',
|
|
| 134 |
- 'Preferences': 'gajim.gui.preferences',
|
|
| 135 |
- 'CreateGroupchatWindow': 'gajim.gui.groupchat_creation',
|
|
| 136 |
- 'StartChatDialog': 'gajim.gui.start_chat',
|
|
| 135 |
+ 'AccountWizard': 'gajim.gui.account_wizard',
|
|
| 137 | 136 |
'AddContact': 'gajim.gui.add_contact',
|
| 138 |
- 'SingleMessageWindow': 'gajim.gui.single_message',
|
|
| 137 |
+ 'AdhocMUC': 'gajim.gui.adhoc_muc',
|
|
| 138 |
+ 'AdvancedConfig': 'gajim.gui.advanced_config',
|
|
| 139 |
+ 'BlockingList': 'gajim.gui.blocking',
|
|
| 139 | 140 |
'Bookmarks': 'gajim.gui.bookmarks',
|
| 140 |
- 'AccountWizard': 'gajim.gui.account_wizard',
|
|
| 141 |
+ 'CertificateDialog': 'gajim.gui.certificate_dialog',
|
|
| 142 |
+ 'ChangePassword': 'gajim.gui.change_password',
|
|
| 143 |
+ 'ContactInfo': 'gajim.gui.contact_info',
|
|
| 144 |
+ 'CreateGroupchatWindow': 'gajim.gui.groupchat_creation',
|
|
| 145 |
+ 'Features': 'gajim.gui.features',
|
|
| 146 |
+ 'GroupchatConfig': 'gajim.gui.groupchat_config',
|
|
| 147 |
+ 'GroupChatInvitation': 'gajim.gui.groupchat_invitation',
|
|
| 148 |
+ 'GroupchatJoin': 'gajim.gui.groupchat_join',
|
|
| 149 |
+ 'HistoryExport': 'gajim.gui.history_export',
|
|
| 150 |
+ 'HistorySyncAssistant': 'gajim.gui.history_sync',
|
|
| 151 |
+ 'MamPreferences': 'gajim.gui.mam_preferences',
|
|
| 141 | 152 |
'ManageProxies': 'gajim.gui.proxies',
|
| 142 | 153 |
'ManageSounds': 'gajim.gui.manage_sounds',
|
| 143 |
- 'ServiceDiscoveryWindow': 'gajim.gui.discovery',
|
|
| 144 |
- 'BlockingList': 'gajim.gui.blocking',
|
|
| 145 |
- 'XMLConsoleWindow': 'gajim.gui.xml_console',
|
|
| 146 |
- 'GroupchatJoin': 'gajim.gui.groupchat_join',
|
|
| 154 |
+ 'PasswordDialog': 'gajim.gui.password_dialog',
|
|
| 147 | 155 |
'PEPConfig': 'gajim.gui.pep_config',
|
| 148 |
- 'GroupchatConfig': 'gajim.gui.groupchat_config',
|
|
| 156 |
+ 'PluginsWindow': 'gajim.plugins.gui',
|
|
| 157 |
+ 'Preferences': 'gajim.gui.preferences',
|
|
| 149 | 158 |
'ProfileWindow': 'gajim.gui.profile',
|
| 150 |
- 'SSLErrorDialog': 'gajim.gui.ssl_error_dialog',
|
|
| 151 |
- 'Themes': 'gajim.gui.themes',
|
|
| 152 |
- 'AdvancedConfig': 'gajim.gui.advanced_config',
|
|
| 153 |
- 'CertificateDialog': 'gajim.gui.certificate_dialog',
|
|
| 154 | 159 |
'RemoveAccount': 'gajim.gui.remove_account',
|
| 155 |
- 'ChangePassword': 'gajim.gui.change_password',
|
|
| 156 |
- 'PluginsWindow': 'gajim.plugins.gui',
|
|
| 157 |
- 'Features': 'gajim.gui.features',
|
|
| 158 |
- 'GroupChatInvitation': 'gajim.gui.groupchat_invitation',
|
|
| 159 |
- 'ContactInfo': 'gajim.gui.contact_info',
|
|
| 160 |
- 'WorkspaceDialog': 'gajim.gui.workspace_dialog',
|
|
| 161 | 160 |
'RosterItemExchange': 'gajim.gui.roster_item_exchange',
|
| 161 |
+ 'ServerInfo': 'gajim.gui.server_info',
|
|
| 162 |
+ 'ServiceDiscoveryWindow': 'gajim.gui.discovery',
|
|
| 162 | 163 |
'ServiceRegistration': 'gajim.gui.service_registration',
|
| 164 |
+ 'SingleMessageWindow': 'gajim.gui.single_message',
|
|
| 165 |
+ 'SSLErrorDialog': 'gajim.gui.ssl_error_dialog',
|
|
| 166 |
+ 'StartChatDialog': 'gajim.gui.start_chat',
|
|
| 163 | 167 |
'SynchronizeAccounts': 'gajim.gui.synchronize_accounts',
|
| 164 |
- 'AdhocMUC': 'gajim.gui.adhoc_muc',
|
|
| 165 |
- 'PasswordDialog': 'gajim.gui.password_dialog',
|
|
| 166 |
- 'HistoryExport': 'gajim.gui.history_export',
|
|
| 168 |
+ 'Themes': 'gajim.gui.themes',
|
|
| 169 |
+ 'WorkspaceDialog': 'gajim.gui.workspace_dialog',
|
|
| 170 |
+ 'XMLConsoleWindow': 'gajim.gui.xml_console',
|
|
| 167 | 171 |
}
|
| ... | ... | @@ -15,7 +15,13 @@ |
| 15 | 15 |
# You should have received a copy of the GNU General Public License
|
| 16 | 16 |
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 17 | 17 |
|
| 18 |
-from typing import List
|
|
| 18 |
+from __future__ import annotations
|
|
| 19 |
+ |
|
| 20 |
+from typing import cast
|
|
| 21 |
+from typing import Any
|
|
| 22 |
+from typing import Callable
|
|
| 23 |
+from typing import Optional
|
|
| 24 |
+from typing import Union
|
|
| 19 | 25 |
|
| 20 | 26 |
import os
|
| 21 | 27 |
import sys
|
| ... | ... | @@ -42,7 +48,12 @@ def _require_native() -> bool: |
| 42 | 48 |
# Notes: Adding mime types to Gtk.FileFilter forces non-native dialogs
|
| 43 | 49 |
|
| 44 | 50 |
class BaseFileChooser:
|
| 45 |
- def _on_response(self, dialog, response, accept_cb, cancel_cb):
|
|
| 51 |
+ def _on_response(self,
|
|
| 52 |
+ dialog: Union[Gtk.FileChooser, Gtk.FileChooserNative],
|
|
| 53 |
+ response: Gtk.ResponseType,
|
|
| 54 |
+ accept_cb: Callable[..., Any],
|
|
| 55 |
+ cancel_cb: Optional[Callable[..., Any]]
|
|
| 56 |
+ ) -> None:
|
|
| 46 | 57 |
if response == Gtk.ResponseType.ACCEPT:
|
| 47 | 58 |
if self.get_select_multiple():
|
| 48 | 59 |
accept_cb(dialog.get_filenames())
|
| ... | ... | @@ -54,7 +65,7 @@ def _on_response(self, dialog, response, accept_cb, cancel_cb): |
| 54 | 65 |
if cancel_cb is not None:
|
| 55 | 66 |
cancel_cb()
|
| 56 | 67 |
|
| 57 |
- def _add_filters(self, filters):
|
|
| 68 |
+ def _add_filters(self, filters: list[Filter]) -> None:
|
|
| 58 | 69 |
for filterinfo in filters:
|
| 59 | 70 |
filter_ = Gtk.FileFilter()
|
| 60 | 71 |
filter_.set_name(filterinfo.name)
|
| ... | ... | @@ -67,9 +78,9 @@ def _add_filters(self, filters): |
| 67 | 78 |
if filterinfo.default:
|
| 68 | 79 |
self.set_filter(filter_)
|
| 69 | 80 |
|
| 70 |
- def _update_preview(self, filechooser):
|
|
| 81 |
+ def _update_preview(self, filechooser: Gtk.FileChooser) -> None:
|
|
| 71 | 82 |
path_to_file = filechooser.get_preview_filename()
|
| 72 |
- preview = filechooser.get_preview_widget()
|
|
| 83 |
+ preview = cast(Gtk.Image, filechooser.get_preview_widget())
|
|
| 73 | 84 |
if path_to_file is None or os.path.isdir(path_to_file):
|
| 74 | 85 |
# nothing to preview
|
| 75 | 86 |
preview.clear()
|
| ... | ... | @@ -80,7 +91,7 @@ def _update_preview(self, filechooser): |
| 80 | 91 |
except GLib.Error:
|
| 81 | 92 |
preview.clear()
|
| 82 | 93 |
return
|
| 83 |
- filechooser.get_preview_widget().set_from_pixbuf(pixbuf)
|
|
| 94 |
+ preview.set_from_pixbuf(pixbuf)
|
|
| 84 | 95 |
|
| 85 | 96 |
|
| 86 | 97 |
class BaseFileOpenDialog:
|
| ... | ... | @@ -107,12 +118,18 @@ class BaseAvatarChooserDialog: |
| 107 | 118 |
class NativeFileChooserDialog(Gtk.FileChooserNative, BaseFileChooser):
|
| 108 | 119 |
|
| 109 | 120 |
_title = ''
|
| 110 |
- _filters: List[Filter] = []
|
|
| 121 |
+ _filters: list[Filter] = []
|
|
| 111 | 122 |
_action = Gtk.FileChooserAction.OPEN
|
| 112 | 123 |
|
| 113 |
- def __init__(self, accept_cb, cancel_cb=None, transient_for=None,
|
|
| 114 |
- path=None, file_name=None, select_multiple=False,
|
|
| 115 |
- modal=False):
|
|
| 124 |
+ def __init__(self,
|
|
| 125 |
+ accept_cb: Callable[..., Any],
|
|
| 126 |
+ cancel_cb: Optional[Callable[..., Any]] = None,
|
|
| 127 |
+ transient_for: Optional[Gtk.Window] = None,
|
|
| 128 |
+ path: Optional[str] = None,
|
|
| 129 |
+ file_name: Optional[str] = None,
|
|
| 130 |
+ select_multiple: bool = False,
|
|
| 131 |
+ modal: bool = False
|
|
| 132 |
+ ) -> None:
|
|
| 116 | 133 |
|
| 117 | 134 |
if transient_for is None:
|
| 118 | 135 |
transient_for = app.app.get_active_window()
|
| ... | ... | @@ -159,13 +176,20 @@ class NativeAvatarChooserDialog(BaseAvatarChooserDialog, NativeFileChooserDialog |
| 159 | 176 |
class GtkFileChooserDialog(Gtk.FileChooserDialog, BaseFileChooser):
|
| 160 | 177 |
|
| 161 | 178 |
_title = ''
|
| 162 |
- _filters: List[Filter] = []
|
|
| 179 |
+ _filters: list[Filter] = []
|
|
| 163 | 180 |
_action = Gtk.FileChooserAction.OPEN
|
| 164 | 181 |
_preivew_size = (200, 200)
|
| 165 | 182 |
|
| 166 |
- def __init__(self, accept_cb, cancel_cb=None, transient_for=None,
|
|
| 167 |
- path=None, file_name=None, select_multiple=False,
|
|
| 168 |
- preview=True, modal=False):
|
|
| 183 |
+ def __init__(self,
|
|
| 184 |
+ accept_cb: Callable[..., Any],
|
|
| 185 |
+ cancel_cb: Optional[Callable[..., Any]] = None,
|
|
| 186 |
+ transient_for: Optional[Gtk.Window] = None,
|
|
| 187 |
+ path: Optional[str] = None,
|
|
| 188 |
+ file_name: Optional[str] = None,
|
|
| 189 |
+ select_multiple: bool = False,
|
|
| 190 |
+ preview: bool = True,
|
|
| 191 |
+ modal: bool = False
|
|
| 192 |
+ ) -> None:
|
|
| 169 | 193 |
|
| 170 | 194 |
if transient_for is None:
|
| 171 | 195 |
transient_for = app.app.get_active_window()
|
| ... | ... | @@ -196,7 +220,7 @@ def __init__(self, accept_cb, cancel_cb=None, transient_for=None, |
| 196 | 220 |
self.connect('response', self._on_response, accept_cb, cancel_cb)
|
| 197 | 221 |
self.show()
|
| 198 | 222 |
|
| 199 |
- def _on_response(self, *args):
|
|
| 223 |
+ def _on_response(self, *args: Any) -> None:
|
|
| 200 | 224 |
super()._on_response(*args)
|
| 201 | 225 |
self.destroy()
|
| 202 | 226 |
|
| ... | ... | @@ -209,13 +233,18 @@ class GtkAvatarChooserDialog(BaseAvatarChooserDialog, GtkFileChooserDialog): |
| 209 | 233 |
pass
|
| 210 | 234 |
|
| 211 | 235 |
|
| 212 |
-def FileChooserDialog(*args, **kwargs):
|
|
| 236 |
+def FileChooserDialog(*args: Any,
|
|
| 237 |
+ **kwargs: Any
|
|
| 238 |
+ ) -> Union[NativeFileOpenDialog, GtkFileOpenDialog]:
|
|
| 213 | 239 |
if _require_native():
|
| 214 | 240 |
return NativeFileOpenDialog(*args, **kwargs)
|
| 215 | 241 |
return GtkFileOpenDialog(*args, **kwargs)
|
| 216 | 242 |
|
| 217 | 243 |
|
| 218 |
-def AvatarChooserDialog(*args, **kwargs):
|
|
| 244 |
+def AvatarChooserDialog(*args: Any,
|
|
| 245 |
+ **kwargs: Any
|
|
| 246 |
+ ) -> Union[NativeAvatarChooserDialog,
|
|
| 247 |
+ GtkAvatarChooserDialog]:
|
|
| 219 | 248 |
if _require_native():
|
| 220 | 249 |
return NativeAvatarChooserDialog(*args, **kwargs)
|
| 221 | 250 |
return GtkAvatarChooserDialog(*args, **kwargs)
|