コード例 #1
0
 def show_files(self):
 
   # If we're not showing identical files, then go through the list
   # and find and remove everything we don't want to see.
   if not self.ui.chkShowSame.isChecked():
     if self.files_nodupes == None:
       self.files_nodupes = set()
     
       for file in self.files:
         file1 = os.path.join(self.folder1, file)
         file2 = os.path.join(self.folder2, file)
         
         if not os.path.isfile(file1) or not os.path.isfile(file2):
           self.files_nodupes.add(file)
           continue
         
         text1 = text_files.load_text(file1)
         text2 = text_files.load_text(file2)
         
         if not text1 == text2:
           self.files_nodupes.add(file)
           
     files = self.files_nodupes
     
   else:
     files = self.files
     
   # If we're not showing files not present in both directories,
   # go through the list and strip them out.
   if not self.ui.chkNotBoth.isChecked():
     if self.files_missing == None:
       self.files_missing = set()
     
       for file in self.files:
         file1 = os.path.join(self.folder1, file)
         file2 = os.path.join(self.folder2, file)
         
         if not os.path.isfile(file1) or not os.path.isfile(file2):
           self.files_missing.add(file)
           
     files = files - self.files_missing
     
   self.ui.treeResults.clear()
   self.ui.treeResults.setHeaderLabel("Results (%d)" % len(files))
   
   if len(files) > 0:
     tree_items = []
     
     for file in files:
       file = os.path.normpath(file)
       file = dir_tools.consolidate_dir(file)
       tree_item = tree.path_to_tree(file)
       tree_items.append(tree_item)
     
     tree_items = tree.consolidate_tree_items(tree_items)
     
     for item in tree_items:
       self.ui.treeResults.addTopLevelItem(item)
     
     self.ui.treeResults.expandAll()
コード例 #2
0
    def show_files(self):

        # If we're not showing identical files, then go through the list
        # and find and remove everything we don't want to see.
        if not self.ui.chkShowSame.isChecked():
            if self.files_nodupes == None:
                self.files_nodupes = set()

                for file in self.files:
                    file1 = os.path.join(self.folder1, file)
                    file2 = os.path.join(self.folder2, file)

                    if not os.path.isfile(file1) or not os.path.isfile(file2):
                        self.files_nodupes.add(file)
                        continue

                    text1 = text_files.load_text(file1)
                    text2 = text_files.load_text(file2)

                    if not text1 == text2:
                        self.files_nodupes.add(file)

            files = self.files_nodupes

        else:
            files = self.files

        # If we're not showing files not present in both directories,
        # go through the list and strip them out.
        if not self.ui.chkNotBoth.isChecked():
            if self.files_missing == None:
                self.files_missing = set()

                for file in self.files:
                    file1 = os.path.join(self.folder1, file)
                    file2 = os.path.join(self.folder2, file)

                    if not os.path.isfile(file1) or not os.path.isfile(file2):
                        self.files_missing.add(file)

            files = files - self.files_missing

        self.ui.treeResults.clear()
        self.ui.treeResults.setHeaderLabel("Results (%d)" % len(files))

        if len(files) > 0:
            tree_items = []

            for file in files:
                file = os.path.normpath(file)
                file = tree.consolidate_path(file)
                tree_item = tree.path_to_tree(file)
                tree_items.append(tree_item)

            tree_items = tree.consolidate_tree_items(tree_items)

            for item in tree_items:
                self.ui.treeResults.addTopLevelItem(item)

            self.ui.treeResults.expandAll()
コード例 #3
0
    def open(self, filename):

        if not filename or not os.path.isfile(filename):
            return

        text = load_text(filename)

        self.from_data(text)

        self.filename = filename
コード例 #4
0
 def search_bar_old(self, dir, query):
   files = list_all_files(dir)
   
   progress = QProgressDialog("", "Abort", 0, len(files), self)
   progress.setWindowTitle("Searching...")
   progress.setWindowModality(Qt.Qt.WindowModal)
   progress.setValue(0)
   
   width = self.width()
   height = self.height()
   x = self.x()
   y = self.y()
   
   matches = []
   
   if not self.ui.chkRegEx.isChecked():
     query = re.escape(query)
   
   query_re = re.compile(query, re.IGNORECASE | re.DOTALL | re.UNICODE)
   
   for i, file in enumerate(files):
     
     if progress.wasCanceled():
       break
     
     if i % 500 == 0:
       progress.setLabelText(file)
       
       # Re-center the dialog.
       progress_w = progress.geometry().width()
       progress_h = progress.geometry().height()
       
       new_x = x + ((width - progress_w) / 2)
       new_y = y + ((height - progress_h) / 2)
       
       progress.move(new_x, new_y)
     
     if os.path.splitext(file)[1] == ".txt":
       text = load_text(file)
       if not query_re.search(text) == None:
         matches.append(file)
     
     progress.setValue(i + 1)
   
   progress.close()
   
   return matches
コード例 #5
0
    def pack_txt(self, filename):

        if os.path.basename(os.path.dirname(filename)) in SCRIPT_NONSTOP:
            is_nonstop = True
        else:
            is_nonstop = False

        text = text_files.load_text(filename)
        text = RE_SCRIPT.sub(u"\g<1>", text)

        # Nonstop Debate lines need an extra newline at the end
        # so they show up in the backlog properly.
        if is_nonstop and not text[-1] == "\n":
            text += "\n"

        return SCRIPT_BOM.bytes + bytearray(
            text, encoding="UTF-16LE") + SCRIPT_NULL.bytes
コード例 #6
0
 def open(self, filename):
   
   try:
     tree = ET.parse(filename)
     root = tree.getroot()
   
   except ET.ParseError:
     # If it fails to parse as XML, assume it's the default format from the game.
     text = load_text(filename).strip("\0")
     text = LINE_BREAKS.sub("\n", text)
     
     root = ET.Element(LINE_TAG)
     
     line = ET.SubElement(root, TEXT_TAG)
     line.set(LANG_ATTR, DEFAULT_LANG)
     line.text = text
     
   except:
     raise
   
   self.text     = defaultdict(unicode)
   self.comments = u""
   
   for child in root:
     if child.tag == TEXT_TAG:
       lang = child.get(LANG_ATTR, DEFAULT_LANG)
       if child.text:
         self.text[lang] = child.text
       else:
         self.text[lang] = u""
     
     elif child.tag == COMMENT_TAG:
       if child.text:
         self.comments = child.text
       else:
         self.comments = u""
   
   self.filename = filename
コード例 #7
0
    def open(self, filename):

        try:
            tree = ET.parse(filename)
            root = tree.getroot()

        except ET.ParseError:
            # If it fails to parse as XML, assume it's the default format from the game.
            text = load_text(filename).strip("\0")
            text = LINE_BREAKS.sub("\n", text)

            root = ET.Element(LINE_TAG)

            line = ET.SubElement(root, TEXT_TAG)
            line.set(LANG_ATTR, DEFAULT_LANG)
            line.text = text

        except:
            raise

        self.text = defaultdict(unicode)
        self.comments = u""

        for child in root:
            if child.tag == TEXT_TAG:
                lang = child.get(LANG_ATTR, DEFAULT_LANG)
                if child.text:
                    self.text[lang] = child.text
                else:
                    self.text[lang] = u""

            elif child.tag == COMMENT_TAG:
                if child.text:
                    self.comments = child.text
                else:
                    self.comments = u""

        self.filename = filename
コード例 #8
0
def load_text(filename):
    text = text_files.load_text(filename)
    text = RE_SCRIPT.sub(u"\g<1>", text)
    return text
コード例 #9
0
def load_text(filename):
  text = text_files.load_text(filename)
  text = RE_SCRIPT.sub(u"\g<1>", text)
  return text