Skip to content

Commit

Permalink
Update ui
Browse files Browse the repository at this point in the history
Add basic keybinds
  • Loading branch information
rakshith111 committed Jul 14, 2023
1 parent 3e1de5e commit fd91679
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
26 changes: 23 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import sys
from PyQt6.QtWidgets import QMainWindow, QApplication, QFrame, QLabel, QTextEdit, QPushButton, QGridLayout, QDialog,QMessageBox
from PyQt6.QtGui import QPixmap, QIcon
from PyQt6.QtCore import Qt
from PyQt6.QtCore import Qt,QEvent, QStandardPaths


from ui_generated.basic import Ui_CopyPasta
from add_widget import AddEditDialog
from PyQt6.QtCore import QStandardPaths

class MainWindow(QMainWindow, Ui_CopyPasta):
def __init__(self):
Expand All @@ -17,7 +16,8 @@ def __init__(self):
self.add_field.clicked.connect(self.show_add_dialog)
self.basic_frame_template.hide()
self.clipboard = QApplication.clipboard()
self.data_dir = os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation), 'user_data')
self.data_dir = os.path.normpath(os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation), 'user_data'))

os.makedirs(self.data_dir, exist_ok=True)
self.data_file = os.path.join(self.data_dir, "data.json")
self.search_field.setPlaceholderText("Search Field...")
Expand All @@ -29,8 +29,24 @@ def __init__(self):
self.resource_path()
self.search_btn.clicked.connect(self.search_entries)
self.reset_btn.clicked.connect(self.reset_search)
self.search_field.installEventFilter(self)

def eventFilter(self, obj, event):
if event.type() == QEvent.Type.KeyPress:
if obj is self.search_field:
if event.key() == Qt.Key.Key_Return or event.key() == Qt.Key.Key_Enter:
self.search_entries()
return True
elif isinstance(obj, AddEditDialog):
if event.key() == Qt.Key.Key_Return or event.key() == Qt.Key.Key_Enter:
obj.accept()
return True
return super().eventFilter(obj, event)

def search_entries(self):
'''
Searches the entries.
'''
search_text = self.search_field.toPlainText().strip().lower()

if not search_text:
Expand All @@ -45,6 +61,10 @@ def search_entries(self):
frame.setVisible(False)

def reset_search(self):
'''
Resets the search field.
And shows all the entries.
'''
self.search_field.clear()

for frame in self.frames:
Expand Down
8 changes: 4 additions & 4 deletions src/ui_files/basic.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
</property>
<property name="minimumSize">
<size>
<width>500</width>
<width>480</width>
<height>120</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<width>480</width>
<height>120</height>
</size>
</property>
Expand Down Expand Up @@ -203,13 +203,13 @@
<widget class="QFrame" name="basic_frame_template">
<property name="minimumSize">
<size>
<width>470</width>
<width>480</width>
<height>90</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>470</width>
<width>480</width>
<height>90</height>
</size>
</property>
Expand Down
4 changes: 2 additions & 2 deletions src/ui_generated/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def setupUi(self, CopyPasta):
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
self.frame.setSizePolicy(sizePolicy)
self.frame.setMinimumSize(QtCore.QSize(500, 120))
self.frame.setMaximumSize(QtCore.QSize(500, 120))
self.frame.setMinimumSize(QtCore.QSize(480, 120))
self.frame.setMaximumSize(QtCore.QSize(480, 120))
self.frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame.setObjectName("frame")
Expand Down

0 comments on commit fd91679

Please sign in to comment.