Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
haesleinhuepf committed Aug 21, 2021
0 parents commit 8e81ec4
Show file tree
Hide file tree
Showing 14 changed files with 477 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: tests

on:
push:
branches:
- master
- main
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
branches:
- master
- main
workflow_dispatch:

jobs:
test:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

# these libraries, along with pytest-xvfb (added in the `deps` in tox.ini),
# enable testing on Qt on linux
- name: Install Linux libraries
if: runner.os == 'Linux'
run: |
sudo apt-get install -y libdbus-1-3 libxkbcommon-x11-0 libxcb-icccm4 \
libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 \
libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0
# strategy borrowed from vispy for installing opengl libs on windows
- name: Install Windows OpenGL
if: runner.os == 'Windows'
run: |
git clone --depth 1 git://github.com/pyvista/gl-ci-helpers.git
powershell gl-ci-helpers/appveyor/install_opengl.ps1
# note: if you need dependencies from conda, considering using
# setup-miniconda: https://github.com/conda-incubator/setup-miniconda
# and
# tox-conda: https://github.com/tox-dev/tox-conda
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools tox tox-gh-actions
# this runs the platform-specific tests declared in tox.ini
- name: Test with tox
run: tox
env:
PLATFORM: ${{ matrix.platform }}

- name: Coverage
uses: codecov/codecov-action@v1

deploy:
# this will run when you have tagged a commit, starting with "v*"
# and requires that you have put your twine API key in your
# github secrets (see readme for details)
needs: [test]
runs-on: ubuntu-latest
if: contains(github.ref, 'tags')
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools setuptools_scm wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
run: |
git tag
python setup.py sdist bdist_wheel
twine upload dist/*
82 changes: 82 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
.napari_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask instance folder
instance/

# Sphinx documentation
docs/_build/

# MkDocs documentation
/site/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# OS
.DS_Store

# written by setuptools_scm
*/_version.py

/.idea/
/venv/
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Copyright (c) 2021, Robert Haase
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of napari-plugin-search nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include LICENSE
include README.md
include requirements.txt

recursive-exclude * __pycache__
recursive-exclude * *.py[co]
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# napari-plugin-search

[![License](https://img.shields.io/pypi/l/napari-plugin-search.svg?color=green)](https://github.com/haesleinhuepf/napari-plugin-search/raw/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/napari-plugin-search.svg?color=green)](https://pypi.org/project/napari-plugin-search)
[![Python Version](https://img.shields.io/pypi/pyversions/napari-plugin-search.svg?color=green)](https://python.org)
[![tests](https://github.com/haesleinhuepf/napari-plugin-search/workflows/tests/badge.svg)](https://github.com/haesleinhuepf/napari-plugin-search/actions)
[![codecov](https://codecov.io/gh/haesleinhuepf/napari-plugin-search/branch/master/graph/badge.svg)](https://codecov.io/gh/haesleinhuepf/napari-plugin-search)

Find napari plugins
![img.png](https://github.com/haesleinhuepf/napari-plugin-search/raw/main/docs/napari-plugin-search-screencast.gif)

## Usage
Enter the name of the plugin you are searching for and use the `up` and `down` arrow keys to navigate between them.
Hit `Enter` to start a plugin.

----------------------------------

This [napari] plugin was generated with [Cookiecutter] using with [@napari]'s [cookiecutter-napari-plugin] template.

## Installation

You can install `napari-plugin-search` via [pip]:

pip install napari-plugin-search

## Contributing

Contributions are very welcome. Tests can be run with [tox], please ensure
the coverage at least stays the same before you submit a pull request.

## License

Distributed under the terms of the [BSD-3] license,
"napari-plugin-search" is free and open source software

## Issues

If you encounter any problems, please create a thread on [image.sc] along with a detailed description and tag [@haesleinhuepf].

[napari]: https://github.com/napari/napari
[Cookiecutter]: https://github.com/audreyr/cookiecutter
[@napari]: https://github.com/napari
[MIT]: http://opensource.org/licenses/MIT
[BSD-3]: http://opensource.org/licenses/BSD-3-Clause
[GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt
[GNU LGPL v3.0]: http://www.gnu.org/licenses/lgpl-3.0.txt
[Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0
[Mozilla Public License 2.0]: https://www.mozilla.org/media/MPL/2.0/index.txt
[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin

[file an issue]: https://github.com/haesleinhuepf/napari-plugin-search/issues

[napari]: https://github.com/napari/napari
[tox]: https://tox.readthedocs.io/en/latest/
[pip]: https://pypi.org/project/pip/
[PyPI]: https://pypi.org/
[image.sc]: https://image.sc
[@haesleinhuepf]: https://twitter.com/haesleinhuepf
Binary file added docs/napari-plugin-search-screencast.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions napari_plugin_search/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

__version__ = "0.0.1"




from ._dock_widget import napari_experimental_provide_dock_widget

94 changes: 94 additions & 0 deletions napari_plugin_search/_dock_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from napari_plugin_engine import napari_hook_implementation
from qtpy.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem, QLabel
from qtpy.QtCore import QEvent, Qt
from magicgui import magicgui
from qtpy.QtCore import Signal, QObject, QEvent


class MyQLineEdit(QLineEdit):
keyup = Signal()
keydown = Signal()

def keyPressEvent(self, event):
if event.key() == Qt.Key_Up:
self.keyup.emit()
return
elif event.key() == Qt.Key_Down:
self.keydown.emit()
return
super().keyPressEvent(event)

class PluginSearch(QWidget):
def __init__(self, napari_viewer):
from napari.plugins import plugin_manager
super().__init__()
self.viewer = napari_viewer

seach_field = MyQLineEdit("")
results = QListWidget()

def text_changed(*args, **kwargs):
search_string = seach_field.text().lower()
results.clear()
for hook_type, (plugin_name, widgets) in plugin_manager.iter_widgets():
for widget in widgets:
if search_string in plugin_name.lower() or search_string in widget.lower():
_add_result(results, plugin_name, widget)
results.sortItems()

def key_up():
if results.currentRow() > 0:
results.setCurrentRow(results.currentRow() - 1)

def key_down():
if results.currentRow() < results.count() - 1:
results.setCurrentRow(results.currentRow() + 1)

seach_field.keyup.connect(key_up)
seach_field.keydown.connect(key_down)
seach_field.textChanged.connect(text_changed)

def item_double_clicked():
item = results.currentItem()
if item is not None:


widget, widget_type = _get_widget(item.plugin_name, item.widget_name)

if widget_type == "function":
napari_viewer.window.add_dock_widget(magicgui(widget), area='right', name=item.plugin_name + ": " + item.widget_name)
else:
napari_viewer.window.add_plugin_dock_widget(item.plugin_name, item.widget_name)

# napari_viewer.window.add_dock_widget(widget(), area='right')

seach_field.returnPressed.connect(item_double_clicked)
results.itemDoubleClicked.connect(item_double_clicked)

self.setLayout(QVBoxLayout())

w = QWidget()
w.setLayout(QHBoxLayout())
w.layout().addWidget(QLabel("Search:"))
w.layout().addWidget(seach_field)
self.layout().addWidget(w)

self.layout().addWidget(results)

def _add_result(results, plugin_name, widget_name):
item = QListWidgetItem(plugin_name + ": " + widget_name)
item.plugin_name = plugin_name
item.widget_name = widget_name
results.addItem(item)

def _get_widget(plugin_name, widget_name):
from napari.plugins import plugin_manager
if plugin_name in plugin_manager._function_widgets:
functions = plugin_manager._function_widgets[plugin_name]
if widget_name in functions:
return functions[widget_name], "function"
return plugin_manager.get_widget(plugin_name, widget_name)[0], "widget"

@napari_hook_implementation
def napari_experimental_provide_dock_widget():
return [PluginSearch]
Empty file.
18 changes: 18 additions & 0 deletions napari_plugin_search/_tests/test_dock_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import napari_plugin_search
import pytest

# this is your plugin name declared in your napari.plugins entry point
MY_PLUGIN_NAME = "napari-plugin-search"
# the name of your widget(s)
MY_WIDGET_NAMES = ["Example Q Widget", "example_magic_widget"]


@pytest.mark.parametrize("widget_name", MY_WIDGET_NAMES)
def test_something_with_viewer(widget_name, make_napari_viewer, napari_plugin_manager):
napari_plugin_manager.register(napari_plugin_search, name=MY_PLUGIN_NAME)
viewer = make_napari_viewer()
num_dw = len(viewer.window._dock_widgets)
viewer.window.add_plugin_dock_widget(
plugin_name=MY_PLUGIN_NAME, widget_name=widget_name
)
assert len(viewer.window._dock_widgets) == num_dw + 1
Loading

0 comments on commit 8e81ec4

Please sign in to comment.