diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index c373e459..6740c7cf 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -632,14 +632,6 @@ class MyForm(settingsmixin.SMainWindow): # startup for linux pass - - self.totalNumberOfBytesReceived = 0 - self.totalNumberOfBytesSent = 0 - - self.timer = QtCore.QTimer() - self.timer.start(2000) # milliseconds - QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.runEveryTwoSeconds) - # e.g. for editing labels self.recurDepth = 0 @@ -739,8 +731,6 @@ class MyForm(settingsmixin.SMainWindow): QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL( "clicked()"), self.click_pushButtonStatusIcon) - self.ui.labelStartupTime.setText(_translate("MainWindow", "Since startup on %1").arg( - l10n.formatTimestamp())) self.numberOfMessagesProcessed = 0 self.numberOfBroadcastsProcessed = 0 self.numberOfPubkeysProcessed = 0 @@ -755,7 +745,7 @@ class MyForm(settingsmixin.SMainWindow): self.ui.tableWidgetAddressBook.setIconSize(QtCore.QSize(identicon_size, identicon_size)) self.ui.tableWidgetBlacklist.setIconSize(QtCore.QSize(identicon_size, identicon_size)) - self.UISignalThread = UISignaler() + self.UISignalThread = UISignaler.get() QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( "writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.writeNewAddressToTable) QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( @@ -768,14 +758,6 @@ class MyForm(settingsmixin.SMainWindow): "displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayNewInboxMessage) QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( "displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayNewSentMessage) - QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( - "updateNetworkStatusTab()"), self.updateNetworkStatusTab) - QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( - "updateNumberOfMessagesProcessed()"), self.updateNumberOfMessagesProcessed) - QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( - "updateNumberOfPubkeysProcessed()"), self.updateNumberOfPubkeysProcessed) - QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( - "updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed) QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( "setStatusIcon(PyQt_PyObject)"), self.setStatusIcon) QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( @@ -1719,21 +1701,6 @@ class MyForm(settingsmixin.SMainWindow): self.actionShow.setChecked(not self.actionShow.isChecked()) self.appIndicatorShowOrHideWindow() - def updateNumberOfMessagesProcessed(self): - self.ui.labelSyncStatus.setText(_translate("MainWindow", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) - self.ui.labelMessageCount.setText(_translate( - "MainWindow", "Processed %1 person-to-person messages.").arg(str(shared.numberOfMessagesProcessed))) - - def updateNumberOfBroadcastsProcessed(self): - self.ui.labelSyncStatus.setText(_translate("MainWindow", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) - self.ui.labelBroadcastCount.setText(_translate( - "MainWindow", "Processed %1 broadcast messages.").arg(str(shared.numberOfBroadcastsProcessed))) - - def updateNumberOfPubkeysProcessed(self): - self.ui.labelSyncStatus.setText(_translate("MainWindow", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) - self.ui.labelPubkeyCount.setText(_translate( - "MainWindow", "Processed %1 public keys.").arg(str(shared.numberOfPubkeysProcessed))) - def formatBytes(self, num): for x in ['bytes','KB','MB','GB']: if num < 1000.0: @@ -1745,74 +1712,6 @@ class MyForm(settingsmixin.SMainWindow): num /= 1000 return "%4.0f KB" % num - def updateNumberOfBytes(self): - """ - This function is run every two seconds, so we divide the rate of bytes - sent and received by 2. - """ - self.ui.labelBytesRecvCount.setText(_translate( - "MainWindow", "Down: %1/s Total: %2").arg(self.formatByteRate(shared.numberOfBytesReceived/2), self.formatBytes(self.totalNumberOfBytesReceived))) - self.ui.labelBytesSentCount.setText(_translate( - "MainWindow", "Up: %1/s Total: %2").arg(self.formatByteRate(shared.numberOfBytesSent/2), self.formatBytes(self.totalNumberOfBytesSent))) - self.totalNumberOfBytesReceived += shared.numberOfBytesReceived - self.totalNumberOfBytesSent += shared.numberOfBytesSent - shared.numberOfBytesReceived = 0 - shared.numberOfBytesSent = 0 - - def updateNetworkStatusTab(self): - totalNumberOfConnectionsFromAllStreams = 0 # One would think we could use len(sendDataQueues) for this but the number doesn't always match: just because we have a sendDataThread running doesn't mean that the connection has been fully established (with the exchange of version messages). - streamNumberTotals = {} - for host, streamNumber in shared.connectedHostsList.items(): - if not streamNumber in streamNumberTotals: - streamNumberTotals[streamNumber] = 1 - else: - streamNumberTotals[streamNumber] += 1 - - while self.ui.tableWidgetConnectionCount.rowCount() > 0: - self.ui.tableWidgetConnectionCount.removeRow(0) - for streamNumber, connectionCount in streamNumberTotals.items(): - self.ui.tableWidgetConnectionCount.insertRow(0) - if streamNumber == 0: - newItem = QtGui.QTableWidgetItem("?") - else: - newItem = QtGui.QTableWidgetItem(str(streamNumber)) - newItem.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - self.ui.tableWidgetConnectionCount.setItem(0, 0, newItem) - newItem = QtGui.QTableWidgetItem(str(connectionCount)) - newItem.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - self.ui.tableWidgetConnectionCount.setItem(0, 1, newItem) - """for currentRow in range(self.ui.tableWidgetConnectionCount.rowCount()): - rowStreamNumber = int(self.ui.tableWidgetConnectionCount.item(currentRow,0).text()) - if streamNumber == rowStreamNumber: - foundTheRowThatNeedsUpdating = True - self.ui.tableWidgetConnectionCount.item(currentRow,1).setText(str(connectionCount)) - #totalNumberOfConnectionsFromAllStreams += connectionCount - if foundTheRowThatNeedsUpdating == False: - #Add a line to the table for this stream number and update its count with the current connection count. - self.ui.tableWidgetConnectionCount.insertRow(0) - newItem = QtGui.QTableWidgetItem(str(streamNumber)) - newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) - self.ui.tableWidgetConnectionCount.setItem(0,0,newItem) - newItem = QtGui.QTableWidgetItem(str(connectionCount)) - newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) - self.ui.tableWidgetConnectionCount.setItem(0,1,newItem) - totalNumberOfConnectionsFromAllStreams += connectionCount""" - self.ui.labelTotalConnections.setText(_translate( - "MainWindow", "Total Connections: %1").arg(str(len(shared.connectedHostsList)))) - if len(shared.connectedHostsList) > 0 and shared.statusIconColor == 'red': # FYI: The 'singlelistener' thread sets the icon color to green when it receives an incoming connection, meaning that the user's firewall is configured correctly. - self.setStatusIcon('yellow') - elif len(shared.connectedHostsList) == 0: - self.setStatusIcon('red') - - # timer driven - def runEveryTwoSeconds(self): - self.ui.labelLookupsPerSecond.setText(_translate( - "MainWindow", "Inventory lookups per second: %1").arg(str(shared.numberOfInventoryLookupsPerformed/2))) - shared.numberOfInventoryLookupsPerformed = 0 - self.updateNumberOfBytes() - # Indicates whether or not there is a connection to the Bitmessage network connected = False @@ -4631,70 +4530,7 @@ class myTableWidgetItem(QTableWidgetItem): def __lt__(self, other): return int(self.data(33).toPyObject()) < int(other.data(33).toPyObject()) -class UISignaler(QThread): - - def __init__(self, parent=None): - QThread.__init__(self, parent) - - def run(self): - while True: - command, data = shared.UISignalQueue.get() - if command == 'writeNewAddressToTable': - label, address, streamNumber = data - self.emit(SIGNAL( - "writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), label, address, str(streamNumber)) - elif command == 'updateStatusBar': - self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"), data) - elif command == 'updateSentItemStatusByToAddress': - toAddress, message = data - self.emit(SIGNAL( - "updateSentItemStatusByToAddress(PyQt_PyObject,PyQt_PyObject)"), toAddress, message) - elif command == 'updateSentItemStatusByAckdata': - ackData, message = data - self.emit(SIGNAL( - "updateSentItemStatusByAckdata(PyQt_PyObject,PyQt_PyObject)"), ackData, message) - elif command == 'displayNewInboxMessage': - inventoryHash, toAddress, fromAddress, subject, body = data - self.emit(SIGNAL( - "displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), - inventoryHash, toAddress, fromAddress, subject, body) - elif command == 'displayNewSentMessage': - toAddress, fromLabel, fromAddress, subject, message, ackdata = data - self.emit(SIGNAL( - "displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), - toAddress, fromLabel, fromAddress, subject, message, ackdata) - elif command == 'updateNetworkStatusTab': - self.emit(SIGNAL("updateNetworkStatusTab()")) - elif command == 'updateNumberOfMessagesProcessed': - self.emit(SIGNAL("updateNumberOfMessagesProcessed()")) - elif command == 'updateNumberOfPubkeysProcessed': - self.emit(SIGNAL("updateNumberOfPubkeysProcessed()")) - elif command == 'updateNumberOfBroadcastsProcessed': - self.emit(SIGNAL("updateNumberOfBroadcastsProcessed()")) - elif command == 'setStatusIcon': - self.emit(SIGNAL("setStatusIcon(PyQt_PyObject)"), data) - elif command == 'changedInboxUnread': - self.emit(SIGNAL("changedInboxUnread(PyQt_PyObject)"), data) - elif command == 'rerenderMessagelistFromLabels': - self.emit(SIGNAL("rerenderMessagelistFromLabels()")) - elif command == 'rerenderMessagelistToLabels': - self.emit(SIGNAL("rerenderMessagelistToLabels()")) - elif command == 'rerenderAddressBook': - self.emit(SIGNAL("rerenderAddressBook()")) - elif command == 'rerenderSubscriptions': - self.emit(SIGNAL("rerenderSubscriptions()")) - elif command == 'rerenderBlackWhiteList': - self.emit(SIGNAL("rerenderBlackWhiteList()")) - elif command == 'removeInboxRowByMsgid': - self.emit(SIGNAL("removeInboxRowByMsgid(PyQt_PyObject)"), data) - elif command == 'newVersionAvailable': - self.emit(SIGNAL("newVersionAvailable(PyQt_PyObject)"), data) - elif command == 'alert': - title, text, exitAfterUserClicksOk = data - self.emit(SIGNAL("displayAlert(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"), title, text, exitAfterUserClicksOk) - else: - sys.stderr.write( - 'Command sent to UISignaler not recognized: %s\n' % command) +from uisignaler import UISignaler app = None diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index 355cc51b..63b10e3c 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -11,6 +11,7 @@ from PyQt4 import QtCore, QtGui from messageview import MessageView from messagecompose import MessageCompose import settingsmixin +from networkstatus import NetworkStatus try: _fromUtf8 = QtCore.QString.fromUtf8 @@ -587,67 +588,8 @@ class Ui_MainWindow(object): icon9 = QtGui.QIcon() icon9.addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/blacklist.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabWidget.addTab(self.blackwhitelist, icon9, _fromUtf8("")) - self.networkstatus = QtGui.QWidget() - self.networkstatus.setObjectName(_fromUtf8("networkstatus")) - self.tableWidgetConnectionCount = settingsmixin.STableWidget(self.networkstatus) - self.tableWidgetConnectionCount.setGeometry(QtCore.QRect(20, 70, 241, 241)) - palette = QtGui.QPalette() - brush = QtGui.QBrush(QtGui.QColor(212, 208, 200)) - brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) - brush = QtGui.QBrush(QtGui.QColor(212, 208, 200)) - brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) - brush = QtGui.QBrush(QtGui.QColor(212, 208, 200)) - brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) - self.tableWidgetConnectionCount.setPalette(palette) - self.tableWidgetConnectionCount.setFrameShape(QtGui.QFrame.Box) - self.tableWidgetConnectionCount.setFrameShadow(QtGui.QFrame.Plain) - self.tableWidgetConnectionCount.setProperty("showDropIndicator", False) - self.tableWidgetConnectionCount.setAlternatingRowColors(True) - self.tableWidgetConnectionCount.setSelectionMode(QtGui.QAbstractItemView.NoSelection) - self.tableWidgetConnectionCount.setObjectName(_fromUtf8("tableWidgetConnectionCount")) - self.tableWidgetConnectionCount.setColumnCount(2) - self.tableWidgetConnectionCount.setRowCount(0) - item = QtGui.QTableWidgetItem() - self.tableWidgetConnectionCount.setHorizontalHeaderItem(0, item) - item = QtGui.QTableWidgetItem() - self.tableWidgetConnectionCount.setHorizontalHeaderItem(1, item) - self.tableWidgetConnectionCount.horizontalHeader().setCascadingSectionResizes(True) - self.tableWidgetConnectionCount.horizontalHeader().setHighlightSections(False) - self.tableWidgetConnectionCount.horizontalHeader().setStretchLastSection(True) - self.tableWidgetConnectionCount.verticalHeader().setVisible(False) - self.labelTotalConnections = QtGui.QLabel(self.networkstatus) - self.labelTotalConnections.setGeometry(QtCore.QRect(20, 30, 401, 16)) - self.labelTotalConnections.setObjectName(_fromUtf8("labelTotalConnections")) - self.labelStartupTime = QtGui.QLabel(self.networkstatus) - self.labelStartupTime.setGeometry(QtCore.QRect(320, 110, 331, 20)) - self.labelStartupTime.setObjectName(_fromUtf8("labelStartupTime")) - self.labelMessageCount = QtGui.QLabel(self.networkstatus) - self.labelMessageCount.setGeometry(QtCore.QRect(350, 130, 361, 16)) - self.labelMessageCount.setObjectName(_fromUtf8("labelMessageCount")) - self.labelPubkeyCount = QtGui.QLabel(self.networkstatus) - self.labelPubkeyCount.setGeometry(QtCore.QRect(350, 170, 331, 16)) - self.labelPubkeyCount.setObjectName(_fromUtf8("labelPubkeyCount")) - self.labelBroadcastCount = QtGui.QLabel(self.networkstatus) - self.labelBroadcastCount.setGeometry(QtCore.QRect(350, 150, 351, 16)) - self.labelBroadcastCount.setObjectName(_fromUtf8("labelBroadcastCount")) - self.labelSyncStatus = QtGui.QLabel(self.networkstatus) - self.labelSyncStatus.setGeometry(QtCore.QRect(350, 190, 331, 20)) - self.labelSyncStatus.setObjectName(_fromUtf8("labelSyncStatus")) - self.labelLookupsPerSecond = QtGui.QLabel(self.networkstatus) - self.labelLookupsPerSecond.setGeometry(QtCore.QRect(320, 270, 291, 16)) - self.labelLookupsPerSecond.setObjectName(_fromUtf8("labelLookupsPerSecond")) - self.labelBytesRecvCount = QtGui.QLabel(self.networkstatus) - self.labelBytesRecvCount.setGeometry(QtCore.QRect(350, 230, 251, 16)) - self.labelBytesRecvCount.setObjectName(_fromUtf8("labelBytesRecvCount")) - self.labelBytesSentCount = QtGui.QLabel(self.networkstatus) - self.labelBytesSentCount.setGeometry(QtCore.QRect(350, 250, 251, 16)) - self.labelBytesSentCount.setObjectName(_fromUtf8("labelBytesSentCount")) - icon11 = QtGui.QIcon() - icon11.addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/networkstatus.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.tabWidget.addTab(self.networkstatus, icon11, _fromUtf8("")) + self.networkstatus = NetworkStatus() + self.tabWidget.addTab(self.networkstatus, QtGui.QIcon(":/newPrefix/images/networkstatus.png"), "") self.gridLayout_10.addWidget(self.tabWidget, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) @@ -730,7 +672,6 @@ class Ui_MainWindow(object): MainWindow.setTabOrder(self.radioButtonBlacklist, self.radioButtonWhitelist) MainWindow.setTabOrder(self.radioButtonWhitelist, self.pushButtonAddBlacklist) MainWindow.setTabOrder(self.pushButtonAddBlacklist, self.tableWidgetBlacklist) - MainWindow.setTabOrder(self.tableWidgetBlacklist, self.tableWidgetConnectionCount) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(_translate("MainWindow", "Bitmessage", None)) @@ -825,19 +766,6 @@ class Ui_MainWindow(object): item = self.tableWidgetBlacklist.horizontalHeaderItem(1) item.setText(_translate("MainWindow", "Address", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.blackwhitelist), _translate("MainWindow", "Blacklist", None)) - item = self.tableWidgetConnectionCount.horizontalHeaderItem(0) - item.setText(_translate("MainWindow", "Stream #", None)) - item = self.tableWidgetConnectionCount.horizontalHeaderItem(1) - item.setText(_translate("MainWindow", "Connections", None)) - self.labelTotalConnections.setText(_translate("MainWindow", "Total connections:", None)) - self.labelStartupTime.setText(_translate("MainWindow", "Since startup:", None)) - self.labelSyncStatus.setText(_translate("MainWindow", "Objects to be synced:", None)) - self.labelMessageCount.setText(_translate("MainWindow", "Processed 0 person-to-person messages.", None)) - self.labelPubkeyCount.setText(_translate("MainWindow", "Processed 0 public keys.", None)) - self.labelBroadcastCount.setText(_translate("MainWindow", "Processed 0 broadcasts.", None)) - self.labelLookupsPerSecond.setText(_translate("MainWindow", "Inventory lookups per second: 0", None)) - self.labelBytesRecvCount.setText(_translate("MainWindow", "Down: 0 KB/s", None)) - self.labelBytesSentCount.setText(_translate("MainWindow", "Up: 0 KB/s", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.networkstatus), _translate("MainWindow", "Network Status", None)) self.menuFile.setTitle(_translate("MainWindow", "File", None)) self.menuSettings.setTitle(_translate("MainWindow", "Settings", None)) diff --git a/src/bitmessageqt/networkstatus.py b/src/bitmessageqt/networkstatus.py new file mode 100644 index 00000000..96bc46f6 --- /dev/null +++ b/src/bitmessageqt/networkstatus.py @@ -0,0 +1,115 @@ +from PyQt4 import QtCore, QtGui +import shared +from tr import _translate +import l10n +from uisignaler import UISignaler +import widgets + + +class NetworkStatus(QtGui.QWidget): + def __init__(self, parent=None): + super(NetworkStatus, self).__init__(parent) + widgets.load('networkstatus.ui', self) + + self.labelStartupTime.setText(_translate("MainWindow", "Since startup on %1").arg( + l10n.formatTimestamp())) + + self.UISignalThread = UISignaler.get() + QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( + "updateNumberOfMessagesProcessed()"), self.updateNumberOfMessagesProcessed) + QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( + "updateNumberOfPubkeysProcessed()"), self.updateNumberOfPubkeysProcessed) + QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( + "updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed) + QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( + "updateNetworkStatusTab()"), self.updateNetworkStatusTab) + + self.totalNumberOfBytesReceived = 0 + self.totalNumberOfBytesSent = 0 + + self.timer = QtCore.QTimer() + self.timer.start(2000) # milliseconds + QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.runEveryTwoSeconds) + + def updateNumberOfMessagesProcessed(self): + self.labelSyncStatus.setText(_translate("MainWindow", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) + self.labelMessageCount.setText(_translate( + "MainWindow", "Processed %1 person-to-person messages.").arg(str(shared.numberOfMessagesProcessed))) + + def updateNumberOfBroadcastsProcessed(self): + self.labelSyncStatus.setText(_translate("MainWindow", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) + self.labelBroadcastCount.setText(_translate( + "MainWindow", "Processed %1 broadcast messages.").arg(str(shared.numberOfBroadcastsProcessed))) + + def updateNumberOfPubkeysProcessed(self): + self.labelSyncStatus.setText(_translate("MainWindow", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) + self.labelPubkeyCount.setText(_translate( + "MainWindow", "Processed %1 public keys.").arg(str(shared.numberOfPubkeysProcessed))) + + def updateNumberOfBytes(self): + """ + This function is run every two seconds, so we divide the rate of bytes + sent and received by 2. + """ + self.labelBytesRecvCount.setText(_translate( + "MainWindow", "Down: %1/s Total: %2").arg(self.formatByteRate(shared.numberOfBytesReceived/2), self.formatBytes(self.totalNumberOfBytesReceived))) + self.labelBytesSentCount.setText(_translate( + "MainWindow", "Up: %1/s Total: %2").arg(self.formatByteRate(shared.numberOfBytesSent/2), self.formatBytes(self.totalNumberOfBytesSent))) + self.totalNumberOfBytesReceived += shared.numberOfBytesReceived + self.totalNumberOfBytesSent += shared.numberOfBytesSent + shared.numberOfBytesReceived = 0 + shared.numberOfBytesSent = 0 + + def updateNetworkStatusTab(self): + totalNumberOfConnectionsFromAllStreams = 0 # One would think we could use len(sendDataQueues) for this but the number doesn't always match: just because we have a sendDataThread running doesn't mean that the connection has been fully established (with the exchange of version messages). + streamNumberTotals = {} + for host, streamNumber in shared.connectedHostsList.items(): + if not streamNumber in streamNumberTotals: + streamNumberTotals[streamNumber] = 1 + else: + streamNumberTotals[streamNumber] += 1 + + while self.tableWidgetConnectionCount.rowCount() > 0: + self.tableWidgetConnectionCount.removeRow(0) + for streamNumber, connectionCount in streamNumberTotals.items(): + self.tableWidgetConnectionCount.insertRow(0) + if streamNumber == 0: + newItem = QtGui.QTableWidgetItem("?") + else: + newItem = QtGui.QTableWidgetItem(str(streamNumber)) + newItem.setFlags( + QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + self.tableWidgetConnectionCount.setItem(0, 0, newItem) + newItem = QtGui.QTableWidgetItem(str(connectionCount)) + newItem.setFlags( + QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + self.tableWidgetConnectionCount.setItem(0, 1, newItem) + """for currentRow in range(self.tableWidgetConnectionCount.rowCount()): + rowStreamNumber = int(self.tableWidgetConnectionCount.item(currentRow,0).text()) + if streamNumber == rowStreamNumber: + foundTheRowThatNeedsUpdating = True + self.tableWidgetConnectionCount.item(currentRow,1).setText(str(connectionCount)) + #totalNumberOfConnectionsFromAllStreams += connectionCount + if foundTheRowThatNeedsUpdating == False: + #Add a line to the table for this stream number and update its count with the current connection count. + self.tableWidgetConnectionCount.insertRow(0) + newItem = QtGui.QTableWidgetItem(str(streamNumber)) + newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) + self.tableWidgetConnectionCount.setItem(0,0,newItem) + newItem = QtGui.QTableWidgetItem(str(connectionCount)) + newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) + self.tableWidgetConnectionCount.setItem(0,1,newItem) + totalNumberOfConnectionsFromAllStreams += connectionCount""" + self.labelTotalConnections.setText(_translate( + "MainWindow", "Total Connections: %1").arg(str(len(shared.connectedHostsList)))) + if len(shared.connectedHostsList) > 0 and shared.statusIconColor == 'red': # FYI: The 'singlelistener' thread sets the icon color to green when it receives an incoming connection, meaning that the user's firewall is configured correctly. + self.window().setStatusIcon('yellow') + elif len(shared.connectedHostsList) == 0: + self.window().setStatusIcon('red') + + # timer driven + def runEveryTwoSeconds(self): + self.labelLookupsPerSecond.setText(_translate( + "MainWindow", "Inventory lookups per second: %1").arg(str(shared.numberOfInventoryLookupsPerformed/2))) + shared.numberOfInventoryLookupsPerformed = 0 + self.updateNumberOfBytes() diff --git a/src/bitmessageqt/networkstatus.ui b/src/bitmessageqt/networkstatus.ui new file mode 100644 index 00000000..afc8b976 --- /dev/null +++ b/src/bitmessageqt/networkstatus.ui @@ -0,0 +1,232 @@ + + + NetworkStatus + + + + 0 + 0 + 731 + 493 + + + + + + 20 + 30 + 401 + 16 + + + + Total connections: + + + + + + 320 + 110 + 331 + 20 + + + + Since startup: + + + + + + 350 + 130 + 361 + 16 + + + + Processed 0 person-to-person messages. + + + + + + 350 + 170 + 331 + 16 + + + + Processed 0 public keys. + + + + + + 350 + 150 + 351 + 16 + + + + Processed 0 broadcasts. + + + + + + 320 + 270 + 291 + 16 + + + + Inventory lookups per second: 0 + + + + + + 350 + 220 + 251 + 16 + + + + Down: 0 KB/s + + + + + + 350 + 240 + 251 + 16 + + + + Up: 0 KB/s + + + + + + 350 + 190 + 331 + 16 + + + + Objects to be synced: + + + + + + 20 + 70 + 241 + 241 + + + + + + + + + + + + 212 + 208 + 200 + + + + + + + + + 212 + 208 + 200 + + + + + + + + + 212 + 208 + 200 + + + + + + + + QFrame::Box + + + QFrame::Plain + + + false + + + true + + + QAbstractItemView::NoSelection + + + true + + + false + + + true + + + false + + + + Stream # + + + + + Connections + + + + + + + + + + STableWidget + QTableWidget +
bitmessageqt/settingsmixin.h
+
+
+ + + + +
diff --git a/src/bitmessageqt/uisignaler.py b/src/bitmessageqt/uisignaler.py new file mode 100644 index 00000000..ea18f0b0 --- /dev/null +++ b/src/bitmessageqt/uisignaler.py @@ -0,0 +1,77 @@ + +from PyQt4.QtCore import QThread, SIGNAL +import shared +import sys + + +class UISignaler(QThread): + _instance = None + + def __init__(self, parent=None): + QThread.__init__(self, parent) + + @classmethod + def get(cls): + if not cls._instance: + cls._instance = UISignaler() + return cls._instance + + def run(self): + while True: + command, data = shared.UISignalQueue.get() + if command == 'writeNewAddressToTable': + label, address, streamNumber = data + self.emit(SIGNAL( + "writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), label, address, str(streamNumber)) + elif command == 'updateStatusBar': + self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"), data) + elif command == 'updateSentItemStatusByToAddress': + toAddress, message = data + self.emit(SIGNAL( + "updateSentItemStatusByToAddress(PyQt_PyObject,PyQt_PyObject)"), toAddress, message) + elif command == 'updateSentItemStatusByAckdata': + ackData, message = data + self.emit(SIGNAL( + "updateSentItemStatusByAckdata(PyQt_PyObject,PyQt_PyObject)"), ackData, message) + elif command == 'displayNewInboxMessage': + inventoryHash, toAddress, fromAddress, subject, body = data + self.emit(SIGNAL( + "displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), + inventoryHash, toAddress, fromAddress, subject, body) + elif command == 'displayNewSentMessage': + toAddress, fromLabel, fromAddress, subject, message, ackdata = data + self.emit(SIGNAL( + "displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), + toAddress, fromLabel, fromAddress, subject, message, ackdata) + elif command == 'updateNetworkStatusTab': + self.emit(SIGNAL("updateNetworkStatusTab()")) + elif command == 'updateNumberOfMessagesProcessed': + self.emit(SIGNAL("updateNumberOfMessagesProcessed()")) + elif command == 'updateNumberOfPubkeysProcessed': + self.emit(SIGNAL("updateNumberOfPubkeysProcessed()")) + elif command == 'updateNumberOfBroadcastsProcessed': + self.emit(SIGNAL("updateNumberOfBroadcastsProcessed()")) + elif command == 'setStatusIcon': + self.emit(SIGNAL("setStatusIcon(PyQt_PyObject)"), data) + elif command == 'changedInboxUnread': + self.emit(SIGNAL("changedInboxUnread(PyQt_PyObject)"), data) + elif command == 'rerenderMessagelistFromLabels': + self.emit(SIGNAL("rerenderMessagelistFromLabels()")) + elif command == 'rerenderMessagelistToLabels': + self.emit(SIGNAL("rerenderMessagelistToLabels()")) + elif command == 'rerenderAddressBook': + self.emit(SIGNAL("rerenderAddressBook()")) + elif command == 'rerenderSubscriptions': + self.emit(SIGNAL("rerenderSubscriptions()")) + elif command == 'rerenderBlackWhiteList': + self.emit(SIGNAL("rerenderBlackWhiteList()")) + elif command == 'removeInboxRowByMsgid': + self.emit(SIGNAL("removeInboxRowByMsgid(PyQt_PyObject)"), data) + elif command == 'newVersionAvailable': + self.emit(SIGNAL("newVersionAvailable(PyQt_PyObject)"), data) + elif command == 'alert': + title, text, exitAfterUserClicksOk = data + self.emit(SIGNAL("displayAlert(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"), title, text, exitAfterUserClicksOk) + else: + sys.stderr.write( + 'Command sent to UISignaler not recognized: %s\n' % command) diff --git a/src/bitmessageqt/widgets.py b/src/bitmessageqt/widgets.py new file mode 100644 index 00000000..7919d7f9 --- /dev/null +++ b/src/bitmessageqt/widgets.py @@ -0,0 +1,14 @@ +from PyQt4 import uic +import os.path +import sys + + +def resource_path(path): + try: + return os.path.join(sys._MEIPASS, path) + except: + return os.path.join(os.path.dirname(__file__), path) + + +def load(path, widget): + uic.loadUi(resource_path(path), widget)