Skip to content

Commit 797426d

Browse files
authored
Merge pull request #4 from deefrawley/hint_update
Add conversion hints. Fixes #2. Some language file cleanup. Git ignores a scratch file I use for testing.
2 parents 43c57a5 + f820ebd commit 797426d

File tree

9 files changed

+92
-85
lines changed

9 files changed

+92
-85
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Created by https://www.toptal.com/developers/gitignore/api/python,vscode
22
# Edit at https://www.toptal.com/developers/gitignore?templates=python,vscode
33

4+
### Project Specific ###
5+
scratch.py
6+
47
### Python ###
58
# Byte-compiled / optimized / DLL files
69
__pycache__/

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "General Converter",
55
"Description": "General weights and measures converter",
66
"Author": "deefrawley",
7-
"Version": "1.0.1",
7+
"Version": "1.0.2",
88
"Language": "python",
99
"Website": "https://github.com/deefrawley/Flow.Launcher.Plugin.GenConvert",
1010
"IcoPath": "assets/favicon.ico",
0 Bytes
Binary file not shown.
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# English translations for Flow.plugin.currency.
22
# Copyright (C) 2020 CitizenDee (author)
33
# This file is distributed under the same license as the project.
4-
# CitizenDee <deefrawley@gmail.com>, 2020.
4+
# CitizenDee <deefrawley@gmail.com>, 2021.
55
#
66
msgid ""
77
msgstr ""
8-
"Project-Id-Version: 2.0.0\n"
8+
"Project-Id-Version: 1.0.2\n"
99
"Report-Msgid-Bugs-To: deefrawley@gmail.com\n"
10-
"POT-Creation-Date: 2021-06-07 15:16+1000\n"
10+
"POT-Creation-Date: 2021-08-26 18:04+1000\n"
1111
"PO-Revision-Date: 2020-12-13 20:26+1100\n"
1212
"Last-Translator: CitizenDee <deefrawley@gmail.com>\n"
1313
"Language: en\n"
@@ -18,29 +18,33 @@ msgstr ""
1818
"Content-Transfer-Encoding: 8bit\n"
1919
"Generated-By: Babel 2.9.1\n"
2020

21-
#: plugin/ui.py:49 plugin/ui.py:58
21+
#: plugin/ui.py:42
22+
msgid "Available conversions"
23+
msgstr ""
24+
25+
#: plugin/ui.py:54 plugin/ui.py:63
2226
msgid "Error - {}"
2327
msgstr "Error - {}"
2428

25-
#: plugin/ui.py:50
29+
#: plugin/ui.py:55
2630
msgid "Check documentation for accepted units"
2731
msgstr ""
2832

29-
#: plugin/ui.py:62
33+
#: plugin/ui.py:67
3034
#, fuzzy
3135
msgid "General Converter"
3236
msgstr "Currency Converter"
3337

34-
#: plugin/ui.py:63
38+
#: plugin/ui.py:68
3539
#, fuzzy
3640
msgid "<Hotkey> <Amount> <Source unit> <Destination unit>"
3741
msgstr "<Hotkey> <Amount> <Source currency> <Destination currency>"
3842

39-
#: plugin/utils.py:50
43+
#: plugin/utils.py:65
4044
msgid "To and from unit is the same"
4145
msgstr ""
4246

43-
#: plugin/utils.py:83
47+
#: plugin/utils.py:98
4448
msgid "Problem converting {} and {}"
4549
msgstr ""
4650

57 Bytes
Binary file not shown.
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Chinese translations for PROJECT.
2-
# Copyright (C) 2021 ORGANIZATION
3-
# This file is distributed under the same license as the PROJECT project.
4-
# FIRST AUTHOR <EMAIL@ADDRESS>, 2021.
1+
# English translations for Flow.plugin.currency.
2+
# Copyright (C) 2020 CitizenDee (author)
3+
# This file is distributed under the same license as the project.
4+
# CitizenDee <deefrawley@gmail.com>, 2021.
55
#
66
msgid ""
77
msgstr ""
8-
"Project-Id-Version: PROJECT VERSION\n"
9-
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10-
"POT-Creation-Date: 2021-06-07 15:16+1000\n"
8+
"Project-Id-Version: 1.0.2\n"
9+
"Report-Msgid-Bugs-To: deefrawley@gmail.com\n"
10+
"POT-Creation-Date: 2021-08-26 18:04+1000\n"
1111
"PO-Revision-Date: 2021-06-07 15:16+1000\n"
12-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12+
"Last-Translator: CitizenDee <deefrawley@gmail.com>\n"
1313
"Language: zh\n"
1414
"Language-Team: zh <LL@li.org>\n"
1515
"Plural-Forms: nplurals=1; plural=0\n"
@@ -18,27 +18,31 @@ msgstr ""
1818
"Content-Transfer-Encoding: 8bit\n"
1919
"Generated-By: Babel 2.9.1\n"
2020

21-
#: plugin/ui.py:49 plugin/ui.py:58
21+
#: plugin/ui.py:42
22+
msgid "Available conversions"
23+
msgstr "可用转换"
24+
25+
#: plugin/ui.py:54 plugin/ui.py:63
2226
msgid "Error - {}"
2327
msgstr "错误 - {}"
2428

25-
#: plugin/ui.py:50
29+
#: plugin/ui.py:55
2630
msgid "Check documentation for accepted units"
2731
msgstr "检查文档以获取正确的度量单位"
2832

29-
#: plugin/ui.py:62
33+
#: plugin/ui.py:67
3034
msgid "General Converter"
3135
msgstr "通用单位换算器"
3236

33-
#: plugin/ui.py:63
37+
#: plugin/ui.py:68
3438
msgid "<Hotkey> <Amount> <Source unit> <Destination unit>"
3539
msgstr "<热键> <量> <源单元> <目的地单位>"
3640

37-
#: plugin/utils.py:50
41+
#: plugin/utils.py:65
3842
msgid "To and from unit is the same"
3943
msgstr "源单元和目标单元相同"
4044

41-
#: plugin/utils.py:83
45+
#: plugin/utils.py:98
4246
msgid "Problem converting {} and {}"
4347
msgstr "转换问题 {} 和 {}"
4448

plugin/ui.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ def sendActionMess(self, title: str, subtitle: str, method: str, value: List):
3636
def query(self, param: str) -> List[dict]:
3737
q = param.strip()
3838
args = q.split(" ")
39-
40-
if len(args) == 3:
39+
if len(args) == 2:
40+
hints = plugin.utils.get_hints(args[1].lower())
41+
self.sendNormalMess(
42+
_("Available conversions"),
43+
(f"{args[0]} {args[1]} to {', '.join(hints)}"),
44+
)
45+
elif len(args) == 3:
4146
try:
4247
# Units are currently case insensitive. May need to change this if in future new units
4348
# with official upper case shorthand are catered for

plugin/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,21 @@
4545
}
4646

4747

48+
def get_hints(from_unit):
49+
""" Takes an input unit and returns a list of units it can be converted to """
50+
for u in units:
51+
if u == from_unit:
52+
return [x for x in units[from_unit].keys()]
53+
for u2 in units[u]:
54+
if u2 == from_unit:
55+
c = [x for x in units[u].keys() if x != from_unit]
56+
c.append(u)
57+
return c
58+
return ["no valid units"]
59+
60+
4861
def genConvert(amount, from_unit, to_unit):
62+
""" Convert between units """
4963
conversions = {}
5064
if from_unit == to_unit:
5165
conversions["Error"] = _("To and from unit is the same")

scratch.py

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from plugin.settings import __package_title__, __version__
2-
31
units = {
42
"m": {
53
"mm": 1000,
@@ -11,73 +9,52 @@
119
"mi": 0.0006213712,
1210
},
1311
"ml": {
12+
"gm": 1,
1413
"l": 0.001,
1514
"pt": 0.002113383,
1615
"qt": 0.001056691,
1716
"cup": 0.004226764,
1817
"tbsp": 0.067628224,
1918
"tsp": 0.2028846715942,
2019
"gal": 0.0002641727499999601,
20+
"floz": 0.03381413,
21+
},
22+
"sqm": {
23+
"h": 0.0001,
24+
"ac": 0.0002471052,
25+
"sqcm": 10000,
26+
"sqkm": 1000000,
27+
"sqin": 1550.003,
28+
"sqmi": 0.0000003861022,
29+
"sqft": 10.76391,
30+
"sqyd": 1.19599,
31+
},
32+
"gm": {
33+
"kg": 0.001,
34+
"lb": 0.002205,
35+
"oz": 0.035274,
36+
"st": 0.000157473,
37+
"ton": 0.000001102310999995,
38+
},
39+
# Special case temp C to F - actually handled in code
40+
"c": {
41+
"f": 1.8,
2142
},
2243
}
2344

2445

25-
def genConvert(amount, from_unit, to_unit):
26-
conversions = {}
27-
if from_unit == to_unit:
28-
conversions["Error"] = "To and from unit is the same"
29-
return conversions
30-
# Convert from key unit to sub-unit (e.g. cm to in)gc 1 km mi
31-
elif from_unit in units and to_unit in units[from_unit]:
32-
conversions[to_unit] = units[from_unit][to_unit] * amount
33-
return conversions
34-
# Convert from sub-unit to key unit (e.g. in to cm)
35-
elif to_unit in units and from_unit in units[to_unit]:
36-
conversions[to_unit] = (1 / units[to_unit][from_unit]) * amount
37-
return conversions
38-
# Convert from sub-unit to sub-unit (e.g. in to ft)
39-
else:
40-
for u in units:
41-
to_sub = False
42-
from_sub = False
43-
for u2 in units[u]:
44-
if u2 == to_unit:
45-
to_sub = True
46-
elif u2 == from_unit:
47-
from_sub = True
48-
if to_sub and from_sub:
49-
# Convert via the key unit
50-
key_convert = ((1 / units[u][from_unit]) * amount) * 10
51-
key_sub = units[u][to_unit] * key_convert
52-
print(f"key_convert {amount} {from_unit} = {key_convert}")
53-
print(f"key_sub = {key_sub}")
54-
55-
conversions[to_unit] = (1 / units[u][from_unit]) * (
56-
units[u][to_unit] * amount
57-
)
58-
return conversions
59-
if not to_sub or not from_sub:
60-
conversions["Error"] = "Unit not found"
61-
return conversions
62-
63-
64-
def listUnits():
65-
# Utility function to print out all conversions
66-
print(f"{__package_title__} v{__version__} Units")
67-
print("==============================")
68-
for all_units in units.keys():
69-
print(f"\n{all_units}, ", end="")
70-
for all_to_units in units[all_units].keys():
71-
print(f"{all_to_units}, ", end="")
72-
46+
def get_hints(from_unit):
47+
""" Takes an input unit and returns a list of units it can be converted to """
48+
for u in units:
49+
if u == from_unit:
50+
return [x for x in units[from_unit].keys()]
51+
for u2 in units[u]:
52+
if u2 == from_unit:
53+
c = [x for x in units[u].keys() if x != from_unit]
54+
c.append(u)
55+
return c
56+
return ["no valid units"]
7357

74-
""" result = input(" > ")
75-
q = result.strip()
76-
args = q.split(" ")
77-
result2 = genConvert(float(args[1]), args[2], args[3])
78-
if "Error" in result2:
79-
print(f"Error - {result2['Error']}")
80-
else:
81-
print(f"{args[1]} {args[2]} = {result2[args[3]]:.6f} {args[3]}") """
8258

83-
listUnits()
59+
vv = get_hints("ox")
60+
print(vv)

0 commit comments

Comments
 (0)