beurk beurk
This commit is contained in:
parent
2b73698aef
commit
499944159f
30
chap/Python.tex
Normal file
30
chap/Python.tex
Normal file
@ -0,0 +1,30 @@
|
||||
\chapter{Python} \label{chap:Python} \index{Python}
|
||||
|
||||
|
||||
|
||||
\section{Pourquoi je n'aime pas Python}
|
||||
|
||||
Depuis des lustres, autour de moi, je vois de plus en plus de
|
||||
gens faire du code en Python,
|
||||
certains même font de choses très avancées.
|
||||
Et beaucoup de ces gens essayent de me convaincre que c'est
|
||||
un langage vraiment trop bien, trop moderne, trop dans la
|
||||
\textit{vibe} du devops, battery included, toussa.
|
||||
Quelques uns d'entre eux vont même jusqu'à me parler d'un
|
||||
certain \textbf{canard} qui faciliterait bien la vie
|
||||
des preogrammeurs.
|
||||
|
||||
Je ne suis pas convaincu.
|
||||
|
||||
|
||||
|
||||
\section{Mais quand même...}
|
||||
|
||||
\begin{figure}[h]
|
||||
\begin{center}
|
||||
\includegraphics[scale=0.75]{chap/chronometre}
|
||||
\caption{Chronometre}
|
||||
\end{center}
|
||||
\end{figure}
|
||||
|
||||
|
BIN
chap/chronometre.png
Normal file
BIN
chap/chronometre.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
79
code/chronometre.py
Executable file
79
code/chronometre.py
Executable file
@ -0,0 +1,79 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from Tkinter import *
|
||||
import time, math
|
||||
|
||||
class StopWatch(Frame):
|
||||
""" Implement a stopwatch frame widget """
|
||||
msec = 420
|
||||
def __init__(self, parent=None, **kw):
|
||||
Frame.__init__(self, parent, kw)
|
||||
self._start = 0.0
|
||||
self._elapsed = 0.0
|
||||
self._running = False
|
||||
self.timestr = StringVar()
|
||||
self.makeWidgets()
|
||||
|
||||
def makeWidgets(self):
|
||||
l = Label(self, textvariable=self.timestr,
|
||||
font = "Helvetica 36 bold",
|
||||
bg = "Grey20", fg = "Yellow",
|
||||
padx = 30, pady = 30)
|
||||
self._setTime(self._elapsed)
|
||||
l.pack(fill=X, expand=YES, pady=0, padx=0)
|
||||
|
||||
def _update(self):
|
||||
self._elapsed = time.time() - self._start
|
||||
self._setTime(self._elapsed)
|
||||
self._timer = self.after(self.msec, self._update)
|
||||
|
||||
def _setTime(self, elap):
|
||||
minutes = int(elap/60)
|
||||
seconds = int(elap - (minutes*60.0))
|
||||
fl = math.floor(elap)
|
||||
hseconds = int((elap - fl)*100)
|
||||
self.timestr.set('%03dm%02d.%02d' % \
|
||||
(minutes, seconds, hseconds))
|
||||
def Start(self):
|
||||
if not self._running:
|
||||
self._start = time.time() - self._elapsed
|
||||
self._update()
|
||||
self._running = True
|
||||
def Stop(self):
|
||||
if self._running:
|
||||
self.after_cancel(self._timer)
|
||||
self._elapsed = time.time() - self._start
|
||||
self._setTime(self._elapsed)
|
||||
self._running = False
|
||||
def Reset(self):
|
||||
""" reset the stopwath to 000m00.00 """
|
||||
self._start = time.time()
|
||||
self._elapsed = 0.0
|
||||
self._setTime(self._elapsed)
|
||||
def Dump(self):
|
||||
""" Display internals variables """
|
||||
print "start = ", self._start
|
||||
print "elapsed = ", self._elapsed
|
||||
print "refresh = ", self.msec
|
||||
print "running = ", self._running
|
||||
# print "timestr = ", self.timestr
|
||||
def About(self):
|
||||
print "A kludge by tTh"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
root = Tk()
|
||||
root.title("Chronometre")
|
||||
sw = StopWatch(root)
|
||||
sw.pack(side=TOP)
|
||||
Button(root, text='Start', command=sw.Start).pack(side=LEFT)
|
||||
Button(root, text='Stop', command=sw.Stop).pack(side=LEFT)
|
||||
Button(root, text='Reset', command=sw.Reset).pack(side=LEFT)
|
||||
Button(root, text='Dump', command=sw.Dump).pack(side=LEFT)
|
||||
Button(root, text='Quit', command=root.quit).pack(side=LEFT)
|
||||
root.mainloop()
|
||||
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user