Skip to content

Commit

Permalink
Add long form abb, new units, setting to turn off helper text
Browse files Browse the repository at this point in the history
  • Loading branch information
deefrawley committed Apr 12, 2023
1 parent bccc56f commit abfb3a3
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 159 deletions.
14 changes: 8 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 deefrawley
Copyright (c) 2023 deefrawley

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,8 +20,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Graduated Cylinder icon by AS Design from the Noun Project
area icon by matteo manenti from the Noun Project
distance icon by Anthony Ledoux from the Noun Project
Weight icon by Adrien Coquet from the Noun Project
Temperature icon by Alexander Skowalsky from the Noun Project
Graduated Cylinder icon by AS Design from Noun Project
Area icon by matteo manenti from Noun Project
Distance icon by Anthony Ledoux from Noun Project
Weight icon by Adrien Coquet from Noun Project
Temperature icon by Alexander Skowalsky from Noun Project
Speed icon by Fahmi Somdi Std from Noun Project
Energy icon by Greg Cresnar from Noun Project
117 changes: 110 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
# General Converter (Flow.Launcher.GenConvert)

General weight, volume, distance, area, temperature converter for the [Flow Launcher](https://github.com/Flow-Launcher/Flow.Launcher)
General weight, volume, distance, area, temperature, speed and energy converter for the [Flow Launcher](https://github.com/Flow-Launcher/Flow.Launcher)

### About

### Requirements

Python 3.5 or later. As of Flow Launcher v1.8, Flow should take care of the installation of Python for you if it is not on your system.
Python 3.9 or later. As of Flow Launcher v1.8, Flow should take care of the installation of Python for you if it is not on your system.

### Installing

Expand All @@ -29,7 +29,10 @@ Currently English and Chinese language supported. Edit the .env file to change t
| ------------------------------------------------------------- | -------------------------------------------------- |
| `gc <amount> <from unit abbreviation> <to unit abbreviation>` | Convert the amount of the from unit to the to unit. |

Just entering the keyword will give you the full list of units to choose from in Flow.
The from and to unit are case sensitive.

Just entering the keyword will give you the full list of units to choose from in Flow. If you want to remove the keyword for this plugin and have it return
results when you simply start entering a number then go to the Plugin settings and turn this helper text off.

Entering the keyword, amount and from unit will give you a subset list of units the from unit can be converted to
#### Units
Expand All @@ -41,10 +44,10 @@ The following units and their abbreviations can be used (each table can only con
<th>Subject</th>
<th>Unit</th>
<th>Abbreviation</th>
<th rowspan="9" align="center"><img src="assets/Distance.ico" alt="Distance Logo"></th>
<th rowspan="10" align="center"><img src="assets/Distance.ico" alt="Distance Logo"></th>
</tr>
<tr>
<td rowspan="8" align="center"> Distance</td>
<td rowspan="9" align="center"> Distance</td>
<td>millimetre</td>
<td>mm</td>
</tr>
Expand All @@ -56,6 +59,10 @@ The following units and their abbreviations can be used (each table can only con
<td>metre</td>
<td>m</td>
</tr>
<tr>
<td>decimetre</td>
<td>dm</td>
</tr>
<tr>
<td>kilometre</td>
<td>km</td>
Expand Down Expand Up @@ -83,10 +90,10 @@ The following units and their abbreviations can be used (each table can only con
<th>Subject</th>
<th>Unit</th>
<th>Abbreviation</th>
<th rowspan="189" align="center"><img src="assets/Volume.ico" alt="Volume Logo"></th>
<th rowspan="27" align="center"><img src="assets/Volume.ico" alt="Volume Logo"></th>
</tr>
<tr>
<td rowspan="17" align="center">Volume</td>
<td rowspan="26" align="center">Volume</td>
<td>millilitre</td>
<td>ml</td>
</tr>
Expand All @@ -98,6 +105,10 @@ The following units and their abbreviations can be used (each table can only con
<td>litre</td>
<td>l</td>
</tr>
<tr>
<td>decalitre</td>
<td>decal</td>
</tr>
<tr>
<td>pint US</td>
<td>pt</td>
Expand Down Expand Up @@ -154,6 +165,38 @@ The following units and their abbreviations can be used (each table can only con
<td>fluid ounce Imperial</td>
<td>flozimp</td>
</tr>
<tr>
<td>cubic decimetre</td>
<td>dm3</td>
</tr>
<tr>
<td>cubic millimetre</td>
<td>mm3</td>
</tr>
<tr>
<td>cubic centimetre</td>
<td>cm3</td>
</tr>
<tr>
<td>cubic metre</td>
<td>m3</td>
</tr>
<tr>
<td>cubic inch</td>
<td>in3</td>
</tr>
<tr>
<td>cubic feet</td>
<td>ft3</td>
</tr>
<tr>
<td>bushel UK</td>
<td>buuk</td>
</tr>
<tr>
<td>bushel US</td>
<td>buus</td>
</tr>
</table>

<table>
Expand Down Expand Up @@ -258,6 +301,66 @@ The following units and their abbreviations can be used (each table can only con
</tr>
</table>

<table>
<tr>
<th>Subject</th>
<th>Unit</th>
<th>Abbreviation</th>
<th rowspan="4" align="center"><img src="assets/Speed.ico" alt="Speed Logo"></th>
</tr>
<tr>
<td rowspan = "3" align="center">Speed</td>
<td>kilometres per hour</td>
<td>km/h</td>
</tr>
<tr>
<td>miles per hour</td>
<td>mp/h</td>
</tr>
<tr>
<td>knots</td>
<td>kt</td>
</tr>
</table>

<table>
<tr>
<th>Subject</th>
<th>Unit</th>
<th>Abbreviation</th>
<th rowspan="8" align="center"><img src="assets/Energy.ico" alt="Energy Logo"></th>
</tr>
<tr>
<td rowspan = "7" align="center">Energy</td>
<td>calories</td>
<td>cal</td>
</tr>
<tr>
<td>kilocalories</td>
<td>kcal</td>
</tr>
<tr>
<td>kilojoules</td>
<td>kJ</td>
</tr>
<tr>
<td>megajoules</td>
<td>MJ</td>
</tr>
<tr>
<td>gigajoules</td>
<td>Gj</td>
</tr>
<tr>
<td>kilowatt hours</td>
<td>kWh</td>
</tr>
<tr>
<td>British thermal units</td>
<td>BTU</td>
</tr>
</table>

### Problems, errors and feature requests

Open an issue in this repo.
1 change: 0 additions & 1 deletion SettingsTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ body:
Convert between different types of units.
- type: checkbox
attributes:
attributes:
name: show_helper_text
label: "Show helper text of what can be converted"
defaultValue: "true"
Expand Down
Binary file added assets/Energy.ico
Binary file not shown.
Binary file added assets/Energy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Speed.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "General Converter",
"Description": "General weights and measures converter",
"Author": "deefrawley",
"Version": "1.1.4",
"Version": "2.0.0",
"Language": "python",
"Website": "https://github.com/deefrawley/Flow.Launcher.Plugin.GenConvert",
"IcoPath": "assets/favicon.ico",
Expand Down
20 changes: 9 additions & 11 deletions plugin/general_converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import locale
import decimal
import textwrap
import re
import units as gc_units
Expand All @@ -23,9 +22,11 @@ def query(self, query):
all_units = get_all_units()
self.add_item(
title=_("General Converter"),
subtitle=_("<Hotkey> <Amount> <Source unit> <Destination unit>"),
subtitle=_(
"<Hotkey> <Amount> <Source unit - case sensitive> <Destination unit - case sensitive>"
),
)
if not self.settings.get("show_helper_text"):
if self.settings.get("show_helper_text"):
for cat in all_units:
title = str(cat[0])
subtitle = ", ".join([str(elem) for elem in cat[1:]])
Expand All @@ -50,18 +51,15 @@ def query(self, query):
)
# Keyword and first unit to convert from - show what it can be converted to
elif len(args) == 2:
hints = get_hints_for_category(args[1].lower())
hints = get_hints_for_category(args[1])
self.add_item(
title=_("Available conversions"),
subtitle=(f"{args[0]} {args[1]} to {', '.join(hints)}"),
)
# Keyword and two units to convert from and to - try to convert
elif len(args) == 3:
try:
# Units are currently case insensitive. May need to change this if in future new units
# with official upper case shorthand are catered for
args[1] = args[1].lower()
args[2] = args[2].lower()
# Units are case sensitive.
do_convert = gen_convert(float(args[0]), args[1], args[2])
if "Error" in do_convert:
if do_convert["Error"] == _("To and from unit is the same"):
Expand Down Expand Up @@ -132,7 +130,7 @@ def get_hints_for_category(from_unit: str):
# Find the category it's in
for u in gc_units.units:
for u2 in gc_units.units[u]:
if u2[0] == from_unit:
if u2[0] == from_unit or u2[1] == from_unit or u2[2] == from_unit:
category = str(u)
for uu in gc_units.units[category]:
if uu[0] != from_unit:
Expand Down Expand Up @@ -176,9 +174,9 @@ def gen_convert(amount: float, from_unit: str, to_unit: str):
return conversions
for u in gc_units.units:
for u2 in gc_units.units[u]:
if u2[0] == from_unit:
if u2[0] == from_unit or u2[1] == from_unit or u2[2] == from_unit:
found_from = u2
if u2[0] == to_unit:
if u2[0] == to_unit or u2[1] == to_unit or u2[2] == to_unit:
found_to = u2
# If we haven't both in the same category, reset
if found_to and found_from:
Expand Down
Loading

0 comments on commit abfb3a3

Please sign in to comment.