class AwindowMotherFucker(QtGui.QMainWindow):
    " A Window M**********r ! "
    def __init__(self):
        " Initialize the Class "
        QtGui.QWidget.__init__(self)
        # Main Window initial Geometry
        self.setGeometry(100, 100, 640, 400)
        # Main Window initial Title
        self.setWindowTitle('CMYK2RGB')
        # Main Window Minimum Size
        self.setMinimumSize(640, 350)
        # Main Window Maximum Size
        self.setMaximumSize(800, 480)
        # Main Window initial StatusBar Message
        self.statusBar().showMessage('CMYK2RGB (Grafica Libre Tool)')
        # Main Window initial ToolTip
        self.setToolTip('Grafica Libre Tools for Ubuntu')
        # Main Window initial Font type
        self.setFont(QtGui.QFont('Ubuntu Light', 10))
        # Main Window Icon
        self.setWindowIcon(QtGui.QIcon('.icon.svg'))
        # Tux image decoration, a QLabel with a QPixmap inside
        self.label = QLabel(self)
        pixmap = QPixmap('.icon.svg')
        self.label.setPixmap(pixmap)
        self.label.setGeometry(405, 12, 300, 300)
        # this always gives the current user Home Folder, cross-platform
        homedir = os.path.expanduser("~")
        # this is the supported file extensions y *.* wildcard
        extensions = ';;'.join(['(*%s)' % e for e in ['.psd', '.icc', '']])
        # print homedir and extensions variables for debug
        print(' INFO: My Home is ' + homedir + ',im using: ' + str(extensions))
        # Menu Bar inicialization and detail definitions
        menu_salir = QtGui.QAction(QtGui.QIcon.fromTheme("application-exit"),
            'Quit | Salir', self)
        menu_salir.setShortcut('Ctrl+Q')
        menu_salir.setStatusTip('Menu Salir')
        self.connect(menu_salir, QtCore.SIGNAL('triggered()'),
            QtGui.qApp, QtCore.SLOT('quit()'))
        # about self
        menu_self = QtGui.QAction(QtGui.QIcon.fromTheme("help-contents"),
            'About | Acerca de', self)
        menu_self.setStatusTip('About self')
        self.connect(menu_self, QtCore.SIGNAL('triggered()'),
            lambda: QMessageBox.about(self, ' CMYK2RGB ',
            unicode(__doc__ + ',\nversion ' + __version__ + '(' + __license__ +
            '),\n by ' + __author__ + ', ( ' + __email__ + ' ). \n\n ' +
            'This program takes proprietary closed canned files\n ' +
            'and produce libre open files, and other magics !; \n' +
            'nothing but Pure, Clean, Open Source Software!.\n\n' +
            'Built for Grafica Libre + Ubuntu-AR community...')))
        # about Qt
        menu_qt = QtGui.QAction(QtGui.QIcon.fromTheme("help-contents"),
            'About Qt | Acerca de Qt', self)
        menu_qt.setStatusTip('About Qt')
        self.connect(menu_qt, QtCore.SIGNAL('triggered()'),
            lambda: QMessageBox.aboutQt(self))

        # about python
        menu_py = QtGui.QAction(QtGui.QIcon.fromTheme("help-contents"),
            'About Python | Acerca de Python', self)
        # set the status tip for this menu item
        menu_py.setStatusTip('About Python...')
        # set the triggered signal to lambda for online about python
        self.connect(menu_py, QtCore.SIGNAL('triggered()'),
            lambda: webbrowser.open_new_tab('http://www.python.org/about'))

        # get support help
        menu_support = QtGui.QAction(QtGui.QIcon.fromTheme("help-faq"),
            'Get Help Online | Obtener Ayuda en Linea', self)
        # set the status tip for this menu item
        menu_support.setStatusTip('Get Help Online...')
        # set the triggered signal to lambda for online help
        self.connect(menu_support, QtCore.SIGNAL('triggered()'),
            lambda: webbrowser.open('mailto:[email protected]'))

        # qt color setting via qcolordialog menu item
        menu_color = QtGui.QAction(
            QtGui.QIcon.fromTheme("preferences-system"),
            'Set GUI Colors | Configurar Colores de GUI', self)
        # set the status tip for this menu item
        menu_color.setStatusTip('Manually set GUI Colors...')
        # set the triggered signal to the showQColorDialog
        self.connect(menu_color, QtCore.SIGNAL('triggered()'),
            self.showQColorDialog)

        # theme setting
        menu_theme = QtGui.QAction(QtGui.QIcon.fromTheme("preferences-system"),
            'Use App GUI Skin | Usar Skin de la App', self)
        # set the status tip for this menu item
        menu_theme.setStatusTip('Use App GUI Skin...')
        # set the triggered signal to the applySkin
        self.connect(menu_theme, QtCore.SIGNAL('triggered()'), self.applySkin)

        # define the menu
        menu = self.menuBar()
        menu.setToolTip('Menu')
        archivo = menu.addMenu('&Archivo')
        archivo.addAction(menu_salir)

        # Settings menu
        settings = menu.addMenu('&Settings')
        settings.addAction(menu_color)
        settings.addAction(menu_theme)

        # Help menu items
        jelp = menu.addMenu('&Help')
        jelp.addAction(menu_support)
        jelp.addSeparator()
        jelp.addAction(menu_self)
        jelp.addAction(menu_qt)
        jelp.addAction(menu_py)

        #
        # Main Input Widgets
        self.label1 = QtGui.QLabel(
            'Elije 2 Archivos .ICC (1 CMYK, 1 RGB) y 1 Archivo .PSD (CMYK)...',
            self)
        self.label1.setGeometry(5, 25, 390, 25)
        self.label1.setAutoFillBackground(True)
        # this is the QFileDialog to open files using a open file dialog gui
        self.btn1 = QtGui.QPushButton('Abrir Archivo .ICC CMYK Origen', self)
        self.btn1.setGeometry(5, 50, 390, 25)
        self.btn1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.btn1, QtCore.SIGNAL('clicked()'),
            lambda: open('.cmyk2rgb-cmyk-icc.txt', 'w').write(unicode(
            QFileDialog.getOpenFileName(self, self.tr("Open File... "),
            homedir, extensions))))
        self.connect(self.btn1, QtCore.SIGNAL('released()'),
         lambda: self.btn1.setText(open('.cmyk2rgb-cmyk-icc.txt', 'r').read()))
        # .ICC
        self.btn2 = QtGui.QPushButton('Abrir Archivo .ICC RGB Destino', self)
        self.btn2.setGeometry(5, 75, 390, 25)
        self.btn2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.btn2, QtCore.SIGNAL('clicked()'),
            lambda: open('.cmyk2rgb-rgb-icc.txt', 'w').write(unicode(
            QFileDialog.getOpenFileName(self, self.tr("Open File... "),
            homedir, extensions))))
        self.connect(self.btn2, QtCore.SIGNAL('released()'),
         lambda: self.btn2.setText(open('.cmyk2rgb-rgb-icc.txt', 'r').read()))
        # .PSD
        self.btn3 = QtGui.QPushButton('Abrir Archivo .PSD CMYK', self)
        self.btn3.setGeometry(5, 100, 390, 25)
        self.btn3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.btn3, QtCore.SIGNAL('clicked()'),
            lambda: open('.cmyk2rgb-cmyk-psd.txt', 'w').write(unicode(
            QFileDialog.getOpenFileName(self, self.tr("Open File... "),
            homedir, extensions))))
        self.connect(self.btn3, QtCore.SIGNAL('released()'),
         lambda: self.btn3.setText(open('.cmyk2rgb-cmyk-psd.txt', 'r').read()))
        # Conversion Intents settings
        self.label2 = QtGui.QLabel('Intent: ', self)
        self.label2.setGeometry(535, 25, 100, 25)
        self.label2.setAutoFillBackground(True)
        # -intent
        self.combo1 = QComboBox(self)
        self.combo1.setGeometry(535, 50, 100, 25)
        self.combo1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.combo1.addItems(['relative', 'absolute',
                              'perceptual', 'saturation'])
        # Color Depth settings
        self.label3 = QtGui.QLabel('Depth: ', self)
        self.label3.setGeometry(535, 75, 100, 25)
        self.label3.setAutoFillBackground(True)
        # -depth
        self.combo2 = QComboBox(self)
        self.combo2.setGeometry(535, 100, 100, 25)
        self.combo2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.combo2.addItems(['8', '16', '4', '2'])
        # Alpha settings
        self.label4 = QtGui.QLabel('Alpha: ', self)
        self.label4.setGeometry(535, 125, 100, 25)
        self.label4.setAutoFillBackground(True)
        # -alpha
        self.combo3 = QComboBox(self)
        self.combo3.setGeometry(535, 150, 100, 25)
        self.combo3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.combo3.addItems(['on', 'activate', 'off', 'deactivate', '0', '1',
                              'opaque', 'copy', 'transparent', 'extract',
                              'background', 'shape'])
        # AutoMagical Extras
        self.label5 = QtGui.QLabel('Magical Extras: ', self)
        self.label5.setGeometry(535, 175, 100, 25)
        self.label5.setAutoFillBackground(True)
        # this enumerates ALL the so called Auto-Magical flag settings
        self.combo4 = QComboBox(self)
        self.combo4.setGeometry(535, 200, 100, 25)
        self.combo4.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.combo4.addItems(['NINGUNO!', 'TODAS JUNTAS?',
                             ' -antialias ', ' -auto-gamma ', ' -auto-level ',
                             ' -clamp ', ' -clip ', ' -despeckle ', ' -fft ',
                             ' -enhance ', ' -equalize ', ' -flip ', ' -flop ',
                             ' -ift ', ' -monochrome ', ' -negate ', ' -trim ',
                             ' -normalize ', ' -transpose ', ' -transverse ',
                             ' -unique-colors ', ' -flatten ', ' -reverse '
                             ])
        # this are the commands to run from the gui
        self.label6 = QtGui.QLabel(
            'Luego, puedes ejecutar alguna de estas Acciones...', self)
        self.label6.setGeometry(5, 150, 390, 25)
        self.label6.setAutoFillBackground(True)
        # LIBERAR PSD CMYK HACIA RGB GIMP
        self.boton1 = QtGui.QPushButton(
            'LIBERAR PSD CMYK HACIA RGB GIMP', self)
        self.boton1.setGeometry(5, 175, 390, 25)
        self.boton1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.boton1, QtCore.SIGNAL('clicked()'), self.komberty)
        # IDENTIFICAR DATOS DE .PSD CMYK
        self.boton2 = QtGui.QPushButton('IDENTIFICAR DATOS DE .PSD CMYK', self)
        self.boton2.setGeometry(5, 200, 390, 25)
        self.boton2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.boton2, QtCore.SIGNAL('clicked()'), self.identy)
        # EXTRAER ARCHIVO .ICC DE .PSD CMYK
        self.boton3 = QtGui.QPushButton(
            'EXTRAER ARCHIVO .ICC DE .PSD CMYK', self)
        self.boton3.setGeometry(5, 225, 390, 25)
        self.boton3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.boton3, QtCore.SIGNAL('clicked()'), self.xtract)
        # Make a HTML5  W.WEBP file and a uncompressed .PNG file
        self.boton4 = QtGui.QPushButton(
            'LIBERAR PSD CMYK HACIA HTML5 .WEBP + .PNG', self)
        self.boton4.setGeometry(5, 250, 390, 25)
        self.boton4.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.boton4, QtCore.SIGNAL('clicked()'), self.webpify)
        # Imagen a texto plano base64
        self.boton5 = QtGui.QPushButton(
            'CONVERTIR IMAGEN A TEXTO PLANO BASE64', self)
        self.boton5.setGeometry(5, 275, 390, 25)
        self.boton5.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        # NOTE: hardcoded Chromium web browser call command, not my Bug,
        # for some reason cant use webbrowser.open(),because on some systems it
        # try to open the base64 with incorrect programs (like gvfs, etc)
        self.connect(self.boton5, QtCore.SIGNAL('clicked()'),
            lambda: commands.getoutput(
            'chromium-browser "data:image/jpg;base64,' + base64.b64encode(open(
            QFileDialog.getOpenFileName(self, "Open a Image File to Encode...",
            os.path.expanduser("~"),
            ';;'.join(['(*%s)' % e for e in ['.jpg', '.png', '.webp', '']])),
            "rb").read()) + '"'))
        # Imagen a NormalMap
        self.boton6 = QtGui.QPushButton(
            'CONVERTIR IMAGEN A NORMALMAP PNG', self)
        self.boton6.setGeometry(5, 300, 390, 25)
        self.boton6.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.connect(self.boton6, QtCore.SIGNAL('clicked()'), self.normalify)

    def komberty(self):
        " Main Conversion Function, dont Complain, Patch! "
        print('\n WAIT!!!, WORKING . . . ')
        self.statusBar().showMessage('WAIT!!!, WORKING . . . ')
        # get vars
        arg1 = unicode(open('.cmyk2rgb-cmyk-icc.txt', 'r').read())
        arg2 = unicode(open('.cmyk2rgb-rgb-icc.txt', 'r').read())
        arg3 = unicode(open('.cmyk2rgb-cmyk-psd.txt', 'r').read())
        arg4 = unicode(self.combo1.currentText())
        arg5 = unicode(self.combo2.currentText())
        arg6 = unicode(self.combo3.currentText())
        # handle special auto-magical settings
        if self.combo4.currentText() == 'NINGUNO!':
            # no magic!, low Mana ?
            arg7 = ''
            print(' INFO: NOT using AutoMagical Extras or Flying Unicorns...')
        elif self.combo4.currentText() == 'TODAS JUNTAS?':
            # this is an internal/backend debugging and benchmarking tool...
            arg7 = ' -antialias -auto-gamma -auto-level -enhance -normalize '
            print('\n INFO: RUN FOR YOUR LIFE!, THIS IS GOING TO EXPLODE!! \n')
        else:
            arg7 = unicode(self.combo4.currentText())
            print(' INFO: using AutoMagical Extras of ' + arg7 + '...')
        # convert
        print(' INFO: Working with ' + arg1 + ', ' + arg2 + ', ' + arg3)
        print(' INFO: My Intent is ' + arg4 + ', using Color Depth of ' + arg5)
        print(' INFO: The Alpha Channel Setting is ' + arg6 + '...')
        self.statusBar().showMessage('Working:' + arg1 + arg2 + arg3)
        commands.getoutput('convert -profile ' + arg1 + ' -profile ' + arg2 +
                         ' -intent ' + arg4 + ' -depth ' + arg5 + ' -alpha ' +
                         arg6 + arg7 + ' -strip -colorspace RGB ' + arg3 + ' '
                         + arg3 + '.tiff' +
              ' ; sleep 1 ; gimp --no-data --no-fonts --no-splash --as-new ' +
                         arg3 + '.tiff')
        self.statusBar().showMessage('Done.')
        print(' INFO: Done. ')

    def identy(self):
        " Identification of the input .PSD file "
        print('\n WAIT!!!, WORKING . . . ')
        self.statusBar().showMessage('WAIT!!!, WORKING . . . ')
        arg3 = unicode(open('.cmyk2rgb-cmyk-psd.txt', 'r').read())
        # print arg3
        cmd1 = commands.getoutput('identify -verbose ' + arg3)
        # print cmd1
        filename = "cmyk2rgb_report.txt"
        try:
            # write Report
            print(' Saving Report to ' + filename + "...")
            self.statusBar().showMessage('Saving Report to ' + filename)
            fout = open(filename, "w")
            fout.write(cmd1)
            fout.close()
            # open Report
            print(' Opening Report ' + filename + "...")
            self.statusBar().showMessage('Opening Report ' + filename + "...")
            webbrowser.open_new_tab(filename)
            self.statusBar().showMessage('Done.')
            print(' INFO: Done. ')
        # except if IO has an error, print an error
        except IOError:
            print " ERROR: File %s could not be saved!" % filename
            self.statusBar().showMessage("ERROR: File could not be saved!")

    def xtract(self):
        " Extract .ICC File from .PSD CMYK File "
        print('\n WAIT!!!, WORKING . . . ')
        self.statusBar().showMessage('WAIT!!!, WORKING . . . ')
        # get vars
        arg3 = unicode(open('.cmyk2rgb-cmyk-psd.txt', 'r').read())
        # print info
        print(' INFO: Working with ' + arg3 + ' . . . ')
        self.statusBar().showMessage(' Working with ' + arg3 + ' . . . ')
        # extract the .icc files from the .psd file
        commands.getoutput('convert ' + arg3 + ' ' + arg3 + '.icc')
        print(' INFO: Done. ')
        self.statusBar().showMessage('Done.')

    def webpify(self):
        'Make a .WEBP file for HTML5 web development and design, on base64 '
        print('\n WAIT!!!, WORKING . . . ')
        self.statusBar().showMessage('WAIT!!!, WORKING . . . ')
        # get vars
        arg1 = unicode(open('.cmyk2rgb-cmyk-icc.txt', 'r').read())
        arg2 = unicode(open('.cmyk2rgb-rgb-icc.txt', 'r').read())
        arg3 = unicode(open('.cmyk2rgb-cmyk-psd.txt', 'r').read())
        arg4 = unicode(self.combo1.currentText())
        arg5 = unicode(self.combo2.currentText())
        arg6 = unicode(self.combo3.currentText())
        # print info
        print(' INFO: Working with ' + arg1 + ', ' + arg2 + ', ' + arg3)
        print(' INFO: My Intent is ' + arg4 + ', using Color Depth of ' + arg5)
        print(' INFO: The Alpha Channel Setting is ' + arg6 + '...')
        self.statusBar().showMessage('Working:' + arg1 + arg2 + arg3)
        # try to get version of WebP and print the info
        try:
            cmd1 = commands.getoutput('cwebp -version')
            print(' INFO: WORKING WITH: \n' + cmd1)
        # except if it has an error, print an error, and quit
        except:
            print(' ERROR: No WEBP Converter!\n ( sudo apt-get install webp )')
            exit()
        # NOTE: hardcoded Chromium web browser call command, not my Bug,
        # Firefox dont want to open .WEBP images, go complain to Mozilla.
        #
        # Convert
        commands.getoutput('convert -profile ' + arg1 + ' -profile ' + arg2 +
                         ' -intent ' + arg4 + ' -depth ' + arg5 + ' -alpha ' +
                         arg6 + ' -strip -flatten -colorspace RGB ' + arg3 +
                         ' ' + arg3 + '.png' +
                    ' ; sleep 1 ; cwebp -preset text -m 6 -strong -pass 10 ' +
                         arg3 + '.png -o ' + arg3 +
                         '.webp ; sleep 1 ; chromium-browser ' + arg3 +
                         '.webp'
                         )
        self.statusBar().showMessage('Done.')
        print(' INFO: Done. ')

    def normalify(self):
        ' make a normal map from image '
        def height2bump(heightBand, filter="Random"):
            ' oooooh, look a nested function!, are they bad ? '
            if filter == "Sobel":
                a1 = 500
                a2 = 64
                a3 = 0
                b1 = 1
                b2 = 250
                b3 = 666
            elif filter == "Scharr":
                a1 = 21.38
                a2 = 85.24
                a3 = 0
                b1 = 5.96
                b2 = 61.81
                b3 = 255
            elif filter == "Random":           # 5x5 random filter
                a1 = float(randint(0, 255))
                a2 = float(randint(0, 255))
                a3 = float(randint(0, 255))
                b1 = float(randint(0, 255))
                b2 = float(randint(0, 255))
                b3 = float(randint(0, 255))
                print(unicode((a1, a2, a3, b1, b2, b3)))
            else:
                raise ValueError(" ERROR: Unknown Filter arguments !")
            print("Filter: ", filter)
            a4 = -a2
            a5 = -a1
            b4 = b2
            b5 = b1
            kernel = []
            kernel.append((a1 * b1, a2 * b1, a3 * b1, a4 * b1, a5 * b1,
                           a1 * b2, a2 * b2, a3 * b2, a4 * b2, a5 * b2,
                           a1 * b3, a2 * b3, a3 * b3, a4 * b3, a5 * b3,
                           a1 * b4, a2 * b4, a3 * b4, a4 * b4, a5 * b4,
                           a1 * b5, a2 * b5, a3 * b5, a4 * b5, a5 * b5))  # x
            kernel.append((b1 * a1, b2 * a1, b3 * a1, b4 * a1, b5 * a1,
                           b1 * a2, b2 * a2, b3 * a2, b4 * a2, b5 * a2,
                           b1 * a3, b2 * a3, b3 * a3, b4 * a3, b5 * a3,
                           b1 * a4, b2 * a4, b3 * a4, b4 * a4, b5 * a4,
                           b1 * a5, b2 * a5, b3 * a5, b4 * a5, b5 * a5))  # y
            # scale factor, vertical fall from 255 to 0
            scale = 0.0
            for i, val in enumerate(kernel[0]):
                if i % 5 < 5 // 2:
                    scale += 255.0 * val
            scale /= 128.0
            print("Scale = ", scale)
            r = heightBand.filter(ImageFilter.Kernel((5, 5),
                kernel[0], scale=scale, offset=128.0))
            g = heightBand.filter(ImageFilter.Kernel((5, 5),
                kernel[1], scale=scale, offset=128.0))
            b = ImageChops.constant(g, 128)
            rr = r.load()
            gg = g.load()
            bb = b.load()
            for y in range(r.size[1]):
                for x in range(r.size[0]):
                    op = 1.0 - (rr[x, y] * 2.0 / 255.0 - 1.0) ** 2 - (
                            gg[x, y] * 2.0 / 255.0 - 1.0) ** 2
                    if op > 0.0:
                        bb[x, y] = 128.0 + 128.0 * sqrt(op)
                    else:
                        bb[x, y] = 128.0
            return([r, g, b])

        # make a dialog gui
        dialog = QtGui.QDialog(self)
        #
        label1 = QtGui.QLabel('Tipo de algoritmo de procesamiento: ', dialog)
        label1.setAutoFillBackground(True)
        combo1 = QComboBox(dialog)
        combo1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        combo1.addItems(['Sobel 5x5 (Strong, Fuerte)',
                         'Random ??? (Variable, entropic)',
                         'Scharr 5x5 (Soft, Suave)'
                         ])
        #
        label2 = QtGui.QLabel('Procesamiento de Canal Alpha: ', dialog)
        label2.setAutoFillBackground(True)
        combo2 = QComboBox(dialog)
        combo2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        combo2.addItems(['HeightMap (Usar Alpha)', 'Ignored (Ignorar Alpha)'])
        #
        label3 = QtGui.QLabel('\n Nombre de archivo de salida sera igual al ' +
        'de entrada con el prefijo " _n ". \n Output filename will be equal ' +
        'to input filename with the " _n " prefix. \n ', dialog)
        label3.setAutoFillBackground(True)
        # make a button
        ok = QtGui.QPushButton(dialog)
        # set the text on the button to ok
        ok.setText('&O K')
        ok.setDefault(True)
        # connect the clicked signal to an accept slot
        self.connect(ok, QtCore.SIGNAL('clicked()'), dialog.accept)
        # make a local layout
        layout = QtGui.QVBoxLayout()
        layout.addWidget(label1)
        layout.addWidget(combo1)
        layout.addWidget(label2)
        layout.addWidget(combo2)
        layout.addWidget(label3)
        layout.addWidget(ok)
        dialog.setLayout(layout)
        # run the dialog
        dialog.exec_()

        # Process the Algorythm string value
        if combo1.currentText() == 'Sobel 5x5 (Strong, Fuerte)':
            arg1 = 'Sobel'
            print(' INFO: Using Sobel for NormalMapping . . . ')
        elif combo1.currentText() == 'Random ??? (Variable, entropic)':
            arg1 = 'Random'
            print(' INFO: Using Random for NormalMapping . . . ')
        else:
            arg1 = 'Scharr'
            print(' INFO: using Scharr for NormalMapping . . . ')

        # Process the HeightMap Boolean
        if combo2.currentText() == 'HeightMap (Usar Alpha)':
            alphaheight = True
        else:
            alphaheight = False

        # try to read input filename and save the output file
        try:
            infile = unicode(QFileDialog.getOpenFileName(self,
              "Open an Image File to make a Normal Map... ",
              os.path.expanduser("~"),
              ';;'.join(['(*%s)' % e for e in ['.jpg', '.png', '']])))
            print(infile)
            im = Image.open(infile)
            print(im)
        except:
            sys.exit(" \n ERROR: Could not open an Image File ! \n ")
        height = im.split()[0]
        normal = height2bump(height, filter=arg1)
        if alphaheight:
            normal.extend([height])
            im = Image.merge("RGBA", normal)
        else:
            im = Image.merge("RGB", normal)
        try:
            outfile = unicode(infile.split('.')[0] + '_n.png')
            print(outfile)
            im.save(outfile)
        except:
            sys.exit(" \n ERROR: Could not save the Output Image File ! \n ")
        print(" INFO: Function completed !")
        return(im)

    def showQColorDialog(self):
        ' Choose a Color for Qt '
        color = QtGui.QColorDialog.getColor()
        # print info
        print(' INFO: Using User requested color ' + str(color.name()) + '...')
        # if the color is a valid color use it into an CSS and apply it
        if color.isValid():
            self.setStyleSheet(" * { background-color: %s } " % color.name())

    def applySkin(self):
        ' Apply a Customized Dark Sexy Skin '
        print(' INFO: Using Built-In CSS . . .')
        # complete CSS for Qt widgets
        self.setStyleSheet('''
            QToolTip {
                border: 1px solid black;
                background-color: #ffa02f;
                padding: 1px;
                border-radius: 3px;
                opacity: 100;
            }

            QWidget{
                color: #b1b1b1;
                background-color: #323232;
            }

            QWidget:item:hover {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #ca0619
                );
                color: #000000;
            }

            QWidget:item:selected {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QMenuBar::item { background: transparent; }

            QMenuBar::item:selected {
                background: transparent;
                border: 1px solid #ffaa00;
            }

            QMenuBar::item:pressed {
                background: #444;
                border: 1px solid #000;
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:1 #212121,
                    stop:0.4 #343434,
                    stop:0.2 #343434,
                    stop:0.1 #ffaa00
                );
                margin-bottom:-1px;
                padding-bottom:1px;
            }

            QMenu { border: 1px solid #000; }

            QMenu::item { padding: 2px 20px 2px 20px; }

            QMenu::item:selected { color: #000000; }

            QWidget:disabled {
                color: #404040;
                background-color: #323232;
            }

            QAbstractItemView {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #4d4d4d,
                    stop: 0.1 #646464,
                    stop: 1 #5d5d5d
                );
            }

            QWidget:focus {
                border: 2px solid QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QLineEdit {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #4d4d4d,
                    stop: 0 #646464,
                    stop: 1 #5d5d5d
                );
                padding: 1px;
                border-style: solid;
                border: 1px solid #1e1e1e;
                border-radius: 5;
            }

            QPushButton {
                color: #b1b1b1;
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #565656,
                    stop: 0.1 #525252,
                    stop: 0.5 #4e4e4e,
                    stop: 0.9 #4a4a4a,
                    stop: 1 #464646
                );
                border-width: 1px;
                border-color: #1e1e1e;
                border-style: solid;
                border-radius: 6;
                padding: 3px;
                font-size: 12px;
                padding-left: 5px;
                padding-right: 5px;
            }

            QPushButton:pressed {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #2d2d2d,
                    stop: 0.1 #2b2b2b,
                    stop: 0.5 #292929,
                    stop: 0.9 #282828,
                    stop: 1 #252525
                );
            }

            QComboBox {
                selection-background-color: #ffaa00;
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #565656,
                    stop: 0.1 #525252,
                    stop: 0.5 #4e4e4e,
                    stop: 0.9 #4a4a4a,
                    stop: 1 #464646
                );
                border-style: solid;
                border: 1px solid #1e1e1e;
                border-radius: 5;
            }

            QComboBox:hover,QPushButton:hover {
                border: 2px solid QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QComboBox:on {
                padding-top: 3px;
                padding-left: 4px;
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #2d2d2d,
                    stop: 0.1 #2b2b2b,
                    stop: 0.5 #292929,
                    stop: 0.9 #282828,
                    stop: 1 #252525
                );
                selection-background-color: #ffaa00;
            }

            QComboBox QAbstractItemView {
                border: 2px solid darkgray;
                selection-background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QComboBox::drop-down {
                 subcontrol-origin: padding;
                 subcontrol-position: top right;
                 width: 15px;
                 border-left-width: 0px;
                 border-left-color: darkgray;
                 border-left-style: solid;
                 border-top-right-radius: 3px;
                 border-bottom-right-radius: 3px;
             }

            QComboBox::down-arrow { }

            QGroupBox:focus {
                border: 2px solid QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QTextEdit:focus {
                border: 2px solid QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QScrollBar:horizontal {
                border: 1px solid #222222;
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0.0 #121212,
                    stop: 0.2 #282828,
                    stop: 1 #484848
                );
                height: 7px;
                margin: 0px 16px 0 16px;
            }

            QScrollBar::handle:horizontal {
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 1, y2: 0,
                    stop: 0 #ffa02f,
                    stop: 0.5 #d7801a,
                    stop: 1 #ffa02f
                );
                min-height: 20px;
                border-radius: 2px;
            }

            QScrollBar::add-line:horizontal {
                border: 1px solid #1b1b19;
                border-radius: 2px;
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 1, y2: 0,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
                width: 14px;
                subcontrol-position: right;
                subcontrol-origin: margin;
            }

            QScrollBar::sub-line:horizontal {
                border: 1px solid #1b1b19;
                border-radius: 2px;
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 1, y2: 0,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
                width: 14px;
                subcontrol-position: left;
                subcontrol-origin: margin;
            }

            QScrollBar::right-arrow:horizontal,
            QScrollBar::left-arrow:horizontal {
                border: 1px solid black;
                width: 1px;
                height: 1px;
                background: white;
            }

            QScrollBar::add-page:horizontal,
            QScrollBar::sub-page:horizontal { background: none; }

            QScrollBar:vertical {
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 1, y2: 0,
                    stop: 0.0 #121212,
                    stop: 0.2 #282828,
                    stop: 1 #484848
                );
                width: 7px;
                margin: 16px 0 16px 0;
                border: 1px solid #222222;
            }

            QScrollBar::handle:vertical {
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 0.5 #d7801a,
                    stop: 1 #ffa02f
                );
                min-height: 20px;
                border-radius: 2px;
            }

            QScrollBar::add-line:vertical {
                border: 1px solid #1b1b19;
                border-radius: 2px;
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
                height: 14px;
                subcontrol-position: bottom;
                subcontrol-origin: margin;
            }

            QScrollBar::sub-line:vertical {
                border: 1px solid #1b1b19;
                border-radius: 2px;
                background: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #d7801a,
                    stop: 1 #ffa02f
                );
                height: 14px;
                subcontrol-position: top;
                subcontrol-origin: margin;
            }

            QScrollBar::up-arrow:vertical,
            QScrollBar::down-arrow:vertical {
                border: 1px solid black;
                width: 1px;
                height: 1px;
                background: white;
            }

            QScrollBar::add-page:vertical,
            QScrollBar::sub-page:vertical { background: none; }

            QTextEdit { background-color: #242424; }

            QPlainTextEdit { background-color: #242424; }

            QHeaderView::section {
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:0 #616161,
                    stop: 0.5 #505050,
                    stop: 0.6 #434343,
                    stop:1 #656565
                );
                color: white;
                padding-left: 4px;
                border: 1px solid #6c6c6c;
            }

            QCheckBox:disabled { color: #414141; }

            QDockWidget::title {
                text-align: center;
                spacing: 3px;
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:0 #323232,
                    stop: 0.5 #242424,
                    stop:1 #323232
                    );
            }

            QDockWidget::close-button,
            QDockWidget::float-button {
                text-align: center;
                spacing: 1px;
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:0 #323232,
                    stop: 0.5 #242424,
                    stop:1 #323232
                );
            }

            QDockWidget::close-button:hover,
            QDockWidget::float-button:hover { background: #242424; }

            QDockWidget::close-button:pressed,
            QDockWidget::float-button:pressed { padding: 1px -1px -1px 1px;}

            QMainWindow::separator {
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:0 #161616,
                    stop: 0.5 #151515,
                    stop: 0.6 #212121,
                    stop:1 #343434
                );
                color: white;
                padding-left: 4px;
                border: 1px solid #4c4c4c;
                spacing: 3px;
            }

            QMainWindow::separator:hover {
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:0 #d7801a,
                    stop:0.5 #b56c17,
                    stop:1 #ffa02f
                );
                color: white;
                padding-left: 4px;
                border: 1px solid #6c6c6c;
                spacing: 3px;
            }

            QToolBar::handle { spacing: 3px; }

            QMenu::separator {
                height: 2px;
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:0 #161616,
                    stop: 0.5 #151515,
                    stop: 0.6 #212121,
                    stop:1 #343434
                );
                color: white;
                padding-left: 4px;
                margin-left: 10px;
                margin-right: 5px;
            }

            QProgressBar {
                border: 2px solid grey;
                border-radius: 5px;
                text-align: center;
            }

            QProgressBar::chunk {
                background-color: #d7801a;
                width: 2.15px;
                margin: 0.5px;
            }

            QTabBar::tab {
                color: #b1b1b1;
                border: 1px solid #444;
                border-bottom-style: none;
                background-color: #323232;
                padding-left: 10px;
                padding-right: 10px;
                padding-top: 3px;
                padding-bottom: 2px;
                margin-right: -1px;
            }

            QTabWidget::pane {
                border: 1px solid #444;
                top: 1px;
            }

            QTabBar::tab:last {
                margin-right: 0;
                border-top-right-radius: 3px;
            }

            QTabBar::tab:first:!selected {
                margin-left: 0px;
                border-top-left-radius: 3px;
            }

            QTabBar::tab:!selected {
                color: #b1b1b1;
                border-bottom-style: solid;
                margin-top: 3px;
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:1 #212121,
                    stop:.4 #343434
                );
            }

            QTabBar::tab:selected {
                border-top-left-radius: 3px;
                border-top-right-radius: 3px;
                margin-bottom: 0px;
            }

            QTabBar::tab:!selected:hover {
                border-top: 2px solid #ffaa00;
                padding-bottom: 3px;
                border-top-left-radius: 3px;
                border-top-right-radius: 3px;
                background-color: QLinearGradient(
                    x1:0, y1:0,
                    x2:0, y2:1,
                    stop:1 #212121,
                    stop:0.4 #343434,
                    stop:0.2 #343434,
                    stop:0.1 #ffaa00
                );
            }

            QRadioButton::indicator:checked, QRadioButton::indicator:unchecked{
                color: #b1b1b1;
                background-color: #323232;
                border: 1px solid #b1b1b1;
                border-radius: 6px;
            }

            QRadioButton::indicator:checked {
                background-color: qradialgradient(
                    cx: 0.5, cy: 0.5,
                    fx: 0.5, fy: 0.5,
                    radius: 1.0,
                    stop: 0.25 #ffaa00,
                    stop: 0.3 #323232
                );
            }

            QCheckBox::indicator {
                color: #b1b1b1;
                background-color: #323232;
                border: 1px solid #b1b1b1;
                width: 9px;
                height: 9px;
            }

            QRadioButton::indicator { border-radius: 6px; }

            QRadioButton::indicator:hover, QCheckBox::indicator:hover {
                border: 1px solid #ffaa00;
            }

            QCheckBox::indicator:checked { }

            QCheckBox::indicator:disabled,
            QRadioButton::indicator:disabled {
                border: 1px solid #444;
            }
        ''')
Exemple #2
0
class MyMainWindow(QMainWindow):
    ' Main Window '
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)
        self.statusBar().showMessage(__doc__)
        self.setWindowTitle(__doc__)
        self.setMinimumSize(250, 280)
        self.setMaximumSize(300, 300)
        self.resize(250, 290)
        self.setWindowIcon(QIcon.fromTheme("face-monkey"))
        self.setStyleSheet('''QWidget { color: rgba( 0, 255, 255, 255 );
            background-color: #323232; font-family: 'Ubuntu Light';
            font-size: 14px;
            }

            QToolTip {
                border: 1px solid black;
                background-color: #ffa02f;
                background-image: None;
                padding: 1px;
                border-radius: 3px;
                opacity: 100;
            }

            QWidget:item:hover {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #ca0619
                );
                color: #000000;
            }

            QWidget:item:selected {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QWidget:disabled {
                color: #404040;
                background-color: #323232;
            }

            QWidget:focus {
                background-image: None;
                border: 2px solid QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QPushButton {
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #565656,
                    stop: 0.1 #525252,
                    stop: 0.5 #4e4e4e,
                    stop: 0.9 #4a4a4a,
                    stop: 1 #464646
                );
                border-width: 1px;
                border-color: #1e1e1e;
                border-style: solid;
                border-radius: 6;
                padding: 3px;
                font-size: 12px;
                padding-left: 5px;
                padding-right: 5px;
                background-image: None;
            }

            QPushButton:pressed {
                background-image: None;
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #2d2d2d,
                    stop: 0.1 #2b2b2b,
                    stop: 0.5 #292929,
                    stop: 0.9 #282828,
                    stop: 1 #252525
                );
            }

            QComboBox {
                background-image: None;
                selection-background-color: #ffaa00;
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #565656,
                    stop: 0.1 #525252,
                    stop: 0.5 #4e4e4e,
                    stop: 0.9 #4a4a4a,
                    stop: 1 #464646
                );
                border-style: solid;
                border: 1px solid #1e1e1e;
                border-radius: 5;
            }

            QComboBox:hover, QPushButton:hover {
                background-image: url(.bg.png);
                border: 2px solid QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QComboBox:on {
                padding-top: 3px;
                padding-left: 4px;
                background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #2d2d2d,
                    stop: 0.1 #2b2b2b,
                    stop: 0.5 #292929,
                    stop: 0.9 #282828,
                    stop: 1 #252525
                );
                selection-background-color: #ffaa00;
                background-image: None;
            }

            QComboBox QAbstractItemView {
                background-image: None;
                border: 2px solid darkgray;
                selection-background-color: QLinearGradient(
                    x1: 0, y1: 0,
                    x2: 0, y2: 1,
                    stop: 0 #ffa02f,
                    stop: 1 #d7801a
                );
            }

            QComboBox::drop-down {
                 subcontrol-origin: padding;
                 subcontrol-position: top right;
                 width: 15px;
                 border-left-width: 0px;
                 border-left-color: darkgray;
                 border-left-style: solid;
                 border-top-right-radius: 3px;
                 border-bottom-right-radius: 3px;
                 background-image: None;
             }

            QComboBox::down-arrow { background-image: None; }

            QSlider {
                border-width: 2px;
                border-color: #1e1e1e;
                border-style: solid;
                padding: 3px;
                font-size: 8px;
                padding-left: 5px;
                padding-right: 5px;
                width: 25px;
                border-radius: 5px;
            }

            QSlider::sub-page:vertical {
                background: red;
                border: none;
                width: 25px;
            }

            QSlider::add-page:vertical {
                background: green;
                border: none;
                width: 25px;
            }

            QSlider::handle:vertical {
                background-color: QLinearGradient(spread:pad, x1:0, y1:0, x2:1,
                    y2:0.273, stop:0 rgba(0, 0, 0, 255),
                    stop:1 rgba(150, 255, 255, 255)
                    );
                width: 10px;
                height: 25px;
                border: 1px solid grey;
                text-align: center;
                border-top-left-radius: 2px;
                border-bottom-left-radius: 2px;
                border-top-right-radius: 2px;
                border-bottom-right-radius 2px;
                margin-left: 2px;
                margin-right: 2px;
            }

            QSlider::handle:vertical:hover {
                border: 2px solid #ffaa00;
                margin-left: 2px;
                margin-right: 2px;
            }

            QSlider::sub-page:vertical:disabled {
                background: #bbb;
                border-color: #999;
            }

            QSlider::add-page:vertical:disabled {
                background: #eee;
                border-color: #999;
            }

            QSlider::handle:vertical:disabled {
                background: #eee;
                border: 1px solid #aaa;
                border-radius: 4px;
            } ''')

        self.label1 = QLabel(self)
        self.label1.setText('Use Debug')
        self.label1.setGeometry(QtCore.QRect(25, 25, 125, 25))

        self.slider1 = QSlider(self)
        self.slider1.setGeometry(QtCore.QRect(150, 25, 25, 25))
        self.slider1.setTickInterval(1)
        self.slider1.setCursor(QCursor(QtCore.Qt.OpenHandCursor))
        self.slider1.TickPosition(QSlider.TicksBothSides)
        self.slider1.setRange(0, 1)
        self.slider1.setValue(1)
        self.sli1lbl = QLabel(str(self.slider1.value()), self.slider1)
        self.sli1lbl.move(9, 5)
        self.sli1lbl.setAutoFillBackground(False)
        self.slider1.valueChanged.connect(
            lambda: self.sli1lbl.setText(str(self.slider1.value())))
        self.slider1.sliderPressed.connect(
            lambda: self.slider1.setCursor(QCursor(QtCore.Qt.ClosedHandCursor)))
        self.slider1.sliderReleased.connect(
            lambda: self.slider1.setCursor(QCursor(QtCore.Qt.OpenHandCursor)))

        self.label2 = QLabel(self)
        self.label2.setText('Make Executable')
        self.label2.setGeometry(QtCore.QRect(25, 75, 125, 25))

        self.slider2 = QSlider(self)
        self.slider2.setGeometry(QtCore.QRect(150, 75, 25, 25))
        self.slider2.setTickInterval(1)
        self.slider2.setCursor(QCursor(QtCore.Qt.OpenHandCursor))
        self.slider2.TickPosition(QSlider.TicksBothSides)
        self.slider2.setRange(0, 1)
        self.slider2.setValue(1)
        self.sli2lbl = QLabel(str(self.slider2.value()), self.slider2)
        self.sli2lbl.move(9, 5)
        self.sli2lbl.setAutoFillBackground(False)
        self.slider2.valueChanged.connect(
            lambda: self.sli2lbl.setText(str(self.slider2.value())))
        self.slider2.sliderPressed.connect(
            lambda: self.slider2.setCursor(QCursor(QtCore.Qt.ClosedHandCursor)))
        self.slider2.sliderReleased.connect(
            lambda: self.slider2.setCursor(QCursor(QtCore.Qt.OpenHandCursor)))

        self.label3 = QLabel(self)
        self.label3.setText('Relative Imports')
        self.label3.setGeometry(QtCore.QRect(25, 125, 125, 25))

        self.slider3 = QSlider(self)
        self.slider3.setGeometry(QtCore.QRect(150, 125, 25, 25))
        self.slider3.setTickInterval(1)
        self.slider3.setCursor(QCursor(QtCore.Qt.OpenHandCursor))
        self.slider3.TickPosition(QSlider.TicksBothSides)
        self.slider3.setRange(0, 1)
        self.slider3.setValue(0)
        self.sli3lbl = QLabel(str(self.slider3.value()), self.slider3)
        self.sli3lbl.move(9, 5)
        self.sli3lbl.setAutoFillBackground(False)
        self.slider3.valueChanged.connect(
            lambda: self.sli3lbl.setText(str(self.slider3.value())))
        self.slider3.sliderPressed.connect(
            lambda: self.slider3.setCursor(QCursor(QtCore.Qt.ClosedHandCursor)))
        self.slider3.sliderReleased.connect(
            lambda: self.slider3.setCursor(QCursor(QtCore.Qt.OpenHandCursor)))

        self.label4 = QLabel(self)
        self.label4.setText('Indent Spaces')
        self.label4.setGeometry(QtCore.QRect(25, 175, 125, 25))

        self.combo1 = QComboBox(self)
        self.combo1.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
        self.combo1.addItems(['4', '0', '2', '6', '8'])
        self.combo1.setGeometry(QtCore.QRect(150, 175, 50, 25))

        self.buttonBox = QDialogButtonBox(self)
        self.buttonBox.setGeometry(QtCore.QRect(25, 225, 200, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel |
            QDialogButtonBox.Close | QDialogButtonBox.Help)
        self.buttonBox.setCenterButtons(False)
        self.buttonBox.helpRequested.connect(lambda: QMessageBox.about(
            self, __doc__, str(__doc__ + ', ' + ',\nversion ' + __version__ +
                               '(' + __license__ + '),\nby ' + __author__ + ', '
                               + __email__)))
        self.buttonBox.accepted.connect(self.run)
        self.buttonBox.rejected.connect(self.close)
        palette = self.palette()
        palette.setBrush(QPalette.Base, Qt.transparent)
        self.setPalette(palette)
        self.setAttribute(Qt.WA_OpaquePaintEvent, False)

    def run(self):
        'Run the actual conversion.'
        # Ask the User for the source .ui file as input
        filein = str(QFileDialog.getOpenFileName(
            self, __doc__, path.expanduser("~"), 'UI(*.ui)')).strip()
        # Parse Value of Slider1 as the Debug flag parameter
        if self.slider1.value() == 0:
            arg1 = ''
        else:
            arg1 = '--debug '
        # Parse Value of Slider2 as the Execute flag parameter
        if self.slider2.value() == 0:
            arg2 = ''
        else:
            arg2 = '--execute '
        # Parse Value of Slider3 as the relative imports flag parameter
        if self.slider3.value() == 0:
            arg3 = ''
        else:
            arg3 = '--from-imports '
        # debug
        #print(arg1, arg2, arg3, str(self.combo1.currentText()))
        # run the subprocesses
        subprocess.Popen(
            'nice --adjustment=19 pyuic4 ' + arg1 + arg2 + arg3 +
            '--indent=' + str(self.combo1.currentText()) +
            ' --output=' + str(filein).lower().replace('.ui', '.py') +
            ' ' + filein +
            ' && chmod -v +x ' + str(filein).lower().replace('.ui', '.py'),
            shell=True)

    def paintEvent(self, event):
        ' Paint semi-transparent background '
        painter = QPainter(self)
        painter.fillRect(event.rect(), Qt.transparent)
        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(0, 0, 0))
        painter.setOpacity(0.75)
        painter.drawRoundedRect(self.rect(), 75, 50)
        painter.end()
    def normalify(self):
        ' make a normal map from image '
        def height2bump(heightBand, filter="Random"):
            ' oooooh, look a nested function!, are they bad ? '
            if filter == "Sobel":
                a1 = 500
                a2 = 64
                a3 = 0
                b1 = 1
                b2 = 250
                b3 = 666
            elif filter == "Scharr":
                a1 = 21.38
                a2 = 85.24
                a3 = 0
                b1 = 5.96
                b2 = 61.81
                b3 = 255
            elif filter == "Random":           # 5x5 random filter
                a1 = float(randint(0, 255))
                a2 = float(randint(0, 255))
                a3 = float(randint(0, 255))
                b1 = float(randint(0, 255))
                b2 = float(randint(0, 255))
                b3 = float(randint(0, 255))
                print(unicode((a1, a2, a3, b1, b2, b3)))
            else:
                raise ValueError(" ERROR: Unknown Filter arguments !")
            print("Filter: ", filter)
            a4 = -a2
            a5 = -a1
            b4 = b2
            b5 = b1
            kernel = []
            kernel.append((a1 * b1, a2 * b1, a3 * b1, a4 * b1, a5 * b1,
                           a1 * b2, a2 * b2, a3 * b2, a4 * b2, a5 * b2,
                           a1 * b3, a2 * b3, a3 * b3, a4 * b3, a5 * b3,
                           a1 * b4, a2 * b4, a3 * b4, a4 * b4, a5 * b4,
                           a1 * b5, a2 * b5, a3 * b5, a4 * b5, a5 * b5))  # x
            kernel.append((b1 * a1, b2 * a1, b3 * a1, b4 * a1, b5 * a1,
                           b1 * a2, b2 * a2, b3 * a2, b4 * a2, b5 * a2,
                           b1 * a3, b2 * a3, b3 * a3, b4 * a3, b5 * a3,
                           b1 * a4, b2 * a4, b3 * a4, b4 * a4, b5 * a4,
                           b1 * a5, b2 * a5, b3 * a5, b4 * a5, b5 * a5))  # y
            # scale factor, vertical fall from 255 to 0
            scale = 0.0
            for i, val in enumerate(kernel[0]):
                if i % 5 < 5 // 2:
                    scale += 255.0 * val
            scale /= 128.0
            print("Scale = ", scale)
            r = heightBand.filter(ImageFilter.Kernel((5, 5),
                kernel[0], scale=scale, offset=128.0))
            g = heightBand.filter(ImageFilter.Kernel((5, 5),
                kernel[1], scale=scale, offset=128.0))
            b = ImageChops.constant(g, 128)
            rr = r.load()
            gg = g.load()
            bb = b.load()
            for y in range(r.size[1]):
                for x in range(r.size[0]):
                    op = 1.0 - (rr[x, y] * 2.0 / 255.0 - 1.0) ** 2 - (
                            gg[x, y] * 2.0 / 255.0 - 1.0) ** 2
                    if op > 0.0:
                        bb[x, y] = 128.0 + 128.0 * sqrt(op)
                    else:
                        bb[x, y] = 128.0
            return([r, g, b])

        # make a dialog gui
        dialog = QtGui.QDialog(self)
        #
        label1 = QtGui.QLabel('Tipo de algoritmo de procesamiento: ', dialog)
        label1.setAutoFillBackground(True)
        combo1 = QComboBox(dialog)
        combo1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        combo1.addItems(['Sobel 5x5 (Strong, Fuerte)',
                         'Random ??? (Variable, entropic)',
                         'Scharr 5x5 (Soft, Suave)'
                         ])
        #
        label2 = QtGui.QLabel('Procesamiento de Canal Alpha: ', dialog)
        label2.setAutoFillBackground(True)
        combo2 = QComboBox(dialog)
        combo2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        combo2.addItems(['HeightMap (Usar Alpha)', 'Ignored (Ignorar Alpha)'])
        #
        label3 = QtGui.QLabel('\n Nombre de archivo de salida sera igual al ' +
        'de entrada con el prefijo " _n ". \n Output filename will be equal ' +
        'to input filename with the " _n " prefix. \n ', dialog)
        label3.setAutoFillBackground(True)
        # make a button
        ok = QtGui.QPushButton(dialog)
        # set the text on the button to ok
        ok.setText('&O K')
        ok.setDefault(True)
        # connect the clicked signal to an accept slot
        self.connect(ok, QtCore.SIGNAL('clicked()'), dialog.accept)
        # make a local layout
        layout = QtGui.QVBoxLayout()
        layout.addWidget(label1)
        layout.addWidget(combo1)
        layout.addWidget(label2)
        layout.addWidget(combo2)
        layout.addWidget(label3)
        layout.addWidget(ok)
        dialog.setLayout(layout)
        # run the dialog
        dialog.exec_()

        # Process the Algorythm string value
        if combo1.currentText() == 'Sobel 5x5 (Strong, Fuerte)':
            arg1 = 'Sobel'
            print(' INFO: Using Sobel for NormalMapping . . . ')
        elif combo1.currentText() == 'Random ??? (Variable, entropic)':
            arg1 = 'Random'
            print(' INFO: Using Random for NormalMapping . . . ')
        else:
            arg1 = 'Scharr'
            print(' INFO: using Scharr for NormalMapping . . . ')

        # Process the HeightMap Boolean
        if combo2.currentText() == 'HeightMap (Usar Alpha)':
            alphaheight = True
        else:
            alphaheight = False

        # try to read input filename and save the output file
        try:
            infile = unicode(QFileDialog.getOpenFileName(self,
              "Open an Image File to make a Normal Map... ",
              os.path.expanduser("~"),
              ';;'.join(['(*%s)' % e for e in ['.jpg', '.png', '']])))
            print(infile)
            im = Image.open(infile)
            print(im)
        except:
            sys.exit(" \n ERROR: Could not open an Image File ! \n ")
        height = im.split()[0]
        normal = height2bump(height, filter=arg1)
        if alphaheight:
            normal.extend([height])
            im = Image.merge("RGBA", normal)
        else:
            im = Image.merge("RGB", normal)
        try:
            outfile = unicode(infile.split('.')[0] + '_n.png')
            print(outfile)
            im.save(outfile)
        except:
            sys.exit(" \n ERROR: Could not save the Output Image File ! \n ")
        print(" INFO: Function completed !")
        return(im)
class SearchBox(QWidget):
    def __init__(self, parent = None):
        super(SearchBox, self).__init__(parent) 
        self.setFixedHeight(30)
        
        self.lineEdit = QLineEdit()                
        self.lineEdit.setFixedHeight(29)
        self.lineEdit.setToolTip("输入搜索关键词")
        self.lineEdit.setFocusPolicy(Qt.ClickFocus)
        
        self.searchButton = QToolButton()
        self.searchButton.setText("搜索")
        self.searchButton.setFixedHeight(30)
        self.searchButton.setToolTip("点击搜索")
        self.searchButton.setCursor(QCursor(Qt.PointingHandCursor))
        
        self.resetButton = QToolButton()
        self.resetButton.setIcon(QIcon(":/iconSources/icons/reset.png"))
        self.resetButton.setIconSize(QSize(24, 24))
        self.resetButton.setFixedSize(27, 27)
        self.resetButton.setToolTip("重置搜索")
        self.resetButton.setCursor(QCursor(Qt.PointingHandCursor))
        
        self.clearButton = QToolButton()
        self.searchComboBox = QComboBox()
        self.searchComboBox.setToolTip("选择搜索类型")
        musicIcon = QIcon(":/iconSources/icons/music.png")
        artistIcon = QIcon(":/iconSources/icons/artist.png")
        albumIcon = QIcon(":/iconSources/icons/album.png")       
        self.searchComboBox.setIconSize(QSize(20,20))
        self.searchComboBox.insertItem(0, musicIcon, "歌曲")
        self.searchComboBox.insertItem(1, artistIcon, "歌手")
        self.searchComboBox.insertItem(2, albumIcon, "专辑")
        self.searchComboBox.setFixedSize(78, 27)
        self.searchComboBox.setCursor(Qt.PointingHandCursor)
        
        searchIcon = QIcon(":/iconSources/icons/delete.png")
        self.clearButton.setFixedSize(27, 27)
        self.clearButton.setIcon(searchIcon)
        self.clearButton.setIconSize(QSize(18, 18))
        self.clearButton.setAutoRaise(True)
        self.clearButton.setToolTip("清空搜索栏")
        self.clearButton.setCursor(Qt.PointingHandCursor)
        self.clearButton.hide()
        
        searchLayout = QHBoxLayout()
        searchLayout.addWidget(self.searchComboBox)
        searchLayout.addStretch()
        searchLayout.addWidget(self.clearButton)
        searchLayout.setMargin(1)
        searchLayout.setSpacing(0)
        searchLayout.setContentsMargins(0, 0, 0, 0)
        self.lineEdit.setLayout(searchLayout)
        self.lineEdit.setTextMargins(self.searchComboBox.width(), 0, self.clearButton.width(), 0)
        
        mainLayout = QHBoxLayout(self)
        mainLayout.setMargin(0)
        mainLayout.setSpacing(1)
        mainLayout.addWidget(self.resetButton)
        mainLayout.addWidget(self.lineEdit)
        mainLayout.addWidget(self.searchButton)

        #self.connect(self.clearButton, SIGNAL("clicked()"), self.lineEdit.clear)
        self.clearButton.clicked.connect(self.lineEdit.clear)
        self.lineEdit.textChanged.connect(self.clrbutton_show)
        
    def clrbutton_show(self):
        if self.lineEdit.text():
            self.clearButton.show()
        else:
            self.clearButton.hide()