Skip to content

Commit d2d2d8c

Browse files
committed
Fixed translate functions not being found as they were being defined after the QT GUI was started
1 parent c2cfff2 commit d2d2d8c

1 file changed

Lines changed: 41 additions & 42 deletions

File tree

src/bitmessagemain.py

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def run(self):
193193
shared.printLock.release()
194194
except socks.Socks5AuthError as err:
195195
shared.UISignalQueue.put((
196-
'updateStatusBar', _translate(
196+
'updateStatusBar', translateText(
197197
"MainWindow", "SOCKS5 Authentication problem: %1").arg(str(err))))
198198
except socks.Socks5Error as err:
199199
pass
@@ -1022,7 +1022,7 @@ def processmsg(self, readPosition, encryptedData):
10221022
shared.sqlReturnQueue.get()
10231023
shared.sqlSubmitQueue.put('commit')
10241024
shared.sqlLock.release()
1025-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (encryptedData[readPosition:], _translate("MainWindow",'Acknowledgement of the message received. %1').arg(unicode(
1025+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (encryptedData[readPosition:], translateText("MainWindow",'Acknowledgement of the message received. %1').arg(unicode(
10261026
strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8')))))
10271027
return
10281028
else:
@@ -2734,7 +2734,7 @@ def sendBroadcast(self):
27342734
fromaddress, 'privencryptionkey')
27352735
except:
27362736
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
2737-
ackdata, _translate("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
2737+
ackdata, translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
27382738
continue
27392739

27402740
privSigningKeyHex = shared.decodeWalletImportFormat(
@@ -2769,7 +2769,7 @@ def sendBroadcast(self):
27692769
payload) + shared.networkDefaultPayloadLengthExtraBytes + 8) * shared.networkDefaultProofOfWorkNonceTrialsPerByte)
27702770
print '(For broadcast message) Doing proof of work...'
27712771
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
2772-
ackdata, _translate("MainWindow", "Doing work necessary to send broadcast..."))))
2772+
ackdata, translateText("MainWindow", "Doing work necessary to send broadcast..."))))
27732773
initialHash = hashlib.sha512(payload).digest()
27742774
trialValue, nonce = proofofwork.run(target, initialHash)
27752775
print '(For broadcast message) Found proof of work', trialValue, 'Nonce:', nonce
@@ -2784,7 +2784,7 @@ def sendBroadcast(self):
27842784
shared.broadcastToSendDataQueues((
27852785
streamNumber, 'sendinv', inventoryHash))
27862786

2787-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, _translate("MainWindow", "Broadcast sent on %1").arg(unicode(
2787+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, translateText("MainWindow", "Broadcast sent on %1").arg(unicode(
27882788
strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8')))))
27892789

27902790
# Update the status of the message in the 'sent' table to have
@@ -2808,7 +2808,7 @@ def sendBroadcast(self):
28082808
fromaddress, 'privencryptionkey')
28092809
except:
28102810
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
2811-
ackdata, _translate("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
2811+
ackdata, translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
28122812
continue
28132813

28142814
privSigningKeyHex = shared.decodeWalletImportFormat(
@@ -2856,7 +2856,7 @@ def sendBroadcast(self):
28562856
payload) + shared.networkDefaultPayloadLengthExtraBytes + 8) * shared.networkDefaultProofOfWorkNonceTrialsPerByte)
28572857
print '(For broadcast message) Doing proof of work...'
28582858
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
2859-
ackdata, _translate("MainWindow", "Doing work necessary to send broadcast..."))))
2859+
ackdata, translateText("MainWindow", "Doing work necessary to send broadcast..."))))
28602860
initialHash = hashlib.sha512(payload).digest()
28612861
trialValue, nonce = proofofwork.run(target, initialHash)
28622862
print '(For broadcast message) Found proof of work', trialValue, 'Nonce:', nonce
@@ -2871,7 +2871,7 @@ def sendBroadcast(self):
28712871
shared.broadcastToSendDataQueues((
28722872
streamNumber, 'sendinv', inventoryHash))
28732873

2874-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, _translate("MainWindow", "Broadcast sent on %1").arg(unicode(
2874+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, translateText("MainWindow", "Broadcast sent on %1").arg(unicode(
28752875
strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8')))))
28762876

28772877
# Update the status of the message in the 'sent' table to have
@@ -2929,7 +2929,7 @@ def sendMsg(self):
29292929
shared.sqlSubmitQueue.put('commit')
29302930
shared.sqlLock.release()
29312931
shared.UISignalQueue.put(('updateSentItemStatusByHash', (
2932-
toripe, _translate("MainWindow",'Encryption key was requested earlier.'))))
2932+
toripe, translateText("MainWindow",'Encryption key was requested earlier.'))))
29332933
else:
29342934
# We have not yet sent a request for the pubkey
29352935
t = (toaddress,)
@@ -2941,7 +2941,7 @@ def sendMsg(self):
29412941
shared.sqlSubmitQueue.put('commit')
29422942
shared.sqlLock.release()
29432943
shared.UISignalQueue.put(('updateSentItemStatusByHash', (
2944-
toripe, _translate("MainWindow",'Sending a request for the recipient\'s encryption key.'))))
2944+
toripe, translateText("MainWindow",'Sending a request for the recipient\'s encryption key.'))))
29452945
self.requestPubKey(toaddress)
29462946
shared.sqlLock.acquire()
29472947
# Get all messages that are ready to be sent, and also all messages
@@ -2983,7 +2983,7 @@ def sendMsg(self):
29832983
shared.sqlSubmitQueue.put('commit')
29842984
shared.sqlLock.release()
29852985
shared.UISignalQueue.put(('updateSentItemStatusByHash', (
2986-
toripe, _translate("MainWindow",'Sending a request for the recipient\'s encryption key.'))))
2986+
toripe, translateText("MainWindow",'Sending a request for the recipient\'s encryption key.'))))
29872987
self.requestPubKey(toaddress)
29882988
continue
29892989
ackdataForWhichImWatching[ackdata] = 0
@@ -2992,7 +2992,7 @@ def sendMsg(self):
29922992
fromStatus, fromAddressVersionNumber, fromStreamNumber, fromHash = decodeAddress(
29932993
fromaddress)
29942994
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
2995-
ackdata, _translate("MainWindow", "Looking up the receiver\'s public key"))))
2995+
ackdata, translateText("MainWindow", "Looking up the receiver\'s public key"))))
29962996
shared.printLock.acquire()
29972997
print 'Found a message in our database that needs to be sent with this pubkey.'
29982998
print 'First 150 characters of message:', repr(message[:150])
@@ -3055,7 +3055,7 @@ def sendMsg(self):
30553055
requiredAverageProofOfWorkNonceTrialsPerByte = shared.networkDefaultProofOfWorkNonceTrialsPerByte
30563056
requiredPayloadLengthExtraBytes = shared.networkDefaultPayloadLengthExtraBytes
30573057
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
3058-
ackdata, _translate("MainWindow", "Doing work necessary to send message.\nThere is no required difficulty for version 2 addresses like this."))))
3058+
ackdata, translateText("MainWindow", "Doing work necessary to send message.\nThere is no required difficulty for version 2 addresses like this."))))
30593059
elif toAddressVersionNumber == 3:
30603060
requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = decodeVarint(
30613061
pubkeyPayload[readPosition:readPosition + 10])
@@ -3067,7 +3067,7 @@ def sendMsg(self):
30673067
requiredAverageProofOfWorkNonceTrialsPerByte = shared.networkDefaultProofOfWorkNonceTrialsPerByte
30683068
if requiredPayloadLengthExtraBytes < shared.networkDefaultPayloadLengthExtraBytes:
30693069
requiredPayloadLengthExtraBytes = shared.networkDefaultPayloadLengthExtraBytes
3070-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, _translate("MainWindow", "Doing work necessary to send message.\nReceiver\'s required difficulty: %1 and %2").arg(str(float(
3070+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, translateText("MainWindow", "Doing work necessary to send message.\nReceiver\'s required difficulty: %1 and %2").arg(str(float(
30713071
requiredAverageProofOfWorkNonceTrialsPerByte) / shared.networkDefaultProofOfWorkNonceTrialsPerByte)).arg(str(float(requiredPayloadLengthExtraBytes) / shared.networkDefaultPayloadLengthExtraBytes)))))
30723072
if status != 'forcepow':
30733073
if (requiredAverageProofOfWorkNonceTrialsPerByte > shared.config.getint('bitmessagesettings', 'maxacceptablenoncetrialsperbyte') and shared.config.getint('bitmessagesettings', 'maxacceptablenoncetrialsperbyte') != 0) or (requiredPayloadLengthExtraBytes > shared.config.getint('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') and shared.config.getint('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') != 0):
@@ -3081,7 +3081,7 @@ def sendMsg(self):
30813081
shared.sqlReturnQueue.get()
30823082
shared.sqlSubmitQueue.put('commit')
30833083
shared.sqlLock.release()
3084-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, _translate("MainWindow", "Problem: The work demanded by the recipient (%1 and %2) is more difficult than you are willing to do.").arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte) / shared.networkDefaultProofOfWorkNonceTrialsPerByte)).arg(str(float(
3084+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, translateText("MainWindow", "Problem: The work demanded by the recipient (%1 and %2) is more difficult than you are willing to do.").arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte) / shared.networkDefaultProofOfWorkNonceTrialsPerByte)).arg(str(float(
30853085
requiredPayloadLengthExtraBytes) / shared.networkDefaultPayloadLengthExtraBytes)).arg(unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8')))))
30863086
continue
30873087

@@ -3102,7 +3102,7 @@ def sendMsg(self):
31023102
fromaddress, 'privencryptionkey')
31033103
except:
31043104
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
3105-
ackdata, _translate("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
3105+
ackdata, translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
31063106
continue
31073107

31083108
privSigningKeyHex = shared.decodeWalletImportFormat(
@@ -3148,7 +3148,7 @@ def sendMsg(self):
31483148
fromaddress, 'privencryptionkey')
31493149
except:
31503150
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
3151-
ackdata, _translate("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
3151+
ackdata, translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
31523152
continue
31533153

31543154
privSigningKeyHex = shared.decodeWalletImportFormat(
@@ -3205,7 +3205,7 @@ def sendMsg(self):
32053205
queryreturn = shared.sqlReturnQueue.get()
32063206
shared.sqlSubmitQueue.put('commit')
32073207
shared.sqlLock.release()
3208-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata',(ackdata,_translate("MainWindow",'Problem: The recipient\'s encryption key is no good. Could not encrypt message. %1').arg(unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'),localtime(int(time.time()))),'utf-8')))))
3208+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata',(ackdata,translateText("MainWindow",'Problem: The recipient\'s encryption key is no good. Could not encrypt message. %1').arg(unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'),localtime(int(time.time()))),'utf-8')))))
32093209
continue
32103210
encryptedPayload = embeddedTime + encodeVarint(toStreamNumber) + encrypted
32113211
target = 2**64 / ((len(encryptedPayload)+requiredPayloadLengthExtraBytes+8) * requiredAverageProofOfWorkNonceTrialsPerByte)
@@ -3228,7 +3228,7 @@ def sendMsg(self):
32283228
objectType = 'msg'
32293229
shared.inventory[inventoryHash] = (
32303230
objectType, toStreamNumber, encryptedPayload, int(time.time()))
3231-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, _translate("MainWindow", "Message sent. Waiting on acknowledgement. Sent on %1").arg(unicode(
3231+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, translateText("MainWindow", "Message sent. Waiting on acknowledgement. Sent on %1").arg(unicode(
32323232
strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8')))))
32333233
print 'Broadcasting inv for my msg(within sendmsg function):', inventoryHash.encode('hex')
32343234
shared.broadcastToSendDataQueues((
@@ -3266,7 +3266,7 @@ def requestPubKey(self, toAddress):
32663266
statusbar = 'Doing the computations necessary to request the recipient\'s public key.'
32673267
shared.UISignalQueue.put(('updateStatusBar', statusbar))
32683268
shared.UISignalQueue.put(('updateSentItemStatusByHash', (
3269-
ripe, _translate("MainWindow",'Doing work necessary to request encryption key.'))))
3269+
ripe, translateText("MainWindow",'Doing work necessary to request encryption key.'))))
32703270
target = 2 ** 64 / ((len(payload) + shared.networkDefaultPayloadLengthExtraBytes +
32713271
8) * shared.networkDefaultProofOfWorkNonceTrialsPerByte)
32723272
initialHash = hashlib.sha512(payload).digest()
@@ -3294,8 +3294,8 @@ def requestPubKey(self, toAddress):
32943294
shared.sqlLock.release()
32953295

32963296
shared.UISignalQueue.put((
3297-
'updateStatusBar', _translate("MainWindow",'Broacasting the public key request. This program will auto-retry if they are offline.')))
3298-
shared.UISignalQueue.put(('updateSentItemStatusByHash', (ripe, _translate("MainWindow",'Sending public key request. Waiting for reply. Requested at %1').arg(unicode(
3297+
'updateStatusBar', translateText("MainWindow",'Broacasting the public key request. This program will auto-retry if they are offline.')))
3298+
shared.UISignalQueue.put(('updateSentItemStatusByHash', (ripe, translateText("MainWindow",'Sending public key request. Waiting for reply. Requested at %1').arg(unicode(
32993299
strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))), 'utf-8')))))
33003300

33013301
def generateFullAckMessage(self, ackdata, toStreamNumber, embeddedTime):
@@ -3947,7 +3947,7 @@ def run(self):
39473947
se.register_introspection_functions()
39483948
se.serve_forever()
39493949

3950-
# This is used so that the _translate function can be used when we are in daemon mode and not using any QT functions.
3950+
# This is used so that the translateText function can be used when we are in daemon mode and not using any QT functions.
39513951
class translateClass:
39523952
def __init__(self, context, text):
39533953
self.context = context
@@ -3958,6 +3958,24 @@ def arg(self,argument):
39583958
else:
39593959
return self.text
39603960

3961+
def _translate(context, text):
3962+
return translateText(context, text)
3963+
3964+
def translateText(context, text):
3965+
if not shared.safeConfigGetBoolean('bitmessagesettings', 'daemon'):
3966+
try:
3967+
from PyQt4 import QtCore, QtGui
3968+
except Exception as err:
3969+
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'
3970+
print 'Error message:', err
3971+
os._exit(0)
3972+
return QtGui.QApplication.translate(context, text)
3973+
else:
3974+
if '%' in text:
3975+
return translateClass(context, text.replace('%','',1))
3976+
else:
3977+
return text
3978+
39613979

39623980
selfInitiatedConnections = {}
39633981
# This is a list of current connections (the thread pointers at least)
@@ -4067,25 +4085,6 @@ def arg(self,argument):
40674085
while True:
40684086
time.sleep(20)
40694087

4070-
def _translate(context, text):
4071-
return translateText(context, text)
4072-
4073-
def translateText(context, text):
4074-
if not shared.safeConfigGetBoolean('bitmessagesettings', 'daemon'):
4075-
try:
4076-
from PyQt4 import QtCore, QtGui
4077-
except Exception as err:
4078-
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'
4079-
print 'Error message:', err
4080-
os._exit(0)
4081-
return QtGui.QApplication.translate(context, text)
4082-
else:
4083-
if '%' in text:
4084-
return translateClass(context, text.replace('%','',1))
4085-
else:
4086-
return text
4087-
4088-
40894088
# So far, the creation of and management of the Bitmessage protocol and this
40904089
# client is a one-man operation. Bitcoin tips are quite appreciated.
40914090
# 1H5XaDA6fYENLbknwZyjiYXYPQaFjjLX2u

0 commit comments

Comments
 (0)