コード例 #1
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
 def delete(self):
     index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
     if index >= 0:
         flag = self.list.GetItemData(index)
         if flag == 2:
             return
         pathname = self.list.GetItemText(index)
         dlg = wx.MessageDialog(self, tr("Do you want to delete %s?") % pathname, tr("Delete"), wx.YES_NO | wx.ICON_QUESTION)
         answer = dlg.ShowModal()
         if answer == wx.ID_YES:
             if flag == 0:   #dir
                 try:
                     self.ftp.rmd(common.decode_string(pathname))
                 except Exception, msg:
                     error.traceback()
                     common.showerror(self, msg)
                     return
             elif flag == 1: #file
                 try:
                     self.ftp.delete(common.decode_string(pathname))
                 except Exception, msg:
                     error.traceback()
                     common.showerror(self, msg)
                     return
             self.refresh(self.curpath)
コード例 #2
0
 def delete(self):
     index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL,
                                   wx.LIST_STATE_SELECTED)
     if index >= 0:
         flag = self.list.GetItemData(index)
         if flag == 2:
             return
         pathname = self.list.GetItemText(index)
         dlg = wx.MessageDialog(self,
                                tr("Do you want to delete %s?") % pathname,
                                tr("Delete"), wx.YES_NO | wx.ICON_QUESTION)
         answer = dlg.ShowModal()
         if answer == wx.ID_YES:
             if flag == 0:  #dir
                 try:
                     self.ftp.rmd(common.decode_string(pathname))
                 except Exception, msg:
                     error.traceback()
                     common.showerror(self, msg)
                     return
             elif flag == 1:  #file
                 try:
                     self.ftp.delete(common.decode_string(pathname))
                 except Exception, msg:
                     error.traceback()
                     common.showerror(self, msg)
                     return
             self.refresh(self.curpath)
コード例 #3
0
 def rename(self):
     index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL,
                                   wx.LIST_STATE_SELECTED)
     if index >= 0:
         pathname = self.list.GetItemText(index)
         dlg = MyTextEntry(self, tr("Name Input"), tr('Input a new name:'),
                           '')
         answer = dlg.ShowModal()
         if answer == wx.ID_OK:
             newpath = dlg.GetValue()
             if not newpath:
                 return
             flag = self.list.GetItemData(index)
             if flag != 2:  #dir
                 try:
                     self.ftp.rename(common.decode_string(pathname),
                                     common.decode_string(newpath))
                 except Exception, msg:
                     error.traceback()
                     common.showerror(self, msg)
                     return
             if self.refresh(self.curpath):
                 index = self.list.FindItem(-1, newpath)
                 self.list.SetItemState(index, wx.LIST_STATE_SELECTED,
                                        wx.LIST_MASK_STATE)
コード例 #4
0
ファイル: MusicListManage.py プロジェクト: LaoMa3953/ulipad
 def addrecord(self,record):
     lastid=self.musiclist.GetItemCount()
     self.musiclist.addline([
         str(lastid+1),
         common.decode_string(record['Author-Title'], common.defaultfilesystemencoding),
         timeformat(record['Time']),
         common.decode_string(record['Path'], common.defaultfilesystemencoding)
         ])
コード例 #5
0
ファイル: MusicListManage.py プロジェクト: zztalker/ulipad
 def addrecord(self, record):
     lastid = self.musiclist.GetItemCount()
     self.musiclist.addline([
         str(lastid + 1),
         common.decode_string(record['Author-Title'],
                              common.defaultfilesystemencoding),
         timeformat(record['Time']),
         common.decode_string(record['Path'],
                              common.defaultfilesystemencoding)
     ])
コード例 #6
0
ファイル: PyMp3Info.py プロジェクト: zztalker/ulipad
 def parse(self, filepath=None):
     "parse ID3v1.0 tags from MP3 file"
     if filepath:
         self.filepath = filepath
     self.filepath = common.decode_string(self.filepath,
                                          common.defaultfilesystemencoding)
     self.info.clear()
     try:
         fsock = open(self.filepath, "rb", 0)
         try:
             fsock.seek(-128, 2)
             tagdata = fsock.read(128)
         finally:
             fsock.close()
         if tagdata[:3] == "TAG":
             for tag, (start, end, parseFunc) in self.tagDataMap.items():
                 self.info[tag] = parseFunc(tagdata[start:end])
             self.ishasinfo = True
         else:
             self.info['title'] = self.filepath
             self.info['author'] = ''
     except IOError:
         error.traceback()
         return False
     return True
コード例 #7
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
    def newfile(self):
        filename = ''
        dlg = MyTextEntry(self, tr("Filename Input"), tr('Input a new filename:'), '')
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            filename = dlg.GetValue()
            if not filename:
                return
            #check if the new name has existed
            index = self.list.FindItem(-1, filename)
            if index > -1:
                common.showerror(self, tr('The filename already exists.\nPlease input another one.'))
                return
            from StringIO import StringIO
            f = StringIO('')
            try:
                self.ftp.storbinary('STOR %s' % common.decode_string(filename), f)
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, filename)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_MASK_STATE)
コード例 #8
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
def readfile(mainframe, filename, siteno, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        data = []
        def getdata(d, data=data):
            data.append(d)
        ftp.retrbinary("RETR %s" % common.decode_string(filename), getdata)
        ftp.quit()
        ftp.close()
        text = ''.join(data)
        return text
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
コード例 #9
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
def writefile(mainframe, filename, siteno, text, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    #connect
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        import StringIO
        f = StringIO.StringIO(text)
        ftp.storbinary("STOR %s" % common.decode_string(filename), f)
        ftp.quit()
        ftp.close()
        return True
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
コード例 #10
0
ファイル: DosPrompt.py プロジェクト: LaoMa3953/ulipad
def appendtext(win, text):
    win.GotoPos(win.GetLength())
    if not isinstance(text, unicode):
        text = common.decode_string(text)
    win.AddText(text)
    win.GotoPos(win.GetLength())
    win.EmptyUndoBuffer()
コード例 #11
0
    def newdir(self):
        dirname = ''
        dlg = MyTextEntry(self, tr("Directory Input"),
                          tr('Input a new directory:'), '')
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            dirname = dlg.GetValue()
            if not dirname:
                return
            #check if the new name has existed
            index = self.list.FindItem(-1, dirname)
            if index > -1:
                common.showerror(
                    self,
                    tr('The directory already exists.\nPlease input another one.'
                       ))
                return
            try:
                self.ftp.mkd(common.decode_string(dirname))
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, dirname)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED,
                                       wx.LIST_MASK_STATE)
コード例 #12
0
def appendtext(win, text):
    win.GotoPos(win.GetLength())
    if not isinstance(text, unicode):
        text = common.decode_string(text)
    win.AddText(text)
    win.GotoPos(win.GetLength())
    win.EmptyUndoBuffer()
コード例 #13
0
    def newfile(self):
        filename = ''
        dlg = MyTextEntry(self, tr("Filename Input"),
                          tr('Input a new filename:'), '')
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            filename = dlg.GetValue()
            if not filename:
                return
            #check if the new name has existed
            index = self.list.FindItem(-1, filename)
            if index > -1:
                common.showerror(
                    self,
                    tr('The filename already exists.\nPlease input another one.'
                       ))
                return
            from StringIO import StringIO
            f = StringIO('')
            try:
                self.ftp.storbinary('STOR %s' % common.decode_string(filename),
                                    f)
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, filename)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED,
                                       wx.LIST_MASK_STATE)
コード例 #14
0
def readfile(mainframe, filename, siteno, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        data = []

        def getdata(d, data=data):
            data.append(d)

        ftp.retrbinary("RETR %s" % common.decode_string(filename), getdata)
        ftp.quit()
        ftp.close()
        text = ''.join(data)
        return text
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
コード例 #15
0
def writefile(mainframe, filename, siteno, text, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    #connect
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        import StringIO
        f = StringIO.StringIO(text)
        ftp.storbinary("STOR %s" % common.decode_string(filename), f)
        ftp.quit()
        ftp.close()
        return True
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
コード例 #16
0
    def download(self):
        index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL,
                                      wx.LIST_STATE_SELECTED)
        if index >= 0:
            flag = self.list.GetItemData(index)
            if flag == 2:
                return
            filename = self.list.GetItemText(index)
            dlg = DownloadFileEntry(self, filename)
            answer = dlg.ShowModal()
            if answer == wx.ID_OK:
                newfile, bin = dlg.GetValue()
                if not newfile:
                    common.showerror(self, tr("The filename can't be empty."))
                    return
            else:
                return

            common.setmessage(self.mainframe, tr('Downloading the file...'))
            try:
                try:
                    if bin:
                        f = file(newfile, 'wb')

                        def getdata(d, f=f):
                            f.write(d)

                        self.ftp.retrbinary(
                            "RETR %s" % common.decode_string(filename),
                            getdata)
                    else:
                        f = file(newfile, 'w')

                        def getdata(d, f=f):
                            f.write(d + "\n")

                        self.ftp.retrlines(
                            "RETR %s" % common.decode_string(filename),
                            getdata)
                except Exception, msg:
                    error.traceback()
                    common.showerror(self, msg)
                    return
            finally:
                f.close()
            common.setmessage(self.mainframe, tr('Downloading finished'))
コード例 #17
0
ファイル: PyM3u.py プロジェクト: LinYuanLab/ulipad
 def Load(self,filepath=None):
     if filepath:
         self.filepath=filepath
     if not self.filepath or not os.path.isfile(self.filepath) or not self.filepath.lower().endswith('.m3u'):
         raise LoadMusicListException()
     lines=open(self.filepath,'r').readlines()
     if lines[0].upper().strip()!='#EXTM3U':
         raise LoadMusicListException()
     p=re.compile('#EXTINF:(?P<time>\d*?),(?P<titleauthor>.*?)$')
     for i in range(1,len(lines),2):
         if not lines[i].startswith('#EXTINF'):
             continue
         result=p.search(lines[i].strip())
         path = common.decode_string(lines[i+1].strip(), common.defaultfilesystemencoding)
         title = common.decode_string(result.group('titleauthor'), common.defaultfilesystemencoding)
         self.data.append({'Author-Title':title,'Time':result.group('time'),'Path':path})
     return True
コード例 #18
0
    def upload(self):
        dlg = UploadFileEntry(self)
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            filename, newfile, bin = dlg.GetValue()
            if not filename:
                common.showerror(self, tr("The filename can't be empty."))
                return
            if not newfile:
                newfile = os.path.basename(filename)
            #check if the new name has existed
            index = self.list.FindItem(-1, newfile)
            if index > -1:
                dlg = wx.MessageDialog(
                    self,
                    tr("The filename already exists. Do you want to overwrite it?"
                       ), tr("Upload File"), wx.YES_NO | wx.ICON_QUESTION)
                answer = dlg.ShowModal()
                if answer == wx.ID_NO:
                    return

            common.setmessage(self.mainframe, tr('Uploading the file...'))
            #           if not self.setBin(bin):
            #               return
            from StringIO import StringIO
            try:
                if bin:
                    f = StringIO(file(filename, 'rb').read())
                    self.ftp.storbinary(
                        'STOR %s' % common.decode_string(newfile), f)
                else:
                    f = StringIO(file(filename, 'r').read())
                    self.ftp.storlines(
                        'STOR %s' % common.decode_string(newfile), f)
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            self.setBin(True)
            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, newfile)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED,
                                       wx.LIST_MASK_STATE)
            common.setmessage(self.mainframe, tr('Uploading finished'))
コード例 #19
0
def OnWindowDos(win, event):
    path = os.getcwd()
    path = common.decode_string(path)
    dlg = wx.DirDialog(win, tr('Choose a directory'), path)
    answer = dlg.ShowModal()
    if answer == wx.ID_OK:
        path = dlg.GetPath()
        win.createDosWindow()
        win.panel.showPage('Dos')
        win.RunDosCommand('cmd.exe /k "cd %s"' % path)
コード例 #20
0
ファイル: __init__.py プロジェクト: LinYuanLab/ulipad
def OnWindowDos(win, event):
    path = os.getcwd()
    path = common.decode_string(path)
    dlg = wx.DirDialog(win, tr('Choose a directory'), path)
    answer = dlg.ShowModal()
    if answer == wx.ID_OK:
        path = dlg.GetPath()
        win.createDosWindow()
        win.panel.showPage('Dos')
        win.RunDosCommand('cmd.exe /k "cd %s"' % path)
コード例 #21
0
ファイル: EditorFactory.py プロジェクト: LaoMa3953/ulipad
 def showPageTitle(self, ctrl):
     title = os.path.basename(ctrl.getShortFilename())
     if isinstance(title, str):
         title = common.decode_string(title, common.defaultfilesystemencoding)
     if ctrl.isModified():
         title = '* ' + title
     index = self.getIndex(ctrl)
     wx.CallAfter(self.EnsureVisible, self.getIndex(ctrl))
     if title != self.GetPageText(index):
         wx.CallAfter(self.SetPageText, self.getIndex(ctrl), title)
コード例 #22
0
ファイル: EditorFactory.py プロジェクト: zztalker/ulipad
 def showPageTitle(self, ctrl):
     title = os.path.basename(ctrl.getShortFilename())
     if isinstance(title, str):
         title = common.decode_string(title,
                                      common.defaultfilesystemencoding)
     if ctrl.isModified():
         title = '* ' + title
     index = self.getIndex(ctrl)
     wx.CallAfter(self.EnsureVisible, self.getIndex(ctrl))
     if title != self.GetPageText(index):
         wx.CallAfter(self.SetPageText, self.getIndex(ctrl), title)
コード例 #23
0
ファイル: MusicListManage.py プロジェクト: zztalker/ulipad
 def OnAddDir(self, event):
     dialog = wx.DirDialog(self.mainframe,
                           "Add Dir\All Media files to Music List",
                           ".",
                           0,
                           name="Add Dir")
     path = []
     if dialog.ShowModal() == wx.ID_OK:
         path = dialog.GetPath()
     else:
         return
     for root, dirs, files in os.walk(path):
         for file in files:
             filename = os.path.join(root, file)
             if self.m3u.isExists(filename):
                 continue
             if filename[-4:].lower() in [
                     '.mp3', '.wav', '.mid', '.wma', '.asf'
             ]:
                 file = common.decode_string(
                     filename, common.defaultfilesystemencoding)
                 record = {}
                 if filename.lower().endswith(".mp3"):
                     from PyMp3Info import MP3FileInfo
                     fi = MP3FileInfo(filename)
                     if fi.parse():
                         record['Author-Title'] = (fi['author']
                                                   and fi['author'] + ' - '
                                                   or '') + fi['title']
                     else:
                         record['Author-Title'] = os.path.split(
                             filename)[-1]
                 else:
                     record['Author-Title'] = os.path.split(filename)[-1]
                 try:
                     from pySonic import FileStream
                     f = FileStream(
                         common.encode_string(
                             filename, common.defaultfilesystemencoding), 0)
                     record['Time'] = str(int(f.Duration))
                     del f
                 except:
                     dlg = wx.MessageDialog(
                         self,
                         tr('Can\'t add file [%s] or this file isn\'t a media file!'
                            ) % filename, tr('Error'),
                         wx.OK | wx.ICON_ERROR)
                     dlg.ShowModal()
                     dlg.Destroy()
                     continue
                 record['Path'] = filename
                 self.m3u.Append(record)
                 self.addrecord(record)
     self.m3u.SaveToFile(self.defm3u)
コード例 #24
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
 def rename(self):
     index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
     if index >= 0:
         pathname = self.list.GetItemText(index)
         dlg = MyTextEntry(self, tr("Name Input"), tr('Input a new name:'), '')
         answer = dlg.ShowModal()
         if answer == wx.ID_OK:
             newpath = dlg.GetValue()
             if not newpath:
                 return
             flag = self.list.GetItemData(index)
             if flag != 2:   #dir
                 try:
                     self.ftp.rename(common.decode_string(pathname), common.decode_string(newpath))
                 except Exception, msg:
                     error.traceback()
                     common.showerror(self, msg)
                     return
             if self.refresh(self.curpath):
                 index = self.list.FindItem(-1, newpath)
                 self.list.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_MASK_STATE)
コード例 #25
0
ファイル: EditorFactory.py プロジェクト: LaoMa3953/ulipad
    def getDispTitle(self, ctrl):
        if ctrl.title:
            return ctrl.title

        if ctrl.isModified():
            pagetitle = ctrl.getFilename() + ' *'
        else:
            pagetitle = ctrl.getFilename()

        if isinstance(pagetitle, str):
            pagetitle = common.decode_string(pagetitle, common.defaultfilesystemencoding)

        return pagetitle
コード例 #26
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
    def upload(self):
        dlg = UploadFileEntry(self)
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            filename, newfile, bin = dlg.GetValue()
            if not filename:
                common.showerror(self, tr("The filename can't be empty."))
                return
            if not newfile:
                newfile = os.path.basename(filename)
            #check if the new name has existed
            index = self.list.FindItem(-1, newfile)
            if index > -1:
                dlg = wx.MessageDialog(self, tr("The filename already exists. Do you want to overwrite it?"), tr("Upload File"), wx.YES_NO | wx.ICON_QUESTION)
                answer = dlg.ShowModal()
                if answer == wx.ID_NO:
                    return

            common.setmessage(self.mainframe, tr('Uploading the file...'))
#           if not self.setBin(bin):
#               return
            from StringIO import StringIO
            try:
                if bin:
                    f = StringIO(file(filename, 'rb').read())
                    self.ftp.storbinary('STOR %s' % common.decode_string(newfile), f)
                else:
                    f = StringIO(file(filename, 'r').read())
                    self.ftp.storlines('STOR %s' % common.decode_string(newfile), f)
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            self.setBin(True)
            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, newfile)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_MASK_STATE)
            common.setmessage(self.mainframe, tr('Uploading finished'))
コード例 #27
0
ファイル: EditorFactory.py プロジェクト: zztalker/ulipad
    def getDispTitle(self, ctrl):
        if ctrl.title:
            return ctrl.title

        if ctrl.isModified():
            pagetitle = ctrl.getFilename() + ' *'
        else:
            pagetitle = ctrl.getFilename()

        if isinstance(pagetitle, str):
            pagetitle = common.decode_string(pagetitle,
                                             common.defaultfilesystemencoding)

        return pagetitle
コード例 #28
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
    def download(self):
        index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
        if index >= 0:
            flag = self.list.GetItemData(index)
            if flag == 2:
                return
            filename = self.list.GetItemText(index)
            dlg = DownloadFileEntry(self, filename)
            answer = dlg.ShowModal()
            if answer == wx.ID_OK:
                newfile, bin = dlg.GetValue()
                if not newfile:
                    common.showerror(self, tr("The filename can't be empty."))
                    return
            else:
                return

            common.setmessage(self.mainframe, tr('Downloading the file...'))
            try:
                try:
                    if bin:
                        f = file(newfile, 'wb')
                        def getdata(d, f=f):
                            f.write(d)
                        self.ftp.retrbinary("RETR %s" % common.decode_string(filename), getdata)
                    else:
                        f = file(newfile, 'w')
                        def getdata(d, f=f):
                            f.write(d+"\n")
                        self.ftp.retrlines("RETR %s" % common.decode_string(filename), getdata)
                except Exception, msg:
                    error.traceback()
                    common.showerror(self, msg)
                    return
            finally:
                f.close()
            common.setmessage(self.mainframe, tr('Downloading finished'))
コード例 #29
0
 def Load(self, filepath=None):
     if filepath:
         self.filepath = filepath
     if not self.filepath or not os.path.isfile(
             self.filepath) or not self.filepath.lower().endswith('.m3u'):
         raise LoadMusicListException()
     lines = open(self.filepath, 'r').readlines()
     if lines[0].upper().strip() != '#EXTM3U':
         raise LoadMusicListException()
     p = re.compile('#EXTINF:(?P<time>\d*?),(?P<titleauthor>.*?)$')
     for i in range(1, len(lines), 2):
         if not lines[i].startswith('#EXTINF'):
             continue
         result = p.search(lines[i].strip())
         path = common.decode_string(lines[i + 1].strip(),
                                     common.defaultfilesystemencoding)
         title = common.decode_string(result.group('titleauthor'),
                                      common.defaultfilesystemencoding)
         self.data.append({
             'Author-Title': title,
             'Time': result.group('time'),
             'Path': path
         })
     return True
コード例 #30
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
 def refresh(self, path=''):
     if not path:
         path = self.txtPath.GetValue()
     try:
         common.setmessage(self.mainframe, tr('Changing the current directory...'))
         self.ftp.cwd(common.encode_string(path))
         self.data = []
         self.ftp.retrlines('LIST', self.receivedData)
         self.curpath = common.decode_string(self.ftp.pwd())
         self.txtPath.SetValue(self.curpath)
         self.loadFile(self.data)
     except Exception, msg:
         common.showerror(self, msg)
         error.traceback()
         return
コード例 #31
0
 def refresh(self, path=''):
     if not path:
         path = self.txtPath.GetValue()
     try:
         common.setmessage(self.mainframe,
                           tr('Changing the current directory...'))
         self.ftp.cwd(common.encode_string(path))
         self.data = []
         self.ftp.retrlines('LIST', self.receivedData)
         self.curpath = common.decode_string(self.ftp.pwd())
         self.txtPath.SetValue(self.curpath)
         self.loadFile(self.data)
     except Exception, msg:
         common.showerror(self, msg)
         error.traceback()
         return
コード例 #32
0
ファイル: MusicListManage.py プロジェクト: LaoMa3953/ulipad
 def OnAddDir(self,event):
     dialog = wx.DirDialog(self.mainframe,
                            "Add Dir\All Media files to Music List",
                            ".",
                            0,
                            name="Add Dir"
                           )
     path=[]
     if dialog.ShowModal() == wx.ID_OK:
         path = dialog.GetPath()
     else:
         return
     for root, dirs, files in os.walk(path):
         for file in files:
             filename=os.path.join(root,file)
             if self.m3u.isExists(filename):
                 continue
             if filename[-4:].lower() in ['.mp3','.wav','.mid','.wma','.asf']:
                 file = common.decode_string(filename, common.defaultfilesystemencoding)
                 record={}
                 if filename.lower().endswith(".mp3"):
                     from PyMp3Info import MP3FileInfo
                     fi = MP3FileInfo(filename)
                     if fi.parse():
                         record['Author-Title']=(fi['author'] and fi['author']+' - ' or '')+fi['title']
                     else:
                         record['Author-Title']=os.path.split(filename)[-1]
                 else:
                     record['Author-Title']=os.path.split(filename)[-1]
                 try:
                     from pySonic import FileStream
                     f=FileStream(common.encode_string(filename, common.defaultfilesystemencoding), 0)
                     record['Time']=str(int(f.Duration))
                     del f
                 except:
                     dlg = wx.MessageDialog(self, tr('Can\'t add file [%s] or this file isn\'t a media file!') % filename,
                                    tr('Error'),
                                    wx.OK | wx.ICON_ERROR
                                    )
                     dlg.ShowModal()
                     dlg.Destroy()
                     continue
                 record['Path'] = filename
                 self.m3u.Append(record)
                 self.addrecord(record)
     self.m3u.SaveToFile(self.defm3u)
コード例 #33
0
ファイル: SvnSupport.py プロジェクト: zztalker/ulipad
    def cbk_update(self, event):
        if event['error']:
            self.result.add([tr('error'), event['error']])
        else:
            action = str(event['action'])
            if action.startswith('update_'):
                action = action[7:]
            elif action.startswith('commit_'):
                action = action[7:]

            if action == 'update':
                return
            elif action == 'completed':
                action = 'completed'
                path = 'At version %d' % event['revision'].number
            else:
                path = event['path']
            self.result.add([action, common.decode_string(path, 'utf8')])
コード例 #34
0
ファイル: SvnSupport.py プロジェクト: hfpiao/ulipad
    def cbk_update(self, event):
        if event["error"]:
            self.result.add([tr("error"), event["error"]])
        else:
            action = str(event["action"])
            if action.startswith("update_"):
                action = action[7:]
            elif action.startswith("commit_"):
                action = action[7:]

            if action == "update":
                return
            elif action == "completed":
                action = "completed"
                path = "At version %d" % event["revision"].number
            else:
                path = event["path"]
            self.result.add([action, common.decode_string(path, "utf8")])
コード例 #35
0
ファイル: SvnSupport.py プロジェクト: LaoMa3953/ulipad
 def cbk_update(self, event):
     if event['error']:
         self.result.add([tr('error'), event['error']])
     else:
         action = str(event['action'])
         if action.startswith('update_'):
             action = action[7:]
         elif action.startswith('commit_'):
             action = action[7:]
             
         if action == 'update':
             return
         elif action == 'completed':
             action = 'completed'
             path = 'At version %d' % event['revision'].number
         else:
             path = event['path']
         self.result.add([action, common.decode_string(path, 'utf8')])
コード例 #36
0
ファイル: UliPad.py プロジェクト: zztalker/ulipad
    def processCommandLineArguments(self):
        #process command line
        try:
            opts, args = getopt.getopt(sys.argv[1:], "e:E:vuhnsfm", [])
        except getopt.GetoptError:
            self.Usage()
            sys.exit(2)


#        self.defaultencoding = common.defaultencoding   #defaultencoding in common.py

        self.ddeflag = True
        self.psycoflag = False
        self.skipsessionfile = False
        self.multiuser = False

        for o, a in opts:
            if o == '-e':  #encoding
                common.defaultencoding = a
                common.defaultfilesystemencoding = a
            elif o == '-E':  #encoding
                common.defaultfilesystemencoding = a
            elif o == '-v':  #version
                self.Version()
                sys.exit()
            elif o == '-u' or o == '-h':  #usage
                self.Usage()
                sys.exit()
            elif o == '-n':  #no dde
                self.ddeflag = False
            elif o == '-s':
                self.psycoflag = True
            elif o == '-f':
                self.skipsessionfile = True
            elif o == '-m':
                self.multiuser = True
        files = args

        self.files = [
            common.decode_string(os.path.join(self.curpath, f)) for f in files
        ]
        self.callplugin('dde', self, self.files)
コード例 #37
0
ファイル: mFileNew.py プロジェクト: zztalker/ulipad
def new_file(win, lexname=None):
    if not lexname:
        lexname = win.pref.last_new_type
    if lexname:
        lexer = win.lexers.getNamedLexer(lexname)
        text = ''
        if lexer:
            templatefile = common.getConfigPathFile('template.%s' % lexer.name)
            if os.path.exists(templatefile):
                text = file(templatefile).read()
                text = common.decode_string(text)
                import re
                eolstring = {0: '\n', 1: '\r\n', 2: '\r'}
                eol = eolstring[Globals.pref.default_eol_mode]
                text = re.sub(r'\r\n|\r|\n', eol, text)
            else:
                text = ''
        document = win.editctrl.new(defaulttext=text, language=lexer.name)
        if document:
            document.goto(document.GetTextLength())
    else:
        win.editctrl.new()
コード例 #38
0
ファイル: UliPad.py プロジェクト: LaoMa3953/ulipad
    def processCommandLineArguments(self):
        #process command line
        try:
            opts, args = getopt.getopt(sys.argv[1:], "e:E:vuhnsfm", [])
        except getopt.GetoptError:
            self.Usage()
            sys.exit(2)
#        self.defaultencoding = common.defaultencoding   #defaultencoding in common.py

        self.ddeflag = True
        self.psycoflag = False
        self.skipsessionfile = False
        self.multiuser = False

        for o, a in opts:
            if o == '-e':       #encoding
                common.defaultencoding = a
                common.defaultfilesystemencoding = a
            elif o == '-E':       #encoding
                common.defaultfilesystemencoding = a
            elif o == '-v':     #version
                self.Version()
                sys.exit()
            elif o == '-u' or o == '-h':     #usage
                self.Usage()
                sys.exit()
            elif o == '-n':     #no dde
                self.ddeflag = False
            elif o == '-s':
                self.psycoflag = True
            elif o == '-f':
                self.skipsessionfile = True
            elif o == '-m':
                self.multiuser = True
        files = args

        self.files = [common.decode_string(os.path.join(self.curpath, f)) for f in files]
        self.callplugin('dde', self, self.files)
コード例 #39
0
ファイル: mFileNew.py プロジェクト: hfpiao/ulipad
def new_file(win, lexname=None):
    if not lexname:
        lexname = win.pref.last_new_type
    if lexname:
        lexer = win.lexers.getNamedLexer(lexname)
        text = ""
        if lexer:
            templatefile = common.getConfigPathFile("template.%s" % lexer.name)
            if os.path.exists(templatefile):
                text = file(templatefile).read()
                text = common.decode_string(text)
                import re

                eolstring = {0: "\n", 1: "\r\n", 2: "\r"}
                eol = eolstring[Globals.pref.default_eol_mode]
                text = re.sub(r"\r\n|\r|\n", eol, text)
            else:
                text = ""
        document = win.editctrl.new(defaulttext=text, language=lexer.name)
        if document:
            document.goto(document.GetTextLength())
    else:
        win.editctrl.new()
コード例 #40
0
ファイル: FtpClass.py プロジェクト: LinYuanLab/ulipad
    def newdir(self):
        dirname = ''
        dlg = MyTextEntry(self, tr("Directory Input"), tr('Input a new directory:'), '')
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            dirname = dlg.GetValue()
            if not dirname:
                return
            #check if the new name has existed
            index = self.list.FindItem(-1, dirname)
            if index > -1:
                common.showerror(self, tr('The directory already exists.\nPlease input another one.'))
                return
            try:
                self.ftp.mkd(common.decode_string(dirname))
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, dirname)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_MASK_STATE)
コード例 #41
0
ファイル: PyMp3Info.py プロジェクト: LinYuanLab/ulipad
 def parse(self, filepath=None):
     "parse ID3v1.0 tags from MP3 file"
     if filepath:
         self.filepath=filepath
     self.filepath=common.decode_string(self.filepath, common.defaultfilesystemencoding)
     self.info.clear()
     try:
         fsock = open(self.filepath, "rb", 0)
         try:
             fsock.seek(-128, 2)
             tagdata = fsock.read(128)
         finally:
             fsock.close()
         if tagdata[:3] == "TAG":
             for tag, (start, end, parseFunc) in self.tagDataMap.items():
                 self.info[tag] = parseFunc(tagdata[start:end])
             self.ishasinfo=True
         else:
             self.info['title']=self.filepath
             self.info['author']=''
     except IOError:
         error.traceback()
         return False
     return True
コード例 #42
0
ファイル: WizardPanel.py プロジェクト: LinYuanLab/ulipad
    def OnEnter(self, event):
        i = self.tree.GetPyData(event.GetItem())
        if not i: return
        x = self.items[i]
        mod, path = importfile(x)
        datafile = ''
        if x.options.datafile == 'open':
            from modules import FileDialog
            datafile = FileDialog.openfiledlg(tr('Open'), tr('Input a data file:'))
        old_path = os.getcwd()
        try:
            os.chdir(path)
            try:
                if x.options.execute == 'wizard':
                    from modules.EasyGuider import EasyCommander
                    easy = EasyCommander.EasyCommander(parent=self, easyfile=mod, inline=True, cmdoption='', outputencoding=x.options.encoding)
                    easy.inipickle = datafile
                    if x.options.output == 'inline':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run():
                            self.mainframe.document.AddText(common.decode_string(buf.getvalue(), x.options.encoding))
                    elif x.options.output == 'save':
                        from modules import FileDialog
                        datafile = FileDialog.savefiledlg(tr('Save'), tr('Input saving filename:'))
                        if datafile:
                            easy.outputfile = datafile
                            if easy.run():
                                self.mainframe.editctrl.new(datafile, encoding=x.options.encoding)
                    elif x.options.output == 'newfile':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run():
                            document = self.mainframe.editctrl.new()
                            document.SetText(common.decode_string(buf.getvalue(), x.options.encoding))
                    else:
                        if easy.run():
                            common.showmessage(self, tr("Completed!"))
                elif x.options.execute == 'program':
                    easy = mod
                    easy.datafile = datafile
                    if x.options.output == 'inline':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run(self.mainframe, x):
                            self.mainframe.document.AddText(common.decode_string(buf.getvalue(), x.options.encoding))
                    elif x.options.output == 'save':
                        from modules import FileDialog
                        datafile = FileDialog.savefiledlg(tr('Save'), tr('Input saving filename:'))
                        if datafile:
                            easy.outputfile = datafile
                            if easy.run(self.mainframe, x):
                                self.mainframe.editctrl.new(datafile, encoding=x.options.encoding)
                    elif x.options.output == 'newfile':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run(self.mainframe, x):
                            document = self.mainframe.editctrl.new()
                            document.SetText(common.decode_string(buf.getvalue(), x.options.encoding))
                    else:
                        if easy.run(self.mainframe, x):
                            common.showmessage(self, tr("Completed!"))
            except:
                error.traceback()
                common.showerror(self, tr("There is something wrong, see the error.log!"))
        finally:
            os.chdir(old_path)

        if path:
            del sys.path[0]
コード例 #43
0
    def OnEnter(self, event):
        i = self.tree.GetPyData(event.GetItem())
        if not i: return
        x = self.items[i]
        mod, path = importfile(x)
        datafile = ''
        if x.options.datafile == 'open':
            from modules import FileDialog
            datafile = FileDialog.openfiledlg(tr('Open'),
                                              tr('Input a data file:'))
        old_path = os.getcwd()
        try:
            os.chdir(path)
            try:
                if x.options.execute == 'wizard':
                    from modules.EasyGuider import EasyCommander
                    easy = EasyCommander.EasyCommander(
                        parent=self,
                        easyfile=mod,
                        inline=True,
                        cmdoption='',
                        outputencoding=x.options.encoding)
                    easy.inipickle = datafile
                    if x.options.output == 'inline':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run():
                            self.mainframe.document.AddText(
                                common.decode_string(buf.getvalue(),
                                                     x.options.encoding))
                    elif x.options.output == 'save':
                        from modules import FileDialog
                        datafile = FileDialog.savefiledlg(
                            tr('Save'), tr('Input saving filename:'))
                        if datafile:
                            easy.outputfile = datafile
                            if easy.run():
                                self.mainframe.editctrl.new(
                                    datafile, encoding=x.options.encoding)
                    elif x.options.output == 'newfile':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run():
                            document = self.mainframe.editctrl.new()
                            document.SetText(
                                common.decode_string(buf.getvalue(),
                                                     x.options.encoding))
                    else:
                        if easy.run():
                            common.showmessage(self, tr("Completed!"))
                elif x.options.execute == 'program':
                    easy = mod
                    easy.datafile = datafile
                    if x.options.output == 'inline':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run(self.mainframe, x):
                            self.mainframe.document.AddText(
                                common.decode_string(buf.getvalue(),
                                                     x.options.encoding))
                    elif x.options.output == 'save':
                        from modules import FileDialog
                        datafile = FileDialog.savefiledlg(
                            tr('Save'), tr('Input saving filename:'))
                        if datafile:
                            easy.outputfile = datafile
                            if easy.run(self.mainframe, x):
                                self.mainframe.editctrl.new(
                                    datafile, encoding=x.options.encoding)
                    elif x.options.output == 'newfile':
                        import StringIO
                        buf = StringIO.StringIO()
                        easy.outputfile = buf
                        if easy.run(self.mainframe, x):
                            document = self.mainframe.editctrl.new()
                            document.SetText(
                                common.decode_string(buf.getvalue(),
                                                     x.options.encoding))
                    else:
                        if easy.run(self.mainframe, x):
                            common.showmessage(self, tr("Completed!"))
            except:
                error.traceback()
                common.showerror(
                    self, tr("There is something wrong, see the error.log!"))
        finally:
            os.chdir(old_path)

        if path:
            del sys.path[0]