Commit eff50232 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo
Browse files

* Read string array results from python methods~

parent c051c1a4
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -204,8 +204,9 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) );
     */
     */
    frame->SetFocus();
    frame->SetFocus();
    frame->GetCanvas()->SetFocus();
    frame->GetCanvas()->SetFocus();
    
#if 0
    DIALOG_SCRIPTING* sw = new DIALOG_SCRIPTING(frame);
    DIALOG_SCRIPTING* sw = new DIALOG_SCRIPTING(frame);
    sw->Show(true);
    sw->Show(true);
#endif
    return true;
    return true;
}
}
+39 −20
Original line number Original line Diff line number Diff line
@@ -59,6 +59,8 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod(const char* aMethod, PyObject *aAr
wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod(const char* aMethod, PyObject *aArglist)
wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod(const char* aMethod, PyObject *aArglist)
{
{
    wxString ret;
    wxString ret;
    
    ret.Clear();
    PyObject *result = CallMethod(aMethod,aArglist);
    PyObject *result = CallMethod(aMethod,aArglist);
    if (result)
    if (result)
    {
    {
@@ -66,17 +68,44 @@ wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod(const char* aMethod, PyObject
         ret  = wxString::FromUTF8(str_res);
         ret  = wxString::FromUTF8(str_res);
         Py_DECREF(result);    
         Py_DECREF(result);    
    }
    }
    else
    {
        printf("method not found, or not callable: %s\n",aMethod);
    }
    
    return ret;
    return ret;
}
}


wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod
wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod
                        (const char *aMethod, PyObject *aArglist)
                        (const char *aMethod, PyObject *aArglist)
{
{
    PyObject *result, *element;
    wxArrayString ret;
    wxString str_item;
    
    result = CallMethod(aMethod,aArglist);
    
    if (result)
    {
         if (!PyList_Check(result))
         {
             Py_DECREF(result);
             ret.Add(wxT("PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, "
                        "result is not a list"),1);
             return ret;
         }
         int list_size = PyList_Size(result);
         
         for (int n=0;n<list_size;n++)
         {
            element = PyList_GetItem(result,n);

            const char *str_res = PyString_AsString(element);
            str_item  = wxString::FromUTF8(str_res);
            ret.Add(str_item,1);
         }
         
         Py_DECREF(result);    
    }
    
    
    
    return ret;
   
   
}
}


@@ -134,25 +163,15 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName(int aPage)


wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames(int aPage)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames(int aPage)
{
{
    wxArrayString a;
  
     wxString ret;
    PyObject *arglist;
    PyObject *arglist;
    PyObject *result;
    wxArrayString ret;
    
    
    /* Time to call the callback */
    arglist = Py_BuildValue("(i)", aPage);
    arglist = Py_BuildValue("(i)", aPage);
    result = CallMethod("GetParameterPageNames",arglist);
    ret = CallRetArrayStrMethod("GetParameterNames",arglist);
    Py_DECREF(arglist);
    Py_DECREF(arglist);
    
    
    if (result)
    return ret;
    {
        
        // TODO GET ITEMS IN LIST
         const char *str_res = PyString_AsString(result);
         ret  = wxString::FromUTF8(str_res);
         Py_DECREF(result);    
    }
    return a;
}
}


wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues(int aPage)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues(int aPage)