def testQTimeValid(self): '''QDataStream <<>> QTime - valid''' self.stream << QTime(12, 12, 21) res = QTime() self.read_stream >> res self.assertEqual(res, QTime(12, 12, 21)) self.assertTrue(res.isValid()) self.assertFalse(res.isNull())
def setTodoStartTime(self, hour, minute): orig_date = self._todo.startDateTime().date() time = QTime(hour, minute) datetime = QDateTime(orig_date, time) self._todo.setStartDateTime(datetime) self.currentTodoChanged.emit()
def _update_time(self): # this gets called every seconds # adjust the remaining time self.countdown = self.countdown.addSecs(-1) # if the remaining time reached zero, stop the timer if self.countdown <= QTime(0, 0, 0): self.timer.stop() # update the display self.setText(self.countdown.toString(Qt.ISODate))
def testQTime(self): time = datetime.time(11, 14, 0, 1000) other = QTime(time) self.assertEqual(time.hour, other.hour()) self.assertEqual(time.minute, other.minute()) self.assertEqual(time.second, other.second()) self.assertEqual(time.microsecond / 1000, other.msec()) self.assertEqual(time, other.toPython())
def __init__(self, playersOut, playersIn, parent=None): super(confirmSubsDialog, self).__init__(parent) self.now = QDateTime.currentDateTime() self.now.setTime( QTime(self.now.time().hour(), self.now.time().minute())) self.setWindowTitle("Confirm Subs") mainVerticalLayout = QVBoxLayout(self) subsLayout = QGridLayout() mainVerticalLayout.addLayout(subsLayout) subsLayout.addWidget(QLabel("<b>Players Out</b>"), 0, 0) subsLayout.addWidget(QLabel("<b>Players In</b>"), 0, 1) for i, (playerOut, playerIn) in enumerate(zip(playersOut, playersIn)): playerOutLabel = QLabel() playerOutLabel.setText("<font color=red>{0}</font>".format( playerOut.name)) subsLayout.addWidget(playerOutLabel, i + 1, 0) playerInLabel = QLabel() playerInLabel.setText("<font color=green>{0}</font>".format( playerIn.name)) subsLayout.addWidget(playerInLabel, i + 1, 1) mainVerticalLayout.addItem( QSpacerItem(0, 15, QSizePolicy.Minimum, QSizePolicy.Expanding)) dateTimeLayout = QHBoxLayout() mainVerticalLayout.addLayout(dateTimeLayout) dateTimeLayout.addWidget(QLabel("Date and time")) self.dateTimeEdit = QDateTimeEdit(self.now) self.dateTimeEdit.setMaximumDateTime(self.now) self.dateTimeEdit.setCalendarPopup(True) self.dateTimeEdit.setDisplayFormat("d MMM yy h:mm AP") dateTimeLayout.addWidget(self.dateTimeEdit) dateTimeLayout.addStretch() mainVerticalLayout.addItem( QSpacerItem(0, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)) buttonBox = QDialogButtonBox(self) buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) buttonBox.button(QDialogButtonBox.Ok).setText("&Accept") mainVerticalLayout.addWidget(buttonBox) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject)
def testQDateTimeValid(self): '''QDataStream <<>> QDateTime - valid''' time = QTime(23, 23, 23) date = QDate(2009, 1, 1) self.stream << QDateTime(date, time) res = QDateTime() self.read_stream >> res self.assertEqual(res, QDateTime(date, time)) self.assertTrue(res.isValid()) self.assertFalse(res.isNull())
def testDateConversion(self): dateTime = QDateTime(QDate(2011, 5, 17), QTime(11, 1, 14, 15)) dateTimePy = QDateTime(datetime.date(2011, 5, 17), datetime.time(11, 1, 14, 15000)) self.assertEqual(dateTime, dateTimePy)
def main(): app = QApplication(sys.argv) widget = CountdownWidget(QTime(0, 0, 5)) widget.start() widget.show() app.exec_()
def run(self): t = QTime() t.start() time.sleep(2) # Sleep 2 seconds
def setUp(self): self.original = QTime(11, 37, 55, 692)
if __name__ == '__main__': app = QApplication(sys.argv) due = QTime.currentTime() message = "Alert! " try: if len(sys.argv) < 2: raise ValueError("Not enough arguments") hours, minutes = sys.argv[1].split(":") #python SimpleApp.py 09:32 <optional message> due = QTime(int(hours), int(minutes)) if not due.isValid(): raise ValueError("Input time is not Valid") if len(sys.argv) > 2: message += " ".join(sys.argv[2:]) except ValueError as e: print e.args print "Usage: python SimpleApp.py HH:MM [message]" sys.exit(0) while QTime.currentTime() < due: time.sleep(5) label = QLabel("<font color=red size=36 >" + message + "</font>")
def tickStrings(self, values, scale, spacing): # PySide's QTime() initialiser fails miserably and dismisses args/kwargs return [QTime().addMSecs(value).toString('mm:ss') for value in values]
from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg from PySide.QtCore import QTime, QTimer from collections import deque t = QTime() t.start() data = deque(maxlen=20) class TimeAxisItem(pg.AxisItem): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def tickStrings(self, values, scale, spacing): # PySide's QTime() initialiser fails miserably and dismisses args/kwargs return [QTime().addMSecs(value).toString('mm:ss') for value in values] app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="Basic plotting examples") win.resize(1000, 600) plot = win.addPlot(title='Timed data', axisItems={'bottom': TimeAxisItem(orientation='bottom')}) curve = plot.plot() def update():
def __init__(self, groups): super(addBlockDialog, self).__init__() self.groups = groups # Status self.errorstatus = QLabel() # Layouts self.topLayout = QVBoxLayout() self.mainLayout = QGridLayout() self.timeLayout = QHBoxLayout() self.buttons = QHBoxLayout() # Main Elements self.statusLabel = QLabel(languagedict['addBlockStatus']) self.status = QComboBox() for status in groups: self.status.addItem(status.getName()) self.status.activated.connect(self.updatetasks) self.tasksLabel = QLabel(languagedict['addBlockTask']) self.tasks = QComboBox() self.weekdayLabel = QLabel(languagedict['addBlockWeekday']) self.weekday = QComboBox() for weekday in languagedict['mainTableHeaders']: self.weekday.addItem(weekday) self.timeLabel = QLabel(languagedict['addBlockTime']) self.start = QTimeEdit(QTime(6, 0)) self.start.setDisplayFormat('hh:mm') self.end = QTimeEdit(QTime(7, 0)) self.end.setDisplayFormat('hh:mm') # Buttons self.ok = QPushButton(languagedict['OKButton']) self.ok.clicked.connect(self.check) self.cancel = QPushButton(languagedict['CancelButton']) self.cancel.clicked.connect(self.reject) # Laying out # Time self.timeLayout.addWidget(self.start) self.timeLayout.addWidget(self.end) # Central self.mainLayout.addWidget(self.statusLabel, 0, 0) self.mainLayout.addWidget(self.status, 1, 0) self.mainLayout.addWidget(self.tasksLabel, 0, 1) self.mainLayout.addWidget(self.tasks, 1, 1) self.mainLayout.addWidget(self.weekdayLabel, 2, 0) self.mainLayout.addWidget(self.weekday, 3, 0) self.mainLayout.addWidget(self.timeLabel, 2, 1) self.mainLayout.addLayout(self.timeLayout, 3, 1) # Buttons self.buttons.addWidget(self.ok) self.buttons.addWidget(self.cancel) # Top level self.topLayout.addWidget(self.errorstatus) self.topLayout.addLayout(self.mainLayout) self.topLayout.addLayout(self.buttons) # Main settings self.setLayout(self.topLayout) self.setWindowTitle(languagedict['addBlockTitle'])