def engine(self, format): engine = self._engines.get(format, None) # self._engine if engine is None: engine = self.engineByFormat.get(format, self.MainEngine)(self._db, self._orgId, progressInformer=self._pi, format=format) engine.setLastExceptionHandler(self._lastExceptionHandler) engine.setUserConfirmationFunction(self.userConfirmation) loggerHandler = CLogHandler(engine.logger(), self) loggerHandler.setLevel(logging.INFO) loggerHandler.logged.connect(self.logInfo.append) self._engines[format] = engine return engine
def __init__(self, db, parent = None): super(CImportDialog, self).__init__(parent = parent) self._db = db self._pi = CProgressInformer(processEventsFlag=QtCore.QEventLoop.AllEvents) self._engine = CImportR85ERZCentralEngine(db, progressInformer=self._pi) self._engine.setUserConfirmationFunction(self.userConfirmation) self._loggerHandler = CLogHandler(self._engine.logger(), self) self._loggerHandler.setLevel(logging.INFO) self._currentState = self.InitState self.setupUi() self.onStateChanged()
def __init__(self, db, accountId, parent=None): super(CExport85MTR_Refused, self).__init__(parent) self._db = db self._pi = CProgressInformer( processEventsFlag=QtCore.QEventLoop.AllEvents) self._accountId = accountId self._engine = CExportR85MTREngine_Refused(db, progressInformer=self._pi) self._loggerHandler = CLogHandler(self._engine.logger(), self) self._loggerHandler.setLevel(logging.INFO) self._currentState = self.InitState self.setupUi() self.onStateChanged()
def on_btnMiac_toggled(self, checked): if not checked: self.engine = CExportR23AttachClientSMOEngine( self.db, self.cmbOrgStructure.value(), self.edtDate.date(), progressInformer=self.pi) self.loggerHandler = CLogHandler(self.engine.logger(), self) else: self.engine = CExportR23AttachClientMIACEngine( self.db, self.cmbOrgStructure.value(), self.edtDate.date(), progressInformer=self.pi) self.loggerHandler = CLogHandler(self.engine.logger(), self)
def __init__(self, db, contractId, parent=None): # noinspection PyArgumentList super(CImport85MTR_Refused, self).__init__(parent=parent) self._db = db self._pi = CProgressInformer( processEventsFlag=QtCore.QEventLoop.AllEvents) self._engine = CImportR85MTREngine_Refused(db, contractId, progressInformer=self._pi) self._engine.setUserConfirmationFunction(self.userConfirmation) self._loggerHandler = CLogHandler(self._engine.logger(), self) self._loggerHandler.setLevel(logging.INFO) self._currentState = self.InitState self.setupUi() self.onStateChanged()
def __init__(self, db, parent=None): QtGui.QDialog.__init__(self, parent) self.db = db self.pi = CProgressInformer( processEventsFlag=QtCore.QEventLoop.AllEvents) self.currentState = self.InitState self.setupUi() self.engine = CExportR23AttachClientMIACEngine( self.db, self.cmbOrgStructure.value(), self.edtDate.date(), progressInformer=self.pi) self.loggerHandler = CLogHandler(self.engine.getLogger(), self) self.btnMiac.setChecked(True) self.onStateChange()
def onNextActionClicked(self): if self.currentState == self.InitState: result = False self.currentState = self.ExportState for accountId in self._accountIdList: engine = None exportInfo = getAccountExportFormat(accountId).split() if exportInfo: exportFormat = exportInfo[0] if exportFormat in ('R85XML'): engine = CExportR85TFEngine(self._db, progressInformer=self._pi, FLC=True) # Крым, выгрузка диспансеризации и профосмотров (МО->Фонд) elif exportFormat == 'R85DDXML': engine = CExportR85DDTFEngine( self._db, progressInformer=self._pi, FLC=True) elif exportFormat == 'R85HTXML': engine = CExportR85HTTFEngine( self._db, progressInformer=self._pi, FLC=True) if engine: # FIXME: может провоцировать падения/ошибки? CLogHandler(engine.logger(), self).logged.connect(self.logInfo.append) self._engines.append(engine) try: result = engine.process(accountId) except: self.currentState = self.InitState raise self.currentState = self.SaveState if result else self.InitState elif self.currentState == self.ExportState: for engine in self._engines: engine.terminate() self._engines = [] elif self.currentState == self.SaveState: self.currentState = self.InitState self.onStateChanged()
class CImportDialog(QtGui.QDialog): InitState = 0 ImportState = 1 def __init__(self, db, parent = None): super(CImportDialog, self).__init__(parent = parent) self._db = db self._pi = CProgressInformer(processEventsFlag=QtCore.QEventLoop.AllEvents) self._engine = CImportR85ERZCentralEngine(db, progressInformer=self._pi) self._engine.setUserConfirmationFunction(self.userConfirmation) self._loggerHandler = CLogHandler(self._engine.logger(), self) self._loggerHandler.setLevel(logging.INFO) self._currentState = self.InitState self.setupUi() self.onStateChanged() def setParams(self, params): if isinstance(params, dict): reqFileName = forceStringEx(getPref(params, 'reqFile', u'')) if os.path.isfile(reqFileName ): self.edtReqFileName.setText(reqFileName ) respFileName = forceStringEx(getPref(params, 'respFile', u'')) if os.path.isfile(respFileName): self.edtRespFileName.setText(respFileName) def engine(self): return self._engine def params(self): params = {} setPref(params, 'reqFile', forceStringEx(self.edtReqFileName.text())) setPref(params, 'respFile', forceStringEx(self.edtRespFileName.text())) return params @property def currentState(self): return self._currentState @currentState.setter def currentState(self, value): if value in [self.InitState, self.ImportState]: self._currentState = value self.onStateChanged() def onStateChanged(self): self.btnNextAction.setText(self._actionNames.get(self.currentState, u'<Error>')) self.btnClose.setEnabled(self.currentState != self.ImportState) self.gbInit.setEnabled(self.currentState == self.InitState) self.gbImport.setEnabled(self.currentState == self.ImportState) # self.btnSave.setEnabled(bool(self._engine.documents)) QtCore.QCoreApplication.processEvents() # noinspection PyAttributeOutsideInit,PyUnresolvedReferences def setupUi(self): layout = QtGui.QVBoxLayout() # init block self.gbInit = QtGui.QGroupBox() gbLayout = QtGui.QVBoxLayout() lineLayout = QtGui.QHBoxLayout() self.edtReqFileName = QtGui.QLineEdit() self.edtReqFileName.setReadOnly(True) lineLayout.addWidget(self.edtReqFileName) self.btnBrowseReqFile = QtGui.QToolButton() self.btnBrowseReqFile.clicked.connect(self.onBrowseReqFileClicked) lineLayout.addWidget(self.btnBrowseReqFile) gbLayout.addLayout(lineLayout) lineLayout = QtGui.QHBoxLayout() self.edtRespFileName = QtGui.QLineEdit() self.edtRespFileName.setReadOnly(True) lineLayout.addWidget(self.edtRespFileName) self.btnBrowseRespFile = QtGui.QToolButton() self.btnBrowseRespFile.clicked.connect(self.onBrowseRespFileClicked) lineLayout.addWidget(self.btnBrowseRespFile) gbLayout.addLayout(lineLayout) self.gbInit.setLayout(gbLayout) layout.addWidget(self.gbInit) # import block self.gbImport = QtGui.QGroupBox() gbLayout = QtGui.QVBoxLayout() self.progressBar = CProgressBar() self.progressBar.setAlignment(QtCore.Qt.AlignCenter) self.progressBar.setRange(0, 0) self.progressBar.setProgressFormat(u'(%v/%m)') self._pi.progressChanged.connect(self.progressBar.setProgress) gbLayout.addWidget(self.progressBar) self.gbImport.setLayout(gbLayout) layout.addWidget(self.gbImport) # log block self.logInfo = QtGui.QTextEdit() layout.addWidget(self.logInfo) self._loggerHandler.logged.connect(self.logInfo.append) # buttons block subLayout = QtGui.QHBoxLayout() self.btnNextAction = QtGui.QPushButton() # noinspection PyUnresolvedReferences self.btnNextAction.clicked.connect(self.onNextActionClicked) subLayout.addStretch() subLayout.addWidget(self.btnNextAction) self.btnClose = QtGui.QPushButton() self.btnClose.clicked.connect(self.onCloseClicked) subLayout.addWidget(self.btnClose) layout.addLayout(subLayout) self.setLayout(layout) self.setMinimumWidth(512) self.retranslateUi() # noinspection PyAttributeOutsideInit def retranslateUi(self): context = unicode(getClassName(self)) self.setWindowTitle(forceTr(u'Импорт. Крым. ЦС ЕРЗ.', context)) self.gbInit.setTitle(forceTr(u'Параметры импорта', context)) self.gbImport.setTitle(forceTr(u'Импорт', context)) self._actionNames = {self.InitState: forceTr(u'Импорт',context), self.ImportState: forceTr(u'Прервать', context)} self.btnClose.setText(forceTr(u'Закрыть', context)) def userConfirmation(self, title, message): # noinspection PyTypeChecker,PyCallByClass return QtGui.QMessageBox.Yes == QtGui.QMessageBox.question(self, title, message, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) @QtCore.pyqtSlot() def onNextActionClicked(self): if self.currentState == self.InitState: self.currentState = self.ImportState try: self._engine.process(forceStringEx(self.edtReqFileName.text()), forceStringEx(self.edtRespFileName.text())) except Exception, e: self.currentState = self.InitState raise self.currentState = self.InitState elif self.currentState == self.ImportState: self._engine.abort() self.currentState = self.InitState
class CExport85MTR_Refused(QtGui.QDialog): InitState = 0 ExportState = 1 SaveState = 2 def __init__(self, db, accountId, parent=None): super(CExport85MTR_Refused, self).__init__(parent) self._db = db self._pi = CProgressInformer( processEventsFlag=QtCore.QEventLoop.AllEvents) self._accountId = accountId self._engine = CExportR85MTREngine_Refused(db, progressInformer=self._pi) self._loggerHandler = CLogHandler(self._engine.logger(), self) self._loggerHandler.setLevel(logging.INFO) self._currentState = self.InitState self.setupUi() self.onStateChanged() def engine(self): return self._engine def setParams(self, params): if isinstance(params, dict): outDir = forceStringEx(getPref(params, 'outDir', u'')) if os.path.isdir(outDir): self.edtSaveDir.setText(outDir) accNumber = forceInt(getPref(params, 'accNumber', 0)) + 1 self.spbAccountNumber.setValue(accNumber) def params(self): params = {} setPref(params, 'outDir', forceStringEx(self.edtSaveDir.text())) setPref(params, 'accNumber', self.spbAccountNumber.value()) return params @property def currentState(self): return self._currentState @currentState.setter def currentState(self, value): if value in [self.InitState, self.ExportState, self.SaveState]: self._currentState = value self.onStateChanged() def onStateChanged(self): self.btnNextAction.setText( self._actionNames.get(self.currentState, u'<Error>')) self.btnClose.setEnabled(self.currentState != self.ExportState) self.gbInit.setEnabled(self.currentState == self.InitState) self.gbExport.setEnabled(self.currentState == self.ExportState) self.gbSave.setEnabled(self.currentState == self.SaveState) self.btnSave.setEnabled(bool(self._engine.documents)) QtCore.QCoreApplication.processEvents() # noinspection PyAttributeOutsideInit def setupUi(self): layout = QtGui.QVBoxLayout() # init block self.gbInit = QtGui.QGroupBox() gbLayout = QtGui.QHBoxLayout() self.lblAccountNumber = QtGui.QLabel() gbLayout.addWidget(self.lblAccountNumber) self.spbAccountNumber = QtGui.QSpinBox() self.spbAccountNumber.setRange(1, 9999) gbLayout.addWidget(self.spbAccountNumber) self.gbInit.setLayout(gbLayout) layout.addWidget(self.gbInit) # export block self.gbExport = QtGui.QGroupBox() gbLayout = QtGui.QVBoxLayout() self.progressBar = CProgressBar() self.progressBar.setAlignment(QtCore.Qt.AlignCenter) self.progressBar.setRange(0, 0) self.progressBar.setProgressFormat(u'(%v/%m)') self._pi.progressChanged.connect(self.progressBar.setProgress) gbLayout.addWidget(self.progressBar) self.gbExport.setLayout(gbLayout) layout.addWidget(self.gbExport) # save block self.gbSave = QtGui.QGroupBox() gbLayout = QtGui.QVBoxLayout() lineLayout = QtGui.QHBoxLayout() self.edtSaveDir = QtGui.QLineEdit(QtCore.QDir.homePath()) self.edtSaveDir.setReadOnly(True) lineLayout.addWidget(self.edtSaveDir) self.btnBrowseDir = QtGui.QToolButton() self.btnBrowseDir.clicked.connect(self.onBrowseDirClicked) lineLayout.addWidget(self.btnBrowseDir) gbLayout.addLayout(lineLayout) lineLayout = QtGui.QHBoxLayout() # self.chkZipping = QtGui.QCheckBox() # lineLayout.addWidget(self.chkZipping) self.btnSave = QtGui.QPushButton() self.btnSave.clicked.connect(self.onSaveClicked) lineLayout.addWidget(self.btnSave) gbLayout.addLayout(lineLayout) self.gbSave.setLayout(gbLayout) layout.addWidget(self.gbSave) # log block self.logInfo = QtGui.QTextEdit() layout.addWidget(self.logInfo) self._loggerHandler.logged.connect(self.logInfo.append) # buttons block subLayout = QtGui.QHBoxLayout() self.btnNextAction = QtGui.QPushButton() self.btnNextAction.clicked.connect(self.onNextActionClicked) subLayout.addStretch() subLayout.addWidget(self.btnNextAction) self.btnClose = QtGui.QPushButton() self.btnClose.clicked.connect(self.onCloseClicked) subLayout.addWidget(self.btnClose) layout.addLayout(subLayout) self.setLayout(layout) self.setMinimumWidth(512) self.retranslateUi() # noinspection PyAttributeOutsideInit def retranslateUi(self): context = unicode(getClassName(self)) self.setWindowTitle( forceTr(u'Экспорт. Крым. МежТер. Возврат.', context)) self.gbInit.setTitle(forceTr(u'Параметры экспорта', context)) self.lblAccountNumber.setText( forceTr(u'Номер выгрузки по счету', context)) self.gbExport.setTitle(forceTr(u'Экспорт', context)) self.gbSave.setTitle(forceTr(u'Сохранение результата', context)) self.btnSave.setText(forceTr(u'Сохранить', context)) self._actionNames = { self.InitState: forceTr(u'Экспорт', context), self.ExportState: forceTr(u'Прервать', context), self.SaveState: forceTr(u'Повторить', context) } self.btnClose.setText(forceTr(u'Закрыть', context)) @QtCore.pyqtSlot() def onNextActionClicked(self): if self.currentState == self.InitState: self.currentState = self.ExportState try: result = self._engine.process(self._accountId) except Exception, e: self.currentState = self.InitState raise self.currentState = self.SaveState if result else self.InitState elif self.currentState == self.ExportState: self._engine.abort()