Beispiel #1
0
    def OnBrowser(self, event):
        filename = ''
        dlg = wx.FileDialog(self, tr("Select Script File"),
                            Globals.pref.last_script_dir, "",
                            tr("Python file (*.py)|*.py"), wx.OPEN)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                filename = dlg.GetPath()
                self.filename.SetValue(filename)

                def guess_name(text):
                    import re
                    import os

                    r = re.compile('(?i)#\s*(?:caption|name)\s*[:=](.*)$',
                                   re.M)
                    b = r.search(text)
                    name = ''
                    if b:
                        name = b.group(1).strip()
                    if not name:
                        name = os.path.splitext(os.path.basename(filename))[0]
                    if not name:
                        name = 'Change the description'
                    return name

                from modules import common
                from modules import unicodetext
                from modules.Debug import error

                try:
                    s, encoding = unicodetext.unicodetext(
                        file(filename).read())
                    name = guess_name(s)
                except unicodetext.UnicodeError:
                    common.showerror(self, tr("Unicode convert error"))
                    error.traceback()
                    return
                except:
                    common.showerror(self,
                                     tr("Can't open the file %s.") % filename)
                    error.traceback()
                    return
                self.text.SetValue(name)
        finally:
            dlg.Destroy()
Beispiel #2
0
 def OnBrowser(self, event):
     filename = ''
     dlg = wx.FileDialog(self, tr("Select Script File"), Globals.pref.last_script_dir, 
         "", tr("Python file (*.py)|*.py"), wx.OPEN)
     try:
         if dlg.ShowModal() == wx.ID_OK:
             filename = dlg.GetPath()
             self.filename.SetValue(filename)
             
             def guess_name(text):
                 import re
                 import os
                 
                 r = re.compile('(?i)#\s*(?:caption|name)\s*[:=](.*)$', re.M)
                 b = r.search(text)
                 name = ''
                 if b:
                     name = b.group(1).strip()
                 if not name:
                     name = os.path.splitext(os.path.basename(filename))[0]
                 if not name:
                     name = 'Change the description'
                 return name
                     
             from modules import common
             from modules import unicodetext
             from modules.Debug import error
             
             try:
                 s, encoding = unicodetext.unicodetext(file(filename).read())
                 name = guess_name(s)
             except unicodetext.UnicodeError:
                 common.showerror(self, tr("Unicode convert error"))
                 error.traceback()
                 return
             except:
                 common.showerror(self, tr("Can't open the file %s.") % filename)
                 error.traceback()
                 return
             self.text.SetValue(name)
     finally:
         dlg.Destroy()
Beispiel #3
0
def auto_uni_open_file(filename):
    text = open(filename, 'rU').read()
    from modules import unicodetext

    text, encoding = unicodetext.unicodetext(text)
    return text.splitlines()
Beispiel #4
0
def auto_uni_open_file(filename):
    text = open(filename, 'rU').read()
    from modules import unicodetext
    
    text, encoding = unicodetext.unicodetext(text)
    return text.splitlines()