示例#1
0
文件: ringers.py 项目: deosai/bitpim
 def ReplaceContents(self, name, origin, new_file_name):
     """Replace the contents of 'file_name' by the contents of
     'new_file_name' by going through the image converter dialog
     """
     file_stat=os.stat(new_file_name)
     mtime=file_stat.st_mtime
     afi=fileinfo.identify_audiofile(new_file_name)
     if afi.size<=0:
         return # zero length file or other issues
     newext,convertinfo=self.mainwindow.phoneprofile.QueryAudio(
         None, common.getext(new_file_name), afi)
     if convertinfo is not afi:
         filedata=None
         try:
             filedata=self.ConvertFormat(new_file_name, convertinfo)
         except:
             pass
         if filedata is None:
             return
     else:
         filedata=open(new_file_name, "rb").read()
     # check for the size limit on the file, if specified
     max_size=getattr(convertinfo, 'MAXSIZE', None)
     if max_size is not None and len(filedata)>max_size:
         # the data is too big
         self.log('ringtone %s is too big!'%common.basename(file))
         with guihelper.WXDialogWrapper(wx.MessageDialog(self,
                                                         'Ringtone %s may be too big.  Do you want to proceed anway?'%common.basename(file),
                                                         'Warning',
                                                         style=wx.YES_NO|wx.ICON_ERROR),
                                        True) as (dlg, dlg_resp):
             if dlg_resp==wx.ID_NO:
                 return
     self.AddToIndex(name, origin, filedata, self._data, mtime)
 def ReplaceContents(self, name, origin, new_file_name):
     """Replace the contents of 'file_name' by the contents of
     'new_file_name' by going through the image converter dialog
     """
     file_stat=os.stat(new_file_name)
     mtime=file_stat.st_mtime
     afi=fileinfo.identify_audiofile(new_file_name)
     if afi.size<=0:
         return # zero length file or other issues
     newext,convertinfo=self.mainwindow.phoneprofile.QueryAudio(
         None, common.getext(new_file_name), afi)
     if convertinfo is not afi:
         filedata=None
         try:
             filedata=self.ConvertFormat(new_file_name, convertinfo)
         except:
             pass
         if filedata is None:
             return
     else:
         filedata=open(new_file_name, "rb").read()
     max_size=getattr(convertinfo, 'MAXSIZE', None)
     if max_size is not None and len(filedata)>max_size:
         self.log('ringtone %s is too big!'%common.basename(file))
         dlg=wx.MessageDialog(self,
                              'Ringtone %s may be too big.  Do you want to proceed anway?'%common.basename(file),
                              'Warning',
                              style=wx.YES_NO|wx.ICON_ERROR)
         dlg_resp=dlg.ShowModal()
         dlg.Destroy()
         if dlg_resp==wx.ID_NO:
             return
     self.AddToIndex(name, origin, filedata, self._data, mtime)
示例#3
0
文件: ringers.py 项目: deosai/bitpim
 def OnAddFiles(self, filenames):
     for file in filenames:
         if file is None: continue  # failed dragdrop?
         file_stat=os.stat(file)
         mtime=file_stat.st_mtime
         if self._raw_media:
             target=self.get_media_name_from_filename(file)
             data=open(file, 'rb').read()
             self.AddToIndex(target, self.active_section, data, self._data, mtime)
         else:
             # do we want to convert file?
             afi=fileinfo.identify_audiofile(file)
             if afi.size<=0: continue # zero length file or other issues
             newext,convertinfo=self.mainwindow.phoneprofile.QueryAudio(None, common.getext(file), afi)
             if convertinfo is not afi:
                 filedata=None
                 wx.EndBusyCursor()
                 try:
                     filedata=self.ConvertFormat(file, convertinfo)
                 finally:
                     # ensure they match up
                     wx.BeginBusyCursor()
                 if filedata is None:
                     continue
             else:
                 filedata=open(file, "rb").read()
             # check for the size limit on the file, if specified
             max_size=getattr(convertinfo, 'MAXSIZE', None)
             if max_size is not None and len(filedata)>max_size:
                 # the data is too big
                 self.log('ringtone %s is too big!'%common.basename(file))
                 with guihelper.WXDialogWrapper(wx.MessageDialog(self,
                                                                 'Ringtone %s may be too big.  Do you want to proceed anway?'%common.basename(file),
                                                                 'Warning',
                                                                 style=wx.YES_NO|wx.ICON_ERROR),
                                                True) as (dlg, dlg_resp):
                     if dlg_resp==wx.ID_NO:
                         continue
             target=self.get_media_name_from_filename(file, newext)
             self.AddToIndex(target, self.active_section, filedata, self._data, mtime)
     self.OnRefresh()
示例#4
0
 def OnAddFiles(self, filenames):
     for file in filenames:
         if file is None: continue  # failed dragdrop?
         file_stat=os.stat(file)
         mtime=file_stat.st_mtime
         if self._raw_media:
             target=self.get_media_name_from_filename(file)
             data=open(file, 'rb').read()
             self.AddToIndex(target, self.active_section, data, self._data, mtime)
         else:
             # do we want to convert file?
             afi=fileinfo.identify_audiofile(file)
             if afi.size<=0: continue # zero length file or other issues
             newext,convertinfo=self.mainwindow.phoneprofile.QueryAudio(None, common.getext(file), afi)
             if convertinfo is not afi:
                 filedata=None
                 wx.EndBusyCursor()
                 try:
                     filedata=self.ConvertFormat(file, convertinfo)
                 finally:
                     # ensure they match up
                     wx.BeginBusyCursor()
                 if filedata is None:
                     continue
             else:
                 filedata=open(file, "rb").read()
             # check for the size limit on the file, if specified
             max_size=getattr(convertinfo, 'MAXSIZE', None)
             if max_size is not None and len(filedata)>max_size:
                 # the data is too big
                 self.log('ringtone %s is too big!'%common.basename(file))
                 with guihelper.WXDialogWrapper(wx.MessageDialog(self,
                                                                 'Ringtone %s may be too big.  Do you want to proceed anway?'%common.basename(file),
                                                                 'Warning',
                                                                 style=wx.YES_NO|wx.ICON_ERROR),
                                                True) as (dlg, dlg_resp):
                     if dlg_resp==wx.ID_NO:
                         continue
             target=self.get_media_name_from_filename(file, newext)
             self.AddToIndex(target, self.active_section, filedata, self._data, mtime)
     self.OnRefresh()
 def OnAddFiles(self, filenames):
     self.thedir=self.mainwindow.ringerpath
     for file in filenames:
         if file is None: continue  # failed dragdrop?
         if self._raw_media:
             decoded_file=self.decodefilename(file)
             target=self.getshortenedbasename(decoded_file)
             open(target, 'wb').write(open(file, 'rb').read())
             self.AddToIndex(str(os.path.basename(target)).decode(fileview.media_codec))
         else:
             afi=fileinfo.identify_audiofile(file)
             if afi.size<=0: continue # zero length file or other issues
             newext,convertinfo=self.mainwindow.phoneprofile.QueryAudio(None, common.getext(file), afi)
             if convertinfo is not afi:
                 filedata=None
                 wx.EndBusyCursor()
                 try:
                     filedata=self.ConvertFormat(file, convertinfo)
                 finally:
                     wx.BeginBusyCursor()
                 if filedata is None:
                     continue
             else:
                 filedata=open(file, "rb").read()
             max_size=getattr(convertinfo, 'MAXSIZE', None)
             if max_size is not None and len(filedata)>max_size:
                 self.log('ringtone %s is too big!'%common.basename(file))
                 dlg=wx.MessageDialog(self,
                                      'Ringtone %s may be too big.  Do you want to proceed anway?'%common.basename(file),
                                      'Warning',
                                      style=wx.YES_NO|wx.ICON_ERROR)
                 dlg_resp=dlg.ShowModal()
                 dlg.Destroy()
                 if dlg_resp==wx.ID_NO:
                     continue
             decoded_file=self.decodefilename(file)
             target=self.getshortenedbasename(decoded_file, newext)
             open(target, "wb").write(filedata)
             self.AddToIndex(str(os.path.basename(target)).decode(fileview.media_codec))
     self.OnRefresh()
 def GetFileInfo(self, filename):
     return fileinfo.identify_audiofile(filename)
示例#7
0
文件: ringers.py 项目: deosai/bitpim
 def GetFileInfo(self, filename):
     return fileinfo.identify_audiofile(filename)