Insert Pics plugin
Insert Pics plugin
Insert Pics is very useful to make a quick record, when I need to share it with someone else, a doc with the pictures would be more directly.
I want to write code to convert the file to *.docx using py-docx package, there are several questions:
1.the *.cuda-pic file seems json format?
2."crc": 4258111033, what dose this key mean?
3.Any API to convert "pic_data" to form a picture again (and then using the pydocx add_pic method to insert it) ?
Thanks!
I want to write code to convert the file to *.docx using py-docx package, there are several questions:
1.the *.cuda-pic file seems json format?
2."crc": 4258111033, what dose this key mean?
3.Any API to convert "pic_data" to form a picture again (and then using the pydocx add_pic method to insert it) ?
Thanks!
-
- Posts: 2323
- Joined: 25.08.2021 18:15
Re: About Insert Pics plugins
1. yes.
2. it is control-sum of the picture. for details, see the python code. it is usually ignored because noone changes the Base64 code.
3. data is Base64 encoded. see the source code, it is usual base64.
2. it is control-sum of the picture. for details, see the python code. it is usually ignored because noone changes the Base64 code.
Code: Select all
def get_file_crc(filename):
s = open(filename, "rb").read()
return zlib.crc32(s) & 0xFFFFFFFF
Code: Select all
def write_file_code(filename, s):
s = s.encode()
s = base64.b64decode(s)
with open(filename, "wb") as f:
f.write(s)
-
- Posts: 2323
- Joined: 25.08.2021 18:15
Re: About Insert Pics plugins
for the DOCX idea. i welcome the addition, ie patch. you may fork the repo and do the patch. https://github.com/CudaText-addons/cuda_insert_pics
Re: About Insert Pics plugins
Hello,
I've writen the code, it works when running outside. When add the code into insert-pic plugin. Then command still works, but Cuda crashed after that. With an error of "access violation" msg box flashed. Attached is the added code in insert-pic plugin _ini_.py
I can't figure it out. Please help me to check it.
BTW, It's hard for me to fork a repo and pull request recently, if the idea is useful for Cuda, maybe you can add it at sometime. Thanks~
I've writen the code, it works when running outside. When add the code into insert-pic plugin. Then command still works, but Cuda crashed after that. With an error of "access violation" msg box flashed. Attached is the added code in insert-pic plugin _ini_.py
I can't figure it out. Please help me to check it.
BTW, It's hard for me to fork a repo and pull request recently, if the idea is useful for Cuda, maybe you can add it at sometime. Thanks~
-
- Posts: 2323
- Joined: 25.08.2021 18:15
Re: About Insert Pics plugins
before I try the code, let's adapt it.
1) make separate module make_doc.py, which will expose public function "convert_to_doc(ed)". maybe add more parameters, for example the folder of DOCX file.
1b) class Command is not needed in your module.
2) reuse "tempfile" module in your code.
import tempfile
temp_filename = tempfile.gettempdir()+os.sep+'mypic.png'
do not use "disk D:" paths. I use linux.
1) make separate module make_doc.py, which will expose public function "convert_to_doc(ed)". maybe add more parameters, for example the folder of DOCX file.
1b) class Command is not needed in your module.
2) reuse "tempfile" module in your code.
import tempfile
temp_filename = tempfile.gettempdir()+os.sep+'mypic.png'
do not use "disk D:" paths. I use linux.
-
- Posts: 2323
- Joined: 25.08.2021 18:15
Re: About Insert Pics plugins
I tried to do it. but 'docx.py' (I get it from PYPI.org) shows errors:
Code: Select all
File "/home/user/.config/cudatext/py/cuda_insert_pics/docx.py", line 30, in <module>
from exceptions import PendingDeprecationWarning
ModuleNotFoundError: No module named 'exceptions'
ERROR: Exception in CudaText for export_docx: ModuleNotFoundError: No module named 'exceptions'
Re: About Insert Pics plugins
I don't sure if understand your description.
For me, as the code needs python-docx package, I install it by PIP. As python3.8 is used in Cuda, I install python3.8 and copy several packages generated after pip command to the Cuda py folder. (the packages for python3.9 didn't work)
The copied packages included 3 items, there are some dependancy there: :
Thanks for the notes to adapt code. That make the code more pythonic~
For me, as the code needs python-docx package, I install it by PIP. As python3.8 is used in Cuda, I install python3.8 and copy several packages generated after pip command to the Cuda py folder. (the packages for python3.9 didn't work)
The copied packages included 3 items, there are some dependancy there: :
Thanks for the notes to adapt code. That make the code more pythonic~
-
- Posts: 2323
- Joined: 25.08.2021 18:15
Re: About Insert Pics plugins
yes, I don't need to download from PYPI.org, I need to install 'python-docx'. I still get exceptions inside exporter code. which I cannot fix. so, I request the full plugin code which is working.
Re: About Insert Pics plugins
I haven't adapt it yet according to your guidance.