Skip to content

Commit

Permalink
Merge pull request #76 from ashu-tosh-kumar/allow-copying-the-meaning-2
Browse files Browse the repository at this point in the history
Allow copying the meaning 2
  • Loading branch information
ashu-tosh-kumar authored Mar 17, 2024
2 parents 6b5f13c + 1ac60fe commit af415ef
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
args: ["--settings-path", "pyproject.toml"]
language_version: python3.11

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Easy Dictionary

- [Easy Dictionary](#easy-dictionary)
- [Contributions](#contributions)
- [Installation Instructions](#installation-instructions)
- [Method 1](#method-1)
- [Method 2](#method-2)
- [Usage](#usage)
- [Changelog](#changelog)

This repository provides an offline English Dictionary plugin based on Webster's
Unabridged English Dictionary for [Wox](http://www.wox.one/).

Easy Dictionary Plugin is also available on [Wox's
website](http://www.wox.one/plugin/351)
website](http://www.wox.one/plugin/351).

[Medium](https://at-k.medium.com/how-to-develop-a-wox-plugin-using-python-8f2372281d7)
article detailing about how to develop a Wox plugin with an example of Easy Dictionary.
Expand Down Expand Up @@ -37,12 +45,13 @@ Python's path.

### Method 1

- Install using Wox: `wpm install Easy Dictionary`
- Install using Wox: `wpm install Easy Dictionary`.
![Usage Screenshot1](.sample_images/ed-screenshot3.png)

### Method 2

- Drag and Drop the `Wox.Plugin.eDict.wox` onto the Wox Launcher
- Drag and Drop the `Wox.Plugin.eDict.wox` onto the Wox Launcher.
- To rebuild the above file, run command `sh build.sh`.

## Usage

Expand All @@ -52,3 +61,14 @@ Python's path.
![Usage Screenshot1](.sample_images/ed-screenshot1.png)

![Usage Screenshot2](.sample_images/ed-screenshot2.png)

## Changelog

Unfortunately didn't maintain history before `v2.2.1`.

`2.2.1`

- Add support for copying the meaning on hitting Enter key. Note that we use
[pyperclip](https://github.com/asweigart/pyperclip) to provide cross platform copy
functionality. So, if copy doesn't work on your platform, have a look at `pyperclip`
GitHub `README` to see if you would need to install any tool on your system.
Binary file modified Wox.Plugin.eDict.wox
Binary file not shown.
21 changes: 19 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/bin/bash

# Handle dependencies
# pyperclip
rm -rf lib
mkdir tmp
pip download --dest tmp pyperclip
cd tmp
for file in *.tar.gz; do tar -xvf "$file"; done
mkdir lib
mv */* lib
rm -rf lib/docs
rm -rf lib/tests
rm -rf lib/src/pyperclip.egg-info
mv lib ../
cd ..
rm -rf tmp

# Define the output zip file
OUTPUT_ZIP="Wox.Plugin.eDict.wox"

Expand All @@ -10,7 +26,8 @@ fi

# Define the filenames and folder
FILES=("spell.py" "plugin.json" "main.py" "dictionary_compact_with_words.zip")
FOLDER="icons"
ICON_FOLDER="icons"
LIB_FOLDER="lib"

# Create a new zip file and add files
zip -r "$OUTPUT_ZIP" "${FILES[@]}" "$FOLDER"
zip -r "$OUTPUT_ZIP" "${FILES[@]}" "$ICON_FOLDER" "$LIB_FOLDER"
44 changes: 32 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@
SOFTWARE.
Notes:
-The dictionary_compact_with_words.json file used in this project is modified form of
dictionary_compact.json file sourced from https://github.com/matthewreagan/WebstersEnglishDictionary
that in turn depends upon Project Gutenberg's Webster's Unabridged English Dictionary
https://www.gutenberg.org/ebooks/29765.
-The spell.py file used in this project is sourced from Peter Norvig's website norvig.com
http://norvig.com/spell-correct.html. The file is modified for the current use case.
- Wox documentation on how to create a plugin: http://doc.wox.one/en/plugin/python_plugin.html
- The dictionary_compact_with_words.json file used in this project is modified
form of dictionary_compact.json file sourced from
https://github.com/matthewreagan/WebstersEnglishDictionary that in turn depends
upon Project Gutenberg's Webster's Unabridged English Dictionary
https://www.gutenberg.org/ebooks/29765.
- The spell.py file used in this project is sourced from Peter Norvig's website
norvig.com http://norvig.com/spell-correct.html. The file is modified for the
current use case.
- Wox documentation on how to create a plugin:
http://doc.wox.one/en/plugin/python_plugin.html
"""

from json import load
from typing import Dict, List
from zipfile import ZipFile

from lib.src.pyperclip import copy
from spell import SpellCorrect

# Wox already contains a python env with `wox` library pre-installed
Expand Down Expand Up @@ -74,11 +78,11 @@ def _format_result(self, definitions: str, key: str, max_results: int, correctio
correction_flag (bool): Whether the key is corrected
Returns:
List[Dict[str, str]]: Returns list of results where each result is a dictionary containing `Title`, `SubTitle` and `IcoPath`
List[Dict[str, str]]: Returns list of results where each result is a
dictionary containing `Title`, `SubTitle` and `IcoPath`
"""
results: List[Dict[str, str]] = []
for definition in definitions.split(";")[:max_results]:
# TODO @ashutosh add explanations on why below three rules are added
if definition[0].isdigit():
definition = definition[3:]

Expand All @@ -93,7 +97,12 @@ def _format_result(self, definitions: str, key: str, max_results: int, correctio
pass

# Creating result
result = {"Title": definition, "IcoPath": ICON_PATH}
result = {
"Title": definition,
"IcoPath": ICON_PATH,
"SubTitle": "Press Enter to Copy",
"JsonRPCAction": {"method": "copy_to_clipboard", "parameters": [definition], "dontHideAfterAction": False},
}

# Showing whether the key has been auto-corrected or not
if correction_flag:
Expand All @@ -105,15 +114,17 @@ def _format_result(self, definitions: str, key: str, max_results: int, correctio

return results

# A function named query is necessary, we will automatically invoke this function when user query this plugin
# A function named query is necessary, we will automatically invoke this function
# when user query this plugin
def query(self, key: str) -> List[Dict[str, str]]:
"""Overrides Wox query function to capture user input
Args:
key (str): User search input
Returns:
List[Dict[str, str]]: Returns list of results where each result is a dictionary
List[Dict[str, str]]: Returns list of results where each result is a
dictionary.
"""
results: List[Dict[str, str]] = []
key = key.strip().lower()
Expand All @@ -138,6 +149,15 @@ def query(self, key: str) -> List[Dict[str, str]]:

return results

def copy_to_clipboard(self, data: str) -> None:
"""Copies data to Windows clipboard using `pyperclip.copy` command
Args:
data (str): Data that needs to be copied to clipboard
"""
# No viable and safe option as of now
copy(data)


# Following statement is necessary by Wox
if __name__ == "__main__":
Expand Down
22 changes: 11 additions & 11 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"ID":"0c6569f79d49409e8e5e42e1ec8bb035",
"ActionKeyword":"ed",
"Name":"Easy Dictionary",
"Description":"Provides an offline English Dictionary",
"Author":"ashutosh",
"Version":"2.2.0",
"Language":"python",
"Website":"https://github.com/ashu-tosh-kumar/Wox.Plugin.eDict",
"IcoPath": "icons\\edict.png",
"ExecuteFileName":"main.py"
}
"ID": "0c6569f79d49409e8e5e42e1ec8bb035",
"ActionKeyword": "ed",
"Name": "Easy Dictionary",
"Description": "An offline English dictionary plugin for Wox based on Webster's Unabridged English Dictionary.",
"Author": "ashutosh",
"Version": "2.2.1",
"Language": "python",
"Website": "https://github.com/ashu-tosh-kumar/Wox.Plugin.eDict",
"IcoPath": "icons\\edict.png",
"ExecuteFileName": "main.py"
}
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ exclude = '''
| dist
| migrations
| venv
| lib
| \.history
)/
'''

[tool.isort]
profile = "black"
skip = ["migrations", ".env", "venv", ".local", ".history", ".vscode", "lib"]

[tool.poetry]
name = "easy-dictionary"
version = "2.2.0"
version = "2.2.1"
description = "An offline English dictionary plugin for Wox based on Webster's Unabridged English Dictionary."
authors = ["Ashutosh <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit af415ef

Please sign in to comment.