Closed PFython closed 3 years ago
That's strange, I cannot reproduce this on my Premiere 14.5.0
I suspect it may be due to a different Qt behavior. Can you please add this line :
print(file_to_import, type(file_to_import))
between line 200 and 201 in demo_ui.py so we can see what's going on ?
Thanks
I've played around some more - import seems to work with some file types e.g. .mp4 but not others e.g. fails for .jpg and .wav files I tried... Hope that helps!
Adding line as requested... will report back!
D:\Pete's Data\OneDrive\Python Scripts>"C:/Program Files/Python39/python.exe" "d:/Pete's Data/OneDrive/Python Scripts/pymiere/demo_ui.py"
D:\Pete's Data\OneDrive\Sound Effects\Music Bridges\Beethoven 2.wav
<class 'str'>
<class 'TypeError'> pymiere.core.Array() argument after * must be a mapping, not str <traceback object at 0x0000028566BB82C0>
Traceback (most recent call last):
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 22, in wrapper
result = func(self, args, kwargs)
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 202, in import_func
pymiere.objects.app.project.importFiles([file_to_import], True, root_bin, True)
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\objects\premiere_objects.py", line 425, in importFiles
return self._eval_on_this_object("importFiles({}, {}, {}, {})".format(_format_object_to_es(arrayOfFilePathsToImport), _format_object_to_es(suppressUI), _format_object_to_es(targetBin), _format_object_to_es(importAsNumberedStills)))
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\core.py", line 380, in _format_object_to_es
return "$._pymiere['{}']".format(Array.from_python_list(obj)._pymiere_id)
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\core.py", line 362, in from_python_list
return cls(_eval_script_returning_object("[{}]".format(", ".join([_format_object_to_es(item) for item in python_list])), as_kwargs=True))
TypeError: pymiere.core.Array() argument after ** must be a mapping, not str
D:\Pete's Data\OneDrive\Python Scripts>"C:/Program Files/Python39/python.exe" "d:/Pete's Data/OneDrive/Python Scripts/pymiere/demo_ui.py"
D:\Pete's Data\OneDrive\Graphics\Backdrops and Textures\Metal 1 Specular.jpg
<class 'str'>
<class 'TypeError'> pymiere.core.Array() argument after * must be a mapping, not str <traceback object at 0x000001BA641FD480>
Traceback (most recent call last):
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 22, in wrapper
result = func(self, args, kwargs)
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 202, in import_func
pymiere.objects.app.project.importFiles([file_to_import], True, root_bin, True)
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\objects\premiere_objects.py", line 425, in importFiles
return self._eval_on_this_object("importFiles({}, {}, {}, {})".format(_format_object_to_es(arrayOfFilePathsToImport), _format_object_to_es(suppressUI), _format_object_to_es(targetBin), _format_object_to_es(importAsNumberedStills)))
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\core.py", line 380, in _format_object_to_es
return "$._pymiere['{}']".format(Array.from_python_list(obj)._pymiere_id)
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\core.py", line 362, in from_python_list
return cls(_eval_script_returning_object("[{}]".format(", ".join([_format_object_to_es(item) for item in python_list])), as_kwargs=True))
TypeError: pymiere.core.Array() argument after ** must be a mapping, not str
I understand what's going on now, the probleme is due to the '
in your path in Pete's Data
. I fixed the code so it support that : https://github.com/qmasingarbe/pymiere/commit/f9d54263cc3caa1e12c3c982a7c9b0b0ac0b06b4
Aaah those pesky apostrophes!
I fixed the code so it support that : f9d5426
@qmasingarbe wouldn't it make more sense to just remove the if statement and always use the single quote?
Or, if this is not solely used for filepaths but just about escaping the quotation marks then we should just escape those. If now you ever pass a string containing both '
and "
it will still fail.
So escaping the quotation mark should work:
if isinstance(obj, str):
escaped = obj.replace('"', '\"')
return '"{}"'.format(escaped)
Maybe I'm overthinking this. I was just wondering.
@BigRoy That's True, both ' and " in the same string would fail. I tried to escape the quotes but ran into a issue due to my design : Let's say I have this python string to pass to extend script : C:\User\Pete's if I escape the ' I get C:\User\Pete\'s then my generic fuction to send code to javascript has to escape the backslashes so I get C:\User\Pete\'s... And I can't move the escape quot code into the funciton that send code because I need quote to create string in javascript. nyway after struggling a bit I changed my mind and simply used 3 double quote around the string which would accomodate most usage (except if you use 3 double quotes in a string...) https://github.com/qmasingarbe/pymiere/commit/8c34733501c62db41821d2d98f95d1692ded5231
I changed my mind and simply used 3 double quote
Brilliant - that's called "Cutting the Gordian Knot"!
I get the following error after clicking the Import / Import & Insert buttons in demo_ui.py and selecting a media file to import:
<class 'TypeError'> pymiere.core.Array() argument after must be a mapping, not str <traceback object at 0x000001920A80AB00> Traceback (most recent call last): File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 22, in wrapper result = func(self, *args, *kwargs) File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 211, in import_insert_func item = self.import_func() File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 22, in wrapper result = func(self, args, kwargs) File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\demo_ui.py", line 201, in import_func pymiere.objects.app.project.importFiles([file_to_import], True, root_bin, True) File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\objects\premiere_objects.py", line 425, in importFiles return self._eval_on_this_object("importFiles({}, {}, {}, {})".format(_format_object_to_es(arrayOfFilePathsToImport), _format_object_to_es(suppressUI), _format_object_to_es(targetBin), _format_object_to_es(importAsNumberedStills))) File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\core.py", line 380, in _format_object_to_es return "$._pymiere['{}']".format(Array.from_python_list(obj)._pymiere_id)
File "d:\Pete's Data\OneDrive\Python Scripts\pymiere\pymiere\core.py", line 362, in from_python_list return cls(_eval_script_returning_object("[{}]".format(", ".join([_format_object_to_es(item) for item in python_list])), as_kwargs=True)) TypeError: pymiere.core.Array() argument after must be a mapping, not str