def processing(self): while not self.shutdown: time.sleep(0.1) self.process() if self.status() == netstream.NET_STATE_ESTABLISHED: while True: data = self.recv() if data: if data == 'hb': logging.debug("--------hb recv--------") self.hbTimeoutCount = 0 self.hbTimer = time.time() self.send('hb') continue logging.debug('recv' + data) response = json.loads(data) if 'sid' in response and 'cid' in response: sid = response['sid'] cid = response['cid'] callbackKey = '%d_%d' % (sid, cid) try: callback = self.callbacksDict[callbackKey] callback(response, data) except: logging.warning('callback err ' + callbackKey) elif self.status() == netstream.NET_STATE_STOP: game_user_manager.GameUserManager().emit(SIGNAL("showLogin"))
def __init__(self, parent=None): QWidget.__init__(self, parent) # network manager self.client = network_client.TcpClient() self.loginManager = game_user_manager.GameUserManager() self.gameRoomManager = game_room_manager.GameRoomManager() self.connect(self.loginManager, SIGNAL("loginCallback(int, int)"), self.loginCallback) self.connect(self.gameRoomManager, SIGNAL("enterRoom"), self.enterRoom) self.connect(self.loginManager, SIGNAL("showLogin"), self.showLogin) # data source self.tableList = [] # ui self.resize(800, 600) self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowMinMaxButtonsHint) self.setAttribute(Qt.WA_TranslucentBackground) self.topbarFrame = game_topbar_frame.GameTopBar(self, self) self.mainFrame = game_hall_main_frame.GameHallMain(self) self.roomWindow = None #dialog self.loginDialog = login_dialog.LoginDialog(self) self.connect(self.loginDialog, SIGNAL("close"), self.loginDialogClose) self.connect(self.loginDialog, SIGNAL("login(QString,int,QString)"), self.login) self.loginDialog.open() self.resultDailog = QMessageBox(self)
def __init__(self, parent=None): QFrame.__init__(self, parent) self.parent = parent self.setStyleSheet("GameRoomUserInfo{background-color: rgba(0, 0, 0, 0)}") self.setGeometry(530, 20, 255, 50) self.roomManager = game_room_manager.GameRoomManager() self.loginManager = game_user_manager.GameUserManager() self.connect(self.roomManager, SIGNAL('refreshRoom'), self.refreshData) self.setup() self.refreshData()
def hbLoop(self): while True: t = time.time() if t - self.hbTimer > 20: logging.debug('--------hb timeout--------') self.hbTimeoutCount += 1 self.hbTimer = t if self.hbTimeoutCount > 3: logging.debug('--------hb close--------') self.close() game_user_manager.GameUserManager().emit(SIGNAL("showLogin")) break
def refresh(self): self.model.clear() rank = 0 for user in game_user_manager.GameUserManager().userScore: if 'uid' in user and 'score' in user: text = user['uid'] + ' : ' + str(user['score']) item = QStandardItem(text) item.setTextAlignment(Qt.AlignCenter) item.setFont(QFont(50)) if rank == 0: item.setForeground(QBrush(QColor(255, 0, 0))) if rank == 1: item.setForeground(QBrush(QColor(200, 0, 0))) if rank == 2: item.setForeground(QBrush(QColor(150, 0, 0))) self.model.appendRow(item) rank += 1
def __init__(self, parent=None): QFrame.__init__(self, parent) self.parent = parent self.setStyleSheet( ''' GameHallMain{ border-image: url(:background); background-repeat: no-repeat; } ''') self.setGeometry(0, 67, 800, 533) self.roomGird = game_hall_room_gird.GameHallRoomGird(self) self.roomGird.setGeometry(40, 40, 550, 450) self.rankTitle = QLabel(self) self.rankTitle.setText(u'排行榜') self.rankTitle.setStyleSheet(_fromUtf8("font: 75 14pt \"微软雅黑\";\n" "color: rgb(100, 100, 200);")) self.rankTitle.setAlignment(Qt.AlignCenter) self.rankTitle.setGeometry(600, 20, 190, 20) self.rankList = game_hall_rank_list.GameHallRankList(self) self.rankList.setGeometry(600, 55, 190, 180) self.chatView = game_chat_view.GameChatView(self) self.chatView.setStyleSheet( ''' border-image: url(:btn_bg); background-repeat: no-repeat; ''') self.chatView.setGeometry(600, 250, 190, 220) self.chatToolBar = game_chat_tool_bar.GameChatToolBar(self) self.chatToolBar.setGeometry(600, 480, 190, 30) self.chatToolBar.updateLayout() self.chatView.connect(game_user_manager.GameUserManager(), SIGNAL( "showHallTextWithRGB(QString,int,int,int)"), self.chatView.showText)
def __init__(self, parent=None): QListView.__init__(self, parent) self.setStyleSheet( ''' border-image: url(:btn_bg); background-repeat: no-repeat; ''') self.model = QStandardItemModel() self.setModel(self.model) self.setWordWrap(True) self.setUniformItemSizes(True) self.setGridSize(QSize(self.rect().width(), 30)) self.setFont(QFont("Microsoft YaHei", 10)) self.setEditTriggers(QAbstractItemView.NoEditTriggers) self.setFocusPolicy(Qt.NoFocus) self.setSelectionMode(QAbstractItemView.NoSelection) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setAcceptDrops(True) self.connect(game_user_manager.GameUserManager(), SIGNAL("refreshRank"), self.refresh)
def sendText(self, s): game_user_manager.GameUserManager().chat(s)