Пример #1
0
  PyObject* ControlTextBox_SetText(ControlTextBox *self, PyObject *args)
  {
    PyObject *pObjectText;
    string strText;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText)) return NULL;
    if (!PyXBMCGetUnicodeString(strText, pObjectText, 1)) return NULL;

    // create message
    ControlTextBox *pControl = (ControlTextBox*)self;
    CGUIMessage msg(GUI_MSG_LABEL_SET, pControl->iParentId, pControl->iControlId);
    msg.SetLabel(strText);

    // send message
    g_windowManager.SendThreadMessage(msg, pControl->iParentId);
    Py_INCREF(Py_None);
    return Py_None;
  }
Пример #2
0
  PyObject* ControlFadeLabel_AddLabel(ControlFadeLabel *self, PyObject *args)
  {
    PyObject *pObjectText;
    string strText;

    if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText))   return NULL;
    if (!PyXBMCGetUnicodeString(strText, pObjectText, 1)) return NULL;

    ControlFadeLabel *pControl = (ControlFadeLabel*)self;
    CGUIMessage msg(GUI_MSG_LABEL_ADD, pControl->iParentId, pControl->iControlId);
    msg.SetLabel(strText);

    g_windowManager.SendThreadMessage(msg, pControl->iParentId);

    Py_INCREF(Py_None);
    return Py_None;
  }
Пример #3
0
  int PyXBMCGetUnicodeString(std::string& buf, PyObject* pObject, bool coerceToString,
                             const char* argumentName, const char* methodname)
  {
    // TODO: UTF-8: Does python use UTF-16?
    //              Do we need to convert from the string charset to UTF-8
    //              for non-unicode data?
    if (PyUnicode_Check(pObject))
    {
      // Python unicode objects are UCS2 or UCS4 depending on compilation
      // options, wchar_t is 16-bit or 32-bit depending on platform.
      // Avoid the complexity by just letting python convert the string.
      PyObject *utf8_pyString = PyUnicode_AsUTF8String(pObject);

      if (utf8_pyString)
      {
        buf = PyString_AsString(utf8_pyString);
        Py_DECREF(utf8_pyString);
        return 1;
      }
    }
    if (PyString_Check(pObject))
    {
      buf = PyString_AsString(pObject);
      return 1;
    }

    // if we got here then we need to coerce the value to a string
    if (coerceToString)
    {
      PyObject* pyStrCast = PyObject_Str(pObject);
      if (pyStrCast)
      {
        int ret = PyXBMCGetUnicodeString(buf,pyStrCast,false,argumentName,methodname);
        Py_DECREF(pyStrCast);
        return ret;
      }
    }

    // Object is not a unicode or a normal string.
    buf = "";
    PyErr_Format(PyExc_TypeError, "argument \"%s\" for method \"%s\" must be unicode or str", argumentName, methodname);
    return 0;
  }
Пример #4
0
  PyObject* ControlCheckMark_SetLabel(ControlCheckMark *self, PyObject *args)
  {
    PyObject *pObjectText;
    char *cFont = NULL;
    char *cTextColor = NULL;
    char* cDisabledColor = NULL;

    if (!PyArg_ParseTuple(
      args, (char*)"O|sss",
      &pObjectText, &cFont,
      &cTextColor,  &cDisabledColor))
      return NULL;

    if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 1))
      return NULL;

    if (cFont) self->strFont = cFont;
    if (cTextColor)
    {
      sscanf(cTextColor, "%x", &self->textColor);
    }
    if (cDisabledColor)
    {
      sscanf(cDisabledColor, "%x", &self->disabledColor);
    }

    PyXBMCGUILock();
    if (self->pGUIControl)
    {
      ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetLabel(
        self->strFont,
        self->strText,
        self->textColor );
      ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetDisabledColor(
        self->disabledColor );
    }
    PyXBMCGUIUnlock();

    Py_INCREF(Py_None);
    return Py_None;
  }
  PyObject* Keyboard_SetHeading(Keyboard *self, PyObject *args)
  {
    PyObject *line = NULL;
    if (!PyArg_ParseTuple(args, (char*)"|O", &line)) return NULL;

    string utf8Line;
    if (line && !PyXBMCGetUnicodeString(utf8Line, line, 1)) return NULL;
    self->strHeading = utf8Line;

    CGUIDialogKeyboard *pKeyboard = (CGUIDialogKeyboard*)g_windowManager.GetWindow(WINDOW_DIALOG_KEYBOARD);
    if(!pKeyboard)
    {
      PyErr_SetString(PyExc_SystemError, "Unable to load keyboard");
      return NULL;
    }

    pKeyboard->SetHeading(self->strHeading);

    Py_INCREF(Py_None);
    return Py_None;
  }
Пример #6
0
 // delete a file
 PyObject* vfs_delete(File *self, PyObject *args, PyObject *kwds)
 {
   PyObject *f_line;
   if (!PyArg_ParseTuple(
     args,
     (char*)"O",
     &f_line))
   {
     return NULL;
   }
   CStdString strSource;
   if (!PyXBMCGetUnicodeString(strSource, f_line, 1)) return NULL;
   
   CPyThreadState pyState;
   self->pFile->Delete(strSource);
   pyState.Restore();
   
   Py_INCREF(Py_None);
   return Py_None;
   
 }
Пример #7
0
    // check for a file or folder existance, mimics Pythons os.path.exists()
    PyObject* vfs_exists(File *self, PyObject *args, PyObject *kwds)
    {
      PyObject *f_line;
      if (!PyArg_ParseTuple(
        args,
        (char*)"O",
        &f_line))
      {
        return NULL;
      }
      CStdString strSource;
      if (!PyXBMCGetUnicodeString(strSource, f_line, 1)) return NULL;
     
      bool bResult;
     
      CPyThreadState pyState;
      bResult = self->pFile->Exists(strSource, false);
      pyState.Restore();

      return Py_BuildValue((char*)"b", bResult);
    }      
Пример #8
0
  PyObject* XBMC_subHashAndFileSize(PyObject *self, PyObject *args, PyObject *kwds)
  {
    PyObject *f_line;
    if (!PyArg_ParseTuple(
      args,
      (char*)"O",
      &f_line))
    {
      return NULL;
    }
    CStdString strSource;
    if (!PyXBMCGetUnicodeString(strSource, f_line, 1)) return NULL;
    
    CStdString strSize;
    CStdString strHash;

    CPyThreadState pyState;
    CFileUtils::SubtitleFileSizeAndHash(strSource, strSize, strHash);
    pyState.Restore();
    
    return Py_BuildValue((char*)"ss",strSize.c_str(), strHash.c_str());
  } 
Пример #9
0
  PyObject* Keyboard_SetHeading(Keyboard *self, PyObject *args)
  {
    PyObject *line = NULL;
    if (!PyArg_ParseTuple(args, (char*)"|O", &line)) return NULL;

    string utf8Line;
    if (line && !PyXBMCGetUnicodeString(utf8Line, line, 1)) return NULL;
    self->strHeading = utf8Line;

    CGUIDialogKeyboard *pKeyboard = ((Keyboard*)self)->dlg;
    if(!pKeyboard)
    {
      PyErr_SetString(PyExc_SystemError, "Unable to load keyboard");
      return NULL;
    }

    PyXBMCGUILock();
    pKeyboard->SetHeading(self->strHeading);
    PyXBMCGUIUnlock();

    Py_INCREF(Py_None);
    return Py_None;
  }
  PyObject* ControlList_AddItem(ControlList *self, PyObject *args)
  {
    PyObject *pObject;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObject))  return NULL;

    ListItem* pListItem = NULL;
    if (ListItem_CheckExact(pObject))
    {
      // object is a listitem
      pListItem = (ListItem*)pObject;
      Py_INCREF(pListItem);
    }
    else
    {
      string strText;
      // object is probably a text item
      if (!PyXBMCGetUnicodeString(strText, pObject, 1)) return NULL;
      // object is a unicode string now, create a new ListItem
      pListItem = ListItem_FromString(strText);
    }

    // add item to objects vector
    self->vecItems.push_back(pListItem);

    // construct a CFileItemList to pass 'em on to the list
    CGUIListItemPtr items(new CFileItemList());
    for (unsigned int i = 0; i < self->vecItems.size(); i++)
      ((CFileItemList*)items.get())->Add(self->vecItems[i]->item);

    CGUIMessage msg(GUI_MSG_LABEL_BIND, self->iParentId, self->iControlId, 0, 0, items);
    msg.SetPointer(items.get());
    g_windowManager.SendThreadMessage(msg, self->iParentId);

    Py_INCREF(Py_None);
    return Py_None;
  }
Пример #11
0
  PyObject* WindowXML_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
    WindowXML *self;

    self = (WindowXML*)type->tp_alloc(type, 0);
    if (!self) return NULL;

    new(&self->sXMLFileName) string();
    new(&self->sFallBackPath) string();
    new(&self->vecControls) std::vector<Control*>();

    self->iWindowId = -1;
    PyObject* pyOXMLname = NULL;
    PyObject* pyOname = NULL;
    PyObject* pyDName = NULL;
    PyObject* pyRes = NULL;

    string strXMLname, strFallbackPath;
    string strDefault = "Default";
    string resolution = "720p";

    if (!PyArg_ParseTuple(args, (char*)"OO|OO", &pyOXMLname, &pyOname, &pyDName, &pyRes)) return NULL;

    PyXBMCGetUnicodeString(strXMLname, pyOXMLname);
    PyXBMCGetUnicodeString(strFallbackPath, pyOname);
    if (pyDName) PyXBMCGetUnicodeString(strDefault, pyDName);
    if (pyRes) PyXBMCGetUnicodeString(resolution, pyRes);

    // Check to see if the XML file exists in current skin. If not use fallback path to find a skin for the script
    RESOLUTION_INFO res;
    CStdString strSkinPath = g_SkinInfo->GetSkinPath(strXMLname, &res);

    if (!XFILE::CFile::Exists(strSkinPath))
    {
      // Check for the matching folder for the skin in the fallback skins folder
      CStdString fallbackPath = URIUtils::AddFileToFolder(strFallbackPath, "resources");
      fallbackPath = URIUtils::AddFileToFolder(fallbackPath, "skins");
      CStdString basePath = URIUtils::AddFileToFolder(fallbackPath, g_SkinInfo->ID());
      strSkinPath = g_SkinInfo->GetSkinPath(strXMLname, &res, basePath);
      if (!XFILE::CFile::Exists(strSkinPath))
      {
        // Finally fallback to the DefaultSkin as it didn't exist in either the XBMC Skin folder or the fallback skin folder
        CStdString str("none");
        AddonProps props(str, ADDON_SKIN, "", "");
        props.path = URIUtils::AddFileToFolder(fallbackPath, strDefault);
        CSkinInfo::TranslateResolution(resolution, res);
        CSkinInfo skinInfo(props, res);

        skinInfo.Start();
        strSkinPath = skinInfo.GetSkinPath(strXMLname, &res);
        if (!XFILE::CFile::Exists(strSkinPath))
        {
          PyErr_SetString(PyExc_TypeError, "XML File for Window is missing");
          return NULL;
        }
      }
    }

    self->sFallBackPath = strFallbackPath;
    self->sXMLFileName = strSkinPath;
    self->bUsingXML = true;

    // create new GUIWindow
    if (!Window_CreateNewWindow((Window*)self, false))
    {
      // error is already set by Window_CreateNewWindow, just release the memory
      self->vecControls.clear();
      self->vecControls.~vector();
      self->sFallBackPath.~string();
      self->sXMLFileName.~string();
      self->ob_type->tp_free((PyObject*)self);
      return NULL;
    }
    ((CGUIWindow*)(self->pWindow))->SetCoordsRes(res);
    return (PyObject*)self;
  }
Пример #12
0
  PyObject* ControlLabel_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
    static const char *keywords[] = {
      "x", "y", "width", "height", "label", "font", "textColor",
      "disabledColor", "alignment", "hasPath", "angle", NULL };

    ControlLabel *self;
    char *cFont = NULL;
    char *cTextColor = NULL;
    char *cDisabledColor = NULL;
    PyObject* pObjectText;
    char bHasPath = false;

    self = (ControlLabel*)type->tp_alloc(type, 0);
    if (!self) return NULL;
    new(&self->strText) string();
    new(&self->strFont) string();

    // set up default values in case they are not supplied
    self->strFont = "font13";
    self->textColor = 0xffffffff;
    self->disabledColor = 0x60ffffff;
    self->align = XBFONT_LEFT;
    self->iAngle = 0;

    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"llllO|ssslbl",
      (char**)keywords,
      &self->dwPosX,
      &self->dwPosY,
      &self->dwWidth,
      &self->dwHeight,
      &pObjectText,
      &cFont,
      &cTextColor,
      &cDisabledColor,
      &self->align,
      &bHasPath,
      &self->iAngle))
    {
        Py_DECREF( self );
        return NULL;
    }
    self->bHasPath = (0 != bHasPath);
    if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 5))
    {
      Py_DECREF( self );
      return NULL;
    }

    if (cFont) self->strFont = cFont;
    if (cTextColor) sscanf(cTextColor, "%x", &self->textColor);
    if (cDisabledColor)
    {
      sscanf( cDisabledColor, "%x", &self->disabledColor );
    }

    return (PyObject*)self;
  }
Пример #13
0
  PyObject* ControlButton_New(
    PyTypeObject *type,
    PyObject *args,
    PyObject *kwds )
  {
    static const char *keywords[] = {
      "x", "y", "width", "height", "label",
      "focusTexture", "noFocusTexture",
      "textOffsetX", "textOffsetY", "alignment",
      "font", "textColor", "disabledColor", "angle", "shadowColor", "focusedColor", NULL };
    ControlButton *self;
    char* cFont = NULL;
    char* cTextureFocus = NULL;
    char* cTextureNoFocus = NULL;
    char* cTextColor = NULL;
    char* cDisabledColor = NULL;
    char* cShadowColor = NULL;
    char* cFocusedColor = NULL;

    PyObject* pObjectText;

    self = (ControlButton*)type->tp_alloc(type, 0);
    if (!self) return NULL;
    new(&self->strFont) string();
    new(&self->strText) string();
    new(&self->strText2) string();
    new(&self->strTextureFocus) string();
    new(&self->strTextureNoFocus) string();

    // set up default values in case they are not supplied
    self->textOffsetX = CONTROL_TEXT_OFFSET_X;
    self->textOffsetY = CONTROL_TEXT_OFFSET_Y;
    self->align = (XBFONT_LEFT | XBFONT_CENTER_Y);
    self->strFont = "font13";
    self->textColor = 0xffffffff;
    self->disabledColor = 0x60ffffff;
    self->iAngle = 0;
    self->shadowColor = 0;
    self->focusedColor = 0xffffffff;

    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"llllO|sslllssslss",
      (char**)keywords,
      &self->dwPosX,
      &self->dwPosY,
      &self->dwWidth,
      &self->dwHeight,
      &pObjectText,
      &cTextureFocus,
      &cTextureNoFocus,
      &self->textOffsetX,
      &self->textOffsetY,
      &self->align,
      &cFont,
      &cTextColor,
      &cDisabledColor,
      &self->iAngle,
      &cShadowColor,
      &cFocusedColor))
    {
      Py_DECREF( self );
      return NULL;
    }


    if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 5))
    {
      Py_DECREF( self );
      return NULL;
    }

    // if texture is supplied use it, else get default ones
    self->strTextureFocus = cTextureFocus ?
      cTextureFocus :
      PyXBMCGetDefaultImage((char*)"button", (char*)"texturefocus", (char*)"button-focus.png");
    self->strTextureNoFocus = cTextureNoFocus ?
      cTextureNoFocus :
      PyXBMCGetDefaultImage((char*)"button", (char*)"texturenofocus", (char*)"button-nofocus.jpg");

    if (cFont) self->strFont = cFont;
    if (cTextColor) sscanf( cTextColor, "%x", &self->textColor );
    if (cDisabledColor) sscanf( cDisabledColor, "%x", &self->disabledColor );
    if (cShadowColor) sscanf( cShadowColor, "%x", &self->shadowColor );
    if (cFocusedColor) sscanf( cFocusedColor, "%x", &self->focusedColor );
    return (PyObject*)self;
  }
Пример #14
0
  PyObject* ControlCheckMark_New(PyTypeObject *type, PyObject *args, PyObject *kwds )
  {
    static const char *keywords[] = {
      "x", "y", "width", "height", "label", "focusTexture", "noFocusTexture",
      "checkWidth", "checkHeight", "alignment", "font", "textColor", "disabledColor", NULL };
    ControlCheckMark *self;
    char* cFont = NULL;
    char* cTextureFocus = NULL;
    char* cTextureNoFocus = NULL;
    char* cTextColor = NULL;
    char* cDisabledColor = NULL;

    PyObject* pObjectText;

    self = (ControlCheckMark*)type->tp_alloc(type, 0);
    if (!self) return NULL;
    new(&self->strFont) string();
    new(&self->strText) string();
    new(&self->strTextureFocus) string();
    new(&self->strTextureNoFocus) string();

    // set up default values in case they are not supplied
    self->checkWidth = 30;
    self->checkHeight = 30;
    self->align = XBFONT_RIGHT;
    self->strFont = "font13";
    self->textColor = 0xffffffff;
    self->disabledColor = 0x60ffffff;

    // parse arguments to constructor
    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"llllO|sslllsss:ControlCheckMark",
      (char**)keywords,
      &self->dwPosX,
      &self->dwPosY,
      &self->dwWidth,
      &self->dwHeight,
      &pObjectText,
      &cTextureFocus,
      &cTextureNoFocus,
      &self->checkWidth,
      &self->checkHeight,
      &self->align,
      &cFont,
      &cTextColor,
      &cDisabledColor ))
    {
      Py_DECREF( self );
      return NULL;
    }
    if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 5))
    {
      Py_DECREF( self );
      return NULL;
    }

    if (cFont) self->strFont = cFont;
    if (cTextColor) sscanf(cTextColor, "%x", &self->textColor);
    if (cDisabledColor)
    {
      sscanf( cDisabledColor, "%x", &self->disabledColor );
    }
    self->strTextureFocus = cTextureFocus ?
      cTextureFocus :
      PyXBMCGetDefaultImage((char*)"checkmark", (char*)"texturefocus", (char*)"check-box.png");
    self->strTextureNoFocus = cTextureNoFocus ?
      cTextureNoFocus :
      PyXBMCGetDefaultImage((char*)"checkmark", (char*)"texturenofocus", (char*)"check-boxNF.png");

    return (PyObject*)self;
  }