Skip to content

Commit 95f375e

Browse files
committed
improves HUD rendering
fixes handling of drop outs in sampling
1 parent f98313f commit 95f375e

File tree

1 file changed

+60
-68
lines changed

1 file changed

+60
-68
lines changed

src/artisanlib/main.py

+60-68
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
QColorDialog, QFrame, QCheckBox,QStatusBar, QProgressDialog, # @Reimport
8282
QStyleFactory, QTableWidget, QTableWidgetItem, QMenu, QDoubleSpinBox,QButtonGroup) # @Reimport
8383
from PyQt5.QtGui import (QImageReader, QWindow, # @Reimport
84-
QKeySequence,QStandardItem,QImage,QPixmap,QColor,QPalette,QDesktopServices,QIcon, # @Reimport
84+
QKeySequence,QStandardItem, #QImage,
85+
QPixmap,QColor,QPalette,QDesktopServices,QIcon, # @Reimport
8586
QRegExpValidator,QDoubleValidator, QIntValidator,QPainter, QFont,QBrush, QRadialGradient,QCursor,QTextDocument) # @Reimport
8687
from PyQt5.QtPrintSupport import (QPrinter,QPrintDialog) # @Reimport
8788
from PyQt5.QtCore import (QLibraryInfo, QTranslator, QLocale, QFileInfo, PYQT_VERSION_STR, pyqtSignal, # @Reimport
@@ -1858,11 +1859,10 @@ def doUpdate(self):
18581859
self.resetlines() # get rid of HUD, projection, cross lines and AUC line
18591860
self.resetdeltalines() # just in case
18601861

1861-
# ask the canvas to kindly draw it self some time in the future
1862-
# when Qt thinks it is convenient
1862+
18631863
try:
18641864
self.fig.canvas.draw() # the triggered _draw_event(self,evt) function resets the self.in_draw_event if done
1865-
#self.fig.canvas.draw_idle()
1865+
#self.fig.canvas.draw_idle() # ask the canvas to kindly draw it self some time in the future when Qt thinks it is convenient
18661866
# make sure that the GUI framework has a chance to run its event loop
18671867
# and clear any GUI events. This needs to be in a try/except block
18681868
# because the default implemenation of this method is to raise
@@ -2428,7 +2428,6 @@ def updategraphics(self):
24282428
self.markCharge() # we do not reset the autoChargeIdx to avoid another trigger
24292429
self.autoChargeIdx = 0
24302430

2431-
24322431
##### updated canvas
24332432
try:
24342433
if not self.block_update:
@@ -2496,8 +2495,9 @@ def updategraphics(self):
24962495
aw.qmc.playbackevent()
24972496
if aw.qmc.backgroundPlaybackDROP:
24982497
aw.qmc.playbackdrop()
2499-
except Exception:
2500-
pass
2498+
except Exception as e:
2499+
_, _, exc_tb = sys.exc_info()
2500+
aw.qmc.adderror((QApplication.translate("Error Message","Exception:",None) + " updategraphics() {0}").format(str(e)),exc_tb.tb_lineno)
25012501

25022502
#####
25032503
if aw.qmc.patheffects:
@@ -2593,17 +2593,18 @@ def toggleHUD(self):
25932593

25942594
#ON
25952595
else:
2596+
self.redraw(False,False)
25962597
#load
25972598
img = self.grab()
25982599
aw.HUD.setPixmap(img)
2599-
26002600
self.HUDflag = True
26012601
aw.button_18.setStyleSheet("QPushButton { background-color: #60ffed }")
26022602
aw.stack.setCurrentIndex(1)
26032603
aw.sendmessage(QApplication.translate("Message","HUD ON", None))
26042604

26052605
def refreshHUD(self):
26062606
aw.stack.setCurrentIndex(0)
2607+
self.redraw(False,False)
26072608
img = self.grab()
26082609
aw.HUD.setPixmap(img)
26092610
aw.stack.setCurrentIndex(1)
@@ -10437,12 +10438,12 @@ def sample(self):
1043710438
if aw.qmc.smooth_curves_on_recording:
1043810439
aw.qmc.l_temp1.set_data(aw.qmc.ctimex1, aw.qmc.stemp1)
1043910440
else:
10440-
aw.qmc.l_temp1.set_data(aw.qmc.ctimex1, aw.qmc.temp1)
10441+
aw.qmc.l_temp1.set_data(aw.qmc.ctimex1, aw.qmc.ctemp1)
1044110442
if aw.qmc.BTcurve:
1044210443
if aw.qmc.smooth_curves_on_recording:
1044310444
aw.qmc.l_temp2.set_data(aw.qmc.ctimex2, aw.qmc.stemp2)
1044410445
else:
10445-
aw.qmc.l_temp2.set_data(aw.qmc.ctimex2, aw.qmc.temp2)
10446+
aw.qmc.l_temp2.set_data(aw.qmc.ctimex2, aw.qmc.ctemp2)
1044610447

1044710448

1044810449

@@ -24988,7 +24989,7 @@ def showHUDmetrics(self):
2498824989
if self.qmc.hudresizeflag:
2498924990
self.qmc.refreshHUD()
2499024991
self.qmc.hudresizeflag = False
24991-
elif len(self.qmc.temp2) > 1: #Need this because viewProjections use rate of change (two values needed)
24992+
if len(self.qmc.temp2) > 1: #Need this because viewProjections use rate of change (two values needed)
2499224993
ETreachTime,BTreachTime,ET2reachTime,BT2reachTime = self.qmc.getTargetTime()
2499324994
if ETreachTime > 0 and ETreachTime < 2000:
2499424995
text1 = u(QApplication.translate("Label","{0} to reach ET {1}", None).format(self.qmc.stringfromseconds(int(ETreachTime)),str(self.qmc.ETtarget) + self.qmc.mode))
@@ -25049,23 +25050,16 @@ def showHUDmetrics(self):
2504925050
MVV = int(round(MV))
2505025051
pidstring = "ET pid = %i "%MVV
2505125052
##### end of ET pid
25052-
# QImage.Format_RGB32, QImage.Format_ARGB32
25053+
# # QImage.Format_RGB32, QImage.Format_ARGB32
2505325054
# w = self.qmc.size().width()*self.devicePixelRatio()
2505425055
# h = self.qmc.size().height()*self.devicePixelRatio()
2505525056
# qImage = QImage(self.qmc.fig.canvas.buffer_rgba(), w, h, QImage.Format_ARGB32_Premultiplied).rgbSwapped()
2505625057
# if hasattr(qImage, 'setDevicePixelRatio'):
25057-
# qImage.setDevicePixelRatio(self.qmc.fig.canvas._dpi_ratio)
25058-
25059-
buf = self.qmc.fig.canvas.buffer_rgba()
25060-
buf = bytearray(buf).copy()
25061-
w = self.qmc.fig.canvas.size().width()*self.qmc.fig.canvas._dpi_ratio
25062-
h = self.qmc.fig.canvas.size().height()*self.qmc.fig.canvas._dpi_ratio
25063-
qImage = QImage(buf,w, h, QImage.Format_ARGB32_Premultiplied)
25064-
if hasattr(qImage, 'setDevicePixelRatio'):
25065-
qImage.setDevicePixelRatio(self.qmc.fig.canvas._dpi_ratio)
25066-
qImage = qImage.rgbSwapped()
25067-
25068-
img = QPixmap.fromImage(qImage)
25058+
# qImage.setDevicePixelRatio(self.qmc.fig.canvas._dpi_ratio)
25059+
# img = QPixmap.fromImage(qImage)
25060+
25061+
img = self.qmc.grab()
25062+
2506925063
Wwidth = self.qmc.size().width()
2507025064
Wheight = self.qmc.size().height()
2507125065
#Draw begins
@@ -25090,51 +25084,49 @@ def showHUDmetrics(self):
2509025084

2509125085
def showHUDthermal(self):
2509225086
if self.qmc.hudresizeflag:
25093-
#turn off
25094-
self.qmc.toggleHUD()
25095-
#turn back ON to adquire new size
25096-
self.qmc.toggleHUD()
25087+
self.qmc.refreshHUD()
2509725088
self.qmc.hudresizeflag = False
25098-
img = self.qmc.grab()
25099-
p = QPainter(img)
25100-
Wwidth= self.qmc.size().width()
25101-
Wheight = self.qmc.size().height()
25102-
p.setOpacity(1)
25103-
p.setPen(QColor(96,255,237)) #color the rectangle the same as HUD button
25104-
p.drawRect(10,10, Wwidth - 20, Wheight - 20)
25105-
if self.qmc.mode == "F" and self.qmc.temp1:
25106-
ETradius = int(self.qmc.temp1[-1]/3)
25107-
BTradius = int(self.qmc.temp2[-1]/3)
25108-
elif self.qmc.mode == "C" and self.qmc.temp1:
25109-
ETradius = int(self.qmc.fromCtoF(self.qmc.temp1[-1]/3))
25110-
BTradius = int(self.qmc.fromCtoF(self.qmc.temp2[-1]/3))
25111-
else:
25112-
ETradius = 50
25113-
BTradius = 50
25114-
Tradius = 300
25115-
p.setOpacity(0.5)
25116-
g = QRadialGradient(Wwidth/2, Wheight/2, ETradius)
25117-
beanbright = 100 - ETradius
25118-
if beanbright < 0: beanbright = 0
25119-
g.setColorAt(0.0, QColor(240,255,beanbright)) #bean center
25120-
g.setColorAt(.5, Qt.yellow)
25121-
g.setColorAt(.8, Qt.red)
25122-
g.setColorAt(1.,QColor("lightgrey"))
25123-
p.setBrush(QBrush(g))
25124-
#draw thermal circle
25125-
p.setPen(0)
25126-
p.drawEllipse(Wwidth/2 -Tradius/2 , Wheight/2 - Tradius/2 , Tradius,Tradius)
25127-
#draw ET circle
25128-
p.setBrush(0)
25129-
p.setPen(QColor("black"))
25130-
p.drawEllipse(Wwidth/2 -ETradius/2 , Wheight/2 - ETradius/2 , ETradius,ETradius)
25131-
#draw BT circle
25132-
p.drawEllipse(Wwidth/2 -BTradius/2 , Wheight/2 - BTradius/2 , BTradius,BTradius)
25133-
delta = QApplication.translate("Label","ET - BT = {0}{1}", None).format("%.1f"%(self.qmc.temp1[-1] - self.qmc.temp2[-1]),self.qmc.mode)
25134-
p.setFont(QFont('Utopia', 14, -1))
25135-
p.drawText(QPoint(Wwidth/2,Wheight/2),u(delta))
25136-
p.end()
25137-
self.HUD.setPixmap(img)
25089+
if len(self.qmc.temp2) > 0:
25090+
img = self.qmc.grab()
25091+
p = QPainter(img)
25092+
Wwidth= self.qmc.size().width()
25093+
Wheight = self.qmc.size().height()
25094+
p.setOpacity(1)
25095+
p.setPen(QColor(96,255,237)) #color the rectangle the same as HUD button
25096+
p.drawRect(10,10, Wwidth - 20, Wheight - 20)
25097+
if self.qmc.mode == "F" and self.qmc.temp1:
25098+
ETradius = int(self.qmc.temp1[-1]/3)
25099+
BTradius = int(self.qmc.temp2[-1]/3)
25100+
elif self.qmc.mode == "C" and self.qmc.temp1:
25101+
ETradius = int(self.qmc.fromCtoF(self.qmc.temp1[-1]/3))
25102+
BTradius = int(self.qmc.fromCtoF(self.qmc.temp2[-1]/3))
25103+
else:
25104+
ETradius = 50
25105+
BTradius = 50
25106+
Tradius = 300
25107+
p.setOpacity(0.5)
25108+
g = QRadialGradient(Wwidth/2, Wheight/2, ETradius)
25109+
beanbright = 100 - ETradius
25110+
if beanbright < 0: beanbright = 0
25111+
g.setColorAt(0.0, QColor(240,255,beanbright)) #bean center
25112+
g.setColorAt(.5, Qt.yellow)
25113+
g.setColorAt(.8, Qt.red)
25114+
g.setColorAt(1.,QColor("lightgrey"))
25115+
p.setBrush(QBrush(g))
25116+
#draw thermal circle
25117+
p.setPen(0)
25118+
p.drawEllipse(Wwidth/2 -Tradius/2 , Wheight/2 - Tradius/2 , Tradius,Tradius)
25119+
#draw ET circle
25120+
p.setBrush(0)
25121+
p.setPen(QColor("black"))
25122+
p.drawEllipse(Wwidth/2 -ETradius/2 , Wheight/2 - ETradius/2 , ETradius,ETradius)
25123+
#draw BT circle
25124+
p.drawEllipse(Wwidth/2 -BTradius/2 , Wheight/2 - BTradius/2 , BTradius,BTradius)
25125+
delta = QApplication.translate("Label","ET - BT = {0}{1}", None).format("%.1f"%(self.qmc.temp1[-1] - self.qmc.temp2[-1]),self.qmc.mode)
25126+
p.setFont(QFont('Utopia', 14, -1))
25127+
p.drawText(QPoint(Wwidth/2,Wheight/2),u(delta))
25128+
p.end()
25129+
self.HUD.setPixmap(img)
2513825130

2513925131
#used by WheelGraphDlg()
2514025132
#wrap values in unicode(.) if and only if those are of type string

0 commit comments

Comments
 (0)