Example #1
1
    def __init__(self, parent = None):
        super(MainWidget, self).__init__(parent)

        # member variables
        self._lTheorySpd = 0
        self._rTheorySpd = 0
        self._serialSend = SerialSend()

        # mainWindow properties
        self.setObjectName('MainWidget')
        self.setWindowIcon(QIcon(':/image/default/app.icon'))
        self.setWindowTitle('%s V%s' % (
                            qApp.applicationDisplayName(),
                            qApp.applicationVersion()))
        self.resize(800, 480)

        # mainWindow layout

        # top

        self.groupBoxTop = QGroupBox(self)
        self.groupBoxTop.setObjectName('groupBoxTop')

        # command dashboard
        buttonLeftPower = JSwitchButton(parent = self.groupBoxTop)
        buttonRightPower = JSwitchButton(parent = self.groupBoxTop)
        buttonSettings = QPushButton(self.groupBoxTop)
        buttonHistory = QPushButton(self.groupBoxTop)
        buttonQuit = QPushButton(self.groupBoxTop)

        buttonLeftPower.setObjectName('buttonLeftPower')
        buttonRightPower.setObjectName('buttonRightPower')
        buttonSettings.setObjectName('buttonSettings')
        buttonHistory.setObjectName('buttonHistory')
        buttonQuit.setObjectName('buttonQuit')

        areaPortState = QWidget(self)
        areaPortState.setObjectName('areaPortState')
        areaPortState.setStyleSheet('QWidget#areaPortState{border-radius:3px;'
                                    'border:1px solid #505050;'
                                    'background-color:rgba(64,64,64,50);}')
        vertLayoutPortState = QVBoxLayout(areaPortState)
        vertLayoutPortState.setContentsMargins(50, 2, 50, 2)
        vertLayoutPortState.setSpacing(3)

        buttonPortState = JSwitchButton(pixmap = QPixmap(':/carmonitor/image/button-port-state.png'), parent = areaPortState)
        buttonPortState.setObjectName('buttonPortState')
        vertLayoutPortState.addWidget(QLabel('串口', areaPortState), 0, Qt.AlignHCenter)
        vertLayoutPortState.addWidget(buttonPortState)

        #
        horiLayoutTop = QHBoxLayout(self.groupBoxTop)
        horiLayoutTop.setContentsMargins(0, 0, 0, 0)
        horiLayoutTop.addSpacing(25)
        horiLayoutTop.addWidget(buttonSettings, 0, Qt.AlignLeft)
        horiLayoutTop.addSpacing(20)
        horiLayoutTop.addWidget(buttonHistory, 0, Qt.AlignLeft)
        horiLayoutTop.addSpacing(65)
        horiLayoutTop.addWidget(buttonLeftPower)
        horiLayoutTop.addWidget(QLabel('左电源开关', self.groupBoxTop))
        horiLayoutTop.addStretch()
        horiLayoutTop.addWidget(areaPortState, 0, Qt.AlignTop)
        horiLayoutTop.addStretch()
        horiLayoutTop.addWidget(QLabel('右电源开关', self.groupBoxTop))
        horiLayoutTop.addWidget(buttonRightPower)
        horiLayoutTop.addSpacing(150)
        horiLayoutTop.addWidget(buttonQuit, 0, Qt.AlignRight)
        horiLayoutTop.addSpacing(25)

        # middle

        # curves
        self.curveLBP = CurveWidget(title = '左刹车压力(MPa)', parent = self)
        self.curveLRP = CurveWidget(title = '左转速(r/min)', parent = self)
        self.curveRBP = CurveWidget(title = '右刹车压力(MPa)', parent = self)
        self.curveRRP = CurveWidget(title = '右转速(r/min)', parent = self)

        self.curveLBP.setObjectName('curveLBP')
        self.curveLRP.setObjectName('curveLRP')
        self.curveRBP.setObjectName('curveRBP')
        self.curveRRP.setObjectName('curveRRP')

        # self.curveLBP.setAxisScale(QwtPlot.yLeft, 0, 30, 5)

        # areaMiddle
        self.areaMiddle = QWidget(self)
        self.areaMiddle.setObjectName('areaMiddle')
        self.areaMiddle.setFixedWidth(280)

        #
        groupBoxStatus = QGroupBox(self)
        groupBoxStatus.setObjectName('groupBoxStatus')

        # status-view
        gridLayoutStatus = QGridLayout(groupBoxStatus)
        gridLayoutStatus.setContentsMargins(5, 5, 5, 5)
        gridLayoutStatus.setHorizontalSpacing(8)
        gridLayoutStatus.setVerticalSpacing(3)

        # Brake-Command
        editLeftBrakeCmd = QLineEdit(groupBoxStatus)
        editRightBrakeCmd = QLineEdit(groupBoxStatus)
        editLeftBrakeCmd.setObjectName('editLeftBrakeCmd')
        editRightBrakeCmd.setObjectName('editRightBrakeCmd')
        editLeftBrakeCmd.setReadOnly(True)
        editRightBrakeCmd.setReadOnly(True)
        gridLayoutStatus.addWidget(QLabel('刹车指令:', groupBoxStatus),
                                   0, 0, 1, 2, Qt.AlignCenter)
        gridLayoutStatus.addWidget(editLeftBrakeCmd, 1, 0, 1, 1)
        gridLayoutStatus.addWidget(editRightBrakeCmd, 1, 1, 1, 1)

        # Major Brake Pressure
        self.editMLeftBrakeP = QLineEdit(groupBoxStatus)
        self.editMRightBrakeP = QLineEdit(groupBoxStatus)
        self.editMLeftBrakeP.setObjectName('editMLeftBrakeP')
        self.editMRightBrakeP.setObjectName('editMRightBrakeP')
        self.editMLeftBrakeP.setReadOnly(True)
        self.editMRightBrakeP.setReadOnly(True)
        gridLayoutStatus.addWidget(QLabel('主刹车压力:', groupBoxStatus),
                                   2, 0, 1, 2, Qt.AlignCenter)
        gridLayoutStatus.addWidget(self.editMLeftBrakeP, 3, 0, 1, 1)
        gridLayoutStatus.addWidget(self.editMRightBrakeP, 3, 1, 1, 1)

        # Assistant Brake Pressure
        self.editALeftBrakeP = QLineEdit(groupBoxStatus)
        self.editARightBrakeP = QLineEdit(groupBoxStatus)
        self.editALeftBrakeP.setObjectName('editALeftBrakeP')
        self.editARightBrakeP.setObjectName('editARightBrakeP')
        self.editALeftBrakeP.setReadOnly(True)
        self.editARightBrakeP.setReadOnly(True)
        gridLayoutStatus.addWidget(QLabel('副刹车压力:', groupBoxStatus),
                                   4, 0, 1, 2, Qt.AlignCenter)
        gridLayoutStatus.addWidget(self.editALeftBrakeP, 5, 0, 1, 1)
        gridLayoutStatus.addWidget(self.editARightBrakeP, 5, 1, 1, 1)

        # Rotation Rate
        self.editLeftRotateRate = QLineEdit(groupBoxStatus)
        self.editRightRotateRate = QLineEdit(groupBoxStatus)
        self.editLeftRotateRate.setObjectName('editLeftRotateRate')
        self.editRightRotateRate.setObjectName('editRightRotateRate')
        gridLayoutStatus.addWidget(QLabel('实际转速:', groupBoxStatus),
                                   6, 0, 1, 2, Qt.AlignCenter)
        gridLayoutStatus.addWidget(self.editLeftRotateRate, 7, 0, 1, 1)
        gridLayoutStatus.addWidget(self.editRightRotateRate, 7, 1, 1, 1)

        # Theory Rotation Rate
        self.editTheoryLeftRotateRate = QLineEdit(groupBoxStatus)
        self.editTheoryRightRotateRate = QLineEdit(groupBoxStatus)
        self.editTheoryLeftRotateRate.setObjectName('editTheoryLeftRotateRate')
        self.editTheoryRightRotateRate.setObjectName('editTheoryRightRotateRate')
        gridLayoutStatus.addWidget(QLabel('理论转速:', groupBoxStatus),
                                   8, 0, 1, 2, Qt.AlignCenter)
        gridLayoutStatus.addWidget(self.editTheoryLeftRotateRate, 9, 0, 1, 1)
        gridLayoutStatus.addWidget(self.editTheoryRightRotateRate, 9, 1, 1, 1)

        #
        groupBoxCtrl = QGroupBox(self)
        groupBoxCtrl.setObjectName('groupBoxCtrl')

        # status-view
        gridLayoutCtrl = QGridLayout(groupBoxCtrl)
        gridLayoutCtrl.setContentsMargins(5, 5, 5, 5)
        gridLayoutCtrl.setSpacing(20)

        # left-button
        buttonLeftDashboard = JDashButton('左指令旋钮', groupBoxCtrl)
        buttonLeftSpeedGain = JDashButton('左转速增益', groupBoxCtrl)
        buttonLeftSpeedKnob = JDashButton('左转速增益', groupBoxCtrl)
        buttonLeftTracksip = JTracksipButton(parent = groupBoxCtrl)
        buttonLeftDashboard.setObjectName('buttonLeftDashboard')
        buttonLeftSpeedGain.setObjectName('buttonLeftSpeedGain')
        buttonLeftSpeedKnob.setObjectName('buttonLeftSpeedKnob')
        buttonLeftTracksip.setObjectName('buttonLeftTracksip')
        buttonLeftTracksip.setFixedSize(110, 45)

        # right-button
        buttonRightDashboard = JDashButton('右指令旋钮', groupBoxCtrl)
        buttonRightSpeedGain = JDashButton('右转速增益', groupBoxCtrl)
        buttonRightSpeedKnob = JDashButton('右转速增益', groupBoxCtrl)
        buttonRightTracksip = JTracksipButton(parent = groupBoxCtrl)
        buttonRightDashboard.setObjectName('buttonRightDashboard')
        buttonRightSpeedGain.setObjectName('buttonRightSpeedGain')
        buttonRightSpeedKnob.setObjectName('buttonRightSpeedKnob')
        buttonRightTracksip.setObjectName('buttonRightTracksip')
        buttonRightTracksip.setFixedSize(110, 45)

        horiLayoutTracksip = QHBoxLayout()
        horiLayoutTracksip.setContentsMargins(0, 0, 0, 0)
        horiLayoutTracksip.setSpacing(5)
        horiLayoutTracksip.addWidget(buttonLeftTracksip)
        horiLayoutTracksip.addWidget(QLabel('打滑', self), 0, Qt.AlignHCenter)
        horiLayoutTracksip.addWidget(buttonRightTracksip)
        gridLayoutCtrl.addLayout(horiLayoutTracksip, 0, 0, 1, 2)

        horiLayoutDashboard = QHBoxLayout()
        horiLayoutDashboard.setContentsMargins(0, 0, 0, 0)
        horiLayoutDashboard.setSpacing(5)
        horiLayoutDashboard.addWidget(buttonLeftDashboard)
        horiLayoutDashboard.addWidget(QLabel('    ', self), 0, Qt.AlignHCenter)
        horiLayoutDashboard.addWidget(buttonRightDashboard)
        gridLayoutCtrl.addLayout(horiLayoutDashboard, 1, 0, 1, 2)

        horiLayoutSpeedGain = QHBoxLayout()
        horiLayoutSpeedGain.setContentsMargins(0, 0, 0, 0)
        horiLayoutSpeedGain.setSpacing(5)
        horiLayoutSpeedGain.addWidget(buttonLeftSpeedGain)
        horiLayoutSpeedGain.addWidget(QLabel('(粗调)', self), 0, Qt.AlignHCenter)
        horiLayoutSpeedGain.addWidget(buttonRightSpeedGain)
        gridLayoutCtrl.addLayout(horiLayoutSpeedGain, 2, 0, 1, 2)


        horiLayoutSpeedKnob = QHBoxLayout()
        horiLayoutSpeedKnob.setContentsMargins(0, 0, 0, 0)
        horiLayoutSpeedKnob.setSpacing(5)
        horiLayoutSpeedKnob.addWidget(buttonLeftSpeedKnob)
        horiLayoutSpeedKnob.addWidget(QLabel('(细调)', self), 0, Qt.AlignHCenter)
        horiLayoutSpeedKnob.addWidget(buttonRightSpeedKnob)
        gridLayoutCtrl.addLayout(horiLayoutSpeedKnob, 3, 0, 1, 2)

        #
        vertLayoutMid = QVBoxLayout(self.areaMiddle)
        vertLayoutMid.setContentsMargins(0, 0, 0, 0)
        vertLayoutMid.setSpacing(0)
        vertLayoutMid.addWidget(groupBoxStatus)
        vertLayoutMid.addWidget(groupBoxCtrl)
        vertLayoutMid.addSpacing(20)

        #
        gridLayoutBottom = QGridLayout()
        gridLayoutBottom.setContentsMargins(0, 0, 0, 0)
        gridLayoutBottom.setSpacing(1)
        gridLayoutBottom.addWidget(self.curveLBP, 0, 0, 1, 1)
        gridLayoutBottom.addWidget(self.curveLRP, 1, 0, 1, 1)
        gridLayoutBottom.addWidget(self.areaMiddle, 0, 1, 2, 1)
        gridLayoutBottom.addWidget(self.curveRBP, 0, 2, 1, 1)
        gridLayoutBottom.addWidget(self.curveRRP, 1, 2, 1, 1)

        # main-layout
        vertLayoutMain = QVBoxLayout(self)
        vertLayoutMain.setContentsMargins(5, 5, 5, 5)
        vertLayoutMain.addWidget(self.groupBoxTop)
        vertLayoutMain.addLayout(gridLayoutBottom)

        # global properties
        qApp.setProperty('MainWidget', self)
        self._serialProxy = SerialPortProxy(self)
        self._serialProxy._serialSimulate = SerialSimulate(self._serialProxy)  #
        qApp.setProperty('SerialProxy', self._serialProxy)

        #
        buttonSettings.clicked.connect(self.onButtonSettingsClicked)
        buttonHistory.clicked.connect(self.onButtonHistoryClicked)
        buttonPortState.clicked.connect(self.onButtonPortStateClicked)
        buttonQuit.clicked.connect(self.onButtonQuitClicked)

        # curves
        self.curveLBP.doubleClicked.connect(self.onCurveDoubleClicked)
        self.curveLRP.doubleClicked.connect(self.onCurveDoubleClicked)
        self.curveRBP.doubleClicked.connect(self.onCurveDoubleClicked)
        self.curveRRP.doubleClicked.connect(self.onCurveDoubleClicked)

        # switch-power
        buttonLeftPower.stateChanged.connect(self.onButtonLeftPowerStateChanged)
        buttonRightPower.stateChanged.connect(self.onButtonRightPowerStateChanged)

        # switch-tracksip
        buttonLeftTracksip.stateChanged.connect(self.onButtonLeftTracksipStateChanged)
        buttonRightTracksip.stateChanged.connect(self.onButtonRightTracksipStateChanged)

        self._serialProxy.stateChanged.connect(self.onSerialStateChanged)
        self._serialProxy.serialPortError.connect(self.onSerialPortError)
        self._serialProxy.displayRespond.connect(self.onSerialDisplayRespond)

        #
        buttonLeftSpeedGain.clicked.connect(self.execSliderWidget)
        buttonLeftSpeedKnob.clicked.connect(self.execSliderWidget)
        buttonRightSpeedGain.clicked.connect(self.execSliderWidget)
        buttonRightSpeedKnob.clicked.connect(self.execSliderWidget)

        # final initialization

        self.editMLeftBrakeP.setText('0 MPa')
        self.editMRightBrakeP.setText('0 MPa')
        self.editALeftBrakeP.setText('0 MPa')
        self.editARightBrakeP.setText('0 MPa')

        self.editLeftRotateRate.setText('0 r/min')
        self.editRightRotateRate.setText('0 r/min')
        self.editTheoryLeftRotateRate.setText('0 r/min')
        self.editTheoryRightRotateRate.setText('0 r/min')

        #
        c_memset(self._serialSend, 0, ctypes.sizeof(self._serialSend))

        # SQL
        sqlName = applicationDirPath() \
            + '/../data/cm-' \
            + QDateTime.currentDateTime().toLocalTime().toString('yyyy-MM-dd-HH-mm-ss') \
            + '.db'
        if not DatabaseMgr().create(sqlName):
            assert(False)

        # start serialport
        self._serialProxy.start()

        #
        buttonLeftTracksip.setState(self._serialSend.ctrlWord.lTracksip)
        buttonRightTracksip.setState(self._serialSend.ctrlWord.lTracksip)
Example #2
0
def create_donate_widget(button):
    w = QWidget()
    w.setLayout(QVBoxLayout())
    w.layout().addWidget(button)
    if isosx:
        w.setStyleSheet('QWidget, QToolButton {background-color: none; border: none; }')
        w.layout().setContentsMargins(0,0,0,0)
        w.setContentsMargins(0,0,0,0)
        w.filler = QLabel(u'\u00a0')
        w.layout().addWidget(w.filler)
    return w
Example #3
0
def create_donate_widget(button):
    w = QWidget()
    w.setLayout(QVBoxLayout())
    w.layout().addWidget(button)
    if isosx:
        w.setStyleSheet(
            'QWidget, QToolButton {background-color: none; border: none; }')
        w.layout().setContentsMargins(0, 0, 0, 0)
        w.setContentsMargins(0, 0, 0, 0)
        w.filler = QLabel(u'\u00a0')
        w.layout().addWidget(w.filler)
    return w
Example #4
0
class SingleRank(QWidget):
    single_rk_comeback_sg = pyqtSignal()
    detail_sg = pyqtSignal(str)

    def __init__(self, parent=None):
        super(SingleRank, self).__init__(parent)
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.h = self.screenRect.height()
        self.w = self.screenRect.width()
        self.xr = self.w / 930
        self.yr = self.h / 640
        self.zr = min(self.xr, self.yr)
        self.inlist = {}
        self.back2_wi = QWidget(self)
        self.rankexit_but = QPushButton(self)
        self.header1 = QLabel(self.back2_wi)
        self.comeback_but = QPushButton(self.back2_wi)
        self.next_but = QPushButton(self.back2_wi)
        self.table = QWidget(self.back2_wi)
        self.tablein = QGridLayout()
        self.headers = ['对局id', '分数', '时间', '详情']
        self.set_ui()
        with open('rank.qss', 'r') as f:
            self.setStyleSheet(f.read())

    def set_ui(self):
        self.setWindowTitle('SingleRank')
        self.setObjectName('singlerank')
        self.resize(self.w, self.h)
        effect = QGraphicsDropShadowEffect()
        effect.setOffset(10, 10)
        effect.setColor(QColor(0, 0, 0, 80))
        effect.setBlurRadius(20)
        effect1 = QGraphicsDropShadowEffect()
        effect1.setOffset(10, 10)
        effect1.setColor(QColor(0, 0, 0, 80))
        effect1.setBlurRadius(20)
        self.back2_wi.setObjectName('back')
        self.back2_wi.resize(self.xr * 793, self.yr * 534)
        self.back2_wi.move(self.xr * 69, self.yr * 53)
        self.back2_wi.setGraphicsEffect(effect)
        self.header1.setObjectName('header')
        self.header1.resize(self.xr * 172, self.yr * 36)
        self.header1.move(self.xr * 24, self.yr * 10)
        self.header1.setText('过往战绩')
        self.header1.setAlignment(Qt.AlignCenter)
        self.comeback_but.setObjectName('comeback')
        self.comeback_but.resize(self.xr * 80, self.yr * 36)
        self.comeback_but.move(self.xr * 67, self.yr * 467)
        self.comeback_but.setText('返回')
        self.comeback_but.clicked.connect(self.come_back)
        self.comeback_but.setGraphicsEffect(effect1)
        self.next_but.setObjectName('next')
        self.next_but.resize(self.zr * 38, self.zr * 38)
        self.next_but.move(self.xr * 725, self.yr * 468)
        self.next_but.setStyleSheet('border-radius:{}px;'.format(self.zr * 18))
        self.next_but.clicked.connect(self.next)
        self.table.setObjectName('table')
        self.table.resize(self.xr * 746, self.yr * 382)
        self.table.move(self.xr * 24, self.yr * 61)
        self.tablein.setSpacing(0)
        self.tablein.setContentsMargins(0, 0, 0, 0)
        self.table.setLayout(self.tablein)
        li = ['#f5f0e3', '#cccccc']
        for i in range(0, 5):
            for j in range(0, 4):
                if j == 3 and i != 0:
                    exec('self.tableheader{}_{} = QPushButton()'.format(i, j))
                    exec(
                        'self.tableheader{}_{}.setMinimumHeight(self.yr *382/5)'
                        .format(i, j))
                    exec('self.tableheader{}_{}.setText("详情")'.format(i, j))
                    exec(
                        'self.tableheader{}_{}.clicked.connect(self.details{})'
                        .format(i, j, i))
                else:
                    exec('self.tableheader{}_{} = QLabel()'.format(i, j))
                    exec('self.tableheader{}_{}.setAlignment(Qt.AlignCenter)'.
                         format(i, j))
                if i == 0:
                    exec('self.tableheader{}_{}.setObjectName("table_head")'.
                         format(i, j))
                    exec('self.tableheader{}_{}.setText("{}")'.format(
                        i, j, self.headers[j]))
                else:
                    exec('self.tableheader{}_{}.setObjectName("table_unit")'.
                         format(i, j))
                exec(
                    'self.tableheader{}_{}.setStyleSheet("background-color:{};")'
                    .format(i, j, li[(i + j) % 2]))
                exec('self.tablein.addWidget(self.tableheader{}_{}, {}, {})'.
                     format(i, j, i, j))
        self.back2_wi.setStyleSheet('#back{border-radius:' +
                                    str(self.zr * 20) +
                                    'px;}#header{border-radius:' +
                                    str(self.zr * 15) + 'px;font-size:' +
                                    str(int(self.zr * 18)) +
                                    'px;}#comeback{border-radius:' +
                                    str(self.zr * 15) + 'px;font-size:' +
                                    str(int(self.zr * 16)) +
                                    'px;}#table_unit{font-size:' +
                                    str(int(self.zr * 18)) +
                                    'px;}#table_head{font-size:' +
                                    str(int(self.zr * 20)) +
                                    'px;font-weight:bold}')

    def come_back(self):
        self.single_rk_comeback_sg.emit()

    def get_list(self, info):
        if len(info) >= 4:
            li = info[:4]
            self.inlist = info[4:]
        else:
            li = info
            self.inlist = info
        self.set_table(li)

    def set_table(self, mp):
        lens = len(mp)
        for i in range(1, lens + 1):
            self.next_but.setEnabled(True)
            exec('self.tableheader{}_0.setText("{}")'.format(
                i, mp[i - 1]['id']))
            exec('self.tableheader{}_1.setText("{}")'.format(
                i, mp[i - 1]['score']))
            exec('self.tableheader{}_2.setText("{}")'.format(
                i, mp[i - 1]['time']))
        if lens < 4:
            for i in range(lens + 1, 5):
                self.next_but.setEnabled(False)
                exec('self.tableheader{}_0.clear()'.format(i))
                exec('self.tableheader{}_1.clear()'.format(i))
                exec('self.tableheader{}_2.clear()'.format(i))

    def next(self):
        if len(self.inlist) >= 4:
            li = self.inlist[:4]
            self.inlist = self.inlist[4:]
        else:
            li = self.inlist
        self.set_table(li)

    def details1(self):
        if self.tableheader1_0.text() != '':
            self.detail_sg.emit(self.tableheader1_0.text())

    def details2(self):
        if self.tableheader2_0.text() != '':
            self.detail_sg.emit(self.tableheader2_0.text())

    def details3(self):
        if self.tableheader3_0.text() != '':
            self.detail_sg.emit(self.tableheader3_0.text())

    def details4(self):
        if self.tableheader4_0.text() != '':
            self.detail_sg.emit(self.tableheader4_0.text())
Example #5
0
class Index(QWidget):
    show_mainindex_sg = pyqtSignal(int, str)
    show_register_sg = pyqtSignal()

    def __init__(self, parent=None):
        super(Index, self).__init__(parent)
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.h = self.screenRect.height()
        self.w = self.screenRect.width()
        self.xr = self.w / 930
        self.yr = self.h / 640
        self.zr = min(self.xr, self.yr)
        self.top_wi = QWidget(self)
        self.logo_la = QLabel(self.top_wi)
        self.ind_wi = QWidget(self)
        self.login_but = QPushButton(self.ind_wi)
        self.joke_but = QPushButton(self.ind_wi)
        self.register_but = QPushButton(self.ind_wi)
        self.imp_la = QLabel(self.ind_wi)
        self.account_le = QLineEdit(self.ind_wi)
        self.psw_le = QLineEdit(self.ind_wi)
        self.loading = QLabel(self)
        self.gif = QMovie('./resource/image/load.gif')
        self.set_ui()
        with open('index.qss', 'r') as f:
            self.setStyleSheet(f.read())

    def set_ui(self):
        self.setWindowTitle('Login')
        self.setObjectName('index')
        self.resize(self.w, self.h)
        self.top_wi.setObjectName('top')
        self.top_wi.resize(930 * self.xr, 95 * self.yr)
        self.logo_la.setObjectName('logo')
        self.logo_la.resize(65 * self.xr, 65 * self.zr)
        self.logo_la.move(29 * self.xr, 16 * self.yr)
        effect = QGraphicsDropShadowEffect()
        effect.setOffset(10, 10)
        effect.setColor(QColor(0, 0, 0, 80))
        effect.setBlurRadius(20)
        self.ind_wi.setObjectName('login')
        self.ind_wi.resize(327 * self.xr, 388 * self.yr)
        self.ind_wi.move(300 * self.xr, 150 * self.yr)
        self.ind_wi.setGraphicsEffect(effect)
        self.joke_but.setObjectName('joke')
        self.joke_but.resize(130 * self.xr, 30 * self.yr)
        self.joke_but.move(76 * self.xr, 234 * self.yr)
        self.joke_but.setFlat(True)
        self.joke_but.setText('忘记密码?我也没办法')
        self.login_but.setObjectName('button')
        self.login_but.move(64 * self.xr, 260 * self.yr)
        self.login_but.resize(202 * self.xr, 45 * self.yr)
        self.login_but.setText('登陆')
        self.login_but.clicked.connect(self.login)
        self.register_but.setObjectName('button')
        self.register_but.move(64 * self.xr, 315 * self.yr)
        self.register_but.resize(202 * self.xr, 45 * self.yr)
        self.register_but.setText('注册')
        self.register_but.clicked.connect(self.show_register)
        self.imp_la.setObjectName('imp_label')
        self.imp_la.resize(100 * self.zr, 100 * self.zr)
        self.imp_la.move(115 * self.xr + 100 * (self.xr - self.zr) / 2, 15 * self.yr)
        self.imp_la.setStyleSheet('border-radius:{}px;'.format(self.zr * 49))
        self.account_le.setObjectName('input')
        self.account_le.setTextMargins(20, 0, 0, 0)
        self.account_le.resize(213 * self.xr, 45 * self.yr)
        self.account_le.move(59 * self.xr, 126 * self.yr)
        self.account_le.setPlaceholderText('账号')
        self.psw_le.setObjectName('input')
        self.psw_le.setTextMargins(20, 0, 0, 0)
        self.psw_le.resize(213 * self.xr, 45 * self.yr)
        self.psw_le.move(59 * self.xr, 181 * self.yr)
        self.psw_le.setPlaceholderText('密码')
        self.psw_le.setEchoMode(QLineEdit.Password)
        self.loading.setObjectName('load')
        self.loading.resize(self.xr * 150, self.yr * 150)
        self.loading.move(self.xr * 760, self.yr * 500)
        self.loading.setScaledContents(True)
        self.loading.setMovie(self.gif)
        self.gif.start()
        self.ind_wi.setStyleSheet('#input{border-radius:' + str(self.zr * 20) + 'px;}' + '#button{border-radius:' + str(
            self.zr * 20) + 'px;' + 'font-size:' + str(int(self.zr * 18)) + 'px;}')

    def login(self):
        account_p = self.account_le.text()
        psw_p = self.psw_le.text()
        dic = login(account_p, psw_p)
        if dic['status'] == 0:
            self.show_mainindex_sg.emit(dic['data']['user_id'], dic['data']['token'])
        elif dic['status'] == 1:
            self.account_le.clear()
            self.psw_le.clear()
            self.account_le.setStyleSheet('border:4px solid;border-color:red;')
            self.account_le.setPlaceholderText('网络超时')
        else:
            self.account_le.clear()
            self.psw_le.clear()
            self.account_le.setStyleSheet('border:4px solid;border-color:red;')
            self.account_le.setPlaceholderText('账号不存在或密码错误')

    def show_register(self):
        self.show_register_sg.emit()
class PlotToolbarOptions(QWidget):
    def __init__(self,
                 parent,
                 series_style,
                 theme_manager,
                 plot,
                 options=None,
                 legend_control=None,
                 right_padding=0.0,
                 has_extra_tools=False):
        QWidget.__init__(self, parent)
        self._theme_manager = theme_manager
        self._plot = plot
        self._toolbar_container = ToolbarContainer(plot)

        self._background_color_qt = _to_qt_color(
            series_style.get_color_from_key('axes_background'))
        self._foreground_color_qt = _to_qt_color(
            series_style.get_color_from_key('axes_foreground'))
        interpolation = interpolate_rgb(self._background_color_qt,
                                        self._foreground_color_qt, 3)
        self._icon_hover_color = interpolation[1]

        self._toolbar = PlotToolbarWidget(self._toolbar_container, plot,
                                          self._foreground_color_qt,
                                          self._icon_hover_color)
        self._toolbar.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self._layout = QGridLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self._layout.addWidget(plot, 0, 0, 1, 3)
        self._background_opacity = 0.8
        plot.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        if options is not None:
            if isinstance(options, PlotOptionsView):
                plot.setOptionsView(options)
            self._options = self._add_popout(ToolType.options, options)
        else:
            self._options = None

        if legend_control is not None:
            if isinstance(legend_control, LegendControlView):
                plot.setLegendControl(legend_control)
            self._legend_control = self._add_popout(ToolType.legend,
                                                    legend_control)
            legend_control.hasHiddenSeriesChanged.connect(
                self._handle_has_hidden_series_changed)
        else:
            self._legend_control = None

        self._toolbar_layout = QVBoxLayout(self._toolbar_container)
        self._toolbar_layout.addWidget(self._toolbar, Qt.AlignTop)

        self._layout.addWidget(self._toolbar_container, 0, 1,
                               Qt.AlignRight | Qt.AlignTop)
        self._layout.setColumnStretch(0, 1)
        self._layout.setColumnStretch(1, 0)
        if right_padding > 0:
            self._padding_widget = QWidget(self)
            self._padding_widget.setVisible(False)
            self._layout.addWidget(self._padding_widget, 0, 2)
            self._layout.setColumnMinimumWidth(2, right_padding)
        else:
            self._padding_widget = None

        if not has_extra_tools:
            self._toolbar_layout.addStretch()

    def _handle_has_hidden_series_changed(self, has_hidden):
        color = None if not has_hidden else self._theme_manager.get_color(
            'highlight')
        self._toolbar.setColor(ToolType.legend, color)

    def _handle_tool_activated(self, tool_type, view):
        def _(tool, active):
            if tool == tool_type:
                view.setVisible(active)
                if self._padding_widget:
                    self._padding_widget.setVisible(active)
                if active:
                    self._toolbar_container.setStyleSheet(
                        "ToolbarContainer {{ background-color: {} }}".format(
                            format_color(self._background_color_qt,
                                         ColorFormat.rgba_string_256,
                                         self._background_opacity)))
                    self._layout.setAlignment(self._toolbar_container,
                                              Qt.AlignRight)
                    if self._padding_widget:
                        self._padding_widget.setStyleSheet(
                            "QWidget {{ background-color: {} }}".format(
                                format_color(self._background_color_qt,
                                             ColorFormat.rgba_string_256,
                                             self._background_opacity)))
                else:
                    self._layout.setAlignment(self._toolbar_container,
                                              Qt.AlignRight | Qt.AlignTop)
                    self._toolbar_container.setStyleSheet("")
                    if self._padding_widget:
                        self._padding_widget.setStyleSheet("")

        return _

    def addTool(self, tool_widget):
        self._toolbar_layout.addWidget(HLine(self._plot), Qt.AlignTop)
        self._toolbar_layout.addWidget(tool_widget,
                                       Qt.AlignTop | Qt.AlignCenter)
        self._toolbar_layout.addStretch()

    @property
    def icon_color(self):
        return self._foreground_color_qt

    @property
    def icon_hover_color(self):
        return self._icon_hover_color

    @property
    def toolbar(self):
        return self._toolbar

    def _add_popout(self, tool_type, view):
        popout = PopoutWidget(self, view, self._background_color_qt,
                              self._foreground_color_qt,
                              self._background_opacity)
        popout.setVisible(False)
        self._layout.addWidget(popout, 0, 0, Qt.AlignRight)
        self._toolbar.toolActivated.connect(
            self._handle_tool_activated(tool_type, popout))
        return popout
Example #7
0
class ResultSingle(QWidget):
    result_exit_sg = pyqtSignal()

    def __init__(self, parent=None):
        super(ResultSingle, self).__init__(parent)
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.h = self.screenRect.height()
        self.w = self.screenRect.width()
        self.xr = self.w / 930
        self.yr = self.h / 640
        self.zr = min(self.xr, self.yr)
        self.back1_wi = QWidget(self)
        self.resexit_but = QPushButton(self)
        self.id_head = QLabel(self.back1_wi)
        self.role1 = QWidget(self.back1_wi)
        self.role1_detail = QWidget(self.role1)
        self.role4 = QWidget(self.back1_wi)
        self.role4_detail = QWidget(self.role4)
        self.role4_special = QLabel(self.role4)
        self.set_ui()
        with open('result.qss', 'r') as f:
            self.setStyleSheet(f.read())

    def set_ui(self):
        self.setWindowTitle('Result')
        self.setObjectName('result')
        self.resize(self.w, self.h)
        effect = QGraphicsDropShadowEffect()
        effect.setOffset(10, 10)
        effect.setColor(QColor(0, 0, 0, 80))
        effect.setBlurRadius(20)
        self.back1_wi.setObjectName('back')
        self.back1_wi.resize(self.xr * 793, self.yr * 534)
        self.back1_wi.move(self.xr * 69, self.yr * 53)
        self.back1_wi.setGraphicsEffect(effect)
        back_x = 69
        back_y = 53
        effect1 = QGraphicsDropShadowEffect()
        effect1.setOffset(10, 10)
        effect1.setColor(QColor(0, 0, 0, 80))
        effect1.setBlurRadius(20)
        effect4 = QGraphicsDropShadowEffect()
        effect4.setOffset(10, 10)
        effect4.setColor(QColor(0, 0, 0, 80))
        effect4.setBlurRadius(20)
        self.resexit_but.setObjectName('resexit')
        self.resexit_but.resize(self.zr * 38, self.zr * 38)
        self.resexit_but.move(self.xr * 834, self.yr * 36)
        self.resexit_but.clicked.connect(self.result_exit)
        self.resexit_but.setStyleSheet('border-radius:{}px;'.format(self.zr * 18))
        self.id_head.setObjectName('id_head')
        self.id_head.resize(self.xr * 350, self.yr * 140)
        self.id_head.move(self.xr * 225, self.yr * 195)
        # self.id_head.setText('战局ID:4396')
        self.id_head.setAlignment(Qt.AlignCenter)
        self.id_head.setStyleSheet('font-size:{}px;'.format(int(self.zr * 50)))
        self.role1.setObjectName('role')
        self.role1.resize(self.xr * 716, self.yr * 87)
        self.role1.move(self.xr * (108 - back_x), self.yr * (77 - back_y))
        self.role1.setGraphicsEffect(effect1)
        # self.role1_head.setText('test')
        self.role1_detail.setObjectName('role_detail')
        self.role1_detail.resize(self.xr * 606, self.yr * 87)
        self.role1_detail.move(self.xr * 110, self.yr * 0)
        self.role4.setObjectName('role')
        self.role4.resize(self.xr * 716, self.yr * 87)
        self.role4.move(self.xr * (108 - back_x), self.yr * (467 - back_y))
        self.role4.setGraphicsEffect(effect4)
        self.role4_detail.setObjectName('role_detail')
        self.role4_detail.resize(self.xr * 606, self.yr * 87)
        self.role4_detail.move(self.xr * 110, self.yr * 0)
        self.role4_special.setObjectName('role_special')
        self.role4_special.resize(self.xr * 88, self.yr * 36)
        self.role4_special.move(self.xr * 70, self.yr * 26)
        self.role4_special.setAlignment(Qt.AlignCenter)
        for i in range(1, 14):
            if i >= 9:
                xp = 416
                t = 9
            elif i >= 4:
                xp = 239
                t = 4
            else:
                xp = 108
                t = 1
            if i == 3 or i == 8 or i == 13:
                exec('self.role4_lv{}=QLabel(self.role4_detail)'.format(i))
                exec('self.role4_lv{}.resize(self.xr*46,self.yr*67)'.format(i))
                exec('self.role4_lv{}.move(self.xr*(xp+({}-t)*20)+90,self.yr*10)'.format(i, i))
                exec('self.role4_lv{}.setStyleSheet("font-size:{}px;")'.format(i, int(self.zr * 17)))
                # exec('self.role4_lv{}.setText(change_vertical(" 葫芦"))'.format(i))
                exec('self.role4_lv{}.setAlignment(Qt.AlignCenter)'.format(i))
            exec('self.role1_card{}=QLabel(self.role1_detail)'.format(i))
            exec('self.role1_card{}.setObjectName("card")'.format(i))
            exec('self.role1_card{}.resize(self.xr*46,self.yr*67)'.format(i))
            exec('self.role1_card{}.move(self.xr*i*33,self.yr*10)'.format(i))
            exec('self.role1_card{}.setScaledContents(True)'.format(i))
            exec('self.role4_card{}=QLabel(self.role4_detail)'.format(i))
            exec('self.role4_card{}.setObjectName("card")'.format(i))
            exec('self.role4_card{}.resize(self.xr*46,self.yr*67)'.format(i))
            exec('self.role4_card{}.move(self.xr*(xp+({}-t)*20),self.yr*10)'.format(i, i))
            exec('self.role4_card{}.setScaledContents(True)'.format(i))
        self.back1_wi.setStyleSheet(
            '#back{border-radius:' + str(self.zr * 25) + 'px;}#role{border-radius:' + str(
                self.zr * 18) + 'px;}#role_head{border-radius:' + str(self.zr * 15) + 'px;font-size:' + str(
                int(self.zr * 16)) + 'px;}#role_special{font-size:' + str(int(self.zr * 18)) + 'px;}')

    def result_exit(self):
        self.result_exit_sg.emit()

    def set_role(self, info):
        self.id_head.setText('战局ID:{}'.format(info['id']))
        self.role4_special.setText('{}'.format('散牌'))
        i = 1
        for card in info['origin_cards']:
            exec('self.role1_card{}.setPixmap(QPixmap("./resource/image/{}.jpg"))'.format(i, card))
            i += 1
        t = 3
        j = 1
        for de in info['cards']:
            exec('self.role4_lv{}.setText("{}")'.format(t, de['lv']))
            for card in de["card"]:
                exec('self.role4_card{}.setPixmap(QPixmap("./resource/image/{}.jpg"))'.format(j, card))
                j += 1
            t += 5
Example #8
0
class TDockWidget(QDockWidget):

    def __init__(self, title="", parent=None, flags=Qt.WindowFlags(), bind_widget=None, close_slot=None, toggle_slot=None):
        QDockWidget.__init__(self, title, parent, flags)
        self.installEventFilter(self)
        self.main_win = parent
        # default stlyesheets for title bars
        self.title_stylesheet = "QWidget {background: rgb(68,68,68);}"
        self.button_style = "QPushButton:hover:!pressed {background: grey;}"
        from TigGUI.Images.ControlDialog import ImageControlDialog
        from TigGUI.Plot.SkyModelPlot import ToolDialog
        from TigGUI.Plot.SkyModelPlot import LiveImageZoom
        if bind_widget is not None:
            self.bind_widget = bind_widget
        if bind_widget is not None:
            if isinstance(bind_widget, ToolDialog):
                self.tdock_style = "ToolDialog {border: 1.5px solid rgb(68,68,68);}"
            elif isinstance(bind_widget, ImageControlDialog):
                self.tdock_style = "ImageControlDialog {border: 1.5px solid rgb(68,68,68);}"
        # set default sizes for QDockWidgets
        self.btn_w = 28
        self.btn_h = 28
        self.icon_size = QSize(20, 20)
        self.font_size = 8
        # setup custom title bar for profiles dockable
        self.dock_title_bar = QWidget()
        self.dock_title_bar.setContentsMargins(0, 0, 0, 0)
        self.dock_title_bar.setStyleSheet(self.title_stylesheet)
        self.dock_title_bar.setBaseSize(0, 0)
        self.dock_title_layout = QHBoxLayout()
        self.dock_title_layout.setContentsMargins(0, 0, 0, 0)
        self.dock_title_layout.setSpacing(0)
        self.dock_title_bar.setLayout(self.dock_title_layout)
        # custom close button
        self.close_button = QPushButton()
        self.close_button.setStyleSheet(self.button_style)
        self.close_button.setMaximumWidth(self.btn_w)
        self.close_button.setMaximumHeight(self.btn_h)
        self.close_button.setContentsMargins(0, 0, 0, 0)
        self.close_button.setBaseSize(0, 0)
        self.close_icon = self.dock_title_bar.style().standardIcon(QStyle.SP_TitleBarCloseButton)
        self.close_button.setIcon(self.close_icon)
        self.close_button.setToolTip("Close")
        # custom toggle button
        self.toggle_button = QPushButton()
        self.toggle_button.setStyleSheet(self.button_style)
        self.toggle_button.setMaximumWidth(self.btn_w)
        self.toggle_button.setMaximumHeight(self.btn_h)
        self.toggle_button.setContentsMargins(0, 0, 0, 0)
        self.toggle_button.setBaseSize(0, 0)
        self.toggle_icon = self.dock_title_bar.style().standardIcon(QStyle.SP_TitleBarShadeButton)
        self.toggle_button.setIcon(self.toggle_icon)
        self.toggle_button.setToolTip("Dock/float widget")
        # tigger logo
        self.image0 = pixmaps.tigger_logo.pm()
        self.title_icon = QLabel()
        self.title_icon.setContentsMargins(0, 0, 0, 0)
        self.title_icon.setBaseSize(0, 0)
        self.title_icon.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.title_icon.setScaledContents(True)
        self.title_icon.setPixmap(self.image0)
        self.title_icon.setAlignment(Qt.AlignCenter)
        self.title_icon.setMaximumSize(self.icon_size)
        # set dock widget title
        self.title_font = QFont()
        self.title_font.setBold(True)
        self.title_font.setPointSize(self.font_size)
        if bind_widget is not None:
            if isinstance(bind_widget, ImageControlDialog):
                self.dock_title = QLabel(f"{title}: Control Dialog")
            else:
                self.dock_title = QLabel(title)
        self.dock_title.setFont(self.title_font)
        self.dock_title.setAlignment(Qt.AlignCenter)
        self.dock_title.setContentsMargins(0, 0, 0, 0)
        self.dock_title.setBaseSize(0, 0)
        self.dock_title.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
        # add dock widget title items to layout
        self.dock_title_layout.addWidget(self.title_icon)
        self.dock_title_layout.addWidget(self.dock_title)
        self.dock_title_layout.addWidget(self.toggle_button)
        self.dock_title_layout.addWidget(self.close_button)
        # set up profiles as dockable
        self.setStyleSheet(self.tdock_style)
        self.setWidget(bind_widget)
        self.setFeatures(QDockWidget.AllDockWidgetFeatures)
        if bind_widget is not None:
            if isinstance(bind_widget, ToolDialog):
                self.setAllowedAreas(Qt.AllDockWidgetAreas)
            elif isinstance(bind_widget, ImageControlDialog):
                self.setAllowedAreas(Qt.RightDockWidgetArea | Qt.LeftDockWidgetArea)
        self.setTitleBarWidget(self.dock_title_bar)
        self.setFloating(False)
        # get current sizeHints()
        if bind_widget is not None:
            self.setBaseSize(bind_widget.sizeHint())
            if isinstance(bind_widget, LiveImageZoom):
                bind_widget.livezoom_resize_signal.connect(self._resizeDockWidget)
        if close_slot is not None:
            self.close_button.clicked.connect(close_slot)
        if toggle_slot is not None:
            self.toggle_button.clicked.connect(toggle_slot)

    def _resizeDockWidget(self, qsize):
        # live zoom signal slot to resize dockwidget and dock areas
        self.setMinimumSize(qsize)
        self.main_win.resizeDocks([self], [qsize.width()], Qt.Horizontal)
        self.main_win.resizeDocks([self], [qsize.height()], Qt.Vertical)

    # hack to stop QDockWidget responding to drag events for undocking - work around for Qt bug
    def eventFilter(self, source, event):
        # event seq 2, 5, 3 - mouse press, mouse move, mouse release
        if event.type() == QEvent.MouseButtonPress:
            label = self.childAt(event.pos())
            if not label:
                return super(TDockWidget, self).eventFilter(source, event)
            if isinstance(label, QLabel):
                if not self.isFloating():
                    fake_mouse_event = QMouseEvent(QEvent.MouseButtonRelease, event.pos(), event.button(), event.buttons(), event.modifiers())
                    super(TDockWidget, self).event(fake_mouse_event)
                    return True
        return super(TDockWidget, self).eventFilter(source, event)
Example #9
0
class Register(QWidget):
    register_ok_sg = pyqtSignal()

    def __init__(self, parent=None):
        super(Register, self).__init__(parent)
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.h = self.screenRect.height()
        self.w = self.screenRect.width()
        self.xr = self.w / 930
        self.yr = self.h / 640
        self.zr = min(self.xr, self.yr)
        self.top_wi = QWidget(self)
        self.logo_la = QLabel(self.top_wi)
        self.ind_wi = QWidget(self)
        self.register_but = QPushButton(self.ind_wi)
        self.imp_la = QLabel(self.ind_wi)
        self.account_le = QLineEdit(self.ind_wi)
        self.psw_le = QLineEdit(self.ind_wi)
        self.name_le = QLineEdit(self.ind_wi)
        self.set_ui()
        with open('index.qss', 'r') as f:
            self.setStyleSheet(f.read())

    def set_ui(self):
        self.setWindowTitle('Register')
        self.setObjectName('register')
        self.resize(self.w, self.h)
        self.top_wi.setObjectName('top')
        self.top_wi.resize(930 * self.xr, 95 * self.yr)
        self.logo_la.setObjectName('logo')
        self.logo_la.resize(65 * self.xr, 65 * self.zr)
        self.logo_la.move(29 * self.xr, 16 * self.yr)
        effect = QGraphicsDropShadowEffect()
        effect.setOffset(10, 10)
        effect.setColor(QColor(0, 0, 0, 80))
        effect.setBlurRadius(20)
        self.ind_wi.setObjectName('login')
        self.ind_wi.resize(327 * self.xr, 388 * self.yr)
        self.ind_wi.move(300 * self.xr, 150 * self.yr)
        self.ind_wi.setGraphicsEffect(effect)
        self.register_but.setObjectName('button')
        self.register_but.move(64 * self.xr, 315 * self.yr)
        self.register_but.resize(202 * self.xr, 45 * self.yr)
        self.register_but.setText('注册新用户')
        self.register_but.clicked.connect(self.register)
        self.imp_la.setObjectName('imp_label')
        self.imp_la.resize(100 * self.zr, 100 * self.zr)
        self.imp_la.move(115 * self.xr + 100 * (self.xr - self.zr) / 2,
                         15 * self.yr)
        self.imp_la.setStyleSheet('border-radius:{}px;'.format(self.zr * 49))
        self.account_le.setObjectName('input')
        self.account_le.setTextMargins(20, 0, 0, 0)
        self.account_le.resize(213 * self.xr, 45 * self.yr)
        self.account_le.move(59 * self.xr, 126 * self.yr)
        self.account_le.setPlaceholderText('账号')
        self.psw_le.setObjectName('input')
        self.psw_le.setTextMargins(20, 0, 0, 0)
        self.psw_le.resize(213 * self.xr, 45 * self.yr)
        self.psw_le.move(59 * self.xr, 181 * self.yr)
        self.psw_le.setPlaceholderText('密码')
        self.psw_le.setEchoMode(QLineEdit.Password)
        self.name_le.setObjectName('input')
        self.name_le.setTextMargins(20, 0, 0, 0)
        self.name_le.resize(213 * self.xr, 45 * self.yr)
        self.name_le.move(59 * self.xr, 236 * self.yr)
        self.name_le.setPlaceholderText('昵称')
        self.ind_wi.setStyleSheet('#input{border-radius:' + str(self.zr * 20) +
                                  'px;}' + '#button{border-radius:' +
                                  str(self.zr * 20) + 'px;' + 'font-size:' +
                                  str(int(self.zr * 18)) + 'px;}')

    def register(self):
        account_p = self.account_le.text()
        psw_p = self.psw_le.text()
        # name_p = self.name_le.text()
        dic = register(account_p, psw_p)
        if dic['status'] == 1001:
            self.account_le.clear()
            self.psw_le.clear()
            self.account_le.setStyleSheet('border:4px solid;border-color:red;')
            self.account_le.setPlaceholderText('账号已存在')
        elif dic['status'] == 0:
            self.register_ok_sg.emit()
        else:
            self.account_le.clear()
            self.psw_le.clear()
            self.account_le.setStyleSheet('border:4px solid;border-color:red;')
            self.account_le.setPlaceholderText('未知错误')
Example #10
0
class Home(QWidget):
    home_exit_sg = pyqtSignal()
    rank_sg = pyqtSignal(list)
    single_rank_sg = pyqtSignal(list)

    def __init__(self, parent=None):
        super(Home, self).__init__(parent)
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.h = self.screenRect.height()
        self.w = self.screenRect.width()
        self.xr = self.w / 930
        self.yr = self.h / 640
        self.zr = min(self.xr, self.yr)
        self.id_p = 0
        self.token = ''
        self.vertical_img = QLabel(self)
        self.role_data_wi = QWidget(self)
        self.rankexit_but = QPushButton(self)
        self.role_header = QLabel(self.role_data_wi)
        self.role_name = QLabel(self.role_data_wi)
        self.role_rank = QPushButton(self.role_data_wi)
        self.ranking = QPushButton(self.role_data_wi)
        self.role_details = QWidget(self.role_data_wi)
        self.bigcard_la = QLabel(self.role_details)
        self.bigcard_wi = QWidget(self.role_details)
        self.rate_la = QLabel(self.role_details)
        self.rate_wi = QLabel(self.role_details)
        self.role_special = QLabel(self.bigcard_wi)
        self.set_ui()
        with open('home.qss', 'r') as f:
            self.setStyleSheet(f.read())

    def set_ui(self):
        self.setWindowTitle('Home')
        self.setObjectName('home')
        self.resize(self.w, self.h)
        effect = QGraphicsDropShadowEffect()
        effect.setOffset(10, 10)
        effect.setColor(QColor(0, 0, 0, 80))
        effect.setBlurRadius(20)
        self.vertical_img.setObjectName('vertical')
        self.vertical_img.resize(self.xr * 205, self.yr * 534)
        self.vertical_img.move(self.xr * 79, self.yr * 39)
        self.role_data_wi.setObjectName('role_data_wi')
        self.role_data_wi.resize(self.xr * 552, self.yr * 534)
        self.role_data_wi.move(self.xr * 320, self.yr * 39)
        self.role_data_wi.setGraphicsEffect(effect)
        self.rankexit_but.setObjectName('resexit')
        self.rankexit_but.resize(self.zr * 38, self.zr * 38)
        self.rankexit_but.move(self.xr * 852, self.yr * 22)
        self.rankexit_but.clicked.connect(self.home_exit)
        self.rankexit_but.setStyleSheet('border-radius:{}px;'.format(self.zr *
                                                                     18))
        self.role_header.setObjectName('role_header')
        self.role_header.resize(self.zr * 70, self.zr * 70)
        self.role_header.move(self.xr * 38, self.yr * 10)
        self.role_name.setObjectName('role_name')
        self.role_name.resize(self.xr * 129, self.yr * 43)
        self.role_name.move(self.xr * 129, self.yr * 21)
        self.role_name.setStyleSheet('border-radius:{}px;'.format(self.zr *
                                                                  18))
        effect1 = QGraphicsDropShadowEffect()
        effect1.setOffset(10, 10)
        effect1.setColor(QColor(0, 0, 0, 80))
        effect1.setBlurRadius(20)
        effect2 = QGraphicsDropShadowEffect()
        effect2.setOffset(10, 10)
        effect2.setColor(QColor(0, 0, 0, 80))
        effect2.setBlurRadius(20)
        self.role_rank.setObjectName('button')
        self.role_rank.resize(self.xr * 120, self.yr * 31)
        self.role_rank.move(self.xr * 269, self.yr * 27)
        self.role_rank.setText('个人战绩')
        self.role_rank.setGraphicsEffect(effect1)
        self.role_rank.clicked.connect(self.show_single_rank)
        self.ranking.setObjectName('button')
        self.ranking.resize(self.xr * 120, self.yr * 31)
        self.ranking.move(self.xr * 399, self.yr * 27)
        self.ranking.setText('排行榜')
        self.ranking.setGraphicsEffect(effect2)
        self.ranking.clicked.connect(self.show_rank)
        self.role_details.setObjectName('role_details')
        self.role_details.resize(self.xr * 500, self.yr * 435)
        self.role_details.move(self.xr * 28, self.yr * 89)
        self.bigcard_la.setObjectName('icon')
        self.bigcard_la.resize(self.xr * 120, self.yr * 23)
        self.bigcard_la.move(self.xr * 12, self.yr * 34)
        self.bigcard_la.setText('最近大牌')
        self.bigcard_la.setAlignment(Qt.AlignCenter)
        self.bigcard_wi.setObjectName('bigcard')
        self.bigcard_wi.resize(self.xr * 477, self.yr * 120)
        self.bigcard_wi.move(self.xr * 12, self.yr * 84)
        for i in range(1, 14):
            if i >= 9:
                xp = 330
                t = 9
            elif i >= 4:
                xp = 190
                t = 4
            else:
                xp = 90
                t = 1
            exec('self.role_card{}=QLabel(self.bigcard_wi)'.format(i))
            exec('self.role_card{}.setObjectName("card")'.format(i))
            exec('self.role_card{}.resize(self.xr*40,self.yr*60)'.format(i))
            exec('self.role_card{}.move(self.xr*(xp+({}-t)*20),self.yr*26)'.
                 format(i, i))
        self.role_special.setObjectName('role_special')
        self.role_special.resize(self.xr * 65, self.yr * 32)
        self.role_special.move(self.xr * 15, self.yr * 40)
        self.rate_la.setObjectName('icon')
        self.rate_la.resize(self.xr * 120, self.yr * 23)
        self.rate_la.move(self.xr * 12, self.yr * 234)
        self.rate_la.setText('近期趋势')
        self.rate_la.setAlignment(Qt.AlignCenter)
        self.rate_wi.setObjectName('rate')
        self.rate_wi.resize(self.xr * 477, self.yr * 120)
        self.rate_wi.move(self.xr * 12, self.yr * 284)
        self.role_data_wi.setStyleSheet('#role_data_wi{border-radius:' +
                                        str(self.zr * 20) +
                                        'px;}#role_header{border-radius:' +
                                        str(self.zr * 30) +
                                        'px;}#button{border-radius:' +
                                        str(self.zr * 15) + 'px;font-size:' +
                                        str(int(self.zr * 15)) +
                                        'px;}#icon{border-radius:' +
                                        str(self.zr * 10) + 'px;font-size:' +
                                        str(int(self.zr * 15)) + 'px;}')

    def home_exit(self):
        self.home_exit_sg.emit()

    def show_rank(self):
        res = rank()
        if res['status'] == 0:
            self.rank_sg.emit(res['details'])

    def show_single_rank(self):
        res = srank(self.id_p, self.token)
        if res['status'] == 0:
            self.single_rank_sg.emit(res['details'])

    def get_id(self, s):
        self.id_p = s

    def get_token(self, t):
        self.token = t