lib.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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):
  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. return a
  28. def addActions(widget, actions):
  29. for action in actions:
  30. if action is None:
  31. widget.addSeparator()
  32. else:
  33. widget.addAction(action)
  34. def labelValidator():
  35. return QRegExpValidator(QRegExp(r'^[^ \t].+'), None)