I created a file with a plugin ,when I opened it with Shellexecute ,an alart window pop up say:the file has already been opened in the plugin_host.
Can the file be disconnected from the plugin_host?
The file has already been opened in the plugin_host?
presumably you just need to close the file handle in your Python code after creating the file
code is below
-
- They work fine outside plugin, try to close the file in plugin ,error message is :str object has no close attribute.
from ctypes import *
import subprocess
import tempfile
import os
import re
from threading import Thread
import time
if os.name == “nt”:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDEpdf_filename = tempfile.mkstemp(prefix=‘sublime_text_graphviz_’, dir=None, suffix=’.pdf’)
file_full_path = “F:/study/Proprac/mytest/atool/graphviz/record.dot”
args = [‘dot.exe’, ‘-Tpdf’, file_full_path, ‘-o’, pdf_filename[1]]
process = subprocess.Popen(args, cwd=os.getcwd(), stderr=subprocess.PIPE, startupinfo=startupinfo)
print(pdf_filename)
def get_output(out, process):
for line in iter(out.readline, b’’):
# queue.put(line)
errstr=re.sub(’\r\n’,’’,line.decode(‘utf-8’))
print(errstr)
print("#"*102)
print("#"*30, “‘end print’”, time.asctime(time.localtime(time.time())), “#”*33)
out.close()
t = Thread(target=get_output, args=(process.stderr, process))
print("#"*102)
print("#"*30, “‘start print’”, time.asctime(time.localtime(time.time())), “#”*32)
t.daemon = True # thread dies with the program
t.start()
def open_graphics(pdffile):
try:shelldll = WinDLL("C:/Windows/System32/shell32.dll") nret = shelldll.ShellExecuteW(None, 'open', pdffile, '', '', 1) print(nret) except Exception as e: raise e
open_graphics(pdf_filename[1])
-
-
* To append two line to block try,change the try block as below ,the plugin works ok now.
-
try:
shelldll = WinDLL("C:/Windows/System32/shell32.dll")
nret = shelldll.ShellExecuteW(None, 'open', pdffile, '', '', 1)
print(nret)
os.close(pdffile[0])
os.unlink(pdffile[1])