Example #1
0
 def __init__(self, parent=None):
     QtGui.QWidget.__init__(self, parent)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.mailed = False
     self.client = TCPClient()
     self.inputlen = 0
     self.Online = {}
     self.connect(self.client, QtCore.SIGNAL(QtCore.QString.fromUtf8("conn(bool)")), self.onconn)
     self.connect(self.client, QtCore.SIGNAL(QtCore.QString.fromUtf8("recv()")), self.onrecv)
     self.showFullScreen()
     self.client.connectsrv()
Example #2
0
class DailyApp(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.mailed = False
        self.client = TCPClient()
        self.inputlen = 0
        self.Online = {}
        self.connect(self.client, QtCore.SIGNAL(QtCore.QString.fromUtf8("conn(bool)")), self.onconn)
        self.connect(self.client, QtCore.SIGNAL(QtCore.QString.fromUtf8("recv()")), self.onrecv)
        self.showFullScreen()
        self.client.connectsrv()
        # self.connect(self.ui.pushButtonChat, QtCore.SIGNAL(QtCore.QString.fromUtf8("clicked()")), self.onbuttonchatclicked)

    def onconn(self, bresult):
        print "onconn"

    def onrecv(self):
        data = self.client.recvqueue[0]
        protoc = [submsg for submsg in data.split("##") if len(submsg) > 0]
        if len(protoc) != 3:
            print "parse data error: %s" % data
        else:
            if int(protoc[0]) == 0 or int(protoc[0]) == self.client.clientid:
                print "data for me:%s" % str(protoc)
                if int(protoc[1]) == 1:
                    self.changebg(protoc[2])
                elif int(protoc[1]) == 2:
                    self.playaudio(protoc[2])
                elif int(protoc[1]) == 3:
                    self.showch(protoc[2])
                elif int(protoc[1]) == 4:
                    self.onplanresult(protoc[2])
        self.client.recvqueue.remove(data)

    def onplanresult(self, result):
        self.ui.label.clear()
        time.sleep(2)
        if result == "Y":
            print "Yes!"
            if 2 == self.client.clientid:
                self.setStyleSheet(_fromUtf8("border-image : url(rc/xi.png)"))
                QtGui.QSound.play(QtCore.QString.fromUtf8("rc\\xshy.wav"))
            else:
                self.setStyleSheet(_fromUtf8("border-image : url(rc/fw.png)"))
                QtGui.QSound.play(QtCore.QString.fromUtf8("rc\\firwork.wav"))
        else:
            print "No?! one more time!"
            self.client.senddata("%d##0##0" % self.client.clientid)

    def changebg(self, bgtype):
        print "changebg: %d" % int(bgtype)
        if int(bgtype) == 1:
            self.backgroundblack()
        elif int(bgtype) == 2:
            self.backgroundpinck()

    def playaudio(self, adtype):
        if int(adtype) == 1:
            print "play audio rc\\boom.wav"
            QtGui.QSound.play(QtCore.QString.fromUtf8("rc\\boom.wav"))
        else:
            print "play audio rc\\cat%d.wav" % (int(adtype) - 1)
            QtGui.QSound.play(QtCore.QString.fromUtf8("rc\\cat%d.wav" % (int(adtype) - 1)))

    def showch(self, ch):
        print "show ch: %s" % ch
        self.ui.label.clear()
        self.ui.label.setText(QtCore.QString.fromUtf8(ch))

    def backgroundblack(self):
        self.setStyleSheet(
            _fromUtf8(
                "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"
            )
        )

    def backgroundpinck(self):
        for times in range(28):
            if times % 2 != 0:
                self.setStyleSheet(_fromUtf8("background-color: rgb(255, 255, 255);"))
            else:
                self.setStyleSheet(_fromUtf8("background-color: rgb(0, 20, 2);"))
            self.repaint()
            time.sleep(0.1)
        self.ui.label.clear()
        self.setStyleSheet(_fromUtf8("border-image : url(rc/cat%d.png)" % self.client.clientid))
        self.repaint()
        # self.setStyleSheet(_fromUtf8("background-color: rgb(255, 85, 255);"))
        # self.setStyleSheet(_fromUtf8("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 143, 255, 255), stop:1 rgba(255, 255, 255, 255));"))

    def keyPressEvent(self, keyEvent):
        QtGui.QSound.play(QtCore.QString.fromUtf8("rc\\star.wav"))
        if keyEvent.key() == QtCore.Qt.Key_G:
            print "Start it!"
            self.client.senddata("%d##0##0" % self.client.clientid)
        elif keyEvent.key() == QtCore.Qt.Key_T:
            print "T!"
            # self.backgroundpinck()
            print "T over!"
        elif keyEvent.key() == QtCore.Qt.Key_Q:
            sys.exit(0)
        elif keyEvent.key() == QtCore.Qt.Key_Y:
            print "key Y!"
            self.client.senddata("%d##4##Y" % self.client.clientid)
        elif keyEvent.key() == QtCore.Qt.Key_N:
            print "key N!"
            self.client.senddata("%d##4##N" % self.client.clientid)
        else:
            QtGui.QMainWindow.keyPressEvent(self, keyEvent)