MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Post your Useful Plugin Code Fragments Here (https://www.mobileread.com/forums/showthread.php?t=268623)

slowsmile 12-18-2016 06:12 PM

@DiapDealer...That's strange. I haven't received your email yet. I've also checked my spam etc.

I'll send you another private email giving you my email address again, just in case I typed it wrong.

slowsmile 12-18-2016 09:49 PM

@DiapDealer...I received your second email without a problem and have just emailed you some info + plugin + test file. Much thanks for your help.

slowsmile 12-22-2016 06:39 AM

Here's another interesting BeautifulSoup snippet that I've just successfully used:

Code:

  # convert all html text to block text format       
    for tag in soup.findAll('p'):
        if tag.has_attr('style') and 'text-align: center' not in tag['style'].lower():
            del tag['style']
            tag['class'] = 'BlockText'

The above four lines of code will delete all 'style' attributes in p tags and then add the BlockText class - centered text will not be affected.

DiapDealer 01-27-2020 04:50 PM

Fairly self-contained Python code to make your PyQt5-based GUI plugin match Sigil's light/dark theme. It should be compatible with any version of Sigil that supports PyQt5 plugins. The dark theme just won't appear unless you're using Sigil 1.1.0 or higher.

Code:

def dark_palette(bk, app):
    supports_theming = (bk.launcher_version() >= 20200117)
    if not supports_theming:
        return
    if bk.colorMode() != "dark":
        return
    try:
        from PyQt5.QtCore import Qt
        from PyQt5.QtGui import QColor, QPalette
        from PyQt5.QtWidgets import QStyleFactory
    except ImportError:
        return

    p = QPalette()
    sigil_colors = bk.color
    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)

    app.setStyle(QStyleFactory.create("Fusion"))
    app.setPalette(p)

Then after you initialize your QApplication and before you show/exec it:

Code:

app = QApplication(sys.argv)
Add the following function call that takes the BookContainer object and QApplication object as parameters:

Code:

dark_palette(bk, app)
That's about it. Building your PyQt5 Application Widgets is up to you.

I may add some platform-specific tweaks and bug workarounds from time to time. I know for a fact there's some Mac color issues.


All times are GMT -4. The time now is 08:32 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.