Skip to content

Commit

Permalink
adds support clicks on large LCDs to set tare and to show/hide curves
Browse files Browse the repository at this point in the history
  • Loading branch information
MAKOMO committed Nov 13, 2023
1 parent e44de8a commit 0d88da7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
77 changes: 67 additions & 10 deletions src/artisanlib/large_lcds.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@
# AUTHOR
# Marko Luther, 2023

import logging
from artisanlib.dialogs import ArtisanDialog
from artisanlib.widgets import MyQLabel
from artisanlib.widgets import MyQLabel, MyQLCDNumber, ClickableLCDFrame

try:
from PyQt6.QtCore import (Qt, QSettings, pyqtSlot) # @UnusedImport @Reimport @UnresolvedImport
from PyQt6.QtCore import (Qt, QSettings, pyqtSlot, QPoint) # @UnusedImport @Reimport @UnresolvedImport
from PyQt6.QtWidgets import (QApplication, QFrame, QWidget, QLCDNumber, QHBoxLayout, QVBoxLayout) # @UnusedImport @Reimport @UnresolvedImport
except ImportError:
from PyQt5.QtCore import (Qt, QSettings, pyqtSlot) # type: ignore # @UnusedImport @Reimport @UnresolvedImport
from PyQt5.QtCore import (Qt, QSettings, pyqtSlot, QPoint) # type: ignore # @UnusedImport @Reimport @UnresolvedImport
from PyQt5.QtWidgets import (QApplication, QFrame, QWidget, QLCDNumber, QHBoxLayout, QVBoxLayout) # type: ignore # @UnusedImport @Reimport @UnresolvedImport

from typing import List, Optional, TYPE_CHECKING
from typing import Final, List, Optional, TYPE_CHECKING

if TYPE_CHECKING:
from artisanlib.main import ApplicationWindow # noqa: F401 # pylint: disable=unused-import
from PyQt6.QtWidgets import QWidget # pylint: disable=unused-import
from PyQt6.QtGui import QCloseEvent # pylint: disable=unused-import


_log: Final[logging.Logger] = logging.getLogger(__name__)

class LargeLCDs(ArtisanDialog):

__slots__ = ['lcds1', 'lcds2', 'lcds1styles', 'lcds2styles', 'lcds1labelsUpper', 'lcds2labelsUpper', 'lcds1labelsLower', 'lcds2labelsLower',
Expand All @@ -49,9 +53,9 @@ def __init__(self, parent:'QWidget', aw:'ApplicationWindow') -> None:
self.lcds1labelsLower:List[MyQLabel] = []
self.lcds2labelsUpper:List[MyQLabel] = []
self.lcds2labelsLower:List[MyQLabel] = []
self.lcds1frames:List[QFrame] = []
self.lcds2frames:List[QFrame] = []
self.visibleFrames:List[QFrame] = [] # visibility flags in display order for all lcd frames
self.lcds1frames:List[ClickableLCDFrame] = []
self.lcds2frames:List[ClickableLCDFrame] = []
self.visibleFrames:List[ClickableLCDFrame] = [] # visibility flags in display order for all lcd frames
self.tight:bool = False
self.layoutNr:int = -1 # -1: unknown, 0: landscape, 1: portrait
self.swaplcds:bool = False
Expand Down Expand Up @@ -172,8 +176,8 @@ def chooseLayout(self,w,h):
else:
self.reLayout(1)

def makeLCD(self, s:str) -> QLCDNumber:
lcd = QLCDNumber()
def makeLCD(self, s:str) -> MyQLCDNumber:
lcd = MyQLCDNumber()
lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Flat)
lcd.setFrameStyle(QFrame.Shadow.Plain)
lcd.setSmallDecimalPoint(False)
Expand All @@ -195,7 +199,7 @@ def makeLCDframe(lcdUpper,lcd,lcdLower):
lcdlayout.addWidget(lcdLower,1)
lcdlayout.setSpacing(0)
lcdlayout.setContentsMargins(0, 0, 0, 0)
frame = QFrame()
frame = ClickableLCDFrame()
frame.setContentsMargins(0, 0, 0, 0)
frame.setLayout(lcdlayout)
return frame
Expand Down Expand Up @@ -364,6 +368,7 @@ def makeLCDs(self):
self.lcd0 = self.makeLCD('timer') # time
self.lcd0.setDigitCount(5)
self.lcd0.display('00:00')
self.lcd0.clicked.connect(self.aw.superusermodeLeftClicked)
# ET
ETlcd = self.makeLCD('et') # Environmental Temperature ET
ETlabelUpper = self.makeLabel(f'<b>{self.aw.ETname.format(self.aw.qmc.etypes[0],self.aw.qmc.etypes[1],self.aw.qmc.etypes[2],self.aw.qmc.etypes[3])}</b> ')
Expand All @@ -374,6 +379,9 @@ def makeLCDs(self):
self.lcds1labelsUpper = [ETlabelUpper]
self.lcds1labelsLower = [ETlabelLower]
self.lcds1frames = [self.makeLCDframe(ETlabelUpper,ETlcd,ETlabelLower)]
self.lcds1frames[0].left_clicked.connect(self.aw.toggleETCurve)
self.lcds1frames[0].setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.lcds1frames[0].customContextMenuRequested.connect(self.aw.setTareET)
# BT
BTlcd = self.makeLCD('bt') # Bean Temperature BT
BTlabelUpper = self.makeLabel(f'<b>{self.aw.BTname.format(self.aw.qmc.etypes[0],self.aw.qmc.etypes[1],self.aw.qmc.etypes[2],self.aw.qmc.etypes[3])}</b> ')
Expand All @@ -384,6 +392,9 @@ def makeLCDs(self):
self.lcds2labelsUpper = [BTlabelUpper]
self.lcds2labelsLower = [BTlabelLower]
self.lcds2frames = [self.makeLCDframe(BTlabelUpper,BTlcd,BTlabelLower)]
self.lcds2frames[0].left_clicked.connect(self.aw.toggleBTCurve)
self.lcds2frames[0].setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.lcds2frames[0].customContextMenuRequested.connect(self.aw.setTareBT)
##
self.updateVisiblitiesETBT()
self.updateStyles()
Expand Down Expand Up @@ -501,6 +512,7 @@ def makeLCDs(self):
self.lcds1labelsUpper = [label1Upper]
self.lcds1labelsLower = [label1Lower]
self.lcds1frames = [self.makeLCDframe(label1Upper,self.lcds1[0],label1Lower)]
self.lcds1frames[0].left_clicked.connect(self.aw.toggleDeltaETCurve)
#
self.lcds2styles = ['deltabt']
self.lcds2 = [self.makeLCD(self.lcds2styles[0])] # DeltaBT
Expand All @@ -509,6 +521,7 @@ def makeLCDs(self):
self.lcds2labelsUpper = [label2Upper]
self.lcds2labelsLower = [label2Lower]
self.lcds2frames = [self.makeLCDframe(label2Upper,self.lcds2[0],label2Lower)]
self.lcds2frames[0].left_clicked.connect(self.aw.toggleDeltaBTCurve)
##
self.updateVisiblitiesDeltaETBT()
self.updateStyles()
Expand Down Expand Up @@ -588,6 +601,44 @@ def __init__(self, parent:'QWidget', aw:'ApplicationWindow') -> None:
self.chooseLayout(self.width(),self.height())
self.setWindowTitle(QApplication.translate('Menu', 'Extra LCDs'))

@pyqtSlot(QPoint)
def setTare_slot(self,_:QPoint) -> None:
sender = self.sender()
try:
assert isinstance(sender, ClickableLCDFrame)
idx = self.lcds1frames.index(sender)
self.aw.setTare(2+idx*2)
except Exception: # pylint: disable=broad-except
pass
try:
assert isinstance(sender, ClickableLCDFrame)
idx = self.lcds2frames.index(sender)
self.aw.setTare(2+idx*2 + 1)
except Exception: # pylint: disable=broad-except
pass

@pyqtSlot()
def toggleExtraCurve1(self) -> None:
try:
sender = self.sender()
assert isinstance(sender, ClickableLCDFrame)
i = self.lcds1frames.index(sender)
self.aw.extraCurveVisibility1[i] = not self.aw.extraCurveVisibility1[i]
except Exception as e: # pylint: disable=broad-except
_log.exception(e)
self.aw.qmc.redraw_keep_view(recomputeAllDeltas=False)

@pyqtSlot()
def toggleExtraCurve2(self) -> None:
try:
sender = self.sender()
assert isinstance(sender, ClickableLCDFrame)
i = self.lcds2frames.index(sender)
self.aw.extraCurveVisibility2[i] = not self.aw.extraCurveVisibility2[i]
except Exception as e: # pylint: disable=broad-except
_log.exception(e)
self.aw.qmc.redraw_keep_view(recomputeAllDeltas=False)

def makeLCDs(self):
self.lcds1 = []
self.lcds2 = []
Expand Down Expand Up @@ -615,6 +666,9 @@ def makeLCDs(self):
label1Lower = self.makeLabel(' ')
self.lcds1labelsLower.append(label1Lower)
self.lcds1frames.append(self.makeLCDframe(label1Upper,lcd1,label1Lower))
self.lcds1frames[-1].left_clicked.connect(self.toggleExtraCurve1)
self.lcds1frames[-1].setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.lcds1frames[-1].customContextMenuRequested.connect(self.setTare_slot)
#
lcd2 = self.makeLCD(lcdstyle)
self.lcds2.append(lcd2)
Expand All @@ -629,6 +683,9 @@ def makeLCDs(self):
label2Lower = self.makeLabel(' ')
self.lcds2labelsLower.append(label2Lower)
self.lcds2frames.append(self.makeLCDframe(label2Upper,lcd2,label2Lower))
self.lcds2frames[-1].left_clicked.connect(self.toggleExtraCurve2)
self.lcds2frames[-1].setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.lcds2frames[-1].customContextMenuRequested.connect(self.setTare_slot)
##
self.updateVisiblitiesExtra()
self.updateStyles()
Expand Down
3 changes: 2 additions & 1 deletion src/artisanlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10183,6 +10183,7 @@ def resetApplication(self,_=False):
#raise flag. Next time app will open, the settings (bad settings) will not be loaded.
self.resetqsettings = 1
self.clearExtraDeviceSettingsBackup()
_log.info('Factory reset')
self.close()
elif reply == QMessageBox.StandardButton.Cancel:
return
Expand Down Expand Up @@ -21635,7 +21636,7 @@ def checkTop(self, d, offset, p0, p1, p2, p3, p4, p5, twice=False):
# . average delta after i-2 is negative and twice as high (absolute) as the one before
# d is minimum temperature delta of the two legs after the event to prevent too early recognition based on noise
def BTbreak(self,i,event):
if event in ('DROP','drop'):
if event in {'DROP','drop'}:
offset = self.qmc.btbreak_params['offset_drop']
d = self.qmc.btbreak_params['d_drop']
else: #CHARGE
Expand Down
10 changes: 5 additions & 5 deletions src/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
types-openpyxl==3.1.0.24
types-openpyxl==3.1.0.27
types-protobuf==4.24.0.4
types-psutil==5.9.5.17
types-pyserial==3.5.0.10
types-python-dateutil==2.8.19.14
types-PyYAML==6.0.12.12
types-requests==2.31.0.10
types-setuptools==68.2.0.0
types-setuptools==68.2.0.1
types-urllib3==1.26.25.14
lxml-stubs==0.4.0
mypy==1.6.1
pyright==1.1.333
mypy==1.7.0
pyright==1.1.335
ruff>=0.1.0
pylint==3.0.2
pre-commit>=3.3.3
Expand All @@ -22,7 +22,7 @@ pytest-qt==4.2.0
#pytest-bdd==6.1.1
#pytest-benchmark==4.0.0
#pytest-mock==3.11.1
hypothesis==6.88.1
hypothesis==6.88.4
coverage==7.3.2
coverage-badge==1.1.0
codespell==2.2.6
10 changes: 5 additions & 5 deletions src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
######
# the following commented package versions are read by appveyor.yml and downloaded outside of pip.
#
# pyinstaller==6.1.0; platform_system='Windows'
# pyinstaller==6.2.0; platform_system='Windows'
# libusb==1.2.7.3; platform_system='Windows' #1.2.6.0
# libusb==1.0.26; platform_system='Linux'
#
Expand Down Expand Up @@ -48,15 +48,15 @@ websockets==11.0.3
PyYAML==6.0.1
psutil==5.9.4
typing-extensions==4.8.0; python_version < '3.8' # required for supporting Final and TypeDict on Python <3.8
protobuf==4.24.4
protobuf==4.25.0
numpy==1.24.3; python_version < '3.9' # last Python 3.8 release
numpy==1.26.1; python_version >= '3.9'
numpy==1.26.2; python_version >= '3.9'
scipy==1.10.1; python_version < '3.9' # last Python 3.8 release
scipy==1.11.3; python_version >= '3.9'
wquantiles==0.6
colorspacious==1.1.2
openpyxl==3.1.2
keyring==24.2.0
keyring==24.3.0
prettytable==3.9.0
lxml==4.9.3
matplotlib==3.7.3; python_version < '3.9' # last Python 3.8 release
Expand Down Expand Up @@ -84,7 +84,7 @@ PyQtWebEngine==5.15.6; (sys_platform=='darwin' and platform_release<'20.0') or (
PyQt6==6.6.0; (sys_platform=='darwin' and platform_release>='20.0') or (platform_system=='Windows' and python_version>'3.10') or (platform_system=='Linux' and platform_machine!='aarch64')
PyQt6-WebEngine==6.6.0; (sys_platform=='darwin' and platform_release>='20.0') or (platform_system=='Windows' and python_version>'3.10') or (platform_system=='Linux' and platform_machine!='aarch64')
###
pyinstaller==6.1.0; platform_system=='Linux' # on Windows pyinstaller is separately installed (see above)
pyinstaller==6.2.0; platform_system=='Linux' # on Windows pyinstaller is separately installed (see above)
###
### Qt build tools not part of PyQt but required by build-derived
qt5-tools==5.15.2.1.3; (platform_system=='Windows' and python_version<'3.9')
Expand Down

0 comments on commit 0d88da7

Please sign in to comment.