diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-10 07:28:14 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-10 07:28:14 +0000 |
commit | dc6c73abf6497802c6b0723d68fe4c23184e5ef8 (patch) | |
tree | ae2dfdae6414ec8f04b2d4ec98baa36d305be5da | |
parent | f1b037a4446389a1d92d1b70b68a17fad016f02d (diff) |
automatic import of python-applaunchservices
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-applaunchservices.spec | 319 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 321 insertions, 0 deletions
@@ -0,0 +1 @@ +/applaunchservices-0.3.0.tar.gz diff --git a/python-applaunchservices.spec b/python-applaunchservices.spec new file mode 100644 index 0000000..d6c5ba6 --- /dev/null +++ b/python-applaunchservices.spec @@ -0,0 +1,319 @@ +%global _empty_manifest_terminate_build 0 +Name: python-applaunchservices +Version: 0.3.0 +Release: 1 +Summary: Simple package for registering an app with apple Launch Services to handle UTI and URL +License: MIT License +URL: https://github.com/impact27/applaunchservices +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/08/c1/116fae680fceceb75ccb46c089631713f4f7a8a755218f9108aad4aaec54/applaunchservices-0.3.0.tar.gz +BuildArch: noarch + +Requires: python3-pyobjc-framework-CoreServices + +%description +# applaunchservices +Simple package for registering an app with apple Launch Services to handle UTI and URL. See Apple documentations for details. + +## URL +Launch Services allows a GUI app to register a URL scheme. +This means the app can be called when the user types a URL like `<scheme>://<something>`. + + - `set_URL_scheme_handler`: Sets the given bundleid as the default handler for a given url scheme. + - `get_URL_scheme_handler`: Gets the default bundleid for a given url scheme. + - `open_URL`: Opens the given URL with launch services + +## Files +Launch Services allows a GUI app to register a uniform type identifier (UTI). +This means the app can be called when the user double click on a file in the finder that matches this scheme. +Or if the user types an url like `<file:///path/to/file.ext>`. + +- `set_UTI_handler`: Sets the given bundleid as the default handler for a given uniform type identifier and role. +- `get_UTI_handler`: Gets the default bundleid for a given uniform type identifier and role. +- `open_path`: Opens the given path with launch services + +The roles are: + - 'none' + - 'viewer' + - 'editor' + - 'shell' + - 'all' + + +## Bundle Identifier +The bundle identifier is used to identify an app. Two functions are supplied: + + - `get_bundle_identifier()`: Gets the current bundle identifier if it exists (The app is a GUI app) + - `get_bundle_identifier(pid)`: Gets the bundle identifier for the given process id if it exists (The app is a GUI app) + - `get_bundle_identifier_for_path(path)`: Gets the bundle identifier if the path points to a bundle + +## Usage example: +```python +import applaunchservices as als +from PyQt5.QtWidgets import QApplication, QWidget +from PyQt5.QtCore import QEvent, Qt + +# This app opens python scripts as an editor +uniform_type_identifier = "public.python-script" +role = 'editor' + + +class MacApplication(QApplication): + """Application that process fileopen events.""" + def event(self, event): + if event.type() == QEvent.FileOpen: + widget.setWindowTitle(str(event.file())) + return QApplication.event(self, event) + +# Create application and window +app = MacApplication(['']) +widget = QWidget() + +# Reset old handler at the end +old_handler = als.get_UTI_handler(uniform_type_identifier, role) +app.aboutToQuit.connect( + lambda: als.set_UTI_handler( + uniform_type_identifier, role, old_handler)) + + +# When the app is visible, register itself as a handler +def handle_applicationStateChanged(state): + if state == Qt.ApplicationActive and app._starting: + app._starting = False + bundle_identifier = als.get_bundle_identifier() + als.set_UTI_handler( + uniform_type_identifier, role, bundle_identifier) + + +app._starting = True +app.applicationStateChanged.connect(handle_applicationStateChanged) + +# Launch app +widget.setWindowTitle('test') +widget.show() +app.exec_() +# The app can now receive file open events +``` + + +%package -n python3-applaunchservices +Summary: Simple package for registering an app with apple Launch Services to handle UTI and URL +Provides: python-applaunchservices +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-applaunchservices +# applaunchservices +Simple package for registering an app with apple Launch Services to handle UTI and URL. See Apple documentations for details. + +## URL +Launch Services allows a GUI app to register a URL scheme. +This means the app can be called when the user types a URL like `<scheme>://<something>`. + + - `set_URL_scheme_handler`: Sets the given bundleid as the default handler for a given url scheme. + - `get_URL_scheme_handler`: Gets the default bundleid for a given url scheme. + - `open_URL`: Opens the given URL with launch services + +## Files +Launch Services allows a GUI app to register a uniform type identifier (UTI). +This means the app can be called when the user double click on a file in the finder that matches this scheme. +Or if the user types an url like `<file:///path/to/file.ext>`. + +- `set_UTI_handler`: Sets the given bundleid as the default handler for a given uniform type identifier and role. +- `get_UTI_handler`: Gets the default bundleid for a given uniform type identifier and role. +- `open_path`: Opens the given path with launch services + +The roles are: + - 'none' + - 'viewer' + - 'editor' + - 'shell' + - 'all' + + +## Bundle Identifier +The bundle identifier is used to identify an app. Two functions are supplied: + + - `get_bundle_identifier()`: Gets the current bundle identifier if it exists (The app is a GUI app) + - `get_bundle_identifier(pid)`: Gets the bundle identifier for the given process id if it exists (The app is a GUI app) + - `get_bundle_identifier_for_path(path)`: Gets the bundle identifier if the path points to a bundle + +## Usage example: +```python +import applaunchservices as als +from PyQt5.QtWidgets import QApplication, QWidget +from PyQt5.QtCore import QEvent, Qt + +# This app opens python scripts as an editor +uniform_type_identifier = "public.python-script" +role = 'editor' + + +class MacApplication(QApplication): + """Application that process fileopen events.""" + def event(self, event): + if event.type() == QEvent.FileOpen: + widget.setWindowTitle(str(event.file())) + return QApplication.event(self, event) + +# Create application and window +app = MacApplication(['']) +widget = QWidget() + +# Reset old handler at the end +old_handler = als.get_UTI_handler(uniform_type_identifier, role) +app.aboutToQuit.connect( + lambda: als.set_UTI_handler( + uniform_type_identifier, role, old_handler)) + + +# When the app is visible, register itself as a handler +def handle_applicationStateChanged(state): + if state == Qt.ApplicationActive and app._starting: + app._starting = False + bundle_identifier = als.get_bundle_identifier() + als.set_UTI_handler( + uniform_type_identifier, role, bundle_identifier) + + +app._starting = True +app.applicationStateChanged.connect(handle_applicationStateChanged) + +# Launch app +widget.setWindowTitle('test') +widget.show() +app.exec_() +# The app can now receive file open events +``` + + +%package help +Summary: Development documents and examples for applaunchservices +Provides: python3-applaunchservices-doc +%description help +# applaunchservices +Simple package for registering an app with apple Launch Services to handle UTI and URL. See Apple documentations for details. + +## URL +Launch Services allows a GUI app to register a URL scheme. +This means the app can be called when the user types a URL like `<scheme>://<something>`. + + - `set_URL_scheme_handler`: Sets the given bundleid as the default handler for a given url scheme. + - `get_URL_scheme_handler`: Gets the default bundleid for a given url scheme. + - `open_URL`: Opens the given URL with launch services + +## Files +Launch Services allows a GUI app to register a uniform type identifier (UTI). +This means the app can be called when the user double click on a file in the finder that matches this scheme. +Or if the user types an url like `<file:///path/to/file.ext>`. + +- `set_UTI_handler`: Sets the given bundleid as the default handler for a given uniform type identifier and role. +- `get_UTI_handler`: Gets the default bundleid for a given uniform type identifier and role. +- `open_path`: Opens the given path with launch services + +The roles are: + - 'none' + - 'viewer' + - 'editor' + - 'shell' + - 'all' + + +## Bundle Identifier +The bundle identifier is used to identify an app. Two functions are supplied: + + - `get_bundle_identifier()`: Gets the current bundle identifier if it exists (The app is a GUI app) + - `get_bundle_identifier(pid)`: Gets the bundle identifier for the given process id if it exists (The app is a GUI app) + - `get_bundle_identifier_for_path(path)`: Gets the bundle identifier if the path points to a bundle + +## Usage example: +```python +import applaunchservices as als +from PyQt5.QtWidgets import QApplication, QWidget +from PyQt5.QtCore import QEvent, Qt + +# This app opens python scripts as an editor +uniform_type_identifier = "public.python-script" +role = 'editor' + + +class MacApplication(QApplication): + """Application that process fileopen events.""" + def event(self, event): + if event.type() == QEvent.FileOpen: + widget.setWindowTitle(str(event.file())) + return QApplication.event(self, event) + +# Create application and window +app = MacApplication(['']) +widget = QWidget() + +# Reset old handler at the end +old_handler = als.get_UTI_handler(uniform_type_identifier, role) +app.aboutToQuit.connect( + lambda: als.set_UTI_handler( + uniform_type_identifier, role, old_handler)) + + +# When the app is visible, register itself as a handler +def handle_applicationStateChanged(state): + if state == Qt.ApplicationActive and app._starting: + app._starting = False + bundle_identifier = als.get_bundle_identifier() + als.set_UTI_handler( + uniform_type_identifier, role, bundle_identifier) + + +app._starting = True +app.applicationStateChanged.connect(handle_applicationStateChanged) + +# Launch app +widget.setWindowTitle('test') +widget.show() +app.exec_() +# The app can now receive file open events +``` + + +%prep +%autosetup -n applaunchservices-0.3.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-applaunchservices -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.3.0-1 +- Package Spec generated @@ -0,0 +1 @@ +591988d5d1b6a91a475524fa3d742d40 applaunchservices-0.3.0.tar.gz |