Changeset 744 in ETALON for CLIO/control/CLIO_graphical_interface.py
- Timestamp:
- Nov 2, 2017, 12:38:09 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CLIO/control/CLIO_graphical_interface.py
r691 r744 15 15 import os 16 16 import subprocess 17 import urllib2 17 18 18 19 #from motor_function import * … … 26 27 from clio_constants import * 27 28 28 INSERTED_VALUE1= 400000029 INSERTED_VALUE1=5500000 29 30 INSERTED_VALUE2=5000000 30 31 … … 32 33 threshold_old= 100 33 34 34 ImagesDisplaySize=(600,400) 35 ImagesDisplaySize=(400,300) 36 N_IMAGES_LINES=2 37 N_IMAGES_COLS=3 38 N_IMAGES=N_IMAGES_LINES*N_IMAGES_COLS 35 39 36 40 PROCESSES_REFRESH_INTERVAL=10 37 41 38 42 imageNames=[] 39 imageNames.append(code_directory+"no_data.png") 40 imageNames.append(code_directory+"no_data.png") 43 for iimage in range(N_IMAGES): 44 imageNames.append(code_directory+"no_data.png") 45 46 URI='http://'+IP_POWER_IP+'/Set.cmd' 47 auth_handler=urllib2.HTTPBasicAuthHandler() 48 auth_handler.add_password(realm='IP9258',uri=URI,user='admin',passwd='12345678') 49 opener= urllib2.build_opener(auth_handler) 50 urllib2.install_opener(opener) 41 51 42 52 #This is used for variables that are not updated on each refresh cycle … … 58 68 self.terminate=0 59 69 self.refresh_loop=0 60 print(data_directory)61 70 # canvas for image 62 self.canvas = Canvas(self.parent, width=800, height= 400)71 self.canvas = Canvas(self.parent, width=800, height=800) 63 72 self.frameImages = Frame(self.parent, borderwidth=10) 64 73 self.frameImages.grid(row=1, column=0) 65 74 self.my_images=[] 66 self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[0]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 67 self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 68 self.imageLabel1=Label(self.frameImages,image=self.my_images[0]) 69 self.imageLabel1.pack(side = "left", fill = "both", expand = "yes") 70 self.imageLabel2=Label(self.frameImages,image=self.my_images[1]) 71 self.imageLabel2.pack(side = "right", fill = "both", expand = "yes") 75 self.imageLabel=[] 76 self.newImage=[] 77 for iline in range(N_IMAGES_LINES): 78 for icol in range(N_IMAGES_COLS): 79 iimage=iline*N_IMAGES_COLS+icol 80 self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[iimage]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 81 self.imageLabel.append(Label(self.frameImages,image=self.my_images[iimage])) 82 self.imageLabel[iimage].grid(row=iline,column=icol) 72 83 73 84 #Control buttons … … 98 109 self.labelAcquisitionStatus=Label(self.frameAcquisition,text='Status: unkown', bg='magenta') 99 110 self.labelAcquisitionStatus.grid(row=3,column=0) 111 self.labelAcquisitionRate=Label(self.frameAcquisition,text='Rate: unkown', bg='magenta') 112 self.labelAcquisitionRate.grid(row=4,column=0) 113 self.labelAcquisitionPause=Label(self.frameAcquisition,text='Pause: unkown', bg='magenta') 114 self.labelAcquisitionPause.grid(row=5,column=0) 100 115 101 116 #Power status 117 self.framePower = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN) 118 self.framePower.pack(side=LEFT) 119 labelPower=Label(self.framePower,text='IP Power') 120 labelPower.grid(row=0,column=0,columnspan=2) 121 self.buttonPower=[ Button(self.framePower, text=str(ipower), command= lambda v=ipower: self.onButtonPower(v)) for ipower in range(4) ] 122 for ipower in range(4): 123 self.buttonPower[ipower].grid(row=ipower+1,column=0) 124 #self.buttonPower[ipower].pack(side=BOTTOM) 125 self.buttonPower[0].config(text="Camera") 126 self.buttonPower[1].config(text="Blinker") 127 self.buttonPower[2].config(text="Amplifier") 128 self.buttonPower[3].config(text="Wago+Pot") 129 102 130 #Motor function 103 131 self.frameMotors = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN) … … 135 163 self.frameProcesses = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN) 136 164 self.frameProcesses.pack(side=LEFT) 165 self.labelProcessIPPower=Label(self.frameProcesses,text='IP Power', bg='blue') 166 self.labelProcessIPPower.grid(row=0,column=0,columnspan=1) 137 167 self.labelProcessWago=Label(self.frameProcesses,text='WAGO', bg='blue') 138 self.labelProcessWago.grid(row= 0,column=0,columnspan=1)168 self.labelProcessWago.grid(row=1,column=0,columnspan=1) 139 169 self.labelProcessMotorMonitor=Label(self.frameProcesses,text='Motor monitor', bg='blue') 140 self.labelProcessMotorMonitor.grid(row= 1,column=0,columnspan=1)170 self.labelProcessMotorMonitor.grid(row=2,column=0,columnspan=1) 141 171 self.labelProcessSaveData=Label(self.frameProcesses,text='Savedata', bg='blue') 142 self.labelProcessSaveData.grid(row= 2,column=0,columnspan=1)172 self.labelProcessSaveData.grid(row=3,column=0,columnspan=1) 143 173 self.labelProcessProcessRecent=Label(self.frameProcesses,text='Process recent', bg='blue') 144 self.labelProcessProcessRecent.grid(row= 3,column=0,columnspan=1)174 self.labelProcessProcessRecent.grid(row=4,column=0,columnspan=1) 145 175 146 176 #Exit … … 165 195 if (time.time()-filetime)<threshold_recent: 166 196 bgcolortxt='green' 197 fgcolortxt='black' 167 198 elif (time.time()-filetime)<threshold_old: 168 199 bgcolortxt='blue' 169 else: 170 bgcolortxt='red' 171 self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt) 200 fgcolortxt='white' 201 else: 202 bgcolortxt='red' 203 fgcolortxt='black' 204 self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt,fg=fgcolortxt) 172 205 173 206 list_of_files_processed = glob.glob(data_directory+"data_CLIO*.png") 174 207 #print(list_of_files_processed) 175 208 if (len(list_of_files_processed)>0): 176 latest_file_processed = max(list_of_files_processed, key=os.path.getctime) 209 #latest_file_processed = max(list_of_files_processed, key=os.path.getctime) 210 latest_file_processed = max(sorted(list_of_files_processed)) 177 211 filetime=os.path.getctime(latest_file_processed) 178 212 if (time.time()-filetime)<threshold_recent: 179 213 bgcolortxt='green' 214 fgcolortxt='black' 180 215 elif (time.time()-filetime)<threshold_old: 181 216 bgcolortxt='blue' 182 else: 183 bgcolortxt='red' 184 self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt) 217 fgcolortxt='white' 218 else: 219 bgcolortxt='red' 220 fgcolortxt='black' 221 self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt,fg=fgcolortxt) 185 222 imageNames[0]=latest_file_processed; 186 223 … … 189 226 #print(list_of_files_with_signal) 190 227 if (len(list_of_files_with_signal)>0): 191 latest_file_with_signal = max(list_of_files_with_signal, key=os.path.getctime) 228 #latest_file_with_signal = max(list_of_files_with_signal, key=os.path.getctime) 229 latest_file_with_signal = max(sorted(list_of_files_with_signal)) 192 230 filetime=os.path.getctime(latest_file_with_signal) 193 231 if (time.time()-filetime)<threshold_recent: 194 232 bgcolortxt='green' 233 fgcolortxt='black' 195 234 elif (time.time()-filetime)<threshold_old: 196 235 bgcolortxt='blue' 197 else: 198 bgcolortxt='red' 199 self.latestFileWithSignal.config(text=os.path.basename(latest_file_with_signal),bg=bgcolortxt) 200 201 imageNames[0]=latest_file_with_signal.replace(".sig","_zoom.png") 202 imageNames[1]=latest_file_with_signal.replace(".sig","_signal.png") 236 fgcolortxt='white' 237 else: 238 bgcolortxt='red' 239 fgcolortxt='black' 240 self.latestFileWithSignal.config(text=os.path.basename(latest_file_with_signal),bg=bgcolortxt,fg=fgcolortxt) 241 242 imageNames[0]=latest_file_with_signal.replace(".sig",".png") 243 imageNames[1]=latest_file_with_signal.replace(".sig","_zoom.png") 244 imageNames[2]=latest_file_with_signal.replace(".sig","_signal.png") 203 245 time.sleep(0.1) 204 try: 205 self.newImage2=ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS)) 206 except: 207 print("An error occurred while opening the image") 208 self.imageLabel2.configure(image=self.newImage2) 209 self.imageLabel2.image=self.newImage2 210 time.sleep(0.1) 211 try: 212 self.newImage1=ImageTk.PhotoImage(Image.open(imageNames[0]).resize(ImagesDisplaySize, Image.ANTIALIAS)) 213 except: 214 print("An error occurred while opening the image") 215 self.imageLabel1.configure(image=self.newImage1) 216 self.imageLabel1.image=self.newImage1 217 246 247 self.newImage=[] 248 for iimage in range(N_IMAGES): 249 try: 250 self.newImage.append(ImageTk.PhotoImage(Image.open(imageNames[iimage]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 251 self.imageLabel[iimage].configure(image=self.newImage[iimage]) 252 self.imageLabel[iimage].image=self.newImage[iimage] 253 except: 254 print("An error occurred while opening the image: "+imageNames[iimage]+" image "+str(iimage)) 255 time.sleep(0.1) 256 257 218 258 self.getMotorPosition() 219 259 #Check acquisition status … … 221 261 pause_file = glob.glob(FILE_PAUSE) 222 262 if (len(stop_file)): 223 self.labelAcquisitionStatus.config(text="Stop",bg='red' )263 self.labelAcquisitionStatus.config(text="Stop",bg='red',fg='black') 224 264 self.buttonAcqPause.config(text="Program stopped!") 225 265 elif (len(pause_file)): 226 self.labelAcquisitionStatus.config(text="Pause", bg='blue' )266 self.labelAcquisitionStatus.config(text="Pause", bg='blue',fg='white') 227 267 self.buttonAcqPause.config(text="Restart") 228 268 else: 229 self.labelAcquisitionStatus.config(text="Enabled", bg='green' )269 self.labelAcquisitionStatus.config(text="Enabled", bg='green',fg='black') 230 270 231 271 #check remote processes … … 270 310 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==4): 271 311 try: 272 response=subprocess.check_output("ps -edf | grep -v grep | grep -c process_recent_files",shell=True) 312 # response=subprocess.check_output("ps -edf | grep -v grep | grep -c process_recent_files",shell=True) 313 response=subprocess.check_output("ps -edf | grep -v grep | grep -c makefile_recent",shell=True) 273 314 except: 274 315 response='0' … … 283 324 self.after(500, self.update_clock) 284 325 285 286 326 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==5): 327 response=os.system("ping -c 1 "+IP_POWER_IP) 328 if response==0: 329 self.labelProcessIPPower.config(bg='green') 330 else: 331 self.labelProcessIPPower.config(bg='red') 332 333 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==6): 334 self.set_power_buttons_color() 335 336 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==7): 337 fid=open(FILE_ACQ_INFO,'r') 338 fileline=fid.readline() 339 print fileline 340 key_values={} 341 while len(fileline)>0: 342 print fileline 343 entries=fileline.replace('\n','').split(' ') 344 key_values[entries[0]]=entries[1] 345 fileline=fid.readline() 346 fid.close() 347 if (key_values['RATE']): 348 rate_value=36000./float(key_values['RATE']) 349 self.labelAcquisitionRate.config(text='Rate= '+str(rate_value)+'kS/s',bg='white') 350 351 if (key_values['PAUSE']): 352 self.labelAcquisitionPause.config(text='Wait= '+key_values['PAUSE']+' ms',bg='white') 353 287 354 def getMotorPosition(self): 288 355 if (len(glob.glob(motor_position_info))>0): … … 291 358 key_values={} 292 359 while len(fileline)>0: 293 #print fileline360 print fileline 294 361 entries=fileline.replace('#','').replace(' ','').replace('\n','').split('=') 295 362 key_values[entries[0]]=entries[1] … … 298 365 if key_values['motor_value']: 299 366 self.labelPositionStep.config(text=key_values['motor_value']); 300 self.labelPositionStep.config(bg='green' );301 else: 302 self.labelPositionStep.config(bg='red' );367 self.labelPositionStep.config(bg='green',fg='black'); 368 else: 369 self.labelPositionStep.config(bg='red',fg='black'); 303 370 304 371 if key_values['current_value']: 305 372 self.labelPositionCurrent.config(text=key_values['current_value']); 306 self.labelPositionCurrent.config(bg='green' );307 else: 308 self.labelPositionCurrent.config(bg='red' );373 self.labelPositionCurrent.config(bg='green',fg='black'); 374 else: 375 self.labelPositionCurrent.config(bg='red',fg='black'); 309 376 else: 310 self.labelPositionCurrent.config(bg='blue'); 311 self.labelPositionStep.config(bg='blue'); 377 self.labelPositionCurrent.config(bg='blue',fg='white'); 378 self.labelPositionStep.config(bg='blue',fg='white'); 379 380 def set_power_buttons_color(self): 381 power_request=urllib2.urlopen(URI+'?CMD=GetPower') 382 values=power_request.read().replace('<html>','').replace('</html>\r\n','').replace('p6','').split(',') 383 # print repr(values) 384 for ipower in range(4): 385 print values[ipower].split('=')[1] 386 if (values[ipower].split('=')[1]=='1'): 387 self.buttonPower[ipower].config(bg='green') 388 else: 389 self.buttonPower[ipower].config(bg='cyan') 312 390 313 391 #---------------- … … 360 438 self.moveMotor(1,1000000) 361 439 440 def onButtonPower(self,value): 441 print('Power value='+str(value)) 442 print(repr(self.buttonPower[value].cget("bg"))) 443 power_state=0 444 if (self.buttonPower[value].cget("bg")=='green'): 445 power_state=1 446 self.buttonPower[value].config(bg='blue') 447 power_request=urllib2.urlopen(URI+'?CMD=SetPower+P6'+str(value+1)+'='+str(1-power_state)) 448 values=power_request.read().replace('<html>','').replace('</html>\r\n','').replace('p6','').split(',') 449 self.after(2000, self.set_power_buttons_color) 362 450 363 451 #----------------
Note: See TracChangeset
for help on using the changeset viewer.