Skip to content

Commit

Permalink
Adding Gauge documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlynybbled committed May 2, 2018
1 parent a1adec5 commit 61e3c8a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/canvas_widgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ These widgets provide visual feedback to the user using the canvas.
.. autoclass:: canvas.RotaryScale
:members:

``Gauge``
---------

.. image:: img/gauges.png

.. autoclass:: canvas.Gauge
:members:

``Graph``
---------

Expand Down
Binary file added docs/img/gauges.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions examples/gauge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import tkinter as tk
import tk_tools


root = tk.Tk()

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


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

speed_gauge.set_value(132.1)
tach_gauge.set_value(4.6)

root.mainloop()
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
# provide correct path for version
__version__ = None
here = os.path.dirname(os.path.dirname(__file__))
exec(open(os.path.join(here, 'tk_tools/version.py')).read())

try:
exec(open(os.path.join(here, 'tk_tools/version.py')).read())
except FileNotFoundError:
# this is the path when installing into venv through pycharm
exec(open(os.path.join(here, 'tk_tools/tk_tools/version.py')).read())

# archive the image files into 'tk_tools/images.py'
try:
Expand Down
4 changes: 2 additions & 2 deletions tk_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tk_tools.canvas import Dial, RotaryScale, Graph, Led
from tk_tools.canvas import Dial, RotaryScale, Gauge, Graph, Led
from tk_tools.groups import EntryGrid, LabelGrid, \
KeyValueEntry, SpreadSheetReader, ButtonGrid, \
Calendar, MultiSlotFrame
Expand All @@ -10,7 +10,7 @@


__all__ = [
'Dial', 'RotaryScale', 'Graph', 'Led',
'Dial', 'RotaryScale', 'Gauge', 'Graph', 'Led',
'EntryGrid', 'LabelGrid', 'ButtonGrid', 'KeyValueEntry',
'SpreadSheetReader', 'SmartOptionMenu', 'SmartSpinBox',
'SmartCheckbutton', 'Calendar', 'MultiSlotFrame',
Expand Down
23 changes: 19 additions & 4 deletions tk_tools/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ def _draw_background(self, divisions=10):


class Gauge(ttk.Frame):
"""
Shows a gauge, much like the RotaryGauge::
gauge = tk_tools.Gauge(root, max_value=100.0, label='speed', unit='km/h')
gauge.grid()
gauge.set_value(10)
:param parent: tkinter parent frame
:param width: canvas width
:param height: canvas height
:param min_value: the minimum value
:param max_value: the maximum value
:param label: the label on the scale
:param unit: the unit to show on the scale
"""
def __init__(self, parent, width=200, height=100, min_value=0.0, max_value=100.0, label='', unit=''):
self._parent = parent
self._width = width
Expand All @@ -195,8 +211,7 @@ def _redraw(self):
self._canvas.delete('all')

max_angle = 120.0
max_percent = 100.0
value_as_percent = self._value / max_percent
value_as_percent = self._value / (self._max_value - self._min_value)
value = int(max_angle * value_as_percent)

# 1/8th tick marks
Expand Down Expand Up @@ -257,7 +272,7 @@ def _redraw(self):
start=150, extent=-120, width=5,
outline='black')

def set(self, value):
def set_value(self, value):
if value < self._min_value:
value = self._min_value
elif value >= self._max_value:
Expand Down Expand Up @@ -514,7 +529,7 @@ def to_yellow(self, on: bool=False):
def test():
global value
value += 1
g.set(value)
g.set_value(value)
root.after(100, test)


Expand Down

0 comments on commit 61e3c8a

Please sign in to comment.