Skip to content

Commit

Permalink
Adding engineering notation for more consistent display of units
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlynybbled committed May 3, 2018
1 parent 132c64f commit ef464f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
18 changes: 10 additions & 8 deletions examples/gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

root = tk.Tk()

max_speed = 20.0
max_speed = 20000
speed_gauge = tk_tools.Gauge(root,
max_value=max_speed,
label='speed', unit='km/h')
label='speed', unit='m/h')
speed_gauge.grid(row=0, column=0, sticky='news')


tach_gauge = tk_tools.Gauge(root,
max_value=8.0,
label='tach', unit='kRPM',
max_value=8000,
label='tach', unit='RPM',
divisions=10)
tach_gauge.grid(row=1, column=0, sticky='news')

strange_gauge = tk_tools.Gauge(root,
max_value=30.0,
max_value=30000,
label='strange', unit='blah',
divisions=3)
strange_gauge.grid(row=2, column=0, sticky='news')
Expand All @@ -30,12 +30,14 @@
def update_gauge():
global count, up

increment = 30

if up:
count += 1.0
count += increment
if count > max_speed:
up = False
else:
count -= 1.0
count -= increment

if count <= 0.0:
up = True
Expand All @@ -44,7 +46,7 @@ def update_gauge():
tach_gauge.set_value(count)
strange_gauge.set_value(count)

root.after(200, update_gauge)
root.after(50, update_gauge)


root.after(100, update_gauge)
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
except ImportError:
pass

requirements = []
requirements = [
'engineering-notation >= 0.5'
]
with open('requirements.txt', 'r') as f:
for line in f.readlines():
requirements.append(line.strip())
Expand Down
3 changes: 2 additions & 1 deletion tk_tools/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import logging
from decimal import Decimal
from engineering_notation import EngNumber

try:
from tk_tools.images import rotary_scale, \
Expand Down Expand Up @@ -300,7 +301,7 @@ def set_value(self, value):
elif value >= self._max_value:
value = self._max_value * 0.99

self._value = value
self._value = EngNumber(value)

self._redraw()

Expand Down
2 changes: 1 addition & 1 deletion tk_tools/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.8.1'
__version__ = '0.8.2'

0 comments on commit ef464f1

Please sign in to comment.