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 (28 lines) | stat: -rw-r--r-- 886 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
from PyQt4.uic.exceptions import NoSuchWidgetError
from PyQt4 import QtGui

class QObjectCreator(object):
    def __init__(self):
        self.widgets = {}
        
    def createQObject(self, classname, objectname, ctor_args, is_attribute = True):
        return self[classname](*ctor_args)


    def addCustomWidget(self, classname, baseclass, module):
        import sys # for now!
        sys.path.append(".")
        self.widgets[classname] = getattr(__import__(module, {}, {}, (classname,)),
                                          classname)

    def getSlot(self, object, slotname):
        return getattr(object, slotname)
    
    def __getitem__(self, cls):
        try:
            return getattr(QtGui, cls)
        except AttributeError:
            try:
                return self.widgets[cls]
            except KeyError:
                raise NoSuchWidgetError, cls