"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ffmulticonverter/preferences_dlg.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.

preferences_dlg.py  (ffmulticonverter-1.7.2):preferences_dlg.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.
# #
# 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/>.
from PyQt4.QtCore import QSettings, QTimer import os
from PyQt4.QtGui import (
from PyQt5.QtCore import QSettings, QTimer
from PyQt5.QtWidgets import (
QDialog, QDialogButtonBox, QFileDialog, QLabel, QLineEdit, QDialog, QDialogButtonBox, QFileDialog, QLabel, QLineEdit,
QRadioButton, QSpacerItem, QTabWidget, QToolButton, QWidget, QRadioButton, QSpacerItem, QTabWidget, QToolButton, QWidget,
QPlainTextEdit, QPushButton QPlainTextEdit, QPushButton
) )
from ffmulticonverter import utils from ffmulticonverter import utils
from ffmulticonverter import config from ffmulticonverter import config
class Preferences(QDialog): class Preferences(QDialog):
def __init__(self, parent=None, test = False): def __init__(self, parent=None, test = False):
skipping to change at line 63 skipping to change at line 65
tabwidget1_layout = utils.add_to_layout( tabwidget1_layout = utils.add_to_layout(
'v', saveQL, 'v', saveQL,
QSpacerItem(14, 13), existQL, exist_layout, QSpacerItem(14, 13), existQL, exist_layout,
QSpacerItem(14, 13), defaultQL, deafult_fol_layout, QSpacerItem(14, 13), defaultQL, deafult_fol_layout,
QSpacerItem(13, 13), nameQL, QSpacerItem(14, 13), QSpacerItem(13, 13), nameQL, QSpacerItem(14, 13),
prefix_layout, None prefix_layout, None
) )
ffmpegQL = QLabel('<html><b>FFmpeg</b></html>') ffmpegQL = QLabel('<html><b>FFmpeg</b></html>')
ffmpeg_pathQL= QLabel(self.tr('Path to executable:'))
self.ffmpegpathQLE = QLineEdit()
default_cmd_ffmpegQL = QLabel(self.tr('Default command:')) default_cmd_ffmpegQL = QLabel(self.tr('Default command:'))
self.ffmpegcmdQLE = QLineEdit() self.ffmpegcmdQLE = QLineEdit()
vidcodecsQL = QLabel( vidcodecsQL = QLabel(
'<html><b>' + self.tr('Video codecs') +'</b></html>') '<html><b>' + self.tr('Video codecs') +'</b></html>')
self.vidcodecsQPTE = QPlainTextEdit() self.vidcodecsQPTE = QPlainTextEdit()
audcodecsQL = QLabel( audcodecsQL = QLabel(
'<html><b>' + self.tr('Audio codecs') +'</b></html>') '<html><b>' + self.tr('Audio codecs') +'</b></html>')
self.audcodecsQPTE = QPlainTextEdit() self.audcodecsQPTE = QPlainTextEdit()
extraformatsffmpegQL = QLabel( extraformatsffmpegQL = QLabel(
skipping to change at line 89 skipping to change at line 94
self.extraformatsffmpegQPTE] self.extraformatsffmpegQPTE]
) )
defvidcodecsQPB = QPushButton(self.tr("Default video codecs")) defvidcodecsQPB = QPushButton(self.tr("Default video codecs"))
defaudcodecsQPB = QPushButton(self.tr("Default audio codecs")) defaudcodecsQPB = QPushButton(self.tr("Default audio codecs"))
hlayout1 = utils.add_to_layout( hlayout1 = utils.add_to_layout(
'h', None, defvidcodecsQPB, defaudcodecsQPB) 'h', None, defvidcodecsQPB, defaudcodecsQPB)
tabwidget2_layout = utils.add_to_layout( tabwidget2_layout = utils.add_to_layout(
'v', ffmpegQL, 'v', ffmpegQL, QSpacerItem(14, 13), ffmpeg_pathQL,
QSpacerItem(14, 13), default_cmd_ffmpegQL, self.ffmpegcmdQLE, self.ffmpegpathQLE, default_cmd_ffmpegQL, self.ffmpegcmdQLE,
QSpacerItem(20, 20), gridlayout, hlayout1, None QSpacerItem(20, 20), gridlayout, hlayout1, None
) )
imagemagickQL = QLabel('<html><b>ImageMagick (convert)</b></html>') imagemagickQL = QLabel('<html><b>ImageMagick (convert)</b></html>')
default_cmd_imageQL = QLabel(self.tr('Default options:')) default_cmd_imageQL = QLabel(self.tr('Default options:'))
self.imagecmdQLE = QLineEdit() self.imagecmdQLE = QLineEdit()
extraformatsimageQL = QLabel( extraformatsimageQL = QLabel(
'<html><b>' + self.tr('Extra formats') +'</b></html>') '<html><b>' + self.tr('Extra formats') +'</b></html>')
self.extraformatsimageQPTE = QPlainTextEdit() self.extraformatsimageQPTE = QPlainTextEdit()
hlayout2 = utils.add_to_layout('h', self.extraformatsimageQPTE, QSpacerI hlayout2 = utils.add_to_layout('h',
tem(220,20)) self.extraformatsimageQPTE, QSpacerItem(220,20))
tabwidget3_layout = utils.add_to_layout( tabwidget3_layout = utils.add_to_layout(
'v', imagemagickQL, 'v', imagemagickQL,
QSpacerItem(14,13), default_cmd_imageQL, self.imagecmdQLE, QSpacerItem(14,13), default_cmd_imageQL, self.imagecmdQLE,
QSpacerItem(20,20), extraformatsimageQL, hlayout2, None QSpacerItem(20,20), extraformatsimageQL, hlayout2, None
) )
extraformatsdocumentQL = QLabel(
'<html><b>' + self.tr('Extra formats') +'</b></html>')
self.extraformatsdocumentQPTE = QPlainTextEdit()
hlayout3 = utils.add_to_layout('h',
self.extraformatsdocumentQPTE, QSpacerItem(220,20))
tabwidget4_layout = utils.add_to_layout(
'v', extraformatsdocumentQL, hlayout3, None)
widget1 = QWidget() widget1 = QWidget()
widget1.setLayout(tabwidget1_layout) widget1.setLayout(tabwidget1_layout)
widget2 = QWidget() widget2 = QWidget()
widget2.setLayout(tabwidget2_layout) widget2.setLayout(tabwidget2_layout)
widget3 = QWidget() widget3 = QWidget()
widget3.setLayout(tabwidget3_layout) widget3.setLayout(tabwidget3_layout)
widget4 = QWidget()
widget4.setLayout(tabwidget4_layout)
tabWidget = QTabWidget() tabWidget = QTabWidget()
tabWidget.addTab(widget1, self.tr('General')) tabWidget.addTab(widget1, self.tr('General'))
tabWidget.addTab(widget2, self.tr('Audio/Video')) tabWidget.addTab(widget2, self.tr('Audio/Video'))
tabWidget.addTab(widget3, self.tr('Images')) tabWidget.addTab(widget3, self.tr('Images'))
tabWidget.addTab(widget4, self.tr('Documents'))
buttonBox = QDialogButtonBox( buttonBox = QDialogButtonBox(
QDialogButtonBox.Ok|QDialogButtonBox.Cancel) QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
final_layout = utils.add_to_layout('v', tabWidget, None, buttonBox) final_layout = utils.add_to_layout('v', tabWidget, None, buttonBox)
self.setLayout(final_layout) self.setLayout(final_layout)
self.defaultQTB.clicked.connect(self.open_dir) self.defaultQTB.clicked.connect(self.open_dir)
buttonBox.accepted.connect(self.save_settings) buttonBox.accepted.connect(self.save_settings)
buttonBox.rejected.connect(self.reject) buttonBox.rejected.connect(self.reject)
defvidcodecsQPB.clicked.connect(self.set_default_videocodecs) defvidcodecsQPB.clicked.connect(
defaudcodecsQPB.clicked.connect(self.set_default_audiocodecs) lambda: self.set_videocodecs(config.video_codecs))
defaudcodecsQPB.clicked.connect(
lambda: self.set_audiocodecs(config.audio_codecs))
self.resize(400, 450) self.resize(400, 450)
self.setWindowTitle(self.tr('Preferences')) self.setWindowTitle(self.tr('Preferences'))
QTimer.singleShot(0, self.load_settings) QTimer.singleShot(0, self.load_settings)
def load_settings(self): def load_settings(self):
"""Load settings and update graphical widgets with loaded values.""" """Load settings and update graphical widgets with loaded values."""
settings = QSettings() settings = QSettings()
overwrite_existing = utils.str_to_bool( overwrite_existing = settings.value('overwrite_existing', type=bool)
settings.value('overwrite_existing')) default_output = settings.value('default_output', type=str)
default_output = settings.value('default_output') prefix = settings.value('prefix', type=str)
prefix = settings.value('prefix') suffix = settings.value('suffix', type=str)
suffix = settings.value('suffix') ffmpeg_path = settings.value('ffmpeg_path', type=str)
default_command = settings.value('default_command') default_command = (settings.value('default_command', type=str) or
videocodecs = settings.value('videocodecs') config.default_ffmpeg_cmd)
audiocodecs = settings.value('audiocodecs') videocodecs = (settings.value('videocodecs') or config.video_codecs)
extraformats_video = settings.value('extraformats') audiocodecs = (settings.value('audiocodecs') or config.audio_codecs)
default_command_image = settings.value('default_command_image') extraformats_video = (settings.value('extraformats_video') or [])
extraformats_image = settings.value('extraformats_image') 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 [])
# QSettings.value() returns str() in python3, not QVariant() as in p2
if overwrite_existing: if overwrite_existing:
self.exst_overwriteQRB.setChecked(True) self.exst_overwriteQRB.setChecked(True)
else: else:
self.exst_prefixQRB.setChecked(True) self.exst_prefixQRB.setChecked(True)
if default_output:
self.defaultQLE.setText(default_output)
if prefix:
self.prefixQLE.setText(prefix)
if suffix:
self.suffixQLE.setText(suffix)
if default_command:
self.ffmpegcmdQLE.setText(default_command)
else:
self.ffmpegcmdQLE.setText(config.default_ffmpeg_cmd)
if not videocodecs: self.defaultQLE.setText(default_output)
self.set_default_videocodecs() self.prefixQLE.setText(prefix)
else: self.suffixQLE.setText(suffix)
self.vidcodecsQPTE.setPlainText(videocodecs) self.ffmpegpathQLE.setText(ffmpeg_path)
if not audiocodecs: self.ffmpegcmdQLE.setText(default_command)
self.set_default_audiocodecs self.set_videocodecs(videocodecs)
else: self.set_audiocodecs(audiocodecs)
self.audcodecsQPTE.setPlainText(audiocodecs) self.extraformatsffmpegQPTE.setPlainText("\n".join(extraformats_video))
self.extraformatsffmpegQPTE.setPlainText(extraformats_video) self.imagecmdQLE.setText(default_command_image)
self.extraformatsimageQPTE.setPlainText("\n".join(extraformats_image))
self.extraformatsdocumentQPTE.setPlainText("\n".join(extraformats_docume
nt))
if default_command_image: def set_videocodecs(self, codecs):
self.imagecmdQLE.setText(default_command_image) self.vidcodecsQPTE.setPlainText("\n".join(codecs))
else:
self.imagecmdQLE.setText(config.default_imagemagick_cmd)
self.extraformatsimageQPTE.setPlainText(extraformats_image)
def set_default_videocodecs(self): def set_audiocodecs(self, codecs):
self.vidcodecsQPTE.setPlainText("\n".join(config.video_codecs)) self.audcodecsQPTE.setPlainText("\n".join(codecs))
def set_default_audiocodecs(self):
self.audcodecsQPTE.setPlainText("\n".join(config.audio_codecs))
def open_dir(self): def open_dir(self):
"""Get a directory name using a standard Qt dialog and update """Get a directory name using a standard Qt dialog and update
self.defaultQLE with dir's name.""" self.defaultQLE with dir's name."""
if self.defaultQLE.isEnabled(): if self.defaultQLE.isEnabled():
_dir = QFileDialog.getExistingDirectory( _dir = QFileDialog.getExistingDirectory(
self, 'FF Multi Converter - ' + self, 'FF Multi Converter - ' +
self.tr('Choose default output destination'), config.home self.tr('Choose default output destination'), config.home
) )
if _dir: if _dir:
self.defaultQLE.setText(_dir) self.defaultQLE.setText(_dir)
@staticmethod
def plaintext_to_list(widget, formats=[]):
"""
Parse the text from a QPlainTextEdit widget and return a list.
The list will consist of every text line that is a single word
and it's not in the formats list. No duplicates allowed.
"""
_list = []
for line in widget.toPlainText().split("\n"):
line = line.strip()
if len(line.split()) == 1 and line not in (_list+formats):
_list.append(line)
return _list
def save_settings(self): def save_settings(self):
"""Set settings values, extracting the appropriate information from """Set settings values by extracting the appropriate information from
the graphical widgets.""" the graphical widgets."""
# remove empty codecs videocodecs = self.plaintext_to_list(self.vidcodecsQPTE)
videocodecs = [] audiocodecs = self.plaintext_to_list(self.audcodecsQPTE)
audiocodecs = [] extraformats_video = self.plaintext_to_list(self.extraformatsffmpegQPTE,
extraformats_video = [] config.video_formats)
extraformats_image = [] extraformats_image = self.plaintext_to_list(self.extraformatsimageQPTE,
config.image_formats)
for i in self.vidcodecsQPTE.toPlainText().split("\n"): extraformats_document = self.plaintext_to_list(
i = i.strip() self.extraformatsdocumentQPTE, config.document_formats)
if len(i.split()) == 1 and i not in videocodecs: # i single word
videocodecs.append(i)
for i in self.audcodecsQPTE.toPlainText().split("\n"):
i = i.strip()
if len(i.split()) == 1 and i not in audiocodecs:
audiocodecs.append(i)
for i in self.extraformatsffmpegQPTE.toPlainText().split("\n"):
i = i.strip()
if len(i.split()) == 1 and i not in extraformats_video \
and i not in config.video_formats:
extraformats_video.append(i)
for i in self.extraformatsimageQPTE.toPlainText().split("\n"):
i = i.strip()
if len(i.split()) == 1 and i not in extraformats_image \
and i not in config.image_formats:
extraformats_image.append(i)
videocodecs = "\n".join(sorted(videocodecs))
audiocodecs = "\n".join(sorted(audiocodecs))
extraformats_video = "\n".join(sorted(extraformats_video))
extraformats_image = "\n".join(sorted(extraformats_image))
settings = QSettings() settings = QSettings()
settings.setValue(
'overwrite_existing', self.exst_overwriteQRB.isChecked()) ffmpeg_path = os.path.expanduser(self.ffmpegpathQLE.text())
settings.setValue( if not utils.is_installed(ffmpeg_path):
'default_output', self.defaultQLE.text()) ffmpeg_path = utils.is_installed('ffmpeg')
settings.setValue(
'prefix', self.prefixQLE.text()) settings.setValue('overwrite_existing', self.exst_overwriteQRB.isChecked
settings.setValue( ())
'suffix', self.suffixQLE.text()) settings.setValue('default_output', self.defaultQLE.text())
settings.setValue( settings.setValue('prefix', self.prefixQLE.text())
'default_command', self.ffmpegcmdQLE.text()) settings.setValue('suffix', self.suffixQLE.text())
settings.setValue( settings.setValue('ffmpeg_path', ffmpeg_path)
'videocodecs', videocodecs) settings.setValue('default_command', self.ffmpegcmdQLE.text())
settings.setValue( settings.setValue('videocodecs', sorted(videocodecs))
'audiocodecs', audiocodecs) settings.setValue('audiocodecs', sorted(audiocodecs))
settings.setValue( settings.setValue('extraformats_video', sorted(extraformats_video))
'extraformats', extraformats_video) settings.setValue('default_command_image', self.imagecmdQLE.text())
settings.setValue( settings.setValue('extraformats_image', sorted(extraformats_image))
'default_command_image', self.imagecmdQLE.text()) settings.setValue('extraformats_document', sorted(extraformats_document)
settings.setValue( )
'extraformats_image', extraformats_image)
self.accept() self.accept()
 End of changes. 19 change blocks. 
103 lines changed or deleted 103 lines changed or added

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