commit
e8bd26e5d3
|
@ -35,15 +35,8 @@ def draw_figure(canvas, figure, loc=(0, 0)):
|
|||
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)
|
||||
|
||||
# Position: convert from top-left anchor to center anchor
|
||||
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
|
||||
|
||||
# Unfortunately, there's no accessor for the pointer to the native renderer
|
||||
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
|
||||
|
||||
# Return a handle which contains a reference to the photo object
|
||||
# which must be kept live or else the picture disappears
|
||||
return photo
|
||||
|
||||
#------------------------------- PASTE YOUR MATPLOTLIB CODE HERE -------------------------------
|
||||
|
@ -94,25 +87,14 @@ plt.plot(x, y)
|
|||
plt.yscale('logit')
|
||||
plt.title('logit')
|
||||
plt.grid(True)
|
||||
# Format the minor tick labels of the y-axis into empty strings with
|
||||
# `NullFormatter`, to avoid cumbering the axis with too many labels.
|
||||
plt.gca().yaxis.set_minor_formatter(NullFormatter())
|
||||
# Adjust the subplot layout, because the logit one may take more space
|
||||
# than usual, due to y-tick labels like "1 - 10^{-3}"
|
||||
plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,
|
||||
wspace=0.35)
|
||||
|
||||
fig = plt.gcf() # if using Pyplot then get the figure from the plot
|
||||
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
|
||||
|
||||
#------------------------------- END OF YOUR MATPLOTLIB CODE -------------------------------
|
||||
|
||||
# ****** Comment out this line if not using Pyplot ******
|
||||
fig = plt.gcf() # if using Pyplot then get the figure from the plot
|
||||
|
||||
# -------------------------------- 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
|
||||
# define the form layout
|
||||
layout = [[sg.Text('Plot test', font='Any 18')],
|
||||
[sg.Canvas(size=(figure_w, figure_h), key='canvas')],
|
||||
|
|
|
@ -24,44 +24,66 @@ from sys import exit as exit
|
|||
The simple case is that you want to add a single meter to your code. The one-line solution
|
||||
"""
|
||||
|
||||
|
||||
# Display a progress meter in work loop. User is not allowed to break out of the loop
|
||||
for i in range(10000):
|
||||
if i % 5 == 0: sg.OneLineProgressMeter('My 1-line progress meter', i+1, 10000, 'single')
|
||||
|
||||
# Display a progress meter. Allow user to break out of loop using cancel button
|
||||
for i in range(10000):
|
||||
if not sg.OneLineProgressMeter('My 1-line progress meter', i+1, 10000, 'single'):
|
||||
break
|
||||
def DemoOneLineProgressMeter():
|
||||
# Display a progress meter. Allow user to break out of loop using cancel button
|
||||
for i in range(1000):
|
||||
if not sg.OneLineProgressMeter('My 1-line progress meter', i+1, 1000, 'meter key' ):
|
||||
break
|
||||
|
||||
|
||||
layout = [
|
||||
[sg.T('One-Line Progress Meter Demo', font=('Any 18'))],
|
||||
[sg.T('Outer Loop Count', size=(15,1), justification='r'), sg.In(default_text='100', size=(5,1), key='CountOuter', do_not_clear=True),
|
||||
sg.T('Delay'), sg.In(default_text='10', key='TimeOuter', size=(5,1), do_not_clear=True), sg.T('ms')],
|
||||
[sg.T('Inner Loop Count', size=(15,1), justification='r'), sg.In(default_text='100', size=(5,1), key='CountInner', do_not_clear=True) ,
|
||||
sg.T('Delay'), sg.In(default_text='10', key='TimeInner', size=(5,1), do_not_clear=True), sg.T('ms')],
|
||||
[sg.Button('Show', pad=((0,0), 3), bind_return_key=True), sg.T('me the meters!')]
|
||||
]
|
||||
layout = [
|
||||
[sg.T('One-Line Progress Meter Demo', font=('Any 18'))],
|
||||
[sg.T('Outer Loop Count', size=(15,1), justification='r'), sg.In(default_text='100', size=(5,1), key='CountOuter', do_not_clear=True),
|
||||
sg.T('Delay'), sg.In(default_text='10', key='TimeOuter', size=(5,1), do_not_clear=True), sg.T('ms')],
|
||||
[sg.T('Inner Loop Count', size=(15,1), justification='r'), sg.In(default_text='100', size=(5,1), key='CountInner', do_not_clear=True) ,
|
||||
sg.T('Delay'), sg.In(default_text='10', key='TimeInner', size=(5,1), do_not_clear=True), sg.T('ms')],
|
||||
[sg.Button('Show', pad=((0,0), 3), bind_return_key=True), sg.T('me the meters!')]
|
||||
]
|
||||
|
||||
window = sg.Window('One-Line Progress Meter Demo').Layout(layout)
|
||||
window = sg.Window('One-Line Progress Meter Demo').Layout(layout)
|
||||
|
||||
while True:
|
||||
button, values = window.Read()
|
||||
if button is None:
|
||||
break
|
||||
if button == 'Show':
|
||||
max_outer = int(values['CountOuter'])
|
||||
max_inner = int(values['CountInner'])
|
||||
delay_inner = int(values['TimeInner'])
|
||||
delay_outer = int(values['TimeOuter'])
|
||||
for i in range(max_outer):
|
||||
if not sg.OneLineProgressMeter('Outer Loop', i+1, max_outer, 'outer'):
|
||||
break
|
||||
sleep(delay_outer/1000)
|
||||
for j in range(max_inner):
|
||||
if not sg.OneLineProgressMeter('Inner Loop', j+1, max_inner, 'inner'):
|
||||
while True:
|
||||
button, values = window.Read()
|
||||
if button is None:
|
||||
break
|
||||
if button == 'Show':
|
||||
max_outer = int(values['CountOuter'])
|
||||
max_inner = int(values['CountInner'])
|
||||
delay_inner = int(values['TimeInner'])
|
||||
delay_outer = int(values['TimeOuter'])
|
||||
for i in range(max_outer):
|
||||
if not sg.OneLineProgressMeter('Outer Loop', i+1, max_outer, 'outer'):
|
||||
break
|
||||
sleep(delay_inner/1000)
|
||||
sleep(delay_outer/1000)
|
||||
for j in range(max_inner):
|
||||
if not sg.OneLineProgressMeter('Inner Loop', j+1, max_inner, 'inner'):
|
||||
break
|
||||
sleep(delay_inner/1000)
|
||||
|
||||
exit(69)
|
||||
'''
|
||||
Make your own progress meter!
|
||||
Embed the meter right into your window
|
||||
'''
|
||||
|
||||
def CustomMeter():
|
||||
# layout the form
|
||||
layout = [[sg.Text('A custom progress meter')],
|
||||
[sg.ProgressBar(10000, orientation='h', size=(20,20), key='progress')],
|
||||
[sg.Cancel()]]
|
||||
|
||||
# create the form`
|
||||
window = sg.Window('Custom Progress Meter').Layout(layout)
|
||||
progress_bar = window.FindElement('progress')
|
||||
# loop that would normally do something useful
|
||||
for i in range(10000):
|
||||
# check to see if the cancel button was clicked and exit loop if clicked
|
||||
button, values = window.ReadNonBlocking()
|
||||
if button == 'Cancel' or values == None:
|
||||
break
|
||||
# update bar with loop value +1 so that bar eventually reaches the maximum
|
||||
progress_bar.UpdateBar(i+1)
|
||||
# done with loop... need to destroy the window as it's still open
|
||||
window.CloseNonBlocking()
|
||||
|
||||
CustomMeter()
|
||||
DemoOneLineProgressMeter()
|
|
@ -2760,14 +2760,18 @@ def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False)
|
|||
if type(sub_menu_info) is str:
|
||||
if not is_sub_menu and not skip:
|
||||
# print(f'Adding command {sub_menu_info}')
|
||||
pos = sub_menu_info.find('&')
|
||||
pos = sub_menu_info.find('_&')
|
||||
if pos != -1:
|
||||
if pos == 0 or sub_menu_info[pos-1] != "\\":
|
||||
sub_menu_info = sub_menu_info[:pos] + sub_menu_info[pos+1:]
|
||||
_ = sub_menu_info[:pos]
|
||||
try:
|
||||
_ += sub_menu_info[pos+2:]
|
||||
except Exception as e:
|
||||
print(e)
|
||||
sub_menu_info = _
|
||||
if sub_menu_info == '---':
|
||||
top_menu.add('separator')
|
||||
else:
|
||||
top_menu.add_command(label=sub_menu_info, underline=pos, command=lambda: Menu.MenuItemChosenCallback(element, sub_menu_info))
|
||||
top_menu.add_command(label=sub_menu_info, underline=pos-1, command=lambda: Menu.MenuItemChosenCallback(element, sub_menu_info))
|
||||
else:
|
||||
i = 0
|
||||
while i < (len(sub_menu_info)):
|
||||
|
@ -3244,11 +3248,15 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
|||
for menu_entry in menu_def:
|
||||
# print(f'Adding a Menubar ENTRY')
|
||||
baritem = tk.Menu(menubar, tearoff=element.Tearoff)
|
||||
pos = menu_entry[0].find('&')
|
||||
pos = menu_entry[0].find('_&')
|
||||
if pos != -1:
|
||||
if pos == 0 or menu_entry[0][pos-1] != "\\":
|
||||
menu_entry[0] = menu_entry[0][:pos] + menu_entry[0][pos+1:]
|
||||
menubar.add_cascade(label=menu_entry[0], menu=baritem, underline = pos)
|
||||
_ = menu_entry[0][:pos]
|
||||
try:
|
||||
_ += menu_entry[0][pos+2:]
|
||||
except:
|
||||
pass
|
||||
menu_entry[0] = _
|
||||
menubar.add_cascade(label=menu_entry[0], menu=baritem, underline = pos-1)
|
||||
if len(menu_entry) > 1:
|
||||
AddMenuItem(baritem, menu_entry[1], element)
|
||||
toplevel_form.TKroot.configure(menu=element.TKMenu)
|
||||
|
|
Loading…
Reference in New Issue