Python Forum
[PyQt] Button clicked not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Button clicked not working
#1
import sys,os,re,time
import numpy as np
import PI_GUI_App_Map as pgam
import PI_GUI_Func as pgfunc
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow, QLineEdit, QMessageBox, QProgressDialog ,QWidget,QGridLayout,QPushButton,QLabel,QTextBrowser,QDesktopWidget,QProgressBar
from PyQt5.QtGui import *
from PyQt5 import QtCore
from PyQt5.QtCore import Qt, QThread, pyqtSignal 

#———————————————GLOBAL VAR———————————————#
PATH='C:\\Users\\jy1u18\\OneDrive - University of Southampton\\secm\\PI-AUTOLAB\\count.txt'

'''———————————————————CLASS———————————————————'''
class appmap(pgam.Ui_Form,QThread):

#——————————————————————————————————#
    def __init__(self,MainWindow,signal):
        self.signal=signal
        self.xlist=[]
        self.ylist=[]
        self.zlist=[]
        self.setupUi(MainWindow)
        self.main(MainWindow)
#——————————————————————————————————#
    def main(self,MainWindow):
        MainWindow.setWindowTitle('Approach Curve-Map')
        self.lineEdit_xp.editingFinished.connect(
            lambda: self.list_read(widget=self.lineEdit_xp,tlist=self.xlist))
        self.lineEdit_yp.editingFinished.connect(
            lambda: self.list_read(widget=self.lineEdit_yp,tlist=self.ylist))
        self.lineEdit_zp.editingFinished.connect(
            lambda: self.list_read(widget=self.lineEdit_zp,tlist=self.zlist))

        self.lineEdit_xp.editingFinished.connect(self.Sample_Stat)
        self.lineEdit_yp.editingFinished.connect(self.Sample_Stat)
        self.lineEdit_zp.editingFinished.connect(self.Sample_Stat)

        self.pushButton.clicked.connect(self.click)
        self.pushButton_2.clicked.connect(self.Monitor_Thrd)

        self.lineEdit_xp.setText('1,2')
        self.lineEdit_yp.setText('1,2')
        self.lineEdit_zp.setText('(0 8 2),(10 45 5),(50 90 10),(100 500 50),(600 2000 200)')
        
        self.list_read(widget=self.lineEdit_xp,tlist=self.xlist)
        self.list_read(widget=self.lineEdit_yp,tlist=self.ylist)
        self.list_read(widget=self.lineEdit_zp,tlist=self.zlist)
        self.Sample_Stat()

    def click(self):
        print('clicked')
#——————————————————————————————————#
    def Sample_Stat(self):
        try:
            self.num2d=len(self.xlist) * len(self.ylist)
            self.num3d=len(self.zlist)
            for i in [len(self.xlist),len(self.ylist)]:
                if i != 0:
                    self.num3d=self.num3d*i
            self.lineEdit_total_2d.setText(str(self.num2d))
            self.lineEdit_total_exp.setText(str(self.num3d))
        except KeyboardInterrupt:
            sys.exit(app.exec_())
        # except Exception:
        #     pass
#——————————————————————————————————#
    def Monitor_Thrd(self):
        
        print('this func is called')
        self.msgrunning=QProgressDialog()
        self.msgrunning.setWindowTitle('Approach Curve experiment in progress...')
        self.msgrunning.setLabelText('Approach Curve experiments running.\n'
            'Do not close this or other window while running. \n This window will close upon finish.')
        self.msgrunning.setCancelButton(None)
        self.msgrunning.show()
        self.mon_thrd=pgfunc.Monitor(self.xlist,self.ylist,self.zlist,self.num3d)
        self.mon_thrd.setProgress.connect(self.msgrunning.setValue)
        self.mon_thrd.exp_cmplt.connect(self.Signal_Ascent)
        self.mon_thrd.start()
        
    def Signal_Ascent(self,i):
        self.signal.emit([2,i])
        
    def list_read(self,widget,tlist,ty=int):
        try:
            string=widget.text()
            res=[]
            element=string.split(",")
            sets=[]
            num=[]
            for ele in element:
                if '(' in ele:
                    sets.append(ele)           
                else:
                    num.append(ty(ele))
            res+=list(map(ty, num))
            for i in sets:
                numset=re.findall(r'[(](.*?)[)]', i)
                rangepara=numset[0].split(' ')
                rangepara=list(map(int, rangepara))
                res+=np.arange(rangepara[0],rangepara[1]+1,rangepara[2]).tolist()
            res.sort()
            tlist[:]=res
        except KeyboardInterrupt:
            raise KeyboardInterrupt
        except Exception:
            self.errormsg=QMessageBox()
            self.errormsg.setIcon(QMessageBox.Critical)
            self.errormsg.setText('Potentially input error, please check your inputs')
            self.errormsg.setStandardButtons(QMessageBox.Ok)
            self.errormsg.setWindowTitle('Error')
            self.errormsg.show()

if __name__=='__main__':
    os.system('python -m PyQt5.uic.pyuic PI_GUI_App_Map.ui -o PI_GUI_App_Map.py')
    app = QApplication(sys.argv)
    win=QWidget()
    move_request=pyqtSignal(list)
    ui=appmap(win,move_request)
    win.show()
    sys.exit(app.exec_())
I have no idea why the buttons are not working. I think they were working yesterday
Reply


Messages In This Thread
Button clicked not working - by catlessness - Jul-23-2021, 05:02 PM
RE: Button clicked not working - by Axel_Erfurt - Jul-23-2021, 05:58 PM
RE: Button clicked not working - by catlessness - Jul-26-2021, 01:11 PM
RE: Button clicked not working - by catlessness - Jul-26-2021, 01:26 PM
RE: Button clicked not working - by Axel_Erfurt - Jul-26-2021, 03:30 PM
RE: Button clicked not working - by catlessness - Jul-26-2021, 04:55 PM
RE: Button clicked not working - by catlessness - Jul-26-2021, 04:59 PM
RE: Button clicked not working - by Axel_Erfurt - Jul-26-2021, 08:54 PM
RE: Button clicked not working - by catlessness - Jul-30-2021, 01:30 PM
RE: Button clicked not working - by deanhystad - Jul-30-2021, 07:00 PM
RE: Button clicked not working - by catlessness - Oct-21-2021, 12:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Hide clicked buttons Rubberduck 6 3,576 Jun-02-2021, 12:44 PM
Last Post: Rubberduck
  [tkinter] not getting checkbutton value when clicked OogieM 5 6,112 Sep-20-2020, 04:49 PM
Last Post: deanhystad
  [PyQt] Avoid clicked event from button when button is not physically selected and clicked mart79 2 2,366 May-05-2020, 12:54 PM
Last Post: mart79
  Closing window on button click not working kenwatts275 4 3,802 May-03-2020, 01:59 PM
Last Post: deanhystad
  [Tkinter] Displaying Data from a database and run a function when clicked? PythonNPC 1 2,072 Mar-11-2020, 08:16 PM
Last Post: Larz60+
  tkinter button not accessing the command when clicked jhf2 1 3,585 Nov-23-2019, 10:17 PM
Last Post: DT2000
  [Tkinter] How to check after 30 minutes if Buttons have been clicked? bmghafoor 1 2,113 Aug-09-2019, 04:57 PM
Last Post: Yoriz
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,034 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Hide button when clicked frequency 2 8,816 Dec-24-2018, 02:10 PM
Last Post: frequency
  how to execute .py script when button is clicked D_frucht 1 6,161 Jun-22-2018, 04:23 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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