Skip to content

Commit

Permalink
Merge pull request #11 from AokiAhishatsu/master
Browse files Browse the repository at this point in the history
RotaryScale constructor changes + new imgs
  • Loading branch information
slightlynybbled committed Oct 18, 2017
2 parents ef0998b + 4be0e5d commit 465d5df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Binary file added tk_tools/img/rotary-gauge-bar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tk_tools/img/rotary-gauge-volt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 14 additions & 8 deletions tk_tools/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RotaryScale(Dial):
"""
Shows a rotary scale, much like a speedometer.
"""
def __init__(self, parent, max_value=100.0, size=100, unit='', **options):
def __init__(self, parent, max_value=100.0, size=100, unit=' u', img_data="", needle_color='blue', needle_thickness=0, **options):
"""
Initializes the RotaryScale object
Expand All @@ -54,16 +54,19 @@ def __init__(self, parent, max_value=100.0, size=100, unit='', **options):
self.max_value = float(max_value)
self.size = size
self.unit = unit
self.needle_color = needle_color
self.needle_thickness = needle_thickness

self.canvas = tk.Canvas(self, width=self.size, height=self.size)
self.canvas.grid(row=0)
self.readout = tk.Label(self, text='-{}'.format(self.unit))
self.readout.grid(row=1)

this_path = os.path.abspath(os.path.dirname(__file__))
img_path = os.path.join(this_path, 'img/rotary-scale.png')
self.image = tk.PhotoImage(file=img_path)
self.image = self.image.subsample(int(200/self.size), int(200/self.size))
if img_data:
self.image = tk.PhotoImage(data=img_data)
else:
self.image = tk.PhotoImage(file=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'img/rotary-scale.png'))
self.image = self.image.subsample(int(200 / self.size), int(200 / self.size))

initial_value = 0.0
self.set_value(initial_value)
Expand All @@ -86,14 +89,17 @@ def set_value(self, number: float):

center = cmath.rect(0, 0)
outer = cmath.rect(radius, angle_in_radians)
if self.needle_thickness == 0:
line_width = int(5 * self.size / 200)
line_width = 1 if line_width < 1 else line_width
else:
line_width = self.needle_thickness

line_width = int(5 * self.size/200)
line_width = 1 if line_width < 1 else line_width
self.canvas.create_line(
*self.to_absolute(center.real, center.imag),
*self.to_absolute(outer.real, outer.imag),
width=line_width,
fill='blue'
fill=self.needle_color
)

self.readout['text'] = '{}{}'.format(number, self.unit)
Expand Down

0 comments on commit 465d5df

Please sign in to comment.