def rename_section(self):
   old_section = self.get_section()
   new_section = self.show_section_editor(old_section)
   
   if new_section == None:
     return
   
   if old_section == new_section:
     return
   
   # All this encoding conversion shit is confusing me.
   if section_exists(common.qt_to_unicode(new_section)):
     answer = QtGui.QMessageBox.warning(
       self,
       "Section Exists",
       "The section \"" + new_section + "\" already exists.\n\n" + 
       "By renaming \"" + old_section + "\" to \"" + new_section + "\", the two sections will be merged.\n\n" +
       "Proceed?",
       buttons = QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel,
       defaultButton = QtGui.QMessageBox.Cancel
     )
     
     if answer == QtGui.QMessageBox.Cancel:
       return
   
   rename_section(common.qt_to_unicode(old_section), common.qt_to_unicode(new_section))
   self.refresh_ui()
   self.show_section(new_section)
Exemple #2
0
    def rename_section(self):
        old_section = self.get_section()
        new_section = self.show_section_editor(old_section)

        if new_section == None:
            return

        if old_section == new_section:
            return

        # All this encoding conversion shit is confusing me.
        if section_exists(common.qt_to_unicode(new_section)):
            answer = QtGui.QMessageBox.warning(
                self,
                "Section Exists",
                "The section \"" + new_section + "\" already exists.\n\n" +
                "By renaming \"" + old_section + "\" to \"" + new_section +
                "\", the two sections will be merged.\n\n" + "Proceed?",
                buttons=QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel,
                defaultButton=QtGui.QMessageBox.Cancel)

            if answer == QtGui.QMessageBox.Cancel:
                return

        rename_section(common.qt_to_unicode(old_section),
                       common.qt_to_unicode(new_section))
        self.refresh_ui()
        self.show_section(new_section)
 def edit_term(self):
   old_word, old_meaning = self.get_current_term()
   word, meaning = self.show_term_editor(old_word, old_meaning)
   
   if word == None or meaning == None:
     return
   
   if word == old_word and meaning == old_meaning:
     return
   
   old_term = Term(common.qt_to_unicode(old_word), common.qt_to_unicode(old_meaning))
   new_term = Term(common.qt_to_unicode(word),     common.qt_to_unicode(meaning))
   section = common.qt_to_unicode(self.get_section())
   
   if term_exists(section, new_term):
     QtGui.QMessageBox.warning(
       self,
       "Term Exists",
       "The term you are trying to add already exists.",
       buttons = QtGui.QMessageBox.Ok,
       defaultButton = QtGui.QMessageBox.Ok
     )
     return
   
   replace_term(section, old_term, new_term)
   self.refresh_ui()
Exemple #4
0
    def edit_term(self):
        old_word, old_meaning = self.get_current_term()
        word, meaning = self.show_term_editor(old_word, old_meaning)

        if word == None or meaning == None:
            return

        if word == old_word and meaning == old_meaning:
            return

        old_term = Term(common.qt_to_unicode(old_word),
                        common.qt_to_unicode(old_meaning))
        new_term = Term(common.qt_to_unicode(word),
                        common.qt_to_unicode(meaning))
        section = common.qt_to_unicode(self.get_section())

        if term_exists(section, new_term):
            QtGui.QMessageBox.warning(
                self,
                "Term Exists",
                "The term you are trying to add already exists.",
                buttons=QtGui.QMessageBox.Ok,
                defaultButton=QtGui.QMessageBox.Ok)
            return

        replace_term(section, old_term, new_term)
        self.refresh_ui()
 def apply_repl(self):
   common.editor_config.repl = []
   
   for i in range(self.ui.treeTextRepl.topLevelItemCount()):
     item = self.ui.treeTextRepl.topLevelItem(i)
     src  = common.qt_to_unicode(item.text(0), normalize = False)
     dst  = common.qt_to_unicode(item.text(1), normalize = False)
     
     common.editor_config.repl.append((src, dst))
     
   return True
Exemple #6
0
    def apply_repl(self):
        common.editor_config.repl = []

        for i in range(self.ui.treeTextRepl.topLevelItemCount()):
            item = self.ui.treeTextRepl.topLevelItem(i)
            src = common.qt_to_unicode(item.text(0), normalize=False)
            dst = common.qt_to_unicode(item.text(1), normalize=False)

            common.editor_config.repl.append((src, dst))

        return True
 def get_subs(self):
   # return {u"\t": u'  ', u"…":  u"..."}
   subs = {}
   
   for i in range(self.ui.treeSubs.topLevelItemCount()):
     item = self.ui.treeSubs.topLevelItem(i)
     
     repl      = unescape(common.qt_to_unicode(item.text(0)))
     repl_with = unescape(common.qt_to_unicode(item.text(1)))
     
     if len(repl) > 0:
       subs[repl] = repl_with
   
   return subs
Exemple #8
0
def tree_item_to_path(tree_item):
  
  if tree_item == None:
    return ""
  
  path = common.qt_to_unicode(tree_item.text(0))
  tree_item = tree_item.parent()
  
  while tree_item != None:
    base = common.qt_to_unicode(tree_item.text(0))
    path = os.path.join(base, path)
    tree_item = tree_item.parent()
  
  return path
    def get_subs(self):
        # return {u"\t": u'  ', u"…":  u"..."}
        subs = {}

        for i in range(self.ui.treeSubs.topLevelItemCount()):
            item = self.ui.treeSubs.topLevelItem(i)

            repl = unescape(common.qt_to_unicode(item.text(0)))
            repl_with = unescape(common.qt_to_unicode(item.text(1)))

            if len(repl) > 0:
                subs[repl] = repl_with

        return subs
Exemple #10
0
 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 __pack_cpk(self, csv, cpk):

        self.progress.setValue(0)
        self.progress.setMaximum(100000)
        self.progress.setLabelText("Building %s" % cpk)

        process = QProcess()
        process.start("tools/cpkmakec",
                      [csv, cpk, "-align=2048", "-mode=FILENAME"])

        percent = 0

        while not process.waitForFinished(100):

            output = QString(process.readAll())
            output = output.split("\n", QString.SkipEmptyParts)

            for line in output:
                line = common.qt_to_unicode(line)
                match = OUTPUT_RE.search(line)

                if match == None:
                    continue

                percent = float(match.group(1)) * 1000

            self.progress.setValue(percent)
            percent += 1
def sanitize_text(text):
  text = common.qt_to_unicode(text)
  text = text.upper()
  text = to_fullwidth(text)
  text = re.sub("\s", "", text)
  
  return text
 def __pack_cpk(self, csv, cpk):
   
   self.progress.setValue(0)
   self.progress.setMaximum(1000)
   self.progress.setLabelText("Building %s" % cpk)
   
   process = QProcess()
   process.start("tools/cpkmakec", [csv, cpk, "-align=2048", "-mode=FILENAME"])
   
   percent = 0
   
   while not process.waitForFinished(100):
   
     output = QString(process.readAll())
     output = output.split("\n", QString.SkipEmptyParts)
     
     for line in output:
       line = common.qt_to_unicode(line)
       match = OUTPUT_RE.search(line)
       
       if match == None:
         continue
       
       percent = float(match.group(1)) * 1000
     
     self.progress.setValue(percent)
     percent += 1
 def highlightBlock(self, text):
   
   # If there is no previous state, then it's -1, which makes the first line 0.
   # And every line after that increases as expected.
   line = self.previousBlockState() + 1
   self.setCurrentBlockState(line)
   
   # Make sure we aren't too long.
   if len(self.matches) > self.parent().blockCount():
     self.matches = self.matches[:self.parent().blockCount()]
     
   # Make sure our matches list is long enough to hold this line.
   for i in range(len(self.matches), line + 1):
     self.matches.append([])
   
   if len(self.keywords) == 0:
     return
   
   self.matches[line] = []
   
   text = common.qt_to_unicode(text)
   
   for keyword in self.keywords:
     matches = keyword.compiled.finditer(text)
     
     for match in matches:
       self.setFormat(match.start(), match.end() - match.start(), self.format)
       
       keyword_match = Keyword()
       keyword_match.word = match.group()
       keyword_match.meaning = keyword.meaning
       keyword_match.section = keyword.section
       
       self.matches[line].append((keyword_match, match.start(), match.end()))
 def check_iso(self):
 
   iso_dir = common.qt_to_unicode(self.ui.txtIso.text(), normalize = False)
   if not os.path.isdir(iso_dir):
     self.show_error("ISO directory does not exist.")
     return
   
   validated = True
   with open("data/file_order.txt", "rb") as file_order:
     # Since we're reappropriating this from the file used by mkisofs,
     # we need to do a little bit of work on it to be useful here.
     # Split it up on the tab, take the first entry, and chop the slash
     # off the beginning so we can use it in os.path.join
     file_list = [line.split('\t')[0][1:] for line in file_order.readlines() if not line == ""]
     
     for filename in file_list:
       full_name = os.path.join(iso_dir, filename)
       if not os.path.isfile(full_name):
         validated = False
         self.show_error("%s missing from ISO directory." % full_name)
         break
   
   if not validated:
     return
   
   self.iso_dir = iso_dir
   self.show_info("ISO directory looks good.")
   self.ui.grpStep1.setEnabled(False)
   self.ui.grpStep2.setEnabled(True)
def sanitize_text(text):
    text = common.qt_to_unicode(text)
    text = text.upper()
    text = to_fullwidth(text)
    text = re.sub("\s", "", text)

    return text
    def check_iso(self):

        iso_dir = common.qt_to_unicode(self.ui.txtIso.text(), normalize=False)
        if not os.path.isdir(iso_dir):
            self.show_error("ISO directory does not exist.")
            return

        validated = True
        with open("data/file_order.txt", "rb") as file_order:
            # Since we're reappropriating this from the file used by mkisofs,
            # we need to do a little bit of work on it to be useful here.
            # Split it up on the tab, take the first entry, and chop the slash
            # off the beginning so we can use it in os.path.join
            file_list = [line.split("\t")[0][1:] for line in file_order.readlines() if not line == ""]

            for filename in file_list:
                full_name = os.path.join(iso_dir, filename)
                if not os.path.isfile(full_name):
                    validated = False
                    self.show_error("%s missing from ISO directory." % full_name)
                    break

        if not validated:
            return

        self.iso_dir = iso_dir
        self.show_info("ISO directory looks good.")
        self.ui.grpStep1.setEnabled(False)
        self.ui.grpStep2.setEnabled(True)
  def highlightBlock(self, text):
    
    # If there is no previous state, then it's -1, which makes the first line 0.
    # And every line after that increases as expected.
    line = self.previousBlockState() + 1
    self.setCurrentBlockState(line)
    
    old_refs = copy.deepcopy(self.references)
    
    # Make sure we aren't too long.
    if len(self.references) > self.parent().blockCount():
      self.references = self.references[:self.parent().blockCount()]
    
    # Make sure our matches list is long enough to hold this line.
    for i in range(len(self.references), line + 1):
      self.references.append([])
    
    if len(self.references) == 0:
      return
    
    self.references[line] = []
    
    text = common.qt_to_unicode(text).lower()
    
    matches = RE_REFERENCE.finditer(text)
    
    for match in matches:
      self.setFormat(match.start(), match.end() - match.start(), self.format)
      self.references[line].append((match.group(1), match.start() + 1))
    
    if not old_refs == self.references:
      self.refs_edited.emit()

### EOF ###
    def checks_to_list(self, type, difficulty):
        text = ""

        if type == CHK_TYPE.Trans:
            text = common.qt_to_unicode(self.ui.txtSolutionTrans.text())
        else:
            text = common.qt_to_unicode(self.ui.txtSolutionOrig.text())

        letters = len(text)

        shown = []

        for i in range(1, letters + 1):
            if self.get_check(type, difficulty, i).isChecked():
                shown.append(i)

        return shown
Exemple #20
0
    def updateLogLevel(self, level):
        if self.creating:
            return

        level = common.qt_to_unicode(level)
        _LOGGER.setLevel(level.upper())

        common.editor_config.log_level = level
 def changeSelection(self, current, prev):
 
   if current and current.childCount() == 0:
     self.current_dir = common.qt_to_unicode(current.text(0))
   else:
     self.current_dir = None
     
   self.updateUI()
Exemple #22
0
    def changeSelection(self, current, prev):

        if current.childCount() == 0:
            self.current_dir = common.qt_to_unicode(current.text(0))
        else:
            self.current_dir = None

        self.updateUI()
 def calculate_progress(self):
   dir_filter = common.qt_to_unicode(self.ui.txtFilterRe.text())
   if dir_filter == "":
     dir_filter_re = script_analytics.DEFAULT_FILTER
   else:
     dir_filter_re = re.compile(dir_filter, re.IGNORECASE | re.DOTALL | re.UNICODE)
   
   self._calculate_progress(dir_filter_re)
 def updateLogLevel(self, level):
   if self.creating:
     return
   
   level = common.qt_to_unicode(level)
   _LOGGER.setLevel(level.upper())
   
   common.editor_config.log_level = level
 def checks_to_list(self, type, difficulty):
   text = ""
   
   if type == CHK_TYPE.Trans:
     text = common.qt_to_unicode(self.ui.txtSolutionTrans.text())
   else:
     text = common.qt_to_unicode(self.ui.txtSolutionOrig.text())
   
   letters = len(text)
   
   shown = []
   
   for i in range(1, letters + 1):
     if self.get_check(type, difficulty, i).isChecked():
       shown.append(i)
   
   return shown
Exemple #26
0
    def delete_term(self):

        answer = QtGui.QMessageBox.question(
            self,
            "Delete Term",
            "Are you sure you want to delete the currently selected term?",
            buttons=QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
            defaultButton=QtGui.QMessageBox.No)

        if answer == QtGui.QMessageBox.No:
            return

        section = common.qt_to_unicode(self.get_section())
        word, meaning = self.get_current_term()

        term = Term(common.qt_to_unicode(word), common.qt_to_unicode(meaning))
        remove_term(section, term)

        self.refresh_ui()
Exemple #27
0
def get_open_file(parent, default, filter=""):
    file = QFileDialog.getOpenFileName(parent,
                                       directory=default,
                                       filter=filter + ";;All files (*.*)")
    file = qt_to_unicode(file)

    if not file == "":
        return os.path.abspath(file)
    else:
        return file
 def get_checked(self, items):
   checked = []
   
   for item in items:
     if item.childCount() == 0 and item.checkState(0) == Qt.Qt.Checked:
       checked.append(common.qt_to_unicode(item.text(0)))
     else:
       checked.extend(self.get_checked([item.child(i) for i in range(item.childCount())]))
   
   return checked
 def apply_hacks(self):
   for i in range(self.ui.lstHacks.count()):
     cfg_id  = common.qt_to_unicode(self.ui.lstHacks.item(i).data(Qt.Qt.UserRole).toString())
     enabled = self.ui.lstHacks.item(i).checkState() == Qt.Qt.Checked
     
     if cfg_id:
       common.editor_config.hacks[cfg_id] = enabled
   
   common.editor_config.hacks[eboot_patch.LANG_CFG_ID] = self.ui.cboHackLang.currentIndex()
     
   return True
Exemple #30
0
def get_existing_dir(parent, default):
    dir = QFileDialog.getExistingDirectory(parent, directory=default)
    dir = qt_to_unicode(dir)

    if not dir == "":
        return os.path.abspath(dir)
    else:
        return dir


### EOF ###
 def delete_term(self):
 
   answer = QtGui.QMessageBox.question(
     self,
     "Delete Term",
     "Are you sure you want to delete the currently selected term?",
     buttons = QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
     defaultButton = QtGui.QMessageBox.No
   )
   
   if answer == QtGui.QMessageBox.No:
     return
   
   section = common.qt_to_unicode(self.get_section())
   word, meaning = self.get_current_term()
   
   term = Term(common.qt_to_unicode(word), common.qt_to_unicode(meaning))
   remove_term(section, term)
   
   self.refresh_ui()
 def add_section_button(self):
   
   section = self.show_section_editor()
   
   if section == None:
     return
   
   if section_exists(common.qt_to_unicode(section)):
     QtGui.QMessageBox.warning(
       self,
       "Section Exists",
       "The section \"" + section + "\" already exists.",
       buttons = QtGui.QMessageBox.Ok,
       defaultButton = QtGui.QMessageBox.Ok
     )
     self.show_section(section)
     return
   
   add_term(common.qt_to_unicode(section), Term(u"プレイスホルダー", u"Placeholder"))
   self.refresh_ui()
   self.show_section(section)
 def update_checks(self, type = CHK_TYPE.Trans):
   text = ""
   
   if type == CHK_TYPE.Trans:
     text = common.qt_to_unicode(self.ui.txtSolutionTrans.text())
   else:
     text = common.qt_to_unicode(self.ui.txtSolutionOrig.text())
   
   letters = len(text)
   
   for diff in CHK_DIFF:
     for i in range(1, letters + 1):
       # Only enable the check boxes for translation mode, since they can't
       # edit the originals.
       if type == CHK_TYPE.Trans:
         self.get_check(type, diff, i).setEnabled(True)
       self.get_check(type, diff, i).setVisible(True)
     for i in range(letters + 1, 16):
       self.get_check(type, diff, i).setEnabled(False)
       self.get_check(type, diff, i).setChecked(False)
       self.get_check(type, diff, i).setVisible(False)
 def add_term_button(self):
   word, meaning = self.show_term_editor()
   
   if word == None or meaning == None:
     return
   
   new_term = Term(common.qt_to_unicode(word), common.qt_to_unicode(meaning))
   section = common.qt_to_unicode(self.get_section())
   
   if term_exists(section, new_term):
     QtGui.QMessageBox.warning(
       self,
       "Term Exists",
       "The term you are trying to add already exists.",
       buttons = QtGui.QMessageBox.Ok,
       defaultButton = QtGui.QMessageBox.Ok
     )
     return
   
   add_term(section, new_term)
   self.refresh_ui()
Exemple #35
0
    def add_term_button(self):
        word, meaning = self.show_term_editor()

        if word == None or meaning == None:
            return

        new_term = Term(common.qt_to_unicode(word),
                        common.qt_to_unicode(meaning))
        section = common.qt_to_unicode(self.get_section())

        if term_exists(section, new_term):
            QtGui.QMessageBox.warning(
                self,
                "Term Exists",
                "The term you are trying to add already exists.",
                buttons=QtGui.QMessageBox.Ok,
                defaultButton=QtGui.QMessageBox.Ok)
            return

        add_term(section, new_term)
        self.refresh_ui()
    def update_checks(self, type=CHK_TYPE.Trans):
        text = ""

        if type == CHK_TYPE.Trans:
            text = common.qt_to_unicode(self.ui.txtSolutionTrans.text())
        else:
            text = common.qt_to_unicode(self.ui.txtSolutionOrig.text())

        letters = len(text)

        for diff in CHK_DIFF:
            for i in range(1, letters + 1):
                # Only enable the check boxes for translation mode, since they can't
                # edit the originals.
                if type == CHK_TYPE.Trans:
                    self.get_check(type, diff, i).setEnabled(True)
                self.get_check(type, diff, i).setVisible(True)
            for i in range(letters + 1, 16):
                self.get_check(type, diff, i).setEnabled(False)
                self.get_check(type, diff, i).setChecked(False)
                self.get_check(type, diff, i).setVisible(False)
 def apply_file_locs(self):
   # Check to make sure none of our boxes are blank.
   for item in FILE_LOCATIONS:
     if self.ui.__dict__[item[TEXT]].text().length() == 0:
       QtGui.QMessageBox.critical(self, "Error", "Please supply locations for all the listed files or folders.")
       return False
   
   # Then apply our changes.
   for item in FILE_LOCATIONS:
     common.editor_config.set_pref(item[CFG], common.qt_to_unicode(self.ui.__dict__[item[TEXT]].text(), normalize = False))
   
   return True
Exemple #38
0
    def add_section_button(self):

        section = self.show_section_editor()

        if section == None:
            return

        if section_exists(common.qt_to_unicode(section)):
            QtGui.QMessageBox.warning(self,
                                      "Section Exists",
                                      "The section \"" + section +
                                      "\" already exists.",
                                      buttons=QtGui.QMessageBox.Ok,
                                      defaultButton=QtGui.QMessageBox.Ok)
            self.show_section(section)
            return

        add_term(common.qt_to_unicode(section),
                 Term(u"プレイスホルダー", u"Placeholder"))
        self.refresh_ui()
        self.show_section(section)
Exemple #39
0
    def get_checked(self, items):
        checked = []

        for item in items:
            if item.childCount() == 0 and item.checkState(0) == Qt.Qt.Checked:
                checked.append(common.qt_to_unicode(item.text(0)))
            else:
                checked.extend(
                    self.get_checked(
                        [item.child(i) for i in range(item.childCount())]))

        return checked
Exemple #40
0
    def apply_hacks(self):
        for i in range(self.ui.lstHacks.count()):
            cfg_id = common.qt_to_unicode(
                self.ui.lstHacks.item(i).data(Qt.Qt.UserRole).toString())
            enabled = self.ui.lstHacks.item(i).checkState() == Qt.Qt.Checked

            if cfg_id:
                common.editor_config.hacks[cfg_id] = enabled

        common.editor_config.hacks[
            eboot_patch.LANG_CFG_ID] = self.ui.cboHackLang.currentIndex()

        return True
 def sub_changed(self, item, col):
   # Make sure everything's valid.
   sub = common.qt_to_unicode(item.text(col))
   sub = unescape(sub)
   
   # The replacement column can only be single characters
   if col == 0:
     sub = sub[:1]
   
   sub = escape(sub)
   item.setText(col, sub)
   
   if not self.importing:
     self.auto_update()
     self.modified.emit()
    def sub_changed(self, item, col):
        # Make sure everything's valid.
        sub = common.qt_to_unicode(item.text(col))
        sub = unescape(sub)

        # The replacement column can only be single characters
        if col == 0:
            sub = sub[:1]

        sub = escape(sub)
        item.setText(col, sub)

        if not self.importing:
            self.auto_update()
            self.modified.emit()
Exemple #43
0
    def delete_section(self):
        section = self.get_section()

        answer = QtGui.QMessageBox.question(
            self,
            "Delete Section",
            "Are you sure you want to delete the section \"" + section + "\"?",
            buttons=QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
            defaultButton=QtGui.QMessageBox.No)

        if answer == QtGui.QMessageBox.No:
            return

        remove_section(common.qt_to_unicode(section))
        self.refresh_ui()
 def apply_prefs(self):
   for item in EDITOR_PREFS_TXT:
     if self.ui.__dict__[item[TEXT]].text().length() == 0:
       QtGui.QMessageBox.critical(self, "Error", "Please provide languages codes for both original and translated text.")
       return False
   
   # Then apply our changes.
   for item in EDITOR_PREFS_TXT:
     common.editor_config.set_pref(item[CFG], common.qt_to_unicode(self.ui.__dict__[item[TEXT]].text(), normalize = False))
       
   for item in EDITOR_PREFS_CHK:
     common.editor_config.set_pref(item[CFG], self.ui.__dict__[item[CHK]].isChecked())
   
   common.editor_config.spell_check_lang = self.ui.cboSpellCheckLang.currentText()
   
   return True
    def check_terminology(self):
        terms_file = common.qt_to_unicode(self.ui.txtTerminology.text(), normalize=False)

        if not terms_file:
            self.show_error("No terminology file provided.")
            return

        if not os.path.isfile(terms_file):
            # Create it.
            with open(terms_file, "wb") as f:
                self.show_info("Terminology file created.")

        self.terminology = terms_file

        self.ui.grpStep6.setEnabled(False)
        self.ui.btnFinish.setEnabled(True)
    def check_workspace(self):
        workspace_dir = common.qt_to_unicode(self.ui.txtWorkspace.text(), normalize=False)

        if not os.path.isdir(workspace_dir):
            try:
                os.makedirs(workspace_dir)
                self.show_info("Workspace directory created.")
            except:
                self.show_error("Error creating workspace directory.")
                return
        else:
            self.show_info("Workspace directory already exists.\n\nExisting data will be overwritten.")

        self.workspace_dir = workspace_dir
        self.ui.grpStep2.setEnabled(False)
        self.ui.grpStep3.setEnabled(True)
 def delete_section(self):
   section = self.get_section()
   
   answer = QtGui.QMessageBox.question(
     self,
     "Delete Section",
     "Are you sure you want to delete the section \"" + section + "\"?",
     buttons = QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
     defaultButton = QtGui.QMessageBox.No
   )
   
   if answer == QtGui.QMessageBox.No:
     return
   
   remove_section(common.qt_to_unicode(section))
   self.refresh_ui()
 def check_terminology(self):
   terms_file = common.qt_to_unicode(self.ui.txtTerminology.text(), normalize = False)
   
   if not terms_file:
     self.show_error("No terminology file provided.")
     return
   
   if not os.path.isfile(terms_file):
     # Create it.
     with open(terms_file, "wb") as f:
       self.show_info("Terminology file created.")
   
   self.terminology = terms_file
   
   self.ui.grpStep6.setEnabled(False)
   self.ui.btnFinish.setEnabled(True)
 def check_workspace(self):
   workspace_dir = common.qt_to_unicode(self.ui.txtWorkspace.text(), normalize = False)
   
   if not os.path.isdir(workspace_dir):
     try:
       os.makedirs(workspace_dir)
       self.show_info("Workspace directory created.")
     except:
       self.show_error("Error creating workspace directory.")
       return
   else:
     self.show_info("Workspace directory already exists.\n\nExisting data will be overwritten.")
   
   self.workspace_dir = workspace_dir
   self.ui.grpStep2.setEnabled(False)
   self.ui.grpStep3.setEnabled(True)
 def __parse_output(self):
   if not self.process:
     return
   
   output = QString(self.process.readAll())
   output = output.split("\n", QString.SkipEmptyParts)
   
   for line in output:
     line = common.qt_to_unicode(line)
     
     match = OUTPUT_RE.match(line)
     
     if match == None:
       continue
     
     percent = float(match.group(1))
     self.progress.setValue(percent)
 def highlightBlock(self, text):
   
   # If there is no previous state, then it's -1, which makes the first line 0.
   # And every line after that increases as expected.
   line = self.previousBlockState() + 1
   self.setCurrentBlockState(line)
   
   # Make sure our error list is long enough to hold this line.
   for i in range(len(self.errors), line + 1):
     self.errors.append([])
   
   self.errors[line] = []
   self.checker.set_text(common.qt_to_unicode(text))
   
   for err in self.checker:
     self.setFormat(err.wordpos, len(err.word), self.format)
     self.errors[line].append((err.word, err.wordpos))
    def __parse_output(self):
        if not self.process:
            return

        output = QString(self.process.readAll())
        output = output.split("\n", QString.SkipEmptyParts)

        for line in output:
            line = common.qt_to_unicode(line)

            match = OUTPUT_RE.match(line)

            if match == None:
                continue

            percent = float(match.group(1))
            self.progress.setValue(percent)
 def get_data(self):
   return FontConfig(
     family    = self.font_name(),
     size      = self.font_size(),
     weight    = self.ui.spnFontWeight.value(),
     x_offset  = self.ui.spnXOffset.value(),
     y_offset  = self.ui.spnYOffset.value(),
     x_margin  = self.ui.spnXMargin.value(),
     y_margin  = self.ui.spnYMargin.value(),
     y_shift   = self.ui.spnYShift.value(),
     pen_size  = self.ui.spnPenSize.value(),
     pen_cap   = self.ui.cboPenCap.itemData(self.ui.cboPenCap.currentIndex()).toInt()[0],
     pen_join  = self.ui.cboPenJoin.itemData(self.ui.cboPenJoin.currentIndex()).toInt()[0],
     use_pen   = self.ui.chkTrace.isChecked(),
     chars     = common.qt_to_unicode(self.ui.txtChars.toPlainText()),
     subs      = self.get_subs(),
   )
    def gim_to_png(self,
                   gim_file,
                   png_file=None,
                   quant_type=QuantizeType.none):
        # So there's no confusion.
        gim_file = os.path.abspath(gim_file)
        if png_file:
            png_file = os.path.abspath(png_file)

        # Convert our GIM.
        self.process.start("tools/gim2png", ["-9", gim_file])
        self.process.waitForFinished(-1)

        # Now get the output location.
        output = QString(self.process.readAllStandardOutput())
        output = output.split("\n", QString.SkipEmptyParts)

        saved_file = None

        for line in output:
            line = common.qt_to_unicode(line)

            match = OUTPUT_RE.match(line)

            if match == None:
                continue

            saved_file = match.group(1)
            break

        # Make sure we actually generated a file.
        if not saved_file:
            _LOGGER.error("Failed to convert %s" % gim_file)
            return

        quant = self.quantize_png(saved_file, quant_type)

        if not quant == saved_file and not quant == png_file:
            os.remove(saved_file)

        # And move it to the requested location, if one exists.
        if png_file:
            shutil.move(quant, png_file)
        else:
            shutil.move(quant, saved_file)
 def changedTranslation(self):
   text = common.qt_to_unicode(self.ui.txtTranslated.toPlainText())
   
   bytes  = bytearray(text, encoding = self.lines[self.current_line].enc)
   length = len(bytes)
   
   self.ui.lblTransLength.setText("Length: %d bytes" % length)
   
   if not text == self.lines[self.current_line].text:
     
     if length > self.max_len:
       cursor = self.ui.txtTranslated.textCursor()
       cursor.movePosition(QTextCursor.End)
       cursor.deletePreviousChar()
       self.ui.txtTranslated.setTextCursor(cursor)
     
     else:
       self.lines[self.current_line].text = text
Exemple #56
0
    def apply_file_locs(self):
        # Check to make sure none of our boxes are blank.
        for item in FILE_LOCATIONS:
            if self.ui.__dict__[item[TEXT]].text().length() == 0:
                QtGui.QMessageBox.critical(
                    self, "Error",
                    "Please supply locations for all the listed files or folders."
                )
                return False

        # Then apply our changes.
        for item in FILE_LOCATIONS:
            common.editor_config.set_pref(
                item[CFG],
                common.qt_to_unicode(self.ui.__dict__[item[TEXT]].text(),
                                     normalize=False))

        return True
    def changedTranslation(self):
        text = common.qt_to_unicode(self.ui.txtTranslated.toPlainText())

        bytes = bytearray(text, encoding=self.lines[self.current_line].enc)
        length = len(bytes)

        self.ui.lblTransLength.setText("Length: %d bytes" % length)

        if not text == self.lines[self.current_line].text:

            if length > self.max_len:
                cursor = self.ui.txtTranslated.textCursor()
                cursor.movePosition(QTextCursor.End)
                cursor.deletePreviousChar()
                self.ui.txtTranslated.setTextCursor(cursor)

            else:
                self.lines[self.current_line].text = text
 def get_data(self):
     return FontConfig(
         family=self.font_name(),
         size=self.font_size(),
         weight=self.ui.spnFontWeight.value(),
         x_offset=self.ui.spnXOffset.value(),
         y_offset=self.ui.spnYOffset.value(),
         x_margin=self.ui.spnXMargin.value(),
         y_margin=self.ui.spnYMargin.value(),
         y_shift=self.ui.spnYShift.value(),
         pen_size=self.ui.spnPenSize.value(),
         pen_cap=self.ui.cboPenCap.itemData(
             self.ui.cboPenCap.currentIndex()).toInt()[0],
         pen_join=self.ui.cboPenJoin.itemData(
             self.ui.cboPenJoin.currentIndex()).toInt()[0],
         use_pen=self.ui.chkTrace.isChecked(),
         chars=common.qt_to_unicode(self.ui.txtChars.toPlainText()),
         subs=self.get_subs(),
     )