+ support of exclusive Python command groups

This commit is contained in:
wmayer
2015-09-02 22:52:04 +02:00
parent c5a2d7dea1
commit eb4040d6d0
3 changed files with 43 additions and 2 deletions

View File

@@ -225,7 +225,7 @@ bool BitmapFactoryInst::loadPixmap(const QString& filename, QPixmap& icon) const
QPixmap BitmapFactoryInst::pixmap(const char* name) const
{
if (!name || *name == '\0')
return QPixmap(px);
return QPixmap();
// as very first test check whether the pixmap is in the cache
QMap<std::string, QPixmap>::ConstIterator it = d->xpmCache.find(name);

View File

@@ -1094,7 +1094,8 @@ bool PythonGroupCommand::isActive(void)
Action * PythonGroupCommand::createAction(void)
{
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true);
pcAction->setDropDownMenu(hasDropDownMenu());
pcAction->setExclusive(isExclusive());
applyCommandData(this->getName(), pcAction);
@@ -1103,6 +1104,7 @@ Action * PythonGroupCommand::createAction(void)
try {
Base::PyGILStateLocker lock;
Py::Object cmd(_pcPyCommand);
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
Py::Callable call(cmd.getAttr("GetCommands"));
Py::Tuple args;
@@ -1111,6 +1113,11 @@ Action * PythonGroupCommand::createAction(void)
Py::String str(*it);
QAction* cmd = pcAction->addAction(QString());
cmd->setProperty("CommandName", QByteArray(static_cast<std::string>(str).c_str()));
PythonCommand* pycmd = dynamic_cast<PythonCommand*>(rcCmdMgr.getCommandByName(cmd->property("CommandName").toByteArray()));
if (pycmd) {
cmd->setCheckable(pycmd->isCheckable());
}
}
if (cmd.hasAttr("GetDefaultCommand")) {
@@ -1229,6 +1236,38 @@ const char* PythonGroupCommand::getAccel() const
return getResource("Accel");
}
bool PythonGroupCommand::isExclusive() const
{
PyObject* item = PyDict_GetItemString(_pcPyResource,"Exclusive");
if (!item) {
return false;
}
if (PyBool_Check(item)) {
return PyObject_IsTrue(item) ? true : false;
}
else {
throw Base::Exception("PythonGroupCommand::isExclusive(): Method GetResources() of the Python "
"command object contains the key 'Exclusive' which is not a boolean");
}
}
bool PythonGroupCommand::hasDropDownMenu() const
{
PyObject* item = PyDict_GetItemString(_pcPyResource,"DropDownMenu");
if (!item) {
return true;
}
if (PyBool_Check(item)) {
return PyObject_IsTrue(item) ? true : false;
}
else {
throw Base::Exception("PythonGroupCommand::hasDropDownMenu(): Method GetResources() of the Python "
"command object contains the key 'DropDownMenu' which is not a boolean");
}
}
//===========================================================================
// CommandManager
//===========================================================================

View File

@@ -402,6 +402,8 @@ public:
const char* getStatusTip () const;
const char* getPixmap () const;
const char* getAccel () const;
bool isExclusive () const;
bool hasDropDownMenu () const;
//@}
protected: