MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / TaskWatcherPython

Method TaskWatcherPython

src/Gui/TaskView/TaskDialogPython.cpp:309–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307// ------------------------------------------------------------------
308
309TaskWatcherPython::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

Callers

nothing calls this directly

Calls 13

pixmapMethod · 0.80
getCommandByNameMethod · 0.80
loadCoreModuleMethod · 0.80
toQObjectMethod · 0.80
c_strMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
addToMethod · 0.45
isEmptyMethod · 0.45
addWidgetMethod · 0.45
groupLayoutMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected