Attachment 'bindable.py'

Download

   1 #!/usr/bin/env python
   2 
   3 import sys
   4 from PyQt4.QtCore import *
   5 from PyQt4.QtGui import *
   6 
   7 def bind(objectName, propertyName, type):
   8 
   9     def getter(self):
  10         return type(self.findChild(QObject, objectName).property(propertyName).toPyObject())
  11     
  12     def setter(self, value):
  13         self.findChild(QObject, objectName).setProperty(propertyName, QVariant(value))
  14     
  15     return property(getter, setter)
  16 
  17 class Window(QWidget):
  18 
  19     def __init__(self, parent = None):
  20     
  21         QWidget.__init__(self, parent)
  22         nameEdit = QLineEdit()
  23         nameEdit.setObjectName("nameEdit")
  24         addressEdit = QTextEdit()
  25         addressEdit.setObjectName("addressEdit")
  26         contactCheckBox = QCheckBox()
  27         contactCheckBox.setObjectName("contactCheckBox")
  28         
  29         layout = QFormLayout(self)
  30         layout.addRow(self.tr("Name:"), nameEdit)
  31         layout.addRow(self.tr("Address:"), addressEdit)
  32         layout.addRow(self.tr("Receive extra information:"), contactCheckBox)
  33     
  34     name = bind("nameEdit", "text", str)
  35     address = bind("addressEdit", "plainText", str)
  36     contact = bind("contactCheckBox", "checked", bool)
  37 
  38 
  39 if __name__ == "__main__":
  40 
  41     app = QApplication(sys.argv)
  42     window = Window()
  43     window.show()
  44     sys.exit(app.exec_())

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2014-06-04 22:12:21, 1.2 KB) [[attachment:bindable.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

Unable to edit the page? See the FrontPage for instructions.