Skip to content

Commit 20a33ba

Browse files
[unit_converter] v3
1 parent cc0b3b7 commit 20a33ba

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

unit_converter/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import pint
2626
from albert import *
2727

28-
md_iid = "2.3"
28+
md_iid = "3.0"
2929
md_version = "1.8"
3030
md_name = "Unit Converter"
3131
md_description = "Convert between units"
@@ -126,7 +126,7 @@ def formatted_from(self) -> str:
126126
def icon(self) -> str:
127127
"""Return the icon for the result's dimensionality"""
128128
# strip characters from the dimensionality if not alphanumeric or underscore
129-
dimensionality = re.sub(r"[^\w]", "", self.dimensionality)
129+
dimensionality = re.sub(r"\W", "", self.dimensionality)
130130
return f"{dimensionality}.svg"
131131

132132
def __repr__(self):
@@ -345,14 +345,7 @@ class Plugin(PluginInstance, GlobalQueryHandler):
345345

346346
def __init__(self):
347347
PluginInstance.__init__(self)
348-
GlobalQueryHandler.__init__(
349-
self,
350-
id=self.id,
351-
name=self.name,
352-
description=self.description,
353-
synopsis="<amount> <from_unit> to <to_unit>",
354-
defaultTrigger="convert ",
355-
)
348+
GlobalQueryHandler.__init__(self)
356349

357350
self.unit_convert_regex = re.compile(
358351
r"(?P<from_amount>-?\d+\.?\d*)\s?(?P<from_unit>.*)\s(?:to|in)\s(?P<to_unit>.*)",
@@ -361,6 +354,12 @@ def __init__(self):
361354
self.unit_converter = StandardUnitConverter()
362355
self.currency_converter = CurrencyConverter()
363356

357+
def defaultTrigger(self):
358+
return "convert "
359+
360+
def synopsis(self, query):
361+
return "<amount> <from_unit> to <to_unit>"
362+
364363
def handleTriggerQuery(self, query: Query) -> None:
365364
if query_string := query.string.strip():
366365
items = self.match_query(query_string)

0 commit comments

Comments
 (0)