"Fossies" - the Fresh Open Source Software Archive

Member "ffmulticonverter-1.8.0/ffmulticonverter/imagetab.py" (25 Jun 2016, 4702 Bytes) of package /linux/privat/ffmulticonverter-1.8.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "imagetab.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.7.2_vs_1.8.0.

    1 # Copyright (C) 2011-2016 Ilias Stamatis <stamatis.iliass@gmail.com>
    2 #
    3 # This program is free software: you can redistribute it and/or modify
    4 # it under the terms of the GNU General Public License as published by
    5 # the Free Software Foundation, either version 3 of the License, or
    6 # (at your option) any later version.
    7 #
    8 # This program is distributed in the hope that it will be useful,
    9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11 # GNU General Public License for more details.
   12 #
   13 # You should have received a copy of the GNU General Public License
   14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   15 
   16 from PyQt5.QtCore import QRegExp
   17 from PyQt5.QtGui import QRegExpValidator
   18 from PyQt5.QtWidgets import (
   19         QWidget, QLabel, QComboBox, QCheckBox, QLineEdit, QMessageBox
   20         )
   21 
   22 from ffmulticonverter import utils
   23 from ffmulticonverter import config
   24 
   25 
   26 class ImageTab(QWidget):
   27     def __init__(self, parent):
   28         super(ImageTab, self).__init__(parent)
   29         self.parent = parent
   30         self.name = 'Images'
   31 
   32         self.formats = config.image_formats
   33         self.extra_img = config.image_extra_formats
   34 
   35         validator = QRegExpValidator(QRegExp(r'^[1-9]\d*'), self)
   36 
   37         converttoQL = QLabel(self.tr('Convert to:'))
   38         self.extQCB = QComboBox()
   39         commandQL = QLabel(self.tr('Extra options:'))
   40         self.commandQLE = QLineEdit()
   41 
   42         hlayout2 = utils.add_to_layout(
   43                 'h', converttoQL, self.extQCB, commandQL, self.commandQLE)
   44 
   45         sizeQL = QLabel(
   46                 '<html><p align="center">' + self.tr('Image Size:') +
   47                 '</p></html>')
   48         self.widthQLE = utils.create_LineEdit((50, 16777215), validator, 4)
   49         self.heightQLE = utils.create_LineEdit((50, 16777215), validator, 4)
   50         label = QLabel('<html><p align="center">x</p></html>')
   51         label.setMaximumWidth(25)
   52 
   53         hlayout1 = utils.add_to_layout('h', self.widthQLE, label,self.heightQLE)
   54         sizelayout = utils.add_to_layout('v', sizeQL, hlayout1)
   55 
   56         self.imgaspectQChB = QCheckBox(self.tr("Maintain aspect ratio"))
   57         self.autocropQChB = QCheckBox(self.tr("Auto-crop"))
   58 
   59         vlayout = utils.add_to_layout('v', self.imgaspectQChB,self.autocropQChB)
   60 
   61         rotateQL = QLabel(
   62                 "<html><div align='center'>" + self.tr("Rotate") +
   63                 ":</div><br>(" + self.tr("degrees - clockwise") + ")</html>")
   64         self.rotateQLE = utils.create_LineEdit((100, 16777215), validator, 3)
   65         self.vflipQChB = QCheckBox(self.tr('Vertical flip'))
   66         self.hflipQChB = QCheckBox(self.tr('Horizontal flip'))
   67 
   68         vlayout2 = utils.add_to_layout('v', self.vflipQChB, self.hflipQChB)
   69         hlayout3 = utils.add_to_layout(
   70                 'h', sizelayout, vlayout, rotateQL, self.rotateQLE,
   71                 vlayout2, None)
   72 
   73         final_layout = utils.add_to_layout('v', hlayout2, hlayout3)
   74         self.setLayout(final_layout)
   75 
   76     def clear(self):
   77         """Clear self.widthQLE and self.heightQLE."""
   78         self.widthQLE.clear()
   79         self.heightQLE.clear()
   80         self.commandQLE.clear()
   81         self.rotateQLE.clear()
   82         self.imgaspectQChB.setChecked(False)
   83         self.autocropQChB.setChecked(False)
   84         self.vflipQChB.setChecked(False)
   85         self.hflipQChB.setChecked(False)
   86 
   87     def fill_extension_combobox(self, extraformats):
   88         self.extQCB.clear()
   89         self.extQCB.addItems(sorted(self.formats + extraformats))
   90 
   91     def ok_to_continue(self):
   92         """
   93         Check if everything is ok with imagetab to continue conversion.
   94 
   95         Check if:
   96         - ImageMagick is missing.
   97         - Either none or both size lineEdits are active at a time.
   98 
   99         Return True if all tests pass, else False.
  100         """
  101         width = self.widthQLE.text()
  102         height = self.heightQLE.text()
  103 
  104         if not self.parent.imagemagick:
  105             QMessageBox.warning(self, 'FF Multi Converter - ' + self.tr(
  106                 'Error!'), self.tr('ImageMagick is not installed!'))
  107             return False
  108         if (width and not height) or (not width and height):
  109             QMessageBox.warning(self, 'FF Multi Converter - ' + self.tr(
  110                      'Error!'), self.tr('The size LineEdit may not be empty.'))
  111             if width and not height:
  112                 self.heightQLE.setFocus()
  113             else:
  114                 self.widthQLE.setFocus()
  115             return False
  116         return True
  117 
  118     def set_default_command(self):
  119         """Set the default value to self.commandQLE."""
  120         self.clear()
  121         self.commandQLE.setText(self.parent.default_command_image)