#!/usr/bin/env python3 import logging import os import sys import time from PySide2.QtCore import QObject, QThread, Signal, Slot from PySide2.QtWidgets import (QApplication, QDialog, QLabel, QLineEdit, QProgressBar, QScrollArea, QTabBar, QVBoxLayout, QFrame, QScroller) import doc_manager 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) self.manager = manager self.signal = LoadDoneSignal() def run(self): self.manager.load() self.signal.sig.emit(self.manager) class Dialog(QDialog): def __init__(self): super(Dialog, self).__init__() self.setWindowTitle("OrgEditor") scrSize = self.screen().size() self.resize(scrSize.width() / 1.5, scrSize.height() / 1.5) self.loader = None self.manager = doc_manager.DocumentManager(DOCS_PATH) layout = QVBoxLayout() # Edit box self.progressBar = QProgressBar() self.progressBar.setRange(0, 0) # Make undetermined layout.addWidget(self.progressBar) self.edit = QLineEdit("", placeholderText='Search for notes') layout.addWidget(self.edit) layout.setSpacing(0) self.results = QScrollArea(widgetResizable=True) layout.addWidget(self.results) QScroller.grabGesture( self.results.viewport(), QScroller.LeftMouseButtonGesture, ) # Options self.tabBar = QTabBar(shape=QTabBar.RoundedSouth) self.tabBar.addTab("Agenda") self.tabBar.addTab("Notes") self.tabBar.addTab("Tasks") self.tabBar.currentChanged.connect(self.update_tab) layout.addWidget(self.tabBar) self.setLayout(layout) self.startLoad() @Slot() def update_tab(self): tabIndex = self.tabBar.currentIndex() if tabIndex == 0: self.loadAgenda() elif tabIndex == 1: self.loadNotes() elif tabIndex == 2: self.loadTasks() def startLoad(self): self.edit.setDisabled(True) self.edit.setVisible(False) self.tabBar.setDisabled(True) self.progressBar.setVisible(True) self.loader = DocumentLoader(self.manager) self.loader.signal.sig.connect(self.longoperationcomplete) self.loading_start_time = time.time() self.loader.start() def endLoad(self): self.edit.setDisabled(False) self.edit.setVisible(True) self.tabBar.setDisabled(False) self.progressBar.setVisible(False) self.update_tab() def longoperationcomplete(self, data): logging.info("Loading complete in {:.3f}s".format(time.time() - self.loading_start_time)) self.endLoad() def loadAgenda(self): agenda = self.manager.get_agenda() old = self.results.layout() if old: print("Deleting old") old.deleteLater() layout = QVBoxLayout() for item in agenda.with_hour: text = "{} {} {}".format( item.scheduled.time, item.state, item.title, ) label = QLabel(text=text) layout.addWidget(label) # if len(agenda.with_hour) > 0 and len(agenda.no_hour) > 0: # layout.addWidget(QSplitter()) for item in agenda.no_hour: text = "{} {} {}".format( item.scheduled.time, item.state, item.title, ) label = QLabel(text=text) layout.addWidget(label) frame = QFrame(self.results) frame.setLayout(layout) self.results.setWidget(frame) def loadNotes(self): logging.warning("loadNotes not yet implemented") def loadTasks(self): logging.warning("loadTasks not yet implemented") # Create the Qt Application if __name__ == '__main__': logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s") app = QApplication(sys.argv) dialog = Dialog() sys.exit(dialog.exec_())