-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: Is there a way to detect if a plot window has been closed? #173
Comments
I think what you have in mind is best realized with a GUI application (e.g. in Qt5 or Qt6) with an embedded GR widget. This would give you complete control over the window management. You could capture the audio data asynchronously in a thread. The advantage of GR is that you can use it in different environments and languages. |
Thanks for the reply, @jheinen. I should have also mentioned that this is a GUI application using TKinter. I can see how I have control over window management, just not specifically detecting if the user closes the GR window (via the 'X' icon, for example). Can you point me in the right direction there? |
Well, you could plot into an image in memory and display it in a Tk canvas. import numpy as np
width, height = 800, 600
image = np.zeros((height, width, 4), np.uint8)
pointer = image.ctypes.data
# Draw something into the memory using gr
import gr
gr.beginprint('!{}x{}@{:x}.mem'.format(width, height, pointer))
gr.polyline([0, 1], [0, 1])
gr.endprint()
# Use the image memory, e.g. using PIL/Pillow
from PIL import Image, ImageTk
img = Image.fromarray(image, 'RGBA')
img.show()
# Alternatively, you could display the image in a Tk canvas
import tkinter
from tkinter import Tk
win = Tk()
win.geometry("800x600")
test = ImageTk.PhotoImage(img)
label = tkinter.Label(image=test)
label.image = test
# Position image
label.place(x=0, y=0)
win.mainloop() |
Hi, I've scoured the docs and and github issues but haven't been able to solve my issue. TL;DR I'd like to know how I can tell if a GR window is open or closed. If you want some more details I've provided them below.
I'm working on an oscilloscope program that can look at units such as db/rms/volts/amplitude of a microphone that can be toggled by a button. As of right now the process looks like this:
i. stop and save the audio
ii. change the unit of measurement
As of right now, if I want to (b) change the unit of measurement I either have to (A):
Or (B), set the program up to just always run the GR code when the mic enabled button is on. This works well as it allows me to change the units in realtime, or even leave the oscilloscope window up even when the mic is toggled off. However....
The issue with (B) is that I would like to have the option to enable the microphone without opening the oscilloscope window. If I could query the visibility of the plot window things would be simple as pie.
Does anyone have any suggestions?
The text was updated successfully, but these errors were encountered: