Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sandbox/studio/plugins/texture_processor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
import os
import sys
import logging

logging.basicConfig(level=logging.INFO, stream=sys.stdout)


def register():
menu = ui.find_or_create_menu("Utils")
menu = ui.find_or_create_menu("Plugins")

act = QtWidgets.QAction("Convert textures", menu)
act.triggered.connect(convert_all_textures_to_tx)

menu.addAction(act)


def convert_all_textures_to_tx():
def _find_maketx():
root_path = studio.get_root_path()
Expand All @@ -28,6 +31,10 @@ def _find_maketx():
raise Exception('maketx binary is not found')

project = studio.current_project()

if project is None:
raise Exception('No project is opened')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should throw. If no project is open there are no textures to convert and no work to do.
Maybe simply return?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, ok


scene = project.get_scene()
textures = get_textures(scene)

Expand Down Expand Up @@ -56,8 +63,10 @@ def _find_maketx():

texture_parameters['filename'] = new_texture_path
texture.set_parameters(texture_parameters)
studio.set_project_dirty()
logging.info('{} converted to {}'.format(texture_path, new_texture_path))


def get_textures(container):
assert isinstance(container, asr.BaseGroup)

Expand All @@ -69,6 +78,7 @@ def get_textures(container):

return textures


def get_full_path(texture_path, project):
if os.path.isabs(texture_path):
return texture_path
Expand Down
3 changes: 3 additions & 0 deletions src/appleseed.python/studio/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
import imp
import traceback


def load_plugins(bundled_plugins_path):
load_plugins_from_dir(bundled_plugins_path)

user_plugins_path = os.environ.get('APPLESEED_STUDIO_PLUGIN_PATH')
if user_plugins_path is not None:
load_plugins_from_dir(user_plugins_path)


def load_plugins_from_dir(bundled_plugins_path):
for plugin in os.listdir(bundled_plugins_path):
plugin_path = os.path.join(bundled_plugins_path, plugin)
Expand All @@ -46,6 +48,7 @@ def load_plugins_from_dir(bundled_plugins_path):

load_plugin(plugin_path)


def load_plugin(plugin_path):
path, name = os.path.split(plugin_path)
name, ext = os.path.splitext(name)
Expand Down
2 changes: 2 additions & 0 deletions src/appleseed.python/studio/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import appleseed.studio as studio
import Qt


def wrapinstance(addr, type):
if Qt.__binding__ == 'PyQt4':
import sip
Expand All @@ -41,6 +42,7 @@ def wrapinstance(addr, type):
else:
raise Exception("No wrapinstance function defined for " + Qt.__binding__)


def find_or_create_menu(menu_name):
ptr = studio.main_window()
main_window = wrapinstance(long(ptr), Qt.QtWidgets.QMainWindow)
Expand Down
6 changes: 6 additions & 0 deletions src/appleseed.studio/python/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ bool is_project_dirty()
return project_manager()->is_project_dirty();
}

void set_project_dirty()
{
project_manager()->set_project_dirty_flag();
}

bpy::long_ main_window_as_pylong()
{
const uintptr_t ptr = binary_cast<uintptr_t>(main_window());
Expand All @@ -135,6 +140,7 @@ BOOST_PYTHON_MODULE(_appleseedstudio)
bpy::def("current_project", current_project,
bpy::return_value_policy<bpy::reference_existing_object>());
bpy::def("is_project_dirty", is_project_dirty);
bpy::def("set_project_dirty", set_project_dirty);

bpy::def("main_window", main_window_as_pylong);
bpy::def("create_dock_widget", create_dock_widget, bpy::args("dock_name"));
Expand Down