Merge pull request #2752 from PySimpleGUI/Dev-latest
NEW demo program - Fourier Transform. Updated Calendar demo
This commit is contained in:
		
						commit
						629cdafb22
					
				
					 3 changed files with 76 additions and 75 deletions
				
			
		|  | @ -4,11 +4,11 @@ import PySimpleGUI as sg | |||
| """ | ||||
|     Simple test harness to demonstate how to use the CalendarButton and the get date popup | ||||
| """ | ||||
| 
 | ||||
| sg.theme('Dark Red') | ||||
| layout = [[sg.Text('Date Chooser Test Harness', key='-TXT-')], | ||||
|       [sg.Input(key='-IN-', size=(20,1)), sg.CalendarButton('Cal US No Buttons Location (0,0)', close_when_date_chosen=True,  target='-IN-', location=(0,0))], | ||||
|       [sg.Input(key='-IN3-', size=(20,1)), sg.CalendarButton('Cal US Monday', close_when_date_chosen=False,  target='-IN3-', begin_at_sunday_plus=1)], | ||||
|       [sg.Input(key='-IN2-', size=(20,1)), sg.CalendarButton('Cal German Feb 2020',  target='-IN2-',  default_date_m_d_y=(2,None,2020), locale='de_DE', begin_at_sunday_plus=1 )], | ||||
|       [sg.Input(key='-IN-', size=(20,1)), sg.CalendarButton('Cal US No Buttons Location (0,0)', close_when_date_chosen=True,  target='-IN-', location=(0,0), no_titlebar=False, )], | ||||
|       [sg.Input(key='-IN3-', size=(20,1)), sg.CalendarButton('Cal Monday', title='Pick a date any date', no_titlebar=True, close_when_date_chosen=False,  target='-IN3-', begin_at_sunday_plus=1, month_names=('студзень', 'люты', 'сакавік', 'красавік', 'май', 'чэрвень', 'ліпень', 'жнівень', 'верасень', 'кастрычнік', 'лістапад', 'снежань'), day_abbreviations=('Дш', 'Шш', 'Шр', 'Бш', 'Жм', 'Иш', 'Жш'))], | ||||
|       [sg.Input(key='-IN2-', size=(20,1)), sg.CalendarButton('Cal German Feb 2020',  target='-IN2-',  default_date_m_d_y=(2,None,2020), locale='de DE', begin_at_sunday_plus=1 )], | ||||
|       [sg.Input(key='-IN4-', size=(20,1)), sg.CalendarButton('Cal Format %m-%d Jan 2020',  target='-IN4-', format='%m-%d', default_date_m_d_y=(1,None,2020), )], | ||||
|       [sg.Button('Read'), sg.Button('Date Popup'), sg.Exit()]] | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										72
									
								
								DemoPrograms/Demo_Graph_FourierTransform.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								DemoPrograms/Demo_Graph_FourierTransform.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,72 @@ | |||
| import math | ||||
| import numpy as np | ||||
| import PySimpleGUI as sg | ||||
| import time | ||||
| 
 | ||||
| """ | ||||
|     Fourier Transform Animated Graph | ||||
|      | ||||
|     A fun demonstration of the Graph Element and the drawing primitive draw_lines | ||||
|     Written by Jason Yang, by an innovative PySimpleGUI user that has created a number | ||||
|     of impressive animations using PySimpleGUI. | ||||
|      | ||||
|     Copyright 2020 Jason Yang | ||||
| """ | ||||
| 
 | ||||
| def push(v): | ||||
|     if len(buffer)==size: | ||||
|         del buffer[-1] | ||||
|     buffer[0:0] = [v] | ||||
| 
 | ||||
| def update(i): | ||||
|     draw.Erase() | ||||
|     x1 = x0 + r1*math.cos(v1*i*rad) | ||||
|     y1 = y0 + r1*math.sin(v1*i*rad) | ||||
|     x2 = x1 + r2*math.cos(v2*i*rad) | ||||
|     y2 = y1 + r2*math.sin(v2*i*rad) | ||||
|     x3 = x2 + r3*math.cos(v3*i*rad) | ||||
|     y3 = y2 + r3*math.sin(v3*i*rad) | ||||
|     push(y3) | ||||
|     draw.DrawCircle((x0, y0), r1, line_color='blue') | ||||
|     draw.DrawCircle((x1, y1), r2, line_color='yellow') | ||||
|     draw.DrawCircle((x2, y2), r3, line_color='red') | ||||
|     draw.DrawLine((x0, y0), (x1, y1), color='magenta') | ||||
|     draw.DrawLine((x1, y1), (x2, y2), color='white') | ||||
|     draw.DrawLine((x2, y2), (x3, y3), color='white') | ||||
|     draw.DrawLine((x3, y3), (x[0]+xx, buffer[0]), color='ivory') | ||||
|     draw.DrawPoint((x3, y3), size=10, color='red') | ||||
|     lines = ((x[i]+xx, y) for i, y in enumerate(buffer)) | ||||
|     draw.DrawLines(lines, color='green1') | ||||
| 
 | ||||
| size = 720 | ||||
| distance = 100 | ||||
| r0, r1, r2, r3 = 90, 90, 30, 18 | ||||
| rad = math.pi/180 | ||||
| v1, v2, v3 = 1, 3, 5 | ||||
| x = np.array(list(range(size))) | ||||
| x0 = y0 = r1+r2+r3 | ||||
| xx = x0*2 + distance | ||||
| buffer = [] | ||||
| win_size = (xx+size, 2*x0) | ||||
| 
 | ||||
| layout = [[sg.Graph(canvas_size=win_size, graph_bottom_left=(0, 0), | ||||
|                      graph_top_right=win_size, key='-GRAPH-')]] | ||||
| window = sg.Window('Fourier', layout=layout, finalize=True) | ||||
| draw = window['-GRAPH-'] | ||||
| 
 | ||||
| i = 0 | ||||
| timeout = refresh_interval = 10    # Target refresh interval = 10 milliseconds | ||||
| 
 | ||||
| while True: | ||||
|     start_time = time.time() | ||||
| 
 | ||||
|     event, values = window.read(timeout=timeout) | ||||
|     if event == None: | ||||
|         break | ||||
| 
 | ||||
|     update(i) | ||||
|     i = i+1 if i<359 else 0 | ||||
| 
 | ||||
|     timeout = max(0, (refresh_interval - (time.time()-start_time)*1000)) | ||||
| 
 | ||||
| window.close() | ||||
|  | @ -1,71 +0,0 @@ | |||
| import PySimpleGUI as sg | ||||
| from threading import Thread | ||||
| import ping | ||||
| import time | ||||
| 
 | ||||
| # Yet another usage of Graph element. | ||||
| 
 | ||||
| STEP_SIZE = 1 | ||||
| SAMPLES = 6000 | ||||
| CANVAS_SIZE = (6000, 500) | ||||
| 
 | ||||
| # globale used to communicate with thread.. yea yea... it's working fine | ||||
| g_exit = False | ||||
| g_response_time = None | ||||
| 
 | ||||
| 
 | ||||
| def ping_thread(args): | ||||
|     global g_exit, g_response_time | ||||
|     while not g_exit: | ||||
|         g_response_time = ping.quiet_ping('google.com', timeout=1000) | ||||
| 
 | ||||
| 
 | ||||
| def main(): | ||||
|     global g_exit, g_response_time | ||||
| 
 | ||||
|     # start ping measurement thread | ||||
|     thread = Thread(target=ping_thread, args=(None,)) | ||||
|     thread.start() | ||||
| 
 | ||||
|     sg.theme('Black') | ||||
|     sg.set_options(element_padding=(0, 0)) | ||||
| 
 | ||||
|     layout = [[sg.Text('Ping times to Google.com', font='Any 12'), | ||||
|                 sg.Quit(pad=((100, 0), 0), button_color=('white', 'black'))], | ||||
|               [sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, 500), | ||||
|                         background_color='black', key='graph')] | ||||
|               ] | ||||
| 
 | ||||
|     form = sg.FlexForm('Canvas test', layout, grab_anywhere=True, background_color='black', | ||||
|                        no_titlebar=False, use_default_focus=False, finalize=True) | ||||
|     graph = form['graph'] | ||||
| 
 | ||||
|     prev_response_time = None | ||||
|     i = 0 | ||||
|     prev_x, prev_y = 0, 0 | ||||
|     while True: | ||||
|         time.sleep(.2) | ||||
| 
 | ||||
|         button, values = form.ReadNonBlocking() | ||||
|         if button == 'Quit' or values is None: | ||||
|             break | ||||
|         if g_response_time is None or prev_response_time == g_response_time: | ||||
|             continue | ||||
|         new_x, new_y = i, g_response_time[0] | ||||
|         prev_response_time = g_response_time | ||||
|         if i >= SAMPLES: | ||||
|             graph.move(-STEP_SIZE, 0) | ||||
|             prev_x = prev_x - STEP_SIZE | ||||
|         graph.draw_line((prev_x, prev_y), (new_x, new_y), color='white') | ||||
|         # form['graph'].draw_point((new_x, new_y), color='red') | ||||
|         prev_x, prev_y = new_x, new_y | ||||
|         i += STEP_SIZE if i < SAMPLES else 0 | ||||
| 
 | ||||
|     # tell thread we're done. wait for thread to exit | ||||
|     g_exit = True | ||||
|     thread.join() | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     main() | ||||
|      | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue