<commit_before>/****************************************************************************
*  imagelabel_python.cpp  -  Imagelabel functions for python api
*
*  Copyright (C) 2003 <NAME> <<EMAIL>>
*  Copyright (C) 2003-2004 <NAME> <<EMAIL>>
*  Copyright (c) 2004 <NAME> <<EMAIL>>
*
*  This file is part of SuperKaramba.
*
*  SuperKaramba is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  SuperKaramba is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with SuperKaramba; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
****************************************************************************/

#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif

#include <Python.h>
#include <qobject.h>
#include "karamba.h"
#include "imagelabel.h"
#include "meter_python.h"
#include "imagelabel_python.h"
#include "lineparser.h"

ImageLabel* createImageLabel(karamba *theme, long x, long y,
                             char* path, bool bg)
{
  QString file;
  //QString fakefile;

  ImageLabel *tmp = new ImageLabel(theme, x, y, 0, 0);
  if(path)
  {
    file.setAscii(path);
    tmp->setValue(file);
    //tmp->parseImages(file, fakefile, x,y, 0, 0);
  }
  tmp->setBackground(bg);
  theme->setSensor(LineParser(file), tmp);
  theme->meterList->append (tmp);
  theme->imageList->append (tmp);
  if(bg)
    theme->kroot->repaint(true);
  return tmp;
}

PyObject* py_createImage(PyObject *, PyObject *args)
{
  long widget, x, y;
  char *text;
  if (!PyArg_ParseTuple(args, (char*)"llls:createImage", &widget, &x, &y, &text))
    return NULL;<commit_msg>An ugly hack to get by the clickarea bug where the ref returned to python land is the same as the old image that was previously deleted. Correctly fixing this will take some work on redesigning the internal workings of how superkaramba handles all meters.  A bit too much work when we want to start working on Plasma soon.<commit_after>/****************************************************************************
*  imagelabel_python.cpp  -  Imagelabel functions for python api
*
*  Copyright (C) 2003 <NAME> <<EMAIL>>
*  Copyright (C) 2003-2004 <NAME> <<EMAIL>>
*  Copyright (c) 2004 <NAME> <<EMAIL>>
*
*  This file is part of SuperKaramba.
*
*  SuperKaramba is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  SuperKaramba is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with SuperKaramba; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
****************************************************************************/

#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif

#include <Python.h>
#include <qobject.h>
#include "karamba.h"
#include "imagelabel.h"
#include "meter_python.h"
#include "imagelabel_python.h"
#include "lineparser.h"

ImageLabel* createImageLabel(karamba *theme, long x, long y,
                             char* path, bool bg)
{
  QString file;
  //QString fakefile;

  //FIXME: This is an ugly hack to ensure a unique reference
  //to add to the meterList.  It is a workaround for when a clickarea
  //is attached to an image, the image is deleted, and a new image is
  //created. A correct solution would be have dictionaries with a key/value
  //pair of ints->refs.
  ImageLabel *tmp2 = new ImageLabel(theme, x, y, 0, 0);
  ImageLabel *tmp = new ImageLabel(theme, x, y, 0, 0);
  delete tmp2;
  
  if(path)
  {
    file.setAscii(path);
    tmp->setValue(file);
    //tmp->parseImages(file, fakefile, x,y, 0, 0);
  }
  tmp->setBackground(bg);
  theme->setSensor(LineParser(file), tmp);
  theme->meterList->append (tmp);
  theme->imageList->append (tmp);
  if(bg)
    theme->kroot->repaint(true);
  return tmp;
}

PyObject* py_createImage(PyObject *, PyObject *args)
{
  long widget, x, y;
  char *text;
  if (!PyArg_ParseTuple(args, (char*)"llls:createImage", &widget, &x, &y, &text))
    return NULL;
{'fraction_non_alphanumeric': 0.16353775552774302, 'fraction_numerical': 0.01543596161869003, 'mean_word_length': 4.150375939849624, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2068713', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1439, 'n_words': 555}