Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
configui.py309 linesDownload Raw Back to editor
1import pywin.scintilla.config2import win32api3import win32con4import win32ui5from pywin.framework.editor import (6    DeleteEditorOption,7    GetEditorFontOption,8    GetEditorOption,9    SetEditorFontOption,10    SetEditorOption,11    defaultCharacterFormat,12    editorTemplate,13)14from pywin.mfc import dialog15 16from . import document17 18# The standard 16 color VGA palette should always be possible19paletteVGA = (20    ("Black", 0, 0, 0),21    ("Navy", 0, 0, 128),22    ("Green", 0, 128, 0),23    ("Cyan", 0, 128, 128),24    ("Maroon", 128, 0, 0),25    ("Purple", 128, 0, 128),26    ("Olive", 128, 128, 0),27    ("Gray", 128, 128, 128),28    ("Silver", 192, 192, 192),29    ("Blue", 0, 0, 255),30    ("Lime", 0, 255, 0),31    ("Aqua", 0, 255, 255),32    ("Red", 255, 0, 0),33    ("Fuchsia", 255, 0, 255),34    ("Yellow", 255, 255, 0),35    ("White", 255, 255, 255),36)37 38 39######################################################40#41# Property Page for editor options42#43class EditorPropertyPage(dialog.PropertyPage):44    def __init__(self):45        dialog.PropertyPage.__init__(self, win32ui.IDD_PP_EDITOR)46        self.autooptions = []47        self._AddEditorOption(win32ui.IDC_AUTO_RELOAD, "i", "Auto Reload", 1)48        self._AddEditorOption(49            win32ui.IDC_COMBO1, "i", "Backup Type", document.BAK_DOT_BAK_BAK_DIR50        )51        self._AddEditorOption(52            win32ui.IDC_AUTOCOMPLETE, "i", "Autocomplete Attributes", 153        )54        self._AddEditorOption(win32ui.IDC_CALLTIPS, "i", "Show Call Tips", 1)55        self._AddEditorOption(56            win32ui.IDC_MARGIN_LINENUMBER, "i", "Line Number Margin Width", 057        )58        self._AddEditorOption(win32ui.IDC_RADIO1, "i", "MarkersInMargin", None)59        self._AddEditorOption(60            win32ui.IDC_MARGIN_MARKER, "i", "Marker Margin Width", None61        )62        self["Marker Margin Width"] = GetEditorOption("Marker Margin Width", 16)63 64        # Folding65        self._AddEditorOption(win32ui.IDC_MARGIN_FOLD, "i", "Fold Margin Width", 12)66        self._AddEditorOption(win32ui.IDC_FOLD_ENABLE, "i", "Enable Folding", 1)67        self._AddEditorOption(win32ui.IDC_FOLD_ON_OPEN, "i", "Fold On Open", 0)68        self._AddEditorOption(win32ui.IDC_FOLD_SHOW_LINES, "i", "Fold Lines", 1)69 70        # Right edge.71        self._AddEditorOption(72            win32ui.IDC_RIGHTEDGE_ENABLE, "i", "Right Edge Enabled", 073        )74        self._AddEditorOption(75            win32ui.IDC_RIGHTEDGE_COLUMN, "i", "Right Edge Column", 7576        )77 78        # Source control, etc79        self.AddDDX(win32ui.IDC_VSS_INTEGRATE, "bVSS")80        self.AddDDX(win32ui.IDC_KEYBOARD_CONFIG, "Configs", "l")81        self["Configs"] = pywin.scintilla.config.find_config_files()82 83    def _AddEditorOption(self, idd, typ, optionName, defaultVal):84        self.AddDDX(idd, optionName, typ)85        # some options are "derived" - ie, can be implied from others86        # (eg, "view markers in background" is implied from "markerMarginWidth==0"87        # So we don't actually store these values, but they do still get DDX support.88        if defaultVal is not None:89            self[optionName] = GetEditorOption(optionName, defaultVal)90            self.autooptions.append((optionName, defaultVal))91 92    def OnInitDialog(self):93        for name, val in self.autooptions:94            self[name] = GetEditorOption(name, val)95 96        # Note that these MUST be in the same order as the BAK constants.97        cbo = self.GetDlgItem(win32ui.IDC_COMBO1)98        cbo.AddString("None")99        cbo.AddString(".BAK File")100        cbo.AddString("TEMP dir")101        cbo.AddString("Own dir")102 103        # Source Safe104        bVSS = (105            GetEditorOption("Source Control Module", "") == "pywin.framework.editor.vss"106        )107        self["bVSS"] = bVSS108 109        edit = self.GetDlgItem(win32ui.IDC_RIGHTEDGE_SAMPLE)110        edit.SetWindowText("Sample Color")111 112        rc = dialog.PropertyPage.OnInitDialog(self)113 114        try:115            self.GetDlgItem(win32ui.IDC_KEYBOARD_CONFIG).SelectString(116                -1, GetEditorOption("Keyboard Config", "default")117            )118        except win32ui.error:119            import traceback120 121            traceback.print_exc()122            pass123 124        self.HookCommand(self.OnButSimple, win32ui.IDC_FOLD_ENABLE)125        self.HookCommand(self.OnButSimple, win32ui.IDC_RADIO1)126        self.HookCommand(self.OnButSimple, win32ui.IDC_RADIO2)127        self.HookCommand(self.OnButSimple, win32ui.IDC_RIGHTEDGE_ENABLE)128        self.HookCommand(self.OnButEdgeColor, win32ui.IDC_RIGHTEDGE_DEFINE)129 130        butMarginEnabled = self["Marker Margin Width"] > 0131        self.GetDlgItem(win32ui.IDC_RADIO1).SetCheck(butMarginEnabled)132        self.GetDlgItem(win32ui.IDC_RADIO2).SetCheck(not butMarginEnabled)133 134        self.edgeColor = self.initialEdgeColor = GetEditorOption(135            "Right Edge Color", win32api.RGB(0xEF, 0xEF, 0xEF)136        )137        for spinner_id in (win32ui.IDC_SPIN1, win32ui.IDC_SPIN2, win32ui.IDC_SPIN3):138            spinner = self.GetDlgItem(spinner_id)139            spinner.SetRange(0, 100)140        self.UpdateUIForState()141 142        return rc143 144    def OnButSimple(self, id, code):145        if code == win32con.BN_CLICKED:146            self.UpdateUIForState()147 148    def OnButEdgeColor(self, id, code):149        if code == win32con.BN_CLICKED:150            d = win32ui.CreateColorDialog(self.edgeColor, 0, self)151            # Ensure the current color is a custom color (as it may not be in the swatch)152            # plus some other nice gray scales.153            ccs = [self.edgeColor]154            for c in range(0xEF, 0x4F, -0x10):155                ccs.append(win32api.RGB(c, c, c))156            d.SetCustomColors(ccs)157            if d.DoModal() == win32con.IDOK:158                self.edgeColor = d.GetColor()159                self.UpdateUIForState()160 161    def UpdateUIForState(self):162        folding = self.GetDlgItem(win32ui.IDC_FOLD_ENABLE).GetCheck()163        self.GetDlgItem(win32ui.IDC_FOLD_ON_OPEN).EnableWindow(folding)164        self.GetDlgItem(win32ui.IDC_FOLD_SHOW_LINES).EnableWindow(folding)165 166        widthEnabled = self.GetDlgItem(win32ui.IDC_RADIO1).GetCheck()167        self.GetDlgItem(win32ui.IDC_MARGIN_MARKER).EnableWindow(widthEnabled)168        self.UpdateData()  # Ensure self[] is up to date with the control data.169        if widthEnabled and self["Marker Margin Width"] == 0:170            self["Marker Margin Width"] = 16171            self.UpdateData(0)  # Ensure control up to date with self[]172 173        # Right edge174        edgeEnabled = self.GetDlgItem(win32ui.IDC_RIGHTEDGE_ENABLE).GetCheck()175        self.GetDlgItem(win32ui.IDC_RIGHTEDGE_COLUMN).EnableWindow(edgeEnabled)176        self.GetDlgItem(win32ui.IDC_RIGHTEDGE_SAMPLE).EnableWindow(edgeEnabled)177        self.GetDlgItem(win32ui.IDC_RIGHTEDGE_DEFINE).EnableWindow(edgeEnabled)178 179        edit = self.GetDlgItem(win32ui.IDC_RIGHTEDGE_SAMPLE)180        edit.SetBackgroundColor(0, self.edgeColor)181 182    def OnOK(self):183        for name, defVal in self.autooptions:184            SetEditorOption(name, self[name])185        # Margin width gets handled differently.186        if self["MarkersInMargin"] == 0:187            SetEditorOption("Marker Margin Width", self["Marker Margin Width"])188        else:189            SetEditorOption("Marker Margin Width", 0)190        if self.edgeColor != self.initialEdgeColor:191            SetEditorOption("Right Edge Color", self.edgeColor)192        if self["bVSS"]:193            SetEditorOption("Source Control Module", "pywin.framework.editor.vss")194        else:195            if (196                GetEditorOption("Source Control Module", "")197                == "pywin.framework.editor.vss"198            ):199                SetEditorOption("Source Control Module", "")200        # Keyboard config201        configname = self.GetDlgItem(win32ui.IDC_KEYBOARD_CONFIG).GetWindowText()202        if configname:203            if configname == "default":204                DeleteEditorOption("Keyboard Config")205            else:206                SetEditorOption("Keyboard Config", configname)207 208            import pywin.scintilla.view209 210            pywin.scintilla.view.LoadConfiguration()211 212        # Now tell all views we have changed.213        ##		for doc in editorTemplate.GetDocumentList():214        ##			for view in doc.GetAllViews():215        ##				try:216        ##					fn = view.OnConfigChange217        ##				except AttributeError:218        ##					continue219        ##				fn()220        return 1221 222 223class EditorWhitespacePropertyPage(dialog.PropertyPage):224    def __init__(self):225        dialog.PropertyPage.__init__(self, win32ui.IDD_PP_TABS)226        self.autooptions = []227        self._AddEditorOption(win32ui.IDC_TAB_SIZE, "i", "Tab Size", 4)228        self._AddEditorOption(win32ui.IDC_INDENT_SIZE, "i", "Indent Size", 4)229        self._AddEditorOption(win32ui.IDC_USE_SMART_TABS, "i", "Smart Tabs", 1)230        self._AddEditorOption(win32ui.IDC_VIEW_WHITESPACE, "i", "View Whitespace", 0)231        self._AddEditorOption(win32ui.IDC_VIEW_EOL, "i", "View EOL", 0)232        self._AddEditorOption(233            win32ui.IDC_VIEW_INDENTATIONGUIDES, "i", "View Indentation Guides", 0234        )235 236    def _AddEditorOption(self, idd, typ, optionName, defaultVal):237        self.AddDDX(idd, optionName, typ)238        self[optionName] = GetEditorOption(optionName, defaultVal)239        self.autooptions.append((optionName, defaultVal))240 241    def OnInitDialog(self):242        for name, val in self.autooptions:243            self[name] = GetEditorOption(name, val)244 245        rc = dialog.PropertyPage.OnInitDialog(self)246 247        idc = win32ui.IDC_TABTIMMY_NONE248        if GetEditorOption("Use Tab Timmy", 1):249            idc = win32ui.IDC_TABTIMMY_IND250        self.GetDlgItem(idc).SetCheck(1)251 252        idc = win32ui.IDC_RADIO1253        if GetEditorOption("Use Tabs", 0):254            idc = win32ui.IDC_USE_TABS255        self.GetDlgItem(idc).SetCheck(1)256 257        tt_color = GetEditorOption("Tab Timmy Color", win32api.RGB(0xFF, 0, 0))258        self.cbo = self.GetDlgItem(win32ui.IDC_COMBO1)259        for c in paletteVGA:260            self.cbo.AddString(c[0])261        sel = 0262        for c in paletteVGA:263            if tt_color == win32api.RGB(c[1], c[2], c[3]):264                break265            sel = sel + 1266        else:267            sel = -1268        self.cbo.SetCurSel(sel)269        self.HookCommand(self.OnButSimple, win32ui.IDC_TABTIMMY_NONE)270        self.HookCommand(self.OnButSimple, win32ui.IDC_TABTIMMY_IND)271        self.HookCommand(self.OnButSimple, win32ui.IDC_TABTIMMY_BG)272        # Set ranges for the spinners.273        for spinner_id in [win32ui.IDC_SPIN1, win32ui.IDC_SPIN2]:274            spinner = self.GetDlgItem(spinner_id)275            spinner.SetRange(1, 16)276        return rc277 278    def OnButSimple(self, id, code):279        if code == win32con.BN_CLICKED:280            self.UpdateUIForState()281 282    def UpdateUIForState(self):283        timmy = self.GetDlgItem(win32ui.IDC_TABTIMMY_NONE).GetCheck()284        self.GetDlgItem(win32ui.IDC_COMBO1).EnableWindow(not timmy)285 286    def OnOK(self):287        for name, defVal in self.autooptions:288            SetEditorOption(name, self[name])289 290        SetEditorOption("Use Tabs", self.GetDlgItem(win32ui.IDC_USE_TABS).GetCheck())291 292        SetEditorOption(293            "Use Tab Timmy", self.GetDlgItem(win32ui.IDC_TABTIMMY_IND).GetCheck()294        )295        c = paletteVGA[self.cbo.GetCurSel()]296        SetEditorOption("Tab Timmy Color", win32api.RGB(c[1], c[2], c[3]))297 298        return 1299 300 301def testpp():302    ps = dialog.PropertySheet("Editor Options")303    ps.AddPage(EditorWhitespacePropertyPage())304    ps.DoModal()305 306 307if __name__ == "__main__":308    testpp()309 
codekingpro/portable-devtools · Team Ai