Merge pull request #2073 from PySimpleGUI/Dev-latest

Dev latest
This commit is contained in:
PySimpleGUI 2019-10-13 15:14:37 -04:00 committed by GitHub
commit 126ad571bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 12 deletions

View File

@ -0,0 +1,29 @@
import PySimpleGUI as sg
import random
BAR_WIDTH = 50
BAR_SPACING = 75
EDGE_OFFSET = 3
GRAPH_SIZE = (500,500)
DATA_SIZE = (500,500)
graph = sg.Graph(GRAPH_SIZE, (0,0), DATA_SIZE)
layout = [[sg.Text('Bar graphs using PySimpleGUI')],
[graph],
[sg.Button('OK')]]
window = sg.Window('Window Title', layout)
while True:
event, values = window.Read()
graph.Erase()
if event is None:
break
for i in range(7):
graph_value = random.randint(0, 400)
graph.DrawRectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue')
graph.DrawText(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
window.Close()

View File

@ -8,18 +8,18 @@ SIZE_Y = 100
NUMBER_MARKER_FREQUENCY = 25
def draw_axis():
graph.DrawLine((-SIZE_X,0), (SIZE_X, 0)) # axis lines
graph.DrawLine((0,-SIZE_Y), (0,SIZE_Y))
graph.draw_line((-SIZE_X,0), (SIZE_X, 0)) # axis lines
graph.draw_line((0,-SIZE_Y), (0,SIZE_Y))
for x in range(-SIZE_X, SIZE_X+1, NUMBER_MARKER_FREQUENCY):
graph.DrawLine((x,-3), (x,3)) # tick marks
graph.draw_line((x,-3), (x,3)) # tick marks
if x != 0:
graph.DrawText( str(x), (x,-10), color='green') # numeric labels
graph.draw_text( str(x), (x,-10), color='green', font='Algerian 15') # numeric labels
for y in range(-SIZE_Y, SIZE_Y+1, NUMBER_MARKER_FREQUENCY):
graph.DrawLine((-3,y), (3,y))
graph.draw_line((-3,y), (3,y))
if y != 0:
graph.DrawText( str(y), (-10,y), color='blue')
graph.draw_text( str(y), (-10,y), color='blue')
# Create the graph that will be put into the window
graph = sg.Graph(canvas_size=(400, 400),
@ -30,22 +30,22 @@ graph = sg.Graph(canvas_size=(400, 400),
# Window layout
layout = [[sg.Text('Example of Using Math with a Graph', justification='center', size=(50,1), relief=sg.RELIEF_SUNKEN)],
[graph],
[sg.Text('y = sin(x / x2 * x1)', font='COURIER 18')],
[sg.Text('y = sin(x / x2 * x1)', font='Algerian 18')],
[sg.Text('x1'),sg.Slider((0,200), orientation='h', enable_events=True,key='_SLIDER_')],
[sg.Text('x2'),sg.Slider((1,200), orientation='h', enable_events=True,key='_SLIDER2_')]]
window = sg.Window('Graph of Sine Function', layout)
while True:
event, values = window.Read()
event, values = window.read()
if event is None:
break
graph.Erase()
graph.erase()
draw_axis()
prev_x = prev_y = None
for x in range(-SIZE_X,SIZE_X):
y = math.sin(x/int(values['_SLIDER2_']))*int(values['_SLIDER_'])
if prev_x is not None:
graph.DrawLine((prev_x, prev_y), (x,y), color='red')
graph.draw_line((prev_x, prev_y), (x,y), color='red')
prev_x, prev_y = x, y

View File

@ -1,5 +1,5 @@
#!/usr/bin/python3
version = __version__ = "4.5.0.23 Unreleased Mac Buttons. Element size get/set. Screen Size. hide/unhide row. Button rebinding. Element.expand"
version = __version__ = "4.5.0.24 Unreleased Mac Buttons. Element size get/set. Screen Size. hide/unhide row, Button rebinding, Element.expand, Experimental Finalize"
# 888888ba .d88888b oo dP .88888. dP dP dP
@ -627,6 +627,7 @@ class Element():
:param event:
"""
print(f'In return handler. event = {event}')
MyForm = self.ParentForm
button_element = self._FindReturnKeyBoundButton(MyForm)
if button_element is not None:
@ -1378,7 +1379,8 @@ class Radio(Element):
return
if value is not None:
try:
self.TKIntVar.set(self.EncodedRadioValue)
if value:
self.TKIntVar.set(self.EncodedRadioValue)
except:
pass
self.InitialState = value
@ -5707,6 +5709,9 @@ class Window:
if self.TKrootDestroyed:
return self
self.Read(timeout=1)
return self
# OLD CODE FOLLOWS
if not self.Shown:
self._Show(non_blocking=True)
try: