View Single Post
Old 01-21-2020, 04:35 PM   #457
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,664
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
A crash course for those who roll their own Sigil and want to get a head start on dark-theming their PyQt5 plugins:

Code:
from PyQt5.QtWidgets import QApplication, QWidget, QStyleFactory
from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtCore import QCoreApplication, Qt

def dark_palette(sigil_colors):
    p = QPalette()
    dark_color = QColor(sigil_colors("Window"))
    disabled_color = QColor(127,127,127)
    dark_link_color = QColor(108, 180, 238)
    text_color = QColor(sigil_colors("Text"))
    p.setColor(p.Window, dark_color)
    p.setColor(p.WindowText, text_color)
    p.setColor(p.Base, QColor(sigil_colors("Base")))
    p.setColor(p.AlternateBase, dark_color)
    p.setColor(p.ToolTipBase, dark_color)
    p.setColor(p.ToolTipText, text_color)
    p.setColor(p.Text, text_color)
    p.setColor(p.Disabled, p.Text, disabled_color)
    p.setColor(p.Button, dark_color)
    p.setColor(p.ButtonText, text_color)
    p.setColor(p.Disabled, p.ButtonText, disabled_color)
    p.setColor(p.BrightText, Qt.red)
    p.setColor(p.Link, dark_link_color)

    p.setColor(p.Highlight, QColor(sigil_colors("Highlight")))
    p.setColor(p.HighlightedText, QColor(sigil_colors("HighlightedText")))
    p.setColor(p.Disabled, p.HighlightedText, disabled_color)

    return p

class MyQWidget(QWidget):
    def __init__(self, bk, prefs):
        blah
        blah
        blah

def run(bk):
    prefs = bk.getPrefs()
    supports_theming = (bk.launcher_version() >= 20200117)
    app = QApplication(sys.argv)
    if supports_theming:
        if bk.colorMode() == "dark":
            # The Windows Sigil darkmode is created with the Fusion style as
            # the basis for Sigil's dark palette. Macs may prefer starting elsewhere.
            # Though "Fusion" should suffice for all three platforms without a lot of fuss.
            app.setStyle(QStyleFactory.create("Fusion"))
            app.setPalette(dark_palette(bk.color))
    ex = MyQWidget(bk, prefs)
    ex.show()
    app.exec_()
Clearly you'd have to create your own MyQWidget class in this case, but I leave that up to you. There's many ways tackle creating PyQt5 plugin interfaces. That's nothing to do with theming. I should have a working version of my DOCXImport plugin that will support dark-mode ready for uploading soon. So people will be able to copy/paste from that as well.

Last edited by DiapDealer; 01-21-2020 at 04:47 PM.
DiapDealer is offline   Reply With Quote