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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
import logging
import debugpy
from far2l.plugin import PluginBase
from far2l.farprogress import ProgressMessage
from far2l.fardialogbuilder import (
TEXT,
EDIT,
BUTTON,
MASKED,
HLine,
HSizer,
VSizer,
DialogBuilder,
)
log = logging.getLogger(__name__)
class Config:
configured = False
logto = "/tmp"
host = "127.0.0.1"
port = 5678
class Plugin(PluginBase):
label = "Python udebug"
openFrom = ["PLUGINSMENU", "COMMANDLINE", "EDITOR", "VIEWER", "FILEPANEL"]
def debug(self):
if Config.configured:
self.parent.Message(("udebug can be configured only once.",))
return
t = ProgressMessage(self, self.label, "Waiting for VSCode", 100)
t.show()
try:
Config.configured = True
debugpy.log_to(Config.logto)
# in vs code debuger select attach, port = 5678
# commands in shell:
# py:debug
# elsewhere in python code:
# import debugpy
# debugpy.breakpoint()
debugpy.listen((Config.host, Config.port))
debugpy.wait_for_client()
# debugpy.breakpoint()
except:
log.exception('configured')
finally:
t.close()
def breakpoint(self):
debugpy.breakpoint()
@staticmethod
def HandleCommandLine(line):
return line in ("debug", "breakpoint")
def CommandLine(self, line):
getattr(self, line)()
def Configure(self):
if Config.configured:
self.parent.Message(("udebug can be configured only once.",))
return
@self.ffi.callback("FARWINDOWPROC")
def DialogProc(hDlg, Msg, Param1, Param2):
if Msg == self.ffic.DN_INITDIALOG:
try:
dlg.SetText(dlg.ID_logpath, Config.logto)
dlg.SetText(dlg.ID_ipaddress, Config.host)
dlg.SetText(dlg.ID_port, str(Config.port))
except:
log.exception("bang")
return self.info.DefDlgProc(hDlg, Msg, Param1, Param2)
b = DialogBuilder(
self,
DialogProc,
"debugpy config",
"helptopic",
0,
VSizer(
HSizer(
TEXT(None, "log path:"),
EDIT("logpath", 33, maxlength=80),
),
HSizer(
TEXT(None, "ip address:"),
EDIT("ipaddress", 20),
),
HSizer(
TEXT(None, "ip port:"),
MASKED("port", "99999"),
),
HLine(),
HSizer(
BUTTON("vok", "OK", default=True, flags=self.ffic.DIF_CENTERGROUP),
BUTTON("vcancel", "Cancel", flags=self.ffic.DIF_CENTERGROUP),
),
),
)
# debugpy.breakpoint()
dlg = b.build(-1, -1)
res = self.info.DialogRun(dlg.hDlg)
if res == dlg.ID_vok:
Config.logto = dlg.GetText(dlg.ID_logpath)
Config.host = dlg.GetText(dlg.ID_ipaddress)
Config.port = int(dlg.GetText(dlg.ID_port), 10)
self.info.DialogFree(dlg.hDlg)
log.debug("end dialog")
def OpenPlugin(self, OpenFrom):
self.Configure()
|