lib.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from PyQt4.QtGui import *
  2. from PyQt4.QtCore import *
  3. def newIcon(icon):
  4. return QIcon(':/' + icon)
  5. def newButton(text, icon=None, slot=None):
  6. b = QPushButton(text)
  7. if icon is not None:
  8. b.setIcon(newIcon(icon))
  9. if slot is not None:
  10. b.clicked.connect(slot)
  11. return b
  12. def newAction(parent, text, slot=None, shortcut=None, icon=None,
  13. tip=None, checkable=False, enabled=True):
  14. """Create a new action and assign callbacks, shortcuts, etc."""
  15. a = QAction(text, parent)
  16. if icon is not None:
  17. a.setIcon(newIcon(icon))
  18. if shortcut is not None:
  19. a.setShortcut(shortcut)
  20. if tip is not None:
  21. a.setToolTip(tip)
  22. a.setStatusTip(tip)
  23. if slot is not None:
  24. a.triggered.connect(slot)
  25. if checkable:
  26. a.setCheckable(True)
  27. a.setEnabled(enabled)
  28. return a
  29. def addActions(widget, actions):
  30. for action in actions:
  31. if action is None:
  32. widget.addSeparator()
  33. else:
  34. widget.addAction(action)
  35. def labelValidator():
  36. return QRegExpValidator(QRegExp(r'^[^ \t].+'), None)