Fix "Gtk was imported without specifying a version first"
Fixes the following warnings: sys:1: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded. sys:1: PyGIWarning: Notify was imported without specifying a version first. Use gi.require_version('Notify', '0.7') before import to ensure that the right version gets loaded.
This commit is contained in:
parent
5c38f90cd6
commit
e1eee2e078
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
|
||||||
from solaar import __version__, NAME
|
from solaar import __version__, NAME
|
||||||
import solaar.i18n as _i18n
|
import solaar.i18n as _i18n
|
||||||
|
@ -31,7 +33,7 @@ import solaar.cli as _cli
|
||||||
|
|
||||||
def _require(module, os_package):
|
def _require(module, os_package):
|
||||||
try:
|
try:
|
||||||
__import__(module)
|
return importlib.import_module(module)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import sys
|
import sys
|
||||||
sys.exit("%s: missing required package '%s'" % (NAME, os_package))
|
sys.exit("%s: missing required package '%s'" % (NAME, os_package))
|
||||||
|
@ -85,7 +87,8 @@ def main():
|
||||||
if not args: return
|
if not args: return
|
||||||
if args.action: return _cli.run(args.action, args.hidraw_path)
|
if args.action: return _cli.run(args.action, args.hidraw_path)
|
||||||
|
|
||||||
_require('gi.repository', 'python-gi')
|
gi = _require('gi', 'python-gi')
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
_require('gi.repository.Gtk', 'gir1.2-gtk-3.0')
|
_require('gi.repository.Gtk', 'gir1.2-gtk-3.0')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -29,9 +29,17 @@ from solaar.i18n import _
|
||||||
#
|
#
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import gi
|
||||||
|
gi.require_version('Notify', '0.7')
|
||||||
# this import is allowed to fail, in which case the entire feature is unavailable
|
# this import is allowed to fail, in which case the entire feature is unavailable
|
||||||
from gi.repository import Notify
|
from gi.repository import Notify
|
||||||
|
|
||||||
|
# assumed to be working since the import succeeded
|
||||||
|
available = True
|
||||||
|
except (ValueError, ImportError):
|
||||||
|
available = False
|
||||||
|
|
||||||
|
if available:
|
||||||
from logging import getLogger, INFO as _INFO
|
from logging import getLogger, INFO as _INFO
|
||||||
_log = getLogger(__name__)
|
_log = getLogger(__name__)
|
||||||
del getLogger
|
del getLogger
|
||||||
|
@ -39,9 +47,6 @@ try:
|
||||||
from solaar import NAME
|
from solaar import NAME
|
||||||
from . import icons as _icons
|
from . import icons as _icons
|
||||||
|
|
||||||
# assumed to be working since the import succeeded
|
|
||||||
available = True
|
|
||||||
|
|
||||||
# cache references to shown notifications here, so if another status comes
|
# cache references to shown notifications here, so if another status comes
|
||||||
# while its notification is still visible we don't create another one
|
# while its notification is still visible we don't create another one
|
||||||
_notifications = {}
|
_notifications = {}
|
||||||
|
@ -137,8 +142,7 @@ try:
|
||||||
except Exception:
|
except Exception:
|
||||||
_log.exception("showing %s", n)
|
_log.exception("showing %s", n)
|
||||||
|
|
||||||
except ImportError:
|
else:
|
||||||
available = False
|
|
||||||
init = lambda: False
|
init = lambda: False
|
||||||
uninit = lambda: None
|
uninit = lambda: None
|
||||||
# toggle = lambda action: False
|
# toggle = lambda action: False
|
||||||
|
|
Loading…
Reference in New Issue