From 48b5e26e461b989550e090cc6ef7af3d8e68bb85 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Mon, 17 Jun 2013 16:42:30 -0400 Subject: [PATCH] Finished adjusted _translate function to work under daemon mode --- src/bitmessagemain.py | 44 +++++++++++++++++++++++++----------- src/bitmessageqt/__init__.py | 6 ++--- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 83815253..a834deb6 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -52,15 +52,6 @@ import proofofwork # For each stream to which we connect, several outgoingSynSender threads # will exist and will collectively create 8 connections with peers. -try: - from PyQt4 import QtCore, QtGui - _encoding = QtGui.QApplication.UnicodeUTF8 - def _translate(context, text): - return QtGui.QApplication.translate(context, text) -except AttributeError: - print 'Error message:', err - - class outgoingSynSender(threading.Thread): def __init__(self): @@ -1094,8 +1085,8 @@ class receiveDataThread(threading.Thread): shared.sqlReturnQueue.get() shared.sqlSubmitQueue.put('commit') shared.sqlLock.release() - shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (encryptedData[readPosition:], 'Acknowledgement of the message received just now. ' + unicode( - strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8')))) + shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (encryptedData[readPosition:], _translate("MainWindow",'Acknowledgement of the message received. %1').arg(unicode( + strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8'))))) return else: shared.printLock.acquire() @@ -4654,6 +4645,18 @@ class singleAPI(threading.Thread): se.register_introspection_functions() se.serve_forever() +# This is used so that the _translate function can be used when we are in daemon mode and not using any QT functions. +class translateClass: + def __init__(self, context, text): + self.context = context + self.text = text + def arg(self,argument): + if '%' in self.text: + return translateClass(self.context, self.text.replace('%','',1)) # This doesn't actually do anything with the arguments because we don't have a UI in which to display this information anyway. + else: + return self.text + + selfInitiatedConnections = {} # This is a list of current connections (the thread pointers at least) alreadyAttemptedConnectionsList = { @@ -4867,19 +4870,34 @@ if __name__ == "__main__": try: from PyQt4.QtCore import * from PyQt4.QtGui import * + from PyQt4 import QtCore, QtGui except Exception as err: print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon' print 'Error message:', err os._exit(0) + try: + _encoding = QtGui.QApplication.UnicodeUTF8 + def _translate(context, text): # A non-QT version of _translate is defined below. + return QtGui.QApplication.translate(context, text) + except Exception as err: + print 'Error:', err + import bitmessageqt bitmessageqt.run() else: + def _translate(context, text): # A QT version of _translate is defined above. + if '%' in text: + return translateClass(context, text.replace('%','',1)) + else: + return text + shared.printLock.acquire() print 'Running as a daemon. You can use Ctrl+C to exit.' + shared.printLock.release() while True: time.sleep(20) -# So far, the Bitmessage protocol, this client, the Wiki, and the forums -# are all a one-man operation. Bitcoin tips are quite appreciated! +# So far, the creation of and management of the Bitmessage protocol and this +# client is a one-man operation. Bitcoin tips are quite appreciated. # 1H5XaDA6fYENLbknwZyjiYXYPQaFjjLX2u diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index f69c29b7..dfdb0b43 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -8,7 +8,7 @@ try: from PyQt4.QtCore import * from PyQt4.QtGui import * except Exception as err: - print 'PyBitmessage requires PyQt. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).' + print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).' print 'Error message:', err sys.exit() @@ -1122,9 +1122,9 @@ class MyForm(QtGui.QMainWindow): if ripe == toRipe: self.ui.tableWidgetSent.item(i, 3).setToolTip(textToDisplay) newlinePosition = textToDisplay.indexOf('\n') - if parenPositionIndex > 1: + if newlinePosition > 1: self.ui.tableWidgetSent.item(i, 3).setText( - textToDisplay[:parenPositionIndex]) + textToDisplay[:newlinePosition]) else: self.ui.tableWidgetSent.item(i, 3).setText(textToDisplay)