guihelpers.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2011 Marek Marczykowski <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. import sys
  24. from optparse import OptionParser
  25. from PyQt4.QtCore import *
  26. from PyQt4.QtGui import *
  27. app = None
  28. system_bus = None
  29. def prepare_app():
  30. global app
  31. app = QApplication(sys.argv)
  32. app.setOrganizationName("The Qubes Project")
  33. app.setOrganizationDomain("http://qubes-os.org")
  34. app.setApplicationName("Qubes")
  35. def ask(text, title="Question", yestoall=False):
  36. global app
  37. if app is None:
  38. prepare_app()
  39. buttons = QMessageBox.Yes | QMessageBox.No
  40. if yestoall:
  41. buttons |= QMessageBox.YesToAll
  42. reply = QMessageBox.question(None, title, text, buttons, defaultButton=QMessageBox.Yes)
  43. if reply == QMessageBox.Yes:
  44. return 0
  45. elif reply == QMessageBox.No:
  46. return 1
  47. elif reply == QMessageBox.YesToAll:
  48. return 2
  49. else:
  50. #?!
  51. return 127