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,too-many-nested-blocks
6+ # pylint: disable=too-many-return-statements
7+ # pylint: disable=too-many-boolean-expressions
58import hashlib
69import locale
710import os
@@ -760,6 +763,11 @@ def __init__(self, parent=None):
760763
761764 self .unreadCount = 0
762765
766+ self .currentTrayIconFileName = ""
767+ self .actionQuiet = None
768+ self .actionShow = None
769+ self .tray = None
770+
763771 # Set the icon sizes for the identicons
764772 identicon_size = 3 * 7
765773 self .ui .tableWidgetInbox .setIconSize (QtCore .QSize (identicon_size , identicon_size ))
@@ -843,7 +851,7 @@ def __init__(self, parent=None):
843851
844852 self .initSettings ()
845853 self .resetNamecoinConnection ()
846- self .sqlInit ()
854+ MyForm .sqlInit ()
847855 self .indicatorInit ()
848856 self .notifierInit ()
849857 self .updateStartOnLogon ()
@@ -1107,7 +1115,8 @@ def propagateUnreadCount(self, folder=None, widget=None):
11071115 if newCount != folderItem .unreadCount :
11081116 folderItem .setUnreadCount (newCount )
11091117
1110- def addMessageListItem (self , tableWidget , items ):
1118+ @staticmethod
1119+ def addMessageListItem (tableWidget , items ):
11111120 sortingEnabled = tableWidget .isSortingEnabled ()
11121121 if sortingEnabled :
11131122 tableWidget .setSortingEnabled (False )
@@ -1117,8 +1126,9 @@ def addMessageListItem(self, tableWidget, items):
11171126 if sortingEnabled :
11181127 tableWidget .setSortingEnabled (True )
11191128
1129+ @staticmethod
11201130 def addMessageListItemSent (
1121- self , tableWidget , toAddress , fromAddress , subject ,
1131+ tableWidget , toAddress , fromAddress , subject ,
11221132 status , ackdata , lastactiontime
11231133 ):
11241134 acct = accountClass (fromAddress ) or BMAccount (fromAddress )
@@ -1191,12 +1201,13 @@ def addMessageListItemSent(
11911201 str (subject ), text_type (acct .subject , 'utf-8' , 'replace' )),
11921202 MessageList_TimeWidget (
11931203 statusText , False , lastactiontime , ackdata )]
1194- self .addMessageListItem (tableWidget , items )
1204+ MyForm .addMessageListItem (tableWidget , items )
11951205
11961206 return acct
11971207
1208+ @staticmethod
11981209 def addMessageListItemInbox (
1199- self , tableWidget , toAddress , fromAddress , subject ,
1210+ tableWidget , toAddress , fromAddress , subject ,
12001211 msgid , received , read
12011212 ):
12021213 if toAddress == str_broadcast_subscribers :
@@ -1218,12 +1229,12 @@ def addMessageListItemInbox(
12181229 MessageList_TimeWidget (
12191230 l10n .formatTimestamp (received ), not read , received , msgid )
12201231 ]
1221- self .addMessageListItem (tableWidget , items )
1232+ MyForm .addMessageListItem (tableWidget , items )
12221233
12231234 return acct
12241235
1225- # Load Sent items from database
12261236 def loadSent (self , tableWidget , account , where = "" , what = "" ):
1237+ """Load Sent items from database"""
12271238 if tableWidget == self .ui .tableWidgetInboxSubscriptions :
12281239 tableWidget .setColumnHidden (0 , True )
12291240 tableWidget .setColumnHidden (1 , False )
@@ -1241,7 +1252,7 @@ def loadSent(self, tableWidget, account, where="", what=""):
12411252 xAddress , account , "sent" , where , what , False )
12421253
12431254 for row in queryreturn :
1244- self .addMessageListItemSent (tableWidget , * row )
1255+ MyForm .addMessageListItemSent (tableWidget , * row )
12451256
12461257 tableWidget .horizontalHeader ().setSortIndicator (
12471258 3 , QtCore .Qt .DescendingOrder )
@@ -1250,11 +1261,11 @@ def loadSent(self, tableWidget, account, where="", what=""):
12501261 _translate ("MainWindow" , "Sent" ))
12511262 tableWidget .setUpdatesEnabled (True )
12521263
1253- # Load messages from database file
12541264 def loadMessagelist (
12551265 self , tableWidget , account , folder = "inbox" , where = "" , what = "" ,
12561266 unreadOnly = False
12571267 ):
1268+ """Load messages from database file"""
12581269 tableWidget .setUpdatesEnabled (False )
12591270 tableWidget .setSortingEnabled (False )
12601271 tableWidget .setRowCount (0 )
@@ -1282,7 +1293,7 @@ def loadMessagelist(
12821293
12831294 for row in queryreturn :
12841295 toAddress , fromAddress , subject , _ , msgid , received , read = row
1285- self .addMessageListItemInbox (
1296+ MyForm .addMessageListItemInbox (
12861297 tableWidget , toAddress , fromAddress , subject ,
12871298 msgid , received , read )
12881299
@@ -1359,8 +1370,9 @@ def appIndicatorInit(self, _app):
13591370 self .tray .setContextMenu (m )
13601371 self .tray .show ()
13611372
1362- # returns the number of unread messages and subscriptions
1363- def getUnread (self ):
1373+ @staticmethod
1374+ def getUnread ():
1375+ """returns the number of unread messages and subscriptions"""
13641376 counters = [0 , 0 ]
13651377
13661378 queryreturn = sqlQuery ('''
@@ -1443,8 +1455,9 @@ def _choose_ext(basename):
14431455
14441456 self ._player (soundFilename )
14451457
1446- # Adapters and converters for QT <-> sqlite
1447- def sqlInit (self ):
1458+ @staticmethod
1459+ def sqlInit ():
1460+ """Adapters and converters for QT <-> sqlite"""
14481461 register_adapter (QtCore .QByteArray , str )
14491462
14501463 def indicatorInit (self ):
@@ -1813,15 +1826,16 @@ def setStatusIcon(self, color):
18131826 def initTrayIcon (self , iconFileName , _app ):
18141827 self .currentTrayIconFileName = iconFileName
18151828 self .tray = QtGui .QSystemTrayIcon (
1816- self .calcTrayIcon (iconFileName ,
1817- self .findInboxUnreadCount ()),
1829+ MyForm .calcTrayIcon (iconFileName ,
1830+ self .findInboxUnreadCount ()),
18181831 _app )
18191832
18201833 def setTrayIconFile (self , iconFileName ):
18211834 self .currentTrayIconFileName = iconFileName
18221835 self .drawTrayIcon (iconFileName , self .findInboxUnreadCount ())
18231836
1824- def calcTrayIcon (self , iconFileName , inboxUnreadCount ):
1837+ @staticmethod
1838+ def calcTrayIcon (iconFileName , inboxUnreadCount ):
18251839 pixmap = QtGui .QPixmap (":/newPrefix/images/" + iconFileName )
18261840 if inboxUnreadCount > 0 :
18271841 # choose font and calculate font parameters
@@ -1854,7 +1868,8 @@ def calcTrayIcon(self, iconFileName, inboxUnreadCount):
18541868 return QtGui .QIcon (pixmap )
18551869
18561870 def drawTrayIcon (self , iconFileName , inboxUnreadCount ):
1857- self .tray .setIcon (self .calcTrayIcon (iconFileName , inboxUnreadCount ))
1871+ self .tray .setIcon (MyForm .calcTrayIcon (iconFileName ,
1872+ inboxUnreadCount ))
18581873
18591874 def changedInboxUnread (self , row = None ):
18601875 self .drawTrayIcon (
@@ -1985,14 +2000,14 @@ def rerenderMessagelistToLabels(self):
19852000 def rerenderAddressBook (self ):
19862001 def addRow (address , label , row_type ):
19872002 self .ui .tableWidgetAddressBook .insertRow (0 )
1988- newItem = Ui_AddressBookWidgetItemLabel (address ,
1989- text_type (label , 'utf-8' ),
1990- row_type )
1991- self .ui .tableWidgetAddressBook .setItem (0 , 0 , newItem )
1992- newItem = Ui_AddressBookWidgetItemAddress (address ,
1993- text_type (label , 'utf-8' ),
1994- row_type )
1995- self .ui .tableWidgetAddressBook .setItem (0 , 1 , newItem )
2003+ newItemL = Ui_AddressBookWidgetItemLabel (address ,
2004+ text_type (label , 'utf-8' ),
2005+ row_type )
2006+ self .ui .tableWidgetAddressBook .setItem (0 , 0 , newItemL )
2007+ newItemA = Ui_AddressBookWidgetItemAddress (address ,
2008+ text_type (label , 'utf-8' ),
2009+ row_type )
2010+ self .ui .tableWidgetAddressBook .setItem (0 , 1 , newItemA )
19962011
19972012 oldRows = {}
19982013 for i in range (self .ui .tableWidgetAddressBook .rowCount ()):
@@ -2964,8 +2979,9 @@ def on_action_InboxMarkUnread(self):
29642979 # tableWidget.clearSelection() manages to mark the message
29652980 # as read again.
29662981
2967- # Format predefined text on message reply.
2968- def quoted_text (self , message ):
2982+ @staticmethod
2983+ def quoted_text (message ):
2984+ """Format predefined text on message reply."""
29692985 if not config .safeGetBoolean ('bitmessagesettings' , 'replybelow' ):
29702986 return '\n \n ------------------------------------------------------\n ' + message
29712987
@@ -3112,7 +3128,7 @@ def on_action_InboxReply(self, reply_type=None):
31123128
31133129 self .setSendFromComboBox (toAddressAtCurrentInboxRow )
31143130
3115- quotedText = self .quoted_text (
3131+ quotedText = MyForm .quoted_text (
31163132 text_type (messageAtCurrentInboxRow , 'utf-8' , 'replace' ))
31173133 widget ['message' ].setPlainText (quotedText )
31183134 if acct .subject [0 :3 ] in ('Re:' , 'RE:' ):
@@ -3978,12 +3994,12 @@ def on_context_menuInbox(self, point):
39783994 popMenuInbox .addAction (self .actionReply )
39793995 popMenuInbox .addAction (self .actionAddSenderToAddressBook )
39803996 # pylint: disable=no-member
3981- self . actionClipboardMessagelist = self .ui .inboxContextMenuToolbar .addAction (
3997+ actionClipboardMessagelist = self .ui .inboxContextMenuToolbar .addAction (
39823998 _translate ("MainWindow" , "Copy subject to clipboard" )
39833999 if tableWidget .currentColumn () == 2 else
39844000 _translate ("MainWindow" , "Copy address to clipboard" ),
39854001 self .on_action_ClipboardMessagelist )
3986- popMenuInbox .addAction (self . actionClipboardMessagelist )
4002+ popMenuInbox .addAction (actionClipboardMessagelist )
39874003 # pylint: disable=no-member
39884004 self ._contact_selected = tableWidget .item (currentRow , 1 )
39894005 # preloaded gui.menu plugins with prefix 'address'
@@ -4229,7 +4245,7 @@ class BitmessageQtApplication(QtGui.QApplication):
42294245 """
42304246
42314247 # Unique identifier for this application
4232- uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
4248+ UUID = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
42334249
42344250 @staticmethod
42354251 def get_windowstyle ():
@@ -4241,7 +4257,6 @@ def get_windowstyle():
42414257
42424258 def __init__ (self , * argv ):
42434259 super (BitmessageQtApplication , self ).__init__ (* argv )
4244- id = BitmessageQtApplication .uuid
42454260
42464261 QtCore .QCoreApplication .setOrganizationName ("PyBitmessage" )
42474262 QtCore .QCoreApplication .setOrganizationDomain ("bitmessage.org" )
@@ -4259,14 +4274,14 @@ def __init__(self, *argv):
42594274 self .is_running = False
42604275
42614276 socket = QLocalSocket ()
4262- socket .connectToServer (id )
4277+ socket .connectToServer (self . UUID )
42634278 self .is_running = socket .waitForConnected ()
42644279
42654280 # Cleanup past crashed servers
42664281 if not self .is_running :
42674282 if socket .error () == QLocalSocket .ConnectionRefusedError :
42684283 socket .disconnectFromServer ()
4269- QLocalServer .removeServer (id )
4284+ QLocalServer .removeServer (self . UUID )
42704285
42714286 socket .abort ()
42724287
@@ -4278,35 +4293,36 @@ def __init__(self, *argv):
42784293 # Nope, create a local server with this id and assign on_new_connection
42794294 # for whenever a second instance tries to run focus the application.
42804295 self .server = QLocalServer ()
4281- self .server .listen (id )
4282- self .server .newConnection .connect (self .on_new_connection )
4296+ self .server .listen (self . UUID )
4297+ self .server .newConnection .connect (MyForm .on_new_connection )
42834298
42844299 self .setStyleSheet ("QStatusBar::item { border: 0px solid black }" )
42854300
42864301 def __del__ (self ):
42874302 if self .server :
42884303 self .server .close ()
42894304
4290- def on_new_connection (self ):
4305+ @staticmethod
4306+ def on_new_connection ():
42914307 if myapp :
42924308 myapp .appIndicatorShow ()
42934309
42944310
42954311def init ():
4296- global app
4312+ global app # pylint: disable=global-statement
42974313 if not app :
42984314 app = BitmessageQtApplication (sys .argv )
42994315 return app
43004316
43014317
43024318def run ():
4303- global myapp
4304- app = init ()
4305- myapp = MyForm ()
4319+ global myapp # pylint: disable=global-statement
4320+ _app = init ()
4321+ myapp = MyForm () # pylint: disable=redefined-outer-name
43064322
43074323 myapp .appIndicatorInit (app )
43084324
4309- if myapp ._firstrun :
4325+ if myapp ._firstrun : # pylint: disable=protected-access
43104326 myapp .showConnectDialog () # ask the user if we may connect
43114327
43124328 # only show after wizards and connect dialogs have completed
@@ -4315,4 +4331,4 @@ def run():
43154331 QtCore .QTimer .singleShot (
43164332 30000 , lambda : myapp .setStatusIcon (state .statusIconColor ))
43174333
4318- app .exec_ ()
4334+ _app .exec_ ()
0 commit comments