Пример #1
0
class OmniRigQTControls:
    def __init__(self, operatingAsClient, sendCommandFunction=None):
        self.operatingAsClient = operatingAsClient
        self.omnirigObject = None
        self.omniRigInfo = {}
        self.sendCommandFunction = sendCommandFunction
        self.blackColorPalette = QPalette()
        self.blackColorPalette.setColor(QPalette.WindowText, QColor("black"))
        self.redColorPalette = QPalette()
        self.redColorPalette.setColor(QPalette.WindowText, QColor("red"))
        self.boldFont = QFont()
        self.boldFont.setBold(True)
        self.regularFont = QFont()
        self.regularFont.setBold(False)

        self.labelRigName = QLabel("Rig is not responding")
        self.rigSelectGroupBox = QGroupBox("Rig select:")

        self.radioBtnTRX1 = QRadioButton("Rig 1")
        self.radioBtnTRX1.setChecked(True)
        self.radioBtnTRX1.toggled.connect(self.refreshRigInformation)
        self.radioBtnTRX2 = QRadioButton("Rig 2")
        self.radioBtnTRX2.toggled.connect(self.refreshRigInformation)

        hboxRigSelect = QHBoxLayout()
        hboxRigSelect.addWidget(self.radioBtnTRX1)
        hboxRigSelect.addWidget(self.radioBtnTRX2)
        hboxRigSelect.addWidget(self.labelRigName)
        hboxRigSelect.addStretch()
        self.rigSelectGroupBox.setLayout(hboxRigSelect)
        self.rigSelectGroupBox.setMaximumWidth(360)

        self.lcdTrxFrequency = QLCDNumber(10)
        self.lcdTrxFrequency.display('00.000.00')
        self.lcdTrxFrequency.setPalette(self.blackColorPalette)
        self.lcdTrxFrequency.setMinimumHeight(50)
        self.lcdTrxFrequency.setMaximumHeight(50)
        self.lcdTrxFrequency.setMaximumWidth(275)
        self.lcdTrxFrequency.setMinimumWidth(275)

        self.labelRigModeLSB = QLabel('LSB')
        self.labelRigModeLSB.setFont(self.boldFont)
        self.labelRigModeLSB.setEnabled(False)

        self.labelRigModeUSB = QLabel('USB')
        self.labelRigModeUSB.setFont(self.boldFont)
        self.labelRigModeUSB.setEnabled(False)

        vboxMiddlePanel = QVBoxLayout()
        vboxMiddlePanel.addWidget(self.labelRigModeLSB)
        vboxMiddlePanel.addWidget(self.labelRigModeUSB)

        hboxMiddlePanel = QHBoxLayout()
        hboxMiddlePanel.addLayout(vboxMiddlePanel)
        hboxMiddlePanel.addStretch()

        self.btnBack500Hz = QPushButton("<--")
        self.btnBack500Hz.setFixedWidth(50)

        self.btnForward500Hz = QPushButton("-->")
        self.btnForward500Hz.setFixedWidth(50)
        self.btnForward500Hz.clicked.connect(self.btnOmniRigPlus500HzClick)

        self.btnOmniRigUSB = QPushButton("USB")
        self.btnOmniRigUSB.clicked.connect(self.btnOmniUSBClick)
        self.btnOmniRigUSB.setFixedWidth(50)

        self.btnOmniRigLSB = QPushButton("LSB")
        self.btnOmniRigLSB.clicked.connect(self.btnOmniLSBClick)
        self.btnOmniRigLSB.setFixedWidth(50)

        hboxRigCATControl = QHBoxLayout()
        hboxRigCATControl.addWidget(self.btnBack500Hz)
        hboxRigCATControl.addWidget(self.btnForward500Hz)
        hboxRigCATControl.addStretch()
        hboxRigCATControl.addWidget(self.btnOmniRigLSB)
        hboxRigCATControl.addWidget(self.btnOmniRigUSB)
        hboxRigCATControl.addStretch(1)

        hboxMainLayout = QHBoxLayout()
        hboxMainLayout.addWidget(self.lcdTrxFrequency)
        hboxMainLayout.addLayout(hboxMiddlePanel)

        self.vboxMainLayout = QVBoxLayout()
        self.vboxMainLayout.addWidget(self.rigSelectGroupBox)
        self.vboxMainLayout.addLayout(hboxMainLayout)
        if self.operatingAsClient is True:
            self.vboxMainLayout.addLayout(hboxRigCATControl)

    def setOmnirigObject(self, omnirigObject):
        self.omnirigObject = omnirigObject

    def btnOmniRigPlus500HzClick(self):
        try:
            self.omnirigObject = win32.Dispatch("OmniRig.OmniRigX")
        except:
            pass
        if self.omnirigObject is not None and self.operatingAsClient is False:
            if self.radioBtnTRX1.isChecked():
                self.omnirigObject.Rig1.SetSimplexMode(str(self.omnirigObject.Rig1.Freq+500))
            else:
                self.omnirigObject.Rig2.SetSimplexMode(str(self.omnirigObject.Rig1.Freq+500))
        if self.operatingAsClient is True and self.sendCommandFunction is not None:
            self.sendCommandFunction('+500=1')

    def btnOmniLSBClick(self):
        try:
            self.omnirigObject = win32.Dispatch("OmniRig.OmniRigX")
        except:
            pass
        if self.omnirigObject is not None and self.operatingAsClient is False:
            if self.radioBtnTRX1.isChecked():
                self.omnirigObject.Rig1.Mode = '67108864'
            else:
                self.omnirigObject.Rig2.Mode = '67108864'
        if self.operatingAsClient is True and self.sendCommandFunction is not None:
            self.sendCommandFunction('setLSB=1')

    def btnOmniUSBClick(self):
        try:
            self.omnirigObject = win32.Dispatch("OmniRig.OmniRigX")
        except:
            pass
        if self.omnirigObject is not None and self.operatingAsClient is False:
            if self.radioBtnTRX1.isChecked():
                self.omnirigObject.Rig1.Mode = '33554432'
            else:
                self.omnirigObject.Rig2.Mode = '33554432'

        if self.operatingAsClient is True and self.sendCommandFunction is not None:
            self.sendCommandFunction('setUSB=1')

    def setDisplayFreq(self, txtFreq):
        self.lcdTrxFrequency.display(txtFreq)

    def setOmniRigErrorText(self, msgText):
        self.labelRigName.setText(msgText)
        self.labelRigName.setPalette(self.redColorPalette)

    def setRigStatus(self, rigType):
        self.labelRigName.setText(rigType)
        self.labelRigName.setPalette(self.blackColorPalette)

    def getRigsInformation(self):
        return self.omniRigInfo

    def disableControls(self):
        self.radioBtnTRX1.setEnabled(False)
        self.radioBtnTRX2.setEnabled(False)

    def refreshRigInformation(self):
        rignum = '2'
        if self.radioBtnTRX1.isChecked():
            rignum = '1'
        if len(self.omniRigInfo) > 1:
            self.radioBtnTRX1.setText(self.omniRigInfo['1'].getRigType())
            self.radioBtnTRX2.setText(self.omniRigInfo['2'].getRigType())
            freqTxt = self.omniRigInfo[rignum].getRigFreq()
            self.setDisplayFreq(self.addDotsToFreq(freqTxt))
            self.setRigStatus(self.omniRigInfo[rignum].getRigStatus())

            if freqTxt == 0:
                self.labelRigModeUSB.setEnabled(False)
                self.labelRigModeLSB.setEnabled(False)
            else:
                if self.omniRigInfo[rignum].getRigMode() == 'LSB':
                    self.labelRigModeUSB.setEnabled(False)
                    self.labelRigModeLSB.setEnabled(True)
                else:
                    self.labelRigModeUSB.setEnabled(True)
                    self.labelRigModeLSB.setEnabled(False)

    def setRigInformation(self, omniRigInfo):
        self.omniRigInfo = omniRigInfo
        self.refreshRigInformation()

    def addDotsToFreq(self, freqvalue):
        freqTxt = str(freqvalue)
        if len(freqTxt) < 6:
            freqTxt = '00000000'

        firstPart = freqTxt[:-6]
        if len(freqTxt) == 8:
            mainPart = freqTxt[:7]
            middlePart = mainPart[2:5]
            lastPart = mainPart[5:]
        else:
            mainPart = freqTxt[:6]
            middlePart = mainPart[1:4]
            lastPart = mainPart[4:]

        return firstPart+"."+middlePart+"."+lastPart

    def getGUI(self):
        return self.vboxMainLayout
Пример #2
0
class Alram(QMainWindow):

    def __init__(self):
        super().__init__()
        self.hour = '00'
        self.minute = '00'

        #set and load music
        try:
            self.song = path.abspath(path.join(path.dirname(__name__),"carol_of_the_bells-alarm.mp3")) 
            self.isMusicPlay = False
            mixer.init()
            mixer.music.load(self.song)
            mixer.music.set_volume(0.7)

            self.setWindowTitle('Alram')
            self.setGeometry(300,200,350,200)
            self.buildGui()
            self.getCurrentTime()
            self.show()
        except Exception as e:
            pass


    def buildGui(self):
        self.digiClock = QFrame(self)
        self.digiClock_ly = QVBoxLayout()
        self.digiClock.setLayout(self.digiClock_ly)


        self.setALrmBox = QFrame(self.digiClock)
        self.setALrmBox_ly = QHBoxLayout()
        self.setALrmBox.setLayout(self.setALrmBox_ly)

        self.LCDDisplay = QLCDNumber(self.digiClock)
        self.LCDDisplay.setMaximumHeight(200)
        self.LCDDisplay.setMaximumWidth(350)
        self.LCDDisplay.setDigitCount(8)
        self.LCDDisplay.setSegmentStyle(QLCDNumber.Flat)
        #self.LCDDisplay.setBaseSize(150,100)

        self.stopAlrm = QPushButton("Stop Alram")
        self.stopAlrm.clicked.connect(self.stopAlarmTone)

        self.HHour = QComboBox(self.setALrmBox)
        self.MMunit = QComboBox(self.setALrmBox)

        self.HHour.addItem('Hour')
        self.MMunit.addItem('Minute')

        for s in range(0,24):
            s = '0'+str(s) if s in [0,1,2,3,4,5,6,7,8,9] else str(s)
            self.HHour.addItem(s)

        for m in range(0,61):
            m = '0'+str(m) if m in [0,1,2,3,4,5,6,7,8,9] else str(m)
            self.MMunit.addItem(m)

        self.setAlrm = QPushButton("Set Alarm",self.setALrmBox)
        self.setAlrm.clicked.connect(self.setAlrmBtnClick)

        self.setALrmBox_ly.addWidget(self.HHour)
        self.setALrmBox_ly.addWidget(self.MMunit)
        self.setALrmBox_ly.addWidget(self.setAlrm)

        self.digiClock_ly.addWidget(self.LCDDisplay)
        self.digiClock_ly.addWidget(self.setALrmBox)
        self.setCentralWidget(self.digiClock)

    def getCurrentTime(self):
        CTime = dt.datetime.now()
        h = '0'+str(CTime.hour) if CTime.hour in [0,1,2,3,4,5,6,7,8,9] else str(CTime.hour)
        m = '0'+str(CTime.minute) if CTime.minute in [0,1,2,3,4,5,6,7,8,9] else str(CTime.minute)
        s = '0'+str(CTime.second) if CTime.second in [0,1,2,3,4,5,6,7,8,9] else str(CTime.second)
        c = h + ':' + m + ':' + s

        if h == self.getHour() and m == self.getMinute():
            if self.isMusicPlay == False:
                mixer.music.play()
                self.isMusicPlay = True                
                if self.stopAlrm.parentWidget() == None:
                    self.stopAlrm.setParent(self.digiClock)
                else:
                    self.stopAlrm.show()
                self.digiClock_ly.addWidget(self.stopAlrm)

        self.LCDDisplay.display(c)
        self.task1 = threading.Timer(1,self.getCurrentTime)
        self.task1.start()

    def setAlrmBtnClick(self):
        if self.isMusicPlay == True:
            self.stopAlrm.hide()
            self.isMusicPlay = False
        self.hour = str(self.HHour.currentText())
        self.minute = str(self.MMunit.currentText())
        QMessageBox.information(self,'Alerm Set Info',"Alerm set Successfully...!",QMessageBox.Ok)
        #print(f'Hour:{self.hour} Minute:{self.minute}')

    def getHour(self):
        return self.hour

    def getMinute(self):
        return self.minute

    def stopAlarmTone(self):
        mixer.music.stop()

    def closeEvent(self,evnt):
        self.task1.cancel()
        return super().closeEvent(evnt)