| 307 | // ------------------------------------------------------------------ |
| 308 | |
| 309 | TaskWatcherPython::TaskWatcherPython(const Py::Object& o) |
| 310 | : TaskWatcher(nullptr) |
| 311 | , watcher(o) |
| 312 | { |
| 313 | QString title; |
| 314 | if (watcher.hasAttr(std::string("title"))) { |
| 315 | Py::String name(watcher.getAttr(std::string("title"))); |
| 316 | std::string s = static_cast<std::string>(name); |
| 317 | title = QString::fromUtf8(s.c_str()); |
| 318 | } |
| 319 | |
| 320 | QPixmap icon; |
| 321 | if (watcher.hasAttr(std::string("icon"))) { |
| 322 | Py::String name(watcher.getAttr(std::string("icon"))); |
| 323 | std::string s = static_cast<std::string>(name); |
| 324 | icon = BitmapFactory().pixmap(s.c_str()); |
| 325 | } |
| 326 | |
| 327 | Gui::TaskView::TaskBox* tb = nullptr; |
| 328 | if (watcher.hasAttr(std::string("commands"))) { |
| 329 | tb = new Gui::TaskView::TaskBox(icon, title, true, nullptr); |
| 330 | Py::Sequence cmds(watcher.getAttr(std::string("commands"))); |
| 331 | CommandManager& mgr = Gui::Application::Instance->commandManager(); |
| 332 | for (Py::Sequence::iterator it = cmds.begin(); it != cmds.end(); ++it) { |
| 333 | Py::String name(*it); |
| 334 | std::string s = static_cast<std::string>(name); |
| 335 | Command* c = mgr.getCommandByName(s.c_str()); |
| 336 | if (c) { |
| 337 | c->addTo(tb); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (watcher.hasAttr(std::string("widgets"))) { |
| 343 | if (!tb && !title.isEmpty()) { |
| 344 | tb = new Gui::TaskView::TaskBox(icon, title, true, nullptr); |
| 345 | } |
| 346 | Py::Sequence list(watcher.getAttr(std::string("widgets"))); |
| 347 | |
| 348 | Gui::PythonWrapper wrap; |
| 349 | if (wrap.loadCoreModule()) { |
| 350 | for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { |
| 351 | QObject* object = wrap.toQObject(*it); |
| 352 | if (object) { |
| 353 | QWidget* w = qobject_cast<QWidget*>(object); |
| 354 | if (w) { |
| 355 | if (tb) { |
| 356 | tb->groupLayout()->addWidget(w); |
| 357 | } |
| 358 | else { |
| 359 | Content.push_back(w); |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 |
nothing calls this directly
no test coverage detected