"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ffmulticonverter/ffmulticonverter.py" between
ffmulticonverter-1.7.2.tar.gz and ffmulticonverter-1.8.0.tar.gz

About: FF Multi Converter is a graphical application which enables you to convert audio, video, image and document files between all popular formats, using and combining other programs.

ffmulticonverter.py  (ffmulticonverter-1.7.2):ffmulticonverter.py  (ffmulticonverter-1.8.0)
# Copyright (C) 2011-2015 Ilias Stamatis <stamatis.iliass@gmail.com> # Copyright (C) 2011-2016 Ilias Stamatis <stamatis.iliass@gmail.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
skipping to change at line 23 skipping to change at line 23
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os import os
import sys import sys
import platform import platform
import textwrap import textwrap
import logging import logging
import webbrowser import webbrowser
from PyQt4.QtCore import ( from PyQt5.QtGui import QIcon, QKeySequence
PYQT_VERSION_STR, QCoreApplication, QLocale, QSettings, from PyQt5.QtCore import (
Qt, QTimer, QTranslator, QT_VERSION_STR PYQT_VERSION_STR, QCoreApplication, QLocale, QSettings, Qt,
QTranslator, QT_VERSION_STR
) )
from PyQt4.QtGui import ( from PyQt5.QtWidgets import (
QAbstractItemView, QApplication, QCheckBox, QFileDialog, QIcon, QAbstractItemView, QApplication, QCheckBox, QFileDialog, QLabel,
QKeySequence, QLabel, QLineEdit, QMainWindow, QMessageBox, QLineEdit, QMainWindow, QMessageBox, QPushButton, QShortcut, QTabWidget,
QPushButton, QShortcut, QTabWidget, QToolButton, QWidget QToolButton, QWidget
) )
import ffmulticonverter as ffmc import ffmulticonverter as ffmc
from ffmulticonverter import utils from ffmulticonverter import utils
from ffmulticonverter import config from ffmulticonverter import config
from ffmulticonverter import about_dlg from ffmulticonverter import about_dlg
from ffmulticonverter import preferences_dlg from ffmulticonverter import preferences_dlg
from ffmulticonverter import presets_dlgs from ffmulticonverter import presets_dlgs
from ffmulticonverter import progress from ffmulticonverter import progress
from ffmulticonverter import qrc_resources from ffmulticonverter import qrc_resources
skipping to change at line 105 skipping to change at line 106
self.dependenciesQL = QLabel() self.dependenciesQL = QLabel()
self.statusBar().addPermanentWidget(self.dependenciesQL, stretch=1) self.statusBar().addPermanentWidget(self.dependenciesQL, stretch=1)
widget = QWidget() widget = QWidget()
widget.setLayout(final_layout) widget.setLayout(final_layout)
self.setCentralWidget(widget) self.setCentralWidget(widget)
openAction = utils.create_action( openAction = utils.create_action(
self, self.tr('Open'), QKeySequence.Open, None, self, self.tr('Open'), QKeySequence.Open, None,
self.tr('Open a file'), self.add_files self.tr('Open a file'), self.filesList_add
) )
convertAction = utils.create_action( convertAction = utils.create_action(
self, self.tr('Convert'), 'Ctrl+C', None, self, self.tr('Convert'), 'Ctrl+C', None,
self.tr('Convert files'), self.start_conversion self.tr('Convert files'), self.start_conversion
) )
quitAction = utils.create_action( quitAction = utils.create_action(
self, self.tr('Quit'), 'Ctrl+Q', None, self, self.tr('Quit'), 'Ctrl+Q', None,
self.tr('Quit'), self.close self.tr('Quit'), self.close
) )
edit_presetsAction = utils.create_action( edit_presetsAction = utils.create_action(
skipping to change at line 191 skipping to change at line 192
[edit_presetsAction, importAction, exportAction, resetAction, [edit_presetsAction, importAction, exportAction, resetAction,
None, syncAction, removeoldAction] None, syncAction, removeoldAction]
) )
utils.add_actions(editMenu, [clearallAction, None, preferencesAction]) utils.add_actions(editMenu, [clearallAction, None, preferencesAction])
utils.add_actions( utils.add_actions(
helpMenu, helpMenu,
[trackerAction, wikiAction, None, ffmpegdocAction, [trackerAction, wikiAction, None, ffmpegdocAction,
imagemagickdocAction, None, aboutAction] imagemagickdocAction, None, aboutAction]
) )
self.filesList.dropped.connect(self.add_files_dropped) self.filesList.dropped.connect(self.filesList_add_dragged)
addQPB.clicked.connect(self.add_files) addQPB.clicked.connect(self.filesList_add)
delQPB.clicked.connect(self.delete_files) delQPB.clicked.connect(self.filesList_delete)
clearQPB.clicked.connect(self.clear_fileslist) clearQPB.clicked.connect(self.filesList_clear)
self.tabWidget.currentChanged.connect( self.tabWidget.currentChanged.connect(
lambda: self.tabs[0].moreQPB.setChecked(False)) lambda: self.tabs[0].moreQPB.setChecked(False))
self.origQCB.toggled.connect( self.origQCB.toggled.connect(
lambda: self.toQLE.setEnabled(not self.origQCB.isChecked())) lambda: self.toQLE.setEnabled(not self.origQCB.isChecked()))
self.toQTB.clicked.connect(self.open_dir) self.toQTB.clicked.connect(self.get_output_folder)
convertQPB.clicked.connect(convertAction.triggered) convertQPB.clicked.connect(convertAction.triggered)
del_shortcut = QShortcut(self) del_shortcut = QShortcut(self)
del_shortcut.setKey(Qt.Key_Delete) del_shortcut.setKey(Qt.Key_Delete)
del_shortcut.activated.connect(self.delete_files) del_shortcut.activated.connect(self.filesList_delete)
self.setWindowTitle('FF Multi Converter') self.setWindowTitle('FF Multi Converter')
QTimer.singleShot(0, self.check_for_dependencies) self.load_settings()
QTimer.singleShot(0, self.load_settings) self.check_for_dependencies()
QTimer.singleShot(0, self.audiovideo_tab.set_default_command)
QTimer.singleShot(0, self.image_tab.set_default_command) self.audiovideo_tab.set_default_command()
QTimer.singleShot(0, self.update_filesList) self.image_tab.set_default_command()
self.toQLE.setText(self.default_output)
self.filesList_update()
def parse_cla(self): def parse_cla(self):
"""Parse command line arguments.""" """Parse command line arguments."""
for i in QCoreApplication.argv()[1:]: for i in QCoreApplication.arguments()[1:]:
i = os.path.abspath(i) i = os.path.abspath(i)
if os.path.isfile(i): if os.path.isfile(i):
self.fnames.append(i) self.fnames.append(i)
else: else:
print("ffmulticonverter: {0}: Not a file".format(i)) print("ffmulticonverter: {0}: Not a file".format(i))
def check_for_dependencies(self): def check_for_dependencies(self):
""" """
Check if each one of the program dependencies are installed and Check if each one of the program dependencies are installed and
update self.dependenciesQL with the appropriate message. update self.dependenciesQL with the appropriate message.
""" """
self.vidconverter = None if not utils.is_installed(self.ffmpeg_path):
if utils.is_installed('ffmpeg'): self.ffmpeg_path = utils.is_installed('ffmpeg')
self.vidconverter = 'ffmpeg' QSettings().setValue('ffmpeg_path', self.ffmpeg_path)
elif utils.is_installed('avconv'):
self.vidconverter = 'avconv'
self.unoconv = utils.is_installed('unoconv') self.unoconv = utils.is_installed('unoconv')
self.imagemagick = utils.is_installed('convert') self.imagemagick = utils.is_installed('convert')
missing = [] missing = []
if self.vidconverter is None: if not self.ffmpeg_path:
missing.append('ffmpeg/avconv') missing.append('ffmpeg')
if not self.unoconv: if not self.unoconv:
missing.append('unoconv') missing.append('unoconv')
if not self.imagemagick: if not self.imagemagick:
missing.append('imagemagick') missing.append('imagemagick')
if missing: if missing:
missing = ', '.join(missing) missing = ', '.join(missing)
status = self.tr('Missing dependencies:') + ' ' + missing status = self.tr('Missing dependencies:') + ' ' + missing
self.dependenciesQL.setText(status) self.dependenciesQL.setText(status)
def load_settings(self, onstart=True): def load_settings(self):
"""
Load settings values.
onstart -- True means that this is the first time the method called,
usually when program beggins
"""
def get_str_value(settings, name):
value = settings.value(name)
if value is not None:
return value
return ''
settings = QSettings() settings = QSettings()
self.overwrite_existing = utils.str_to_bool(
get_str_value(settings, 'overwrite_existing'))
self.default_output = get_str_value(settings, 'default_output')
self.prefix = get_str_value(settings, 'prefix')
self.suffix = get_str_value(settings, 'suffix')
defcmd = get_str_value(settings, 'default_command')
extraformats_video = get_str_value(settings, 'extraformats')
videocodecs = settings.value('videocodecs')
audiocodecs = settings.value('audiocodecs')
defcmd_image = get_str_value(settings, 'default_command_image')
extraformats_image = get_str_value(settings, 'extraformats_image')
if videocodecs is None:
videocodecs = "\n".join(config.video_codecs)
settings.setValue('videocodecs', videocodecs)
if audiocodecs is None:
audiocodecs = "\n".join(config.audio_codecs)
settings.setValue('audiocodecs', audiocodecs)
if defcmd:
self.default_command = defcmd
else:
self.default_command = config.default_ffmpeg_cmd
if defcmd_image:
self.default_command_image = defcmd_image
else:
self.default_command_image = config.default_imagemagick_cmd
self.audiovideo_tab.fill_video_comboboxes( self.overwrite_existing = settings.value('overwrite_existing', type=bool
videocodecs, audiocodecs, extraformats_video) )
self.image_tab.fill_extension_combobox(extraformats_image) self.default_output = settings.value('default_output', type=str)
self.prefix = settings.value('prefix', type=str)
self.suffix = settings.value('suffix', type=str)
self.ffmpeg_path = settings.value('ffmpeg_path', type=str)
self.default_command = (settings.value('default_command', type=str) or
config.default_ffmpeg_cmd)
# type=list won't work for some reason
extraformats_video = (settings.value('extraformats_video') or [])
videocodecs = (settings.value('videocodecs') or config.video_codecs)
audiocodecs = (settings.value('audiocodecs') or config.audio_codecs)
self.default_command_image = (settings.value('default_command_image',
type=str) or
config.default_imagemagick_cmd)
extraformats_image = (settings.value('extraformats_image') or [])
extraformats_document = (settings.value('extraformats_document') or [])
if onstart: self.audiovideo_tab.fill_video_comboboxes(videocodecs,
self.toQLE.setText(self.default_output) audiocodecs, extraformats_video)
self.image_tab.fill_extension_combobox(extraformats_image)
self.document_tab.fill_extension_combobox(extraformats_document)
def current_tab(self): def get_current_tab(self):
"""Return the corresponding object of the selected tab."""
for i in self.tabs: for i in self.tabs:
if self.tabs.index(i) == self.tabWidget.currentIndex(): if self.tabs.index(i) == self.tabWidget.currentIndex():
return i return i
def update_filesList(self): def filesList_update(self):
"""Clear self.filesList and add to it all items of self.fname."""
self.filesList.clear() self.filesList.clear()
for i in self.fnames: for i in self.fnames:
self.filesList.addItem(i) self.filesList.addItem(i)
def add_files(self): def filesList_add(self):
""" filters = 'All Files (*);;'
Get file names using a standard Qt dialog. filters += 'Audio/Video Files (*.{});;'.format(
Append to self.fnames each file name that not already exists ' *.'.join(self.audiovideo_tab.formats))
and update self.filesList. filters += 'Image Files (*.{});;'.format(
""" ' *.'.join(self.image_tab.formats + self.image_tab.extra_img))
# Create lists holding file formats extension. filters += 'Document Files (*.{})'.format(
# To be passed in QFileDialog.getOpenFileNames(). ' *.'.join(self.document_tab.formats))
all_files = '*'
audiovideo_files = ' '.join(
['*.'+i for i in self.audiovideo_tab.formats])
img_formats = self.image_tab.formats[:]
img_formats.extend(self.image_tab.extra_img)
image_files = ' '.join(['*.'+i for i in img_formats])
document_files = ' '.join(['*.'+i for i in self.document_tab.formats])
formats = [all_files, audiovideo_files, image_files, document_files]
strings = [self.tr('All Files'), self.tr('Audio/Video Files'),
self.tr('Image Files'), self.tr('Document Files')]
filters = ''
for string, extensions in zip(strings, formats):
filters += string + ' ({0});;'.format(extensions)
filters = filters[:-2] # remove last ';;'
fnames = QFileDialog.getOpenFileNames(self, 'FF Multi Converter - ' + fnames = QFileDialog.getOpenFileNames(self, 'FF Multi Converter - ' +
self.tr('Choose File'), config.home, filters) self.tr('Choose File'), config.home, filters,
options=QFileDialog.HideNameFilterDetails)[0]
if fnames: if fnames:
for i in fnames: for i in fnames:
if not i in self.fnames: if not i in self.fnames:
self.fnames.append(i) self.fnames.append(i)
self.update_filesList() self.filesList_update()
def add_files_dropped(self, links): def filesList_add_dragged(self, links):
"""
Append to self.fnames each file name that not already exists
and update self.filesList.
"""
for path in links: for path in links:
if os.path.isfile(path) and not path in self.fnames: if os.path.isfile(path) and not path in self.fnames:
self.fnames.append(path) self.fnames.append(path)
self.update_filesList() self.filesList_update()
def delete_files(self): def filesList_delete(self):
"""
Get selectedItems of self.filesList, remove them from self.fnames and
update the filesList.
"""
items = self.filesList.selectedItems() items = self.filesList.selectedItems()
if items: if items:
for i in items: for i in items:
self.fnames.remove(i.text()) self.fnames.remove(i.text())
self.update_filesList() self.filesList_update()
def clear_fileslist(self): def filesList_clear(self):
"""Make self.fnames empty and update self.filesList."""
self.fnames = [] self.fnames = []
self.update_filesList() self.filesList_update()
def clear_all(self): def clear_all(self):
"""Clear all values of graphical widgets.""" """Clears or sets to default the values of all graphical widgets."""
self.toQLE.clear() self.toQLE.clear()
self.origQCB.setChecked(False) self.origQCB.setChecked(False)
self.deleteQCB.setChecked(False) self.deleteQCB.setChecked(False)
self.clear_fileslist() self.filesList_clear()
self.audiovideo_tab.clear() self.audiovideo_tab.clear()
self.image_tab.clear() self.image_tab.clear()
def open_dir(self): def get_output_folder(self):
"""
Get a directory name using a standard QtDialog and update
self.toQLE with dir's name.
"""
if self.toQLE.isEnabled(): if self.toQLE.isEnabled():
output = QFileDialog.getExistingDirectory( output = QFileDialog.getExistingDirectory(
self, 'FF Multi Converter - ' + self, 'FF Multi Converter - ' +
self.tr('Choose output destination'), self.tr('Choose output destination'),
config.home) config.home)
if output: if output:
self.toQLE.setText(output) self.toQLE.setText(output)
def import_presets(self): def import_presets(self):
presets_dlgs.ShowPresets().import_presets() presets_dlgs.ShowPresets().import_presets()
skipping to change at line 428 skipping to change at line 377
try: try:
if not self.fnames: if not self.fnames:
raise ValidationError( raise ValidationError(
self.tr('You must add at least one file to convert!')) self.tr('You must add at least one file to convert!'))
elif not self.origQCB.isChecked() and not self.toQLE.text(): elif not self.origQCB.isChecked() and not self.toQLE.text():
raise ValidationError( raise ValidationError(
self.tr('You must choose an output folder!')) self.tr('You must choose an output folder!'))
elif (not self.origQCB.isChecked() and elif (not self.origQCB.isChecked() and
not os.path.exists(self.toQLE.text())): not os.path.exists(self.toQLE.text())):
raise ValidationError(self.tr('Output folder does not exists!')) raise ValidationError(self.tr('Output folder does not exists!'))
if not self.current_tab().ok_to_continue(): if not self.get_current_tab().ok_to_continue():
return False return False
return True return True
except ValidationError as e: except ValidationError as e:
QMessageBox.warning( QMessageBox.warning(
self, 'FF Multi Converter - ' + self.tr('Error!'), str(e)) self, 'FF Multi Converter - ' + self.tr('Error!'), str(e))
return False return False
def get_output_extension(self):
"""Extract the desired output file extension from GUI and return it."""
tab = self.current_tab()
if tab.name == 'AudioVideo':
ext_to = self.audiovideo_tab.extQCB.currentText()
elif tab.name == 'Images':
ext_to = tab.extQCB.currentText()
else:
ext_to = tab.convertQCB.currentText().split()[-1]
return '.' + ext_to
def start_conversion(self): def start_conversion(self):
""" """
Extract the appropriate information from GUI and call the Extract the appropriate information from GUI and call the
Progress dialog with the suitable argumens. Progress dialog with the suitable argumens.
""" """
if not self.ok_to_continue(): if not self.ok_to_continue():
return return
tab = self.current_tab() tab = self.get_current_tab()
ext_to = '.' + tab.extQCB.currentText()
if tab.name == 'Documents' and not self.office_listener_started: if tab.name == 'Documents' and not self.office_listener_started:
utils.start_office_listener() utils.start_office_listener()
self.office_listener_started = True self.office_listener_started = True
ext_to = self.get_output_extension()
_list = utils.create_paths_list( _list = utils.create_paths_list(
self.fnames, ext_to, self.prefix, self.suffix, self.fnames, ext_to, self.prefix, self.suffix,
self.toQLE.text(), self.origQCB.isChecked(), self.toQLE.text(), self.origQCB.isChecked(),
self.overwrite_existing self.overwrite_existing
) )
dialog = progress.Progress( dialog = progress.Progress(
_list, tab, self.deleteQCB.isChecked(), self) _list, tab, self.deleteQCB.isChecked(), self)
dialog.show() dialog.show()
def open_dialog_preferences(self): def open_dialog_preferences(self):
"""Open the preferences dialog.""" """Open the preferences dialog."""
dialog = preferences_dlg.Preferences(self) dialog = preferences_dlg.Preferences(self)
if dialog.exec_(): if dialog.exec_():
self.load_settings(onstart=False) self.load_settings()
def open_dialog_presets(self): def open_dialog_presets(self):
"""Open the presets dialog.""" """Open the presets dialog."""
dialog = presets_dlgs.ShowPresets(self) dialog = presets_dlgs.ShowPresets(self)
dialog.exec_() dialog.exec_()
def open_dialog_about(self): def open_dialog_about(self):
"""Call the about dialog with the appropriate values.""" """Call the about dialog with the appropriate values."""
msg = self.tr('Convert among several file types to other formats') msg = self.tr('Convert among several file types to other formats')
msg = textwrap.fill(msg, 54).replace('\n', '<br>') msg = textwrap.fill(msg, 54).replace('\n', '<br>')
text = '''<b> FF Multi Converter {0} </b> text = '''<b> FF Multi Converter {0} </b>
<p>{1} <p>{1}
<p><a href="{2}">FF Multi Converter - Home Page</a> <p><a href="{2}">FF Multi Converter - Home Page</a>
<p>Copyright &copy; 2011-2015 {3} <p>Copyright &copy; 2011-2016 {3}
<br>License: {4} <br>License: {4}
<p>Python {5} - Qt {6} - PyQt {7} on {8}'''\ <p>Python {5} - Qt {6} - PyQt {7} on {8}'''\
.format(ffmc.__version__, msg, ffmc.__url__, ffmc.__author__, .format(ffmc.__version__, msg, ffmc.__url__, ffmc.__author__,
ffmc.__license__, platform.python_version()[:5], ffmc.__license__, platform.python_version()[:5],
QT_VERSION_STR, PYQT_VERSION_STR, platform.system()) QT_VERSION_STR, PYQT_VERSION_STR, platform.system())
image = ':/ffmulticonverter.png' image = ':/ffmulticonverter.png'
authors = '{0} <{1}>\n\n'.format(ffmc.__author__, ffmc.__author_email__) authors = '{0} <{1}>\n\n'.format(ffmc.__author__, ffmc.__author_email__)
authors += 'Contributors:\nPanagiotis Mavrogiorgos' authors += 'Contributors:\nPanagiotis Mavrogiorgos'
translators = [] translators = []
for i in config.translators: for i in config.translators:
 End of changes. 35 change blocks. 
141 lines changed or deleted 80 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS