Keypirinha / Keypirinha

A fast keystroke launcher for Windows
http://keypirinha.com
1.05k stars 21 forks source link

Can plugins control search? #484

Open pfmoore opened 3 years ago

pfmoore commented 3 years ago

I have a plugin that searches Python PEPs. If I type PEP 8, the first search hit is PEP 801, with PEP 8 being the second result. Is there a way to prioritise exact matches? I haven't found anything obvious in the API documentation.

Related question, I can't work out how to get my plugin to "remember" previous searches, like the main list does. Is this possible?

dufferzafar commented 3 years ago

@pfmoore the PEP plugin sounds cool. could you share it?

pfmoore commented 3 years ago

Sure. Here it is.

The get_url function uses a call to urlmon.dll via ctypes because at one point I needed that to get past our corporate firewall (Windows API calls worked with our proxy, Python urllib didn't). You can probably just use urllib for normal situations, though.

dufferzafar commented 3 years ago

So you're using set_catalog here. I'm creating my first plugin and am going through the docs, and found that set_suggestions has a sort parameter. Maybe you could use that?

https://keypirinha.com/api/plugin.html#keypirinha.Plugin.set_suggestions

https://keypirinha.com/api/module.html#keypirinha.Sort

ueffel commented 3 years ago

Related question, I can't work out how to get my plugin to "remember" previous searches, like the main list does. Is this possible?

it's all about the ItemHitHint

The get_url function uses a call to urlmon.dll via ctypes because at one point I needed that to get past our corporate firewall (Windows API calls worked with our proxy, Python urllib didn't). You can probably just use urllib for normal situations, though.

Your corporate firewall likely uses a proxy script which is sadly not supported by python's urllib. If you want to use urllib with a proxy from keypirinha, you have to configure the proxy manually first in keypirinha, like this:

[network]
proxy =
    http://127.0.0.1:8080
    https=http://127.0.0.1:8080

See the main configuration file for more information (Keypirinha: Configure)

Then you can use it in the plugin code to get a preconfigured urlopener:

import keypirinha_net as kpn

opener = kpn.build_urllib_opener()
req = urllib.request.Request("<url>")
with opener.open(req) as response:
    text = response.read().decode()
Shani-Dal commented 3 years ago

Joining to pfmoore first question: is there a way to priorities the catalog items? or control which item will appear first when typing a keyword?

I created my own custom plugins and I want them to always have top priority in the catalog. Meaning If one of my plugins fits current typing, it will appear first.

Thanks!