From 60f47546c29d80114fe27395586206a36a1e9bf8 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Sat, 13 May 2023 23:12:29 +0100 Subject: [PATCH 1/4] Hide the API key field as a password and add a show/show button --- comictaggerlib/ui/talkeruigenerator.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/comictaggerlib/ui/talkeruigenerator.py b/comictaggerlib/ui/talkeruigenerator.py index ff5e5b5..e2eca93 100644 --- a/comictaggerlib/ui/talkeruigenerator.py +++ b/comictaggerlib/ui/talkeruigenerator.py @@ -40,6 +40,14 @@ def generate_api_widgets( else: QtWidgets.QMessageBox.warning(None, "API Test Failed", check_text) + def show_key(le_key: QtWidgets.QLineEdit) -> None: + current_state = le_key.echoMode() + + if current_state == 0: + le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.PasswordEchoOnEdit) + else: + le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal) + # get the actual config objects in case they have overwritten the default talker_key = config[1][f"talker_{talker_id}"][1][f"{talker_id}_key"] talker_url = config[1][f"talker_{talker_id}"][1][f"{talker_id}_url"] @@ -50,8 +58,9 @@ def generate_api_widgets( # only file settings are saved if talker_key.file: # record the current row so we know where to add the button - btn_test_row = layout.rowCount() + btn_show_key = layout.rowCount() le_key = generate_textbox(talker_key, layout) + le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.PasswordEchoOnEdit) # To enable setting and getting sources["tabs"][talker_id].widgets[f"talker_{talker_id}_{talker_id}_key"] = le_key @@ -64,6 +73,12 @@ def generate_api_widgets( # To enable setting and getting sources["tabs"][talker_id].widgets[f"talker_{talker_id}_{talker_id}_url"] = le_url + # The key button row was recorded so we add the show/hide button + if btn_show_key is not None: + btn_show = QtWidgets.QPushButton("Show/Hide") + layout.addWidget(btn_show, btn_show_key, 2) + btn_show.clicked.connect(partial(show_key, le_key=le_key)) + # The button row was recorded so we add it if btn_test_row is not None: btn = QtWidgets.QPushButton("Test API") From 5996bd35886395ab1884a7cf8ed5b1a936dbab3f Mon Sep 17 00:00:00 2001 From: Mizaki Date: Mon, 15 May 2023 23:46:16 +0100 Subject: [PATCH 2/4] Add show/hide icon to key field --- comictaggerlib/graphics/eye.svg | 102 ++++++++++++++++++++++++ comictaggerlib/graphics/hidden.svg | 106 +++++++++++++++++++++++++ comictaggerlib/ui/talkeruigenerator.py | 25 +++--- 3 files changed, 224 insertions(+), 9 deletions(-) create mode 100644 comictaggerlib/graphics/eye.svg create mode 100644 comictaggerlib/graphics/hidden.svg diff --git a/comictaggerlib/graphics/eye.svg b/comictaggerlib/graphics/eye.svg new file mode 100644 index 0000000..8f1cf36 --- /dev/null +++ b/comictaggerlib/graphics/eye.svg @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/comictaggerlib/graphics/hidden.svg b/comictaggerlib/graphics/hidden.svg new file mode 100644 index 0000000..c722e1a --- /dev/null +++ b/comictaggerlib/graphics/hidden.svg @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/comictaggerlib/ui/talkeruigenerator.py b/comictaggerlib/ui/talkeruigenerator.py index e2eca93..0441f32 100644 --- a/comictaggerlib/ui/talkeruigenerator.py +++ b/comictaggerlib/ui/talkeruigenerator.py @@ -6,8 +6,9 @@ from functools import partial from typing import Any, NamedTuple import settngs -from PyQt5 import QtCore, QtWidgets +from PyQt5 import QtCore, QtGui, QtWidgets +from comictaggerlib.graphics import graphics_path from comictalker.comictalker import ComicTalker logger = logging.getLogger(__name__) @@ -40,13 +41,18 @@ def generate_api_widgets( else: QtWidgets.QMessageBox.warning(None, "API Test Failed", check_text) - def show_key(le_key: QtWidgets.QLineEdit) -> None: + visibleIcon = QtGui.QIcon(str(graphics_path / "eye.svg")) + hiddenIcon = QtGui.QIcon(str(graphics_path / "hidden.svg")) + + def show_key(le_key: QtWidgets.QLineEdit, le_action: QtWidgets.QAction) -> None: current_state = le_key.echoMode() if current_state == 0: le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.PasswordEchoOnEdit) + le_action.setIcon(visibleIcon) else: le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal) + le_action.setIcon(hiddenIcon) # get the actual config objects in case they have overwritten the default talker_key = config[1][f"talker_{talker_id}"][1][f"{talker_id}_key"] @@ -58,9 +64,16 @@ def generate_api_widgets( # only file settings are saved if talker_key.file: # record the current row so we know where to add the button - btn_show_key = layout.rowCount() + btn_test_row = layout.rowCount() le_key = generate_textbox(talker_key, layout) + + # Generate show/hide icon for key/password within the text box le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.PasswordEchoOnEdit) + + le_key_toggle = le_key.addAction(visibleIcon, QtWidgets.QLineEdit.TrailingPosition) + le_key_toggle.setToolTip("Show/Hide") + le_key_toggle.triggered.connect(partial(show_key, le_key=le_key, le_action=le_key_toggle)) + # To enable setting and getting sources["tabs"][talker_id].widgets[f"talker_{talker_id}_{talker_id}_key"] = le_key @@ -73,12 +86,6 @@ def generate_api_widgets( # To enable setting and getting sources["tabs"][talker_id].widgets[f"talker_{talker_id}_{talker_id}_url"] = le_url - # The key button row was recorded so we add the show/hide button - if btn_show_key is not None: - btn_show = QtWidgets.QPushButton("Show/Hide") - layout.addWidget(btn_show, btn_show_key, 2) - btn_show.clicked.connect(partial(show_key, le_key=le_key)) - # The button row was recorded so we add it if btn_test_row is not None: btn = QtWidgets.QPushButton("Test API") From 057725c5da0e7c9032cf5985d8bcaab129431182 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Tue, 16 May 2023 00:25:12 +0100 Subject: [PATCH 3/4] Create generate_password_textbox --- comictaggerlib/ui/talkeruigenerator.py | 67 ++++++++++++++++++-------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/comictaggerlib/ui/talkeruigenerator.py b/comictaggerlib/ui/talkeruigenerator.py index 0441f32..4a700c5 100644 --- a/comictaggerlib/ui/talkeruigenerator.py +++ b/comictaggerlib/ui/talkeruigenerator.py @@ -41,19 +41,6 @@ def generate_api_widgets( else: QtWidgets.QMessageBox.warning(None, "API Test Failed", check_text) - visibleIcon = QtGui.QIcon(str(graphics_path / "eye.svg")) - hiddenIcon = QtGui.QIcon(str(graphics_path / "hidden.svg")) - - def show_key(le_key: QtWidgets.QLineEdit, le_action: QtWidgets.QAction) -> None: - current_state = le_key.echoMode() - - if current_state == 0: - le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.PasswordEchoOnEdit) - le_action.setIcon(visibleIcon) - else: - le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal) - le_action.setIcon(hiddenIcon) - # get the actual config objects in case they have overwritten the default talker_key = config[1][f"talker_{talker_id}"][1][f"{talker_id}_key"] talker_url = config[1][f"talker_{talker_id}"][1][f"{talker_id}_url"] @@ -65,14 +52,7 @@ def generate_api_widgets( if talker_key.file: # record the current row so we know where to add the button btn_test_row = layout.rowCount() - le_key = generate_textbox(talker_key, layout) - - # Generate show/hide icon for key/password within the text box - le_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.PasswordEchoOnEdit) - - le_key_toggle = le_key.addAction(visibleIcon, QtWidgets.QLineEdit.TrailingPosition) - le_key_toggle.setToolTip("Show/Hide") - le_key_toggle.triggered.connect(partial(show_key, le_key=le_key, le_action=le_key_toggle)) + le_key = generate_password_textbox(talker_key, layout) # To enable setting and getting sources["tabs"][talker_id].widgets[f"talker_{talker_id}_{talker_id}_key"] = le_key @@ -140,6 +120,51 @@ def generate_textbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> return widget +def generate_password_textbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> QtWidgets.QLineEdit: + class PasswordEdit(QtWidgets.QLineEdit): + """ + Password LineEdit with icons to show/hide password entries. + Taken from https://github.com/pythonguis/python-qtwidgets/tree/master/qtwidgets + Based on this example https://kushaldas.in/posts/creating-password-input-widget-in-pyqt.html by Kushal Das. + """ + + def __init__(self, show_visibility=True, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.visibleIcon = QtGui.QIcon(str(graphics_path / "eye.svg")) + self.hiddenIcon = QtGui.QIcon(str(graphics_path / "hidden.svg")) + + self.setEchoMode(QtWidgets.QLineEdit.Password) + + if show_visibility: + # Add the password hide/shown toggle at the end of the edit box. + self.togglepasswordAction = self.addAction(self.visibleIcon, QtWidgets.QLineEdit.TrailingPosition) + self.togglepasswordAction.setToolTip("Show/Hide") + self.togglepasswordAction.triggered.connect(self.on_toggle_password_Action) + + self.password_shown = False + + def on_toggle_password_Action(self): + if not self.password_shown: + self.setEchoMode(QtWidgets.QLineEdit.Normal) + self.password_shown = True + self.togglepasswordAction.setIcon(self.hiddenIcon) + else: + self.setEchoMode(QtWidgets.QLineEdit.Password) + self.password_shown = False + self.togglepasswordAction.setIcon(self.visibleIcon) + + row = layout.rowCount() + lbl = QtWidgets.QLabel(option.display_name) + lbl.setToolTip(option.help) + layout.addWidget(lbl, row, 0) + widget = PasswordEdit() + widget.setToolTip(option.help) + layout.addWidget(widget, row, 1) + + return widget + + def settings_to_talker_form(sources: dict[str, QtWidgets.QWidget], config: settngs.Config[settngs.Namespace]) -> None: # Set the active talker via id in sources combo box sources["cbx_select_talker"].setCurrentIndex(sources["cbx_select_talker"].findData(config[0].talker_source)) From 2da64fd52d4e5cec0ba609f0401fb5c86bd0db32 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Tue, 16 May 2023 15:20:45 +0100 Subject: [PATCH 4/4] Remove password class from function --- comictaggerlib/ui/talkeruigenerator.py | 69 ++++++++++++++------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/comictaggerlib/ui/talkeruigenerator.py b/comictaggerlib/ui/talkeruigenerator.py index 4a700c5..b6d8f1d 100644 --- a/comictaggerlib/ui/talkeruigenerator.py +++ b/comictaggerlib/ui/talkeruigenerator.py @@ -19,6 +19,42 @@ class TalkerTab(NamedTuple): widgets: dict[str, QtWidgets.QWidget] +class PasswordEdit(QtWidgets.QLineEdit): + """ + Password LineEdit with icons to show/hide password entries. + Taken from https://github.com/pythonguis/python-qtwidgets/tree/master/qtwidgets + Based on this example https://kushaldas.in/posts/creating-password-input-widget-in-pyqt.html by Kushal Das. + """ + + def __init__(self, show_visibility=True, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.visibleIcon = QtGui.QIcon(str(graphics_path / "eye.svg")) + self.hiddenIcon = QtGui.QIcon(str(graphics_path / "hidden.svg")) + + self.setEchoMode(QtWidgets.QLineEdit.Password) + + if show_visibility: + # Add the password hide/shown toggle at the end of the edit box. + self.togglepasswordAction = self.addAction(self.visibleIcon, QtWidgets.QLineEdit.TrailingPosition) + self.togglepasswordAction.setToolTip("Show password") + self.togglepasswordAction.triggered.connect(self.on_toggle_password_Action) + + self.password_shown = False + + def on_toggle_password_Action(self): + if not self.password_shown: + self.setEchoMode(QtWidgets.QLineEdit.Normal) + self.password_shown = True + self.togglepasswordAction.setIcon(self.hiddenIcon) + self.togglepasswordAction.setToolTip("Hide password") + else: + self.setEchoMode(QtWidgets.QLineEdit.Password) + self.password_shown = False + self.togglepasswordAction.setIcon(self.visibleIcon) + self.togglepasswordAction.setToolTip("Show password") + + def generate_api_widgets( talker_id: str, sources: dict[str, QtWidgets.QWidget], @@ -121,39 +157,6 @@ def generate_textbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> def generate_password_textbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> QtWidgets.QLineEdit: - class PasswordEdit(QtWidgets.QLineEdit): - """ - Password LineEdit with icons to show/hide password entries. - Taken from https://github.com/pythonguis/python-qtwidgets/tree/master/qtwidgets - Based on this example https://kushaldas.in/posts/creating-password-input-widget-in-pyqt.html by Kushal Das. - """ - - def __init__(self, show_visibility=True, *args, **kwargs): - super().__init__(*args, **kwargs) - - self.visibleIcon = QtGui.QIcon(str(graphics_path / "eye.svg")) - self.hiddenIcon = QtGui.QIcon(str(graphics_path / "hidden.svg")) - - self.setEchoMode(QtWidgets.QLineEdit.Password) - - if show_visibility: - # Add the password hide/shown toggle at the end of the edit box. - self.togglepasswordAction = self.addAction(self.visibleIcon, QtWidgets.QLineEdit.TrailingPosition) - self.togglepasswordAction.setToolTip("Show/Hide") - self.togglepasswordAction.triggered.connect(self.on_toggle_password_Action) - - self.password_shown = False - - def on_toggle_password_Action(self): - if not self.password_shown: - self.setEchoMode(QtWidgets.QLineEdit.Normal) - self.password_shown = True - self.togglepasswordAction.setIcon(self.hiddenIcon) - else: - self.setEchoMode(QtWidgets.QLineEdit.Password) - self.password_shown = False - self.togglepasswordAction.setIcon(self.visibleIcon) - row = layout.rowCount() lbl = QtWidgets.QLabel(option.display_name) lbl.setToolTip(option.help)