editconfig.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # $Id$
  2. from PyQt4 import QtCore, QtGui
  3. from preferences import preferences
  4. from qt_utils import connect
  5. # Some useful notes on how to improve things:
  6. # (not necessarily in this file, though!)
  7. # to check if executable: os.access(path, os.X_OK)
  8. # to expand PATH: os.environ['PATH'].split(os.path.pathsep)
  9. # to find the Program Files dir on Windows:
  10. # import _winreg
  11. #key = _winreg.OpenKey(
  12. # _winreg.HKEY_LOCAL_MACHINE,
  13. # "Software\\Microsoft\\Windows\\CurrentVersion"
  14. # )
  15. #value, type = _winreg.QueryValueEx(key, "ProgramFilesDir")
  16. #print "Your Program Files dir is here: %s" % value
  17. # to check if we're on windows:
  18. #if hasattr(sys, 'getwindowsversion'):
  19. # print 'Windows found'
  20. #else:
  21. # print 'Windows not found'
  22. class ConfigDialog(object):
  23. def __init__(self):
  24. self.__configDialog = None
  25. self.__browseExecutableButton = None
  26. self.__execEdit = None
  27. def show(self, block = False):
  28. dialog = self.__configDialog
  29. if dialog is None:
  30. self.__configDialog = dialog = QtGui.QDialog(
  31. None, # TODO: find a way to get the real parent
  32. QtCore.Qt.Dialog
  33. | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint
  34. )
  35. # Do not keep openMSX running just because of this dialog.
  36. dialog.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
  37. # Setup UI made in Qt Designer.
  38. from ui_config import Ui_Dialog
  39. ui = Ui_Dialog()
  40. ui.setupUi(dialog)
  41. self.__browseExecutableButton = ui.browseExecutableButton
  42. self.__execEdit = ui.execEdit
  43. try:
  44. self.__execEdit.setText(preferences['system/executable'])
  45. except KeyError:
  46. self.__execEdit.setText('')
  47. connect(self.__browseExecutableButton, 'clicked()', self.__browseExec)
  48. connect(self.__execEdit, 'editingFinished()', self.__setExec)
  49. if block:
  50. dialog.exec_()
  51. else:
  52. dialog.show()
  53. dialog.raise_()
  54. dialog.activateWindow()
  55. def __setExec(self):
  56. preferences['system/executable'] = self.__execEdit.text()
  57. def __browseExec(self):
  58. path = QtGui.QFileDialog.getOpenFileName(
  59. self.__browseExecutableButton,
  60. 'Select openMSX executable',
  61. QtCore.QDir.currentPath(),
  62. 'All Files (*)'
  63. )
  64. if not path.isNull():
  65. self.__execEdit.setText(path)
  66. self.__setExec()
  67. configDialog = ConfigDialog()