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