Skip to content

Commit

Permalink
Merge pull request #6340 from The-OpenROAD-Project-staging/gui-set_title
Browse files Browse the repository at this point in the history
gui: Add option to set title from Tcl
  • Loading branch information
maliberty authored Dec 17, 2024
2 parents ed2a2be + 9a93986 commit 4d86b92
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/gui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ gui::show
| `script` | TCL script to evaluate in the GUI. |
| `interactive` | Boolean if true, the GUI should open in an interactive session (default), or if false that the GUI would execute the script and return to the terminal.|

### Set GUI Title

To set the title of the main GUI window:

```tcl
gui::set_title title
```

#### Options

| Switch Name | Description |
| ---- | ---- |
| `title` | window title to use for the main GUI window |

### Hide GUI

To close the GUI and return to the command-line:
Expand Down
5 changes: 5 additions & 0 deletions src/gui/include/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ class Gui
const std::string& option);
void dumpHeatMap(const std::string& name, const std::string& file);

void setMainWindowTitle(const std::string& title);
std::string getMainWindowTitle();

void selectHelp(const std::string& item);
void selectChart(const std::string& name);
void updateTimingReport();
Expand Down Expand Up @@ -814,6 +817,8 @@ class Gui
std::unique_ptr<PlacementDensityDataSource> placement_density_heat_map_;

static Gui* singleton_;

std::string main_window_title_ = "OpenROAD";
};

// The main entry point
Expand Down
14 changes: 14 additions & 0 deletions src/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,19 @@ void Gui::dumpHeatMap(const std::string& name, const std::string& file)
source->dumpToFile(file);
}

void Gui::setMainWindowTitle(const std::string& title)
{
main_window_title_ = title;
if (main_window) {
main_window->setTitle(title);
}
}

std::string Gui::getMainWindowTitle()
{
return main_window_title_;
}

Renderer::~Renderer()
{
gui::Gui::get()->unregisterRenderer(this);
Expand Down Expand Up @@ -1372,6 +1385,7 @@ int startGui(int& argc,
if (minimize) {
main_window->showMinimized();
}
main_window->setTitle(gui->getMainWindowTitle());

open_road->addObserver(main_window);
if (!interactive) {
Expand Down
7 changes: 7 additions & 0 deletions src/gui/src/gui.i
Original file line number Diff line number Diff line change
Expand Up @@ -767,4 +767,11 @@ void update_timing_report()
auto gui = gui::Gui::get();
gui->updateTimingReport();
}

void set_title(std::string title)
{
auto gui = gui::Gui::get();
gui->setMainWindowTitle(title);
}

%} // inline
28 changes: 22 additions & 6 deletions src/gui/src/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,9 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
settings.endGroup();
}

// load resources and set window icon and title
// load resources and set window icon
loadQTResources();
setWindowIcon(QIcon(":/icon.png"));
setWindowTitle(window_title_);

Descriptor::Property::convert_dbu
= [this](int value, bool add_units) -> std::string {
Expand Down Expand Up @@ -449,13 +448,30 @@ void MainWindow::setDatabase(odb::dbDatabase* db)
db_ = db;
}

void MainWindow::setTitle(const std::string& title)
{
window_title_ = title;
updateTitle();
}

void MainWindow::updateTitle()
{
if (!window_title_.empty()) {
odb::dbBlock* block = getBlock();
if (block != nullptr) {
const std::string title
= fmt::format("{} - {}", window_title_, block->getName());
setWindowTitle(QString::fromStdString(title));
} else {
setWindowTitle(QString::fromStdString(window_title_));
}
}
}

void MainWindow::setBlock(odb::dbBlock* block)
{
updateTitle();
if (block != nullptr) {
const std::string title
= fmt::format("{} - {}", window_title_, block->getName());
setWindowTitle(QString::fromStdString(title));

save_->setEnabled(true);
}
for (auto* heat_map : Gui::get()->getHeatMaps()) {
Expand Down
8 changes: 6 additions & 2 deletions src/gui/src/mainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class MainWindow : public QMainWindow, public ord::OpenRoadObserver

std::vector<std::string> getRestoreTclCommands();

void setTitle(const std::string& title);

signals:
// Signaled when we get a postRead callback to tell the sub-widgets
// to update
Expand Down Expand Up @@ -300,6 +302,8 @@ class MainWindow : public QMainWindow, public ord::OpenRoadObserver
std::string convertDBUToString(int value, bool add_units) const;
int convertStringToDBU(const std::string& value, bool* ok) const;

void updateTitle();

odb::dbDatabase* db_;
utl::Logger* logger_;
SelectionSet selected_;
Expand All @@ -325,6 +329,8 @@ class MainWindow : public QMainWindow, public ord::OpenRoadObserver
FindObjectDialog* find_dialog_;
GotoLocationDialog* goto_dialog_;

std::string window_title_;

QMenu* file_menu_;
QMenu* view_menu_;
QMenu* tools_menu_;
Expand Down Expand Up @@ -366,8 +372,6 @@ class MainWindow : public QMainWindow, public ord::OpenRoadObserver

// heat map actions
std::map<HeatMapDataSource*, QAction*> heatmap_actions_;

static constexpr const char* window_title_ = "OpenROAD";
};

} // namespace gui

0 comments on commit 4d86b92

Please sign in to comment.