예제 #1
0
def QTimeToMsecs(time: QTime):
    msecs = 0
    msecs += time.msec()
    msecs += time.second() * 1000
    msecs += time.minute() * 1000 * 60
    msecs += time.hour() * 1000 * 60 * 60
    return msecs
예제 #2
0
    def update_list(self):
        que = self.w1.update()
        rows = self.cur.execute(que).fetchmany(self.count_rows_spin.value())
        self.list_order.clear()
        self.list_order_2.clear()
        for i in rows:
            dish_time_s = self.cur.execute(f'''select cooktime from dish 
                                                    where id = (select dishid from orderdish
                                                    where id = ({i[0]}))''').fetchone()[0]
            date_time_s = self.cur.execute(f'''select datetime from orderclient
                                              where id = {i[1]}''').fetchone()[0]
            dish_count = int(i[4])
            date_time = QDateTime.fromString(date_time_s, date_time_format())
            dish_time = QTime.fromString(dish_time_s, time_format())
            dish_time_minutes = dish_time.hour() * 60 + dish_time.minute() * dish_count
            dish_time = QTime(dish_time_minutes // 60, dish_time_minutes % 60)

            secs_passed = date_time.secsTo(QDateTime.currentDateTime())
            hms = [dish_time.hour() - secs_passed // 3600,
                   dish_time.minute() - secs_passed // 60 % 60,
                   59 - secs_passed % 60]
            time_last = QTime(*hms)
            if time_last.isValid():
                order = [time_last.toString(time_format() + ':ss'), *i[2:]]
            else:
                order = ['Done', *i[2:]]
            item = QListWidgetItem(' - '.join(map(str, order)))
            if not time_last.isValid():
                item.setBackground(QColor(255, 220, 220))
                self.list_order_2.addItem(item)
            else:
                self.list_order.addItem(item)
예제 #3
0
파일: timer.py 프로젝트: char101/timer
class Timer(QLCDNumber):
    textChanged = pyqtSignal(str)
    started = pyqtSignal()
    stopped = pyqtSignal()
    reset_ = pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)
        self.timer = QTimer()
        self.timer.timeout.connect(self.tick)
        self.reset()

    def start(self):
        self.timer.start(1000)
        self.started.emit()

    def stop(self):
        self.timer.stop()
        self.stopped.emit()

    def reset(self):
        self.time = QTime(0, 0)
        self.display(self.time.toString())
        self.reset_.emit()

    def isRunning(self):
        return self.timer.isActive()

    def text(self):
        if self.time.hour() == 0:
            return self.time.toString('mm:ss')
        else:
            return self.time.toString('h:mm:ss')

    def seconds(self):
        return self.time.hour() * 3600 + self.time.minute() * 60 + self.time.second()

    def tick(self):
        self.time = self.time.addSecs(1)
        text = self.text()
        if len(text) != self.digitCount():
            self.setDigitCount(len(text))
        self.display(text)
        self.textChanged.emit(text)
예제 #4
0
def get_total_seconds(t: QTime) -> int:
    return t.hour() * 3600 + t.minute() * 60 + t.second()
예제 #5
0
 def qTime2float(self, qTime: QTime) -> float:
     return qTime.hour() * 3600 + qTime.minute() * 60 + qTime.second(
     ) + qTime.msec() / 1000
 def timeChanged(self, time: QTime) -> None:
     hour = time.hour()
     minute = time.minute()
     self.prefs.day_start = "{}:{}".format(hour, minute)
     logging.debug("Setting day start to %s", self.prefs.day_start)
     self.downloads_today_tracker.set_day_start(hour=hour, minute=minute)
예제 #7
0
 def QTime2pytime(qtm:QtCore.QTime)->datetime:
     return datetime(1900,1,1,qtm.hour(),qtm.minute(),qtm.second())
예제 #8
0
class TimerWindow(QWidget):

    #Button control functions
    def handleStartBtn(self):
        global isStarted
        isStarted = True
        self.statusInput.setText("Timer Started!")
        self.statusInput.setStyleSheet('color: grey')

    def handleStopBtn(self):
        global isStarted
        if isStarted:
            isStarted = False
            self.statusInput.setText("Reset Timer?")
            self.statusInput.setStyleSheet('color: blue')

    def handleResetBtn(self):
        global isStarted
        global elapseHours
        isStarted = False
        elapseHours = 0
        self.stopwatchTime = QTime(0, 0, 0, 0)
        self.curElapse.setText("00:00:00:000 ms")
        self.updateTimer()

    def handleCloseBtn(self):
        print("Close Button Pressed!")
        self.hide()

    def formatTime(self):
        #Find current time
        timeNow = QTime.currentTime()
        fullTime = timeNow.toString("hh:mm:ss:zzz 'ms'")
        return fullTime

    def formatElapse(self):
        global elapseHours
        if self.stopwatchTime.hour() == 1:
            elapseHours += 1
            self.stopwatchTime = self.stopwatchTime.addSecs(-3600)
        if elapseHours < 10:
            elapseHoursS = "0" + str(elapseHours)
        else:
            elapseHoursS = str(elapseHours)
        fullElapseS = elapseHoursS + ":" + self.stopwatchTime.toString(
            "mm:ss:zzz 'ms'")
        return fullElapseS

    def deductTimer(self):
        global totalMSecRemain
        totalMSecRemain -= 87

    def formatTimer(self):

        global totalMSecRemain
        global isInfoShown

        #Return zeros if miliseconds remaining are negative
        if totalMSecRemain <= 0:
            if not isInfoShown:
                showInfo("Time is Up!")
                isInfoShown = True
            return "00:00:00:000 ms"

        #Calculate timer values
        totalHours = int(totalMSecRemain / 3600000)
        totalMin = int((totalMSecRemain % 3600000) / 60000)
        totalSec = int(((totalMSecRemain % 3600000) % 60000) / 1000)
        totalMilSec = int(((totalMSecRemain % 3600000) % 60000) % 1000)

        #Update timer label
        if totalHours == 0:
            totalHoursS = "00"
        elif totalHours < 10:
            totalHoursS = "0" + str(totalHours)
        else:
            totalHoursS = str(totalHours)

        if totalMin == 0:
            totalMinS = "00"
        elif totalMin < 10:
            totalMinS = "0" + str(totalMin)
        else:
            totalMinS = str(totalMin)

        if totalSec == 0:
            totalSecS = "00"
        elif totalSec < 10:
            totalSecS = "0" + str(totalSec)
        else:
            totalSecS = str(totalSec)

        if totalMilSec == 0:
            totalMilSecS = "000"
        elif totalMilSec < 10:
            totalMilSecS = "00" + str(totalMilSec)
        elif totalMilSec < 100:
            totalMilSecS = "0" + str(totalMilSec)
        else:
            totalMilSecS = str(totalMilSec)

        fullTimerS = totalHoursS + ":" + totalMinS + ":" + totalSecS + ":" + totalMilSecS + " ms"
        return fullTimerS

    def updateTime(self):
        #Update of cur time clock
        self.curTime.setText(self.formatTime())
        #Update next two clocks if started
        if isStarted == True:
            #Update of elapsed time
            self.stopwatchTime = self.stopwatchTime.addMSecs(87)
            self.curElapse.setText(self.formatElapse())
            #Update of timer clock
            self.deductTimer()
            self.curTimer.setText(self.formatTimer())

    def updateTimer(self):
        if isStarted:
            return

        global totalMSecRemain
        global isInfoShown

        inputPresent = False
        isAccepted = False

        #Value validation
        try:
            if self.hourInputFeild.text() != "":
                hourInputNum = int(float(self.hourInputFeild.text()))
                inputPresent = True
                isAccepted = True
            else:
                hourInputNum = 0
            if self.minInputFeild.text() != "":
                minInputNum = int(float(self.minInputFeild.text()))
                inputPresent = True
                isAccepted = True
            else:
                minInputNum = 0
            if self.secInputFeild.text() != "":
                secInputNum = int(float(self.secInputFeild.text()))
                inputPresent = True
                isAccepted = True
            else:
                secInputNum = 0
            self.statusInput.setText("Input Accepted!")
            self.statusInput.setStyleSheet('color: green')
        except ValueError:
            isAccepted = False
            inputPresent = True
            self.statusInput.setText("Input Declined")
            self.statusInput.setStyleSheet('color: red')

        if (inputPresent == False) or ((hourInputNum == 0) and
                                       (minInputNum == 0) and
                                       (secInputNum == 0)):
            totalMSecRemain = 1
            isAccepted = False
            self.curTimer.setText("00:00:00:000 ms")
            self.statusInput.setText("Awaiting Input!")
            self.statusInput.setStyleSheet('color: orange')

        #Update timer variable if value accepted
        if (isAccepted == True):
            #Calculate timer values
            isInfoShown = False
            totalMSecRemain = (hourInputNum * 3600000) + (
                minInputNum * 60000) + (secInputNum * 1000)
            fullTimerS = self.formatTimer()

            self.curTimer.setText(fullTimerS)

    def initWindow(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.show()

    def horLine(self):
        hLine = QFrame()
        hLine.setFrameShape(QFrame.HLine)
        hLine.setFrameShadow(QFrame.Sunken)
        return hLine

    def __init__(self, screenW, screenH):

        super().__init__()
        self.title = "Simple Timer"
        self.width = 640
        self.height = 480
        self.left = (screenW / 2) - (self.width / 2)
        self.top = (screenH / 2) - (self.height / 2)

        #Create button horizontal layout
        btnBox = QHBoxLayout()
        btnBox.addStretch(.5)
        #Create button instaces
        self.startBtn = QPushButton('Start', self)
        self.startBtn.clicked.connect(self.handleStartBtn)
        self.stopBtn = QPushButton('Stop', self)
        self.stopBtn.clicked.connect(self.handleStopBtn)
        self.resetBtn = QPushButton('Reset', self)
        self.resetBtn.clicked.connect(self.handleResetBtn)
        self.closeBtn = QPushButton('Close', self)
        self.closeBtn.clicked.connect(self.handleCloseBtn)
        #Add buttons to layout
        btnBox.addWidget(self.startBtn)
        btnBox.addWidget(self.stopBtn)
        btnBox.addWidget(self.resetBtn)
        btnBox.addWidget(self.closeBtn)
        btnBox.addStretch(.5)

        #Create Update Calls for All Clocks
        self.curTimeTimer = QTimer(self)
        self.curTimeTimer.timeout.connect(self.updateTime)
        self.curTimeTimer.start(87)

        #Create Three Info Clocks
        timeFont = QFont("Ariel", 40)
        #Set the initial current time at start
        curTimeBox = QHBoxLayout()
        curTimeBox.addStretch(.5)
        self.curTime = QLabel(self.formatTime(), self)
        self.curTime.setFont(timeFont)
        curTimeBox.addWidget(self.curTime)
        curTimeBox.addStretch(.5)
        #Set the initial timer time at start
        curTimerBox = QHBoxLayout()
        curTimerBox.addStretch(.5)
        self.curTimer = QLabel("00:00:00:000 ms", self)
        self.curTimer.setFont(timeFont)
        curTimerBox.addWidget(self.curTimer)
        curTimerBox.addStretch(.5)
        #Set the initial elapsed time at start
        self.stopwatchTime = QTime(0, 0, 0, 0)
        curElapseBox = QHBoxLayout()
        curElapseBox.addStretch(.5)
        self.curElapse = QLabel("00:00:00:000 ms", self)
        self.curElapse.setFont(timeFont)
        curElapseBox.addWidget(self.curElapse)
        curElapseBox.addStretch(.5)

        #Create timer input feilds
        inputBox = QHBoxLayout()
        self.introInput = QLabel('Set timer to -', self)
        self.hourInput = QLabel(' Hours:', self)
        self.hourInputFeild = QLineEdit()
        self.minInput = QLabel(' Minutes:', self)
        self.minInputFeild = QLineEdit()
        self.secInput = QLabel(' Seconds:', self)
        self.secInputFeild = QLineEdit()
        self.statusInput = QLabel('Awaiting Input!', self)
        self.statusInput.setStyleSheet('color: orange')
        inputBox.addStretch(.2)
        inputBox.addWidget(self.introInput)
        inputBox.addStretch(.3)
        inputBox.addWidget(self.hourInput)
        inputBox.addWidget(self.hourInputFeild)
        inputBox.addWidget(self.minInput)
        inputBox.addWidget(self.minInputFeild)
        inputBox.addWidget(self.secInput)
        inputBox.addWidget(self.secInputFeild)
        inputBox.addStretch(.3)
        inputBox.addWidget(self.statusInput)
        inputBox.addStretch(.2)

        #Connect input signals to the apropriate function
        self.hourInputFeild.textChanged.connect(self.updateTimer)
        self.minInputFeild.textChanged.connect(self.updateTimer)
        self.secInputFeild.textChanged.connect(self.updateTimer)

        #Create all static labels
        titleFont = QFont("Courier", 20)
        self.curTimeTitle = QLabel('Current Time:', self)
        self.curTimeTitle.setFont(titleFont)
        self.curTimerTitle = QLabel('Time Remaining:', self)
        self.curTimerTitle.setFont(titleFont)
        self.curElapseTitle = QLabel('Elapsed Time:', self)
        self.curElapseTitle.setFont(titleFont)

        #Create and populate root layout
        rootBox = QVBoxLayout()
        rootBox.addWidget(self.curTimeTitle)
        rootBox.addLayout(curTimeBox)
        rootBox.addStretch(.165)
        rootBox.addWidget(self.horLine())
        rootBox.addStretch(.165)
        rootBox.addWidget(self.curTimerTitle)
        rootBox.addLayout(curTimerBox)
        rootBox.addStretch(.165)
        rootBox.addWidget(self.horLine())
        rootBox.addStretch(.165)
        rootBox.addWidget(self.curElapseTitle)
        rootBox.addLayout(curElapseBox)
        rootBox.addStretch(.165)
        rootBox.addWidget(self.horLine())
        rootBox.addStretch(.165)
        rootBox.addLayout(inputBox)
        rootBox.addLayout(btnBox)

        self.setLayout(rootBox)

        self.initWindow()
예제 #9
0
 def set_time(self, time: QtCore.QTime):
     self.time_input = "{:02d}{:02d}{:02d}".format(time.hour(),
                                                   time.minute(),
                                                   time.second())
예제 #10
0
class Main_Page(QMainWindow, Ui_MainWindow, QWidget):
    def __init__(self, h, m, s, window): 
        super().__init__()
        self.setWindowTitle('Таймер')
        
        with open("changes.txt", "rt", encoding="utf8") as f:
            text = f.read().split(';')
        color = text[0].replace('(', '').replace(')', '')
        self.note = text[1]
        color = [int(i) for i in color.split(', ')]
        current_color = QColor(color[0], color[1], color[2], color[3])
        self.setStyleSheet("QMainWindow { background-color: %s }" % 
                           current_color.name())
        
        self.h = h
        self.m = m
        self.s = s
        self.window = window
        self.play_check = False 
        self.setupUi(self)
        self.setGeometry(300, 100, 800, 600)        
        self.current_timer = QTimer(self)
        self.current_timer.setSingleShot(True)
        self.current_timer.timeout.connect(self.runTime)
        self.current_timer.start(100)
        self.Pause.clicked.connect(self.pauseTime)
        self.Stop.clicked.connect(self.stopTime)
        self.Melody.clicked.connect(self.open_mel_win)
 
    def runTime(self):
        self.t1 = QTime(self.h, self.m, self.s, 0)
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.showTime)
        self.timer.start(1000) 
        self.showTime()
        
    def showTime(self):
        if [self.t1.hour(), self.t1.minute(), self.t1.second()] == [0, 0, 0]:
            self.timer.stop()
            self.Melody.setEnabled(False)
            if self.note != '':
                self.Melody.setText(self.note)
            self.Pause.setEnabled(False)
            mixer.init()
            mixer.music.load(self.window.mel.ringtone)
            self.play_check = True
            mixer.music.play(-1)
        text = self.t1.toString('hh:mm:ss')
        if (self.t1.second() % 2) != 0:
            text = text[:2] + ' ' + text[3:5] + ' ' + text[6:]
        self.t1 = self.t1.addSecs(-1)
        self.Time.display(text)
    
    def pauseTime(self):
        if self.timer.isActive():
            self.timer.stop()
            self.Pause.setText('Дальше')
        else:
            self.Pause.setText('Пауза')
            milisec_timer = QTimer(self)
            milisec_timer.setSingleShot(True)
            self.h = self.t1.hour()
            self.m = self.t1.minute()
            self.s = self.t1.second()
            milisec_timer.start(500)
            milisec_timer.timeout.connect(self.runTime)
    
    def stopTime(self):
        if self.play_check:
            mixer.music.stop()
        self.timer.stop()
        self.Pause.setDisabled(False)
        self.Melody.setDisabled(False)
        self.current_timer.stop()
        self.hide()
        self.window.show()
    
    def open_mel_win(self):
        self.window.mel.show()
예제 #11
0
파일: binding.py 프로젝트: aleekaup2/potku
def from_qtime(qtime: QTime) -> int:
    """Converts QTime object to seconds.
    """
    return qtime.hour() * 60 * 60 + qtime.minute() * 60 + qtime.second()