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,12 @@ 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
12261234 def loadSent (self , tableWidget , account , where = "" , what = "" ):
1235+ """Load Sent items from database"""
12271236 if tableWidget == self .ui .tableWidgetInboxSubscriptions :
12281237 tableWidget .setColumnHidden (0 , True )
12291238 tableWidget .setColumnHidden (1 , False )
@@ -1241,7 +1250,7 @@ def loadSent(self, tableWidget, account, where="", what=""):
12411250 xAddress , account , "sent" , where , what , False )
12421251
12431252 for row in queryreturn :
1244- self .addMessageListItemSent (tableWidget , * row )
1253+ MyForm .addMessageListItemSent (tableWidget , * row )
12451254
12461255 tableWidget .horizontalHeader ().setSortIndicator (
12471256 3 , QtCore .Qt .DescendingOrder )
@@ -1250,11 +1259,11 @@ def loadSent(self, tableWidget, account, where="", what=""):
12501259 _translate ("MainWindow" , "Sent" ))
12511260 tableWidget .setUpdatesEnabled (True )
12521261
1253- # Load messages from database file
12541262 def loadMessagelist (
12551263 self , tableWidget , account , folder = "inbox" , where = "" , what = "" ,
12561264 unreadOnly = False
12571265 ):
1266+ """Load messages from database file"""
12581267 tableWidget .setUpdatesEnabled (False )
12591268 tableWidget .setSortingEnabled (False )
12601269 tableWidget .setRowCount (0 )
@@ -1282,7 +1291,7 @@ def loadMessagelist(
12821291
12831292 for row in queryreturn :
12841293 toAddress , fromAddress , subject , _ , msgid , received , read = row
1285- self .addMessageListItemInbox (
1294+ MyForm .addMessageListItemInbox (
12861295 tableWidget , toAddress , fromAddress , subject ,
12871296 msgid , received , read )
12881297
@@ -1359,8 +1368,9 @@ def appIndicatorInit(self, _app):
13591368 self .tray .setContextMenu (m )
13601369 self .tray .show ()
13611370
1362- # returns the number of unread messages and subscriptions
1363- def getUnread (self ):
1371+ @staticmethod
1372+ def getUnread ():
1373+ """returns the number of unread messages and subscriptions"""
13641374 counters = [0 , 0 ]
13651375
13661376 queryreturn = sqlQuery ('''
@@ -1443,8 +1453,9 @@ def _choose_ext(basename):
14431453
14441454 self ._player (soundFilename )
14451455
1446- # Adapters and converters for QT <-> sqlite
1447- def sqlInit (self ):
1456+ @staticmethod
1457+ def sqlInit ():
1458+ """Adapters and converters for QT <-> sqlite"""
14481459 register_adapter (QtCore .QByteArray , str )
14491460
14501461 def indicatorInit (self ):
@@ -1813,15 +1824,16 @@ def setStatusIcon(self, color):
18131824 def initTrayIcon (self , iconFileName , _app ):
18141825 self .currentTrayIconFileName = iconFileName
18151826 self .tray = QtGui .QSystemTrayIcon (
1816- self .calcTrayIcon (iconFileName ,
1817- self .findInboxUnreadCount ()),
1827+ MyForm .calcTrayIcon (iconFileName ,
1828+ self .findInboxUnreadCount ()),
18181829 _app )
18191830
18201831 def setTrayIconFile (self , iconFileName ):
18211832 self .currentTrayIconFileName = iconFileName
18221833 self .drawTrayIcon (iconFileName , self .findInboxUnreadCount ())
18231834
1824- def calcTrayIcon (self , iconFileName , inboxUnreadCount ):
1835+ @staticmethod
1836+ def calcTrayIcon (iconFileName , inboxUnreadCount ):
18251837 pixmap = QtGui .QPixmap (":/newPrefix/images/" + iconFileName )
18261838 if inboxUnreadCount > 0 :
18271839 # choose font and calculate font parameters
@@ -1854,7 +1866,8 @@ def calcTrayIcon(self, iconFileName, inboxUnreadCount):
18541866 return QtGui .QIcon (pixmap )
18551867
18561868 def drawTrayIcon (self , iconFileName , inboxUnreadCount ):
1857- self .tray .setIcon (self .calcTrayIcon (iconFileName , inboxUnreadCount ))
1869+ self .tray .setIcon (MyForm .calcTrayIcon (iconFileName ,
1870+ inboxUnreadCount ))
18581871
18591872 def changedInboxUnread (self , row = None ):
18601873 self .drawTrayIcon (
@@ -3978,12 +3991,12 @@ def on_context_menuInbox(self, point):
39783991 popMenuInbox .addAction (self .actionReply )
39793992 popMenuInbox .addAction (self .actionAddSenderToAddressBook )
39803993 # pylint: disable=no-member
3981- self . actionClipboardMessagelist = self .ui .inboxContextMenuToolbar .addAction (
3994+ actionClipboardMessagelist = self .ui .inboxContextMenuToolbar .addAction (
39823995 _translate ("MainWindow" , "Copy subject to clipboard" )
39833996 if tableWidget .currentColumn () == 2 else
39843997 _translate ("MainWindow" , "Copy address to clipboard" ),
39853998 self .on_action_ClipboardMessagelist )
3986- popMenuInbox .addAction (self . actionClipboardMessagelist )
3999+ popMenuInbox .addAction (actionClipboardMessagelist )
39874000 # pylint: disable=no-member
39884001 self ._contact_selected = tableWidget .item (currentRow , 1 )
39894002 # preloaded gui.menu plugins with prefix 'address'
@@ -4229,7 +4242,7 @@ class BitmessageQtApplication(QtGui.QApplication):
42294242 """
42304243
42314244 # Unique identifier for this application
4232- uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
4245+ UUID = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
42334246
42344247 @staticmethod
42354248 def get_windowstyle ():
@@ -4241,7 +4254,6 @@ def get_windowstyle():
42414254
42424255 def __init__ (self , * argv ):
42434256 super (BitmessageQtApplication , self ).__init__ (* argv )
4244- id = BitmessageQtApplication .uuid
42454257
42464258 QtCore .QCoreApplication .setOrganizationName ("PyBitmessage" )
42474259 QtCore .QCoreApplication .setOrganizationDomain ("bitmessage.org" )
@@ -4259,14 +4271,14 @@ def __init__(self, *argv):
42594271 self .is_running = False
42604272
42614273 socket = QLocalSocket ()
4262- socket .connectToServer (id )
4274+ socket .connectToServer (self . UUID )
42634275 self .is_running = socket .waitForConnected ()
42644276
42654277 # Cleanup past crashed servers
42664278 if not self .is_running :
42674279 if socket .error () == QLocalSocket .ConnectionRefusedError :
42684280 socket .disconnectFromServer ()
4269- QLocalServer .removeServer (id )
4281+ QLocalServer .removeServer (self . UUID )
42704282
42714283 socket .abort ()
42724284
@@ -4278,7 +4290,7 @@ def __init__(self, *argv):
42784290 # Nope, create a local server with this id and assign on_new_connection
42794291 # for whenever a second instance tries to run focus the application.
42804292 self .server = QLocalServer ()
4281- self .server .listen (id )
4293+ self .server .listen (self . UUID )
42824294 self .server .newConnection .connect (self .on_new_connection )
42834295
42844296 self .setStyleSheet ("QStatusBar::item { border: 0px solid black }" )
@@ -4293,20 +4305,20 @@ def on_new_connection(self):
42934305
42944306
42954307def init ():
4296- global app
4308+ global app # pylint: disable=global-statement
42974309 if not app :
42984310 app = BitmessageQtApplication (sys .argv )
42994311 return app
43004312
43014313
43024314def run ():
4303- global myapp
4304- app = init ()
4305- myapp = MyForm ()
4315+ global myapp # pylint: disable=global-statement
4316+ _app = init ()
4317+ myapp = MyForm () # pylint: disable=redefined-outer-name
43064318
43074319 myapp .appIndicatorInit (app )
43084320
4309- if myapp ._firstrun :
4321+ if myapp ._firstrun : # pylint: disable=protected-access
43104322 myapp .showConnectDialog () # ask the user if we may connect
43114323
43124324 # only show after wizards and connect dialogs have completed
@@ -4315,4 +4327,4 @@ def run():
43154327 QtCore .QTimer .singleShot (
43164328 30000 , lambda : myapp .setStatusIcon (state .statusIconColor ))
43174329
4318- app .exec_ ()
4330+ _app .exec_ ()
0 commit comments