PK%N!}lVVtktimer/__init__.py"""Set of timer (stopwatch & countdown) widgets for tkinter""" __version__ = '0.0.1' PK-uNVtktimer/example.pyimport tkinter as tk from tktimer import Countdown if __name__ == "__main__": root = tk.Tk() timer = Countdown(root, unit="seconds", precision=4, prefix="The bomb will explode in ", suffix=" seconds.") timer.grid(row=0, column=0, columnspan=2, sticky="nswe") tk.Button(root, text="START", command=timer.start).grid(row=1, column=0) tk.Button(root, text="PAUSE", command=timer.pause).grid(row=1, column=1) root.mainloop()PK3N<* tktimer/tktimer.pyimport datetime import tkinter as tk UNITS = { "seconds": 1, "minutes": 60, "hours": 3600, "days": 3600 * 24, "weeks": 3600 * 24 * 7, "years": 3600 * 24 * 365.2422 } class HybridLabel(tk.Label): def __init__(self, parent, *args, **kwargs): self.text = kwargs.pop("text", "{}") self.textvariable = kwargs.pop("textvariable", tk.StringVar(parent)) self.textvariable.trace_add("write", self._update_text) super().__init__(parent, *args, **kwargs) self._update_text() def _update_text(self, *args, **kwargs): self.config(text=self.text.format(self.textvariable.get())) class Stopwatch(tk.Frame): def __init__( self, parent, prefix="", suffix="", unit="seconds", update_every=10, precision=2, time_elapsed=0, *args, **kwargs ): super().__init__(parent, *args, **kwargs) self.value = tk.DoubleVar() self.value.set(time_elapsed) self.label = HybridLabel( self, text=prefix + "{{:.{}f}}".format(precision) + suffix, textvariable=self.value, ) self.label.pack(fill="both", expand=True) self.unit = unit self.update_every = update_every self.precision = precision self.time_elapsed = time_elapsed self.starting_point = None self.paused_point = None self.continue_point = None self.paused = False self.been_paused = 0 def start(self): if self.paused: self.paused = False self.continue_point = datetime.datetime.now() self.been_paused += (self.continue_point - self.paused_point).total_seconds() else: self.starting_point = datetime.datetime.now() self._update() def pause(self): self.paused = True self.paused_point = datetime.datetime.now() def _update(self): if self.paused: return diff = ((datetime.datetime.now() - self.starting_point).total_seconds() - self.been_paused + self.time_elapsed) self.value.set(diff / UNITS[self.unit]) self.after(self.update_every, self._update) class Countdown(tk.Frame): def __init__( self, parent, prefix="", suffix="", unit="seconds", beginning=10, update_every=10, precision=2, *args, **kwargs ): super().__init__(parent, *args, **kwargs) self.value = tk.DoubleVar() self.value.set(beginning / UNITS[unit]) self.label = HybridLabel( self, text=prefix + "{{:.{}f}}".format(precision) + suffix, textvariable=self.value, ) self.label.pack(fill="both", expand=True) self.unit = unit self.update_every = update_every self.beginning = beginning self.precision = precision self.paused = False def start(self): if self.paused: self.paused = False self._update() def pause(self): self.paused = True def _update(self): if self.paused or not round(self.value.get(), self.precision): return self.beginning -= self.update_every / 1000 self.value.set(self.beginning / UNITS[self.unit]) self.after(self.update_every, self._update) PKNNtktimer-0.0.1.dist-info/LICENSECopyright (c) 2019 adder46 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HPOtktimer-0.0.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UrPK!HNmW tktimer-0.0.1.dist-info/METADATAVm4_1!h6ZAˡӮXvytqib9l6?-NBGıyfƓ[>J.2`w؍5j6,'nhA!Xմf%| r檕hE^5V i፪q0Jk8;+-*T}Wg;7"Ciw?v^c*EGpkgK;XsQ- Ǽ-g?;'4}GMEcIKE?v )Mx:a%iKA2\aM˜_tBp/h, ?=vXd@#a?y}/%BI"kc wS: j  7Z 3Q7JAnhZz73$q3h[A?Z4.g#~d.3"mHGq|U,Dy9z4G~+Հ̗} ?٣\Qkt((.&qBi*+b4^CL.ۂT–}a5w.'`HbMz>mI S|g{8hyF FxÏAKGt3n}>5В IaנP0S27 ZHg1 Kt qrZv5RRU=^H^_卢$`Zd`Cm']k[|Bݥ2LC-/-+T !ܭXzE8.j^EM&1) `[xc0EZqC=W?ҿQ-dt=ώj>fi$Clߺ4L\X;k8ၩm9$=ORGY9JRp#.c7 ߆ģE9Jc߻>5I$]Sl$F<]PEZ\Է|B4 F6Zˇ.OU:`TX4$V*@kS#$Z)y=2-t3z-فC?7r- q,G7X=!5=_JU)oPK!HCoStktimer-0.0.1.dist-info/RECORDuλv0gpaA-QDX8TߢEvq,cI Y-%@˹KVM#Ćx V8 \Y(MK /jlUCpfz9C3Ǣ>T/nQ^' CJU=\k Ϥ߲ ,b}Yw@xa܌54)dw +}-tuθI|oqu#z}ӯ.4udR@No]G#9ۥ-Bv ` `.5,2ЙrlϹs:>Ek5^uK,%=]0PK%N!}lVVtktimer/__init__.pyPK-uNVtktimer/example.pyPK3N<* utktimer/tktimer.pyPKNNtktimer-0.0.1.dist-info/LICENSEPK!HPOtktimer-0.0.1.dist-info/WHEELPK!HNmW tktimer-0.0.1.dist-info/METADATAPK!HCoStktimer-0.0.1.dist-info/RECORDPK