Last active
September 27, 2018 04:14
-
-
Save eagleEggs/1da1dcb6e95cdb559efe8003cebc865e to your computer and use it in GitHub Desktop.
PySimpleGUI Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib | |
matplotlib.use('TkAgg') | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import pylab | |
import seaborn as sns | |
from pandas.plotting import scatter_matrix | |
import numpy as np | |
from matplotlib.ticker import NullFormatter | |
from matplotlib.backends.backend_tkagg import FigureCanvasAgg | |
import matplotlib.backends.tkagg as tkagg | |
import tkinter as Tk | |
# PDF Generation: | |
#import pdfkit | |
# GUI: | |
import PySimpleGUI as sg | |
######################## | |
######### GUI ########## | |
######################## | |
def Graphing(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(500), int(300) | |
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 | |
def GenerateGraph(): | |
np.random.seed(19680801) | |
y = np.random.normal(loc=0.5, scale=0.4, size=200) | |
y = y[(y > 0) & (y < 1)] | |
y.sort() | |
x = np.arange(len(y)) | |
plt.figure(1) | |
plt.subplot(221) | |
plt.plot(x, y) | |
plt.yscale('linear') | |
plt.title('linear') | |
plt.grid(True) | |
plt.gca().yaxis.set_minor_formatter(NullFormatter()) | |
plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25, | |
wspace=0.35) | |
fig = plt.gcf() | |
return fig | |
def NightMode(): | |
sg.ChangeLookAndFeel('Black') | |
####################### | |
###### Matplot ######## | |
####################### | |
fig = GenerateGraph() | |
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds | |
######################## | |
####### Columns ######## | |
######################## | |
col1 = [[sg.Text('App Name:'), sg.InputText('App')], | |
[sg.Text('Tester Name:'), sg.InputText('Leonardo')], | |
[sg.Text('Browser Type (IE):'), sg.InputText('FF')], | |
[sg.T("")], | |
[sg.Checkbox('Enable MySQLDatabase')], | |
[sg.Checkbox('PDF Generation', default = True)], | |
[sg.Checkbox('HTML Generation', default = True)], | |
[sg.Checkbox('Graph Generation')], | |
[sg.Checkbox('Email Reporting')]] | |
col2 = [[sg.T("These settings are for your Topanga MySQL Database.")], | |
[sg.T("")], | |
[sg.Text('Topanga MySQL Database IP:'), sg.InputText('')], | |
[sg.Text('Topanga MySQL Username:'), sg.InputText('')], | |
[sg.Text('Topanga MySQL Password:'), sg.InputText('')], | |
[sg.Text('Topanga MySQL Port:'), sg.InputText('')], | |
[sg.Text('')], | |
[sg.ReadButton(" Connect Database ")]] | |
col3 = [[sg.T("These settings should be customized to your apps needs.")], | |
[sg.T("")], | |
[sg.Text('User URL:'), sg.InputText('https://')], | |
[sg.Text('Admin URL:'), sg.InputText('https://')], | |
[sg.Text('Patient Last Name:'), sg.InputText('')], | |
[sg.Text('Patient Last Four SSN:'), sg.InputText('')], | |
[sg.Text('Patient Other Reason for Visit:'), sg.InputText('My gravity is wearing off')], | |
[sg.T("")], | |
[sg.Text('Oracle Login Name:'), sg.InputText('')], | |
[sg.Text('Oracle Login Password:'), sg.InputText('')], | |
[sg.Text('Database IP Address:'), sg.InputText('')], | |
[sg.Text('Database Port:'), sg.InputText('')]] | |
col4 = [[sg.T("Graphing")]] | |
# center menu | |
colm = [[sg.T("")],[sg.T('Topanga ∩(^-^)∩ Test Anatomy', justification="center"), | |
sg.ReadButton("Create a Topanga")]] | |
col5 = [[sg.T("Screenshots")]] | |
col6 = [[sg.T("Reporting")]] | |
col7 = [[sg.T('Logging')]] | |
col8 = [[sg.T('Notes:'), sg.InputText('')]] | |
######################## | |
######### Tabs ######### | |
######################## | |
tab1 = [[sg.T("General Settings", text_color='blue')], | |
[sg.Column(col1)]] | |
tab2 = [[sg.T("Database Settings", text_color='blue')], | |
[sg.Column(col2)]] | |
tab3 = [[sg.T("Custom Settings", text_color='blue')], | |
[sg.Column(col3)]] | |
tab4 = [[sg.T("Graphing", text_color='blue')], | |
[sg.Column(col4, pad=(0, (0, 0)))], [sg.Canvas(size=(figure_w, figure_h), key='canvas')]] | |
tab5 = [[sg.T("Screenshots", text_color='blue')], | |
[sg.Column(col5)]] | |
tab6 = [[sg.T("Reporting", text_color='blue')], | |
[sg.Column(col6)]] | |
tab7 = [[sg.T("Logging", text_color='blue')], | |
[sg.Column(col7)]] | |
tab8 = [[sg.T("Notes", text_color='blue')], | |
[sg.Column(col8)]] | |
layout = [[sg.TabGroup([[sg.Tab('General Settings', tab1), | |
sg.Tab('Database Settings', tab2), | |
sg.Tab('Custom App Settings', tab3)]])], | |
[sg.Column(colm)], | |
[sg.Text('')], | |
[sg.TabGroup([[sg.Tab('Graphing', tab4), | |
sg.Tab('Screenshots', tab5), | |
sg.Tab('Reporting', tab6), | |
sg.Tab('Logging', tab7), | |
sg.Tab('Notes', tab8)]])], | |
[sg.Text('')]] | |
window = sg.Window("Topanga ∩(^-^)∩", grab_anywhere=False, auto_size_text=False).Layout(layout).Finalize() | |
#fig = GenerateGraph() | |
fig_photo = Graphing(window.FindElement('canvas').TKCanvas, fig) | |
while True: | |
b, v = window.Read() | |
print(b,v) | |
if b is None: | |
break | |
### The two functions are below: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment