File: qobjectcreator.py

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (33 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from PyQt4.uic.exceptions import NoSuchWidgetError
import qtproxies

from indenter import write_code

class QObjectProxyCreator(object):
    cwidgets = {}
    def createQObject(self, classname, objectname, ctor_args,
                      is_attribute = True, no_instantiation = False):
        return self[classname](objectname, is_attribute,
                               ctor_args, no_instantiation)
        

    def addCustomWidget(self, classname, baseclass, module):
        write_code("from %s import %s" % (module, classname))
        self.cwidgets[classname] = type(classname, (getattr(qtproxies.QtGui, baseclass),),
                                        {"module":""})

    def getSlot(self, object, slotname):
        return qtproxies.Literal("%s.%s" % (object, slotname))
    
    def __getitem__(self, cls):
        try:
            return self.cwidgets[cls]
        except KeyError:
            try:
                w = getattr(qtproxies.QtGui, cls)
                if issubclass(w, qtproxies.LiteralProxyClass):
                    raise NoSuchWidgetError, cls
                return w
            except AttributeError:
                raise NoSuchWidgetError, cls