Permalink
Browse files

Added the ability to *hack* in a richcompare implementation in CPytho…

…n and implemented it on Action for BW compatibility.
  • Loading branch information...
1 parent 3696fca commit 0bd9efbba2aa429a31a225cb439cada1f6280990 Jim Carroll committed Sep 14, 2012
Showing with 50 additions and 2 deletions.
  1. +13 −2 xbmc/interfaces/python/PythonSwig.cpp.template
  2. +37 −0 xbmc/interfaces/swig/AddonModuleXbmcgui.i
@@ -294,12 +294,19 @@ void doClassMethodInfo(Node clazz, List initTypeCalls = null)
if (doComparator){
%>
- int ${classNameAsVariable}_cmp(PyObject* obj1, PyObject* obj2)
+ static int ${module.@name}_${classNameAsVariable}_cmp(PyObject* obj1, PyObject* obj2)
{
return PythonCompare<${fullClassName}>::compare(obj1,obj2,"p.${fullClassName}","${Helper.findNamespace(clazz)}","compare on ${fullClassName}");
}
<%
}
+
+ if (clazz.@feature_python_rcmp)
+ { %>
+ static PyObject* ${module.@name}_${classNameAsVariable}_rcmp(PyObject* obj1, PyObject *obj2, int method)
+ ${Helper.unescape(clazz.@feature_python_rcmp)}
+<%
+ }
%>
//=========================================================================
// This section contains the initialization for the
@@ -341,8 +348,12 @@ void doClassMethodInfo(Node clazz, List initTypeCalls = null)
Py${classNameAsVariable}_Type.tp_basicsize = sizeof(PyHolder);
Py${classNameAsVariable}_Type.tp_dealloc = (destructor)${module.@name}_${classNameAsVariable}_Dealloc; <%
if (doComparator) { %>
- Py${classNameAsVariable}_Type.tp_compare=${classNameAsVariable}_cmp;<%
+ Py${classNameAsVariable}_Type.tp_compare=${module.@name}_${classNameAsVariable}_cmp;<%
+ }
+ if (clazz.@feature_python_rcmp) { %>
+ Py${classNameAsVariable}_Type.tp_richcompare=(richcmpfunc)${module.@name}_${classNameAsVariable}_rcmp;<%
} %>
+
Py${classNameAsVariable}_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
Py${classNameAsVariable}_Type.tp_doc = ${Helper.hasDoc(clazz) ? (classNameAsVariable + '__doc__') : 'NULL' };
Py${classNameAsVariable}_Type.tp_methods = ${classNameAsVariable}_methods;
@@ -69,6 +69,43 @@ using namespace xbmcgui;
%feature("director") WindowXML;
%feature("director") WindowXMLDialog;
+// This is such a damn hack it makes me nauseous
+%feature("python:rcmp") XBMCAddon::xbmcgui::Action
+ { TRACE;
+ if (method == Py_EQ)
+ {
+ XBMCAddon::xbmcgui::Action* a1 = (Action*)retrieveApiInstance(obj1,&PyXBMCAddon_xbmcgui_Action_Type,"rcmp","XBMCAddon::xbmcgui::Action");
+ if (PyObject_TypeCheck(obj2, &PyXBMCAddon_xbmcgui_Action_Type))
+ {
+ // both are Action objects
+ XBMCAddon::xbmcgui::Action* a2 = (Action*)retrieveApiInstance(obj2,&PyXBMCAddon_xbmcgui_Action_Type,"rcmp","XBMCAddon::xbmcgui::Action");
+
+ if (a1->id == a2->id &&
+ a1->buttonCode == a2->buttonCode &&
+ a1->fAmount1 == a2->fAmount1 &&
+ a1->fAmount2 == a2->fAmount2 &&
+ a1->fRepeat == a2->fRepeat &&
+ a1->strAction == a2->strAction)
+ {
+ Py_RETURN_TRUE;
+ }
+ else
+ {
+ Py_RETURN_FALSE;
+ }
+ }
+ else
+ {
+ // for backwards compatability in python scripts
+ PyObject* o1 = PyLong_FromLong(a1->id);
+ return PyObject_RichCompare(o1, obj2, method);
+ }
+ }
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+
%include "interfaces/legacy/Window.h"
%include "interfaces/legacy/WindowDialog.h"
%include "interfaces/legacy/Dialog.h"

0 comments on commit 0bd9efb

Please sign in to comment.