diff --git a/Pythonwin/pywin/default.cfg b/Pythonwin/pywin/default.cfg index 9366e2dfb6..ce79f46ccf 100644 --- a/Pythonwin/pywin/default.cfg +++ b/Pythonwin/pywin/default.cfg @@ -2,7 +2,7 @@ # # The format of this file is very similar to a Windows INI file. # Sections are identified with [Section] lines, but comments -# use the standatd Python # character. Depending on the section, +# use the standard Python # character. Depending on the section, # lines may not be in the standard "key=value" format. # NOTE: You should not need to modify this file. @@ -47,9 +47,9 @@ Ctrl+Shift+F = ViewFixedFont # Auto-complete, call-tips, etc. Alt+/ = <> -Ctrl+Space = <> -( = <> -) = <> +Ctrl+Space = <> +( = <> +) = <> Up = <> Down = <> Left = <> @@ -134,53 +134,59 @@ Ctrl+Shift+Tab = MDIPrev # Add a simple file/class/function simple banner def AddBanner(editor_window, event): + text = editor_window.text + big_line = "#" * 70 + banner = "%s\n## \n## \n## \n%s\n" % (big_line, big_line) - text = editor_window.text - big_line = "#" * 70 - banner = "%s\n## \n## \n## \n%s\n" % (big_line, big_line) + # Insert at the start of the current line. + pos = text.index("insert linestart") - # Insert at the start of the current line. - pos = text.index("insert linestart") + text.undo_block_start() # Allow action to be undone as a single unit. + text.insert(pos, banner) + text.undo_block_stop() - text.undo_block_start() # Allow action to be undone as a single unit. - text.insert(pos, banner) - text.undo_block_stop() - - # Now set the insert point to the middle of the banner. - line, col = [int(s) for s in pos.split(".")] - text.mark_set("insert", "%d.1 lineend" % (line+2, ) ) + # Now set the insert point to the middle of the banner. + line, col = [int(s) for s in pos.split(".")] + text.mark_set("insert", "%d.1 lineend" % (line + 2,)) # Here is a sample event bound to the "Home" key in the # interactive window def InteractiveHome(editor_window, event): - return _DoInteractiveHome(editor_window.text, 0) + return _DoInteractiveHome(editor_window.text, 0) + def InteractiveHomeExtend(editor_window, event): - return _DoInteractiveHome(editor_window.text, 1) + return _DoInteractiveHome(editor_window.text, 1) + def _DoInteractiveHome(text, extend): - import sys - # If Scintilla has an autocomplete window open, then let Scintilla handle it. - if text.edit.SCIAutoCActive(): - return 1 - of_interest = "insert linestart + %d c" % len(sys.ps1) - if not text.compare("insert", "==", of_interest) and \ - text.get("insert linestart", of_interest) in [sys.ps1, sys.ps2]: # Not sys.ps? line - end = of_interest - else: - end = "insert linestart" - - if extend: start = "insert" - else: start = end - text.tag_add("sel", start, end) + import sys + + # If Scintilla has an autocomplete window open, then let Scintilla handle it. + if text.edit.SCIAutoCActive(): + return 1 + of_interest = "insert linestart + %d c" % len(sys.ps1) + if not text.compare("insert", "==", of_interest) and text.get( + "insert linestart", of_interest + ) in [sys.ps1, sys.ps2]: + # Not sys.ps? line + end = of_interest + else: + end = "insert linestart" + + if extend: + start = "insert" + else: + start = end + text.tag_add("sel", start, end) + # From Niki Spahie def AutoFindNext(editor_window, event): - "find selected text or word under cursor" + """find selected text or word under cursor""" - from pywin.scintilla import find - from pywin.scintilla import scintillacon + from pywin.scintilla import find, scintillacon try: sci = editor_window.edit @@ -189,26 +195,29 @@ def AutoFindNext(editor_window, event): find.lastSearch.findText = word find.lastSearch.sel = sci.GetSel() else: - pos = sci.SendScintilla( scintillacon.SCI_GETCURRENTPOS ) - start = sci.SendScintilla( scintillacon.SCI_WORDSTARTPOSITION, pos, 1 ) - end = sci.SendScintilla( scintillacon.SCI_WORDENDPOSITION, pos, 1 ) - word = sci.GetTextRange( start, end ) + pos = sci.SendScintilla(scintillacon.SCI_GETCURRENTPOS) + start = sci.SendScintilla(scintillacon.SCI_WORDSTARTPOSITION, pos, 1) + end = sci.SendScintilla(scintillacon.SCI_WORDENDPOSITION, pos, 1) + word = sci.GetTextRange(start, end) if word: find.lastSearch.findText = word - find.lastSearch.sel = (start,end) + find.lastSearch.sel = (start, end) except Exception: import traceback + traceback.print_exc() find.FindNext() # A couple of generic events. def Beep(editor_window, event): - editor_window.text.beep() + editor_window.text.beep() + def DoNothing(editor_window, event): - pass + pass + def ContinueEvent(editor_window, event): - # Almost an "unbind" - allows Pythonwin/MFC to handle the keystroke - return 1 + # Almost an "unbind" - allows Pythonwin/MFC to handle the keystroke + return 1 diff --git a/Pythonwin/start_pythonwin.pyw b/Pythonwin/start_pythonwin.pyw index 0a1b2e60ba..370e3efb59 100644 --- a/Pythonwin/start_pythonwin.pyw +++ b/Pythonwin/start_pythonwin.pyw @@ -1,11 +1,10 @@ -# A Python file that can be used to start Pythonwin, instead of using -# pythonwin.exe +"""A Python file that can be used to start Pythonwin, instead of using pythonwin.exe""" + import os import sys -import win32ui - import pywin.framework.intpyapp # InteractivePythonApp() +import win32ui assert pywin.framework.intpyapp # not unused # Pretend this script doesn't exist, or pythonwin tries to edit it diff --git a/com/win32comext/axscript/demos/client/wsh/excel.pys b/com/win32comext/axscript/demos/client/wsh/excel.pys index 67094cd423..b10a80d731 100644 --- a/com/win32comext/axscript/demos/client/wsh/excel.pys +++ b/com/win32comext/axscript/demos/client/wsh/excel.pys @@ -1,18 +1,20 @@ -#app=WScript.Application -#app._print_details_() # Use this to see what Python knows about a COM object. - +# app=WScript.Application +# app._print_details_() # Use this to see what Python knows about a COM object. g_index = 1 + + # A procedure, using a global. -def Show(desc, value = None): - global g_index # Need global for g_index, as I locally assign. - # No global needed to "xl" object, as only referenced. - # Also note "xl" is assigned later in the script - ie, Python is very late bound. - xl.Cells(g_index, 1).Value = desc - if value: xl.Cells(g_index, 2).Value = value - g_index = g_index + 1 +def Show(desc, value=None): + global g_index # Need global for g_index, as I locally assign. + # No global needed to "xl" object, as only referenced. + # Also note "xl" is assigned later in the script - ie, Python is very late bound. + xl.Cells(g_index, 1).Value = desc + if value: + xl.Cells(g_index, 2).Value = value + g_index = g_index + 1 + xl = WScript.CreateObject("Excel.Application") -import sys xl.Visible = 1 xl.Workbooks.Add() @@ -27,5 +29,5 @@ Show("State of Interactive Mode", WScript.Interactive) Show("All script arguments:") args = WScript.Arguments -for i in range(0,args.Count()): - Show("Arg %d" % i, args(i)) +for i in range(0, args.Count()): + Show("Arg %d" % i, args(i)) diff --git a/com/win32comext/axscript/demos/client/wsh/registry.pys b/com/win32comext/axscript/demos/client/wsh/registry.pys index 76e91d8fe1..265450b213 100644 --- a/com/win32comext/axscript/demos/client/wsh/registry.pys +++ b/com/win32comext/axscript/demos/client/wsh/registry.pys @@ -1,4 +1,4 @@ -""" Windows Script Host Sample Script +"""Windows Script Host Sample Script ' Ported to Python ' ' ------------------------------------------------------------------------ @@ -21,24 +21,24 @@ WshShell.Popup("Create key HKCU\\Foo with value 'Top level key'") WshShell.RegWrite("HKCU\\Foo\\", "Top level key") WshShell.Popup("Create key HKCU\\Foo\\Bar with value 'Second level key'") -WshShell.RegWrite( "HKCU\\Foo\\Bar\\", "Second level key") +WshShell.RegWrite("HKCU\\Foo\\Bar\\", "Second level key") -WshShell.Popup ("Set value HKCU\\Foo\\Value to REG_SZ 1") -WshShell.RegWrite( "HKCU\\Foo\\Value", 1) +WshShell.Popup("Set value HKCU\\Foo\\Value to REG_SZ 1") +WshShell.RegWrite("HKCU\\Foo\\Value", 1) -WshShell.Popup ("Set value HKCU\\Foo\\Bar to REG_DWORD 2") -WshShell.RegWrite ("HKCU\\Foo\\Bar", 2, "REG_DWORD") +WshShell.Popup("Set value HKCU\\Foo\\Bar to REG_DWORD 2") +WshShell.RegWrite("HKCU\\Foo\\Bar", 2, "REG_DWORD") -WshShell.Popup ("Set value HKCU\\Foo\\Bar to REG_EXPAND_SZ '3'") -WshShell.RegWrite ("HKCU\\Foo\\Bar\\Baz", "%SystemRoot%\\Foo") +WshShell.Popup("Set value HKCU\\Foo\\Bar to REG_EXPAND_SZ '3'") +WshShell.RegWrite("HKCU\\Foo\\Bar\\Baz", "%SystemRoot%\\Foo") -WshShell.Popup ("Delete value HKCU\\Foo\\Bar\\Baz") -WshShell.RegDelete ("HKCU\\Foo\\Bar\\Baz") +WshShell.Popup("Delete value HKCU\\Foo\\Bar\\Baz") +WshShell.RegDelete("HKCU\\Foo\\Bar\\Baz") -WshShell.Popup ("Delete key HKCU\\Foo\\Bar") -WshShell.RegDelete ("HKCU\\Foo\\Bar\\") +WshShell.Popup("Delete key HKCU\\Foo\\Bar") +WshShell.RegDelete("HKCU\\Foo\\Bar\\") -WshShell.Popup ("Delete key HKCU\\Foo") -WshShell.RegDelete ("HKCU\\Foo\\") +WshShell.Popup("Delete key HKCU\\Foo") +WshShell.RegDelete("HKCU\\Foo\\") -WScript.Echo ("Done") +WScript.Echo("Done") diff --git a/com/win32comext/axscript/demos/client/wsh/test.pys b/com/win32comext/axscript/demos/client/wsh/test.pys index a3fcaf5006..581873171e 100644 --- a/com/win32comext/axscript/demos/client/wsh/test.pys +++ b/com/win32comext/axscript/demos/client/wsh/test.pys @@ -2,13 +2,14 @@ # Test "Restricted Execution" (ie, IObjectSafety). # This will fail if in a "restricted execution" environment, but -# will silenty do nothing of not restricted. This same line in an MSIE +# will silently do nothing of not restricted. This same line in an MSIE # script would cause an exception. print("Importing win32api...") import win32api -if 1==1: - print("Hi") + +if 1 == 1: + print("Hi") WScript.Echo("Hello from WScript") -#fail +# fail diff --git a/com/win32comext/axscript/test/debugTest.pys b/com/win32comext/axscript/test/debugTest.pys index 8ceea0980b..9abc57623c 100644 --- a/com/win32comext/axscript/test/debugTest.pys +++ b/com/win32comext/axscript/test/debugTest.pys @@ -1,16 +1,17 @@ def Function(i): - Test.Echo(i) + Test.Echo(i) + print(dir()) -a=1 -b=a -c=b # And here is a comment -d="A string" +a = 1 +b = a +c = b # And here is a comment +d = "A string" print(a) Test.echo("Hello from Python") for i in range(2): - Function(i) + Function(i) a = """\ A multi-line string! """ diff --git a/ruff.toml b/ruff.toml index e96c2eafef..bba1bd4278 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,4 +1,10 @@ target-version = "py39" # Target the oldest supported version +extend-include = [ + "*.pyw", # Will be included by default in Ruff eventually + "*.pys", # PythonScript (Windows Script Host) + # Can be uncommented to format the [Extensions] section + # "**/default.cfg", +] # This file is not UTF-8 extend-exclude = ["Pythonwin/pywin/test/_dbgscript.py"]