Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ideoptions.py 4.9KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # The property page to define generic IDE options for Pythonwin
  2. import win32con
  3. import win32ui
  4. from pywin.framework import interact
  5. from pywin.mfc import dialog
  6. buttonControlMap = {
  7. win32ui.IDC_BUTTON1: win32ui.IDC_EDIT1,
  8. win32ui.IDC_BUTTON2: win32ui.IDC_EDIT2,
  9. win32ui.IDC_BUTTON3: win32ui.IDC_EDIT3,
  10. }
  11. class OptionsPropPage(dialog.PropertyPage):
  12. def __init__(self):
  13. dialog.PropertyPage.__init__(self, win32ui.IDD_PP_IDE)
  14. self.AddDDX(win32ui.IDC_CHECK1, "bShowAtStartup")
  15. self.AddDDX(win32ui.IDC_CHECK2, "bDocking")
  16. self.AddDDX(win32ui.IDC_EDIT4, "MRUSize", "i")
  17. def OnInitDialog(self):
  18. edit = self.GetDlgItem(win32ui.IDC_EDIT1)
  19. format = eval(
  20. win32ui.GetProfileVal(
  21. interact.sectionProfile,
  22. interact.STYLE_INTERACTIVE_PROMPT,
  23. str(interact.formatInput),
  24. )
  25. )
  26. edit.SetDefaultCharFormat(format)
  27. edit.SetWindowText("Input Text")
  28. edit = self.GetDlgItem(win32ui.IDC_EDIT2)
  29. format = eval(
  30. win32ui.GetProfileVal(
  31. interact.sectionProfile,
  32. interact.STYLE_INTERACTIVE_OUTPUT,
  33. str(interact.formatOutput),
  34. )
  35. )
  36. edit.SetDefaultCharFormat(format)
  37. edit.SetWindowText("Output Text")
  38. edit = self.GetDlgItem(win32ui.IDC_EDIT3)
  39. format = eval(
  40. win32ui.GetProfileVal(
  41. interact.sectionProfile,
  42. interact.STYLE_INTERACTIVE_ERROR,
  43. str(interact.formatOutputError),
  44. )
  45. )
  46. edit.SetDefaultCharFormat(format)
  47. edit.SetWindowText("Error Text")
  48. self["bShowAtStartup"] = interact.LoadPreference("Show at startup", 1)
  49. self["bDocking"] = interact.LoadPreference("Docking", 0)
  50. self["MRUSize"] = win32ui.GetProfileVal("Settings", "Recent File List Size", 10)
  51. # Hook the button clicks.
  52. self.HookCommand(self.HandleCharFormatChange, win32ui.IDC_BUTTON1)
  53. self.HookCommand(self.HandleCharFormatChange, win32ui.IDC_BUTTON2)
  54. self.HookCommand(self.HandleCharFormatChange, win32ui.IDC_BUTTON3)
  55. # Ensure the spin control remains in range.
  56. spinner = self.GetDlgItem(win32ui.IDC_SPIN1)
  57. spinner.SetRange(1, 16)
  58. return dialog.PropertyPage.OnInitDialog(self)
  59. # Called to save away the new format tuple for the specified item.
  60. def HandleCharFormatChange(self, id, code):
  61. if code == win32con.BN_CLICKED:
  62. editId = buttonControlMap.get(id)
  63. assert editId is not None, "Format button has no associated edit control"
  64. editControl = self.GetDlgItem(editId)
  65. existingFormat = editControl.GetDefaultCharFormat()
  66. flags = win32con.CF_SCREENFONTS
  67. d = win32ui.CreateFontDialog(existingFormat, flags, None, self)
  68. if d.DoModal() == win32con.IDOK:
  69. cf = d.GetCharFormat()
  70. editControl.SetDefaultCharFormat(cf)
  71. self.SetModified(1)
  72. return 0 # We handled this fully!
  73. def OnOK(self):
  74. # Handle the edit controls - get all the fonts, put them back into interact, then
  75. # get interact to save its stuff!
  76. controlAttrs = [
  77. (win32ui.IDC_EDIT1, interact.STYLE_INTERACTIVE_PROMPT),
  78. (win32ui.IDC_EDIT2, interact.STYLE_INTERACTIVE_OUTPUT),
  79. (win32ui.IDC_EDIT3, interact.STYLE_INTERACTIVE_ERROR),
  80. ]
  81. for id, key in controlAttrs:
  82. control = self.GetDlgItem(id)
  83. fmt = control.GetDefaultCharFormat()
  84. win32ui.WriteProfileVal(interact.sectionProfile, key, str(fmt))
  85. # Save the other interactive window options.
  86. interact.SavePreference("Show at startup", self["bShowAtStartup"])
  87. interact.SavePreference("Docking", self["bDocking"])
  88. # And the other options.
  89. win32ui.WriteProfileVal("Settings", "Recent File List Size", self["MRUSize"])
  90. return 1
  91. def ChangeFormat(self, fmtAttribute, fmt):
  92. dlg = win32ui.CreateFontDialog(fmt)
  93. if dlg.DoModal() != win32con.IDOK:
  94. return None
  95. return dlg.GetCharFormat()
  96. def OnFormatTitle(self, command, code):
  97. fmt = self.GetFormat(interact.formatTitle)
  98. if fmt:
  99. formatTitle = fmt
  100. SaveFontPreferences()
  101. def OnFormatInput(self, command, code):
  102. global formatInput
  103. fmt = self.GetFormat(formatInput)
  104. if fmt:
  105. formatInput = fmt
  106. SaveFontPreferences()
  107. def OnFormatOutput(self, command, code):
  108. global formatOutput
  109. fmt = self.GetFormat(formatOutput)
  110. if fmt:
  111. formatOutput = fmt
  112. SaveFontPreferences()
  113. def OnFormatError(self, command, code):
  114. global formatOutputError
  115. fmt = self.GetFormat(formatOutputError)
  116. if fmt:
  117. formatOutputError = fmt
  118. SaveFontPreferences()