Esempio n. 1
0
  PyObject* Keyboard_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
    Keyboard *self;

    self = (Keyboard*)type->tp_alloc(type, 0);
    if (!self) return NULL;
   PLACEMENT_NEW(&self->strDefault) string();
   PLACEMENT_NEW(&self->strHeading) string();

    PyObject *line = NULL;
    PyObject *heading = NULL;
    char bHidden = false;
    if (!PyArg_ParseTuple(args, (char*)"|OOb", &line, &heading, &bHidden)) return NULL;

    string utf8Line;
    if (line && !PyGetUnicodeString(utf8Line, line, 1)) return NULL;
    string utf8Heading;
    if (heading && !PyGetUnicodeString(utf8Heading, heading, 2)) return NULL;

    self->strDefault = utf8Line;
    self->strHeading = utf8Heading;
    self->bHidden = (0 != bHidden);

    return (PyObject*)self;
  }
Esempio n. 2
0
  PyObject* ControlButton_SetLabel(ControlButton *self, PyObject *args, PyObject *kwds)
  {
    static char *keywords[] = {
      "label",
      "font",
      "textColor",
      "disabledColor",
      "shadowColor",
      "focusedColor",
      "label2",
      NULL};
    char *cFont = NULL;
    char *cTextColor = NULL;
    char *cDisabledColor = NULL;
    char *cShadowColor = NULL;
    char *cFocusedColor = NULL;
    PyObject *pObjectText = NULL;
    PyObject *pObjectText2 = NULL;
 
    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      "|OsssssO",
      keywords,
      &pObjectText,
      &cFont,
      &cTextColor,
      &cDisabledColor,
      &cShadowColor,
      &cFocusedColor,
      &pObjectText2))
    {
      return NULL;
    }
    if (pObjectText) PyGetUnicodeString(self->strText, pObjectText, 1);
    if (pObjectText2) PyGetUnicodeString(self->strText2, pObjectText2, 1);
    if (cFont) self->strFont = cFont;
    if (cTextColor) sscanf(cTextColor, "%x", &self->dwTextColor);
    if (cDisabledColor) sscanf( cDisabledColor, "%x", &self->dwDisabledColor );
    if (cShadowColor) sscanf(cShadowColor, "%x", &self->dwShadowColor);
    if (cFocusedColor) sscanf(cFocusedColor, "%x", &self->dwFocusedColor);

    PyGUILock();
    if (self->pGUIControl)
    {
      ((CGUIButtonControl*)self->pGUIControl)->PythonSetLabel(
        self->strFont, self->strText, self->dwTextColor, self->dwShadowColor, self->dwFocusedColor);
      ((CGUIButtonControl*)self->pGUIControl)->SetLabel2(self->strText2);
      ((CGUIButtonControl*)self->pGUIControl)->PythonSetDisabledColor(self->dwDisabledColor);
    }
    PyGUIUnlock();

    Py_INCREF(Py_None);
    return Py_None;
  }
Esempio n. 3
0
  PyObject* XBMC_MakeLegalFilename(PyObject *self, PyObject *args, PyObject *kwds)
  {
    static const char *keywords[] = { "filename", "fatX", NULL };
    PyObject *pObjectText;
    bool bIsFatX = true;
    // parse arguments to constructor
    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"O|b",
      (char**)keywords,
      &pObjectText,
      &bIsFatX
      ))
    {
      return NULL;
    };

    CStdString strText;
    if (!PyGetUnicodeString(strText, pObjectText, 1)) return NULL;

    CStdString strFilename;
    strFilename = CUtil::MakeLegalPath(strText);
    return Py_BuildValue((char*)"s", strFilename.c_str());
  }
Esempio n. 4
0
  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 (!PyGetUnicodeString(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);

    // create message
    CGUIMessage msg(GUI_MSG_LABEL_ADD, self->iParentId, self->iControlId, 0, 0, pListItem->item);

    // send message
    PyGUILock();
    if (self->pGUIControl) self->pGUIControl->OnMessage(msg);
    PyGUIUnlock();

    Py_INCREF(Py_None);
    return Py_None;
  }
Esempio n. 5
0
  PyObject* PlayList_Add(PlayList *self, PyObject *args, PyObject *kwds)
  {
    static const char *keywords[] = {
      "url",
      "listitem",
      "index",
      NULL};

    PyObject *pObjectUrl = NULL;
    PyObject *pObjectListItem = NULL;
    int iPos = -1;

    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"O|Ol",
      (char**)keywords,
      &pObjectUrl,
      &pObjectListItem,
      &iPos))
    {
      return NULL;
    }

    CStdString strUrl = "";
    if (!PyGetUnicodeString(strUrl, pObjectUrl)) return NULL;

    if (pObjectListItem != NULL && !ListItem_CheckExact(pObjectListItem))
    {
      PyErr_SetString(PyExc_TypeError, "Object should be of type ListItem!");
      return NULL;
    }

    CFileItemList items;

    if (pObjectListItem != NULL && ListItem_CheckExact(pObjectListItem))
    {
      // an optional listitem was passed
      ListItem* pListItem = NULL;
      pListItem = (ListItem*)pObjectListItem;

      // set m_strPath to the passed url
      pListItem->item->m_strPath = strUrl;

      items.Add(pListItem->item);
    }
    else
    {
      CFileItemPtr item(new CFileItem(strUrl, false));
        item->SetLabel(strUrl);

      items.Add(item);
    }

    self->pPlayList->Insert(items, iPos);

    Py_INCREF(Py_None);
    return Py_None;
  }
Esempio n. 6
0
  PyObject* ControlList_AddItems(ControlList *self, PyObject *args, PyObject *kwds)
  {
    PyObject *pList = NULL;
    static const char *keywords[] = { "items", NULL };

    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"O",
      (char**)keywords,
      &pList) || pList == NULL || !PyObject_TypeCheck(pList, &PyList_Type))
    {
      PyErr_SetString(PyExc_TypeError, "Object should be of type List");
      return NULL;
    }

    CFileItemList items;
    for (int item = 0; item < PyList_Size(pList); item++)
    {
      PyObject *pItem = PyList_GetItem(pList, item);

      ListItem* pListItem = NULL;
      if (ListItem_CheckExact(pItem))
      {
        // object is a listitem
        pListItem = (ListItem*)pItem;
        Py_INCREF(pListItem);
      }
      else
      {
        string strText;
        // object is probably a text item
        if (!PyGetUnicodeString(strText, pItem, 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);
      items.Add(pListItem->item);
    }

    // create message
    CGUIMessage msg(GUI_MSG_LABEL_BIND, self->iParentId, self->iControlId, 0, 0, &items);

    // send message
    PyGUILock();
    if (self->pGUIControl) self->pGUIControl->OnMessage(msg);
    PyGUIUnlock();


    Py_INCREF(Py_None);
    return Py_None;
  }
Esempio n. 7
0
  PyObject* XBMC_GetCacheThumbName(PyObject *self, PyObject *args)
  {
    PyObject *pObjectText;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText)) return NULL;
 
    string strText;
    if (!PyGetUnicodeString(strText, pObjectText, 1)) return NULL;

    Crc32 crc;
    CStdString strPath;
    crc.ComputeFromLowerCase(strText);
    strPath.Format("%08x.tbn", (unsigned __int32)crc);
    return Py_BuildValue((char*)"s", strPath.c_str());
  }
Esempio n. 8
0
PyObject* XBMC_TranslatePath(PyObject *self, PyObject *args)
{
    PyObject *pObjectText;
    if (!PyArg_ParseTuple(args, "O", &pObjectText)) return NULL;

    CStdString strText;
    if (!PyGetUnicodeString(strText, pObjectText, 1)) return NULL;

    CStdString strPath;
    if (strText.Left(3).Equals("P:\\"))
        CUtil::AddFileToFolder(g_settings.GetProfileUserDataFolder(),strText.Mid(3),strText);
    strPath = _P(strText);

    return Py_BuildValue("s", strPath.c_str());
}
Esempio n. 9
0
  PyObject* XBMC_TranslatePath(PyObject *self, PyObject *args)
  {
    PyObject *pObjectText;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText)) return NULL;

    CStdString strText;
    if (!PyGetUnicodeString(strText, pObjectText, 1)) return NULL;

    CStdString strPath;
    if (CUtil::IsDOSPath(strText))
      strText = CSpecialProtocol::ReplaceOldPath(strText, 0);

    strPath = CSpecialProtocol::TranslatePath(strText);

    return Py_BuildValue((char*)"s", strPath.c_str());
  }
Esempio n. 10
0
  PyObject* ControlFadeLabel_AddLabel(ControlFadeLabel *self, PyObject *args)
  {
    PyObject *pObjectText;
    string strText;

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

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

    PyGUILock();
    if (pControl->pGUIControl) pControl->pGUIControl->OnMessage(msg);
    PyGUIUnlock();

    Py_INCREF(Py_None);
    return Py_None;
  }
Esempio n. 11
0
  PyObject* ControlTextBox_SetText(ControlTextBox *self, PyObject *args)
  {
    PyObject *pObjectText;
    string strText;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText))	return NULL;
    if (!PyGetUnicodeString(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
    PyGUILock();
    if (pControl->pGUIControl) pControl->pGUIControl->OnMessage(msg);
    PyGUIUnlock();

    Py_INCREF(Py_None);
    return Py_None;
  }
Esempio n. 12
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 (!PyGetUnicodeString(self->strText, pObjectText, 1))
      return NULL;

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

    PyGUILock();
    if (self->pGUIControl)
    {
      ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetLabel(
        self->strFont,
        self->strText,
        self->dwTextColor );
      ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetDisabledColor(
        self->dwDisabledColor );
    }
    PyGUIUnlock();

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

    string utf8Line;
    if (line && !PyGetUnicodeString(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;
  }
Esempio n. 14
0
  PyObject* WindowXMLDialog_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
    WindowXMLDialog *self;

    self = (WindowXMLDialog*)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;
    bool bForceDefaultSkin = false;

    string strXMLname, strFallbackPath;
    string strDefault = "Default";

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

    PyGetUnicodeString(strXMLname, pyOXMLname);
    PyGetUnicodeString(strFallbackPath, pyOname);
    if (pyDName) PyGetUnicodeString(strDefault, pyDName);

    RESOLUTION res;
    CStdString strSkinPath;
    if (!bForceDefaultSkin)
    {
      // Check to see if the XML file exists in current skin. If not use fallback path to find a skin for the script
      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 basePath;
        CUtil::AddFileToFolder(strFallbackPath, "resources", basePath);
        CUtil::AddFileToFolder(basePath, "skins", basePath);
        CUtil::AddFileToFolder(basePath, CUtil::GetFileName(g_SkinInfo.GetBaseDir()), basePath);
        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
          bForceDefaultSkin = true;
        }
      }
    }

    if (bForceDefaultSkin)
    {
      CSkinInfo skinInfo;
      CStdString basePath;
      CUtil::AddFileToFolder(strFallbackPath, "resources", basePath);
      CUtil::AddFileToFolder(basePath, "skins", basePath);
      CUtil::AddFileToFolder(basePath, strDefault, basePath);

      skinInfo.Load(basePath);
      // if no skin.xml file exists default to PAL_4x3 and PAL_16x9
      if (skinInfo.GetDefaultResolution() == INVALID)
        skinInfo.SetDefaults();
      strSkinPath = skinInfo.GetSkinPath(strXMLname, &res, basePath);

      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, true))
    {
      // error is already set by Window_CreateNewWindow, just release the memory
      self->sFallBackPath.~string();          
      self->sXMLFileName.~string();          
      self->ob_type->tp_free((PyObject*)self);
      return NULL;
    }
    ((CGUIWindow*)(self->pWindow))->SetCoordsRes(res);
    return (PyObject*)self;
  }
Esempio n. 15
0
  PyObject* ControlRadioButton_New(
    PyTypeObject *type,
    PyObject *args,
    PyObject *kwds )
  {
    static char *keywords[] = {
      "x", "y", "width", "height", "label",
      "focusTexture", "noFocusTexture",
      "textXOffset", "textYOffset", "alignment",
      "font", "textColor", "disabledColor", "angle", "shadowColor", "focusedColor",
      "TextureRadioFocus", "TextureRadioNoFocus", NULL };
    ControlRadioButton *self;
    char* cFont = NULL;
    char* cTextureFocus = NULL;
    char* cTextureNoFocus = NULL;
    char* cTextColor = NULL;
    char* cDisabledColor = NULL;
    char* cShadowColor = NULL;
    char* cFocusedColor = NULL;
    char* cTextureRadioFocus = NULL;
    char* cTextureRadioNoFocus = NULL;

    PyObject* pObjectText;

    self = (ControlRadioButton*)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(); 
    new(&self->strTextureRadioFocus) string();    
    new(&self->strTextureRadioNoFocus) string(); 
    
    // set up default values in case they are not supplied
    self->dwTextXOffset = CONTROL_TEXT_OFFSET_X;
    self->dwTextYOffset = CONTROL_TEXT_OFFSET_Y;
    self->dwAlign = (XBFONT_LEFT | XBFONT_CENTER_Y);
    self->strFont = "font13";
    self->dwTextColor = 0xffffffff;
    self->dwDisabledColor = 0x60ffffff;
    self->iAngle = 0;
    self->dwShadowColor = 0;
    self->dwFocusedColor = 0xffffffff;

    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      "llllO|sslllssslssss",
      keywords,
      &self->dwPosX,
      &self->dwPosY,
      &self->dwWidth,
      &self->dwHeight,
      &pObjectText,
      &cTextureFocus,
      &cTextureNoFocus,
      &self->dwTextXOffset,
      &self->dwTextYOffset,
      &self->dwAlign,
      &cFont,
      &cTextColor,
      &cDisabledColor,
      &self->iAngle,
      &cShadowColor,
      &cFocusedColor,
      &cTextureRadioFocus,
      &cTextureRadioNoFocus))
    {
      Py_DECREF( self );
      return NULL;
    }

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

    // if texture is supplied use it, else get default ones
    self->strTextureFocus = cTextureFocus ?
      cTextureFocus :
      PyGetDefaultImage("radiobutton", "texturefocus", "radiobutton-focus.png");
    self->strTextureNoFocus = cTextureNoFocus ?
      cTextureNoFocus :
      PyGetDefaultImage("radiobutton", "texturenofocus", "radiobutton-nofocus.jpg");
    self->strTextureRadioFocus = cTextureRadioFocus ?
      cTextureRadioFocus :
      PyGetDefaultImage("radiobutton", "textureradiofocus", "radiobutton-focus.png");
    self->strTextureRadioNoFocus = cTextureRadioNoFocus ?
      cTextureRadioNoFocus :
      PyGetDefaultImage("radiobutton", "textureradionofocus", "radiobutton-nofocus.jpg");

    if (cFont) self->strFont = cFont;
    if (cTextColor) sscanf( cTextColor, "%x", &self->dwTextColor );
    if (cDisabledColor) sscanf( cDisabledColor, "%x", &self->dwDisabledColor );
    if (cShadowColor) sscanf( cShadowColor, "%x", &self->dwShadowColor );
    if (cFocusedColor) sscanf( cFocusedColor, "%x", &self->dwFocusedColor );
    return (PyObject*)self;
  }
Esempio n. 16
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->dwCheckWidth = 30;
    self->dwCheckHeight = 30;
    self->dwAlign = XBFONT_RIGHT;
    self->strFont = "font13";
    self->dwTextColor = 0xffffffff;
    self->dwDisabledColor = 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->dwCheckWidth,
      &self->dwCheckHeight,
      &self->dwAlign,
      &cFont,
      &cTextColor,
      &cDisabledColor ))
    {
      Py_DECREF( self );
      return NULL;
    }
    if (!PyGetUnicodeString(self->strText, pObjectText, 5))
    {
      Py_DECREF( self );
      return NULL;
    }

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

    return (PyObject*)self;
  }