def __init__(self, parent, top, g_id, cover, nick): super().__init__(parent) self.top = top self.setProperty('class', 'the-room') self.setFixedSize(140, 150) self.g_id = g_id layer = CommonVBox() h_layer = CommonHBox() id_label = qt.QLabel(str(g_id), self) id_label.setAlignment(qt.Qt.AlignCenter) id_label.setProperty('class', 'id') cover_img = qt.QLabel(self) cover_img.setProperty('class', 'cover') cover_img.setFixedSize(66, 60) cover_img.setScaledContents(True) cover_img.setPixmap(qt.QPixmap(f'./static/avatar/{cover}.png')) join_btn = CommonBtn('加入', self) join_btn.clicked.connect(self.join_room) h_layer.addWidget(cover_img) nick_ = qt.QLabel(nick, self) nick_.setProperty('class', 'nick') nick_.setWordWrap(True) h_layer.addWidget(nick_) layer.addWidget(id_label, 0) layer.addLayout(h_layer, 2) layer.addWidget(join_btn, 0) self.setLayout(layer)
def __init__(self, p, top): super().__init__(p) self.top = top self.choose_color = config['color'] self.setProperty('class', 'set') layer = qt.QVBoxLayout() self.server_cfg = qt.QFrame(self) layer_1 = CommonHBox() layer_1.addWidget(qt.QLabel('服务器', self.server_cfg)) self.server_input = qt.QLineEdit(config['server'], self.server_cfg) layer_1.addWidget(self.server_input) self.server_cfg.setLayout(layer_1) self.color_cfg = qt.QFrame(self) layer_2 = CommonHBox() layer_2.addWidget(qt.QLabel('主题', self.server_cfg)) self.white = qt.QPushButton(self.color_cfg) self.white.clicked.connect(self.set_white) self.white.setProperty('class', 'white') self.dracula = qt.QPushButton(self.color_cfg) self.dracula.clicked.connect(self.set_dracula) self.dracula.setProperty('class', 'dracula') layer_2.addWidget(self.white) layer_2.addWidget(self.dracula) self.color_cfg.setLayout(layer_2) self.save_btn = CommonBtn('保存', self) self.save_btn.clicked.connect(self.save) layer.addWidget(self.server_cfg) layer.addWidget(self.color_cfg) layer.addWidget(self.save_btn) self.setLayout(layer)
def __init__(self, parent, top): super().__init__(parent) self.top = top self.setProperty('class', 'set-about') self.set_dialog = SetDialog(self, top) self.about_dialog = AboutDialog(self, top) layer = CommonHBox() self.set_btn = CommonBtn(chr(0xe002), self) self.set_btn.clicked.connect(self.set_dialog.exec) self.about_btn = CommonBtn(chr(0xe003), self) self.about_btn.clicked.connect(self.about_dialog.exec) layer.addStretch(0) layer.addWidget(self.set_btn, alignment=qt.Qt.AlignRight) layer.addWidget(self.about_btn, alignment=qt.Qt.AlignRight) self.setLayout(layer) self.set_qss.connect(self.do_set_qss) self.set_qss.emit()
def __init__(self, head, top): super().__init__(top) self.head = head self.top = top self.setProperty('class', 'game-head-dialog') self.at = 'c' # 等待创建,为取消做标志物 self.creating = False self.join_id = None layer = CommonVBox() self.create_frm = qt.QFrame(self) create_layer = CommonVBox() self.create_state = qt.QLabel('创建中...', self.create_frm) self.cancel_create = CommonBtn('取消', self.create_frm) self.cancel_create.clicked.connect(self.close) create_layer.addWidget(self.create_state) create_layer.addWidget(self.cancel_create) self.create_frm.setLayout(create_layer) self.join_frm = qt.QFrame(self) join_layer = CommonVBox() self.join_state = qt.QLabel('输入房间号(数字)', self.join_frm) self.join_input = qt.QLineEdit(self.join_frm) self.join_btn = CommonBtn('查询', self.join_frm) self.join_btn.clicked.connect(self.do_join) join_layer.addWidget(self.join_state) join_layer.addWidget(self.join_input) join_layer.addWidget(self.join_btn) self.join_frm.setLayout(join_layer) layer.addWidget(self.create_frm) layer.addWidget(self.join_frm) self.setLayout(layer) self.search_signal.connect(self.search_result)
def init_page(self, page_count): while self.layer.count(): self.layer.itemAt(0).widget().setParent(None) self.btn_lis.clear() for i in range(1, page_count + 1): btn = CommonBtn(str(i), self) btn.setFixedSize(46, 36) btn.clicked.connect(self.click_page_btn) if i == 1: btn.setProperty('class', 'active') self.btn_lis.append(btn) self.layer.addWidget(btn) self.top.set_qss.emit()
def __init__(self, parent, top): super().__init__(top) self.parent = parent self.top = top self.i = 0 self.setWindowTitle('选择头像') self.setObjectName('choose-avatar') layer = qt.QGridLayout() lis = listdir('./static/avatar/') self.avatar_lis = [] for i in range(len(lis) - 1): avatar = CommonBtn(self) avatar.i = i + 1 avatar.setProperty('class', 'avatar') avatar.setFixedSize(74, 74) avatar.setIcon(qt.QIcon(f'./static/avatar/{i+1}.png')) avatar.setIconSize(qt.QSize(70, 70)) avatar.clicked.connect(self.click_avatar) self.avatar_lis.append(avatar) layer.addWidget(avatar, i // 4, i % 4) self.setLayout(layer)
class HeadDialog(CommonDialog): search_signal = qt.pyqtSignal(dict, int) def __init__(self, head, top): super().__init__(top) self.head = head self.top = top self.setProperty('class', 'game-head-dialog') self.at = 'c' # 等待创建,为取消做标志物 self.creating = False self.join_id = None layer = CommonVBox() self.create_frm = qt.QFrame(self) create_layer = CommonVBox() self.create_state = qt.QLabel('创建中...', self.create_frm) self.cancel_create = CommonBtn('取消', self.create_frm) self.cancel_create.clicked.connect(self.close) create_layer.addWidget(self.create_state) create_layer.addWidget(self.cancel_create) self.create_frm.setLayout(create_layer) self.join_frm = qt.QFrame(self) join_layer = CommonVBox() self.join_state = qt.QLabel('输入房间号(数字)', self.join_frm) self.join_input = qt.QLineEdit(self.join_frm) self.join_btn = CommonBtn('查询', self.join_frm) self.join_btn.clicked.connect(self.do_join) join_layer.addWidget(self.join_state) join_layer.addWidget(self.join_input) join_layer.addWidget(self.join_btn) self.join_frm.setLayout(join_layer) layer.addWidget(self.create_frm) layer.addWidget(self.join_frm) self.setLayout(layer) self.search_signal.connect(self.search_result) def closeEvent(self, e): if self.at == 'c': # 终止等待玩家加入 AsyncRequest(self.top, url='/del_room', data={}).start() else: self.join_id = None def show_create(self): self.at = 'c' self.creating = True self.create_frm.show() self.join_frm.hide() self.top.game_frm.run_game('create') self.exec() def show_join(self): self.at = 'j' self.join_state.setText('输入房间号(数字)') self.join_btn.setText('查询') self.join_btn.setEnabled(True) self.create_frm.hide() self.join_frm.show() self.exec() def do_join(self): self.join_btn.setEnabled(False) if self.join_btn.text() == '查询': room_id = self.join_input.text() if match('^[0-9]+$', room_id): self.join_id = room_id self.join_btn.setText('查询中') AsyncRequest(self.top, url='/search_room', data={ 'id': room_id }, signal=self.search_signal).start() else: self.join_state.setText('房间号为数字!') self.join_btn.setEnabled(True) elif self.join_btn.text() == '加入': self.top.game_frm.run_game(self.join_id) def search_result(self, dic, req_id): if self.join_id: self.join_btn.setEnabled(True) if dic['state'] == 'suc': state = '找到房间' self.top.game_frm.footer_frm.p2.preserve_info(dic['data']) btn = '加入' else: btn = '查询' if dic['state'] == 'warn': state = '未找到房间!' else: state = '错误:' + dic['data'] self.join_state.setText(state) self.join_btn.setText(btn)