Skip to content

Commit

Permalink
Merge pull request #11 from UuuNyaa/feature/#8_asset_search_error_on_…
Browse files Browse the repository at this point in the history
…windows

Feature/#8 asset search error on windows
  • Loading branch information
UuuNyaa authored Mar 1, 2021
2 parents 481b37f + afd9d41 commit 55ccb4a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion mmd_uuunyaa_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"name": "mmd_uuunyaa_tools",
"description": "Utility tools for MMD model & scene editing by Uuu(/>ω<)/Nyaa!.",
"author": "UuuNyaa",
"version": (0, 0, 6),
"version": (0, 1, 1),
"blender": (2, 80, 0),
"warning": "",
"location": "View3D > Tool Shelf > MMD Tools Panel",
Expand Down
10 changes: 7 additions & 3 deletions mmd_uuunyaa_tools/asset_search/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ def unrar(rar_file_path, password=None, asset=None):
loader = importlib.machinery.SourceFileLoader(namespace, os.path.join(PACKAGE_PATH, 'externals', 'rarfile', 'rarfile.py'))
rarfile = loader.load_module(namespace)

with rarfile.RarFile(rar_file_path) as rar:
rar.extractall(path=asset_path, pwd=password)
try:
with rarfile.RarFile(rar_file_path) as rar:
rar.extractall(path=asset_path, pwd=password)
except rarfile.RarCannotExec:
raise rarfile.RarCannotExec('Failed to execute unrar or WinRAR\nPlease install unrar or WinRAR and setup the PATH properly.')

_Utilities.write_json(asset)
_Utilities.chmod_recursively(asset_path, stat.S_IWRITE)
Expand Down Expand Up @@ -251,6 +254,7 @@ def execute_import_action(asset: AssetDescription, target_file: Union[str, None]
tree = ast.parse(asset.import_action)

_Utilities.Visitor().visit(tree)

exec(compile(tree, '<source>', 'exec'), {'__builtins__': {}}, {
'unzip': functools.partial(_Utilities.unzip, asset=asset),
'unrar': functools.partial(_Utilities.unrar, asset=asset),
Expand Down Expand Up @@ -283,7 +287,7 @@ def reload(self, asset_jsons_folder: str):

for json_path in glob.glob(os.path.join(asset_jsons_folder, '*.json')):
try:
with open(json_path) as f:
with open(json_path, encoding='utf-8') as f:
for asset in json.load(f)['assets']:
self.add(_Utilities.from_dict(asset))
except:
Expand Down
16 changes: 2 additions & 14 deletions mmd_uuunyaa_tools/asset_search/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from typing import List, Set, Union

import bpy
import bpy.utils.previews
from mmd_uuunyaa_tools.asset_search.assets import ASSETS, AssetDescription
from mmd_uuunyaa_tools.asset_search.cache import CONTENT_CACHE, Content, Task
from mmd_uuunyaa_tools.utilities import to_human_friendly_text, to_int32
from mmd_uuunyaa_tools.utilities import label_multiline, to_human_friendly_text, to_int32


class AssetState(Enum):
Expand Down Expand Up @@ -135,19 +136,6 @@ def execute(self, context):
return {'FINISHED'}


def label_multiline(layout, text='', width=0):
if text.strip() == '':
return

threshold = int(width / 5.5) if width > 0 else 35
for line in text.split('\n'):
while len(line) > threshold:
space_index = line.rfind(' ', 0, threshold)
layout.label(text=line[:space_index])
line = line[space_index:].lstrip()
layout.label(text=line)


class AssetDownload(bpy.types.Operator):
bl_idname = 'mmd_uuunyaa_tools.asset_download'
bl_label = 'Download Asset'
Expand Down
27 changes: 25 additions & 2 deletions mmd_uuunyaa_tools/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os

import bpy
from mmd_uuunyaa_tools.utilities import label_multiline


class ConvertMaterialsForEevee(bpy.types.Operator):
Expand Down Expand Up @@ -90,9 +91,31 @@ def execute(self, context):
eevee.gi_irradiance_smoothing = 0.50

# Film > Transparent
bpy.data.scenes["Scene"].render.film_transparent = self.film_transparent
bpy.data.scenes['Scene'].render.film_transparent = self.film_transparent

# Color Management > Look: High Contrast
bpy.data.scenes["Scene"].view_settings.look = 'High Contrast'
bpy.data.scenes['Scene'].view_settings.look = 'High Contrast'

return {'FINISHED'}


class ShowMessageBox(bpy.types.Operator):
bl_idname = 'mmd_uuunyaa_tools.show_message_box'
bl_label = 'Show Message Box'
bl_description = 'Show message box.'
bl_options = {'INTERNAL'}

icon: bpy.props.StringProperty(default='INFO')
title: bpy.props.StringProperty(default='')
message: bpy.props.StringProperty(default='')
width: bpy.props.IntProperty(default=400)

def execute(self, context):
self.report({'INFO'}, message=self.message)
return context.window_manager.invoke_popup(self, width=self.width)

def draw(self, context):
layout = self.layout
layout.label(text=self.title, icon=self.icon)
col = layout.column(align=True)
label_multiline(col, text=self.message, width=self.width)
4 changes: 1 addition & 3 deletions mmd_uuunyaa_tools/tuners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Dict, NamedTuple

import bpy
import bpy.utils.previews
from mmd_uuunyaa_tools import PACKAGE_PATH


Expand Down Expand Up @@ -40,9 +41,6 @@ def __init__(self, *tuners: TunerABC):
for t in tuners:
self.add(t)

def __del__(self):
del self.previews

def __getitem__(self, tuner_id: str) -> TunerABC:
return self.tuners[tuner_id].tuner

Expand Down
13 changes: 13 additions & 0 deletions mmd_uuunyaa_tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ def sanitize_path_fragment(path_fragment: str) -> str:
)


def label_multiline(layout, text='', width=0):
if text.strip() == '':
return

threshold = int(width / 5.5) if width > 0 else 35
for line in text.split('\n'):
while len(line) > threshold:
space_index = line.rfind(' ', 0, threshold)
layout.label(text=line[:space_index])
line = line[space_index:].lstrip()
layout.label(text=line)


class ObjectMarker:
def __init__(self, mark_id: str):
self.mark_id = mark_id
Expand Down

0 comments on commit 55ccb4a

Please sign in to comment.