Editing
Machacks
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Open Vplot files with Double Click == This actually requires an application. MacOS cannot use shell scripts as applications, and the application also needs to be able to parse arguments (needed for the double click funcionality - the instigating file becomes the first argument). The below steps will turn a simple python script into an Application. First, install [http://pythonhosted.org/py2app/ py2ap] and then follow the below instructions (based on a website of [https://moosystems.com/double-click-on-files-in-finder-to-open-them-in-your-python-and-tk-application/ MooSystems]). # Use the following python file (named ClickPen.py). Adapt the sfpen path as needed, or use an environmental variable: <syntaxhighlight lang="python"> #!/usr/bin/env python # -*- coding: utf-8 -*- """This piece of code shows how to accept 'Open Document' Apple Events in your Python / Tk application.""" import os import sys import commands import logging import logging.handlers # configure logging home_dir = os.path.expanduser('~') log_file = os.path.join(home_dir, "Library/Logs/CliclPen.log") log = logging.getLogger("main") log.setLevel(logging.DEBUG) handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=30000000, backupCount=10) handler.setLevel(logging.DEBUG) fmt = logging.Formatter('%(asctime)s - %(message)s') handler.setFormatter(fmt) log.addHandler(handler) # callback which gets invoked when files or folders are sent to our app: def doOpenFile(*args): for f in args: if os.path.isfile(f): command = '/opt/RSF/bin/sfpen %s'%(f) commands.getoutput(command) else: log.info("'%s' is not compatible." % f) # when the app starts up, check for command-line arguments: for f in sys.argv[1:]: doOpenFile(f) </syntaxhighlight> # Use the following setup file (named setup.py): <syntaxhighlight lang="python"> """ This is a setup.py script generated by py2applet Usage: python setup.py py2app """ from setuptools import setup APP = ['ClickPen.py'] DATA_FILES = [] OPTIONS = {'argv_emulation': True, 'plist': { 'CFBundleDocumentTypes': [{ 'CFBundleTypeName': "File suffix of my app's documents", 'CFBundleTypeRole': "Editor", 'LSHandlerRank': "Owner", 'LSItemContentTypes': ["ClickPen"], }], 'UTExportedTypeDeclarations': [{ 'UTTypeConformsTo': ["public.data"], 'UTTypeIdentifier': "ClickPen", 'UTTypeDescription': "File suffix of my app's documents", 'UTTypeTagSpecification': {'public.filename-extension': ".vpl"} }], 'CFBundleIdentifier': "ClickPen", 'CFBundleName': "ClickPen" } } setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], ) </syntaxhighlight> # Run the following command: <pre> python setup.py py2app </pre> # Now in the dist folder you should find a ClickPen.app program. Use it wisely.
Summary:
Please note that all contributions to Madagascar are considered to be released under the GNU Free Documentation License 1.3 or later (see
My wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
English
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Getting Madagascar
download
Installation
GitHub repository
SEGTeX
Introduction
Package overview
Tutorial
Hands-on tour
Reproducible documents
Hall of Fame
User Documentation
List of programs
Common programs
Popular programs
The RSF file format
Reproducibility with SCons
Developer documentation
Adding programs
Contributing programs
API demo: clipping data
API demo: explicit finite differences
Community
Conferences
User mailing list
Developer mailing list
GitHub organization
LinkedIn group
Development blog
Twitter
Slack
Tools
What links here
Related changes
Special pages
Page information