def mouseReleaseEvent(self, event): if event.button() == Qt.LeftButton: if self.panActive: self.panActive = False if not ENABLE_KINETIC_PANNING or self.lastMoveTime.msecsTo( QTime.currentTime()) > HOLD_TIME_THRESHOLD: return self.kineticPanSpeed = QPointF() entriesConsidered = 0 currentTime = QTime.currentTime() for entry in self.mouseHistory: if not entry.time: continue if entry.time.msecsTo(currentTime) < HOLD_TIME_THRESHOLD: self.kineticPanSpeed += entry.position entriesConsidered += 1 if entriesConsidered > 0: self.kineticPanSpeed /= entriesConsidered self.lastMoveTime = currentTime self.kineticTimer.start() self.panDecellerate = True event.accept()
def mouseReleaseEvent(self, event): if event.button() == Qt.LeftButton: if self.panActive: self.panActive = False if not ENABLE_KINETIC_PANNING or self.lastMoveTime.msecsTo(QTime.currentTime()) > HOLD_TIME_THRESHOLD: return self.kineticPanSpeed = QPointF() entriesConsidered = 0 currentTime = QTime.currentTime() for entry in self.mouseHistory: if not entry.time: continue if entry.time.msecsTo(currentTime) < HOLD_TIME_THRESHOLD: self.kineticPanSpeed += entry.position entriesConsidered += 1 if entriesConsidered > 0: self.kineticPanSpeed /= entriesConsidered self.lastMoveTime = currentTime self.kineticTimer.start() self.panDecellerate = True event.accept()
def TurnGenerator(self, startPosition): """ Takes PointerPosition on explicit call to send(). Generates turn positions between lines that lie on a axis (vertical or horizontal). Qt doesn't have event.time . Fabricate it here. X11 has event.time. """ position = None # if events are: send(None), close(), need this defined previousPosition = startPosition positionClock = QTime.currentTime() # note restart returns elapsed positionClock.restart() # I also tried countPositionsSinceTurn to solve lag for cusp-like # print "init turn" try: while True: position = (yield) positionElapsedTime = positionClock.restart() turn = self.detectTurn(previousPosition, position) if turn is not None: self.lineGenerator.send((turn, positionElapsedTime)) previousPosition = position # Roll forward else: # path is still on an axis: wait pass finally: # assert position is defined if previousPosition != position: """ Have position not sent. Fabricate a turn (equal to position) and send() """ self.lineGenerator.send((position, 0)) print "Closing turn generator"
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 show_time(self): ''' clock :return: ''' time = QTime.currentTime() text = time.toString('hh:mm:ss') self.time_lcd.display(text)
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 editNewTodo(self): """Sets the current todo to a newly created todo""" newTodo = QOrganizerTodo() newTodo.setPriority(QOrganizerItemPriority.HighPriority) newTodo.setStatus(QOrganizerTodoProgress.StatusNotStarted) currentDateTime = QDateTime(QDate.currentDate(), QTime.currentTime()) newTodo.setStartDateTime(currentDateTime) newTodo.setDueDateTime(currentDateTime.addSecs(60 * 60)) self._todo = newTodo self._todo.isNewTodo = True self.currentTodoChanged.emit()
def editNewTodo(self): """Sets the current todo to a newly created todo""" newTodo = QOrganizerTodo() newTodo.setPriority(QOrganizerItemPriority.HighPriority) newTodo.setStatus(QOrganizerTodoProgress.StatusNotStarted) currentDateTime = QDateTime(QDate.currentDate(), QTime.currentTime()) newTodo.setStartDateTime(currentDateTime) newTodo.setDueDateTime(currentDateTime.addSecs(60*60)) self._todo = newTodo self._todo.isNewTodo = True self.currentTodoChanged.emit()
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 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 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 kineticTimerEvent(self): currentTime = QTime.currentTime() deltaTime = self.lastMoveTime.msecsTo(currentTime) self.lastMoveTime = currentTime if self.panDecellerate: self.kineticPanSpeed *= pow(0.5, float(deltaTime / KINETIC_PANNING_HALFLIFE)) scaledSpeed = self.kineticPanSpeed * deltaTime if self.kineticPanSpeed.manhattanLength() < KINETIC_PAN_SPEED_THRESHOLD: self.kineticTimer.stop() return self.panFloatWrapper(scaledSpeed)
def mousePressEvent(self, event): self.setFocus() if event.button() == Qt.LeftButton: if event.modifiers() & Qt.ControlModifier: pass else: if self.coordQueryState: self.coordQueryResult.emit(self.screenPositionToCoordinate(event.lastPos())) return self.panActive = True self.kineticTimer.stop() self.kineticPanSpeed = QPointF() self.lastMoveTime = QTime.currentTime() event.accept()
def testInsert(self): myHash = {} qdate = QDate.currentDate() qdatetime = QDateTime.currentDateTime() qtime = QTime.currentTime() qurl = QUrl("http://www.pyside.org") qpoint = QPoint(12, 42) myHash[qdate] = "QDate" myHash[qdatetime] = "QDateTime" myHash[qtime] = "QTime" myHash[qurl] = "QUrl" myHash[qpoint] = "QPoint" self.assertEqual(myHash[qdate], "QDate") self.assertEqual(myHash[qdatetime], "QDateTime") self.assertEqual(myHash[qtime], "QTime") self.assertEqual(myHash[qurl], "QUrl") self.assertEqual(myHash[qpoint], "QPoint")
def mouseMoveEvent(self, event): if event.modifiers() & Qt.ControlModifier: if self.lastCircle: self.lastCircle.setCenter(self.screenPositionToCoordinate(event.pos())) elif self.panActive: currentTime = QTime.currentTime() deltaTime = self.lastMoveTime.msecsTo(currentTime) delta = event.lastPos() - event.pos() if deltaTime > 0: self.kineticPanSpeed = delta / deltaTime self.mouseHistory.popleft() self.mouseHistory.append(MouseHistoryEntry(self.kineticPanSpeed, currentTime)) self.panFloatWrapper(delta) event.accept()
def updateClock(self): self.setText(QTime.currentTime().toString("hh:mm"))
def run(self): t = QTime() t.start() time.sleep(2) # Sleep 2 seconds
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'])
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():
# Only Example: import, it's not recommended but for the simple app it's okay from PySide.QtCore import QTime, QTimer, Qt from PySide.QtGui import QApplication, QLabel import sys import time app = QApplication(sys.argv) # Hold the current time for the alarm clock due = QTime.currentTime() # Static message for Alert box message = 'Alert!' try: message = 'Alert!' # The application requires always an argument if len(sys.argv) < 2: sys.argv.append('%02d:%02d' % (due.hour(), due.minute())) elif len(sys.argv) > 2: message = ' '.join(sys.argv[2:]) # class PySide.QtCore.QTime(h, m[, s=0[, ms=0]]) hours, minutes = sys.argv[1].split(':') due = QTime(int(hours), int(minutes))
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]
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_()
from PySide.QtCore import QTime, QTimer, Qt from PySide.QtGui import QApplication, QLabel import sys import time def quitApplication(app): return app.quit 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:])
def setUp(self): self.original = QTime(11, 37, 55, 692)