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
#2
print('clicked') 
is not working?
Reply
#3
(Jul-23-2021, 05:58 PM)Axel_Erfurt Wrote:
print('clicked') 
is not working?
no, it is really weird.
Reply
#4
(Jul-23-2021, 05:58 PM)Axel_Erfurt Wrote:
print('clicked') 
is not working?

I'm not sure if it is wrong to connect one signal to two slots that way, but i think the second part (Sample_Stat) is not working as well, but it used to.
Reply
#5
    os.system('python -m PyQt5.uic.pyuic PI_GUI_App_Map.ui -o PI_GUI_App_Map.py')
Do that once (in a terminal)and remove this line.

Without knowing the code of PI_GUI_App_Map and PI_GUI_Funcc and count.txt it is difficult to help.
Reply
#6
(Jul-26-2021, 03:30 PM)Axel_Erfurt Wrote:
    os.system('python -m PyQt5.uic.pyuic PI_GUI_App_Map.ui -o PI_GUI_App_Map.py')
Do that once (in a terminal)and remove this line.

Without knowing the code of PI_GUI_App_Map and PI_GUI_Funcc and count.txt it is difficult to help.

Thanks for replying.

yes, I have tried that (without os.system()).
PI_GUI_App_Map.py is transformed from the ui file.
PI_GUI_Func includes a class to start up a child thread.
count.txt is a file created by another equipment, which is monitored by this program to see when it changes (basically just 1, 2, 3...).
The py files are attached.

Many thanks

Attached Files

.py   PI_GUI_Func.py (Size: 1.79 KB / Downloads: 14)
.py   PI_GUI_App_Map.py (Size: 8.15 KB / Downloads: 12)
.py   AppMap_setup.py (Size: 5.95 KB / Downloads: 15)
Reply
#7
(Jul-26-2021, 03:30 PM)Axel_Erfurt Wrote:
    os.system('python -m PyQt5.uic.pyuic PI_GUI_App_Map.ui -o PI_GUI_App_Map.py')
Do that once (in a terminal)and remove this line.

Without knowing the code of PI_GUI_App_Map and PI_GUI_Funcc and count.txt it is difficult to help.

I just tried the file again, it worked. I have no idea what is wrong lol
Reply
#8
you forgot super().__init__() in main

    def main(self,MainWindow):
        super().__init__()
        MainWindow.setWindowTitle('Approach Curve-Map')
Reply
#9
(Jul-26-2021, 08:54 PM)Axel_Erfurt Wrote: you forgot super().__init__() in main

    def main(self,MainWindow):
        super().__init__()
        MainWindow.setWindowTitle('Approach Curve-Map')

yeah thanks. everything is working now even tho idk what really went wrong lol.
Reply
#10
Do you use any kind of version control software? If not, you really should start. Knowing what you changed to make something work, or more importantly what you changed that made something stop working, will go a long way in speeding your learning progress.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Hide clicked buttons Rubberduck 6 711 Jun-02-2021, 12:44 PM
Last Post: Rubberduck
  [tkinter] not getting checkbutton value when clicked OogieM 5 1,524 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 870 May-05-2020, 12:54 PM
Last Post: mart79
  Closing window on button click not working kenwatts275 4 1,029 May-03-2020, 01:59 PM
Last Post: deanhystad
  [Tkinter] Displaying Data from a database and run a function when clicked? PythonNPC 1 826 Mar-11-2020, 08:16 PM
Last Post: Larz60+
  tkinter button not accessing the command when clicked jhf2 1 1,114 Nov-23-2019, 10:17 PM
Last Post: DT2000
  [Tkinter] How to check after 30 minutes if Buttons have been clicked? bmghafoor 1 956 Aug-09-2019, 04:57 PM
Last Post: Yoriz
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 2,445 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Hide button when clicked frequency 2 4,681 Dec-24-2018, 02:10 PM
Last Post: frequency
  how to execute .py script when button is clicked D_frucht 1 2,284 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