Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 53 additions & 44 deletions Pythonwin/pywin/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -47,9 +47,9 @@ Ctrl+Shift+F = ViewFixedFont

# Auto-complete, call-tips, etc.
Alt+/ = <<expand-word>>
Ctrl+Space = <<expand-word>>
( = <<paren-open>>
) = <<paren-close>>
Ctrl+Space = <<expand-word>>
( = <<paren-open>>
) = <<paren-close>>
Up = <<check-calltip-cancel>>
Down = <<check-calltip-cancel>>
Left = <<check-calltip-cancel>>
Expand Down Expand Up @@ -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
Expand All @@ -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
7 changes: 3 additions & 4 deletions Pythonwin/start_pythonwin.pyw
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 15 additions & 13 deletions com/win32comext/axscript/demos/client/wsh/excel.pys
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -27,5 +29,5 @@
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))
30 changes: 15 additions & 15 deletions com/win32comext/axscript/demos/client/wsh/registry.pys
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Windows Script Host Sample Script
"""Windows Script Host Sample Script
' Ported to Python
'
' ------------------------------------------------------------------------
Expand All @@ -21,24 +21,24 @@
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")
9 changes: 5 additions & 4 deletions com/win32comext/axscript/demos/client/wsh/test.pys
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Testall - test core AX support.

# 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
13 changes: 7 additions & 6 deletions com/win32comext/axscript/test/debugTest.pys
Original file line number Diff line number Diff line change
@@ -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!
"""
6 changes: 6 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
Loading