def __init__(self, *args, **kwargs): super(CadastroOS, self).__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle("Cadastro de OSs") self.setFixedSize(845, 440) self.ui.textDate.setDate(datetime.datetime.now().date()) # Conecta os eventos dos botões self.ui.btSalvar.clicked.connect(self.btSalvar) self.ui.btLimpar.clicked.connect( lambda: self.btLimpar(self.ui.btLimpar)) #caminho = find_data_file("famotica.db") # Para cada tela de cadastro aberta, uma nova conexão ao banco é feita. #engine = create_engine('sqlite:///%s', echo=False) Session = sessionmaker(bind=engine) self.session = Session()
class CadastroOS(QtGui.QWidget): def __init__(self, *args, **kwargs): super(CadastroOS, self).__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle("Cadastro de OSs") self.setFixedSize(845, 440) self.ui.textDate.setDate(datetime.datetime.now().date()) # Conecta os eventos dos botões self.ui.btSalvar.clicked.connect(self.btSalvar) self.ui.btLimpar.clicked.connect( lambda: self.btLimpar(self.ui.btLimpar)) #caminho = find_data_file("famotica.db") # Para cada tela de cadastro aberta, uma nova conexão ao banco é feita. #engine = create_engine('sqlite:///%s', echo=False) Session = sessionmaker(bind=engine) self.session = Session() def btLimpar(self, qbutt): # SEMPRE usar O.O.!! # self.ui.textDate.setDate(datetime.datetime.now().date()) pai = qbutt.parentWidget() if (pai is not None): for tipo in (QtGui.QLineEdit, QtGui.QTextEdit): for filhos in pai.findChildren(tipo): filhos.setText("") def btSalvar(self): seta_locale(False) try: cadastro = OS( nome=self.ui.textNome.text(), endereco=self.ui.textEndereco.text(), preco=locale.atof(self.ui.textPreco.text()), sinal=locale.atof(self.ui.textSinal.text()), formaPagamento=self.ui.textForma.text(), bairro=self.ui.textBairro.text(), cidade=self.ui.textCidade.text(), estado=self.ui.textEstado.text(), telefone=self.ui.textFone.text(), data=datetime.datetime.now(), armacao=self.ui.textArmacao.text(), lente=self.ui.textLente.text(), grauLongeOD=locale.atof(self.ui.textGLOD.text()), grauLongeODCIL=locale.atof(self.ui.textGLODCIL.text()), grauLongeODEIXO=locale.atof(self.ui.textGLODEI.text()), grauLongeOE=locale.atof(self.ui.textGLOE.text()), grauLongeOECIL=locale.atof(self.ui.textGLOECIL.text()), grauLongeOEEIXO=locale.atof(self.ui.textGLOEEI.text()), grauLongeDP=locale.atof(self.ui.textGLDP.text()), grauPertoOD=locale.atof(self.ui.textGPOD.text()), grauPertoODCIL=locale.atof(self.ui.textGPODCIL.text()), grauPertoODEIXO=locale.atof(self.ui.textGPODEI.text()), grauPertoOE=locale.atof(self.ui.textGPOE.text()), grauPertoOECIL=locale.atof(self.ui.textGPOECIL.text()), grauPertoOEEIXO=locale.atof(self.ui.textGPOEEI.text()), grauPertoDP=locale.atof(self.ui.textGPDP.text()), obs=self.ui.TextObs.toPlainText(), dataNasc=datetime.datetime.strptime( self.ui.textDataNasc.text(), getDataString()).date(), sexo=self.ui.comboGenero.currentText(), entrega=datetime.datetime.strptime(self.ui.textDate.text(), getDataString()).date()) mostrarMessageBox("Sucesso!", "OS Cadastrada com sucesso!") except ValueError as e: print e mostrarMessageBox("Erro!", e.message) lineno, fname = get_filename_lnumber() enviaEmail(e.message, fname, lineno) try: self.session.add(cadastro) self.session.commit() except Exception as e: mostrarMessageBox("Erro!", u"Não foi possivel salvar os dados no banco.\n %s" % e.message)