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
|
||||
|
||||
import importlib
|
||||
|
||||
|
||||
from solaar import __version__, NAME
|
||||
import solaar.i18n as _i18n
|
||||
|
@ -31,7 +33,7 @@ import solaar.cli as _cli
|
|||
|
||||
def _require(module, os_package):
|
||||
try:
|
||||
__import__(module)
|
||||
return importlib.import_module(module)
|
||||
except ImportError:
|
||||
import sys
|
||||
sys.exit("%s: missing required package '%s'" % (NAME, os_package))
|
||||
|
@ -85,7 +87,8 @@ def main():
|
|||
if not args: return
|
||||
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')
|
||||
|
||||
try:
|
||||
|
|
|
@ -29,9 +29,17 @@ from solaar.i18n import _
|
|||
#
|
||||
|
||||
try:
|
||||
import gi
|
||||
gi.require_version('Notify', '0.7')
|
||||
# this import is allowed to fail, in which case the entire feature is unavailable
|
||||
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
|
||||
_log = getLogger(__name__)
|
||||
del getLogger
|
||||
|
@ -39,9 +47,6 @@ try:
|
|||
from solaar import NAME
|
||||
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
|
||||
# while its notification is still visible we don't create another one
|
||||
_notifications = {}
|
||||
|
@ -137,8 +142,7 @@ try:
|
|||
except Exception:
|
||||
_log.exception("showing %s", n)
|
||||
|
||||
except ImportError:
|
||||
available = False
|
||||
else:
|
||||
init = lambda: False
|
||||
uninit = lambda: None
|
||||
# toggle = lambda action: False
|
||||
|
|
Loading…
Reference in New Issue