def changedSelection(self, current, prev): if current == None or current.childCount() != 0: return file = common.qt_to_unicode(current.text(0)) path = tree.tree_item_to_path(current.parent()) path = dir_tools.expand_dir(path) filename = os.path.join(common.editor_config.data01_dir, path, file) if not os.path.isfile(filename): self.ui.txtTranslated.setPlainText("Could not load \"%s\"." % file) self.ui.txtOriginal.setPlainText("") self.ui.txtComments.setPlainText("") return script_file = ScriptFile(filename) notags = self.search_flags & script_analytics.SEARCH_NOTAGS self.ui.txtTranslated.setPlainText(script_file.notags[common.editor_config.lang_trans] if notags else script_file[common.editor_config.lang_trans]) self.ui.txtOriginal.setPlainText(script_file.notags[common.editor_config.lang_orig] if notags else script_file[common.editor_config.lang_orig]) self.ui.txtComments.setPlainText(script_file.comments) self.update_highlights()
def changedSelection(self, current, prev): if current == None or current.childCount() != 0: return file = common.qt_to_unicode(current.text(0)) path = tree.tree_item_to_path(current.parent()) self.setWindowTitle("%s - %s" % (self.menu_name, os.path.join(path, file))) path = dir_tools.expand_dir(path) file = os.path.join(path, file) file1 = os.path.join(self.folder1, file) file2 = os.path.join(self.folder2, file) if not os.path.isfile(file1): script1 = ScriptFile() else: script1 = ScriptFile(file1) if not os.path.isfile(file2): script2 = ScriptFile() else: script2 = ScriptFile(file2) # So we can loop this shit. to_diff = [ # Text 1 Text 2 Text Box 1 Text Box 2 (script1.translated, script2.translated, self.ui.txtTranslated1, self.ui.txtTranslated2), (script1.original, script2.original, self.ui.txtOriginal1, self.ui.txtOriginal2), (script1.comments, script2.comments, self.ui.txtComments1, self.ui.txtComments2), ] # Save us a little bit of time recalculating. if file in self.saved_diffs: diffs = self.saved_diffs[file] else: diffs = [None] * len(to_diff) for i, (text1, text2, box1, box2) in enumerate(to_diff): if diffs[i] == None: diffs[i] = DIFFER.diff_main(text1, text2) DIFFER.diff_cleanupSemantic(diffs[i]) box1.setPlainText(text1) box2.setPlainText(text2) highlight1, highlight2 = parse_diffs(diffs[i]) cursor1 = box1.textCursor() cursor2 = box2.textCursor() cursor1.select(QTextCursor.Document) cursor2.select(QTextCursor.Document) cursor1.setCharFormat(self.format_plain) cursor2.setCharFormat(self.format_plain) cursor1.movePosition(QTextCursor.Start) cursor2.movePosition(QTextCursor.Start) for pos, length in highlight1: cursor1.setPosition(pos, QTextCursor.MoveAnchor) cursor1.setPosition(pos + length, QTextCursor.KeepAnchor) cursor1.setCharFormat(self.format1) cursor1.movePosition(QTextCursor.Start) for pos, length in highlight2: cursor2.setPosition(pos, QTextCursor.MoveAnchor) cursor2.setPosition(pos + length, QTextCursor.KeepAnchor) cursor2.setCharFormat(self.format2) cursor2.movePosition(QTextCursor.Start) box1.setTextCursor(cursor1) box2.setTextCursor(cursor2) # for i, (text1, text2, box1, box2) in enumerate(to_diff): self.saved_diffs[file] = diffs
def changedSelection(self, current, prev): if current == None or current.childCount() != 0: return file = common.qt_to_unicode(current.text(0)) path = tree.tree_item_to_path(current.parent()) self.setWindowTitle("%s - %s" % (self.menu_name, os.path.join(path, file))) path = dir_tools.expand_dir(path) file = os.path.join(path, file) file1 = os.path.join(self.folder1, file) file2 = os.path.join(self.folder2, file) if not os.path.isfile(file1): script1 = ScriptFile() else: script1 = ScriptFile(file1) if not os.path.isfile(file2): script2 = ScriptFile() else: script2 = ScriptFile(file2) # So we can loop this shit. to_diff = [ # Text 1 Text 2 Text Box 1 Text Box 2 (script1[common.editor_config.lang_trans], script2[common.editor_config.lang_trans], self.ui.txtTranslated1, self.ui.txtTranslated2), (script1[common.editor_config.lang_orig], script2[common.editor_config.lang_orig], self.ui.txtOriginal1, self.ui.txtOriginal2), (script1.comments, script2.comments, self.ui.txtComments1, self.ui.txtComments2), ] # Save us a little bit of time recalculating. if file in self.saved_diffs: diffs = self.saved_diffs[file] else: diffs = [None] * len(to_diff) for i, (text1, text2, box1, box2) in enumerate(to_diff): if diffs[i] == None: diffs[i] = DIFFER.diff_main(text1, text2) DIFFER.diff_cleanupSemantic(diffs[i]) box1.setPlainText(text1) box2.setPlainText(text2) highlight1, highlight2 = parse_diffs(diffs[i]) cursor1 = box1.textCursor() cursor2 = box2.textCursor() cursor1.select(QTextCursor.Document) cursor2.select(QTextCursor.Document) cursor1.setCharFormat(self.format_plain) cursor2.setCharFormat(self.format_plain) cursor1.movePosition(QTextCursor.Start) cursor2.movePosition(QTextCursor.Start) for pos, length in highlight1: cursor1.setPosition(pos, QTextCursor.MoveAnchor) cursor1.setPosition(pos + length, QTextCursor.KeepAnchor) cursor1.setCharFormat(self.format1) cursor1.movePosition(QTextCursor.Start) for pos, length in highlight2: cursor2.setPosition(pos, QTextCursor.MoveAnchor) cursor2.setPosition(pos + length, QTextCursor.KeepAnchor) cursor2.setCharFormat(self.format2) cursor2.movePosition(QTextCursor.Start) box1.setTextCursor(cursor1) box2.setTextCursor(cursor2) # for i, (text1, text2, box1, box2) in enumerate(to_diff): self.saved_diffs[file] = diffs
def get_real_dir(self): # Rather than the easy to look at directory name we usually store, # get the actual, untampered directory name where you can find the files. return dir_tools.expand_dir(self.directory)