Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions rsudp/c_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,32 @@
PhotoImage = False
try:
from matplotlib import use
try:
use('Qt5Agg')
from PyQt5 import QtGui
QT = True
except Exception as e:
printW('Qt import failed. Trying Tk...')
printW('detail: %s' % e, spaces=True)

if os.environ.get('DISPLAY') is None:
use('Agg') # Headless environment
else:
try:
use('TkAgg')
from tkinter import PhotoImage
use('Qt5Agg')
from PyQt5 import QtGui

QT = True
except Exception as e:
printE('Could not import either Qt or Tk, and the plot module requires at least one of them to run.', sender)
printE('Please make sure either PyQt5 or Tkinter is installed.', sender, spaces=True)
printE('detail: %s'% e, sender, spaces=True)
raise ImportError('Could not import either Qt or Tk, and the plot module requires at least one of them to run')
printW('Qt import failed. Trying Tk...')
printW('detail: %s' % e, spaces=True)
try:
use('TkAgg')
from tkinter import PhotoImage
except Exception as e:
printE(
'Could not import either Qt or Tk, and the plot module requires at least one of them to run.',
sender,
)
printE('Please make sure either PyQt5 or Tkinter is installed.', sender, spaces=True)
printE('detail: %s' % e, sender, spaces=True)
raise ImportError(
'Could not import either Qt or Tk, and the plot module requires at least one of them to run'
)

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.image as mpimg
Expand Down Expand Up @@ -553,6 +564,8 @@ def _set_icon(self):
'''
Set RS plot icons.
'''
if os.environ.get('DISPLAY') is None:
return
mgr = plt.get_current_fig_manager()
ico = pr.resource_filename('rsudp', os.path.join('img', ICON))
if QT:
Expand Down