def _actNewLogbookTriggered(self): 'New Logbook Action Event Handler' if self._logbook is not None: dir = os.path.dirname(self._logbookPath) else: dir = os.path.expanduser('~') fn = QFileDialog.getSaveFileName(self, caption=self.tr('Save new Logbook as...'), dir=dir, filter='Logbook Files (*.lbk);;All Files (*.*)')[0] if fn == '': return if os.path.exists(fn): if QMessageBox.question(self, self.tr('Create new Logbook?'), self.tr('Logbook "%s" already exists. Would you like to overwrite it?') % os.path.basename(fn), QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) != QMessageBox.Yes: return # Try and remove the old Logbook file try: os.remove(fn) except: QMessageBox.error(self, self.tr('Cannot remove Logbook'), self.tr('Unable to remove Logbook file "%s". Please delete this file manually.') % os.path.basename(fn), QMessageBox.Ok, QMessageBox.Ok) return # Create a new Logbook File Logbook.Create(fn) self._openLogbook(fn)
def updateFunction(self): """ Updates a function. """ old_func = list(self.selectedTitles(self.ui.listWidgetFunction.selectedItems())) new_func = str(self.ui.lineEditFunction.text()) if len(old_func) != 1: QMessageBox.error(self, self.tr('Update'), self.tr('Please select just one item to update.'), QMessageBox.Ok) elif new_func != '': if self.updateQuestion("function",(new_func,old_func)) == QMessageBox.Yes: self.container.update(function=[(new_func,old_func[0])]) self.writeStatusBar('Function "{}" has already updated to "{}".'.format(old_func[0], new_func)) self.updateFunctionView()
def updateSubSection(self): """ Updates one subsection """ old_subs = list(self.selectedTitles(self.ui.listWidgetSubSection.selectedItems())) new_subs = str(self.ui.lineEditSubSection.text()) if len(old_subs) != 1: QMessageBox.error(self, self.tr('Update'), self.tr('Please select just one item to update.'), QMessageBox.Ok) elif new_subs != '': if self.updateQuestion("subsection",(new_subs,old_subs[0])) == QMessageBox.Yes: self.container.update(subsection=[(new_subs,old_subs[0])]) self.writeStatusBar('Sub section "{}" has already updated to "{}".'.format(old_subs[0], new_subs)) self.updateSubSectionView()