Skip to content

Commit

Permalink
Fixing script commands for old python
Browse files Browse the repository at this point in the history
  • Loading branch information
dpizetta committed Oct 28, 2018
1 parent a248ae0 commit 467a5a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
28 changes: 24 additions & 4 deletions qdarkstyle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@
"""

import importlib
importlib_error = ""

try:
import importlib
except ImportError:
importlib_error = "Not available in Python 2.7"

import logging
import os
import platform
Expand All @@ -58,7 +64,7 @@
QT_BINDINGS = ['PyQt4', 'PyQt5', 'PySide', 'PySide2']
"""list: values of all Qt bindings to import."""

QT_ABSTRACTIONS = ['qtpy', 'pyqtgraph', 'Qt.py']
QT_ABSTRACTIONS = ['qtpy', 'pyqtgraph', 'Qt']
"""list: values of all Qt abstraction layers to import."""

QT4_IMPORT_API = ['QtCore', 'QtGui']
Expand Down Expand Up @@ -364,9 +370,12 @@ def information():

try:
from Qt import __binding__
qt_lib = __binding__
except (KeyError, ModuleNotFoundError):
except Exception:
# It should be (KeyError, ModuleNotFoundError, ImportError)
# but each python version have a different one, and not define others
qt_lib = 'Not set or nonexistent'
else:
qt_lib = __binding__

try:
qt_bin = os.environ['PYQTGRAPH_QT_LIB']
Expand All @@ -391,6 +400,9 @@ def information():

def qt_bindings():
"""Return a list of qt bindings available."""
if importlib_error:
print(importlib_error)
return []

bindings = QT_BINDINGS
for binding in bindings:
Expand All @@ -404,6 +416,10 @@ def qt_bindings():

def qt_abstractions():
"""Return a list of qt abstraction layers available."""
if importlib_error:
print(importlib_error)
return []

abstractions = QT_ABSTRACTIONS
for abstraction in abstractions:
# check import
Expand All @@ -416,6 +432,10 @@ def qt_abstractions():

def import_qt_modules_from(use_binding='pyqt5', use_abstraction='qtpy'):
"""New approach to import modules using importlib."""
if importlib_error:
print(importlib_error)
return []

spec_binding = importlib.util.find_spec(use_binding)
spec_abstraction = importlib.util.find_spec(use_abstraction)

Expand Down
8 changes: 4 additions & 4 deletions qdarkstyle/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def main():
help="Show available bindings for Qt")
parser.add_argument('-a', '--abstractions', action='store_true',
help="Show available abstraction layers for Qt bindings")
parser.add_argument('-e', '--example', action='store_true',
help="Show qdarkstyle example")
# parser.add_argument('-e', '--example', action='store_true',
# help="Show qdarkstyle example")
parser.add_argument('-v', '--version', action='store_true',
help="Show qdarkstyle version")
parser.add_argument('--all', action='store_true',
Expand Down Expand Up @@ -58,8 +58,8 @@ def main():
info = __version__
print('\nVersion: %s' % info)

if args.example:
example.main()
# if args.example:
# example.main()


if __name__ == "__main__":
Expand Down

0 comments on commit 467a5a6

Please sign in to comment.