1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
| #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
import sys
from Tkinter import *
import Tkinter
import time
import threading
###############################################################################
class FoggingThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.encore = True
def run(self):
print "FoggingThread commence proprement"
time.sleep(2)
print "et se termine"
def stop(self):
print "FoggingThread a ete oblige de s'arreter et a rechanger le pin"
self.encore = False
###############################################################################
class WateringThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.encore = True
def run(self):
print "WateringThread commence proprement je change le pin"
time.sleep(1)
if Cmd.Radioarrosage.get() == 3: # si je n'ai pas fait "On" ou "Off" # self.Cmd renverrait à WateringThread, et Cmd n'est pas défini comme variable globale
print "je peux faire passer la pin à 0 et éteindre"
print "WateringThread s'arrete facile et rechange le pin"
#print cmd.Radioarrosage.get()
print "WateringThread fin de test"
def stop(self):
print "WateringThread a ete oblige de s'arreter et a rechanger le pin"
self.encore == False
###############################################################################
class General(Tkinter.Tk):
def __init__(self, parent):
Tkinter.Tk.__init__(self, parent)
self.parent = parent
self.title('Menu')
self.grid()
self.Bouton_Menu1 = Tkinter.Button(self,text='Actions',font=('bold'),fg='black', bg='pink', activebackground='red', command = self.Menu1)
self.Bouton_Menu1.grid(column=1,row=0, rowspan=1, columnspan=1, sticky='EWNS')
self.Bouton_Menu2 = Tkinter.Button(self,text='Tools',font=('bold'),fg='black', bg='pink', activebackground='red', command = self.Menu2)
self.Bouton_Menu2.grid(column=2,row=0, rowspan=1,columnspan=1, sticky='EWNS')
self.Bouton_Parameters = Tkinter.Button(self,text='Par.',font=('bold'),fg='black', bg='pink', activebackground='red', command = self.Menu3)
self.Bouton_Parameters.grid(column=3,row=0, sticky='EWNS')
def Menu1(self):
self.Cmd= Commandes()
#self.destroy()
def Menu2(self):
self.Outils = Tools()
#self.destroy()
def Menu3(self):
self.Par = Parameters()
#self.destroy()
###############################################################################
class Commandes (Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Commandes")
self.Radioarrosage = IntVar(self)
self.fog = IntVar()
self.RadiobrumisationOn = Radiobutton(self, text='\n on \n',font=('bold'), variable=self.fog, value=1, indicatoron =0,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchOnBrumisation)
self.RadiobrumisationOff = Radiobutton(self, text='\noff\n', font=('bold'),variable=self.fog, value=2, indicatoron =0,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchOffBrumisation)
self.RadiobrumisationDeuxMin = Radiobutton(self, text='\ntimer\n',font=('bold'), variable=self.fog, value=3, indicatoron =0,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchDeuxMinBrumisation)
self.Bouton_brumisation = Tkinter.Button(self,text='Fogging',font=('bold', 15),fg='black', bg='lightblue', activebackground='red')
self.Bouton_brumisation.grid(column=0,row=10,columnspan=6, sticky='EW')
self.RadiobrumisationOn.grid(column=0,row=11,columnspan=2,sticky='EW')
self.RadiobrumisationOff.grid(column=2,row=11,columnspan=2,sticky='EW')
self.RadiobrumisationDeuxMin.grid(column=4,row=11, columnspan=2,sticky='EW')
self.RadioarrosageOn = Radiobutton(self, text='\non\n',font=('bold'), variable= self.Radioarrosage, value=1, indicatoron =0 ,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchOnArrosage )
self.RadioarrosageOff = Radiobutton(self, text='\noff\n',font=('bold'), variable= self.Radioarrosage, value=2, indicatoron =0 ,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchOffArrosage )
self.RadioarrosageCinqMin = Radiobutton(self, text='\ntimer\n', font=('bold'),variable= self.Radioarrosage, value=3, indicatoron =0 ,highlightcolor='blue', background = 'green', activebackground = 'red', command = self.SwitchCinqMinArrosage)
self.Bouton_arrosage = Tkinter.Button(self,text='Watering',font=('bold', 15),fg='white', bg='darkblue', activebackground='red')
self.Bouton_arrosage.grid(column=6,row=10,columnspan=6, sticky='EW')
self.RadioarrosageOn.grid(column=6,row=11,columnspan=2,sticky='EW')
self.RadioarrosageOff.grid(column=8,row=11,columnspan=2,sticky='EW')
self.RadioarrosageCinqMin.grid(column=10,row=11,columnspan=2,sticky='EW')
self.Bouton_Back1 = Tkinter.Button(self,text='BACK',font=('bold', 11),fg='white', bg='red', activebackground='red', command= self.back1)
self.Bouton_Back1.grid(column=6,row=13, rowspan=3, columnspan = 6, sticky='EWN')
def back1(self):
Interface = General(None)
#self.destroy()
def SwitchOnBrumisation(self):
self.RadiobrumisationOn.configure(selectcolor='red')
self.Bouton_brumisation.configure(bg='red')
def SwitchOffBrumisation(self):
self.RadiobrumisationOff.configure(selectcolor='red')
self.Bouton_brumisation.configure(bg='red')
def SwitchDeuxMinBrumisation(self):
self.RadiobrumisationDeuxMin.configure(selectcolor='red')
self.Bouton_brumisation.configure(bg='red')
self.RadiobrumisationOn.deselect()
self.RadiobrumisationOff.deselect()
if all(type(i) != FoggingThread for i in threading.enumerate()):
FT=FoggingThread()
FT.start()
#print self.fog.get()
def SwitchOnArrosage(self):
self.RadioarrosageOn.configure(selectcolor='red')
self.Bouton_arrosage.configure(bg='red', fg='black')
print self.Radioarrosage.get()
def SwitchOffArrosage(self):
self.RadioarrosageOff.configure(selectcolor='red')
self.Bouton_arrosage.configure(bg='red',fg='black')
print self.Radioarrosage.get()
def SwitchCinqMinArrosage(self):
self.RadioarrosageCinqMin.configure(selectcolor='red')
self.Bouton_arrosage.configure(bg='red',fg='black')
self.RadioarrosageOn.deselect()
self.RadioarrosageOff.deselect()
#print self.Radioarrosage.get()
if all(type(i) != WateringThread for i in threading.enumerate()):
WT=WateringThread()
WT.start()
###############################################################################
class Tools (Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Tools")
self.Led = IntVar(self)
self.RadioLedsOn = Radiobutton(self, text='\non\n', font=('bold'), variable=self.Led, value=1, indicatoron =0 ,highlightcolor='blue', background = 'green', activebackground = 'red' )
self.RadioLedsOff = Radiobutton(self, text='\noff\n', font=('bold'),variable=self.Led, value=2, indicatoron =0,highlightcolor='blue', background = 'green', activebackground = 'red' )
self.Bouton_Leds = Tkinter.Button(self,text='\nLeds\n',fg='black', font=('bold', 10),bg='yellow', activebackground='red')
self.Bouton_Leds.grid(column=0,row=0,columnspan=2, sticky='EWNS')
self.RadioLedsOn.grid(column=0,row=1,sticky='EWNS')
self.RadioLedsOff.grid(column=1,row=1,sticky='EWNS')
self.Bouton_Back2 = Tkinter.Button(self,text='\nBACK\n',fg='white',font=('bold', 10), bg='red', activebackground='red', command= self.back2)
self.Bouton_Back2.grid(column=10,row=3,rowspan=4,columnspan = 3, sticky='EWN')
def back2(self):
Interface = General(None)
#self.destroy()
def SwitchOnLeds(self):
self.RadioLedsOn.configure(selectcolor='red')
self.Bouton_Leds.configure(bg='red')
def StopLeds (self):
self.RadioLedsOn.deselect()
self.RadioLedsOff.deselect()
self.Bouton_Leds.configure(bg='yellow')
###############################################################################
###############################################################################
###############################################################################
###############################################################################
class Parameters (Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Parameters")
self.ValeurHourOn = StringVar(self)
self.ValeurHourOn.set(2)
self.SpinValeurHourOn = StringVar(self)
self.SpinValeurHourOn.set('10')
self.HourOn = StringVar(self)
self.HourOn.set("Time On\n"+str(self.ValeurHourOn.get())+'h')
self.LabelHourOn=Label(self,textvariable= self.HourOn, bg='yellow').grid(column=0,row=0,columnspan=2, sticky='EW')
self.boiteHourOn = Spinbox(self,from_=0.10,to=23.50,increment=0.10,font=('bold', 13),textvariable=self.SpinValeurHourOn,width=5)
self.boiteHourOn.grid(column=0,row=1,columnspan=1, rowspan = 2, sticky='EW')
self.Bouton_ValidHourOn = Button(self,text='ok',font=('bold'),fg='black', bg='white', activebackground='red', command = self.HorairesOn)
self.Bouton_ValidHourOn.grid(column=1,row=1, sticky='EWS',rowspan = 2)
self.Bouton_Back3 = Tkinter.Button(self,text='Back',fg='white', bg='red',font=('bold',14), activebackground='red', command= self.back3)
self.Bouton_Back3.grid(column=0,row=9,rowspan=2, columnspan = 8, sticky='EWN')
def HorairesOn(self):
self.HourOn.set("Time On\n"+str(self.SpinValeurHourOn.get())+'h')
def back3(self):
Interface = General(None)
#self.destroy()
###############################################################################
#if __name__ == '__main__':
Interface = General(None)
Interface.title('Menu')
Interface.mainloop() |