Skip to content

Commit 8010ea5

Browse files
committed
gui: initial support to open GUI with python
Signed-off-by: Peter Gadfort <[email protected]>
1 parent eee505c commit 8010ea5

File tree

10 files changed

+538
-49
lines changed

10 files changed

+538
-49
lines changed

include/ord/OpenRoad.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,6 @@ class OpenRoad
283283
};
284284

285285
int tclAppInit(Tcl_Interp* interp);
286+
void pyAppInit();
286287

287288
} // namespace ord

src/Main.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int main(int argc, char* argv[])
249249

250250
utl::Logger* logger = ord::OpenRoad::openRoad()->getLogger();
251251
if (findCmdLineFlag(cmd_argc, cmd_argv, "-gui")) {
252-
logger->warn(utl::ORD, 38, "-gui is not yet supported with -python");
252+
gui::startGui(cmd_argc, cmd_argv, gui::Interpreter::Python, interp);
253253
}
254254

255255
if (!findCmdLineFlag(cmd_argc, cmd_argv, "-no_init")) {
@@ -265,7 +265,7 @@ int main(int argc, char* argv[])
265265
ord::OpenRoad::openRoad()->getThreadCount(), false);
266266
}
267267

268-
initPython();
268+
ord::pyAppInit();
269269
bool exit = findCmdLineFlag(cmd_argc, cmd_argv, "-exit");
270270
std::vector<wchar_t*> args;
271271
args.push_back(Py_DecodeLocale(cmd_argv[0], nullptr));
@@ -285,6 +285,11 @@ int main(int argc, char* argv[])
285285
return 0;
286286
}
287287

288+
void ord::pyAppInit()
289+
{
290+
initPython();
291+
}
292+
288293
#ifdef ENABLE_READLINE
289294
static int tclReadlineInit(Tcl_Interp* interp)
290295
{
@@ -321,7 +326,7 @@ static int tclAppInit(int& argc,
321326
while (findCmdLineFlag(argc, argv, "-gui"))
322327
;
323328

324-
gui::startGui(argc, argv, interp);
329+
gui::startGui(argc, argv, gui::Interpreter::Tcl, interp);
325330
} else {
326331
// init tcl
327332
if (Tcl_Init(interp) == TCL_ERROR) {

src/gui/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if (Qt5_FOUND AND BUILD_GUI)
3232
src/mainWindow.cpp
3333
src/scriptWidget.cpp
3434
src/cmdInputWidget.cpp
35+
src/pythonCmdInputWidget.cpp
3536
src/tclCmdInputWidget.cpp
3637
src/tclCmdHighlighter.cpp
3738
src/displayControls.cpp
@@ -72,6 +73,14 @@ messages(
7273
TARGET gui
7374
)
7475

76+
if (Python3_FOUND AND BUILD_PYTHON)
77+
target_include_directories(gui
78+
PRIVATE
79+
${Python3_INCLUDE_DIRS}
80+
)
81+
target_compile_definitions(gui PRIVATE ENABLE_PYTHON3)
82+
endif()
83+
7584
else()
7685
message(STATUS "GUI is not enabled")
7786
add_library(gui

src/gui/include/gui/gui.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class Painter;
6161
class Selected;
6262
class Options;
6363

64+
enum class Interpreter
65+
{
66+
Tcl,
67+
Python
68+
};
69+
6470
// A collection of selected objects
6571
using SelectionSet = std::set<Selected>;
6672
using HighlightSet = std::array<SelectionSet, 8>; // Only 8 Discrete Highlight
@@ -684,7 +690,9 @@ class Gui
684690
void hideGui();
685691

686692
// Called to show the gui and return to tcl command line
687-
void showGui(const std::string& cmds = "", bool interactive = true);
693+
void showGui(Interpreter interpreter,
694+
const std::string& cmds = "",
695+
bool interactive = true);
688696

689697
// set the system logger
690698
void setLogger(utl::Logger* logger);
@@ -781,6 +789,7 @@ class Gui
781789
// The main entry point
782790
int startGui(int& argc,
783791
char* argv[],
792+
Interpreter interpreter,
784793
Tcl_Interp* interp,
785794
const std::string& script = "",
786795
bool interactive = true);

src/gui/src/gui.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ void Gui::saveImage(const std::string& filename,
666666
save_cmds += "unset ::gui::display_settings\n";
667667
// end with hide to return
668668
save_cmds += "gui::hide";
669-
showGui(save_cmds, false);
669+
showGui(Interpreter::Tcl, save_cmds, false);
670670
} else {
671-
// save current display settings and apply new
671+
// save current displexitingay settings and apply new
672672
main_window->getControls()->save();
673673
for (const auto& [control, value] : display_settings) {
674674
setDisplayControlsVisible(control, value);
@@ -1071,7 +1071,9 @@ void Gui::hideGui()
10711071
main_window->exit();
10721072
}
10731073

1074-
void Gui::showGui(const std::string& cmds, bool interactive)
1074+
void Gui::showGui(Interpreter interpreter,
1075+
const std::string& cmds,
1076+
bool interactive)
10751077
{
10761078
if (enabled()) {
10771079
logger_->warn(utl::GUI, 8, "GUI already active.");
@@ -1082,7 +1084,7 @@ void Gui::showGui(const std::string& cmds, bool interactive)
10821084
// passing in cmd_argc and cmd_argv to meet Qt application requirement for
10831085
// arguments nullptr for tcl interp to indicate nothing to setup and commands
10841086
// and interactive setting
1085-
startGui(cmd_argc, cmd_argv, nullptr, cmds, interactive);
1087+
startGui(cmd_argc, cmd_argv, interpreter, nullptr, cmds, interactive);
10861088
}
10871089

10881090
void Gui::init(odb::dbDatabase* db, utl::Logger* logger)
@@ -1102,6 +1104,7 @@ void Gui::init(odb::dbDatabase* db, utl::Logger* logger)
11021104
// returns when the GUI is done.
11031105
int startGui(int& argc,
11041106
char* argv[],
1107+
Interpreter interpreter,
11051108
Tcl_Interp* interp,
11061109
const std::string& script,
11071110
bool interactive)
@@ -1139,15 +1142,26 @@ int startGui(int& argc,
11391142
interp = open_road->tclInterp();
11401143
}
11411144

1142-
// pass in tcl interp to script widget and ensure OpenRoad gets initialized
1143-
main_window->getScriptWidget()->setupTcl(
1144-
interp, interactive, init_openroad, [&]() {
1145-
// init remainder of GUI, to be called immediately after OpenRoad is
1146-
// guaranteed to be initialized.
1147-
main_window->init(open_road->getSta());
1148-
// announce design created to ensure GUI gets setup
1149-
main_window->postReadDb(main_window->getDb());
1150-
});
1145+
auto post_or_init = [&]() {
1146+
// init remainder of GUI, to be called immediately after OpenRoad is
1147+
// guaranteed to be initialized.
1148+
main_window->init(open_road->getSta());
1149+
// announce design created to ensure GUI gets setup
1150+
main_window->postReadDb(main_window->getDb());
1151+
};
1152+
1153+
switch (interpreter) {
1154+
case Interpreter::Tcl:
1155+
// pass in tcl interp to script widget and ensure OpenRoad gets
1156+
// initialized
1157+
main_window->getScriptWidget()->setupTcl(
1158+
interp, interactive, init_openroad, post_or_init);
1159+
break;
1160+
case Interpreter::Python:
1161+
// init python in script widget and ensure OpenRoad gets initialized
1162+
main_window->getScriptWidget()->setupPython(post_or_init);
1163+
break;
1164+
}
11511165

11521166
// Exit the app if someone chooses exit from the menu in the window
11531167
QObject::connect(main_window, SIGNAL(exit()), &app, SLOT(quit()));

src/gui/src/gui.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ void hide_widget(const char* name)
472472
void show(const char* script = "", bool interactive = true)
473473
{
474474
auto gui = gui::Gui::get();
475-
gui->showGui(script, interactive);
475+
gui->showGui(gui::Interpreter::Tcl, script, interactive);
476476
}
477477

478478
void hide()

0 commit comments

Comments
 (0)