add open current file dir extension

This commit is contained in:
Mario Voigt 2024-01-28 23:54:02 +01:00
parent 720629935c
commit d6c43d341c
6 changed files with 78 additions and 6 deletions

View File

@ -0,0 +1,20 @@
[
{
"name": "Open Current File Directory",
"id": "fablabchemnitz.de.open_currentfile_dir",
"path": "open_currentfile_dir",
"dependent_extensions": null,
"original_name": "Open Current File Directory",
"original_id": "fablabchemnitz.de.open_currentfile_dir",
"license": "GNU GPL v3",
"license_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.2/src/branch/master/LICENSE",
"comment": "Written by Mario Voigt",
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.2/src/branch/master/extensions/fablabchemnitz/open_currentfile_dir",
"fork_url": null,
"documentation_url": "https://stadtfabrikanten.org/display/IFM/Open+Extension+Directory",
"inkscape_gallery_url": null,
"contributors": [
"github.com/eridur-de"
]
}
]

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Open Current File Directory</name>
<id>fablabchemnitz.de.open_currentfile_dir</id>
<effect needs-live-preview="false">
<object-type>all</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">open_currentfile_dir.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
import subprocess
import os
import sys
import warnings
import inkex
DETACHED_PROCESS = 0x00000008
class OpenCurrentFileDirectory(inkex.EffectExtension):
def spawnIndependentProcess(self, args):
warnings.simplefilter('ignore', ResourceWarning) #suppress "enable tracemalloc to get the object allocation traceback"
if os.name == 'nt':
subprocess.Popen(args, close_fds=True, creationflags=DETACHED_PROCESS)
else:
subprocess.Popen(args, start_new_session=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
warnings.simplefilter("default", ResourceWarning)
def effect(self):
dir = os.path.dirname(self.document_path())
if dir == '':
inkex.utils.debug("Please save the document first!")
if os.name == 'nt':
explorer = "explorer"
else:
explorer = "xdg-open"
args = [explorer, dir]
try:
self.spawnIndependentProcess(args)
except FileNotFoundError as e:
inkex.utils.debug(e)
exit(1)
if __name__ == '__main__':
OpenCurrentFileDirectory().run()

View File

@ -1,15 +1,15 @@
[
{
"name": "Open Extension Directory",
"id": "fablabchemnitz.de.open_dir",
"path": "open_dir",
"id": "fablabchemnitz.de.open_extensions_dir",
"path": "open_extensions_dir",
"dependent_extensions": null,
"original_name": "Open Extension Directory",
"original_id": "fablabchemnitz.de.open_dir",
"original_id": "fablabchemnitz.de.open_extensions_dir",
"license": "GNU GPL v3",
"license_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.2/src/branch/master/LICENSE",
"comment": "Written by Mario Voigt",
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.2/src/branch/master/extensions/fablabchemnitz/open_dir",
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.2/src/branch/master/extensions/fablabchemnitz/open_extensions_dir",
"fork_url": null,
"documentation_url": "https://stadtfabrikanten.org/display/IFM/Open+Extension+Directory",
"inkscape_gallery_url": null,

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Open Extension Directory</name>
<id>fablabchemnitz.de.open_dir</id>
<id>fablabchemnitz.de.open_extensions_dir</id>
<effect needs-live-preview="false">
<object-type>all</object-type>
<effects-menu>
@ -9,6 +9,6 @@
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">open_dir.py</command>
<command location="inx" interpreter="python">open_extensions_dir.py</command>
</script>
</inkscape-extension>