Python Forum
[PyQt] Assign Label Text as number in Hz
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Assign Label Text as number in Hz
#14
(Jul-12-2018, 09:38 PM)Alfalfa Wrote: I'm glad to help you get on the right track, but unfortunately I do not have the time to go over your code. So your problem is that you are trying to have a long running code in parallel with your GUI? In that case, instead of QTimer your need to put the long running code in a separate thread, or else the GUI will becomes unresponsive.

Then the right way to send data back from the worker thread to the gui thread is by using signals and slots. To get you started, have a look at this example: https://gitlab.com/snippets/1732597

In your case, the frequency analysis would go into the function run() (class WorkerThread), the result would be sent through the signal/slot mechanism, and the label would be set into the function signalExample() of the gui thread (class Main). Hope that helps.

I've checked the post you linked but it's for Python 3x and using PyQt5, and I'm using Python 2.7 and PyQt4...
So what I can confirmed for the progress I've been making from my last post is, when I said it's error not showing the graphs window and etc but only the python running box...

It's actually happened that way because when I combined the freq analyzer with my graph sound visualizer and when I run the overall code both the freq analyzer and sound visualizer (it's on the go.py)
from PyQt4 import QtGui,QtCore

import sys
import ui_main
import StrSetting
import numpy as np
import pyqtgraph
import SWHear
import freq
from freq import Freq_analysis

class SoundApp(QtGui.QMainWindow, ui_main.Ui_MainWindow):
    def __init__(self, parent=None):
        pyqtgraph.setConfigOption('background', 'w') #before loading widget
        super(SoundApp, self).__init__(parent)
        self.setupUi(self)
        self.grFFT.plotItem.showGrid(True, True, 0.7)
        self.grPCM.plotItem.showGrid(True, True, 0.7)
        self.maxFFT=0
        self.maxPCM=0
        self.ear = SWHear.SWHear(rate=44100,updatesPerSecond=20)
        self.ear.stream_start()
        

    def update(self):
        if not self.ear.data is None and not self.ear.fft is None:
            pcmMax=np.max(np.abs(self.ear.data))
            if pcmMax>self.maxPCM:
                self.maxPCM=pcmMax
                self.grPCM.plotItem.setRange(yRange=[-pcmMax,pcmMax])
            if np.max(self.ear.fft)>self.maxFFT:
                self.maxFFT=np.max(np.abs(self.ear.fft))
                #self.grFFT.plotItem.setRange(yRange=[0,self.maxFFT])
                self.grFFT.plotItem.setRange(yRange=[0,1])
            self.pbLevel.setValue(1000*pcmMax/self.maxPCM)
            pen=pyqtgraph.mkPen(color='b')
            self.grPCM.plot(self.ear.datax,self.ear.data,pen=pen,clear=True)
            pen=pyqtgraph.mkPen(color='r')
            self.grFFT.plot(self.ear.fftx,self.ear.fft/self.maxFFT,pen=pen,clear=True)
        QtCore.QTimer.singleShot(1, self.update) # QUICKLY repeat
        

if __name__=="__main__":
    app = QtGui.QApplication(sys.argv)
    form = SoundApp()
    form.show()
    form.update() #start with something
    Tuner = Freq_analysis()

    for i in range(100):
        Tuner.listen()
    app.exec_()
    print("DONE")
so what I want to pointed is, the freq analyzer is had to be runned 1st and finishing it's recording and later the sound visualizer came in (so the sound visualizer window keeps loading whie the freq give it's results) Wall

what can I do to make the both running in the same time?? Huh
Reply


Messages In This Thread
Assign Label Text as number in Hz - by mekha - Jul-01-2018, 12:45 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-01-2018, 05:28 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-01-2018, 11:12 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-03-2018, 04:17 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-04-2018, 01:44 AM
RE: Assign Label Text as number in Hz - by mekha - Jul-07-2018, 02:44 AM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-10-2018, 04:26 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-11-2018, 04:18 AM
RE: Assign Label Text as number in Hz - by DeaD_EyE - Jul-03-2018, 10:02 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-07-2018, 01:14 AM
RE: Assign Label Text as number in Hz - by DeaD_EyE - Jul-04-2018, 10:30 AM
RE: Assign Label Text as number in Hz - by mekha - Jul-12-2018, 01:48 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-12-2018, 09:38 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-16-2018, 11:39 AM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-16-2018, 12:45 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-16-2018, 01:59 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-16-2018, 04:35 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-18-2018, 12:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,216 Jun-26-2022, 06:26 PM
Last Post: menator01
  update text variable on label with keypress knoxvilles_joker 3 5,063 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  How to read text in kivy textinput or Label jadel440 1 5,379 Dec-29-2020, 10:47 AM
Last Post: joe_momma
  Tkinter: How to assign calculated value to a Label LoneStar 7 4,012 Sep-03-2020, 08:19 PM
Last Post: LoneStar
  [Kivy] Kivy text label won't shows up! AVD_01 1 2,990 Jun-21-2020, 04:01 PM
Last Post: AVD_01
  [Tkinter] Python 3 change label text gw1500se 6 4,828 May-08-2020, 05:47 PM
Last Post: deanhystad
  [Tkinter] how to update label text from list Roshan 8 5,598 Apr-25-2020, 08:04 AM
Last Post: Roshan
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,863 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [Tkinter] Label, align imported text from pandas kundrius 2 4,303 Dec-11-2019, 08:26 AM
Last Post: kundrius
  Make Label Text background (default color) transparent using tkinter in python barry76 1 24,144 Nov-28-2019, 10:19 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020