diff --git a/gajim/gtk/const.py b/gajim/gtk/const.py new file mode 100644 index 000000000..de9499184 --- /dev/null +++ b/gajim/gtk/const.py @@ -0,0 +1,19 @@ +# 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 . + +# Constants for the gtk module + +from collections import namedtuple + +Filter = namedtuple('Filter', 'name pattern default') diff --git a/gajim/gtk/filechoosers.py b/gajim/gtk/filechoosers.py index 64ab2e5e5..2113a3f4d 100644 --- a/gajim/gtk/filechoosers.py +++ b/gajim/gtk/filechoosers.py @@ -18,7 +18,6 @@ import os import sys from pathlib import Path -from collections import namedtuple from gi.repository import Gtk from gi.repository import GdkPixbuf @@ -26,11 +25,11 @@ from gi.repository import GObject from gajim.common import app from gajim.common.i18n import _ - -Filter = namedtuple('Filter', 'name pattern default') +from gajim.gtk.const import Filter +from gajim.gtk.types import FilterList # pylint: disable=unused-import -def _require_native(): +def _require_native() -> bool: if app.is_flatpak(): return True if sys.platform in ('win32', 'darwin'): @@ -85,7 +84,7 @@ class BaseFileChooser: class BaseFileOpenDialog: _title = _('Choose File to Send…') - _filters = [Filter(_('All files'), '*', True)] + _filters = [Filter(_('All files'), '*', True)] # type: FilterList class BaseAvatarChooserDialog: @@ -96,7 +95,7 @@ class BaseAvatarChooserDialog: if _require_native(): _filters = [Filter(_('PNG files'), '*.png', True), Filter(_('JPEG files'), '*.jp*g', False), - Filter(_('SVG files'), '*.svg', False)] + Filter(_('SVG files'), '*.svg', False)] # type: FilterList else: _filters = [Filter(_('Images'), ['image/png', 'image/jpeg', @@ -106,7 +105,7 @@ class BaseAvatarChooserDialog: class NativeFileChooserDialog(Gtk.FileChooserNative, BaseFileChooser): _title = '' - _filters = [] + _filters = [] # type: FilterList _action = Gtk.FileChooserAction.OPEN def __init__(self, accept_cb, cancel_cb=None, transient_for=None, @@ -161,7 +160,7 @@ class NativeAvatarChooserDialog(BaseAvatarChooserDialog, NativeFileChooserDialog class GtkFileChooserDialog(Gtk.FileChooserDialog, BaseFileChooser): _title = '' - _filters = [] + _filters = [] # type: FilterList _action = Gtk.FileChooserAction.OPEN _preivew_size = (200, 200) diff --git a/gajim/gtk/types.py b/gajim/gtk/types.py new file mode 100644 index 000000000..c22ce5c33 --- /dev/null +++ b/gajim/gtk/types.py @@ -0,0 +1,22 @@ +# 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 . + +# Types for typechecking + +from typing import ClassVar +from typing import List + +from gajim.gtk.const import Filter + +FilterList = ClassVar[List[Filter]]