def _init(self): from .History import History minTs = HistoryDbModel.select(peewee.fn.Min( HistoryDbModel.date)).scalar() if minTs <= 0: return today = QDate.currentDate() week = today.addDays(1 - today.dayOfWeek()) month = QDate(today.year(), today.month(), 1) currentTs = QDateTime.currentMSecsSinceEpoch() ts = currentTs while ts > minTs: tsDate = QDateTime.fromMSecsSinceEpoch(ts).date() endTs = 0 itemName = '' if tsDate == today: endTs = QDateTime(today).toMSecsSinceEpoch() itemName = _('Today') elif tsDate >= week: endTs = QDateTime(week).toMSecsSinceEpoch() itemName = _('This Week') elif tsDate.month() == month.month() and tsDate.year( ) == month.year(): endTs = QDateTime(month).toMSecsSinceEpoch() itemName = _('This Month') else: startDate = QDate(tsDate.year(), tsDate.month(), tsDate.daysInMonth()) endDate = QDate(startDate.year(), startDate.month(), 1) ts = QDateTime(startDate, QTime(23, 59, 59)).toMSecsSinceEpoch() endTs = QDateTime(endDate).toMSecsSinceEpoch() itemName = '%s %s' % (tsDate.year(), History.titleCaseLocalizedMonth( tsDate.month())) dbobj = HistoryDbModel.select().where( HistoryDbModel.date.between(endTs, ts)).first() if dbobj: item = HistoryItem(self._rootItem) item.setStartTimestamp(ts == currentTs and -1 or ts) item.setEndTimestamp(endTs) item.title = itemName item.canFetchMore = True if ts == currentTs: self._todayItem = item ts = endTs - 1
def setEditorData(self, editor, index): val = index.data(Qt.EditRole) if is_date_undefined(val): val = QDate(2000, 1, 1) if isinstance(val, QDateTime): val = val.date() editor.setDate(val)
def pd_timestamp_to_q_datetime(pd_timestamp: datetime): if pd_timestamp is None or pd.isna(pd_timestamp): return QDateTime() return QDateTime( QDate(pd_timestamp.year, pd_timestamp.month, pd_timestamp.day), QTime(pd_timestamp.hour, pd_timestamp.minute, pd_timestamp.second, pd_timestamp.microsecond / 1000))
def _init_date(self): # 日期设置 current = QDate.currentDate() self.dateEdit.setDate(QDate(current.year(), current.month(), 1)) self.dateEdit.setDisplayFormat("yyyy-MM-dd") self.dateEdit_2.setDate(current) self.dateEdit_2.setDisplayFormat("yyyy-MM-dd") settings.setValue(Configs.start_time, self.dateEdit.text()) settings.setValue(Configs.end_time, self.dateEdit_2.text())
def setEditorData(self, editor, index): val = index.data(Qt.EditRole) if check_key_modifier(Qt.ControlModifier): val = UNDEFINED_QDATETIME elif check_key_modifier(Qt.ShiftModifier + Qt.ControlModifier): val = now() elif is_date_undefined(val): val = QDate(2000, 1, 1) if isinstance(val, QDateTime): val = val.date() editor.setDate(val)
def __init__(self,user_id): super(act_modify_panel,self).__init__() self.setupUi(self) self.user_id=user_id sql='select * from activity where acId=%s' self.data=LinkMysql().select_sql(sql,user_id) print(self.data) self.time.setDate(QDate(self.data[0][2])) self.title_ln.setText(self.data[0][1]) self.con_ln.setText(self.data[0][3])
def __init__(self, user_id): super(check_modify_panel, self).__init__() self.setupUi(self) self.user_id = user_id sql = 'select * from checking_in where staId=%s' self.data = LinkMysql().select_sql(sql, user_id) self.ch_id.setText(str(self.data[0][0])) self.ch_name.setText(self.data[0][1]) self.ch_dep.setText(self.data[0][2]) self.ch_work.setText(self.data[0][3]) self.ch_date.setDate(QDate(self.data[0][4]))
def _dialogAccepted(self): QApplication.setOverrideCursor(Qt.WaitCursor) if self._ui.history.isChecked(): start = QDateTime.currentMSecsSinceEpoch() end = 0 # QDate today = QDate.currentDate() week = today.addDays(1 - today.dayOfWeek()) month = QDate(today.year(), today.month(), 1) index = self._ui.historyLength.currentIndex() if index == 0: # Later Today end = QDateTime(today).toMSecsSinceEpoch() elif index == 1: # Week end = QDateTime(week).toMSecsSinceEpoch() elif index == 2: # Month end = QDateTime(month).toMSecsSinceEpoch() elif index == 3: # All end = 0 if end == 0: gVar.app.history().clearHistory() else: indexes = gVar.app.history().indexesFromTimeRange(start, end) gVar.app.history().deleteHistoryEntry(indexes) if self._ui.cookies.isChecked(): gVar.app.cookieJar().deleteAllCookies() if self._ui.cache.isChecked(): self.clearCache() if self._ui.databases.isChecked(): self.clearWebDatabases() if self._ui.localStorage.isChecked(): self.clearLocalStorage() QApplication.restoreOverrideCursor() self._ui.clear.setEnabled(False) self._ui.clear.setText(_('Done')) QTimer.singleShot(1000, self.close)
def getDate(dateIn): month_string = { "Jan": 1, "Feb": 2, "Mar": 3, "Apr": 4, "May": 5, "Jun": 6, "Jul": 7, "Aug": 8, "Sep": 9, "Oct": 10, "Nov": 11, "Dec": 12 } ano = int(dateIn.split('_')[0]) mes = month_string[dateIn.split('_')[1]] dia = int(dateIn.split('_')[2]) dateQ = QDate(ano, mes, dia) return dateQ
def __show_form(self): if self.__showed: return self.gridLayout.addWidget( QLabel(tr('№ дела (обращения) <em style="color: red">*</em>'))) w = QLineEdit() self.gridLayout.addWidget(w) w.setFocus() self.__wgts['declar_number'] = w self.gridLayout.addWidget( QLabel( tr('Услуга (код или номер, или наименование)<em style="color: red">*</em>' ))) w = QLineEdit() self.gridLayout.addWidget(w) self.__wgts['service'] = w self.gridLayout.addWidget( QLabel( tr('Дата регистрации запроса <em style="color: red">*</em>'))) de = QDateEdit(QDate().currentDate()) de.setCalendarPopup(True) self.gridLayout.addWidget(de) self.__wgts['register_date'] = de self.gridLayout.addWidget( QLabel( tr('Плановый срок предоставления услуги <em style="color: red">*</em>' ))) de = QDateEdit() self.__wgts['register_date'].dateChanged.connect(de.setMinimumDate) de.setCalendarPopup(True) de.setMinimumDate(self.__wgts['register_date'].date()) self.gridLayout.addWidget(de) self.__wgts['end_date'] = de gb = QGroupBox(tr('Место нахождения объекта услуги')) gb_l = QGridLayout() self.__wgts['object_address'] = self.__add_address(gb_l) gb.setLayout(gb_l) self.gridLayout.addWidget(gb, self.gridLayout.rowCount() + 1, 0, 1, 2) doc = {} gb = QGroupBox(tr('Приложенный документ *')) gb_l = QGridLayout() gb_l.addWidget( QLabel(tr('Наименование документа <em style="color: red">*</em>'))) w = QLineEdit() w.setMaxLength(1024) gb_l.addWidget(w, 0, 1, 1, 1) doc['title'] = w gb_l.addWidget( QLabel(tr('Номер документа <em style="color: red">*</em>'))) w = QLineEdit() w.setMaxLength(50) gb_l.addWidget(w) doc['number'] = w gb_l.addWidget( QLabel(tr('Дата документа <em style="color: red">*</em>'))) w = QDateEdit() w.setCalendarPopup(True) gb_l.addWidget(w) doc['date'] = w gb_l.addWidget( QLabel( tr('Прямая ссылка на файл. Поддерживаются только пртоколы ' 'HTTP, FTP <em style="color: red">*</em>'))) w = QLineEdit() gb_l.addWidget(w) doc['url'] = w gb.setLayout(gb_l) self.gridLayout.addWidget(gb, self.gridLayout.rowCount() + 1, 0, 1, 2) self.documents.append(doc) gb = QGroupBox(tr('Заявители *')) self.dec_layout = QGridLayout() self.cb = QComboBox() self.cb.addItems(('Физическое лицо', 'Юридическое лицо/Индивидуальный предприниматель')) self.dec_layout.addWidget(self.cb) b = QPushButton(tr('Добавить')) b.clicked.connect(self.add_declarant) self.dec_layout.addWidget(b, 0, 1, 1, 1) gb.setLayout(self.dec_layout) self.gridLayout.addWidget(gb, self.gridLayout.rowCount() + 1, 0, 1, 2) b = QPushButton(tr('Добавить файл документа')) b.clicked.connect(self.__add_doc_file) self.gridLayout.addWidget(b) self.file_label = QLabel() self.gridLayout.addWidget(self.file_label) self.warn_label = QLabel(tr("Не удаляйте файл до отправки запроса")) self.warn_label.setStyleSheet('color: red') self.warn_label.setVisible(False) self.gridLayout.addWidget(self.warn_label, self.gridLayout.rowCount() + 1, 0, 1, 2) self.__showed = True
def alterTable(self, mtd1, mtd2, key): util = FLUtil() oldMTD = None newMTD = None doc = QDomDocument("doc") docElem = None if not util.docDocumentSetContect(doc, mtd1): print("FLManager::alterTable : " + qApp.tr("Error al cargar los metadatos.")) else: docElem = doc.documentElement() oldMTD = self.db_.manager().metadata(docElem, True) if oldMTD and oldMTD.isQuery(): return True if not util.docDocumentSetContect(doc, mtd2): print("FLManager::alterTable : " + qApp.tr("Error al cargar los metadatos.")) return False else: docElem = doc.documentElement() newMTD = self.db_.manager().metadata(docElem, True) if not oldMTD: oldMTD = newMTD if not oldMTD.name() == newMTD.name(): print("FLManager::alterTable : " + qApp.tr("Los nombres de las tablas nueva y vieja difieren.")) if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False oldPK = oldMTD.primaryKey() newPK = newMTD.primaryKey() if not oldPK == newPK: print("FLManager::alterTable : " + qApp.tr("Los nombres de las claves primarias difieren.")) if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False if not self.db_.manager().checkMetaData(oldMTD, newMTD): if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return True if not self.db_.manager().existsTable(oldMTD.name()): print("FLManager::alterTable : " + qApp.tr( "La tabla %1 antigua de donde importar los registros no existe." ).arg(oldMTD.name())) if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False fieldList = oldMTD.fieldList() oldField = None if not fieldList: print("FLManager::alterTable : " + qApp.tr("Los antiguos metadatos no tienen campos.")) if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False renameOld = "%salteredtable%s" % (oldMTD.name()[0:5], QDateTime( ).currentDateTime().toString("ddhhssz")) if not self.db_.dbAux(): if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False self.db_.dbAux().transaction() if key and len(key) == 40: c = FLSqlCursor("flfiles", True, self.db_.dbAux()) c.setForwardOnly(True) c.setFilter("nombre = '%s.mtd'" % renameOld) c.select() if not c.next(): buffer = c.primeInsert() buffer.setValue("nombre", "%s.mtd" % renameOld) buffer.setValue("contenido", mtd1) buffer.setValue("sha", key) c.insert() q = FLSqlQuery("", self.db_.dbAux()) if not q.exec_("CREATE TABLE %s AS SELECT * FROM %s;" % (renameOld, oldMTD.name())) or not q.exec_( "DROP TABLE %s;" % oldMTD.name()): print("FLManager::alterTable : " + qApp.tr("No se ha podido renombrar la tabla antigua.")) self.db_.dbAux().rollback() if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False if not self.db_.manager().createTable(newMTD): self.db_.dbAux().rollback() if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False oldCursor = FLSqlCursor(renameOld, True, self.db_.dbAux()) oldCursor.setModeAccess(oldCursor.Browse) newCursor = FLSqlCursor(newMTD.name(), True, self.db_.dbAux()) newCursor.setMode(newCursor.Insert) oldCursor.select() totalSteps = oldCursor.size() progress = QProgressDialog( qApp.tr("Reestructurando registros para %1...").arg( newMTD.alias()), qApp.tr("Cancelar"), 0, totalSteps) progress.setLabelText(qApp.tr("Tabla modificada")) step = 0 newBuffer = None # sequence = "" fieldList = newMTD.fieldList() newField = None if not fieldList: print("FLManager::alterTable : " + qApp.tr("Los nuevos metadatos no tienen campos.")) self.db_.dbAux().rollback() if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD return False v = None ok = True while oldCursor.next(): v = None newBuffer = newCursor.primeInsert() for it in fieldList: oldField = oldMTD.field(newField.name()) if not oldField or not oldCursor.field(oldField.name()): if not oldField: oldField = newField v = newField.defaultValue() else: v = oldCursor.value(newField.name()) if (not oldField.allowNull() or not newField.allowNull()) and (v is None): defVal = newField.defaultValue() if defVal is not None: v = defVal if not newBuffer.field( newField.name()).type() == newField.type(): print("FLManager::alterTable : " + qApp.tr( "Los tipos del campo %1 no son compatibles. Se introducirá un valor nulo." ).arg(newField.name())) if not oldField.allowNull( ) or not newField.allowNull() and v is not None: if oldField.type() in ("int", "serial", "uint", "bool", "unlock"): v = 0 elif oldField.type() == "double": v = 0.0 elif oldField.type() == "time": v = QTime().currentTime() elif oldField.type() == "date": v = QDate().currentDate() else: v = "NULL"[0:newField.length()] newBuffer.setValue(newField.name(), v) if not newCursor.insert(): ok = False break step = step + 1 progress.setProgress(step) progress.setProgress(totalSteps) if oldMTD and not oldMTD == newMTD: del oldMTD if newMTD: del newMTD if ok: self.db_.dbAux().commit() else: self.db_.dbAux().rollback() return False return True
def get_date(self): date_now = list( map(int, str(datetime.datetime.now()).split()[0].split('-'))) self.date.setDate(QDate(*date_now))