def on_navigate(self, page=1, direction=0): try: if self.cooldown_page: self.status.setText("You have to wait " + str(self.cooldown_time_page / 1000) + " second(s) before switching pages!") palette = QPalette() palette.setColor(QPalette.Foreground, Qt.red) self.status.setPalette(palette) return if direction == 2: self.page += page elif direction == 1: self.page -= page else: self.page = page self.listServers() if not self.cooldown: self.cooldown_page = True self.previous.setEnabled(False) self.next.setEnabled(False) self.first.setEnabled(False) self.last.setEnabled(False) QTimer.singleShot(self.cooldown_time_page, self.disable_cooldown_page) except: ts3.logMessage(traceback.format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "PyTSon", 0)
def listServers(self): if self.cooldown: self.status.setText("You have to wait "+str(self.cooldown_time/1000)+" second(s) before retrying!") palette = QPalette() palette.setColor(QPalette.Foreground,Qt.red) self.status.setPalette(palette) return url = self.setupURL() self.requestServers(url)
def requestServers(self, url): if self.serverBrowser.config["GENERAL"]["debug"] == "True": self.requests += 1 ts3.printMessageToCurrentTab("Request: " + str(self.requests)) servers = requests.get(url) self.status.setText("Response from \"" + self.serverBrowser.config['GENERAL']['api'] + "\": " + str(servers.status_code) + ": " + servers.reason) palette = QPalette() if not servers.status_code == 200: palette.setColor(QPalette.Foreground, Qt.red) self.status.setPalette(palette) _servers = servers.content.decode('utf-8') __servers = json.loads(_servers) return __servers
def on_pageLabel_clicked(self, event): try: page = QInputDialog.getInt(self, "Goto Page", "Page:") if page > 0: if self.cooldown_page: self.status.setText("You have to wait "+str(self.cooldown_time_page/1000)+" second(s) before switching pages!") palette = QPalette() palette.setColor(QPalette.Foreground,Qt.red) self.status.setPalette(palette) return self.page = page self.listServers() if not self.cooldown: self.cooldown_page = True self.previous.setEnabled(False) self.next.setEnabled(False) QTimer.singleShot(self.cooldown_time_page, self.disable_cooldown_page) except: ts3.logMessage(traceback.format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def requestCountries(self): countries = requests.get(self.serverBrowser.config['GENERAL']['api'] + "servercountries") self.status.setText("Response from \"" + self.serverBrowser.config['GENERAL']['api'] + "\": " + str(countries.status_code) + ": " + countries.reason) palette = QPalette() if countries.status_code == 200: palette.setColor(QPalette.Foreground, Qt.darkGreen) self.countryBox.clear() else: palette.setColor(QPalette.Foreground, Qt.red) self.status.setPalette(palette) countries = countries.content.decode('utf-8') countries = json.loads(countries)["result"]["data"] y = sum(x[2] for x in countries) #y = 0 #for x in countries: # y = y + x[2] #ts3.printMessageToCurrentTab(str(countries)) if "-" in [h[0] for h in countries]: countries = countries[0:1] + sorted(countries[1:], key=lambda x: x[1]) else: countries = sorted(countries, key=lambda x: x[1]) self.countries = [['ALL', 'All', y]] + countries
def onCountryListReply(self, reply): try: _api = self.serverBrowser.config['GENERAL']['api'] _reply = reply.readAll() countries = json.loads(_reply.data().decode('utf-8'))["result"]["data"] ts3.printMessageToCurrentTab("%s"%countries) _reason = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) self.status.setText("Response from \"{0}\": {1}: {2}".format(_api, _reason, reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute))) palette = QPalette() if _reason == 200: palette.setColor(QPalette.Foreground,Qt.darkGreen) self.countryBox.clear() else: palette.setColor(QPalette.Foreground,Qt.red) self.status.setPalette(palette) y= sum(x[2] for x in countries) #y = 0 #for x in countries: # y = y + x[2] #ts3.printMessageToCurrentTab(str(countries)) if "-" in [h[0] for h in countries]: countries = countries[0:1]+sorted(countries[1:],key=lambda x: x[1]) else: countries = sorted(countries,key=lambda x: x[1]) self.countries = [['ALL', 'All', y]]+countries #if self.serverBrowser.config['GENERAL']['morerequests'] == "True": #self.countryBox.addItems([x[1]+" ("+str(x[2])+")" for x in self.countries]) #else: self.countryBox.addItems([x[1] for x in self.countries]) #__countries = __countries.__add__([['ALL', 'All', 0]]) except: ts3.logMessage(traceback.format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def listServers(self): if self.cooldown: self.status.setText("You have to wait " + str(self.cooldown_time / 1000) + " second(s) before retrying!") palette = QPalette() palette.setColor(QPalette.Foreground, Qt.red) self.status.setPalette(palette) return url = self.setupURL() servers = self.requestServers(url) self.status.setText("Status: " + servers["status"].title()) if servers["status"] == "success": self.pages = servers["result"]["pagestotal"] self.pageLabel.setText( str(servers["result"]["pageactive"]) + " / " + str(servers["result"]["pagestotal"])) self.pageLabel.updateGeometry() self.info.setText( str(servers["result"]["itemsshown"]) + " / " + str(servers["result"]["itemstotal"]) + " Servers shown.") self.serverList.setRowCount(0) elif servers["status"] == "error": self.info.setText("Requested Page: " + str(self.page)) self.status.setText(servers["status"].title() + ": " + servers["result"]["message"] + " (" + str(servers["result"]["code"]) + ")") palette = QPalette() palette.setColor(QPalette.Foreground, Qt.red) self.status.setPalette(palette) return else: self.info.setText("Requested Page: " + str(self.page)) palette = QPalette() palette.setColor(QPalette.Foreground, Qt.red) self.status.setPalette(palette) return _list = self.serverList _filters = self.serverBrowser.config["FILTERS"] if servers["result"]["pageactive"] == 1: self.previous.setEnabled(False) else: self.previous.setEnabled(True) if servers["result"]["pageactive"] == servers["result"]["pagestotal"]: self.next.setEnabled(False) else: self.next.setEnabled(True) for key in servers["result"]["data"]: if self.buhl( _filters["hideFull"]) and key["users"] >= key["slots"]: continue elif self.buhl(_filters["hideEmpty"]) and key["users"] <= 0: continue else: print("%s" % key) rowPosition = _list.rowCount _list.insertRow(rowPosition) # if key['premium']: # _list.setItem(rowPosition, 0, QTableWidgetItem("Yes")) # else: # _list.setItem(rowPosition, 0, QTableWidgetItem("No")) _list.setItem(rowPosition, 0, QTableWidgetItem(key['name'])) _list.setItem( rowPosition, 1, QTableWidgetItem( str(key['users']) + ' / ' + str(key['slots']))) if key['users'] >= key['slots']: palette = QPalette() palette.setColor(QPalette.Foreground, Qt.red) _list.setPalette(palette) _list.setItem( rowPosition, 2, QTableWidgetItem(self.getCountryNamebyID(key['country']))) if key['createchannels']: _list.setItem(rowPosition, 3, QTableWidgetItem("Yes")) else: _list.setItem(rowPosition, 3, QTableWidgetItem("No")) if key['password']: _list.setItem(rowPosition, 4, QTableWidgetItem("Yes")) else: _list.setItem(rowPosition, 4, QTableWidgetItem("No"))
def serversReply(self, reply): try: _api = self.serverBrowser.config['GENERAL']['api'] _reason = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) _reply = reply.readAll() servers = json.loads(_reply.data().decode('utf-8')) ts3.printMessageToCurrentTab("servers: %s"%servers) self.status.setText("Response from \"{0}\": {1}: {2}".format(_api, _reason, reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute))) palette = QPalette() if not _reason == 200: palette.setColor(QPalette.Foreground,Qt.red) self.status.setPalette(palette) self.status.setText("Status: %s"%reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute)) if servers["status"] == "success": self.pages = servers["result"]["pagestotal"] self.pageLabel.setText(str(servers["result"]["pageactive"])+" / "+str(servers["result"]["pagestotal"])) self.pageLabel.updateGeometry() self.info.setText(str(servers["result"]["itemsshown"])+" / "+str(servers["result"]["itemstotal"])+" Servers shown.") self.serverList.setRowCount(0) elif servers["status"] == "error": self.info.setText("Requested Page: "+str(self.page)) self.status.setText(servers["status"].title()+": "+servers["result"]["message"]+" ("+str(servers["result"]["code"])+")") palette = QPalette() palette.setColor(QPalette.Foreground,Qt.red) self.status.setPalette(palette) return else: self.info.setText("Requested Page: "+str(self.page)) palette = QPalette() palette.setColor(QPalette.Foreground,Qt.red) self.status.setPalette(palette) return _list = self.serverList _filters = self.serverBrowser.config["FILTERS"] if servers["result"]["pageactive"] == 1: self.previous.setEnabled(False) else: self.previous.setEnabled(True) if servers["result"]["pageactive"] == servers["result"]["pagestotal"]: self.next.setEnabled(False) else: self.next.setEnabled(True) for key in servers["result"]["data"]: if self.buhl(_filters["hideFull"]) and key["users"] >= key["slots"]: continue elif self.buhl(_filters["hideEmpty"]) and key["users"] <= 0: continue else: rowPosition = _list.rowCount _list.insertRow(rowPosition) # if key['premium']: # _list.setItem(rowPosition, 0, QTableWidgetItem("Yes")) # else: # _list.setItem(rowPosition, 0, QTableWidgetItem("No")) _list.setItem(rowPosition, 0, QTableWidgetItem(key['name'])) _list.setItem(rowPosition, 1, QTableWidgetItem(str(key['users'])+' / '+str(key['slots']))) if key['users'] >= key['slots']: palette = QPalette() palette.setColor(QPalette.Foreground,Qt.red) _list.setPalette(palette) _list.setItem(rowPosition, 2, QTableWidgetItem(self.getCountryNamebyID(key['country']))) if key['createchannels']: _list.setItem(rowPosition, 3, QTableWidgetItem("Yes")) else: _list.setItem(rowPosition, 3, QTableWidgetItem("No")) if key['password']: _list.setItem(rowPosition, 4, QTableWidgetItem("Yes")) else: _list.setItem(rowPosition, 4, QTableWidgetItem("No")) #item.setData(Qt.UserRole, key['ip']); _list.setAlternatingRowColors(True) _list.styleSheet = "alternate-background-color: grey;" _list.setStyleSheet("alternate-background-color: grey;") except: ts3.logMessage(traceback.format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)