Skip to content

Libs/Application/Job/PythonWorker.h

Namespaces

Name
shapeworks
User usage reporting (telemetry)

Classes

Name
class shapeworks::PythonWorker

Source code

#pragma once

#include <functional>
#include <string>
#include <vector>

// qt
#include <QObject>
#include <QSharedPointer>

// vtk
#include <vtkSmartPointer.h>

// studio
#include <Job/Job.h>
#include <Libs/Application/ShapeWorksVtkOutputWindow.h>

namespace shapeworks {
class PythonLogger;

class PythonWorker : public QObject {
  Q_OBJECT

 public:
  constexpr static const char* python_api_version = "6.8";

  PythonWorker();
  ~PythonWorker();

  void set_vtk_output_window(vtkSmartPointer<ShapeWorksVtkOutputWindow> output_window);
  void set_cli_mode(bool cli_mode);

  void run_job(QSharedPointer<Job> job);
  void set_current_job(QSharedPointer<Job> job);

  void incoming_python_message(std::string message_string);
  void incoming_python_progress(double value, std::string message);

  void end_python();

  void abort_job();

  static bool is_torch_available();

  static bool install_torch(std::function<void(std::string)> output_callback = nullptr);

  static std::string get_user_site_packages();

 public Q_SLOTS:

  bool init();

  void start_job(QSharedPointer<Job> job);

  void finalize_python();

 Q_SIGNALS:

  void result_ready();
  void finished();

 private:
  static std::string find_bundled_python_home();
  static std::vector<std::string> compute_bundled_python_path(const std::string& python_home);

  bool initialized_ = false;
  bool initialized_success_ = false;
  bool interpreter_started_ = false;

  vtkSmartPointer<ShapeWorksVtkOutputWindow> studio_vtk_output_window_;

  QSharedPointer<PythonLogger> python_logger_;

  QSharedPointer<Job> current_job_;

  QThread* thread_{nullptr};
};
}  // namespace shapeworks

Updated on 2026-06-30 at 16:03:27 +0000