Add base note searching functionality.
This commit is contained in:
parent
df5931aeb7
commit
a8e667dbce
@ -7,7 +7,8 @@ from typing import List
|
||||
import org_rw
|
||||
from org_rw import OrgDoc, OrgTime
|
||||
|
||||
EXTENSIONS = ( ".org", ".org.txt" )
|
||||
EXTENSIONS = (".org", ".org.txt")
|
||||
|
||||
|
||||
def is_today(ot: OrgTime):
|
||||
now = datetime.now()
|
||||
@ -19,10 +20,12 @@ def is_today(ot: OrgTime):
|
||||
|
||||
|
||||
class Agenda:
|
||||
def __init__(self, /,
|
||||
with_hour: List[org_rw.Headline],
|
||||
no_hour: List[org_rw.Headline],
|
||||
):
|
||||
def __init__(
|
||||
self,
|
||||
/,
|
||||
with_hour: List[org_rw.Headline],
|
||||
no_hour: List[org_rw.Headline],
|
||||
):
|
||||
self.with_hour = with_hour
|
||||
self.no_hour = no_hour
|
||||
|
||||
@ -52,7 +55,7 @@ class DocumentManager:
|
||||
# Prune dirs
|
||||
i = 0
|
||||
while i < len(dirs):
|
||||
if dirs[i].startswith('.git'):
|
||||
if dirs[i].startswith(".git"):
|
||||
del dirs[i]
|
||||
else:
|
||||
i += 1
|
||||
@ -79,7 +82,6 @@ class DocumentManager:
|
||||
self.docs = docs
|
||||
|
||||
def get_agenda(self) -> Agenda:
|
||||
|
||||
headline_count = 0
|
||||
items_in_agenda = []
|
||||
now = datetime.now()
|
||||
@ -114,5 +116,27 @@ class DocumentManager:
|
||||
|
||||
return Agenda(
|
||||
with_hour=sorted(items_with_hour, key=lambda x: x.scheduled.time),
|
||||
no_hour=other_items
|
||||
no_hour=other_items,
|
||||
)
|
||||
|
||||
def get_notes(self, query) -> List[org_rw.Headline]:
|
||||
headline_count = 0
|
||||
t0 = datetime.now()
|
||||
notes = []
|
||||
query = [q.lower() for q in query]
|
||||
|
||||
for doc in self.docs:
|
||||
for hl in doc.getAllHeadlines():
|
||||
headline_count += 1
|
||||
|
||||
data = "\n".join(hl.get_contents("raw")).lower()
|
||||
if all([q in data for q in query]):
|
||||
notes.append(hl)
|
||||
|
||||
logging.info(
|
||||
"Filtered {} to {} items in {:.3f}s".format(
|
||||
headline_count, len(notes), (datetime.now() - t0).total_seconds()
|
||||
)
|
||||
)
|
||||
|
||||
return notes
|
||||
|
71
main.py
71
main.py
@ -4,19 +4,23 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import webbrowser
|
||||
|
||||
from PySide2.QtCore import QObject, QThread, Signal, Slot
|
||||
from PySide2.QtWidgets import (QApplication, QDialog, QLabel, QLineEdit, QProgressBar, QScrollArea, QTabBar,
|
||||
QVBoxLayout, QFrame, QScroller, QHBoxLayout, QPushButton, QGroupBox)
|
||||
from PySide2.QtWidgets import (QApplication, QDialog, QFrame, QGroupBox,
|
||||
QHBoxLayout, QLabel, QLineEdit, QProgressBar,
|
||||
QPushButton, QScrollArea, QScroller, QTabBar,
|
||||
QVBoxLayout)
|
||||
|
||||
import doc_manager
|
||||
|
||||
DOCS_PATH = os.environ['ORG_PATH']
|
||||
DOCS_PATH = os.environ["ORG_PATH"]
|
||||
|
||||
|
||||
class LoadDoneSignal(QObject):
|
||||
sig = Signal(doc_manager.DocumentManager)
|
||||
|
||||
|
||||
class DocumentLoader(QThread):
|
||||
def __init__(self, manager):
|
||||
QThread.__init__(self, None)
|
||||
@ -34,8 +38,7 @@ class Dialog(QDialog):
|
||||
|
||||
self.setWindowTitle("OrgEditor")
|
||||
scrSize = self.screen().size()
|
||||
self.resize(scrSize.width() / 1.5,
|
||||
scrSize.height() / 1.5)
|
||||
self.resize(scrSize.width() / 1.5, scrSize.height() / 1.5)
|
||||
self.loader = None
|
||||
self.manager = doc_manager.DocumentManager(DOCS_PATH)
|
||||
|
||||
@ -46,7 +49,7 @@ class Dialog(QDialog):
|
||||
self.progressBar.setRange(0, 0) # Make undetermined
|
||||
layout.addWidget(self.progressBar)
|
||||
|
||||
self.edit = QLineEdit("", placeholderText='Search for notes')
|
||||
self.edit = QLineEdit("", placeholderText="Search for notes")
|
||||
self.edit.textEdited.connect(self.on_text_edited)
|
||||
layout.addWidget(self.edit)
|
||||
|
||||
@ -55,7 +58,8 @@ class Dialog(QDialog):
|
||||
self.results = QScrollArea(widgetResizable=True)
|
||||
layout.addWidget(self.results)
|
||||
QScroller.grabGesture(
|
||||
self.results.viewport(), QScroller.LeftMouseButtonGesture,
|
||||
self.results.viewport(),
|
||||
QScroller.LeftMouseButtonGesture,
|
||||
)
|
||||
|
||||
# Options
|
||||
@ -73,7 +77,10 @@ class Dialog(QDialog):
|
||||
|
||||
@Slot()
|
||||
def on_text_edited(self):
|
||||
self.tabBar.setCurrentIndex(1)
|
||||
if self.tabBar.currentIndex() != 1:
|
||||
self.tabBar.setCurrentIndex(1)
|
||||
else:
|
||||
self.loadNotes()
|
||||
|
||||
@Slot()
|
||||
def update_tab(self):
|
||||
@ -105,7 +112,9 @@ class Dialog(QDialog):
|
||||
self.update_tab()
|
||||
|
||||
def longoperationcomplete(self, data):
|
||||
logging.info("Loading complete in {:.3f}s".format(time.time() - self.loading_start_time))
|
||||
logging.info(
|
||||
"Loading complete in {:.3f}s".format(time.time() - self.loading_start_time)
|
||||
)
|
||||
self.endLoad()
|
||||
|
||||
def loadAgenda(self):
|
||||
@ -141,32 +150,58 @@ class Dialog(QDialog):
|
||||
state_button.setFlat(True)
|
||||
box.addWidget(state_button)
|
||||
|
||||
box.addWidget(
|
||||
QLabel(text=f"{item.scheduled.time}", maximumWidth=200)
|
||||
)
|
||||
box.addWidget(
|
||||
QLabel(text=f"{item.title}")
|
||||
)
|
||||
box.addWidget(QLabel(text=f"{item.scheduled.time}", maximumWidth=200))
|
||||
box.addWidget(QLabel(text=f"{item.title}"))
|
||||
|
||||
def on_clicked():
|
||||
state_button.setText('DONE')
|
||||
state_button.setText("DONE")
|
||||
# state_button.setFlat(True)
|
||||
# item.state = 'DONE'
|
||||
|
||||
if not item.is_done:
|
||||
state_button.clicked.connect(on_clicked)
|
||||
|
||||
return frame
|
||||
|
||||
def build_note_task_widget(self, item):
|
||||
box = QHBoxLayout()
|
||||
frame = QGroupBox()
|
||||
frame.setLayout(box)
|
||||
|
||||
titleButton = QPushButton(text=f"{item.title}")
|
||||
box.addWidget(titleButton)
|
||||
|
||||
def on_clicked():
|
||||
webbrowser.open("org-protocol://org-id?id=" + item.id)
|
||||
|
||||
titleButton.clicked.connect(on_clicked)
|
||||
|
||||
return frame
|
||||
|
||||
def loadNotes(self):
|
||||
logging.warning("loadNotes not yet implemented")
|
||||
query = self.edit.text()
|
||||
notes = self.manager.get_notes(query.split())
|
||||
old = self.results.layout()
|
||||
|
||||
if old:
|
||||
print("Deleting old")
|
||||
old.deleteLater()
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
for note in notes:
|
||||
layout.addWidget(self.build_note_task_widget(note))
|
||||
|
||||
frame = QFrame(self.results)
|
||||
frame.setLayout(layout)
|
||||
self.results.setWidget(frame)
|
||||
|
||||
def loadTasks(self):
|
||||
logging.warning("loadTasks not yet implemented")
|
||||
|
||||
|
||||
# Create the Qt Application
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
Loading…
Reference in New Issue
Block a user