3131 from Foundation import NSURL
3232 from Cocoa import NSString , NSUTF8StringEncoding
3333lastCheckedForUpdates = None
34+ from syncplay .vendor import darkdetect
35+ if isMacOS ():
36+ isDarkMode = darkdetect .isDark ()
37+ else :
38+ isDarkMode = None
3439
3540
3641class ConsoleInGUI (ConsoleUI ):
@@ -51,7 +56,8 @@ def getUserlist(self):
5156
5257
5358class UserlistItemDelegate (QtWidgets .QStyledItemDelegate ):
54- def __init__ (self ):
59+ def __init__ (self , view = None ):
60+ self .view = view
5561 QtWidgets .QStyledItemDelegate .__init__ (self )
5662
5763 def sizeHint (self , option , index ):
@@ -72,9 +78,10 @@ def paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex):
7278 roomController = currentQAbstractItemModel .data (itemQModelIndex , Qt .UserRole + constants .USERITEM_CONTROLLER_ROLE )
7379 userReady = currentQAbstractItemModel .data (itemQModelIndex , Qt .UserRole + constants .USERITEM_READY_ROLE )
7480 isUserRow = indexQModelIndex .parent () != indexQModelIndex .parent ().parent ()
81+ bkgColor = self .view .palette ().color (QtGui .QPalette .Base )
7582 if isUserRow and isMacOS ():
76- whiteRect = QtCore .QRect (0 , optionQStyleOptionViewItem .rect .y (), optionQStyleOptionViewItem .rect .width (), optionQStyleOptionViewItem .rect .height ())
77- itemQPainter .fillRect (whiteRect , QtGui . QColor ( Qt . white ) )
83+ blankRect = QtCore .QRect (0 , optionQStyleOptionViewItem .rect .y (), optionQStyleOptionViewItem .rect .width (), optionQStyleOptionViewItem .rect .height ())
84+ itemQPainter .fillRect (blankRect , bkgColor )
7885
7986 if roomController and not controlIconQPixmap .isNull ():
8087 itemQPainter .drawPixmap (
@@ -130,7 +137,11 @@ def __init__(self, parent=None):
130137 self .setWindowIcon (QtGui .QPixmap (resourcespath + 'syncplay.png' ))
131138 nameLabel = QtWidgets .QLabel ("<center><strong>Syncplay</strong></center>" )
132139 nameLabel .setFont (QtGui .QFont ("Helvetica" , 18 ))
133- linkLabel = QtWidgets .QLabel ("<center><a href=\" https://syncplay.pl\" >syncplay.pl</a></center>" )
140+ linkLabel = QtWidgets .QLabel ()
141+ if isDarkMode :
142+ linkLabel .setText (("<center><a href=\" https://syncplay.pl\" style=\" {}\" >syncplay.pl</a></center>" ).format (constants .STYLE_DARK_ABOUT_LINK_COLOR ))
143+ else :
144+ linkLabel .setText ("<center><a href=\" https://syncplay.pl\" >syncplay.pl</a></center>" )
134145 linkLabel .setOpenExternalLinks (True )
135146 versionExtString = version + revision
136147 versionLabel = QtWidgets .QLabel (
@@ -324,11 +335,17 @@ def updatePlaylistIndexIcon(self):
324335 fileIsAvailable = self .selfWindow .isFileAvailable (itemFilename )
325336 fileIsUntrusted = self .selfWindow .isItemUntrusted (itemFilename )
326337 if fileIsUntrusted :
327- self .item (item ).setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_UNTRUSTEDITEM_COLOR )))
338+ if isDarkMode :
339+ self .item (item ).setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_DARK_UNTRUSTEDITEM_COLOR )))
340+ else :
341+ self .item (item ).setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_UNTRUSTEDITEM_COLOR )))
328342 elif fileIsAvailable :
329- self .item (item ).setForeground (QtGui .QBrush (QtGui . QColor ( QtGui . QPalette . ColorRole (QtGui .QPalette .Text ) )))
343+ self .item (item ).setForeground (QtGui .QBrush (self . selfWindow . palette (). color (QtGui .QPalette .Text )))
330344 else :
331- self .item (item ).setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_DIFFERENTITEM_COLOR )))
345+ if isDarkMode :
346+ self .item (item ).setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_DARK_DIFFERENTITEM_COLOR )))
347+ else :
348+ self .item (item ).setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_DIFFERENTITEM_COLOR )))
332349 self .selfWindow ._syncplayClient .fileSwitch .setFilenameWatchlist (self .selfWindow .newWatchlist )
333350 self .forceUpdate ()
334351
@@ -605,24 +622,28 @@ def showUserList(self, currentUser, rooms):
605622 sameDuration = sameFileduration (user .file ['duration' ], currentUser .file ['duration' ])
606623 underlinefont = QtGui .QFont ()
607624 underlinefont .setUnderline (True )
625+ differentItemColor = constants .STYLE_DARK_DIFFERENTITEM_COLOR if isDarkMode else constants .STYLE_DIFFERENTITEM_COLOR
608626 if sameRoom :
609627 if not sameName :
610- filenameitem .setForeground (QtGui .QBrush (QtGui .QColor (constants . STYLE_DIFFERENTITEM_COLOR )))
628+ filenameitem .setForeground (QtGui .QBrush (QtGui .QColor (differentItemColor )))
611629 filenameitem .setFont (underlinefont )
612630 if not sameSize :
613631 if formatSize (user .file ['size' ]) == formatSize (currentUser .file ['size' ]):
614632 filesizeitem = QtGui .QStandardItem (formatSize (user .file ['size' ], precise = True ))
615633 filesizeitem .setFont (underlinefont )
616- filesizeitem .setForeground (QtGui .QBrush (QtGui .QColor (constants . STYLE_DIFFERENTITEM_COLOR )))
634+ filesizeitem .setForeground (QtGui .QBrush (QtGui .QColor (differentItemColor )))
617635 if not sameDuration :
618- filedurationitem .setForeground (QtGui .QBrush (QtGui .QColor (constants . STYLE_DIFFERENTITEM_COLOR )))
636+ filedurationitem .setForeground (QtGui .QBrush (QtGui .QColor (differentItemColor )))
619637 filedurationitem .setFont (underlinefont )
620638 else :
621639 filenameitem = QtGui .QStandardItem (getMessage ("nofile-note" ))
622640 filedurationitem = QtGui .QStandardItem ("" )
623641 filesizeitem = QtGui .QStandardItem ("" )
624642 if room == currentUser .room :
625- filenameitem .setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_NOFILEITEM_COLOR )))
643+ if isDarkMode :
644+ filenameitem .setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_DARK_NOFILEITEM_COLOR )))
645+ else :
646+ filenameitem .setForeground (QtGui .QBrush (QtGui .QColor (constants .STYLE_NOFILEITEM_COLOR )))
626647 font = QtGui .QFont ()
627648 if currentUser .username == user .username :
628649 font .setWeight (QtGui .QFont .Bold )
@@ -637,7 +658,7 @@ def showUserList(self, currentUser, rooms):
637658 roomitem .appendRow ((useritem , filesizeitem , filedurationitem , filenameitem ))
638659 self .listTreeModel = self ._usertreebuffer
639660 self .listTreeView .setModel (self .listTreeModel )
640- self .listTreeView .setItemDelegate (UserlistItemDelegate ())
661+ self .listTreeView .setItemDelegate (UserlistItemDelegate (view = self . listTreeView ))
641662 self .listTreeView .setItemsExpandable (False )
642663 self .listTreeView .setRootIsDecorated (False )
643664 self .listTreeView .expandAll ()
@@ -849,7 +870,10 @@ def showErrorMessage(self, message, criticalerror=False):
849870 message = message .replace ("&" , "&" ).replace ('"' , """ ).replace ("<" , "<" ).replace (">" , ">" )
850871 message = message .replace ("<a href="https://syncplay.pl/trouble">" , '<a href="https://syncplay.pl/trouble">' ).replace ("</a>" , "</a>" )
851872 message = message .replace ("\n " , "<br />" )
852- message = "<span style=\" {}\" >" .format (constants .STYLE_ERRORNOTIFICATION ) + message + "</span>"
873+ if isDarkMode :
874+ message = "<span style=\" {}\" >" .format (constants .STYLE_DARK_ERRORNOTIFICATION ) + message + "</span>"
875+ else :
876+ message = "<span style=\" {}\" >" .format (constants .STYLE_ERRORNOTIFICATION ) + message + "</span>"
853877 self .newMessage (time .strftime (constants .UI_TIME_FORMAT , time .localtime ()) + message + "<br />" )
854878
855879 @needsClient
@@ -1259,14 +1283,16 @@ def addTopLayout(self, window):
12591283
12601284 window .outputLayout = QtWidgets .QVBoxLayout ()
12611285 window .outputbox = QtWidgets .QTextBrowser ()
1286+ if isDarkMode : window .outputbox .document ().setDefaultStyleSheet (constants .STYLE_DARK_LINKS_COLOR );
12621287 window .outputbox .setReadOnly (True )
12631288 window .outputbox .setTextInteractionFlags (window .outputbox .textInteractionFlags () | Qt .TextSelectableByKeyboard )
12641289 window .outputbox .setOpenExternalLinks (True )
12651290 window .outputbox .unsetCursor ()
12661291 window .outputbox .moveCursor (QtGui .QTextCursor .End )
12671292 window .outputbox .insertHtml (constants .STYLE_CONTACT_INFO .format (getMessage ("contact-label" )))
12681293 window .outputbox .moveCursor (QtGui .QTextCursor .End )
1269- window .outputbox .setVerticalScrollBarPolicy (Qt .ScrollBarAlwaysOn )
1294+ window .outputbox .setCursorWidth (0 )
1295+ if not isMacOS (): window .outputbox .setVerticalScrollBarPolicy (Qt .ScrollBarAlwaysOn )
12701296
12711297 window .outputlabel = QtWidgets .QLabel (getMessage ("notifications-heading-label" ))
12721298 window .outputlabel .setMinimumHeight (27 )
@@ -1414,8 +1440,6 @@ def addBottomLayout(self, window):
14141440 playlistItem = QtWidgets .QListWidgetItem (getMessage ("playlist-instruction-item-message" ))
14151441 playlistItem .setFont (noteFont )
14161442 window .playlist .addItem (playlistItem )
1417- playlistItem .setFont (noteFont )
1418- window .playlist .addItem (playlistItem )
14191443 window .playlistLayout .addWidget (window .playlist )
14201444 window .playlistLayout .setAlignment (Qt .AlignTop )
14211445 window .playlistGroup .setLayout (window .playlistLayout )
0 commit comments