Merge pull request #61 from MikeTheWatchGuy/Dev-latest

Dev latest
This commit is contained in:
MikeTheWatchGuy 2018-08-27 12:10:58 -04:00 committed by GitHub
commit 712c146f7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 17 deletions

View File

@ -1,9 +1,7 @@
import PySimpleGUI as g
import matplotlib
matplotlib.use('TkAgg')
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
import matplotlib.backends.tkagg as tkagg
import tkinter as Tk
@ -42,22 +40,30 @@ def draw_figure(canvas, figure, loc=(0, 0)):
# which must be kept live or else the picture disappears
return photo
f = Figure(figsize=(5, 4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
#------------------------------- PASTE YOUR MATPLOTLIB CODE HERE -------------------------------
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
a.plot(t, s)
a.set_title('Tk embedding')
a.set_xlabel('X axis label')
a.set_ylabel('Y label')
# Fixing random state for reproducibility
np.random.seed(19680801)
# -------------------------------- GUI Starts Here --------------------------------
canvas_elem = g.Canvas(size=(500, 400)) # get the canvas we'll be drawing on
matplotlib.rcParams['axes.unicode_minus'] = False
fig, ax = plt.subplots()
ax.plot(10*np.random.randn(100), 10*np.random.randn(100), 'o')
ax.set_title('Using hyphen instead of Unicode minus')
# -------------------------------- GUI Starts Here -------------------------------#
# fig = your figure you want to display. Assumption is that 'fig' holds the #
# information to display. #
# --------------------------------------------------------------------------------#
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
canvas_elem = g.Canvas(size=(figure_w, figure_h)) # get the canvas we'll be drawing on
# define the form layout
layout = [[g.Text('Plot test')],
[canvas_elem],
[g.OK(pad=((250,0), 3))]]
[g.OK(pad=((figure_w/2,0), 3), size=(4,2))]]
# create the form and show it without the plot
form = g.FlexForm('Demo Application - Embedding Matplotlib In PySimpleGUI')
@ -65,7 +71,7 @@ form.Layout(layout)
form.ReadNonBlocking()
# add the plot to the window
fig_photo = draw_figure(canvas_elem.TKCanvas, f)
fig_photo = draw_figure(canvas_elem.TKCanvas, fig)
# show it all again and get buttons
button, values = form.Read()

View File

@ -850,7 +850,7 @@ class Frame(Element):
# Slider #
# ---------------------------------------------------------------------- #
class Slider(Element):
def __init__(self, range=(None,None), default_value=None, orientation=None, border_width=None, relief=None, scale=(None, None), size=(None, None), font=None, background_color=None, text_color=None, key=None, pad=None):
def __init__(self, range=(None,None), default_value=None, resolution=None, orientation=None, border_width=None, relief=None, scale=(None, None), size=(None, None), font=None, background_color=None, text_color=None, key=None, pad=None):
'''
Slider Element
:param range:
@ -869,6 +869,8 @@ class Slider(Element):
self.Orientation = orientation if orientation else DEFAULT_SLIDER_ORIENTATION
self.BorderWidth = border_width if border_width else DEFAULT_SLIDER_BORDER_WIDTH
self.Relief = relief if relief else DEFAULT_SLIDER_RELIEF
self.Resolution = 1 if resolution is None else resolution
super().__init__(ELEM_TYPE_INPUT_SLIDER, scale=scale, size=size, font=font, background_color=background_color, text_color=text_color, key=key, pad=pad)
return
@ -1084,6 +1086,9 @@ class FlexForm:
if self.RootNeedsDestroying:
self.TKroot.destroy()
_my_windows.Decrement()
# if form was closed with X
if self.LastButtonClicked is None and self.LastKeyboardEvent is None and self.ReturnValues[0] is None:
_my_windows.Decrement()
if self.LastKeyboardEvent is not None or self.LastButtonClicked is not None:
return BuildResults(self, False, self)
else:
@ -1805,7 +1810,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
else:
range_from = element.Range[0]
range_to = element.Range[1]
tkscale = tk.Scale(tk_row_frame, orient=element.Orientation, variable=element.TKIntVar, from_=range_from, to_=range_to, length=slider_length, width=slider_width , bd=element.BorderWidth, relief=element.Relief, font=font)
tkscale = tk.Scale(tk_row_frame, orient=element.Orientation, variable=element.TKIntVar, from_=range_from, to_=range_to, resolution = element.Resolution, length=slider_length, width=slider_width , bd=element.BorderWidth, relief=element.Relief, font=font)
# tktext_label.configure(anchor=tk.NW, image=photo)
tkscale.config(highlightthickness=0)
if element.BackgroundColor is not None: