I have the following code where I initialize three variables g_turno
, g_sucursal
, g_fecha
with any value.
These variables should change their value respectively when the following signals are activated:
self.turno_1.currentIndexChanged.connect(lambda:self.turno_online(self.turno_1.currentText()))
self.sucursal.currentIndexChanged.connect(lambda:self.sucursal_online(self.sucursal.currentText()))
self.fecha.dateChanged.connect(self.cambio_fecha)
Later when the signal self.turno_1.currentIndexChanged.connect(lambda:self.turno_online(self.turno_1.currentText()))
is activated, execute the following action:
@QtCore.pyqtSlot(str)
def turno_online(self,str):
g_turno = str
if str == 'Mañana':
self.stack.setCurrentIndex(0)
editar(self.tabla_1,g_sucursal,g_fecha,g_turno)
else:
self.stack.setCurrentIndex(1)
editar(self.tabla_2,g_sucursal,g_fecha,g_turno)
when I execute the edit function I send the arguments of the previously defined variables as arguments, however the problem is that the variables keep the same value.
This is the complete code:
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import uic
from PyQt5 import QtCore
from Acces import *
import time
from editar_campos import editar
class Principal(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
uic.loadUi("new_exe.ui",self)
global g_turno
g_turno = 'Matutino'
global g_sucursal
g_sucursal = 'Exe 1'
global g_fecha
g_fecha = str(time.strftime("%Y-%m-%d"))
self.fecha.dateChanged.connect(self.cambio_fecha)
self.turno_1.currentIndexChanged.connect(lambda:self.turno_online(self.turno_1.currentText()))
self.sucursal.currentIndexChanged.connect(lambda:self.sucursal_online(self.sucursal.currentText()))
@QtCore.pyqtSlot(QtCore.QDate)
def cambio_fecha(self,fecha):
g_fecha = fecha.toPyDate()
print(g_fecha)
@QtCore.pyqtSlot(str)
def turno_online(self,str):
g_turno = str
if str == 'Mañana':
self.stack.setCurrentIndex(0)
editar(self.tabla_1,g_sucursal,g_fecha,g_turno)
else:
self.stack.setCurrentIndex(1)
editar(self.tabla_2,g_sucursal,g_fecha,g_turno)
@QtCore.pyqtSlot(str)
def sucursal_online(self,str):
g_sucursal = str
app = QApplication([])
p = Principal()
p.show()
app.exec_()