-
Notifications
You must be signed in to change notification settings - Fork 0
/
wing_debug.py
82 lines (64 loc) · 2.88 KB
/
wing_debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
# Python 3.6 or later
# Examples of resources in Lime/LiR Integ:
# from . import lime
# lime.MsgBoxStyle.YesNoCancel is already defined by Henrik.
# app = lime.get_app()
# app.ActiveExplorer.Class.Name
# app.MenuBar.Menu.Item(8).SubMenu.Item(1).Name
# app.ActiveExplorer.Items.Count
# app.ActiveExplorer.Selection.Count
# app.ActiveExplorer.Selection.Item(1).Value("idparticipant")
# cParticipant = app.Database.Classes.Lookup('participant', constants.lkLookupClassByName)
# instanciated object log must be global so that logging will work
import logging
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG) # filter (DEBUG, INFO, WARNING, ERROR)
from pathlib import Path
from . import lime
from . import vba_dialogs
from win32com.shell import shell, shellcon
class Wingdebugger():
# two use cases:
# (1) declare an object (debugger) and then destroy it (debugger = None)
# (2) with Wingdebugger(): ...
def __init__(self): # called before __enter__ when used in with statement
try:
import wingdbstub # may cause debugger to start; must be inside class, not global
wingdbstub.Ensure() # force debugger start; raises exception if Wingware is not running
except ImportError:
pass #log.exception('Missing wingdbstub on class init') # not for production
def __enter__(self): # used in with statement, try: statement is implicit
pass
def __exit__(self, exc_type, exc_value, traceback): # used in with statement
if exc_value is not None:
messagebox(str(exc_value))
log.exception(str(exc_value))
try:
import wingdbstub
wingdbstub.debugger.ProgramQuit()
except ImportError:
pass #log.exception('Missing wingdbstub on class exit') # not for production
return True # True suppresses exception processing
def __del__(self): # called after __exit__ when used in with statement
try:
import wingdbstub
wingdbstub.debugger.ProgramQuit()
except Exception:
pass #log.exception('Missing wingdbstub on class delete') # not for production
self.log = None
def get_known_path(key):
csidl = {'appdata': shellcon.CSIDL_LOCAL_APPDATA,
'desktop': shellcon.CSIDL_DESKTOPDIRECTORY}[key]
SHGFP_TYPE_CURRENT = 0
return Path(shell.SHGetFolderPath(None, csidl, None, SHGFP_TYPE_CURRENT))
def messagebox(message, style=0, *, title="LiR Rapportplugin"):
return vba_dialogs.messagebox(
lime.get_app(), message,
title=title, style=style)
def inputbox(message, title="LiR Rapportplugin", default=None,
xpos=100, ypos=100):
return vba_dialogs.inputbox(
lime.get_app(),
message, title=title, default=default,
xpos=xpos, ypos=ypos)