Create a Wox plugin (Python)

What is #Wox

Win + S is a great launcher running on Windows: http://www.wox.one/

I use Alfred (+ Powerpack) on macOS, but I found it when I was looking for a similar usability launcher in the recently assigned Windows environment. I can create a plugin with C # and Python. , Alfred workflow (although not as flexible) You can do similar extensions.

plugin development

As mentioned above, I'm an Alfred user, so I chose Python because I want to port my own Alfred workflow written in Python. To run the plugin written in Python, I need to install Python 3 separately and tell Wox where I am. Therefore, I feel that the hurdles are a little high in terms of widespread use. Unless there is a particular concern, it seems better to develop in C #.

principle

Click here for official documentation: http://doc.wox.one/en/plugin/create_plugin.html

The point is that Wox passes user input to the plugin, so it's as simple as returning the corresponding result in JSON. The developer receives the string because the helper class makes it good for each language while saying JSON. Just return an array of dicts (for Python). JSONRPC.png

Wox displays the options based on the array returned by the plugin, and a callback is generated for the item selected by the user, so process it (as soon as you open the browser or folder). Select the item that does not contain callback information. Can not. SoWkIImgAStDuGejJYrIqBLJ2C-lKB1IA2nDBQha0h91GW4vfUcPUN1H21UXjYYrk3Id1AOOP0vGi3WZlrmXEIC_Cpcr6DLig2Y6uNdv9PbfSDCH9YKcbsJcvt4vfEQbWDm90000.png

Development procedure

Installation of Python 3

Used by Wox to run the Python plugin. After installation, specify the installation destination from the Wox setting screen.

Decide the working directory

--- git init --Make sure that the previously installed Python 3 works (I used pyenv because I created a development environment on WSL)

Create plugin.json

Create a plugin.json file by referring to Official

{
  "ID": "1AEB702E890911EABAF20C54152B91EC",  //Plugin ID,32 bit UUID
  "ActionKeyword": "sample",                 //Plugin default action keyword
  "Name": "sample plugin",                   //Plugin name
  "Description": "sample plugin",            //Plugin description
  "Author": "kosugi",                        //Plugin Author
  "Version": "1.0.0",                        //Plugin version,must be x.x.x format
  "Language": "python",                      //Plugin language,we support csharp,python and executable now
  "Website": "https://qiita.com/kosugi",     //Plugin website or author website
  "IcoPath": "Images\\icon.png ",             //Plugin icon, relative path to the pluign folder
  "ExecuteFileName": "main.py"               //Execution entry. Dll name for c# plugin, and python file for python plugin
}

--ID is python -c'import uuid; print (uuid.uuid1 (). Hex.upper ())' etc. --Version is played when registering to the official repository unless it is in the format x.x.x as per the document (there is no problem if it works at hand) --IcoPath is often installed under the ʻImages` directory, but there is no problem even if it is directly under it.

wox.py ready

Looking at the Official Sample Program, I read that wox.py is needed, but I don't know the correct procurement method. Probably executed from Wox. When it is done, it may be included in the module search path, but what should I do during development?

Upon examination, it was included in Wox's GitHub repository (it doesn't seem necessary to clone the repository itself).

wget https://raw.githubusercontent.com/Wox-launcher/Wox/master/JsonRPC/wox.py

If wox.py exists when running from Wox, it will be prioritized and should not be included in the archive (described later) or the installation destination.

plugin body

main.py


# -*- coding: utf-8 -*-
from wox import Wox

class Main(Wox):

    def query(self, user_input):
        # user_Returns the result corresponding to input
        return [{
            'Title': 'Displayed on the first line(test: ' + user_input + ')',
            'SubTitle': 'Displayed on the second line',
            'IcoPath': 'Icon displayed on the left.png',
            'JsonRPCAction': {
                'method': 'action', #Method name called at the time of selection
                'parameters': ['Argument 1 passed to method', '2...'],
                'dontHideAfterAction': False
            }
        }]

    def action(self, data1, data2):
        #The item has been selected and will be processed
        pass

if __name__ == '__main__':
    Main()

When the script is executed, the JSON given as a command line argument is interpreted by the Wox class of the wox.py at hand, and the query method is called. Specifically, it is executed as follows.

$ python main.py '{"method": "query", "parameters": ["user intput"]}' | jq
{
  "result": [
    {
      "Title": "Displayed on the first line(test: user intput)",
      "SubTitle": "Displayed on the second line",
      "IcoPath": "Icon displayed on the left.png ",
      "JsonRPCAction": {
        "method": "action",
        "parameters": [
          "Argument 1 passed to method",
          "2..."
        ],
        "dontHideAfterAction": false
      }
    }
  ]
}

If you use the method of executing main.py, you cannot check the callback (here, the behavior when the ʻaction` method is called), so you need to actually install it on Wox and check it, but if you devise it, you can test it. It would be possible to write.

Install on Wox

--Digging a directory with an appropriate name directly under the Plugins directory of the Wox installation destination, and placing plugin.json, main.py and the icon file. --Restart Wox or run Reload Plugin Data from Wox. --Can be called from Wox by entering the ActionKeyword specified in plugin.json

When called via Wox, the display looks like this: sample.png

Registration in plugin repository

If you register an account on http://www.wox.one/plugin, you can register the created plugin. You can search and install the registered plugin from Wox.

For registration, use a ZIP archive of the required files. The extension should be wox instead of zip.

What I made (registered) this time

2020-04-28-09-32-50_Trim.gif

You can search for unicode name and copy the corresponding character to the clipboard, or copy the character corresponding to the code point you entered to the clipboard. You can install it with wpm install Unicodebuilder (query) and wpm install Unicodebuilder, respectively. Alfred Then you can include multiple ActionKeywords in one workflow, but Wox doesn't, so we separated the plugins.

Recommended Posts

Create a Wox plugin (Python)
Create a Python module
Create a Python environment
Create a function in Python
Create a dictionary in Python
Create a python numpy array
Create a directory with python
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
Create a python GUI using tkinter
Create a DI Container in Python
Create a Python environment on Mac (2017/4)
Create a virtual environment with Python!
Create a binary file in Python
Create a python environment on centos
Write a vim plugin in Python
Create a Python general-purpose decorator framework
Create a Kubernetes Operator in Python
5 Ways to Create a Python Chatbot
Create a random string in Python
Create a Python function decorator with Class
Create a new Python numerical calculation project
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
Create a python environment on your Mac
Create a simple GUI app in Python
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a JSON object mapper in Python
[Python] Create a Batch environment using AWS-CDK
[Python] [LINE Bot] Create a parrot return LINE Bot
Create a word frequency counter with Python 3.4
Create a deb file from a python package
[Python] Create a LineBot that runs regularly
[GPS] Create a kml file in Python
Write a simple Vim Plugin in Python 3
Create a frame with transparent background with tkinter [Python]
[Python] List Comprehension Various ways to create a list
Edit Excel from Python to create a PivotTable
Create a Vim + Python test environment in 1 minute
Create a GIF file using Pillow in Python
How to create a Python virtual environment (venv)
Create a C array from a Python> Excel sheet
[python] Create a list of various character types
Create a LINE BOT with Minette for Python
I want to create a window in Python
Create a standard normal distribution graph in Python
How to create a JSON file in Python
Create a virtual environment with conda in Python
Create a New Todoist Task from Python Script
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Create a web map using Python and GDAL
Create a color bar with Python + Qt (PySide)
Steps to create a Twitter bot with python
[Venv] Create a python virtual environment on Ubuntu
Create a simple momentum investment model in Python
Python: Create a class that supports unpacked assignment