wxSize SlideShow::ToGif(wxString file)
{
  wxArrayString which;
  bool success = true;

  wxString convert(wxT("convert -delay "+wxString::Format(wxT("%i"),100/GetFrameRate())));
  wxString convertArgs;

  wxString tmpdir = wxFileName::GetTempDir();

  for (int i=0; i<m_size; i++)
  {
    wxFileName imgname(tmpdir, wxString::Format(wxT("wxm_anim%d.png"), i));

    wxImage image = m_images[i]->ToImageFile(imgname.GetFullPath());

    convert << wxT(" \"") << imgname.GetFullPath() << wxT("\"");
  }

  convert << wxT(" \"") << file << wxT("\"");

#if defined __WXMSW__
  if (!wxShell(convert))
#else
  if (wxExecute(convert, wxEXEC_SYNC) != 0)
#endif
  {
    success = false;
    wxMessageBox(_("There was an error during GIF export!\n\nMake sure ImageMagick is installed and wxMaxima can find the convert program."),
        wxT("Error"), wxICON_ERROR);
  }

  for (int i=0; i<m_size; i++)
  {
    wxFileName imgname(tmpdir, wxString::Format(wxT("wxm_anim%d.png"), i));
    wxRemoveFile(imgname.GetFullPath());
  }

  if(success)
  {
    if(m_size>0)
      return wxSize(m_images[1]->GetOriginalWidth(),m_images[1]->GetOriginalHeight());
    else
    {
      wxSize retval;
      retval.x=retval.y=0;
      return retval;
    }
  }
  else
  {
    wxSize retval;
    retval.x=retval.y=-1;
    return retval;
  }
}
Exemple #2
0
QVariant HelpWidget::HelpBrowser::loadResource(int type, const QUrl& name) {
    QUrl url(name);
    if (name.isRelative()) url = source().resolved(url);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    QUrlQuery query(url);
    if (query.hasQueryItem("classIdentifier")) {
        QString cid = query.queryItemValue("classIdentifier");

        auto imageCache = InviwoApplication::getPtr()->getPath(InviwoApplication::PATH_SETTINGS);
        imageCache += "image-cache";
        filesystem::createDirectoryRecursively(imageCache);

        QString imgname(QString::fromStdString(imageCache) + "/" + cid + ".png");
        QImageReader reader(imgname);
        QImage img = reader.read();
        if (!img.isNull()) {
            return img;
        } else {
            QImage img = utilqt::generatePreview(cid);
            QByteArray data;
            QBuffer buffer(&data);
            buffer.open(QIODevice::WriteOnly);
            img.save(&buffer, "PNG");

            QImageWriter writer(imgname);
            writer.write(img);

            return data;
        }
    }
#endif

#ifdef IVW_DEBUG  // Look for the html in the doc-qt folder.
    if (type == QTextDocument::HtmlResource || type == QTextDocument::ImageResource) {
        std::string docbase = InviwoApplication::getPtr()->getPath(InviwoApplication::PATH_DATA,
                                                                   "../tools/doxygen/doc-qt/html");
        QString file = name.toString();
        file.replace("qthelp://org.inviwo/doc", QString::fromStdString(docbase));
        QFile newfile(file);

        if (newfile.exists() && newfile.open(QIODevice::ReadOnly)) {
            QByteArray data = newfile.readAll();
            return data;
        }
    }
#endif

    QByteArray data = helpEngine_->fileData(url);
    switch (type) {
        case QTextDocument::HtmlResource:
            return data;
        case QTextDocument::ImageResource:
            return data;
        case QTextDocument::StyleSheetResource:
            return data;
    }
    return QTextBrowser::loadResource(type, url);
}
Exemple #3
0
bool SlideShow::ToGif(wxString file)
{
  wxArrayString which;
  bool retval = true;

  wxString convert(wxT("convert -delay 40 "));
  wxString convertArgs;

  wxString tmpdir = wxFileName::GetTempDir();

  for (int i=0; i<m_size; i++)
  {
    wxFileName imgname(tmpdir, wxString::Format(wxT("wxm_anim%d.png"), i));

    wxImage image = m_bitmaps[i]->ConvertToImage();
    image.SaveFile(imgname.GetFullPath(), wxBITMAP_TYPE_PNG);

    convert << wxT(" \"") << imgname.GetFullPath() << wxT("\"");
  }

  convert << wxT(" \"") << file << wxT("\"");

#if defined __WXMSW__
  if (!wxShell(convert))
#else
  if (wxExecute(convert, wxEXEC_SYNC) != 0)
#endif
  {
    retval = false;
    wxMessageBox(_("There was and error during GIF export!\n\nMake sure ImageMagick is installed and wxMaxima can find the convert program."),
        wxT("Error"), wxICON_ERROR);
  }

  for (int i=0; i<m_size; i++)
  {
    wxFileName imgname(tmpdir, wxString::Format(wxT("wxm_anim%d.png"), i));
    wxRemoveFile(imgname.GetFullPath());
  }

  return retval;
}
PyObject* py_saveProcessorPreview(PyObject* self, PyObject* args) {
    static PythonParameterParser tester;

    std::string classIdentifier;
    std::string path;
    if (tester.parse<std::string, std::string>(args, classIdentifier, path) == 2) {
        QString imgname(QString::fromStdString(path));

        QImage img = utilqt::generatePreview(QString::fromStdString(classIdentifier));
        if (!img.isNull()) {
            QByteArray data;
            QBuffer buffer(&data);
            buffer.open(QIODevice::WriteOnly);
            img.save(&buffer, "PNG");

            QImageWriter writer(imgname);
            writer.write(img);
            Py_RETURN_NONE;
        }
    }
    return nullptr;
}
Exemple #5
0
QVariant HelpWidget::HelpBrowser::loadResource(int type, const QUrl& name) {
    QUrl url(name);
    if (name.isRelative()) url = source().resolved(url);

    QUrlQuery query(url);
    if (query.hasQueryItem("classIdentifier")) {
        QString cid = query.queryItemValue("classIdentifier");

        auto imageCache =
            helpwidget_->mainwindow_->getInviwoApplication()->getPath(PathType::Settings);
        imageCache += "/image-cache";
        filesystem::createDirectoryRecursively(imageCache);

        QString imgname(QString::fromStdString(imageCache) + "/" + cid + ".png");
        QImageReader reader(imgname);
        QImage img = reader.read();
        if (!img.isNull()) {
            return img;
        } else {
            img = utilqt::generatePreview(cid);
            if (img.isNull()) return QVariant();
            QByteArray data;
            QBuffer buffer(&data);
            buffer.open(QIODevice::WriteOnly);
            img.save(&buffer, "PNG");

            QImageWriter writer(imgname);
            writer.write(img);

            return data;
        }
    }

#ifdef IVW_DEBUG  // Look for the html in the doc-qt folder.
    if (type == QTextDocument::HtmlResource || type == QTextDocument::ImageResource) {
        std::string docbase = helpwidget_->mainwindow_->getInviwoApplication()->getPath(
            PathType::Data, "/../tools/doxygen/doc-qt/html");

        QString file = name.toString();
        file.replace("qthelp://org.inviwo/doc", QString::fromStdString(docbase));
        QFile newfile(file);

        if (newfile.exists() && newfile.open(QIODevice::ReadOnly)) {
            QByteArray data = newfile.readAll();
            return data;
        }
    }
#endif

    QByteArray data = helpEngine_->fileData(url);
    switch (type) {
        case QTextDocument::HtmlResource:
            return data;
        case QTextDocument::ImageResource: {
            auto image = QImage::fromData(data, QFileInfo(url.path()).suffix().toLatin1().data());
            QImage resized{image.scaled(std::max(200, width() - 60), image.height(), Qt::KeepAspectRatio)};

            QByteArray smalldata;
            QBuffer buffer(&smalldata);
            resized.save(&buffer, QFileInfo(url.path()).suffix().toLatin1().data());
            return smalldata;
        }
        case QTextDocument::StyleSheetResource:
            return data;
    }
    return QTextBrowser::loadResource(type, url);
}