def DoConfigChange(self): # Bit of a hack I dont kow what to do about - these should be "editor options" from pywin.framework.editor import GetEditorOption self.bAutoCompleteAttributes = GetEditorOption("Autocomplete Attributes", 1) self.bShowCallTips = GetEditorOption("Show Call Tips", 1) # Update the key map and extension data. configManager.configure(self, self._GetSubConfigNames()) if configManager.last_error: win32ui.MessageBox(configManager.last_error, "Configuration Error") self.bMatchBraces = GetEditorOption("Match Braces", 1) self.ApplyFormattingStyles(1)
def OnInitDialog(self): for name, val in self.autooptions: self[name] = GetEditorOption(name, val) # Note that these MUST be in the same order as the BAK constants. cbo = self.GetDlgItem(win32ui.IDC_COMBO1) cbo.AddString("None") cbo.AddString(".BAK File") cbo.AddString("TEMP dir") cbo.AddString("Own dir") # Source Safe bVSS = (GetEditorOption("Source Control Module", "") == "pywin.framework.editor.vss") self["bVSS"] = bVSS edit = self.GetDlgItem(win32ui.IDC_RIGHTEDGE_SAMPLE) edit.SetWindowText("Sample Color") rc = dialog.PropertyPage.OnInitDialog(self) try: self.GetDlgItem(win32ui.IDC_KEYBOARD_CONFIG).SelectString( -1, GetEditorOption("Keyboard Config", "default")) except win32ui.error: import traceback traceback.print_exc() pass self.HookCommand(self.OnButSimple, win32ui.IDC_FOLD_ENABLE) self.HookCommand(self.OnButSimple, win32ui.IDC_RADIO1) self.HookCommand(self.OnButSimple, win32ui.IDC_RADIO2) self.HookCommand(self.OnButSimple, win32ui.IDC_RIGHTEDGE_ENABLE) self.HookCommand(self.OnButEdgeColor, win32ui.IDC_RIGHTEDGE_DEFINE) butMarginEnabled = self["Marker Margin Width"] > 0 self.GetDlgItem(win32ui.IDC_RADIO1).SetCheck(butMarginEnabled) self.GetDlgItem(win32ui.IDC_RADIO2).SetCheck(not butMarginEnabled) self.edgeColor = self.initialEdgeColor = GetEditorOption( "Right Edge Color", win32api.RGB(0xEF, 0xEF, 0xEF)) for spinner_id in (win32ui.IDC_SPIN1, win32ui.IDC_SPIN2, win32ui.IDC_SPIN3): spinner = self.GetDlgItem(spinner_id) spinner.SetRange(0, 100) self.UpdateUIForState() return rc
def __init__(self): dialog.PropertyPage.__init__(self, win32ui.IDD_PP_EDITOR) self.autooptions = [] self._AddEditorOption(win32ui.IDC_AUTO_RELOAD, "i", "Auto Reload", 1) self._AddEditorOption(win32ui.IDC_COMBO1, "i", "Backup Type", document.BAK_DOT_BAK_BAK_DIR) self._AddEditorOption(win32ui.IDC_AUTOCOMPLETE, "i", "Autocomplete Attributes", 1) self._AddEditorOption(win32ui.IDC_CALLTIPS, "i", "Show Call Tips", 1) self._AddEditorOption(win32ui.IDC_MARGIN_LINENUMBER, "i", "Line Number Margin Width", 0) self._AddEditorOption(win32ui.IDC_RADIO1, "i", "MarkersInMargin", None) self._AddEditorOption(win32ui.IDC_MARGIN_MARKER, "i", "Marker Margin Width", None) self["Marker Margin Width"] = GetEditorOption("Marker Margin Width", 16) # Folding self._AddEditorOption(win32ui.IDC_MARGIN_FOLD, "i", "Fold Margin Width", 12) self._AddEditorOption(win32ui.IDC_FOLD_ENABLE, "i", "Enable Folding", 1) self._AddEditorOption(win32ui.IDC_FOLD_ON_OPEN, "i", "Fold On Open", 0) self._AddEditorOption(win32ui.IDC_FOLD_SHOW_LINES, "i", "Fold Lines", 1) # Right edge. self._AddEditorOption(win32ui.IDC_RIGHTEDGE_ENABLE, "i", "Right Edge Enabled", 0) self._AddEditorOption(win32ui.IDC_RIGHTEDGE_COLUMN, "i", "Right Edge Column", 75) # Source control, etc self.AddDDX(win32ui.IDC_VSS_INTEGRATE, "bVSS") self.AddDDX(win32ui.IDC_KEYBOARD_CONFIG, "Configs", "l") self["Configs"] = pywin.scintilla.config.find_config_files()
def OnOK(self): for name, defVal in self.autooptions: SetEditorOption(name, self[name]) # Margin width gets handled differently. if self['MarkersInMargin'] == 0: SetEditorOption("Marker Margin Width", self["Marker Margin Width"]) else: SetEditorOption("Marker Margin Width", 0) if self.edgeColor != self.initialEdgeColor: SetEditorOption("Right Edge Color", self.edgeColor) if self['bVSS']: SetEditorOption("Source Control Module", "pywin.framework.editor.vss") else: if GetEditorOption("Source Control Module", "")=='pywin.framework.editor.vss': SetEditorOption("Source Control Module", "") # Keyboard config configname = self.GetDlgItem(win32ui.IDC_KEYBOARD_CONFIG).GetWindowText() if configname: if configname == "default": DeleteEditorOption("Keyboard Config") else: SetEditorOption("Keyboard Config", configname) import pywin.scintilla.view pywin.scintilla.view.LoadConfiguration() # Now tell all views we have changed. ## for doc in editorTemplate.GetDocumentList(): ## for view in doc.GetAllViews(): ## try: ## fn = view.OnConfigChange ## except AttributeError: ## continue ## fn() return 1
def __init__(self, template): self.bAutoReload = GetEditorOption("Auto Reload", 1) self.bDeclinedReload = 0 # Has the user declined to reload. self.fileStat = None self.bReportedFileNotFound = 0 # what sort of bak file should I create. # default to write to %temp%/bak/filename.ext self.bakFileType=GetEditorOption("Backup Type", BAK_DOT_BAK_BAK_DIR) self.watcherThread = FileWatchingThread(self) self.watcherThread.CreateThread() # Should I try and use VSS integration? self.scModuleName=GetEditorOption("Source Control Module", "") self.scModule = None # Loaded when first used. ParentEditorDocument.__init__(self, template, template.CreateWin32uiDocument())
def _AddEditorOption(self, idd, typ, optionName, defaultVal): self.AddDDX(idd, optionName, typ) # some options are "derived" - ie, can be implied from others # (eg, "view markers in background" is implied from "markerMarginWidth==0" # So we don't actually store these values, but they do still get DDX support. if defaultVal is not None: self[optionName] = GetEditorOption(optionName, defaultVal) self.autooptions.append((optionName, defaultVal))
def __init__(self, doc): ParentEditorView.__init__(self, doc) if isRichText: self.SetWordWrap(win32ui.CRichEditView_WrapNone) self.addToMRU = 1 self.HookHandlers() self.bCheckingFile = 0 self.defCharFormat = GetEditorFontOption("Default Font", defaultCharacterFormat) # Smart tabs override everything else if context can be worked out. self.bSmartTabs = GetEditorOption("Smart Tabs", 1) self.tabSize = GetEditorOption("Tab Size", 8) self.indentSize = GetEditorOption("Indent Size", 8) # If next indent is at a tab position, and useTabs is set, a tab will be inserted. self.bUseTabs = GetEditorOption("Use Tabs", 1)
def OnInitDialog(self): for name, val in self.autooptions: self[name] = GetEditorOption(name, val) rc = dialog.PropertyPage.OnInitDialog(self) idc = win32ui.IDC_TABTIMMY_NONE if GetEditorOption("Use Tab Timmy", 1): idc = win32ui.IDC_TABTIMMY_IND self.GetDlgItem(idc).SetCheck(1) idc = win32ui.IDC_RADIO1 if GetEditorOption("Use Tabs", 0): idc = win32ui.IDC_USE_TABS self.GetDlgItem(idc).SetCheck(1) tt_color = GetEditorOption("Tab Timmy Color", win32api.RGB(0xff, 0, 0)) self.cbo = self.GetDlgItem(win32ui.IDC_COMBO1) for c in paletteVGA: self.cbo.AddString(c[0]) sel = 0 for c in paletteVGA: if tt_color == win32api.RGB(c[1], c[2], c[3]): break sel = sel + 1 else: sel = -1 self.cbo.SetCurSel(sel) self.HookCommand(self.OnButSimple, win32ui.IDC_TABTIMMY_NONE) self.HookCommand(self.OnButSimple, win32ui.IDC_TABTIMMY_IND) self.HookCommand(self.OnButSimple, win32ui.IDC_TABTIMMY_BG) # Set ranges for the spinners. for spinner_id in [win32ui.IDC_SPIN1, win32ui.IDC_SPIN2]: spinner = self.GetDlgItem(spinner_id) spinner.SetRange(1, 16) return rc
def DoConfigChange(self): SyntEditViewParent.DoConfigChange(self) tabSize = GetEditorOption("Tab Size", 4, 2) indentSize = GetEditorOption("Indent Size", 4, 2) bUseTabs = GetEditorOption("Use Tabs", 0) bSmartTabs = GetEditorOption("Smart Tabs", 1) ext = self.idle.IDLEExtension("AutoIndent") # Required extension. self.SCISetViewWS( GetEditorOption("View Whitespace", 0) ) self.SCISetViewEOL( GetEditorOption("View EOL", 0) ) self.SCISetIndentationGuides( GetEditorOption("View Indentation Guides", 0) ) if GetEditorOption("Right Edge Enabled", 0): mode = EDGE_BACKGROUND else: mode = EDGE_NONE self.SCISetEdgeMode(mode) self.SCISetEdgeColumn( GetEditorOption("Right Edge Column", 75) ) self.SCISetEdgeColor( GetEditorOption("Right Edge Color", win32api.RGB(0xef, 0xef, 0xef))) width = GetEditorOption("Marker Margin Width", 16) self.SCISetMarginWidthN(1, width) width = GetEditorOption("Folding Margin Width", 12) self.SCISetMarginWidthN(2, width) width = GetEditorOption("Line Number Margin Width", 0) self.SCISetMarginWidthN(0, width) self.bFolding = GetEditorOption("Enable Folding", 1) fold_flags = 0 self.SendScintilla(SCI_SETMODEVENTMASK, SC_MOD_CHANGEFOLD); if self.bFolding: if GetEditorOption("Fold Lines", 1): fold_flags = 16 self.SCISetProperty("fold", self.bFolding) self.SCISetFoldFlags(fold_flags) tt_color = GetEditorOption("Tab Timmy Color", win32api.RGB(0xff, 0, 0)) self.SendScintilla(SCI_INDICSETFORE, 1, tt_color) tt_use = GetEditorOption("Use Tab Timmy", 1) if tt_use: self.SCISetProperty("tab.timmy.whinge.level", "1") # Auto-indent has very complicated behaviour. In a nutshell, the only # way to get sensible behaviour from it is to ensure tabwidth != indentsize. # Further, usetabs will only ever go from 1->0, never 0->1. # This is _not_ the behaviour Pythonwin wants: # * Tab width is arbitary, so should have no impact on smarts. # * bUseTabs setting should reflect how new files are created, and # if Smart Tabs disabled, existing files are edited # * If "Smart Tabs" is enabled, bUseTabs should have no bearing # for existing files (unless of course no context can be determined) # # So for smart tabs we configure the widget with completely dummy # values (ensuring tabwidth != indentwidth), ask it to guess, then # look at the values it has guessed, and re-configure if bSmartTabs: ext.config(usetabs=1, tabwidth=5, indentwidth=4) ext.set_indentation_params(1) if ext.indentwidth==5: # Either 5 literal spaces, or a single tab character. Assume a tab usetabs = 1 indentwidth = tabSize else: # Either Indented with spaces, and indent size has been guessed or # an empty file (or no context found - tough!) if self.GetTextLength()==0: # emtpy usetabs = bUseTabs indentwidth = indentSize else: # guessed. indentwidth = ext.indentwidth usetabs = 0 # Tab size can never be guessed - set at user preference. ext.config(usetabs=usetabs, indentwidth=indentwidth, tabwidth=tabSize) else: # Dont want smart-tabs - just set the options! ext.config(usetabs=bUseTabs, tabwidth=tabSize, indentwidth=indentSize) self.SCISetIndent(indentSize) self.SCISetTabWidth(tabSize)
def _AddEditorOption(self, idd, typ, optionName, defaultVal): self.AddDDX(idd, optionName, typ) self[optionName] = GetEditorOption(optionName, defaultVal) self.autooptions.append((optionName, defaultVal))
def FinalizeViewCreation(self, view): ParentEditorDocument.FinalizeViewCreation(self, view) if view == self.GetFirstView(): self._DocumentStateChanged() if view.bFolding and GetEditorOption("Fold On Open", 0): view.FoldTopLevelEvent()