<commit_before>/* dtkCreatorScriptBrowser.cpp --- 
 * 
 * Author: <NAME>
 * Copyright (C) 2008 - <NAME>, Inria.
 * Created: Tue Aug  4 10:07:29 2009 (+0200)
 * Version: $Id$
 * Last-Updated: Thu Sep  3 18:59:35 2009 (+0200)
 *           By: <NAME>
 *     Update #: 145
 */

/* Commentary: 
 * 
 */

/* Change log:
 * 
 */

#include "dtkCreatorScriptBrowser.h"
#include "dtkCreatorWidgetFactory.h"

#include <dtkCore/dtkLog.h>

#include <dtkScript/dtkScriptInterpreter.h>
#include <dtkScript/dtkScriptInterpreterPool.h>
#include <dtkScript/dtkScriptManager.h>

// /////////////////////////////////////////////////////////////////
// dtkCreatorScriptListPrivate
// /////////////////////////////////////////////////////////////////

class dtkCreatorScriptListPrivate
{
public:
    QTextEdit *description;
    QColumnView *view;
    QDirModel *model;
};

// /////////////////////////////////////////////////////////////////
// dtkCreatorScriptList
// /////////////////////////////////////////////////////////////////

dtkCreatorScriptList::dtkCreatorScriptList(QWidget *parent) : QWidget(parent), d(new dtkCreatorScriptListPrivate)
{
    d->description = new QTextEdit;
    d->description->setFrameStyle(QFrame::NoFrame);
    d->description->setAttribute(Qt::WA_MacShowFocusRect, false);
    d->description->setReadOnly(true);

    d->model = new QDirModel;
    d->model->setFilter(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files);

    d->view = new QColumnView(this);
    d->view->setFrameStyle(QFrame::NoFrame);
    d->view->setAttribute(Qt::WA_MacShowFocusRect, false);
    d->view->setColumnWidths(QList<int>() << 200 << 200 << 200);
    d->view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    d->view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    d->view->setModel(d->model);
    d->view->setRootIndex(d->model->index(dtkScriptManager::instance()->scriptPath()));
    d->view->setPreviewWidget(d->description);

    connect(d->view, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onModelIndexClicked(const QModelIndex&)));
    connect(d->view, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(onModelIndexDoubleClicked(const QModelIndex&)));
    connect(d->view, SIGNAL(updatePreviewWidget(const QModelIndex&)), this, SLOT(onModelIndexClicked(const QModelIndex&)));

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(d->view);
}

dtkCreatorScriptList::~dtkCreatorScriptList(void)
{
    delete d->description;
    delete d->view;
    delete d;

    d = NULL;
}

void dtkCreatorScriptList::onModelIndexClicked(const QModelIndex& index)
{
    d->description->setText("");

    if (d->model->fileInfo(index).isDir())
        return;
 
    QString fileName = d->model->fileInfo(index).absoluteFilePath();
   
    dtkScriptInterpreter *interpreter; int stat;
    if (fileName.endsWith(".py"))
        interpreter = dtkScriptInterpreterPool::instance()->python();
    else if (fileName.endsWith(".tcl"))
        interpreter = dtkScriptInterpreterPool::instance()->tcl();
    else
        return;

    interpreter->load(fileName);
    d->description->setText(interpreter->interpret("description", QStringList(), &stat));
    interpreter->release();    
}

void dtkCreatorScriptList::onModelIndexDoubleClicked(const QModelIndex& index)
{
    if (d->model->fileInfo(index).isDir())
        return;
 
    QString fileName = d->model->fileInfo(index).absoluteFilePath();
   
    dtkScriptInterpreter *interpreter; int stat;
    if (fileName.endsWith(".py"))
        interpreter = dtkScriptInterpreterPool::instance()->python();
    else if (fileName.endsWith(".tcl"))
        interpreter = dtkScriptInterpreterPool::instance()->tcl();
    else
        return;

    interpreter->load(fileName);
    interpreter->interpret("init", QStringList(), &stat);
    interpreter->retain();    

    connect(dtkCreatorWidgetFactory::instance(), SIGNAL(interpret(const QString&, int *)),
            interpreter,                           SLOT(interpret(const QString&, int *)));

    emit scriptClicked(fileName);
}

// /////////////////////////////////////////////////////////////////
// dtkCreatorScriptWidgetPrivate<commit_msg>Attempt at fixing bug #8535.<commit_after>/* dtkCreatorScriptBrowser.cpp --- 
 * 
 * Author: <NAME>
 * Copyright (C) 2008 - <NAME>, Inria.
 * Created: Tue Aug  4 10:07:29 2009 (+0200)
 * Version: $Id$
 * Last-Updated: Tue Sep 15 18:41:31 2009 (+0200)
 *           By: <NAME>
 *     Update #: 148
 */

/* Commentary: 
 * 
 */

/* Change log:
 * 
 */

#include "dtkCreatorScriptBrowser.h"
#include "dtkCreatorWidgetFactory.h"

#include <dtkCore/dtkLog.h>

#include <dtkScript/dtkScriptInterpreter.h>
#include <dtkScript/dtkScriptInterpreterPool.h>
#include <dtkScript/dtkScriptManager.h>

// /////////////////////////////////////////////////////////////////
// dtkCreatorScriptListPrivate
// /////////////////////////////////////////////////////////////////

class dtkCreatorScriptListPrivate
{
public:
    QTextEdit *description;
    QColumnView *view;
    QDirModel *model;
};

// /////////////////////////////////////////////////////////////////
// dtkCreatorScriptList
// /////////////////////////////////////////////////////////////////

dtkCreatorScriptList::dtkCreatorScriptList(QWidget *parent) : QWidget(parent), d(new dtkCreatorScriptListPrivate)
{
    d->description = new QTextEdit;
    d->description->setFrameStyle(QFrame::NoFrame);
    d->description->setAttribute(Qt::WA_MacShowFocusRect, false);
    d->description->setReadOnly(true);

    d->model = new QDirModel;
    d->model->setFilter(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files);

    d->view = new QColumnView(this);
    d->view->setFrameStyle(QFrame::NoFrame);
    d->view->setAttribute(Qt::WA_MacShowFocusRect, false);
    d->view->setColumnWidths(QList<int>() << 200 << 200 << 200);
    d->view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    d->view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    d->view->setModel(d->model);
    d->view->setRootIndex(d->model->index(dtkScriptManager::instance()->scriptPath()));
    d->view->setPreviewWidget(d->description);

    connect(d->view, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onModelIndexClicked(const QModelIndex&)));
    connect(d->view, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(onModelIndexDoubleClicked(const QModelIndex&)));
    connect(d->view, SIGNAL(updatePreviewWidget(const QModelIndex&)), this, SLOT(onModelIndexClicked(const QModelIndex&)));

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(d->view);
}

dtkCreatorScriptList::~dtkCreatorScriptList(void)
{
    delete d->description;
    delete d->view;
    delete d;

    d = NULL;
}

void dtkCreatorScriptList::onModelIndexClicked(const QModelIndex& index)
{
    d->description->setText("");

    if (d->model->fileInfo(index).isDir())
        return;
 
    QString fileName = d->model->fileInfo(index).absoluteFilePath();
   
    dtkScriptInterpreter *interpreter; int stat;
    if (fileName.endsWith(".py"))
        interpreter = dtkScriptInterpreterPool::instance()->python();
    else if (fileName.endsWith(".tcl"))
        interpreter = dtkScriptInterpreterPool::instance()->tcl();
    else
        return;

    interpreter->load(fileName);

    d->description->setText(interpreter->interpret("description", QStringList(), &stat));

    // interpreter->release();
}

void dtkCreatorScriptList::onModelIndexDoubleClicked(const QModelIndex& index)
{
    if (d->model->fileInfo(index).isDir())
        return;
 
    QString fileName = d->model->fileInfo(index).absoluteFilePath();
   
    dtkScriptInterpreter *interpreter; int stat;
    if (fileName.endsWith(".py"))
        interpreter = dtkScriptInterpreterPool::instance()->python();
    else if (fileName.endsWith(".tcl"))
        interpreter = dtkScriptInterpreterPool::instance()->tcl();
    else
        return;

    interpreter->load(fileName);

    interpreter->interpret("init", QStringList(), &stat);

    // interpreter->retain();    

    connect(dtkCreatorWidgetFactory::instance(), SIGNAL(interpret(const QString&, int *)),
            interpreter,                           SLOT(interpret(const QString&, int *)));

    emit scriptClicked(fileName);
}

// /////////////////////////////////////////////////////////////////
// dtkCreatorScriptWidgetPrivate
{'fraction_non_alphanumeric': 0.2186944674801564, 'fraction_numerical': 0.011965406942305414, 'mean_word_length': 2.9210404087320017, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 145, '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': '1551904', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2532, 'n_words': 391}