def process_note(note): """Builds out note""" if PluginManager().bypass_today(note): return note return "today: " + note
class App(QMainWindow): """QT Application""" def __init__(self): super().__init__() self.title = 'Notes' self.left = 10 self.top = 10 self.width = 920 self.height = 380 self.connection_manager = ConnectionManager() self.plugin_manager = PluginManager() self.logger = get_logger() self.timestamp = timestamp_to_datestring # display elements self.notes_txt = None self.filter_txt = None self.count_label = None self.main_program_loop() def main_program_loop(self): """Main Connection Program Loop""" while True: try: self.init_interface() break except Exception as error: response = QMessageBox.warning( self, 'Notes Error Occured', "%s" % error, QMessageBox.Retry | QMessageBox.Cancel, QMessageBox.Retry) if response == QMessageBox.Cancel: break def init_interface(self): """Sets up base UI""" self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.build_notes_display() self.build_filter_display() self.build_count_display() self.filter_notes() self.logger.debug("[Window] Drawing Window") self.show() self.logger.debug("[Window] Window Drawn") def build_notes_display(self): """Creates Notes UI""" notes_txt = QTextBrowser(self) notes_txt.setReadOnly(True) notes_txt.anchorClicked.connect(self.click_link) notes_txt.setOpenLinks(False) font = QFont('Monospace') notes_txt.setFont(font) self.setStyleSheet(""" QTextEdit, QLineEdit { background-color: #272822; color: #aaa; } QLabel { font-weight: bold; color: #aaa; padding: 5px; } """) self.notes_txt = notes_txt def build_filter_display(self): """Creates Filter UI""" filter_txt = QLineEdit(self) filter_txt.setReadOnly(False) filter_txt.setText('date:today') filter_txt.setFocus() filter_txt.textChanged.connect(self.filter_notes) filter_txt.returnPressed.connect(self.filter_notes) filter_txt.setStyleSheet("border: 0px;") filter_txt.setToolTip("Filter Input") self.filter_txt = filter_txt completer = QCompleter( self.connection_manager.get_primary_connector().get_common_words()) completer.setCompletionMode(QCompleter.PopupCompletion) completer.setCaseSensitivity(Qt.CaseInsensitive) completer.setModelSorting(QCompleter.CaseInsensitivelySortedModel) completer.popup().setStyleSheet(""" QListView { background-color: #272822; color: #aaa; selection-background-color: #511; } """) filter_txt.setCompleter(completer) def build_count_display(self): """Creates Count Lable UI""" count_label = QLabel(self) count_label.setAlignment(Qt.AlignRight) self.count_label = count_label def filter_notes(self): """Displays filtered down notes""" self.logger.debug("[Filter] Filtering Down Notes") self.logger.info("[Filter] Filter Term: %s", self.filter_txt.text()) self.notes_txt.setText('') self.count_label.setText('loading...') text = self.filter_txt.text() if len(text) > 2: terms = [term.strip() for term in text.split(' ')] else: # for repsonsiveness, don't allow sub-3 character searches return connector = self.connection_manager.get_primary_connector() notes = connector.find_notes(terms) self.logger.debug("[Filter] Found %s notes", len(notes)) self.count_label.setText('%s results' % len(notes)) html = '' for timestamp, note in notes: html += "%s<br>" % self.plugin_manager.format_note_line( timestamp, note) self.logger.debug("[Filter] DOM prepared. Drawing") self.notes_txt.insertHtml(html) self.logger.debug("[Filter] Notes Filtered") self.notes_txt.verticalScrollBar().setValue( self.notes_txt.verticalScrollBar().maximum()) def click_link(self, qurl): """Handles Note Clicking""" url = qurl.toString() self.logger.debug("Processing click: %s", url) if url[0:7] == 'filter:': self.filter_txt.setText(url[7:]) self.filter_notes() elif url[0:4] == 'http': webbrowser.open(url, autoraise=True) def resizeEvent(self, event): """Handles resizing""" input_height = 30 self.notes_txt.setGeometry(0, 0, event.size().width(), event.size().height() - input_height) self.filter_txt.setGeometry(0, event.size().height() - input_height, event.size().width(), input_height) self.count_label.setGeometry( event.size().width() - self.count_label.width(), event.size().height() - input_height, self.count_label.width(), input_height)