22PyQt based UI for bitmessage, the main module
33"""
44# pylint: disable=import-error,too-many-lines,no-member
5+ # pylint: disable=too-many-branches
56import hashlib
67import locale
78import os
@@ -760,6 +761,11 @@ def __init__(self, parent=None):
760761
761762 self .unreadCount = 0
762763
764+ self .currentTrayIconFileName = ""
765+ self .actionQuiet = None
766+ self .actionShow = None
767+ self .tray = None
768+
763769 # Set the icon sizes for the identicons
764770 identicon_size = 3 * 7
765771 self .ui .tableWidgetInbox .setIconSize (QtCore .QSize (identicon_size , identicon_size ))
@@ -843,7 +849,7 @@ def __init__(self, parent=None):
843849
844850 self .initSettings ()
845851 self .resetNamecoinConnection ()
846- self .sqlInit ()
852+ MyForm .sqlInit ()
847853 self .indicatorInit ()
848854 self .notifierInit ()
849855 self .updateStartOnLogon ()
@@ -1107,7 +1113,8 @@ def propagateUnreadCount(self, folder=None, widget=None):
11071113 if newCount != folderItem .unreadCount :
11081114 folderItem .setUnreadCount (newCount )
11091115
1110- def addMessageListItem (self , tableWidget , items ):
1116+ @staticmethod
1117+ def addMessageListItem (tableWidget , items ):
11111118 sortingEnabled = tableWidget .isSortingEnabled ()
11121119 if sortingEnabled :
11131120 tableWidget .setSortingEnabled (False )
@@ -1117,8 +1124,9 @@ def addMessageListItem(self, tableWidget, items):
11171124 if sortingEnabled :
11181125 tableWidget .setSortingEnabled (True )
11191126
1127+ @staticmethod
11201128 def addMessageListItemSent (
1121- self , tableWidget , toAddress , fromAddress , subject ,
1129+ tableWidget , toAddress , fromAddress , subject ,
11221130 status , ackdata , lastactiontime
11231131 ):
11241132 acct = accountClass (fromAddress ) or BMAccount (fromAddress )
@@ -1191,12 +1199,13 @@ def addMessageListItemSent(
11911199 str (subject ), text_type (acct .subject , 'utf-8' , 'replace' )),
11921200 MessageList_TimeWidget (
11931201 statusText , False , lastactiontime , ackdata )]
1194- self .addMessageListItem (tableWidget , items )
1202+ MyForm .addMessageListItem (tableWidget , items )
11951203
11961204 return acct
11971205
1206+ @staticmethod
11981207 def addMessageListItemInbox (
1199- self , tableWidget , toAddress , fromAddress , subject ,
1208+ tableWidget , toAddress , fromAddress , subject ,
12001209 msgid , received , read
12011210 ):
12021211 if toAddress == str_broadcast_subscribers :
@@ -1218,12 +1227,13 @@ def addMessageListItemInbox(
12181227 MessageList_TimeWidget (
12191228 l10n .formatTimestamp (received ), not read , received , msgid )
12201229 ]
1221- self .addMessageListItem (tableWidget , items )
1230+ MyForm .addMessageListItem (tableWidget , items )
12221231
12231232 return acct
12241233
1225- # Load Sent items from database
1226- def loadSent (self , tableWidget , account , where = "" , what = "" ):
1234+ @staticmethod
1235+ def loadSent (tableWidget , account , where = "" , what = "" ):
1236+ """Load Sent items from database"""
12271237 if tableWidget == self .ui .tableWidgetInboxSubscriptions :
12281238 tableWidget .setColumnHidden (0 , True )
12291239 tableWidget .setColumnHidden (1 , False )
@@ -1241,7 +1251,7 @@ def loadSent(self, tableWidget, account, where="", what=""):
12411251 xAddress , account , "sent" , where , what , False )
12421252
12431253 for row in queryreturn :
1244- self .addMessageListItemSent (tableWidget , * row )
1254+ MyForm .addMessageListItemSent (tableWidget , * row )
12451255
12461256 tableWidget .horizontalHeader ().setSortIndicator (
12471257 3 , QtCore .Qt .DescendingOrder )
@@ -1250,17 +1260,17 @@ def loadSent(self, tableWidget, account, where="", what=""):
12501260 _translate ("MainWindow" , "Sent" ))
12511261 tableWidget .setUpdatesEnabled (True )
12521262
1253- # Load messages from database file
12541263 def loadMessagelist (
12551264 self , tableWidget , account , folder = "inbox" , where = "" , what = "" ,
12561265 unreadOnly = False
12571266 ):
1267+ """Load messages from database file"""
12581268 tableWidget .setUpdatesEnabled (False )
12591269 tableWidget .setSortingEnabled (False )
12601270 tableWidget .setRowCount (0 )
12611271
12621272 if folder == 'sent' :
1263- self .loadSent (tableWidget , account , where , what )
1273+ MyForm .loadSent (tableWidget , account , where , what )
12641274 return
12651275
12661276 if tableWidget == self .ui .tableWidgetInboxSubscriptions :
@@ -1282,7 +1292,7 @@ def loadMessagelist(
12821292
12831293 for row in queryreturn :
12841294 toAddress , fromAddress , subject , _ , msgid , received , read = row
1285- self .addMessageListItemInbox (
1295+ MyForm .addMessageListItemInbox (
12861296 tableWidget , toAddress , fromAddress , subject ,
12871297 msgid , received , read )
12881298
@@ -1359,8 +1369,9 @@ def appIndicatorInit(self, _app):
13591369 self .tray .setContextMenu (m )
13601370 self .tray .show ()
13611371
1362- # returns the number of unread messages and subscriptions
1363- def getUnread (self ):
1372+ @staticmethod
1373+ def getUnread ():
1374+ """returns the number of unread messages and subscriptions"""
13641375 counters = [0 , 0 ]
13651376
13661377 queryreturn = sqlQuery ('''
@@ -1443,8 +1454,9 @@ def _choose_ext(basename):
14431454
14441455 self ._player (soundFilename )
14451456
1446- # Adapters and converters for QT <-> sqlite
1457+ @ staticmethod
14471458 def sqlInit (self ):
1459+ """Adapters and converters for QT <-> sqlite"""
14481460 register_adapter (QtCore .QByteArray , str )
14491461
14501462 def indicatorInit (self ):
@@ -1813,15 +1825,16 @@ def setStatusIcon(self, color):
18131825 def initTrayIcon (self , iconFileName , _app ):
18141826 self .currentTrayIconFileName = iconFileName
18151827 self .tray = QtGui .QSystemTrayIcon (
1816- self .calcTrayIcon (iconFileName ,
1817- self .findInboxUnreadCount ()),
1828+ MyForm .calcTrayIcon (iconFileName ,
1829+ self .findInboxUnreadCount ()),
18181830 _app )
18191831
18201832 def setTrayIconFile (self , iconFileName ):
18211833 self .currentTrayIconFileName = iconFileName
18221834 self .drawTrayIcon (iconFileName , self .findInboxUnreadCount ())
18231835
1824- def calcTrayIcon (self , iconFileName , inboxUnreadCount ):
1836+ @staticmethod
1837+ def calcTrayIcon (iconFileName , inboxUnreadCount ):
18251838 pixmap = QtGui .QPixmap (":/newPrefix/images/" + iconFileName )
18261839 if inboxUnreadCount > 0 :
18271840 # choose font and calculate font parameters
@@ -1854,7 +1867,8 @@ def calcTrayIcon(self, iconFileName, inboxUnreadCount):
18541867 return QtGui .QIcon (pixmap )
18551868
18561869 def drawTrayIcon (self , iconFileName , inboxUnreadCount ):
1857- self .tray .setIcon (self .calcTrayIcon (iconFileName , inboxUnreadCount ))
1870+ self .tray .setIcon (MyForm .calcTrayIcon (iconFileName ,
1871+ inboxUnreadCount ))
18581872
18591873 def changedInboxUnread (self , row = None ):
18601874 self .drawTrayIcon (
@@ -3978,12 +3992,12 @@ def on_context_menuInbox(self, point):
39783992 popMenuInbox .addAction (self .actionReply )
39793993 popMenuInbox .addAction (self .actionAddSenderToAddressBook )
39803994 # pylint: disable=no-member
3981- self . actionClipboardMessagelist = self .ui .inboxContextMenuToolbar .addAction (
3995+ actionClipboardMessagelist = self .ui .inboxContextMenuToolbar .addAction (
39823996 _translate ("MainWindow" , "Copy subject to clipboard" )
39833997 if tableWidget .currentColumn () == 2 else
39843998 _translate ("MainWindow" , "Copy address to clipboard" ),
39853999 self .on_action_ClipboardMessagelist )
3986- popMenuInbox .addAction (self . actionClipboardMessagelist )
4000+ popMenuInbox .addAction (actionClipboardMessagelist )
39874001 # pylint: disable=no-member
39884002 self ._contact_selected = tableWidget .item (currentRow , 1 )
39894003 # preloaded gui.menu plugins with prefix 'address'
@@ -4229,7 +4243,7 @@ class BitmessageQtApplication(QtGui.QApplication):
42294243 """
42304244
42314245 # Unique identifier for this application
4232- uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
4246+ UUID = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
42334247
42344248 @staticmethod
42354249 def get_windowstyle ():
@@ -4241,7 +4255,6 @@ def get_windowstyle():
42414255
42424256 def __init__ (self , * argv ):
42434257 super (BitmessageQtApplication , self ).__init__ (* argv )
4244- id = BitmessageQtApplication .uuid
42454258
42464259 QtCore .QCoreApplication .setOrganizationName ("PyBitmessage" )
42474260 QtCore .QCoreApplication .setOrganizationDomain ("bitmessage.org" )
@@ -4259,14 +4272,14 @@ def __init__(self, *argv):
42594272 self .is_running = False
42604273
42614274 socket = QLocalSocket ()
4262- socket .connectToServer (id )
4275+ socket .connectToServer (self . UUID )
42634276 self .is_running = socket .waitForConnected ()
42644277
42654278 # Cleanup past crashed servers
42664279 if not self .is_running :
42674280 if socket .error () == QLocalSocket .ConnectionRefusedError :
42684281 socket .disconnectFromServer ()
4269- QLocalServer .removeServer (id )
4282+ QLocalServer .removeServer (self . UUID )
42704283
42714284 socket .abort ()
42724285
@@ -4278,7 +4291,7 @@ def __init__(self, *argv):
42784291 # Nope, create a local server with this id and assign on_new_connection
42794292 # for whenever a second instance tries to run focus the application.
42804293 self .server = QLocalServer ()
4281- self .server .listen (id )
4294+ self .server .listen (self . UUID )
42824295 self .server .newConnection .connect (self .on_new_connection )
42834296
42844297 self .setStyleSheet ("QStatusBar::item { border: 0px solid black }" )
@@ -4293,20 +4306,20 @@ def on_new_connection(self):
42934306
42944307
42954308def init ():
4296- global app
4309+ global app # pylint: disable=global-statement
42974310 if not app :
42984311 app = BitmessageQtApplication (sys .argv )
42994312 return app
43004313
43014314
43024315def run ():
4303- global myapp
4304- app = init ()
4305- myapp = MyForm ()
4316+ global myapp # pylint: disable=global-statement
4317+ _app = init ()
4318+ myapp = MyForm () # pylint: disable=redefined-outer-name
43064319
43074320 myapp .appIndicatorInit (app )
43084321
4309- if myapp ._firstrun :
4322+ if myapp ._firstrun : # pylint: disable=protected-access
43104323 myapp .showConnectDialog () # ask the user if we may connect
43114324
43124325 # only show after wizards and connect dialogs have completed
@@ -4315,4 +4328,4 @@ def run():
43154328 QtCore .QTimer .singleShot (
43164329 30000 , lambda : myapp .setStatusIcon (state .statusIconColor ))
43174330
4318- app .exec_ ()
4331+ _app .exec_ ()
0 commit comments