예제 #1
0
파일: uifactory.py 프로젝트: Darriall/idle
 def askstring(self, prompt=None, title=None, parent=None, 
               initialvalue=None, oklabel=None, validatecmd=None):
     from idlelib.querydialog import askstring
     if parent is None:
         parent = self.root
     return askstring(prompt=prompt, title=title, parent=parent,
                      initialvalue=initialvalue, validatecmd=validatecmd,
                      oklabel=oklabel, use_ttk=self.using_ttk)
예제 #2
0
파일: uifactory.py 프로젝트: wannalara/idle
 def askstring(self,
               prompt=None,
               title=None,
               parent=None,
               initialvalue=None,
               oklabel=None,
               validatecmd=None):
     from idlelib.querydialog import askstring
     if parent is None:
         parent = self.root
     return askstring(prompt=prompt,
                      title=title,
                      parent=parent,
                      initialvalue=initialvalue,
                      validatecmd=validatecmd,
                      oklabel=oklabel,
                      use_ttk=self.using_ttk)
예제 #3
0
파일: IOBinding.py 프로젝트: wannalara/idle
    def _decode(self, two_lines, bytes):
        "Create a Unicode string."
        chars = None
        # Check presence of a UTF-8 signature first
        if bytes.startswith(BOM_UTF8):
            try:
                chars = bytes[3:].decode("utf-8")
            except UnicodeDecodeError:
                # has UTF-8 signature, but fails to decode...
                return None, False
            else:
                # Indicates that this file originally had a BOM
                self.fileencoding = 'BOM'
                return chars, False
        # Next look for coding specification
        try:
            enc = coding_spec(two_lines)
        except LookupError as name:
            tkMessageBox.showerror(
                title="Error loading the file",
                message="The encoding '%s' is not known to this Python "\
                "installation. The file may not display correctly" % name,
                parent = self.text)
            enc = None
        except UnicodeDecodeError:
            return None, False
        if enc:
            try:
                chars = str(bytes, enc)
                self.fileencoding = enc
                return chars, False
            except UnicodeDecodeError:
                pass
        # Try ascii:
        try:
            chars = str(bytes, 'ascii')
            self.fileencoding = None
            return chars, False
        except UnicodeDecodeError:
            pass
        # Try utf-8:
        try:
            chars = str(bytes, 'utf-8')
            self.fileencoding = 'utf-8'
            return chars, False
        except UnicodeDecodeError:
            pass
        # Finally, try the locale's encoding. This is deprecated;
        # the user should declare a non-ASCII encoding
        try:
            # Wait for the editor window to appear
            self.editwin.text.update()
            enc = querydialog.askstring(
                title="Specify file encoding",
                prompt="The file's encoding is invalid for Python 3.x.\n"
                "IDLE will convert it to UTF-8.\n"
                "What is the current encoding of the file?",
                initialvalue = locale_encoding,
                parent = self.editwin.text, use_ttk=ui.using_ttk)

            if enc:
                chars = str(bytes, enc)
                self.fileencoding = None
            return chars, True
        except (UnicodeDecodeError, LookupError):
            pass
        return None, False  # None on failure