From 313955f4a58dccac403cfbd129b1da629a3a307c Mon Sep 17 00:00:00 2001 From: chrin Date: Thu, 9 Jan 2025 16:19:57 +0100 Subject: [PATCH] password protected reset button --- hush.json | 3 +- hush.sh | 2 +- src/gui.py | 65 +++++++++++++++++++++++++++++++++---------- src/invisible-eye.svg | 5 ++++ src/passwordedit.py | 65 +++++++++++++++++++++++++++++++++++++++++++ src/visible-eye.svg | 13 +++++++++ summary2004.txt | 11 -------- 7 files changed, 136 insertions(+), 28 deletions(-) create mode 100644 src/invisible-eye.svg create mode 100644 src/passwordedit.py create mode 100644 src/visible-eye.svg delete mode 100644 summary2004.txt diff --git a/hush.json b/hush.json index ee04c3a..c36c49e 100755 --- a/hush.json +++ b/hush.json @@ -111,5 +111,6 @@ }, "IOC": { "resultsTabTitle" : "IOC" - } + }, + "Reset": "HUSH!" } diff --git a/hush.sh b/hush.sh index 1974ac4..6c5b236 100755 --- a/hush.sh +++ b/hush.sh @@ -58,7 +58,7 @@ echo "PYTHON_VERSION $PYTHON_VERSION" #C_EXT version for Py 3.5, 3.7. 3.8, 3.10: -export PYTHONPATH=.:/opt/gfa/cafe/python/pycafe/cafe-1.21.0/lib/${_EPICS_HOST_ARCH}:/hipa/bd/applications/deps/apps4ops/v1.12.0 +export PYTHONPATH=.:/opt/gfa/cafe/python/pycafe/cafe-1.21.0/lib/${_EPICS_HOST_ARCH}:/hipa/bd/applications/deps/apps4ops/v1.13.0 echo $PYTHONPATH diff --git a/src/gui.py b/src/gui.py index cc711af..e9ef755 100644 --- a/src/gui.py +++ b/src/gui.py @@ -15,16 +15,15 @@ from qtpy.QtGui import QColor, QPixmap from qtpy.QtCore import __version__ as QT_VERSION_STR from qtpy.QtCore import QEventLoop, Qt, QTimer, Slot from qtpy.QtWidgets import ( - QApplication, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QMessageBox, - QPushButton, QTabBar, QTabWidget, QTableWidgetItem, QTextEdit, QVBoxLayout, - QWidget) + QApplication, QGridLayout, QGroupBox, QHBoxLayout, QInputDialog, QLabel, + QLineEdit, QMessageBox, QPushButton, QTabBar, QTabWidget, QTableWidgetItem, + QTextEdit, QVBoxLayout, QWidget) try: import elog except: from common.packages import elog - from apps4ops.bdbase.utils import _line from apps4ops.bdbase.enumkind import MsgSeverity @@ -32,6 +31,8 @@ from caqtwidgets.pvwidgets import ( CAQLabel, CAQLineEdit, CAQMessageButton, CAQTableWidget, CAQTextEntry, QHLine) +from src.passwordedit import PasswordEdit + _pymodule = os.path.basename(__file__) @@ -155,7 +156,7 @@ class AppGui(QWidget): label.setFixedHeight(180) label.setPixmap(pixmap) label.setScaledContents(True) - + self.gui_frame.results_layout.addWidget( label, 0, 2, 1, 1, Qt.AlignLeft) self.gui_frame.results_layout.setContentsMargins(10, 40, 10, 10) @@ -1067,18 +1068,52 @@ class AppGui(QWidget): def clear_saving(self, sector_prefix_list: list = None): if not sector_prefix_list: return - qm = QMessageBox() - mess = ("This action will reset the energy saving account to zero. \n" + - "This is typically undertaken at the end of the calendar " + - "year. \n\n" + - "Present accounting figures will be entered in the elogbook\n" + - "Are you sure you wish to continue with the reset?") - reply = qm.warning(self, "Reset Accounting", mess, - QMessageBox.Yes | QMessageBox.No) + + #qm = QMessageBox() + #mess = ("This action will reset the energy saving account to zero. \n" + + # "This is typically undertaken at the end of the calendar " + + # "year. \n\n" + + # "Present accounting figures will be entered in the elogbook\n" + + # "Are you sure you wish to continue with the reset?") + #reply = qm.warning(self, "Reset Accounting", mess, + # QMessageBox.Yes | QMessageBox.No) - if reply == QMessageBox.No: + #if reply == QMessageBox.No: + # return + + + #Now prompt for password + mess = (#"This action will reset the energy\nsaving account to zero.\n" + + #"This is typically undertaken at\nthe end of the calendar " + + #"year.\n" + + #"The current accounting figures\nwill be entered into elog\n " + + "To execute the reset,\nplease enter the password:" + ) + pwedit = QLineEdit() + pwedit.setObjectName("Write") + pwedit.setFixedWidth(40) + pwedit.setFixedHeight(25) + + + qd = QInputDialog() + #qd.resize(500,100) + #qd.setObjectName('Password') + #qd.setWindowFlag(Qt.WindowType.WindowMinimizeButtonHint, False) + + text, ok = qd.getText(pwedit, "Reset Account", mess, + pwedit.Password) + if ok and text: + print(f'ok={ok}, password={text}', flush=True) + if text.upper()!= self.settings.data["Reset"]: + qmb = QMessageBox() + mess = "Incorrect password!\nTry Reset Account once again." + qmb.information(self, "Reset Account", mess) + return + else: return - + + + self.parent.prepare_elog_message() print("message", self.parent.message, flush=True) print("logbook", self.parent.logbook, flush=True) diff --git a/src/invisible-eye.svg b/src/invisible-eye.svg new file mode 100644 index 0000000..25c20a2 --- /dev/null +++ b/src/invisible-eye.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/passwordedit.py b/src/passwordedit.py new file mode 100644 index 0000000..506991a --- /dev/null +++ b/src/passwordedit.py @@ -0,0 +1,65 @@ +import os + +from qtpy import QtGui +from qtpy.QtWidgets import QLineEdit + +class PasswordEdit(QLineEdit): + """ + A LineEdit with icons to show/hide password entries + """ + CSS = '''QLineEdit { + border-radius: 0px; + height: 30px; + margin: 0px 0px 0px 0px; + } + ''' + + def __init__(self, parent): + self.parent = parent + super().__init__(self.parent) + + # Set styles + self.setStyleSheet(self.CSS) + + self.visibleIcon = QtGui.QIcon(':/eye-visible.svg') #QtGui.QIcon(':/eye-visible.svg') #self.load_icon("visible-eye.svg") + self.hiddenIcon = QtGui.QIcon(':/eye-invisible.svg') # QtGui.QIcon(':/eye-invisible.svg') #self.load_icon("invisible-eye.svg") + + self.setEchoMode(QLineEdit.Password) + self.togglepasswordAction = self.addAction( + self.visibleIcon, QLineEdit.TrailingPosition) + self.togglepasswordAction.triggered.connect( + self.on_toggle_password_Action) + self.password_shown = False + print('PasswordEdit init complete') + print(f'on_init {self.visibleIcon} {self.hiddenIcon} {self.password_shown} ', flush=True) + + def load_icon(self, fname_icon): + #path_this_file = os.path.abspath(__file__) + #path_this_dir = os.path.dirname(path_this_file) + #path_icons = os.path.join(path_this_dir, '..', 'media', 'icons') + #path_icon = os.path.join(path_icons, fname_icon) + + #pixmap = QtGui.QPixmap(path_icon) + + pixmap = QtGui.QPixmap(fname_icon) + + pixmap.fill(QtGui.QColor('red')) + #pixmap.setMask(pixmap.createMaskFromColor(QtGui.QColor('black'), QtGui.Qt.MaskOutColor)) + + icon = QtGui.QIcon() + icon.addPixmap(pixmap, QtGui.QIcon.Normal) + icon.addPixmap(pixmap, QtGui.QIcon.Disabled) + + return icon + + def on_toggle_password_Action(self): + if not self.password_shown: + self.setEchoMode(QLineEdit.Normal) + self.password_shown = True + self.togglepasswordAction.setIcon(self.hiddenIcon) + else: + self.setEchoMode(QLineEdit.Password) + self.password_shown = False + self.togglepasswordAction.setIcon(self.visibleIcon) + + print(f'on_toggle {self.visibleIcon} {self.hiddenIcon} {self.password_shown} {QLineEdit.Password}', flush=True) diff --git a/src/visible-eye.svg b/src/visible-eye.svg new file mode 100644 index 0000000..c636593 --- /dev/null +++ b/src/visible-eye.svg @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/summary2004.txt b/summary2004.txt deleted file mode 100644 index 8adb910..0000000 --- a/summary2004.txt +++ /dev/null @@ -1,11 +0,0 @@ -Summary for 2024 - -Power saved for the current year stands at 1516.412 MWh: -IP2: 314.258 MWh -IW2: 91.529 MWh -PK1: 86.399 MWh -PK2: 393.997 MWh -SNQ: 178.202 MWh -UCN: 452.027 MWh ------------------- -Tot: 1516.412 MWh