import math
import argparse
-from PyQt5 import QtCore, QtGui, QtWidgets
-from PyQt5.QtCore import pyqtSlot
-
+from PyQt5 import QtCore
+from PyQt5.QtCore import (pyqtSlot, QTimer, QRect, QPoint, Qt)
+from PyQt5.QtGui import (QPainter, QColor, QPen, QBrush, QLinearGradient, QFont,
+ QPainterPath, QPolygonF)
+from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget)
import serialfpv
import qtosd_ui
return s
try:
- _encoding = QtWidgets.QApplication.UnicodeUTF8
+ _encoding = QApplication.UnicodeUTF8
def _translate(context, text, disambig):
- return QtWidgets.QApplication.translate(context, text, disambig, _encoding)
+ return QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
- return QtWidgets.QApplication.translate(context, text, disambig)
+ return QApplication.translate(context, text, disambig)
-class OSDWidget(QtWidgets.QWidget):
+class OSDWidget(QWidget):
def __init__(self, roundWidget = False, filename = None):
super(OSDWidget, self).__init__()
# init parameters
self.fpv.open_file(filename)
self.FPS = 50.
- self.timer = QtCore.QTimer(self)
+ self.timer = QTimer(self)
self.timer.timeout.connect(self.frameTimerCb)
self.timer.start(1000. / self.FPS)
@pyqtSlot(name = "paintEvent")
def paintEvent(self, evt):
"""Paint callback, this is the entry point for all drawings."""
- painter = QtGui.QPainter()
+ painter = QPainter()
painter.begin(self)
- painter.setRenderHint(QtGui.QPainter.Antialiasing)
+ painter.setRenderHint(QPainter.Antialiasing)
self.dev = evt.rect()
self.min_dim = min(self.dev.right(), self.dev.bottom())
self.max_dim = max(self.dev.right(), self.dev.bottom())
- self.adjdev = QtCore.QRect(0, 0, self.min_dim, self.min_dim)
+ self.adjdev = QRect(0, 0, self.min_dim, self.min_dim)
self.adjdev.moveCenter(self.dev.center())
self.draw(painter)
painter.end()
def getSkyBrush(self):
"""return the color gradient for the sky (blue)"""
- sky_gradient = QtGui.QLinearGradient(self.adjdev.topLeft(),
- self.adjdev.bottomRight())
- color1 = QtCore.Qt.blue
- color2 = QtCore.Qt.darkBlue
+ sky_gradient = QLinearGradient(self.adjdev.topLeft(),
+ self.adjdev.bottomRight())
+ color1 = Qt.blue
+ color2 = Qt.darkBlue
sky_gradient.setColorAt(0, color1)
sky_gradient.setColorAt(.8, color2)
return sky_gradient
def getGroundBrush(self):
"""return the color gradient for the ground (marron)"""
- ground_gradient = QtGui.QLinearGradient(self.adjdev.topLeft(),
- self.adjdev.bottomRight())
- color1 = QtGui.QColor(140, 100, 80)
- color2 = QtGui.QColor(140, 100, 40)
+ ground_gradient = QLinearGradient(self.adjdev.topLeft(),
+ self.adjdev.bottomRight())
+ color1 = QColor(140, 100, 80)
+ color2 = QColor(140, 100, 40)
ground_gradient.setColorAt(0, color1)
ground_gradient.setColorAt(.8, color2)
return ground_gradient
y_off = (pitch / self.CAM_ANGLE) * dev_r
painter.translate(center.x(), center.y())
painter.rotate(roll)
- ground_rect = QtCore.QRect(0, 0, self.max_dim * 5., self.max_dim * 5.)
+ ground_rect = QRect(0, 0, self.max_dim * 5., self.max_dim * 5.)
if self.pitch < 90. and self.pitch > -90.:
- ground_rect.moveCenter(QtCore.QPoint(0, -y_off + ground_rect.width()/2.))
+ ground_rect.moveCenter(QPoint(0, -y_off + ground_rect.width()/2.))
else:
- ground_rect.moveCenter(QtCore.QPoint(0, y_off - ground_rect.width()/2.))
+ ground_rect.moveCenter(QPoint(0, y_off - ground_rect.width()/2.))
painter.setBrush(self.getGroundBrush())
painter.drawRect(ground_rect)
painter.restore()
"""Draw the cross on the middle of the OSD"""
center = self.adjdev.center()
r = self.getCenterRadius()
- pen = QtGui.QPen(QtCore.Qt.red, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.red, r / 100., Qt.SolidLine)
painter.setPen(pen)
- pt1 = QtCore.QPoint(center.x() - 0.05 * r, center.y())
- pt2 = QtCore.QPoint(center.x() + 0.05 * r, center.y())
+ pt1 = QPoint(center.x() - 0.05 * r, center.y())
+ pt2 = QPoint(center.x() + 0.05 * r, center.y())
painter.drawLine(pt1, pt2)
- pt1 = QtCore.QPoint(center.x(), center.y() + -0.025 * r)
- pt2 = QtCore.QPoint(center.x(), center.y() + 0.025 * r)
+ pt1 = QPoint(center.x(), center.y() + -0.025 * r)
+ pt2 = QPoint(center.x(), center.y() + 0.025 * r)
painter.drawLine(pt1, pt2)
def drawPitchGraduation(self, painter):
painter.rotate(roll)
# set font and pen
- pen = QtGui.QPen(QtCore.Qt.white, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 100., Qt.SolidLine)
painter.setPen(pen)
- font = QtGui.QFont("Meiryo UI", 0, QtGui.QFont.Bold)
+ font = QFont("Meiryo UI", 0, QFont.Bold)
font.setPointSizeF(self.FONT_SIZE * r)
painter.setFont(font)
for a in angles:
# thin line
if int(a) % int(self.PITCH_REFLINES_BOLD_STEP_ANGLE) != 0:
- pen = QtGui.QPen(QtCore.Qt.white, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 100., Qt.SolidLine)
painter.setPen(pen)
- pt1 = QtCore.QPoint(-0.05 * r, dev_r / self.CAM_ANGLE * a)
- pt2 = QtCore.QPoint(0.05 * r, dev_r / self.CAM_ANGLE * a)
+ pt1 = QPoint(-0.05 * r, dev_r / self.CAM_ANGLE * a)
+ pt2 = QPoint(0.05 * r, dev_r / self.CAM_ANGLE * a)
painter.drawLine(pt1, pt2)
continue
# bold line
- pen = QtGui.QPen(QtCore.Qt.white, r / 50., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 50., Qt.SolidLine)
painter.setPen(pen)
- pt1 = QtCore.QPoint(-0.2 * r, dev_r / self.CAM_ANGLE * a)
- pt2 = QtCore.QPoint(0.2 * r, dev_r / self.CAM_ANGLE * a)
+ pt1 = QPoint(-0.2 * r, dev_r / self.CAM_ANGLE * a)
+ pt2 = QPoint(0.2 * r, dev_r / self.CAM_ANGLE * a)
painter.drawLine(pt1, pt2)
# the left text
disp_val = -180. - disp_val
disp_val = str(int(disp_val))
metrics = painter.fontMetrics()
- sz = metrics.size(QtCore.Qt.TextSingleLine, disp_val)
- lefttxt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
- lefttxt.moveCenter(pt1 - QtCore.QPoint(0.2 * r, 0))
+ sz = metrics.size(Qt.TextSingleLine, disp_val)
+ lefttxt = QRect(QPoint(0, 0), sz)
+ lefttxt.moveCenter(pt1 - QPoint(0.2 * r, 0))
# XXX
#pen.setWidth(1);
- #brush = QtGui.QBrush(QtCore.Qt.white)
+ #brush = QBrush(Qt.white)
#painter.setBrush(brush)
- #pen.setColor(QtCore.Qt.black);
+ #pen.setColor(Qt.black);
#painter.setPen(pen)
- #path = QtGui.QPainterPath()
+ #path = QPainterPath()
#path.addText(lefttxt.center(), font, disp_val)
#painter.drawPath(path)
- painter.drawText(lefttxt, QtCore.Qt.TextSingleLine, disp_val)
+ painter.drawText(lefttxt, Qt.TextSingleLine, disp_val)
# flip the right text
painter.save()
- painter.translate(pt2 + QtCore.QPoint(0.2 * r, 0))
+ painter.translate(pt2 + QPoint(0.2 * r, 0))
painter.rotate(180.)
- painter.translate(-pt2 - QtCore.QPoint(0.2 * r, 0))
- righttxt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
- righttxt.moveCenter(pt2 + QtCore.QPoint(0.2 * r, 0))
- #path = QtGui.QPainterPath()
+ painter.translate(-pt2 - QPoint(0.2 * r, 0))
+ righttxt = QRect(QPoint(0, 0), sz)
+ righttxt.moveCenter(pt2 + QPoint(0.2 * r, 0))
+ #path = QPainterPath()
#path.addText(righttxt.center(), font, disp_val)
#painter.drawPath(path)
- painter.drawText(righttxt, QtCore.Qt.TextSingleLine, disp_val)
+ painter.drawText(righttxt, Qt.TextSingleLine, disp_val)
painter.restore()
painter.restore()
center = self.adjdev.center()
x = center.x() - math.cos(math.radians(deg)) * r
y = center.y() - math.sin(math.radians(deg)) * r
- pt = QtCore.QPoint(x, y)
- path = QtGui.QPainterPath()
+ pt = QPoint(x, y)
+ path = QPainterPath()
path.moveTo(pt)
path.lineTo(center)
pt2 = path.pointAtPercent(0.075) # graduation len is 7.5% of the radius
# then draw the text
if disp_text == True:
pt_txt = path.pointAtPercent(0.2)
- font = QtGui.QFont("Meiryo UI", 0, QtGui.QFont.Bold)
+ font = QFont("Meiryo UI", 0, QFont.Bold)
font.setPointSizeF(self.FONT_SIZE * r)
painter.setFont(font)
disp_val = deg
disp_val = 180. - disp_val
disp_val = str(int(disp_val))
metrics = painter.fontMetrics()
- sz = metrics.size(QtCore.Qt.TextSingleLine, disp_val)
- txt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
+ sz = metrics.size(Qt.TextSingleLine, disp_val)
+ txt = QRect(QPoint(0, 0), sz)
txt.moveCenter(pt_txt.toPoint())
- painter.drawText(txt, QtCore.Qt.TextSingleLine, disp_val)
+ painter.drawText(txt, Qt.TextSingleLine, disp_val)
def drawRollGraduation(self, painter):
"""Draw the roll graduations."""
painter.save()
painter.translate(center.x(), center.y())
painter.rotate(self.roll)
- pen = QtGui.QPen(QtCore.Qt.red, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.red, r / 100., Qt.SolidLine)
painter.setPen(pen)
- pt1 = QtCore.QPoint(-0.925 * r, 0)
- pt2 = QtCore.QPoint(-0.85 * r, 0)
+ pt1 = QPoint(-0.925 * r, 0)
+ pt2 = QPoint(-0.85 * r, 0)
painter.drawLine(pt1, pt2)
- pt1 = QtCore.QPoint(0.925 * r, 0)
- pt2 = QtCore.QPoint(0.85 * r, 0)
+ pt1 = QPoint(0.925 * r, 0)
+ pt2 = QPoint(0.85 * r, 0)
painter.drawLine(pt1, pt2)
painter.restore()
- pen = QtGui.QPen(QtCore.Qt.white, r / 50., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 50., Qt.SolidLine)
painter.setPen(pen)
deg = 0
while deg <= 180:
def drawYaw(self, painter):
center = self.adjdev.center()
r = self.getCenterRadius()
- pen = QtGui.QPen(QtCore.Qt.red, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.red, r / 100., Qt.SolidLine)
painter.setPen(pen)
- font = QtGui.QFont("Meiryo UI", 0, QtGui.QFont.Bold)
+ font = QFont("Meiryo UI", 0, QFont.Bold)
font.setPointSizeF(self.FONT_SIZE * r)
painter.setFont(font)
if self.roundWidget == True:
y1 = center.y() + r * 1.1
y2 = center.y() + r * 1.2
y3 = center.y() + r * 1.25
- pt1 = QtCore.QPoint(center.x(), y2)
- pt2 = QtCore.QPoint(center.x(), y3)
+ pt1 = QPoint(center.x(), y2)
+ pt2 = QPoint(center.x(), y3)
painter.drawLine(pt1, pt2)
# round to nearest angle multiple of step
# text (N, S, E, W)
if int(a) % 90 == 0:
disp_text = True
- pen = QtGui.QPen(QtCore.Qt.white, r / 50., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 50., Qt.SolidLine)
painter.setPen(pen)
else:
disp_text = False
- pen = QtGui.QPen(QtCore.Qt.white, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 100., Qt.SolidLine)
painter.setPen(pen)
# the line
x = center.x() - ((r / (self.YAW_REFLINES_TOTAL_ANGLE / 2.)) *
(self.yaw - a) * self.YAW_REFLINES_SIZE_FACTOR)
- pt_txt = QtCore.QPoint(x, y_txt)
- pt1 = QtCore.QPoint(x, y1)
- pt2 = QtCore.QPoint(x, y2)
+ pt_txt = QPoint(x, y_txt)
+ pt1 = QPoint(x, y1)
+ pt2 = QPoint(x, y2)
painter.drawLine(pt1, pt2)
if disp_text == False:
continue
disp_val = ["N", "E", "S", "W"][(int(a)/90)%4]
metrics = painter.fontMetrics()
- sz = metrics.size(QtCore.Qt.TextSingleLine, disp_val)
- txt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
+ sz = metrics.size(Qt.TextSingleLine, disp_val)
+ txt = QRect(QPoint(0, 0), sz)
txt.moveCenter(pt_txt)
- painter.drawText(txt, QtCore.Qt.TextSingleLine, disp_val)
+ painter.drawText(txt, Qt.TextSingleLine, disp_val)
def drawSpeed(self, painter):
center = self.adjdev.center()
r = self.getCenterRadius()
- pen = QtGui.QPen(QtCore.Qt.red, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.red, r / 100., Qt.SolidLine)
painter.setPen(pen)
- font = QtGui.QFont("Meiryo UI", 0, QtGui.QFont.Bold)
+ font = QFont("Meiryo UI", 0, QFont.Bold)
font.setPointSizeF(self.FONT_SIZE * r)
painter.setFont(font)
x1 = center.x() - 1.5 * r
x2 = center.x() - 1.6 * r
- pt1 = QtCore.QPoint(center.x() - 1.45 * r, center.y())
- pt2 = QtCore.QPoint(x2, center.y())
+ pt1 = QPoint(center.x() - 1.45 * r, center.y())
+ pt2 = QPoint(x2, center.y())
painter.drawLine(pt1, pt2)
# round to nearest angle multiple of step
for s in speeds:
if int(s) % int(self.SPEED_REFLINES_BOLD_STEP) == 0:
disp_text = True
- pen = QtGui.QPen(QtCore.Qt.white, r / 50., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 50., Qt.SolidLine)
painter.setPen(pen)
else:
disp_text = False
- pen = QtGui.QPen(QtCore.Qt.white, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 100., Qt.SolidLine)
painter.setPen(pen)
# the line
y = center.y() + ((r / (self.SPEED_REFLINES_TOTAL/2.)) *
(self.speed - s) * self.SPEED_REFLINES_SIZE_FACTOR)
- pt_txt = QtCore.QPoint(center.x() + r * -1.75, y)
- pt1 = QtCore.QPoint(x1, y)
- pt2 = QtCore.QPoint(x2, y)
+ pt_txt = QPoint(center.x() + r * -1.75, y)
+ pt1 = QPoint(x1, y)
+ pt2 = QPoint(x2, y)
painter.drawLine(pt1, pt2)
if disp_text == False:
continue
disp_val = str(int(s))
metrics = painter.fontMetrics()
- sz = metrics.size(QtCore.Qt.TextSingleLine, disp_val)
- txt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
+ sz = metrics.size(Qt.TextSingleLine, disp_val)
+ txt = QRect(QPoint(0, 0), sz)
txt.moveCenter(pt_txt)
- painter.drawText(txt, QtCore.Qt.TextSingleLine, disp_val)
+ painter.drawText(txt, Qt.TextSingleLine, disp_val)
def drawAlt(self, painter):
center = self.adjdev.center()
r = self.getCenterRadius()
- pen = QtGui.QPen(QtCore.Qt.red, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.red, r / 100., Qt.SolidLine)
painter.setPen(pen)
- font = QtGui.QFont("Meiryo UI", 0, QtGui.QFont.Bold)
+ font = QFont("Meiryo UI", 0, QFont.Bold)
font.setPointSizeF(self.FONT_SIZE * r)
painter.setFont(font)
x1 = center.x() + 1.5 * r
x2 = center.x() + 1.6 * r
- pt1 = QtCore.QPoint(center.x() + 1.45 * r, center.y())
- pt2 = QtCore.QPoint(x2, center.y())
+ pt1 = QPoint(center.x() + 1.45 * r, center.y())
+ pt2 = QPoint(x2, center.y())
painter.drawLine(pt1, pt2)
# round to nearest angle multiple of step
for a in alts:
if int(a) % int(self.ALT_REFLINES_BOLD_STEP) == 0:
disp_text = True
- pen = QtGui.QPen(QtCore.Qt.white, r / 50., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 50., Qt.SolidLine)
painter.setPen(pen)
else:
disp_text = False
- pen = QtGui.QPen(QtCore.Qt.white, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 100., Qt.SolidLine)
painter.setPen(pen)
# the line
y = center.y() + ((r / (self.ALT_REFLINES_TOTAL / 2.)) *
(self.alt - a) * self.ALT_REFLINES_SIZE_FACTOR)
- pt_txt = QtCore.QPoint(center.x() + r * 1.75, y)
- pt1 = QtCore.QPoint(x1, y)
- pt2 = QtCore.QPoint(x2, y)
+ pt_txt = QPoint(center.x() + r * 1.75, y)
+ pt1 = QPoint(x1, y)
+ pt2 = QPoint(x2, y)
painter.drawLine(pt1, pt2)
if disp_text == False:
continue
disp_val = str(int(a))
metrics = painter.fontMetrics()
- sz = metrics.size(QtCore.Qt.TextSingleLine, disp_val)
- txt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
+ sz = metrics.size(Qt.TextSingleLine, disp_val)
+ txt = QRect(QPoint(0, 0), sz)
txt.moveCenter(pt_txt)
- painter.drawText(txt, QtCore.Qt.TextSingleLine, disp_val)
+ painter.drawText(txt, Qt.TextSingleLine, disp_val)
def drawReturnToHome(self, painter):
center = self.adjdev.center()
painter.save()
painter.translate(center.x(), center.y() - 0.9 * dev_r)
painter.rotate(self.yaw) # XXX
- pen = QtGui.QPen(QtCore.Qt.white, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 100., Qt.SolidLine)
painter.setPen(pen)
- poly = QtGui.QPolygonF()
- poly.append(QtCore.QPoint(0., -0.08 * r))
- poly.append(QtCore.QPoint(0.04 * r, 0.08 * r))
- poly.append(QtCore.QPoint(-0.04 * r, 0.08 * r))
- poly.append(QtCore.QPoint(0., -0.08 * r))
- path = QtGui.QPainterPath()
+ poly = QPolygonF()
+ poly.append(QPoint(0., -0.08 * r))
+ poly.append(QPoint(0.04 * r, 0.08 * r))
+ poly.append(QPoint(-0.04 * r, 0.08 * r))
+ poly.append(QPoint(0., -0.08 * r))
+ path = QPainterPath()
path.addPolygon(poly)
- brush = QtGui.QBrush(QtCore.Qt.darkGray)
+ brush = QBrush(Qt.darkGray)
painter.setBrush(brush)
painter.drawPath(path)
painter.restore()
center = self.adjdev.center()
dev_r = self.adjdev.width() / 2.
r = self.getCenterRadius()
- pen = QtGui.QPen(QtCore.Qt.white, r / 100., QtCore.Qt.SolidLine)
+ pen = QPen(Qt.white, r / 100., Qt.SolidLine)
painter.setPen(pen)
- font = QtGui.QFont("Meiryo UI", 0, QtGui.QFont.Bold)
+ font = QFont("Meiryo UI", 0, QFont.Bold)
font.setPointSizeF(self.FONT_SIZE * r)
metrics = painter.fontMetrics()
- sz = metrics.size(QtCore.Qt.AlignLeft, self.left_txt)
- txt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
- pt_txt = QtCore.QPoint(center.x() + dev_r * -0.95,
+ sz = metrics.size(Qt.AlignLeft, self.left_txt)
+ txt = QRect(QPoint(0, 0), sz)
+ pt_txt = QPoint(center.x() + dev_r * -0.95,
center.y() + dev_r * -0.95)
txt.moveTopLeft(pt_txt)
- painter.drawText(txt, QtCore.Qt.AlignLeft, self.left_txt)
+ painter.drawText(txt, Qt.AlignLeft, self.left_txt)
- sz = metrics.size(QtCore.Qt.AlignRight, self.right_txt)
- txt = QtCore.QRect(QtCore.QPoint(0, 0), sz)
- pt_txt = QtCore.QPoint(center.x() + dev_r * 0.95,
+ sz = metrics.size(Qt.AlignRight, self.right_txt)
+ txt = QRect(QPoint(0, 0), sz)
+ pt_txt = QPoint(center.x() + dev_r * 0.95,
center.y() + dev_r * -0.95)
txt.moveTopRight(pt_txt)
- painter.drawText(txt, QtCore.Qt.AlignRight, self.right_txt)
+ painter.drawText(txt, Qt.AlignRight, self.right_txt)
def setPitch(self, pitch):
"""set the pitch in degrees, between -180 and 180"""
"""set the left text"""
self.right_txt = txt
-class Ui_MainWindow(QtWidgets.QMainWindow):
+class Ui_MainWindow(QMainWindow):
def __init__(self, parent = None, roundWidget = False, filename = None):
super(Ui_MainWindow, self).__init__(parent)
self.ui = qtosd_ui.Ui_MainWindow()
help='specify the log file')
args = parser.parse_args()
- app = QtWidgets.QApplication(sys.argv)
+ app = QApplication(sys.argv)
ui = Ui_MainWindow(filename = args.filename, roundWidget = args.round)
ui.show()
sys.exit(app.exec_())