def forceUpdateWindow(self): """Update an alternate window that shows the same file""" oldWin = globalref.mainWin oldWin.saveMultiWinTree() for win in self.duplicateWindows(): globalref.updateRefs(win) win.updateMultiWinTree() globalref.updateRefs(oldWin) oldWin.updateMultiWinTree()
def openFile(self, filePath, newWinOk=True, importOnFail=True, addToRecent=True): """Open given file, fail quietly if not importOnFail, return True on success or user cancel, return False on failure (to remove from recent files)""" if self.matchingWindows(filePath): win = self.matchingWindows(filePath)[0] win.activateWindow() win.raise_() return True oldWin = globalref.mainWin if newWinOk and globalref.options.boolData('OpenNewWindow') and \ (globalref.docRef.fileName or globalref.docRef.modified): win = treemainwin.TreeMainWin() else: win = globalref.mainWin if not self.checkAutoSave(filePath): return True QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) try: win.doc = treedoc.TreeDoc(filePath) win.fileImported = False except treedoc.PasswordError: QtGui.QApplication.restoreOverrideCursor() dlg = treedialogs.PasswordEntry(False, win) if dlg.exec_() != QtGui.QDialog.Accepted: globalref.updateRefs(oldWin) return True win.doc.setPassword(filePath, dlg.password) result = self.openFile(filePath, False, importOnFail) if not dlg.saveIt: win.doc.clearPassword(filePath) return result except (IOError, UnicodeError): QtGui.QApplication.restoreOverrideCursor() QtGui.QMessageBox.warning(win, 'TreeLine', _('Error - could not read file "%s"') % filePath) globalref.updateRefs(oldWin) return False except treedoc.ReadFileError, e: QtGui.QApplication.restoreOverrideCursor() if not importOnFail: globalref.updateRefs(oldWin) return True # assume file is not a TreeLine file importType = self.chooseImportType() if not importType: globalref.updateRefs(oldWin) return True try: QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) win.doc = treedoc.TreeDoc(filePath, False, importType) except treedoc.ReadFileError, e: QtGui.QApplication.restoreOverrideCursor() QtGui.QMessageBox.warning(win, 'TreeLine', _('Error - %s') % e) globalref.updateRefs(oldWin) return False
def updateFocus(self): """Check for focus change to a different main window""" win = QtGui.QApplication.activeWindow() while win and win.parent(): win = win.parent() if win and win != globalref.mainWin and win in self.windowList: oldWin = globalref.mainWin if self.duplicateWindows(): oldWin.saveMultiWinTree() globalref.updateRefs(win) self.recentFiles.updateMenu() self.updateWinMenu() if self.duplicateWindows(): win.updateMultiWinTree() win.updateNonModalDialogs()
def openFile(self, filePath, newWinOk=True, importOnFail=True, addToRecent=True): """Open given file, fail quietly if not importOnFail, return True on success or user cancel, return False on failure (to remove from recent files)""" if self.matchingWindows(filePath): win = self.matchingWindows(filePath)[0] win.activateWindow() win.raise_() return True oldWin = globalref.mainWin if newWinOk and globalref.options.boolData('OpenNewWindow') and \ (globalref.docRef.fileName or globalref.docRef.modified): win = treemainwin.TreeMainWin() else: win = globalref.mainWin if not self.checkAutoSave(filePath): return True QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) try: win.doc = treedoc.TreeDoc(filePath) win.fileImported = False except treedoc.PasswordError: QtGui.QApplication.restoreOverrideCursor() dlg = treedialogs.PasswordEntry(False, win) if dlg.exec_() != QtGui.QDialog.Accepted: globalref.updateRefs(oldWin) return True win.doc.setPassword(filePath, dlg.password) result = self.openFile(filePath, False, importOnFail) if not dlg.saveIt: win.doc.clearPassword(filePath) return result except (IOError, UnicodeError): QtGui.QApplication.restoreOverrideCursor() QtGui.QMessageBox.warning(win, 'TreeLine', _('Error - could not read file "%s"') % filePath) globalref.updateRefs(oldWin) return False except treedoc.ReadFileError, e: QtGui.QApplication.restoreOverrideCursor() if not importOnFail: return True # assume file is not a TreeLine file importType = self.chooseImportType() if not importType: globalref.updateRefs(oldWin) return True try: QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) win.doc = treedoc.TreeDoc(filePath, False, importType) except treedoc.ReadFileError, e: QtGui.QApplication.restoreOverrideCursor() QtGui.QMessageBox.warning(win, 'TreeLine', _('Error - %s') % e) globalref.updateRefs(oldWin) return False
def dropMimeData(self, parent, mimeData, isCopy=False): """Decode dropped data""" mainWin = self.parent().parent().parent().parent() oldMainWin = globalref.mainWin if globalref.treeControl.duplicateWindows(): oldMainWin.saveMultiWinTree() globalref.updateRefs(mainWin) text = unicode(mimeData.data('text/xml'), 'utf-8') root, newFormats = globalref.docRef.readXmlStringAndFormat(text) if not root: globalref.updateRefs(oldMainWin) return False if root.formatName == treedoc.TreeDoc.copyFormat.name: itemList = root.childList else: itemList = [root] undoParents = [parent] + filter( None, [item.parent for item in globalref.docRef.selection]) if newFormats: globalref.docRef.undoStore.addBranchUndo(undoParents) for format in newFormats: globalref.docRef.treeFormats.addIfMissing(format) globalref.docRef.treeFormats.updateDerivedTypes() globalref.docRef.treeFormats.updateUniqueID() if treemainwin.TreeMainWin.configDlg: treemainwin.TreeMainWin.configDlg.resetParam() else: globalref.docRef.undoStore.addChildListUndo(undoParents) for node in itemList: parent.addTree(node) if isCopy: node.setDescendantUniqueID(True) parent.open = True globalref.docRef.selection.replace(itemList) if newFormats: globalref.docRef.treeFormats.updateAutoChoices() globalref.updateViewAll() globalref.updateRefs(oldMainWin) if globalref.treeControl.duplicateWindows(): oldMainWin.updateMultiWinTree() return True
def dropMimeData(self, parent, mimeData, isCopy=False): """Decode dropped data""" mainWin = self.parent().parent().parent().parent() oldMainWin = globalref.mainWin if globalref.treeControl.duplicateWindows(): oldMainWin.saveMultiWinTree() globalref.updateRefs(mainWin) text = unicode(mimeData.data("text/xml"), "utf-8") root, newFormats = globalref.docRef.readXmlStringAndFormat(text) if not root: globalref.updateRefs(oldMainWin) return False if root.formatName == treedoc.TreeDoc.copyFormat.name: itemList = root.childList else: itemList = [root] undoParents = [parent] + filter(None, [item.parent for item in globalref.docRef.selection]) if newFormats: globalref.docRef.undoStore.addBranchUndo(undoParents) for format in newFormats: globalref.docRef.treeFormats.addIfMissing(format) globalref.docRef.treeFormats.updateDerivedTypes() globalref.docRef.treeFormats.updateUniqueID() if treemainwin.TreeMainWin.configDlg: treemainwin.TreeMainWin.configDlg.resetParam() else: globalref.docRef.undoStore.addChildListUndo(undoParents) for node in itemList: parent.addTree(node) if isCopy: node.setDescendantUniqueID(True) parent.open = True globalref.docRef.selection.replace(itemList) if newFormats: globalref.docRef.treeFormats.updateAutoChoices() globalref.updateViewAll() globalref.updateRefs(oldMainWin) if globalref.treeControl.duplicateWindows(): oldMainWin.updateMultiWinTree() return True