Skip to content

Commit

Permalink
CMD+C copies result without thousands separator. Closes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jan 26, 2019
1 parent 03f9c60 commit 69e04a1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Usage
-----

- `conv <quantity> <from unit> [<to unit>]` — Perform a conversion
- `` or `⌘C` — Copy the result to the pasteboard
- `` — Copy the result to the pasteboard
- `⌘C` — Copy result to pasteboard without thousands separator
- `⌘↩` — Add/remove destination unit as default for this dimensionality
- `⌘L` — Show result in Alfred's Large Type window
- `convinfo` — View help file and information about the workflow, or edit custom units and active currencies
Expand Down
21 changes: 18 additions & 3 deletions src/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ def formatted(self, n, unit=None):

return num

def formatted_no_thousands(self, n, unit=None):
"""Format number with decimal separator only."""
fmt = u'{{:0.{:d}f}}'.format(self._decimal_places(n))
num = fmt.format(n)
# log.debug('n=%r, fmt=%r, num=%r', n, fmt, num)
num = num.replace('.', '||point||')
num = num.replace('||point||', self.decimal_separator)

if unit:
num = u'{} {}'.format(num, unit)

return num


class Conversion(object):
"""Results of a conversion.
Expand Down Expand Up @@ -577,13 +590,15 @@ def convert(query):
DYNAMIC_DECIMALS)
wf.setvar('query', query)
for conv in results:
value = copytext = f.formatted(conv.to_number, conv.to_unit)
value = arg = f.formatted(conv.to_number, conv.to_unit)
copytext = f.formatted_no_thousands(conv.to_number, conv.to_unit)
if not COPY_UNIT:
copytext = f.formatted(conv.to_number)
arg = f.formatted(conv.to_number)
copytext = f.formatted_no_thousands(conv.to_number)

it = wf.add_item(value,
valid=True,
arg=copytext,
arg=arg,
copytext=copytext,
largetext=value,
icon='icon.png')
Expand Down
8 changes: 5 additions & 3 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ variables={allvars}</string>
Based on the awesome Pint library.
In addition to all units supported by Pint, all the currencies supported by Yahoo! Finance and cryptocurrencies supported by CryptoCompare.com are supported.
In addition to all units supported by Pint, almost all the currencies supported by OpenExchangeRates.org and cryptocurrencies supported by CryptoCompare.com are supported.
You can also add your own custom units.
Expand All @@ -499,9 +499,11 @@ Configuration
COPY_UNIT determines whether the unit is also copied when you press CMD+C. 0 or no value means the unit won't be copied. Any other value means the unit will also be copied.
CURRENCY_DECIMAL_PLACES overrides DECIMAL_PLACES (see below) for currency conversion.
DECIMAL_PLACES is the number of decimal places to show in conversion results.
DECIMAL_SEPARATOR is the character used to separate whole numbers from decimal fraction when parsing and outputting numbers.
DECIMAL_SEPARATOR is the character used to separate whole numbers from decimal fraction when parsing input and displaying output (see also THOUSANDS_SEPARATOR below).
DYNAMIC_DECIMALS is whether to dynamically increase the number of decimal places shown until the result is non-zero. Set to 0 or empty to turn off.
Expand Down Expand Up @@ -643,7 +645,7 @@ UPDATE_INTERVAL is the number of minutes between exchange rate updates.</string>
<string>APP_KEY</string>
</array>
<key>version</key>
<string>3.5.1</string>
<string>3.5.2</string>
<key>webaddress</key>
<string></string>
</dict>
Expand Down

0 comments on commit 69e04a1

Please sign in to comment.