Python Forum

Full Version: Button clicked not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
print('clicked') 
is not working?
(Jul-23-2021, 05:58 PM)Axel_Erfurt Wrote: [ -> ]
print('clicked') 
is not working?
no, it is really weird.
(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.
    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.
(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
(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
you forgot super().__init__() in main

    def main(self,MainWindow):
        super().__init__()
        MainWindow.setWindowTitle('Approach Curve-Map')
(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.
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.
Pages: 1 2