Permalink
Browse files

Completely new set of materials for GUI class! Thanks Tony!!

  • Loading branch information...
MikeTheWatchGuy committed Oct 8, 2018
1 parent ee0765c commit 8f7356f425d764588e6fab333f57a92f4bb631b7
Showing with 1,909 additions and 903 deletions.
  1. +62 −0 ProgrammingClassExamples/10a PSG Plot (Matplotlib numpy pyplot(y=sinx)) .py
  2. +54 −0 ProgrammingClassExamples/10b PSG Plot (axes moved).py
  3. +68 −0 ProgrammingClassExamples/10c PSG Plot (axes pi format).py
  4. +90 −0 ProgrammingClassExamples/10d PSG (Plots Tabs and sin cos options).py
  5. +88 −0 ProgrammingClassExamples/10e PSG (Same Window).py
  6. +111 −0 ProgrammingClassExamples/10f PSG (linear and quadratics).py
  7. +9 −5 ProgrammingClassExamples/1a PSG (Entry and PopUp).py
  8. +8 −5 ProgrammingClassExamples/1c PSG (persistent form and bind key).py
  9. +6 −5 ProgrammingClassExamples/1d PSG (named input keys and catch errors).py
  10. +7 −7 ProgrammingClassExamples/1e PSG (validation and Look and Feel).py
  11. +13 −9 ...Examples/{2a. PSG (checkbox and radiobuttons).py → 2a. PSG (checkbox and radiobuttons) - Copy.py}
  12. +42 −0 ProgrammingClassExamples/2b. PSG (Add logo).py
  13. +3 −2 ProgrammingClassExamples/3 PSG (multiline display).py
  14. +4 −4 ProgrammingClassExamples/4a PSG (Sliders and combo).py
  15. +2 −2 ProgrammingClassExamples/4b PSG (Spinner and combo) .py
  16. +14 −9 ProgrammingClassExamples/5a PSG (listboxes add remove).py
  17. +0 −130 ProgrammingClassExamples/6 PSG sort and search .py
  18. +86 −0 ProgrammingClassExamples/6a PSG (search linear and binary).py
  19. +0 −78 ProgrammingClassExamples/6a PSG search.py
  20. +95 −0 ProgrammingClassExamples/6b PSG (search - disabled buttons).py
  21. +0 −82 ProgrammingClassExamples/6b PSG search (disabled buttons).py
  22. +79 −0 ProgrammingClassExamples/6c PSG (search text preloaded).py
  23. +0 −79 ProgrammingClassExamples/6c PSG search text preloaded.py
  24. +137 −0 ProgrammingClassExamples/6d PSG (sort and search with textbox.py
  25. +0 −130 ProgrammingClassExamples/6d PSG sort and search.py
  26. +132 −0 ProgrammingClassExamples/6e PSG (sort and search with listbox).py
  27. +0 −130 ProgrammingClassExamples/6e PSG sort and search (listbox) TODO.py
  28. +138 −0 ProgrammingClassExamples/6f PSG (data from text file).py
  29. +21 −17 ...es/{7a PSG Text file save and retrieve.py → 7a PSG (Data entry calc using file save retrieve).py}
  30. +68 −0 ProgrammingClassExamples/7b PSG (add validation and error trap).py
  31. +76 −0 ProgrammingClassExamples/7c PSG (add get pathname to save and retrieve files), - Copy.py
  32. +5 −3 ...mingClassExamples/{8a PSG Data to plot from csv file.py → 8a PSG (Data to plot from csv file).py}
  33. +61 −0 ProgrammingClassExamples/8b PSG (Tables and calc from csv file).py
  34. +0 −41 ProgrammingClassExamples/8b PSG Tables and calc from csv file.py
  35. +66 −0 ProgrammingClassExamples/8c PSG (Tables - add sort).py
  36. +59 −0 ProgrammingClassExamples/8d PSG (Tables - add logo).py
  37. +47 −0 ProgrammingClassExamples/9a PSG Windows(location hide).py
  38. +0 −22 ProgrammingClassExamples/9a Plot Matplotlib numpy pyplot(y=sinx).py
  39. +18 −0 ProgrammingClassExamples/9b PSG Tabs example.py
  40. +0 −27 ProgrammingClassExamples/9b Plot (axes moved).py
  41. +78 −0 ProgrammingClassExamples/9c PSG Tabs example plus.py
  42. +0 −28 ProgrammingClassExamples/9c Plot (axes pi format).py
  43. BIN ProgrammingClassExamples/AFL.png
  44. +19 −0 ProgrammingClassExamples/AFL2018 (sorted alpha teams).csv
  45. +19 −0 ProgrammingClassExamples/AFL2018 (sorted pts and %).csv
  46. BIN ProgrammingClassExamples/Gym_Logo.png
  47. +10 −0 ProgrammingClassExamples/Names(sorted).txt
  48. +10 −0 ProgrammingClassExamples/Names.txt
  49. +0 −88 ProgrammingClassExamples/Text files.py
  50. +3 −0 ProgrammingClassExamples/Tony.txt
  51. BIN ProgrammingClassExamples/default_icon.ico
  52. +3 −0 ProgrammingClassExamples/results.txt
  53. +98 −0 ProgrammingClassExamples/weight 2018.csv
@@ -0,0 +1,62 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018
import PySimpleGUI as sg
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,54 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018
import PySimpleGUI as sg
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,68 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018
import PySimpleGUI as sg
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,90 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018
import PySimpleGUI as sg
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
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,88 @@
#matplotlib, numpy, pyplot
#Tony Crewe
#Oct 2018
import PySimpleGUI as sg
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
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 8f7356f

Please sign in to comment.