def loadFiles(self, paths, type, skipMissing=False): items = [] errors = [] def load(paths, skipMissing): for path in paths: if os.path.isdir(path): for root, _, names in os.walk(path): paths = [os.path.join(root, name) for name in names] load(paths, skipMissing=True) else: loadFile(path, skipMissing) def loadFile(path, skipMissing): try: item = type(path=path) if item.hasMatchingStream(): items.append(item) elif not skipMissing: errors.append((path, _('There are no usable streams'))) except Exception as err: if not skipMissing or error.getExceptionField( err, 'averror') != 'AVERROR_INVALIDDATA': msg = error.getExceptionMessage( err) + '\n' + error.getExceptionDetails() errors.append((path, msg)) msg = _('Loading, please wait...') busydlg.showBusyDlgAsyncJob(self, msg, load, paths, skipMissing) if errors: msg = [_('Following files could not be added:')] msg += [path for path, _ in errors[:10]] if len(errors) > 10: msg.append(_('and {} more').format(len(errors) - 10)) with ErrorWin(self, '\n'.join(msg)) as dlg: for path, msg in errors: dlg.addDetails('FILE ' + path) dlg.addDetails(msg, '\n') dlg.ShowModal() return items
def addFiles(self, col, paths, index=None, sort=False): msg = _('Loading, please wait...') types = self.refs.types if col and not sort: types = col.types items, errors = busydlg.showBusyDlgAsyncJob(self, msg, self.loadFiles, paths, types) if sort: subsIndex, refsIndex = len(self.subs), len(self.refs) if index is not None: subsIndex = min(index, subsIndex) refsIndex = min(index, refsIndex) subs, refs = sortInputFiles(items) addedSubs = self.subs.addItems(subs, subsIndex) addedRefs = self.refs.addItems(refs, refsIndex) self.m_items.setSelection(addedSubs or addedRefs) added = addedSubs + addedRefs else: added = col.addItems(items, index or len(col)) self.m_items.setSelection(added) if len(paths) > len(added): msg = [_('Following files could not be added:')] msg += list( sorted(set(paths) - set(item.file.path for item in added))) with ErrorWin(self, '\n'.join(msg)) as dlg: for path in sorted( set([i.file.path for i in items]) - set([a.file.path for a in added])): dlg.addDetails('# {}'.format(path)) dlg.addDetails(_('There are no usable streams')) dlg.addDetails('\n') dlg.addDetails(*errors) dlg.ShowModal() elif errors: with ErrorWin(self, _('Unexpected error occured')) as dlg: dlg.addDetails(*errors) dlg.ShowModal() if added: self.m_items.updateSize() self.m_items.Refresh() self.onItemsChange()
def readStream(parent, file, path): msg = _('Loading, please wait...') f = copy(file) showBusyDlgAsyncJob(parent, msg, f.open, path=path) return f
def readStream(parent, path, types): msg = _('Loading, please wait...') return showBusyDlgAsyncJob(parent, msg, InputFile, path=path, types=types)