Skip to content
Merged
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
18 changes: 6 additions & 12 deletions Pythonwin/pywin/framework/editor/color/coloreditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
# even tighter into Pythonwin.

import pywin.scintilla.keycodes
import pywin.scintilla.view
import win32api
import win32con
import win32ui
from pywin.debugger import dbgcon
from pywin.framework.editor import GetEditorOption
Comment thread
Avasam marked this conversation as resolved.
from pywin.scintilla import bindings

# from pywin.framework.editor import EditorPropertyPage
from pywin.framework.editor.document import EditorDocumentBase
from pywin.scintilla import bindings, scintillacon

MSG_CHECK_EXTERNAL_FILE = (
win32con.WM_USER + 1999
) ## WARNING: Duplicated in document.py and editor.py
# WARNING: Duplicated in document.py and editor.py
MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER + 1999

# Define a few common markers
MARKER_BOOKMARK = 0
MARKER_BREAKPOINT = 1
MARKER_CURRENT = 2

import pywin.scintilla.view
from pywin.debugger import dbgcon
from pywin.framework.editor.document import EditorDocumentBase
from pywin.scintilla import scintillacon # For the marker definitions
from pywin.scintilla.document import CScintillaDocument


class SyntEditDocument(EditorDocumentBase):
"A SyntEdit document."
Expand Down
21 changes: 9 additions & 12 deletions Pythonwin/pywin/framework/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@
GetEditorOption,
defaultCharacterFormat,
)
from pywin.mfc import afxres, docview
from pywin.mfc import afxres
from pywin.mfc.docview import RichEditView as ParentEditorView

from .document import EditorDocumentBase as ParentEditorDocument

# from pywin.mfc.docview import EditView as ParentEditorView
# from pywin.mfc.docview import Document as ParentEditorDocument

patImport = regex.symcomp(r"import \(<name>.*\)")
patIndent = regex.compile(r"^\([ \t]*[~ \t]\)")

ID_LOCATE_FILE = 0xE200
ID_GOTO_LINE = 0xE2001
MSG_CHECK_EXTERNAL_FILE = (
win32con.WM_USER + 1999
) ## WARNING: Duplicated in document.py and coloreditor.py
# WARNING: Duplicated in document.py and coloreditor.py
MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER + 1999

# Key Codes that modify the bufffer when Ctrl or Alt are NOT pressed.
MODIFYING_VK_KEYS = [
Expand Down Expand Up @@ -76,11 +81,6 @@

isRichText = 1 # We are using the Rich Text control. This has not been tested with value "0" for quite some time!

# ParentEditorDocument=docview.Document
from .document import EditorDocumentBase

ParentEditorDocument = EditorDocumentBase


class EditorDocument(ParentEditorDocument):
#
Expand Down Expand Up @@ -164,9 +164,6 @@ def SetLineColor(self, lineNo, color):
# self.saveFileHandle.write(data)
# return 1 # keep em coming!

# ParentEditorView=docview.EditView
ParentEditorView = docview.RichEditView


class EditorView(ParentEditorView):
def __init__(self, doc):
Expand Down
82 changes: 13 additions & 69 deletions com/win32comext/axdebug/Test/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

import pythoncom
import win32api
import win32com.server.util
import winerror
from win32com.axdebug import adb, axdebug, codecontainer, gateways
from win32com.axdebug.util import trace
from win32com.axdebug import codecontainer, gateways
from win32com.axdebug.util import _wrap, trace
from win32com.server.exception import Exception


Expand All @@ -24,8 +23,10 @@ def ReleaseConnection(self, extconn, reserved, fLastReleaseCloses):
return self.numExtRefs


# externalConnectionManager = ExternalConnection()
# wrappedExternalConnectionManager = _wrap(externalConnectionManager, pythoncom.IID_IExternalConnection)
externalConnectionManager = ExternalConnection()
wrappedExternalConnectionManager = _wrap(
externalConnectionManager, pythoncom.IID_IExternalConnection
)


def DelegatedExternalConnectionQI(iid):
Expand All @@ -47,9 +48,7 @@ def _query_interface_(self, iid):
from win32com.util import IIDToInterfaceName

trace(
"PySourceModuleDebugDocumentHost QI with {} ({})".format(
IIDToInterfaceName(iid), str(iid)
)
f"PySourceModuleDebugDocumentHost QI with {IIDToInterfaceName(iid)} ({iid})"
)
return 0

Expand All @@ -58,7 +57,7 @@ def _GetCodeContainer(self):
try:
codeText = open(self.module.__file__, "rt").read()
except OSError as details:
codeText = "# Exception opening file\n# %s" % (details)
codeText = f"# Exception opening file\n# {details}"

self.codeContainer = codecontainer.SourceCodeContainer(
codeText, self.module.__file__
Expand Down Expand Up @@ -96,71 +95,25 @@ def GetPathName(self):
try:
return win32api.GetFullPathName(self.module.__file__), 1
except (AttributeError, win32api.error):
raise Exception(scode == E_FAIL)
raise Exception(scode=winerror.E_FAIL)

def GetFileName(self):
# Result is a string with just the name of the document, no path information.
trace("GetFileName")
return os.path.split(module.__file__)
return os.path.split(self.module.__file__)

def NotifyChanged():
trace("NotifyChanged")
raise Exception(scode=winerror.E_NOTIMPL)


def TestSmartHelper():
pdm = pythoncom.CoCreateInstance(
axdebug.CLSID_ProcessDebugManager,
None,
pythoncom.CLSCTX_ALL,
axdebug.IID_IProcessDebugManager,
)
app = pdm.CreateApplication()
app.SetName("Python Process")

pydebugger = adb.Debugger()

nodes = BuildModuleTree()

all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes)
root = app.GetRootNode()
AttachParentNodes(root, nodes, all_real_nodes)

pydebugger.AttachApp(app)
cookie = pdm.AddApplication(app)
input("Waiting...")
ttest.test()

pdm.RemoveApplication(cookie)
print("Done")


def testdumb():
pdm = pythoncom.CoCreateInstance(
axdebug.CLSID_ProcessDebugManager,
None,
pythoncom.CLSCTX_ALL,
axdebug.IID_IProcessDebugManager,
)
app = pdm.GetDefaultApplication()

nodes = BuildModuleTree()
all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes)
AttachParentNodes(None, nodes, all_real_nodes)

parentNode = None
all_real_nodes = {}
input("Waiting...")
print("Done")


Comment on lines -111 to -156
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were commented out in the caller code (so it's unused) and contain a bunch of undefined names / unbound variables that I can't find anywhere.
If you still think it's worth keeping around, I'll comment them out instead.

def TestSmartProvider():
import ttest
from win32com.axdebug import debugger

d = debugger.AXDebugger()
# d.StartDebugger()
# d.Attach()
# d.StartDebugger()
# d.Attach()
d.Break()
input("Waiting...")
ttest.test()
Expand All @@ -170,22 +123,13 @@ def TestSmartProvider():

def test():
try:
# app = TestSmartHelper()
app = TestSmartProvider()
# app = testdumb()
except:
traceback.print_exc()


# _wrap_remove(externalConnectionManager)
# wrappedExternalConnectionManager = None

if __name__ == "__main__":
test()
import win32com.axdebug.util

win32com.axdebug.util._dump_wrapped()
print(
" %d/%d com objects still alive"
% (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())
f" {pythoncom._GetInterfaceCount()}/{pythoncom._GetGatewayCount()} com objects still alive"
)
55 changes: 23 additions & 32 deletions com/win32comext/axdebug/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import pythoncom
import win32api
import win32com.client.connect
from win32com.axdebug.util import _wrap, _wrap_remove, trace
from win32com.server.util import unwrap
from win32com.axdebug.util import _wrap, trace

from . import axdebug, gateways, stackframe

Expand Down Expand Up @@ -53,12 +52,7 @@ def _dumpf(frame):
addn = "(with trace!)"
if frame.f_trace is None:
addn = " **No Trace Set **"
return "Frame at %d, file %s, line: %d%s" % (
id(frame),
frame.f_code.co_filename,
frame.f_lineno,
addn,
)
return f"Frame at {id(frame)}, file {frame.f_code.co_filename}, line: {frame.f_lineno}{addn}"


g_adb = None
Expand Down Expand Up @@ -118,8 +112,8 @@ def __xxxxx__set_break(self, filename, lineno, cond=None):
def stop_here(self, frame):
traceenter("stop_here", _dumpf(frame), _dumpf(self.stopframe))
# As per bdb.stop_here, except for logicalbotframe
## if self.stopframe is None:
## return 1
# if self.stopframe is None:
# return 1
if frame is self.stopframe:
return 1

Expand Down Expand Up @@ -157,13 +151,13 @@ def dispatch_return(self, frame, arg):
tracev("dispatch_return resetting sys.trace")
sys.settrace(None)
return
# self.bSetTrace = 0
# self.bSetTrace = 0
self.currentframe = frame.f_back
return bdb.Bdb.dispatch_return(self, frame, arg)

def dispatch_line(self, frame):
traceenter("dispatch_line", _dumpf(frame), _dumpf(self.botframe))
# trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe)
# trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe)
if frame is self.logicalbotframe:
trace("dispatch_line", _dumpf(frame), "for bottom frame returing tracer")
# The next code executed in the frame above may be a builtin (eg, apply())
Expand Down Expand Up @@ -195,13 +189,13 @@ def dispatch_call(self, frame, arg):
trace(
"dispatch_call has no document for", _dumpf(frame), "- skipping trace!"
)
## sys.settrace(None)
# sys.settrace(None)
return None
return self.trace_dispatch

# rc = bdb.Bdb.dispatch_call(self, frame, arg)
# trace("dispatch_call", _dumpf(frame),"returned",rc)
# return rc
# rc = bdb.Bdb.dispatch_call(self, frame, arg)
# trace("dispatch_call", _dumpf(frame),"returned",rc)
# return rc

def trace_dispatch(self, frame, event, arg):
traceenter("trace_dispatch", _dumpf(frame), event, arg)
Expand All @@ -213,8 +207,8 @@ def trace_dispatch(self, frame, event, arg):
#
# The user functions do bugger all!
#
# def user_call(self, frame, argument_list):
# traceenter("user_call",_dumpf(frame))
# def user_call(self, frame, argument_list):
# traceenter("user_call",_dumpf(frame))

def user_line(self, frame):
traceenter("user_line", _dumpf(frame))
Expand All @@ -226,11 +220,11 @@ def user_line(self, frame):
self._HandleBreakPoint(frame, None, breakReason)

def user_return(self, frame, return_value):
# traceenter("user_return",_dumpf(frame),return_value)
# traceenter("user_return",_dumpf(frame),return_value)
bdb.Bdb.user_return(self, frame, return_value)

def user_exception(self, frame, exc_info):
# traceenter("user_exception")
# traceenter("user_exception")
bdb.Bdb.user_exception(self, frame, exc_info)

def _HandleBreakPoint(self, frame, tb, reason):
Expand Down Expand Up @@ -281,11 +275,8 @@ def CloseApp(self):

except pythoncom.com_error:
trace(
"*** Could not RemoveStackFrameSniffer %d"
% (self.stackSnifferCookie)
f"*** Could not RemoveStackFrameSniffer {self.stackSnifferCookie}"
)
if self.stackSniffer:
_wrap_remove(self.stackSniffer)
self.stackSnifferCookie = self.stackSniffer = None

if self.appEventConnection is not None:
Expand All @@ -298,7 +289,7 @@ def CloseApp(self):
self.codeContainerProvider = None

def AttachApp(self, debugApplication, codeContainerProvider):
# traceenter("AttachApp", debugApplication, codeContainerProvider)
# traceenter("AttachApp", debugApplication, codeContainerProvider)
self.codeContainerProvider = codeContainerProvider
self.debugApplication = debugApplication
self.stackSniffer = _wrap(
Expand All @@ -307,7 +298,7 @@ def AttachApp(self, debugApplication, codeContainerProvider):
self.stackSnifferCookie = debugApplication.AddStackFrameSniffer(
self.stackSniffer
)
# trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie)
# trace(f"StackFrameSniffer added ({self.stackSnifferCookie})")

# Connect to the application events.
self.appEventConnection = win32com.client.connect.SimpleConnection(
Expand All @@ -321,7 +312,7 @@ def ResetAXDebugging(self):
return

if len(self.recursiveData) == 0:
# print "ResetAXDebugging called for final time."
# print("ResetAXDebugging called for final time.")
self.logicalbotframe = None
self.debuggingThread = None
self.currentframe = None
Expand Down Expand Up @@ -427,14 +418,14 @@ def OnBreakFlagChange(self, abf, rdat):

def _BreakFlagsChanged(self):
traceenter(
"_BreakFlagsChanged to {} with our thread = {}, and debugging thread = {}".format(
self.breakFlags, self.debuggingThread, win32api.GetCurrentThreadId()
)
f"_BreakFlagsChanged to {self.breakFlags} "
+ f"with our thread = {self.debuggingThread}, "
+ f"and debugging thread = {win32api.GetCurrentThreadId()}"
)
trace("_BreakFlagsChanged has breaks", self.breaks)
# If a request comes on our debugging thread, then do it now!
# if self.debuggingThread!=win32api.GetCurrentThreadId():
# return
# if self.debuggingThread!=win32api.GetCurrentThreadId():
# return

if len(self.breaks) or self.breakFlags:
if self.logicalbotframe:
Expand Down
Loading