Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a trailing add note button. #68 #76

Merged
merged 1 commit into from
May 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ui.dialog import ConfirmationDialog

from ui.settings import UI_SCALE

from ui.utils import get_font

Expand All @@ -35,6 +36,7 @@ def __init__(self, file_path):
self.load_text_from_file()
self.setFont(get_font(size=16))
self.textChanged.connect(self.save_text_to_file)
# self.save_text_to_file()
self.setAcceptRichText(False)
self.setStyleSheet(
"""
Expand Down Expand Up @@ -62,7 +64,11 @@ def __init__(self, parent=None):
self.addTabButton = QToolButton(self)
self.addTabButton.setText("+")
self.addTabButton.clicked.connect(parent.add_new_tab)
self.setCornerWidget(self.addTabButton, Qt.TopRightCorner)

def movePlusButton(self, no_of_tabs=0):
"""Move the plus button to the correct location."""
w = self.count()
self.addTabButton.move(w * 100, 0)


class JottingDownWindow(QWidget):
Expand Down Expand Up @@ -101,8 +107,7 @@ def __init__(self):
}
"""
)

self.setFixedSize(500, 500)
self.setFixedSize(900 * int(UI_SCALE), 900 * int(UI_SCALE))
self.old_pos = None

def paintEvent(self, event):
Expand All @@ -126,15 +131,18 @@ def load_tabs(self):
self.add_button_to_tab(tabno)

self.tab_widget.setCurrentIndex(config["last_active"])
self.tab_widget.movePlusButton(3)
else:
# If config file doesn't exist, load tabs by iterating over files in the notes folder
# If config file doesn't exist, load tabs by iterating
# over files in the notes folder

for tabno, file_name in enumerate(os.listdir(self.notes_folder)):
if file_name.endswith(".txt"):
file_path = os.path.join(self.notes_folder, file_name)
self.tab_widget.addTab(NoteTab(file_path), file_name)
self.add_button_to_tab(tabno)
# If no tabs are found after loading existing .txt files, add the default "notes" file
# If no tabs are found after loading existing .txt files, add the
# default "notes" file
if self.tab_widget.count() == 0:
self.add_new_tab("notes")

Expand Down Expand Up @@ -171,12 +179,13 @@ def delete_tab(self):
tabid = int(sending_button.objectName()) - 1
file_name = self.tab_widget.tabText(tabid)
dialog = ConfirmationDialog(f"Delete tab {file_name}?")
res=dialog.exec()
res = dialog.exec()
if res:
return
self.tab_widget.removeTab(tabid)
self.delete_tab_text_file(file_name)
self.rename_remaining_buttons()
self.tab_widget.movePlusButton()
self.save_tabs()

def add_new_tab(self, file_name=""):
Expand All @@ -192,7 +201,8 @@ def add_new_tab(self, file_name=""):
if not os.path.exists(file_path):
self.tab_widget.addTab(NoteTab(file_path), file_name)
self.add_button_to_tab(len(self.tab_widget) - 1)
self.save_tabs()
# self.tab_widget.movePlusButton()
self.tab_widget.movePlusButton(self.tab_widget.count())

else:
QMessageBox.warning(
Expand Down