Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 11-17-2019, 08:42 AM   #451
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: 21,806
Karma: 120485668
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Vroni View Post
or is something availöable in the API to make use of?
We've been mentioning the new stuff available in the api all along.

There's the group functions which return the locations of the different mimetypes (where are the xhtml files being kept, where are the css files stored, where is the opf?). Then there's still the href from the iter functions that can be used in combination with the group data (or the relative link between two hrefs just discussed) and other things.

It's not a matter of not being able to "trust" that certain locations will be present. It's a matter of switching to new methods/paradigms that don't make hard-coded assumptions about where things always used to be.

Examples of all this are in the plugins that have already been updated to accommodate non-standard (as well as standard) epub structures.

If you have any specific code-related questions as to how to perform a certain task, feel fee to ask--in words OR in Python.

Last edited by DiapDealer; 11-17-2019 at 08:45 AM.
DiapDealer is online now   Reply With Quote
Old 11-17-2019, 10:28 AM   #452
KevinH
Wizard
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 4,161
Karma: 2620702
Join Date: Nov 2009
Device: many
Yes bk.addfile() still works as before. It will check the filename to make sure it is unique and the add the file to the current default folder for that file group. The id is returned and you can always do a bk.id_to_bookpath() routine to get the resulting bookpath.

Or you can get the folders to be used via file group and choose among them if there is more than one, etc.

Or you can create your own bookpath and pass that to the new way to add a file.
KevinH is offline   Reply With Quote
Old 11-17-2019, 10:32 AM   #453
Vroni
Banned
Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'
 
Posts: 168
Karma: 10010
Join Date: Oct 2018
Device: Tolino/PRS 650/Tablet
Creating a new xhtml file. Currently i "just" need to place an entry in the spine (getspine; setspine) and then just call addfile. Theres no other place it can go right now as in the TEXT folder. In the new version, it can go anywhere and i have to query the user where it should be stored...

Vroni
Vroni is offline   Reply With Quote
Old 11-17-2019, 11:19 AM   #454
KevinH
Wizard
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 4,161
Karma: 2620702
Join Date: Nov 2009
Device: many
Or just do as before and use the default folder for that group (type of file). Actually, I think adding an xhtml file in the plugin should auto handle the spine for you (but it has been a long time since I checked that code).
KevinH is offline   Reply With Quote
Old 11-17-2019, 11:29 AM   #455
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: 21,806
Karma: 120485668
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by KevinH View Post
Or just do as before and use the default folder for that group (type of file).
Agreed.

You're free to query the user for as little, or as much info as you like. They didn't have a choice in where your newly-created xhtml file went before, and they don't really need a choice now (unless you want to give them one). The physical location of the xhtml file in the archive has no functional relevance to how the epub will render. That is taken care of by the spine section in the opf. If after your plugin is done, the user doesn't like where the file is physically located, we've given them the tools to put it wherever they want.
DiapDealer is online now   Reply With Quote
Old 01-21-2020, 12:35 PM   #456
KevinH
Wizard
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 4,161
Karma: 2620702
Join Date: Nov 2009
Device: many
New Plugin Interface Routines for the Next Release of Sigil

For the upcoming release of Sigil, we have added some capability to use dark mode because for some end-users who use plugins, the white background of a plugin gui elements may be a bit jarring under dark mode.

For plugins using tk widgets on macOSX, the tk widgets will automatically take on the dark mode of macOS as long as a recent (version 8.6.10 or later) release of TCl/Tk is installed on the system and Python 3.7 has been compiled against it. The next macOS release of Sigil will have been properly compiled to support dark mode. So macOS users with a recent Tcl/Tk version should get dark mode with no further work.

For plugins that use pyqt5 (or tk on platforms other than macOS), we have extended the plugin interface to provide some colour related information as follows:

Code:
    # New in Sigil 1.1                                                                                              
    # ----------------                                                                                              

    # returns "light" or "dark"                                                                                     
    def colorMode(self):
        return self._w.colorMode()

    # returns color as css or javascript hex color string "#xxxxxx"                                                 
    # acccepts the following color roles in a case insensitive manner:                                              
    #    "Window", "Base", "Text", "Highlight", "HighlightedText"                                                   
    def color(self, role):
        return self._w.color(role)
Sigil master now supports these routines for bk.launcher_version() >= 20200117:

Plugin developers will be able to determine if the system/Sigil is using dark or light mode and get some basic colour information (#XXXXXX). Using this additional information, plugin developers could change their gui to use these colours (in either or both light and dark modes). The colour roles used here match the colour roles used in Qt. See QPalette and etc.

Hope this helps,

KevinH and DiapDealer
KevinH is offline   Reply With Quote
Old 01-21-2020, 05: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: 21,806
Karma: 120485668
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 05:47 PM.
DiapDealer is online now   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading Plugin in development Sladd Development 6 06-17-2014 07:57 PM
Question for plugin development gurus DiapDealer Plugins 2 02-05-2012 12:33 AM
DR800 Plugin development for DR800/DR1000 yuri_b iRex Developer's Corner 0 09-18-2010 10:46 AM
Device plugin development reader42 Plugins 10 03-29-2010 01:39 PM
Calibre plugin development - Newbie problems minstrel Plugins 5 04-12-2009 01:44 PM


All times are GMT -4. The time now is 09:35 PM.


MobileRead.com is a privately owned, operated and funded community.