Skip to content

Commit

Permalink
Dump notification, show notification text in item instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadfebrianto committed Jan 5, 2023
1 parent bfead95 commit ec07b80
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ class Constants:

DOUBLE_TAP_INTERVAL = 500
MAX_IMAGE_SIZE = 1024 * 1024

NOTIF_DURATION = 1000
1 change: 1 addition & 0 deletions src/utils/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class String:
NOTIF_COPY_SUCCESS = "OTP code copied to clipboard"
TITLE_DELETE_ENTRY = "Delete entry"
BODY_DELETE_ENTRY = "Are you sure you want to delete this entry?"
OTP_COPIED = "OTP code copied..."

# File: view/widget_add_entry.py
TITLE_ADD_ENTRY = "Add Entry"
Expand Down
32 changes: 21 additions & 11 deletions src/view/widget_list_entry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from time import sleep

from PySide6.QtCore import QElapsedTimer, Qt, Signal
from PySide6.QtCore import QElapsedTimer, Qt, QTimer, Signal
from PySide6.QtWidgets import (
QListWidget,
QMenu,
Expand All @@ -12,7 +11,7 @@
)

from model.db import db
from utils.common import copy_to_clipboard, load_stylesheet, show_notification
from utils.common import copy_to_clipboard, load_stylesheet
from utils.constants import Constants
from utils.strings import String

Expand All @@ -28,7 +27,8 @@ def __init__(self):
self.setWindowTitle(String.APP_NAME)
self.setup_ui()
self.key_pressed = False
self.timer = QElapsedTimer()
self.elapsed_timer = QElapsedTimer()
self.timeout_timer = QTimer()

def setup_ui(self):
# List widget
Expand Down Expand Up @@ -56,11 +56,10 @@ def show_menu(self, position):
def copy_otp_code(self, item=None):
if not item:
item = self.list_widget.currentItem()
otp_code = db.get_otp_code(item.text())
text = item.text()
otp_code = db.get_otp_code(text)
copy_to_clipboard(otp_code)
show_notification(String.APP_NAME, String.NOTIF_COPY_SUCCESS)
sleep(1)
self.otp_copied.emit()
self.notify(item)

def on_menu_export_clicked(self):
chosen_entry = self.list_widget.currentItem().text()
Expand Down Expand Up @@ -116,7 +115,7 @@ def keyPressEvent(self, event):
if self.key_pressed:
# If the elapsed time is less than the threshold,
# copy the item's data to the clipboard
if self.timer.elapsed() < Constants.DOUBLE_TAP_INTERVAL:
if self.elapsed_timer.elapsed() < Constants.DOUBLE_TAP_INTERVAL:
item = self.list_widget.currentItem()
self.copy_otp_code(item)
# Reset the flag and time
Expand All @@ -126,8 +125,19 @@ def keyPressEvent(self, event):
# set the flag to indicate that it has been pressed once
# and start the time
self.key_pressed = True
self.timer.start()
self.elapsed_timer.start()

def reset_key_pressed(self):
self.key_pressed = False
self.timer.invalidate()
self.elapsed_timer.invalidate()

def notify(self, widget):
def update_text():
widget.setText(original_text)
self.timeout_timer.singleShot(
Constants.NOTIF_DURATION, self.otp_copied.emit
)

original_text = widget.text()
widget.setText(String.OTP_COPIED)
self.timeout_timer.singleShot(Constants.NOTIF_DURATION, update_text)

0 comments on commit ec07b80

Please sign in to comment.