Permalink
Browse files

Latest updates from Tony

  • Loading branch information...
MikeTheWatchGuy committed Nov 13, 2018
1 parent 3b63c82 commit b5e001dabcbaba4dcdf1c747e430c759d9797aee
Showing with 2,579 additions and 52 deletions.
  1. BIN Colours.gif
  2. BIN { → DemoPrograms}/ButtonClick.wav
  3. BIN { → DemoPrograms}/Color-Guide.png
  4. BIN { → DemoPrograms}/Color-names.png
  5. +65 −0 ProgrammingClassExamples/MacOS versions/10a PSG Plot (Matplotlib numpy pyplot(y=sinx)) .py
  6. +57 −0 ProgrammingClassExamples/MacOS versions/10b PSG Plot (axes moved).py
  7. +73 −0 ProgrammingClassExamples/MacOS versions/10c PSG Plot (axes pi format).py
  8. +100 −0 ProgrammingClassExamples/MacOS versions/10d PSG (Plots Tabs and sin cos options).py
  9. +98 −0 ProgrammingClassExamples/MacOS versions/10e PSG (Same Window).py
  10. +121 −0 ProgrammingClassExamples/MacOS versions/10f PSG (linear and quadratics).py
  11. +36 −0 ProgrammingClassExamples/MacOS versions/1a PSG (Entry and PopUp).py
  12. +41 −0 ProgrammingClassExamples/MacOS versions/1b PSG (Format).py
  13. +35 −0 ProgrammingClassExamples/MacOS versions/1c PSG (persistent form and bind key).py
  14. +36 −0 ProgrammingClassExamples/MacOS versions/1d PSG (named input keys and catch errors).py
  15. +36 −0 ProgrammingClassExamples/MacOS versions/1e PSG (validation and Look and Feel).py
  16. 0 ...gClassExamples/{1e PSG (validation and Look and Feel).py → MacOS versions/1e PSG (validation).py}
  17. +49 −0 ProgrammingClassExamples/MacOS versions/2a. PSG (checkbox and radiobuttons) - Copy.py
  18. +42 −0 ProgrammingClassExamples/MacOS versions/2b. PSG (Add logo).py
  19. +46 −0 ProgrammingClassExamples/MacOS versions/3 PSG (multiline display).py
  20. +55 −0 ProgrammingClassExamples/MacOS versions/4a PSG (Sliders and combo).py
  21. +43 −0 ProgrammingClassExamples/MacOS versions/4b PSG (Spinner and combo) .py
  22. +51 −0 ProgrammingClassExamples/MacOS versions/5a PSG (listboxes add remove).py
  23. +90 −0 ProgrammingClassExamples/MacOS versions/6a PSG (search linear and binary).py
  24. +98 −0 ProgrammingClassExamples/MacOS versions/6b PSG (search - disabled buttons).py
  25. +79 −0 ProgrammingClassExamples/MacOS versions/6c PSG (search text preloaded).py
  26. +139 −0 ProgrammingClassExamples/MacOS versions/6d PSG (sort and search with textbox.py
  27. +137 −0 ProgrammingClassExamples/MacOS versions/6e PSG (sort and search with listbox).py
  28. +148 −0 ProgrammingClassExamples/MacOS versions/6f PSG (data from text file).py
  29. +67 −0 ProgrammingClassExamples/MacOS versions/7a PSG (Data entry calc using file save retrieve).py
  30. +72 −0 ProgrammingClassExamples/MacOS versions/7b PSG (add validation and error trap).py
  31. +80 −0 ProgrammingClassExamples/MacOS versions/7c PSG (add get pathname to save and retrieve files).py
  32. +40 −0 ProgrammingClassExamples/MacOS versions/8a PSG (Data to plot from csv file).py
  33. +20 −12 ProgrammingClassExamples/{ → MacOS versions}/8b PSG (Tables and calc from csv file).py
  34. +77 −0 ProgrammingClassExamples/MacOS versions/8c PSG (Tables - add sort).py
  35. +71 −0 ProgrammingClassExamples/MacOS versions/8d PSG (Tables - add logo).py
  36. +52 −0 ProgrammingClassExamples/MacOS versions/9a PSG Windows(location hide).py
  37. +22 −0 ProgrammingClassExamples/MacOS versions/9b PSG Tabs example.py
  38. +89 −0 ProgrammingClassExamples/MacOS versions/9c PSG Tabs example plus.py
  39. BIN ProgrammingClassExamples/{ → MacOS versions}/AFL.png
  40. 0 ProgrammingClassExamples/{ → MacOS versions}/AFL2018 (sorted alpha teams).csv
  41. 0 ProgrammingClassExamples/{ → MacOS versions}/AFL2018 (sorted pts and %).csv
  42. BIN ProgrammingClassExamples/{ → MacOS versions}/Gym_Logo.png
  43. 0 ProgrammingClassExamples/{ → MacOS versions}/Names(sorted).txt
  44. 0 ProgrammingClassExamples/{ → MacOS versions}/Names.txt
  45. +3 −0 ProgrammingClassExamples/MacOS versions/Test.txt
  46. +3 −0 ProgrammingClassExamples/MacOS versions/TonyCrewe2.txt
  47. BIN ProgrammingClassExamples/{ → MacOS versions}/default_icon.ico
  48. +3 −0 ProgrammingClassExamples/MacOS versions/results.txt
  49. 0 ProgrammingClassExamples/{ → MacOS versions}/weight 2018.csv
  50. +0 −3 ProgrammingClassExamples/Tony.txt
  51. 0 ProgrammingClassExamples/{ → Win10 versions}/10a PSG Plot (Matplotlib numpy pyplot(y=sinx)) .py
  52. 0 ProgrammingClassExamples/{ → Win10 versions}/10b PSG Plot (axes moved).py
  53. 0 ProgrammingClassExamples/{ → Win10 versions}/10c PSG Plot (axes pi format).py
  54. 0 ProgrammingClassExamples/{ → Win10 versions}/10d PSG (Plots Tabs and sin cos options).py
  55. 0 ProgrammingClassExamples/{ → Win10 versions}/10e PSG (Same Window).py
  56. +8 −8 ProgrammingClassExamples/{ → Win10 versions}/10f PSG (linear and quadratics).py
  57. +4 −1 ProgrammingClassExamples/{ → Win10 versions}/1a PSG (Entry and PopUp).py
  58. +3 −1 ProgrammingClassExamples/{ → Win10 versions}/1b PSG (Format).py
  59. 0 ProgrammingClassExamples/{ → Win10 versions}/1c PSG (persistent form and bind key).py
  60. 0 ProgrammingClassExamples/{ → Win10 versions}/1d PSG (named input keys and catch errors).py
  61. +34 −0 ProgrammingClassExamples/Win10 versions/1e PSG (validation and Look and Feel).py
  62. 0 ProgrammingClassExamples/{ → Win10 versions}/2a. PSG (checkbox and radiobuttons) - Copy.py
  63. +1 −1 ProgrammingClassExamples/{ → Win10 versions}/2b. PSG (Add logo).py
  64. 0 ProgrammingClassExamples/{ → Win10 versions}/2b_makewinexe_file.py
  65. 0 ProgrammingClassExamples/{ → Win10 versions}/3 PSG (multiline display).py
  66. 0 ProgrammingClassExamples/{ → Win10 versions}/4a PSG (Sliders and combo).py
  67. 0 ProgrammingClassExamples/{ → Win10 versions}/4b PSG (Spinner and combo) .py
  68. 0 ProgrammingClassExamples/{ → Win10 versions}/5a PSG (listboxes add remove).py
  69. 0 ProgrammingClassExamples/{ → Win10 versions}/6a PSG (search linear and binary).py
  70. 0 ProgrammingClassExamples/{ → Win10 versions}/6b PSG (search - disabled buttons).py
  71. +0 −3 ProgrammingClassExamples/{ → Win10 versions}/6c PSG (search text preloaded).py
  72. 0 ProgrammingClassExamples/{ → Win10 versions}/6d PSG (sort and search with textbox.py
  73. 0 ProgrammingClassExamples/{ → Win10 versions}/6e PSG (sort and search with listbox).py
  74. +10 −3 ProgrammingClassExamples/{ → Win10 versions}/6f PSG (data from text file).py
  75. +1 −1 ProgrammingClassExamples/{ → Win10 versions}/7a PSG (Data entry calc using file save retrieve).py
  76. +1 −1 ProgrammingClassExamples/{ → Win10 versions}/7b PSG (add validation and error trap).py
  77. +1 −1 ...rieve files), - Copy.py → Win10 versions/7c PSG (add get pathname to save and retrieve files).py}
  78. 0 ProgrammingClassExamples/{ → Win10 versions}/8a PSG (Data to plot from csv file).py
  79. +67 −0 ProgrammingClassExamples/Win10 versions/8b PSG (Tables and calc from csv file).py
  80. +9 −5 ProgrammingClassExamples/{ → Win10 versions}/8c PSG (Tables - add sort).py
  81. +13 −6 ProgrammingClassExamples/{ → Win10 versions}/8d PSG (Tables - add logo).py
  82. 0 ProgrammingClassExamples/{ → Win10 versions}/9a PSG Windows(location hide).py
  83. +4 −0 ProgrammingClassExamples/{ → Win10 versions}/9b PSG Tabs example.py
  84. +2 −2 ProgrammingClassExamples/{ → Win10 versions}/9c PSG Tabs example plus.py
  85. BIN ProgrammingClassExamples/Win10 versions/AFL.png
  86. +19 −0 ProgrammingClassExamples/Win10 versions/AFL2018 (sorted alpha teams).csv
  87. +19 −0 ProgrammingClassExamples/Win10 versions/AFL2018 (sorted pts and %).csv
  88. BIN ProgrammingClassExamples/Win10 versions/Gym_Logo.png
  89. +10 −0 ProgrammingClassExamples/Win10 versions/Names.txt
  90. BIN ProgrammingClassExamples/Win10 versions/default_icon.ico
  91. +98 −0 ProgrammingClassExamples/Win10 versions/weight 2018.csv
  92. +0 −3 ProgrammingClassExamples/results.txt
  93. +1 −1 requirements.txt
BIN -40.4 KB Colours.gif
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,65 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018 MacOS
import PySimpleGUI as sg
import matplotlib
# added this to work with MacOs
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
import matplotlib.backends.tkagg as tkagg
import numpy as np
import tkinter as tk
"""
Demonstrates one way of embedding Matplotlib figures into a PySimpleGUI window.
Adapted: From https://gitlab.com/lotspaih/PySimpleGUI/tree/master
Basic steps are:
* Create a Canvas Element
* Layout form
* Display form (NON BLOCKING)
* Draw plots onto convas
* Display form (BLOCKING)
"""
#No exactly sure how all this works, but taken from example given as a template.
def draw_figure(canvas, figure, loc = (0,0)):
figure_canvas_agg = FigureCanvasAgg(figure)
figure_canvas_agg.draw()
figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds
figure_w, figure_h = int(figure_w), int(figure_h)
photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h)
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
return photo
#------------ Matplotlib code ----------------------
#see https://matplotlib.org/
fig = plt.figure()
ax = fig.add_subplot(111)
#x-values
x = np.linspace(-np.pi*2, np.pi*2, 100)
#y-values
y = np.sin(x)
plt.plot(x,y)
ax.set_title('sin(x)')
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
#------------End Matplotlib code --------------------
layout = [[sg.Text('Plot Test - PySimpleGUI and Matplotlib', font = ('Calibri', 18, 'bold'))],
[sg.Canvas(size = (figure_w, figure_h), key = '_canvas_')],
[sg.OK(pad=((figure_w / 2, 0), 3), size=(6, 2))]]
window = sg.Window('Matplot in PySimpleGUI', force_toplevel = True).Layout(layout).Finalize()
fig_photo = draw_figure(window.FindElement('_canvas_').TKCanvas, fig)
button, value = window.Read()
@@ -0,0 +1,57 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018 MacOS
import PySimpleGUI as sg
import matplotlib
# added this to work with MacOs
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
import matplotlib.backends.tkagg as tkagg
import numpy as np
import tkinter as tk
def draw_figure(canvas, figure, loc = (0,0)):
figure_canvas_agg = FigureCanvasAgg(figure)
figure_canvas_agg.draw()
figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds
figure_w, figure_h = int(figure_w), int(figure_h)
photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h)
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
return photo
#------------ Matplotlib code --------------------
fig=plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(-np.pi*2, np.pi*2, 100)
y= np.sin(x)
plt.plot(x,y)
ax.set_title('sin(x)')
#centre bottom and left axes to zero
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
#------------End Matplotlib code --------------------
layout = [[sg.Text('Plot Test - PySimpleGUI and Matplotlib (axes centred)', font = ('Calibri', 18, 'bold'))],
[sg.Canvas(size = (figure_w, figure_h), key = '_canvas_')],
[sg.OK(pad=((figure_w / 2, 0), 3), size=(6, 2))]]
window = sg.Window('Matplot in PySimpleGUI', force_toplevel = True).Layout(layout).Finalize()
fig_photo = draw_figure(window.FindElement('_canvas_').TKCanvas, fig)
button, value = window.Read()
@@ -0,0 +1,73 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018 MacOS
import PySimpleGUI as sg
import matplotlib
# added this to work with MacOs
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
import matplotlib.backends.tkagg as tkagg
import numpy as np
import tkinter as tk
"""
Demonstrates one way of embedding Matplotlib figures into a PySimpleGUI window.
Basic steps are:
* Create a Canvas Element
* Layout form
* Display form (NON BLOCKING)
* Draw plots onto convas
* Display form (BLOCKING)
"""
def draw_figure(canvas, figure, loc = (0,0)):
figure_canvas_agg = FigureCanvasAgg(figure)
figure_canvas_agg.draw()
figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds
figure_w, figure_h = int(figure_w), int(figure_h)
photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h)
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
return photo
#------------ Matplotlib code --------------------
fig=plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(-np.pi*2, np.pi*2, 100)
y= np.sin(x)
plt.plot(x/np.pi,y)
ax.set_title('sin(x)')
#centre bottom and left axes to zero
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
#Format axes - nicer eh!
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%g $\pi$'))
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
#------------End Matplotlib code --------------------
layout = [[sg.Text('Plot Test - PySimpleGUI and Matplotlib (axes pi format)', font = ('Calibri', 18, 'bold'))],
[sg.Canvas(size = (figure_w, figure_h), key = '_canvas_')],
[sg.OK(pad=((figure_w / 2, 0), 3), size=(6, 2))]]
window = sg.Window('Matplot in PySimpleGUI', force_toplevel = True).Layout(layout).Finalize()
fig_photo = draw_figure(window.FindElement('_canvas_').TKCanvas, fig)
button, value = window.Read()
@@ -0,0 +1,100 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018 MacOs
import PySimpleGUI as sg
import matplotlib
# added this to work with MacOs
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
import matplotlib.backends.tkagg as tkagg
import numpy as np
import tkinter as tk
sg.SetOptions (background_color = 'LightBlue',
element_background_color = 'LightBlue',
text_element_background_color = 'LightBlue',
font = ('Arial', 14, 'bold'),
text_color = 'DarkBlue',
input_text_color ='DarkBlue',
button_color = ('DarkBlue', 'White'))
def draw_figure(canvas, figure, loc = (0,0)):
figure_canvas_agg = FigureCanvasAgg(figure)
figure_canvas_agg.draw()
figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds
figure_w, figure_h = int(figure_w), int(figure_h)
photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h)
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
return photo
#------------ Matplotlib code --------------------
def set_plot(amp, function):
global figure_w, figure_h, fig
fig=plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(-np.pi*2, np.pi*2, 100)
if function == 'sine':
y= amp*np.sin(x)
ax.set_title('sin(x)')
else:
y=amp*np.cos(x)
ax.set_title('cos(x)')
plt.plot(x/np.pi,y)
#centre bottom and left axes to zero
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
#Format axes - nicer eh!
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%g $\pi$'))
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
amp = 1
function = 'sine'
set_plot(amp, function)
#------------End Matplotlib code --------------------
#use Tabs - one for options, one for canvas to be displayed
#set spinner for amplitude and combo for function type
tab1_layout = [[sg.Text('Select Amplitude and trig function type', font = ('Calibri', 18, 'bold'))],
[sg.Spin([sz for sz in range (1,5)], initial_value =1, size = (2,1), key = '_spin_'),
sg.Text('Amplitude', size = (10, 1), font = ('Calibri', 12, 'bold'))],
[sg.InputCombo(['sine', 'cosine'], size = (8, 4), key = '_function_'),
sg.Text('Function', size = (10, 1),font = ('Calibri', 12, 'bold'))],
[sg.ReadButton('Redraw Plot')],
[sg.Text('', size = (2, 25))]]
tab2_layout = [[sg.Text('Plot Test - PySimpleGUI and Matplotlib and options', font = ('Calibri', 18, 'bold'))],
[sg.Canvas(size = (figure_w, figure_h), key = '_canvas_')],
[sg.OK(pad=((figure_w / 2, 0), 3), size=(6, 2))]]
layout = [[sg.TabGroup([[sg.Tab('Select options', tab1_layout), sg.Tab('Display Plot', tab2_layout)]])]]
window = sg.Window('Matplot, PySimpleGUI and options', force_toplevel = True).Layout(layout).Finalize()
fig_photo = draw_figure(window.FindElement('_canvas_').TKCanvas, fig)
while True:
button, value = window.Read()
if button == 'Redraw Plot':
amp = int(value['_spin_'])
function = value['_function_']
set_plot(amp,function)
fig_photo = draw_figure(window.FindElement('_canvas_').TKCanvas, fig)
if button is None:
break
@@ -0,0 +1,98 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018 MacOs
import PySimpleGUI as sg
import matplotlib
# added this to work with MacOs
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
import matplotlib.backends.tkagg as tkagg
import numpy as np
import tkinter as tk
sg.SetOptions (background_color = 'LightBlue',
element_background_color = 'LightBlue',
text_element_background_color = 'LightBlue',
font = ('Arial', 14, 'bold'),
text_color = 'DarkBlue',
input_text_color ='DarkBlue',
button_color = ('DarkBlue', 'White'))
def draw_figure(canvas, figure, loc = (0,0)):
figure_canvas_agg = FigureCanvasAgg(figure)
figure_canvas_agg.draw()
figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds
figure_w, figure_h = int(figure_w), int(figure_h)
photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h)
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
return photo
#------------ Matplotlib code --------------------
def set_plot(amp, function):
global figure_w, figure_h, fig
fig=plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(-np.pi*2, np.pi*2, 100)
if function == 'sine':
y= amp*np.sin(x)
ax.set_title('sin(x)')
else:
y=amp*np.cos(x)
ax.set_title('cos(x)')
plt.plot(x/np.pi,y)
#centre bottom and left axes to zero
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
#Format axes - nicer eh!
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%g $\pi$'))
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
amp = 1
function = 'sine'
set_plot(amp, function)
#------------End Matplotlib code --------------------
#using one window based on two columns instead of Tabs
column1 = [[sg.Text('Select Amplitude and trig function type', font = ('Calibri', 18, 'bold'))],
[sg.Spin([sz for sz in range (1,5)], initial_value =1, size = (2,1), key = '_spin_'),
sg.Text('Amplitude', size = (10, 1), font = ('Calibri', 12, 'bold'))],
[sg.InputCombo(['sine', 'cosine'], size = (8, 4), key = '_function_'),
sg.Text('Function', size = (10, 1),font = ('Calibri', 12, 'bold'))],
[sg.ReadButton('Redraw Plot')],
[sg.Text('', size = (1, 27))]]
column2 = [[sg.Text('Plot Test - PySimpleGUI and Matplotlib and options', font = ('Calibri', 18, 'bold'))],
[sg.Canvas(size = (figure_w, figure_h), key = '_canvas_')],
[sg.OK(pad=((figure_w / 2, 0), 3), size=(6, 2))]]
layout = [[sg.Column(column1), sg.Column(column2)]]
window = sg.Window('Matplot, PySimpleGUI and options', force_toplevel = True).Layout(layout).Finalize()
fig_photo = draw_figure(window.FindElement('_canvas_').TKCanvas, fig)
while True:
button, value = window.Read()
if button == 'Redraw Plot':
amp = int(value['_spin_'])
function = value['_function_']
set_plot(amp,function)
fig_photo = draw_figure(window.FindElement('_canvas_').TKCanvas, fig)
if button is None:
break
Oops, something went wrong.

0 comments on commit b5e001d

Please sign in to comment.