codekingpro/portable-devtools
115k
1# __init__ for the Pythonwin editor package.2#3# We used to support optional editors - eg, color or non-color.4#5# This really isnt necessary with Scintilla, and scintilla6# is getting so deeply embedded that it was too much work.7 8import sys9 10import win32con11import win32ui12 13defaultCharacterFormat = (-402653169, 0, 200, 0, 0, 0, 49, "Courier New")14 15##def GetDefaultEditorModuleName():16## import pywin17## # If someone has set pywin.editormodulename, then this is what we use18## try:19## prefModule = pywin.editormodulename20## except AttributeError:21## prefModule = win32ui.GetProfileVal("Editor","Module", "")22## return prefModule23##24##def WriteDefaultEditorModule(module):25## try:26## module = module.__name__27## except:28## pass29## win32ui.WriteProfileVal("Editor", "Module", module)30 31 32def LoadDefaultEditor():33 pass34 35 36## prefModule = GetDefaultEditorModuleName()37## restorePrefModule = None38## mod = None39## if prefModule:40## try:41## mod = __import__(prefModule)42## except 'xx':43## msg = "Importing your preferred editor ('%s') failed.\n\nError %s: %s\n\nAn attempt will be made to load the default editor.\n\nWould you like this editor disabled in the future?" % (prefModule, sys.exc_info()[0], sys.exc_info()[1])44## rc = win32ui.MessageBox(msg, "Error importing editor", win32con.MB_YESNO)45## if rc == win32con.IDNO:46## restorePrefModule = prefModule47## WriteDefaultEditorModule("")48## del rc49##50## try:51## # Try and load the default one - dont catch errors here.52## if mod is None:53## prefModule = "pywin.framework.editor.color.coloreditor"54## mod = __import__(prefModule)55##56## # Get at the real module.57## mod = sys.modules[prefModule]58##59## # Do a "from mod import *"60## globals().update(mod.__dict__)61##62## finally:63## # Restore the users default editor if it failed and they requested not to disable it.64## if restorePrefModule:65## WriteDefaultEditorModule(restorePrefModule)66 67 68def GetEditorOption(option, defaultValue, min=None, max=None):69 rc = win32ui.GetProfileVal("Editor", option, defaultValue)70 if min is not None and rc < min:71 rc = defaultValue72 if max is not None and rc > max:73 rc = defaultValue74 return rc75 76 77def SetEditorOption(option, newValue):78 win32ui.WriteProfileVal("Editor", option, newValue)79 80 81def DeleteEditorOption(option):82 try:83 win32ui.WriteProfileVal("Editor", option, None)84 except win32ui.error:85 pass86 87 88# Load and save font tuples89def GetEditorFontOption(option, default=None):90 if default is None:91 default = defaultCharacterFormat92 fmt = GetEditorOption(option, "")93 if fmt == "":94 return default95 try:96 return eval(fmt)97 except:98 print("WARNING: Invalid font setting in registry - setting ignored")99 return default100 101 102def SetEditorFontOption(option, newValue):103 SetEditorOption(option, str(newValue))104 105 106from pywin.framework.editor.color.coloreditor import editorTemplate107 