ideoptions.py 4.1 KB

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