guihelpers.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. app = None
  26. system_bus = None
  27. def prepare_app():
  28. from PyQt4.QtGui import QApplication,QMessageBox
  29. global app
  30. app = QApplication(sys.argv)
  31. app.setOrganizationName("The Qubes Project")
  32. app.setOrganizationDomain("http://qubes-os.org")
  33. app.setApplicationName("Qubes")
  34. def ask(text, title="Question", yestoall=False):
  35. global app
  36. if app is None:
  37. prepare_app()
  38. buttons = QMessageBox.Yes | QMessageBox.No
  39. if yestoall:
  40. buttons |= QMessageBox.YesToAll
  41. reply = QMessageBox.question(None, title, text, buttons, defaultButton=QMessageBox.Yes)
  42. if reply == QMessageBox.Yes:
  43. return 0
  44. elif reply == QMessageBox.No:
  45. return 1
  46. elif reply == QMessageBox.YesToAll:
  47. return 2
  48. else:
  49. #?!
  50. return 127