def __init__(self, parent=None): QLCDNumber.__init__(self) self.parent = parent self.signals = SignalManager(self) self.settings = Settings(SETTING_FILEPTH['app'], ST_FORMAT['ini'], self) self.time = QTime() self.zone = QTimeZone() self.date = QDate() self.values = dict(w=self.width(), h=self.height(), x=self.x(), y=self.y())
def setWidgetDateTime(self, index): tz = str(self.ui.countryList.itemData(index)) currentDateTime = QDateTime.currentDateTimeUtc().toTimeZone( QTimeZone(tz)) self.ui.calendarWidget.setDate(currentDateTime.date()) self.ui.timeEdit.setDateTime(currentDateTime)
def setupUi(self,mainWindow): super().setupUi(mainWindow) self.refresh.clicked.connect(ui.refreshAll) self.actionQuit.triggered.connect(ui.quit) #self.actionRuns.triggered.connect(ui.runs) self.runsTable.clicked.connect(ui.selectRun) self.plateTable.clicked.connect(ui.selectPlate) self.sampleTable.clicked.connect(ui.selectSample) self.dbopen() self.refreshAll() print("timezone=",QTimeZone.systemTimeZone().comment())
def __init__(self, config): super().__init__() self.ui = design.Ui_MainWindow() self.ui.setupUi(self) self.setWindowTitle( "SportiduinoPQ {}".format(sportiduinopq_version_string)) self.config = config geometry = self.config.value('geometry') if geometry is not None: self.restoreGeometry(geometry) self.connected = False self.printer = QPrinter() printer_name = config.value('printer/name', self.printer.printerName()) self.printer.setPrinterName(printer_name) outputfilename = config.value('printer/outputfilename', self.printer.outputFileName()) self.printer.setOutputFileName(outputfilename) self.ui.printerName.setText(self.printer.printerName()) init_time = datetime.now() self.cards_data_filename = os.path.join( 'data', 'cards{:%Y%m%d}.csv'.format(init_time)) if not os.path.exists(self.cards_data_filename): with open(self.cards_data_filename, 'w') as cards_data_file: cards_data_file.write( 'No.;Read at;Card no.;;;;;;;;;;;;;;;;Clear time;;;Check time;;;Start time;;;Finish time;No. of punches;;1.CP;;1.Time;2.CP;;2.Time;3.CP;;3.Time\n' ) self.cards_data = [] self._logger = self.Logger() self.log('{:%Y-%m-%d %H:%M:%S}'.format(init_time)) self.timer = QTimer(self) self.timer.timeout.connect(self.poll_card) availablePorts = [] if platform.system() == 'Linux': availablePorts = [ os.path.join('/dev', f) for f in os.listdir('/dev') if re.match('ttyUSB.+', f) ] availablePorts.sort() elif platform.system() == 'Windows': availablePorts = ['COM' + str(i) for i in range(32)] self.ui.choiseCom.addItems(availablePorts) self.ui.cbUartPort.addItems(availablePorts) self.ui.Connect.clicked.connect(self.Connect_clicked) self.ui.ReadCard.clicked.connect(self.ReadCard_clicked) self.ui.InitCard.clicked.connect(self.InitCard_clicked) self.ui.SetTime.clicked.connect(self.SetTime_clicked) self.ui.SetNum.clicked.connect(self.SetNum_clicked) self.ui.SetStart.clicked.connect(self.SetStart_clicked) self.ui.SetFinish.clicked.connect(self.SetFinish_clicked) self.ui.CheckSt.clicked.connect(self.CheckSt_clicked) self.ui.ClearSt.clicked.connect(self.ClearSt_clicked) self.ui.LogCard.clicked.connect(self.LogCard_clicked) self.ui.ReadLog.clicked.connect(self.ReadLog_clicked) self.ui.SleepCard.clicked.connect(self.SleepCard_clicked) self.ui.PassCard.clicked.connect(self.PassCard_clicked) self.ui.SelectPrinter.clicked.connect(self.SelectPrinter_clicked) self.ui.Print.clicked.connect(self.Print_clicked) self.ui.btnApplyPwd.clicked.connect(self.ApplyPwd_clicked) self.ui.btnCreateInfoCard.clicked.connect(self.CreateInfo_clicked) self.ui.btnReadInfo.clicked.connect(self.ReadInfo_clicked) self.ui.btnUartRead.clicked.connect(self.SerialRead_clicked) self.ui.btnUartWrite.clicked.connect(self.SerialWrite_clicked) self.ui.btnClearText.clicked.connect(self.ClearText_clicked) self.ui.btnMsConfigRead.clicked.connect(self.btnMsConfigRead_clicked) self.ui.btnMsConfigWrite.clicked.connect(self.write_ms_config) self.ui.AutoRead.stateChanged.connect(self.autoread_change) bs_config = BaseStation.Config() for key, default_value in vars(bs_config).items(): value_type = type(default_value) if isinstance(default_value, list): value_type = type(default_value[0]) setattr( bs_config, key, self.config.value('settings/' + key, default_value, type=value_type)) self._apply_settings(bs_config, datetime.now()) self.ui.sbCurPwd1.setValue(bs_config.password[0]) self.ui.sbCurPwd2.setValue(bs_config.password[1]) self.ui.sbCurPwd3.setValue(bs_config.password[2]) ianaIds = QTimeZone.availableTimeZoneIds() all_timezones = sorted( {QTimeZone(id).offsetFromUtc(datetime.now()) for id in ianaIds}) tzlocaloffset = time.localtime().tm_gmtoff tzlocalname = None for dt in all_timezones: tz = timezone(timedelta(seconds=dt)) tzname = tz.tzname(None) if dt == tzlocaloffset: tzlocalname = tzname self.ui.cbTimeZone.addItem(tzname, dt) if tzlocalname is not None: self.ui.cbTimeZone.setCurrentText(tzlocalname) else: self.ui.cbTimeZone.setCurrentText( timezone(offset=timedelta(0)).tzname(None))
utc_to_local(filter_['end_datetime']). strftime('%Y-%m-%d %H:%M:%S')) return text @pyqtSlot() def on_changeFilter_clicked(self): pass filterDialog = LogFilterDialog() filterDialog.initControls(self._filter) if filterDialog.exec_() == QDialog.Accepted: self.setFilter(filterDialog.filter()) TZ = QTimeZone('Europe/Prague') class LogFilterDialog(QDialog): OPERATION_OPTIONS = ['', 'insert', 'delete'] TABLENAME_OPTIONS = ['', 'blocks', 'devices', 'measurements',\ 'raw_data_view'] def __init__(self, parent=None): super(LogFilterDialog, self).__init__(parent) self.accepted.connect(self.createFilter) self.operationCombo = QComboBox() self.operationCombo.addItems(LogFilterDialog.OPERATION_OPTIONS) self.tablenameCombo = QComboBox() self.tablenameCombo.addItems(LogFilterDialog.TABLENAME_OPTIONS)
def __init__(self, app): QMainWindow.__init__(self, None) self.l.debug('Initializing MainWindow ...') self.theSun = SunSimulator() self.timeZones = [] for x in QTimeZone.availableTimeZoneIds(): tz = QTimeZone(x) self.timeZones.append(tz) #print(" {} {} {}".format(str(tz.id()), tz.comment(), tz.hasDaylightTime())) #self.revLookup = {} #idx = 0 #for d in self.timeZones: # self.revLookup[d[1]] = idx # idx += 1 self.setWindowTitle('Shadow') # app.setWindowIcon(QIcon(':/icons/mynpad.png')) # # if os.name == 'nt': # # On Windows, make sure to use a unique Application User Model Id, otherwise # # Windows shows the default python icon in the taskbar # # see http://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7 # myappid = 'afester.mynpad' # import ctypes; ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) self.theApplication = app app.aboutToQuit.connect(self.saveState) # read the local configuration file iniPath = 'shadow.ini' if not os.path.exists(iniPath): iniPath = os.path.join(expanduser("~"), iniPath) self.settings = Settings(iniPath) self.settings.load() # Set up the menu bar menuBar = QMenuBar(self) exitAction = QAction("Exit", self, triggered=self.theApplication.exit) fileMenu = menuBar.addMenu("&File") fileMenu.addAction(exitAction) aboutAction = QAction("About ...", self, triggered=self.handleAbout) helpMenu = menuBar.addMenu("&Help") helpMenu.addAction(aboutAction) self.setMenuBar(menuBar) self.centralWidget = QWidget() self.left = DataWidget(self.centralWidget) self.right = ShadowWidget(self.centralWidget) # Create time zone selector self.left.ui.timeZoneComboBox.clear() for tz in self.timeZones: # TODO: Hack (?) displayId = tz.id().data().decode(encoding="UTF-8") if not displayId.startswith('UTC'): utcOffset = tz.displayName(QTimeZone.GenericTime, QTimeZone.OffsetName) #self.left.ui.timeZoneComboBox.addItem("({}) {} - {}".format(utcOffset, displayId, tz.comment())) self.left.ui.timeZoneComboBox.addItem("({}) {}".format( utcOffset, displayId)) self.left.ui.timeZoneComboBox.setCurrentIndex( self.settings.getTzIndex()) self.left.ui.timeZoneComboBox.currentIndexChanged.connect( self.setTimeZone) self.left.ui.dateEdit.dateChanged.connect(self.updateDate) self.left.ui.timeEdit.timeChanged.connect(self.updateTime) self.left.ui.timeSlider.valueChanged.connect(self.slideTime) layout = QHBoxLayout() self.centralWidget.setLayout(layout) layout.addWidget(self.left) layout.addWidget(self.right) layout.setStretch(0, 0) layout.setStretch(1, 1) self.setCentralWidget(self.centralWidget) # Reset main window size and position pos = self.settings.getMainWindowPos() self.move(pos.x(), pos.y()) size = self.settings.getMainWindowSize() self.resize(size) # sample values self.left.ui.treeHeightLineEdit.setValue(10) self.left.ui.latitudeLineEdit.setValue(48.1) self.left.ui.LongitudeLineEdit.setValue(11.6) self.left.ui.dateEdit.setDate(QDate(2015, 9, 11)) self.left.ui.timeEdit.setTime(QTime(8, 0))
def __init__(self, app): QMainWindow.__init__(self, None) self.l.debug('Initializing MainWindow ...') self.theSun = SunSimulator() self.timeZones = [] for x in QTimeZone.availableTimeZoneIds(): tz = QTimeZone(x) self.timeZones.append(tz) #print(" {} {} {}".format(str(tz.id()), tz.comment(), tz.hasDaylightTime())) #self.revLookup = {} #idx = 0 #for d in self.timeZones: # self.revLookup[d[1]] = idx # idx += 1 self.setWindowTitle('Shadow') # app.setWindowIcon(QIcon(':/icons/mynpad.png')) # # if os.name == 'nt': # # On Windows, make sure to use a unique Application User Model Id, otherwise # # Windows shows the default python icon in the taskbar # # see http://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7 # myappid = 'afester.mynpad' # import ctypes; ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) self.theApplication = app app.aboutToQuit.connect(self.saveState) # read the local configuration file iniPath = 'shadow.ini' if not os.path.exists(iniPath): iniPath = os.path.join(expanduser("~"), iniPath) self.settings = Settings(iniPath) self.settings.load() # Set up the menu bar menuBar = QMenuBar(self) exitAction = QAction("Exit", self, triggered=self.theApplication.exit) fileMenu = menuBar.addMenu("&File") fileMenu.addAction(exitAction) aboutAction = QAction("About ...", self, triggered = self.handleAbout) helpMenu = menuBar.addMenu("&Help") helpMenu.addAction(aboutAction) self.setMenuBar(menuBar) self.centralWidget = QWidget() self.left = DataWidget(self.centralWidget) self.right = ShadowWidget(self.centralWidget) # Create time zone selector self.left.ui.timeZoneComboBox.clear() for tz in self.timeZones: # TODO: Hack (?) displayId = tz.id().data().decode(encoding="UTF-8") if not displayId.startswith('UTC'): utcOffset = tz.displayName(QTimeZone.GenericTime, QTimeZone.OffsetName) #self.left.ui.timeZoneComboBox.addItem("({}) {} - {}".format(utcOffset, displayId, tz.comment())) self.left.ui.timeZoneComboBox.addItem("({}) {}".format(utcOffset, displayId)) self.left.ui.timeZoneComboBox.setCurrentIndex(self.settings.getTzIndex()) self.left.ui.timeZoneComboBox.currentIndexChanged.connect(self.setTimeZone) self.left.ui.dateEdit.dateChanged.connect(self.updateDate) self.left.ui.timeEdit.timeChanged.connect(self.updateTime) self.left.ui.timeSlider.valueChanged.connect(self.slideTime) layout = QHBoxLayout() self.centralWidget.setLayout(layout) layout.addWidget(self.left) layout.addWidget(self.right) layout.setStretch(0, 0); layout.setStretch(1, 1); self.setCentralWidget(self.centralWidget) # Reset main window size and position pos = self.settings.getMainWindowPos() self.move(pos.x(), pos.y()) size = self.settings.getMainWindowSize() self.resize(size) # sample values self.left.ui.treeHeightLineEdit.setValue(10) self.left.ui.latitudeLineEdit.setValue(48.1) self.left.ui.LongitudeLineEdit.setValue(11.6) self.left.ui.dateEdit.setDate(QDate(2015, 9, 11)) self.left.ui.timeEdit.setTime(QTime(8, 0))
class LCDNumber(QLCDNumber): Type = 'DAMGUI' key = 'LCDNumber' _name = 'DAMG LCD Number' _copyright = __copyright__ def __init__(self, parent=None): QLCDNumber.__init__(self) self.parent = parent self.signals = SignalManager(self) self.settings = Settings(SETTING_FILEPTH['app'], ST_FORMAT['ini'], self) self.time = QTime() self.zone = QTimeZone() self.date = QDate() self.values = dict(w=self.width(), h=self.height(), x=self.x(), y=self.y()) def sizeHint(self): size = super(LCDNumber, self).sizeHint() size.setHeight(size.height()) size.setWidth(max(size.width(), size.height())) return size def setValue(self, key, value): return self.settings.initSetValue(key, value, self.key) def getValue(self, key): return self.settings.initValue(key, self.key) def moveEvent(self, event): if self.settings._settingEnable: self.setValue('x', self.x()) self.setValue('y', self.y()) def resizeEvent(self, event): if self.settings._settingEnable: self.setValue('w', self.width()) self.setValue('h', self.height()) def closeEvent(self, event): if __name__ == '__main__': self.close() else: self.signals.emit('showLayout', self.key, 'hide') def hideEvent(self, event): if __name__ == '__main__': self.hide() else: if self.settings._settingEnable: for key, value in self.values.items(): self.setValue(key, value) self.signals.emit('showLayout', self.key, 'hide') def showEvent(self, event): if self.settings._settingEnable: w = self.getValue('w') h = self.getValue('h') x = self.getValue('x') y = self.getValue('x') vals = [w, h, x, y] for i in range(len(vals)): if vals[i] is None: key = [k for k in self.values.keys()] value = self.values[key[i]] for index, element in enumerate(vals): if element == vals[i]: vals[index] = value self.setValue(key[i], self.values[key[i]]) for v in vals: if not type(v) in [int]: v = int(v) self.resize(vals[0], vals[1]) self.move(vals[2], vals[3]) if __name__ == '__main__': self.show() else: self.signals.emit('showLayout', self.key, 'show') @property def copyright(self): return self._copyright @property def name(self): return self._name @name.setter def name(self, newName): self._name = newName def currentTime(self): return self.time.currentTime() def currentTimeZone(self): return self.zone.utc() def currentDate(self): return self.date.currentDate()