Gui: add possibility to connect to remote Python debugger

This commit is contained in:
wmayer
2020-02-29 14:25:51 +01:00
parent cbbf1c8dbb
commit d99f424345
5 changed files with 291 additions and 3 deletions

View File

@@ -1369,3 +1369,23 @@ else(WIN32)
INSTALL(FILES Icons/freecad.xpm DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pixmaps)
INSTALL(FILES Icons/freecad-doc.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/mimetypes RENAME application-x-extension-fcstd.svg)
endif(WIN32)
set(FreeCADGui_Scripts
RemoteDebugger.ui
RemoteDebugger.py
)
add_custom_target(FreeCADGui_Resources ALL
SOURCES ${FreeCADGui_Scripts}
)
fc_copy_sources(FreeCADGui_Resources
${CMAKE_BINARY_DIR}/Ext/freecad/gui
${FreeCADGui_Scripts})
INSTALL(
FILES
${FreeCADGui_Scripts}
DESTINATION
Ext/freecad/gui
)

View File

@@ -151,6 +151,31 @@ bool StdCmdDlgMacroExecuteDirect::isActive(void)
return getGuiApplication()->sendHasMsgToActiveView("Run");
}
DEF_STD_CMD_A(StdCmdMacroAttachDebugger)
StdCmdMacroAttachDebugger::StdCmdMacroAttachDebugger()
: Command("Std_MacroAttachDebugger")
{
sGroup = QT_TR_NOOP("Macro");
sMenuText = QT_TR_NOOP("Attach to remote debugger...");
sToolTipText = QT_TR_NOOP("Attach to a remotely running debugger");
sWhatsThis = "Std_MacroAttachDebugger";
sStatusTip = QT_TR_NOOP("Attach to a remotely running debugger");
eType = 0;
}
void StdCmdMacroAttachDebugger::activated(int iMsg)
{
Q_UNUSED(iMsg);
doCommand(Gui, "from freecad.gui import RemoteDebugger\n"
"RemoteDebugger.attachToRemoteDebugger()");
}
bool StdCmdMacroAttachDebugger::isActive(void)
{
return true;
}
DEF_STD_CMD_A(StdCmdMacroStartDebug)
StdCmdMacroStartDebug::StdCmdMacroStartDebug()
@@ -297,6 +322,7 @@ void CreateMacroCommands(void)
rcCmdMgr.addCommand(new StdCmdMacroStopRecord());
rcCmdMgr.addCommand(new StdCmdDlgMacroExecute());
rcCmdMgr.addCommand(new StdCmdDlgMacroExecuteDirect());
rcCmdMgr.addCommand(new StdCmdMacroAttachDebugger());
rcCmdMgr.addCommand(new StdCmdMacroStartDebug());
rcCmdMgr.addCommand(new StdCmdMacroStopDebug());
rcCmdMgr.addCommand(new StdCmdMacroStepOver());

69
src/Gui/RemoteDebugger.py Normal file
View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
#/******************************************************************************
# * Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This library is free software; you can redistribute it and/or *
# * modify it under the terms of the GNU Library General Public *
# * License as published by the Free Software Foundation; either *
# * version 2 of the License, or (at your option) any later version. *
# * *
# * This library is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this library; see the file COPYING.LIB. If not, *
# * write to the Free Software Foundation, Inc., 59 Temple Place, *
# * Suite 330, Boston, MA 02111-1307, USA *
# * *
# ******************************************************************************/
import FreeCAD as App
import FreeCADGui as Gui
from PySide import QtCore
from PySide import QtGui
class RemoteDebugger():
def __init__(self, parent=None):
ui = App.getHomePath() + "Ext/freecad/gui/RemoteDebugger.ui"
self.dialog = Gui.PySideUic.loadUi(ui)
self.dialog.buttonBox.accepted.connect(self.accept)
self.dialog.buttonBox.rejected.connect(self.reject)
def accept(self):
try:
index = self.dialog.tabWidget.currentIndex()
if index == 0: # winpdb
passwd = self.dialog.lineEditPassword.text()
import rpdb2
rpdb2.start_embedded_debugger(passwd, timeout = 30)
elif index == 1: # VS code
address = self.dialog.lineEditAddress.text()
port = self.dialog.spinBoxPort.value()
redirect = self.dialog.checkRedirectOutput.isChecked()
import ptvsd
ptvsd.enable_attach(address=(address, port), redirect_output=redirect)
ptvsd.wait_for_attach()
except Exception as e:
QtGui.QMessageBox.warning(self.dialog, "Failed to attach", str(e))
self.dialog.accept()
def reject(self):
self.dialog.reject()
def exec_(self):
self.dialog.exec_()
def attachToRemoteDebugger():
dlg = RemoteDebugger(Gui.getMainWindow())
dlg.exec_()

166
src/Gui/RemoteDebugger.ui Normal file
View File

@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::Dialog::RemoteDebugger</class>
<widget class="QDialog" name="Gui::Dialog::RemoteDebugger">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>287</height>
</rect>
</property>
<property name="windowTitle">
<string>Attach to remote debugger</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabWinpdb">
<attribute name="title">
<string>winpdb</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelPassword">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>155</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabVSCode">
<attribute name="title">
<string>VS Code</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="labelAddress">
<property name="text">
<string>Address:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditAddress">
<property name="text">
<string notr="true">localhost</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelPort">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxPort">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>5678</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkRedirectOutput">
<property name="text">
<string>Redirect output</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>94</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Gui::Dialog::RemoteDebugger</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Gui::Dialog::RemoteDebugger</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -611,9 +611,16 @@ MenuItem* StdWorkbench::setupMenuBar() const
// Macro
MenuItem* macro = new MenuItem( menuBar );
macro->setCommand("&Macro");
*macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute"
<< "Separator" << "Std_DlgMacroExecuteDirect" << "Std_MacroStartDebug"
<< "Std_MacroStopDebug" << "Std_MacroStepOver" << "Std_MacroStepInto"
*macro << "Std_DlgMacroRecord"
<< "Std_MacroStopRecord"
<< "Std_DlgMacroExecute"
<< "Separator"
<< "Std_DlgMacroExecuteDirect"
<< "Std_MacroAttachDebugger"
<< "Std_MacroStartDebug"
<< "Std_MacroStopDebug"
<< "Std_MacroStepOver"
<< "Std_MacroStepInto"
<< "Std_ToggleBreakpoint";
// Windows