Welcome to Pycante’s documentation!

_images/logo.png

Allows a unique way to deal with QtDesigner .ui files. Literally you can inherith a class from xml/ui file.

Contents:

Installation Guide

Ubuntu/Debian/Mint

Execute

$ sudo apt-get install python-setuptools python-pip python-qt4
$ sudo pip install pycante

Windows or other *nix

Finally open a console and execute

> easy_install pycante

Installing Manually

The project is hosted at http://bitbucket.org/leliel12/pycante/ and can be installed manually:

$ hg clone clone https://bitbucket.org/leliel12/pycante
$ cd pycante
$ python setup.py install

Tutorial

This example: https://bitbucket.org/leliel12/pycante/src/tip/example

  1. Open QtDesigner [1] and make a QDialog like this one

    _images/qdesigner.png
    where:
    1. Is a QDialog with objectName Dialog.
    2. Is a QLineEdit with objectName lineEdit.
    3. Is a QLabel with objectName label.
    4. Is a QPushButton with objectName pushButton.

    Save the design as Dialog.ui.

  2. Create in the same directory where the Dialog.ui file live a Python script with the next code.

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    # "THE WISKEY-WARE LICENSE":
    # <juan@brainiac> wrote this file. As long as you retain this notice you
    # can do whatever you want with this stuff. If we meet some day, and you think
    # this stuff is worth it, you can buy me a WISKEY in return Juan
    
    #===============================================================================
    # DOCS
    #===============================================================================
    
    """This is a example from tutorial of pycante
    
    """
    
    #===============================================================================
    # IMPORTS
    #===============================================================================
    
    import os
    from PyQt4 import QtCore, QtGui
    
    import pycante
    
    #===============================================================================
    # CONSTANTS
    #===============================================================================
    
    # The canonical way to determine the path of this file
    PATH = os.path.abspath(os.path.dirname(__file__))
    
    # Bind the path of this file as UI path for picante
    UI_DIR = pycante.EDir(PATH)
    
    
    #===============================================================================
    # CLASS
    #===============================================================================
    
    # The class dialog extend the Dialog.ui file
    class Dialog(UI_DIR("Dialog.ui")):
    
        # when signal clicked of push button is emited execute this code.
        def on_pushButton_clicked(self):
            text = self.lineEdit.text()
            self.label.setText("Hello " + unicode(text) + "!")
    
    
    #===============================================================================
    # RUN QT
    #===============================================================================
    
    app = QtGui.QApplication([])
    d = Dialog()
    d.show()
    app.exec_()
    
  3. Save the file as “dialog.py” and run it with:

    $ python dialog.py
    

This is a video with the expected behavior

[1]http://qt.digia.com/Product/Developer-Tools/

API

The hotest way to deal with PyQt

Allows a unique way to deal with QtDesigner .ui files.

Example:

from PyQt4 import QtGui
import pycante

class MyWidget(pycante.E("/path/to/file.ui"), AnotherClass);
    pass

class MyAnotherWidget(pycante.E(QtGui.QFrame), AnotherClass):
    pass

w0 = MyWidget()
w1 = MyAnotherWidget()

BTW, picante in spanish means spicy.

pycante.E(ui_or_widget)[source]

Resolve a qt widget class from ui file path or Widget class

Params
ui_or_widget:for inerith visual stile (can be a designer ui file)

Return New base class

Example:

from PyQt4 import QtGui
import pycante

class MyWidget(pycante.E("my/ui/file.ui")):
    pass

class AnotherWidget(pycante.E(QtGui.QFrame)):
    pass
pycante.EDir(path)[source]

Creates a binding for resolve .ui files in to a given path. If you use a widget class the path is ignored.

Params:
path:A path to a firectory where all the ui files lives.

Return: Bind to a given path.

Example:

from PyQt4 import QtGui
import pycante

UI = pycante.EDir("path/to/where/all/my/uis/files/live")

class MyWidget(UI("file.ui"));
    pass

class MyAnotherWidget(UI(QtGui.QFrame)):
    pass

w0 = MyWidget()
w1 = MyAnotherWidget()

Indices and tables