def closeEvent(self, event): # Save notebooks self.save() # Save state and geometries s = F.settings() s.setValue("geometry", self.saveGeometry()) s.setValue("windowState", self.saveState()) # Save filter visibily fv = [] for t, w in [ ("filter", self.actViewFilterPanel), ("toolbar", self.actViewToolbar), ("calendar", self.actToggleCalendar), ("tags", self.actToggleTags), ("words", self.actToggleWords), ("list", self.actToggleList), ]: if w.isChecked(): fv.append(t) s.setValue("filterVisible", ",".join(fv)) # Save openned notebooks p = [] for nb in self.notebooks: p.append(nb.path) F.settings().setValue("OpenLastNotebooks", "\n".join(p)) QWidget.closeEvent(self, event)
def openPreviousNotebooks(self): if F.settings("OpenLast", Qt.Checked, int): last = F.settings("OpenLastNotebooks", "", str).split("\n") for path in last: if not path: continue self.openNotebook(path) # We call that in case no notebooks were openend self.setupNotebooks()
def getRecents(self): s = F.settings() r = s.value("recentNotebooks", "") recents = [] if r: r = r.split("\n") while r: path = r.pop() name = r.pop() if os.path.exists(path): recents.append((name, path)) return recents
def run(): global MW app = QApplication(sys.argv) app.setOrganizationName("noteflow") app.setOrganizationDomain("www.theologeek.ch") app.setApplicationName("noteflow") app.setApplicationVersion(_version) #icon = QIcon() #for i in [16, 31, 64, 128, 256, 512]: #icon.addFile(appPath("icons/noteflow/icon-{}px.png".format(i))) #qApp.setWindowIcon(icon) #app.setStyle("fusion") # # # Load style from QSettings settings = F.settings() # if settings.contains("applicationStyle"): # style = settings.value("applicationStyle") # app.setStyle(style) # Translation process locale = QLocale.system().name() appTranslator = QTranslator() # By default: locale translation = F.appPath( os.path.join("i18n", "noteflow_{}.qm".format(locale))) # Load translation from settings if settings.contains("applicationTranslation"): translation = F.appPath( os.path.join("i18n", settings.value("applicationTranslation"))) print("Found translation in settings:", translation) if appTranslator.load(translation): app.installTranslator(appTranslator) print(app.tr("Loaded translation: {}.").format(translation)) else: pass # qDebug(app.tr("Warning: failed to load translator for locale {}...").format(locale)) # print(QIcon.themeSearchPaths()) QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + [F.appPath("icons")]) QIcon.setThemeName("Mint-X") # qApp.setWindowIcon(QIcon.fromTheme("im-aim")) # Seperating launch to avoid segfault, so it seem. # Cf. http://stackoverflow.com/questions/12433491/is-this-pyqt-4-python-bug-or-wrongly-behaving-code launch()
def addToRecentNotebooks(self, nb): if not nb.name or not nb.path: return recents = self.getRecents() if (nb.name, nb.path) in recents: return recents.append((nb.name, nb.path)) val = "\n".join(["{}\n{}".format(name, path) for name, path in recents]) s = F.settings() s.setValue("recentNotebooks", val) self.loadRecents()
def __init__(self): QMainWindow.__init__(self) self.setupUi(self) #============================================================================== # UI Stuff #============================================================================== self.splitter.setStretchFactor(0, 0) self.splitter.setStretchFactor(1, 12) for w in [ self.lstTags, self.lstWords]: w.setStyleSheet("QListWidget{{{}}}".format(S.transparentSS())) self.setStyleSheet(S.mainWindowSS()) self.txtFilter.setStyleSheet(S.lineEditSS_2()) self.txtDate.setStyleSheet("background:transparent;") #self.tab.setStyleSheet(S.tabBarSS()) self.text.setStyleSheet(S.textEditorSS()) self.tab.setShape(self.tab.RoundedWest) self.tblList.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents) self.tblList.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch) self.tblList.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents) # Toggle filters self.actViewFilterPanel.toggled.connect(self.filter.setVisible) #self.actViewFilterPanel.toggled.connect(self.wdgTab.setVisible) self.actToggleCalendar.toggled.connect(self.wdgCalendar.setVisible) self.actToggleTags.toggled.connect(self.lstTags.setVisible) self.actToggleWords.toggled.connect(self.lstWords.setVisible) self.actToggleList.toggled.connect(self.grpNotes.setVisible) self.actViewToolbar.toggled.connect(self.toolBar.setVisible) self.toolBar.visibilityChanged.connect(self.actViewToolbar.setChecked) ## Buttons widget in status bar... #w = QWidget() #l = QHBoxLayout(w) #l.setSpacing(0) #self.btnToggleCalendar = QToolButton() #self.btnToggleTags = QToolButton() #self.btnToggleWords = QToolButton() #self.btnToggleList = QToolButton() #for btn, act in [ #(self.btnToggleCalendar, self.actToggleCalendar), #(self.btnToggleTags, self.actToggleTags), #(self.btnToggleWords, self.actToggleWords), #(self.btnToggleList, self.actToggleList), #]: #btn.setDefaultAction(act) #l.addWidget(btn) #self.statusBar().addWidget(w) ##w.setStyleSheet("QToolButton{border: 1px solid;}") self.lblStats = LabelTextStats() self.statusBar().addPermanentWidget(self.lblStats) self.text.statsChanged.connect(self.lblStats.setStats) self.lblNoteDate = LabelDate() self.statusBar().addPermanentWidget(self.lblNoteDate) self.lblNoteDate.hide() # Connections self.txtFilter.textChanged.connect(self.filterNotes) self.tab.currentChanged.connect(self.setupFilters) #self.tab.currentChanged.connect(self.filterNotes) self.tab.currentChanged.connect(self.updateUI) self.tab.tabBarDoubleClicked.connect(self.changeNotebookName) self.lstTags.itemSelectionChanged.connect(self.filterNotes) self.lstWords.itemSelectionChanged.connect(self.filterNotes) self.tblList.itemSelectionChanged.connect(self.listNoteActivated) self.calendar.selectionChanged.connect(self.calendarChanged) self.btnDateClear.clicked.connect(self.calendarCleared) self.wdgDateInfos.hide() self.scroll.noteSelected.connect(self.tblSelectRow) #self.scroll.noteActivated.connect(lambda i:self.tblSelectRow(i, False)) self.scroll.noteActivated.connect(self.tblChangeRow) self.tblList.hideColumn(2) self.tblList.setStyleSheet(S.tableSS()) self.actNewNotebook.triggered.connect(self.newNotebook) self.actOpenNotebook.triggered.connect(self.openNotebookDialog) self.actCloseCurrent.triggered.connect(self.closeCurrentNotebook) self.actSaveAll.triggered.connect(self.save) self.dateA = None self.dateB = None self.actPreferences.triggered.connect(self.popupPreferences) self.actNoteUp.triggered.connect(self.navigateUp) self.actNoteDown.triggered.connect(self.navigateDown) self.actNotePrevious.triggered.connect(self.navigatePrevious) self.actNotePrevious.setEnabled(False) self.actNoteNext.triggered.connect(self.navigateNext) self.actNoteNext.setEnabled(False) self.actNoteNew.triggered.connect(self.newNote) self.actNoteDelete.triggered.connect(self.deleteNote) self.actNoteDelete.setEnabled(False) self.actNotePreview.triggered.connect(self.previewNote) self.actNotePreview.setEnabled(False) self.actFormatBold.triggered.connect(self.text.bold) self.actFormatItalic.triggered.connect(self.text.italic) self.actFormatStrike.triggered.connect(self.text.strike) self.actFormatVerbatim.triggered.connect(self.text.verbatim) self.actFormatComment.triggered.connect(self.text.comment) self.actFormatCommentLine.triggered.connect(self.text.commentLine) self.actFormatSuperScript.triggered.connect(self.text.superscript) self.actFormatSubScript.triggered.connect(self.text.subscript) self.actFormatClear.triggered.connect(self.text.clearFormat) self.actFormatHeaderSetext1.triggered.connect(lambda: self.text.titleSetext(1)) self.actFormatHeaderSetext1.setShortcut("Ctrl+Alt+1") self.actFormatHeaderSetext2.triggered.connect(lambda: self.text.titleSetext(2)) self.actFormatHeaderSetext2.setShortcut("Ctrl+Alt+2") self.actFormatHeaderATX1.triggered.connect(lambda: self.text.titleATX(1)) self.actFormatHeaderATX2.triggered.connect(lambda: self.text.titleATX(2)) self.actFormatHeaderATX3.triggered.connect(lambda: self.text.titleATX(3)) self.actFormatHeaderATX4.triggered.connect(lambda: self.text.titleATX(4)) self.actFormatHeaderATX5.triggered.connect(lambda: self.text.titleATX(5)) self.actFormatHeaderATX6.triggered.connect(lambda: self.text.titleATX(6)) # Add some status tips self.tab.setStatusTip("CTRL+Tab to cycle through open notebooks. (CTRL+Shift+Tab to cycle backward)") self.calendar.setStatusTip("Click on a date to filter that date. " + "Then Shift-click an other date to select a range.") # Shortcuts for tab navigation QShortcut("Ctrl+Tab", self).activated.connect(lambda: self.tab.setCurrentIndex((self.tab.currentIndex() + 1) % self.tab.count()) if self.tab.isVisible() else None) QShortcut("Ctrl+Shift+Tab", self).activated.connect(lambda: self.tab.setCurrentIndex((self.tab.currentIndex() - 1) % self.tab.count()) if self.tab.isVisible() else None) self.updateUIforNoteOpen(False) self.loadRecents() self.editor.setCurrentIndex(0) # PREVIEW settings = self.web.settings() # settings.setFontFamily(QtWebKit.QWebSettings.StandardFont, 'Times New Roman') settings.setFontSize(settings.DefaultFontSize, 13) self.html.anchorClicked.connect(self.previewNavigateLink) self.web.linkClicked.connect(self.previewNavigateLink) self.html.setOpenLinks(False) # NOTEBOOKS AND NOTES self.notebooks = [] self.notes = [] # filtered notes self.history = [] # history of openned notes self.historyPos = 0 # CUSTOM TAGS & WORDS self.tags = TagCollector() self.tags.tagsChanged.connect(self.tagsChanged) self.minWordSize = 3 self.hiddenWords = [] self.preferences = Preferences(self) # Dialog self.customTag = None # Dialog # self.lstWords._minValue = 3 self.lstTags.setCustomTags(self.tags) self.tblList.setCustomTags(self.tags) # Load settings s = F.settings() if s.value("geometry"): self.restoreGeometry(s.value("geometry")) self.restoreState(s.value("windowState")) # Filter visibily fv = s.value("filterVisible", "").split(",") for t, w in [ ("filter", self.actViewFilterPanel), ("toolbar", self.actViewToolbar), ("calendar", self.actToggleCalendar), ("tags", self.actToggleTags), ("words", self.actToggleWords), ("list", self.actToggleList), ]: if t in fv: w.setChecked(True) w.toggled.emit(True) else: w.setChecked(False) w.toggled.emit(False) # Previous notebooks self.openPreviousNotebooks() # Debug self.text.cursorPositionChanged.connect(lambda: self.message( "Block state: {}".format(self.text.textCursor().block().userState())))