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

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 01-06-2019, 05:28 PM   #1
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 908
Karma: 1171905
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
[Editor Plugin] - Enabling 'Customize plugin' dialog directly from the Editor

Hi, everyone!

Firts of all, I am one BIG NOOB. So, if you can help me, please be as detailed as possible.

Here is the deal: I've created an Editor Plugin (ACE) and it is working fine.
It can be configured via Preferences > Plugin > Customize Plugin. It has a simple dialog with only 3 options.

What I want is to enable this configuration to take place directly from the Plugin Icon (actualy, a litle arrow beside it) on the Editor Plugins toolbar.

I've managed to create the menu entry 'Customize'.
On 'main.py', I'm calling 'ConfigWidget' from 'config.py'. Altough, I get no error, nothing happens when I click 'Customize'.

Relevant code on 'main.py':
Spoiler:
Code:
# Get config
import calibre_plugins.ACE.config as cfg

class AceTool(Tool):
    def create_action(self, for_toolbar=True):
        # Create an action, this will be added to the plugins toolbar and
        # the plugins menu
        ac = QAction(get_icon('images/icon.png'), msg_RUN, self.gui)
        if not for_toolbar:
            # Register a keyboard shortcut for this toolbar action. We only
            # register it for the action created for the menu, not the toolbar,
            # to avoid a double trigger
            self.register_shortcut(ac, 'ACE-tool', default_keys=('Ctrl+Shift+Alt+A',))
        else:
            menu = QMenu()
            ac.setMenu(menu)
            config_menu_item = menu.addAction(_('Customize'), cfg.ConfigWidget)

        ac.triggered.connect(self.ask_user)

Relevant code on 'config.py':
Spoiler:

Code:
class ConfigWidget(QWidget):

    def __init__(self):
        QWidget.__init__(self)
        layout = QVBoxLayout(self)
        self.setLayout(layout)

        # --- Directory Options ---
        directory_group_box = QGroupBox(_(msg_REPORT_FOLDER), self)
        layout.addWidget(directory_group_box)
        directory_group_box_layout = QVBoxLayout()
        directory_group_box.setLayout(directory_group_box_layout)

        # Directory path Textbox
        # Load the textbox with the current preference setting
        self.directory_txtBox = QLineEdit(plugin_prefs['report_path'], self)
        self.directory_txtBox.setToolTip(_(msg_REPORT_FOLDER_TEXT))
        directory_group_box_layout.addWidget(self.directory_txtBox)
        self.directory_txtBox.setReadOnly(True)

        # Folder select button
        directory_button = QPushButton(_(msg_SELECT_FOLDER), self)
        directory_button.setToolTip(_(msg_SELECT_FOLDER_HINT))
        # Connect button to the getDirectory function
        directory_button.clicked.connect(self.getDirectory)
        directory_group_box_layout.addWidget(directory_button)

        # Open report checkbox
        self.open_report_check = QCheckBox(_(msg_OPEN_REPORT), self)
        self.open_report_check.setToolTip(_(msg_OPEN_REPORT_HINT))
        directory_group_box_layout.addWidget(self.open_report_check)
        # Load the checkbox with the current preference setting
        self.open_report_check.setChecked(plugin_prefs['open_report'])

        # Debug checkbox
        self.debug_mode_check = QCheckBox(_(msg_DEBUG_MODE), self)
        self.debug_mode_check.setToolTip(_(msg_DEBUG_MODE_HINT))
        directory_group_box_layout.addWidget(self.debug_mode_check)
        # Load the checkbox with the current preference setting
        self.debug_mode_check.setChecked(plugin_prefs['debug_mode'])

    def save_settings(self):
        # Save current dialog sttings back to JSON config file
            plugin_prefs['report_path'] = unicode(self.directory_txtBox.displayText())
            plugin_prefs['open_report'] = self.open_report_check.isChecked()
            plugin_prefs['debug_mode'] = self.debug_mode_check.isChecked()

    def getDirectory(self):
        c = choose_dir(self, _(PLUGIN_NAME + 'dir_chooser'),
                _(msg_GET_DIR))
        if c:
            self.directory_txtBox.setReadOnly(False)
            self.directory_txtBox.setText(c)
            self.directory_txtBox.setReadOnly(True)

    def validate(self):
        # This is just to catch the situation where someone might
        # manually enter a non-existent path in the Default path textbox.
        # Shouldn't be possible at this point.
        if not os.path.exists(self.directory_txtBox.text()):
            errmsg = msg_ERRMSG
            error_dialog(None, _(PLUGIN_NAME + ' v' + PLUGIN_VERSION),
                                    _(errmsg), show=True)
            return False
        return True

In case the code provide above is not enough, I'm attaching the actual plugin.

Can anyone point me what I got wrong?
Attached Files
File Type: zip ACE.zip (11.5 KB, 286 views)
thiago.eec is offline   Reply With Quote
Old 01-06-2019, 08:40 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
First for language, you want:

Code:
if language[0] in ("pt_BR", "pt_PT", "pt")
more generally speaking you can eventually setup proper translations for the plugin, via Transifex.

Now for the config dialog , you have to link up the config menu item to some code to actually open the dialog, like this, in main.py:

Code:
    def do_config(self):
        from calibre.gui2.widgets2 import Dialog
        from calibre.gui2.tweak_book import tprefs
        from PyQt5.Qt import QVBoxLayout
        from calibre_plugins.ACE.config import ConfigWidget
        tool = self

        class ConfigDialog(Dialog):

            def __init__(self):
                Dialog.__init__(self, 'Configure ACE', 'plugin-ace-config-dialog', parent=tool.gui, prefs=tprefs)

            def setup_ui(self):
                self.l = QVBoxLayout(self)
                self.w = ConfigWidget()
                self.l.addWidget(self.w)

            def accept(self):
                if self.w.validate():
                    self.w.save_settings()
                    Dialog.accept(self)

        d = ConfigDialog()
        d.exec_()
link it up to you action like this:

Code:
            config_menu_item.triggered.connect(self.do_config)
kovidgoyal is offline   Reply With Quote
Old 01-07-2019, 05:02 AM   #3
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 908
Karma: 1171905
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
First for language, you want:

Code:
if language[0] in ("pt_BR", "pt_PT", "pt")
Thanks for the tip! This is the first time I ever used python, so I do a lot of things in a weird way. lol

Quote:
Originally Posted by kovidgoyal View Post
more generally speaking you can eventually setup proper translations for the plugin, via Transifex.
Sure. I'll prepare the code for extracting the strings and use POEDIT.
Just one question: supose I have the POT (and PO/MO) file, how do I add it to Transifex?

Quote:
Originally Posted by kovidgoyal View Post
Now for the config dialog , you have to link up the config menu item to some code to actually open the dialog, like this, in main.py:

Code:
    def do_config(self):
        from calibre.gui2.widgets2 import Dialog
        from calibre.gui2.tweak_book import tprefs
        from PyQt5.Qt import QVBoxLayout
        from calibre_plugins.ACE.config import ConfigWidget
        tool = self

        class ConfigDialog(Dialog):

            def __init__(self):
                Dialog.__init__(self, 'Configure ACE', 'plugin-ace-config-dialog', parent=tool.gui, prefs=tprefs)

            def setup_ui(self):
                self.l = QVBoxLayout(self)
                self.w = ConfigWidget()
                self.l.addWidget(self.w)

            def accept(self):
                if self.w.validate():
                    self.w.save_settings()
                    Dialog.accept(self)

        d = ConfigDialog()
        d.exec_()
link it up to you action like this:

Code:
            config_menu_item.triggered.connect(self.do_config)
It worked perfectly. Thank you very much, Kovid! You are great.
thiago.eec is offline   Reply With Quote
Old 01-08-2019, 03:11 PM   #4
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 908
Karma: 1171905
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
more generally speaking you can eventually setup proper translations for the plugin, via Transifex.
Thanks again for the help, Kovid.
Got everthing working and using MO files for translation.
Attached Files
File Type: zip ACE_v_0.3.0.zip (13.3 KB, 278 views)
thiago.eec is offline   Reply With Quote
Old 01-08-2019, 11:31 PM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
cool, you are welcome. If you wish to extract the translations into transifex, the best way to do it is to setup a guthub project for you plugin, have the .pot file there, then I can add the plugin to calibre-plugins on transifex and have it update the translations automatically from there. See for example how the SmartEject or PrincePDF plugins do their translations.
kovidgoyal is offline   Reply With Quote
Old 01-09-2019, 11:24 AM   #6
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 908
Karma: 1171905
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
cool, you are welcome. If you wish to extract the translations into transifex, the best way to do it is to setup a guthub project for you plugin, have the .pot file there, then I can add the plugin to calibre-plugins on transifex and have it update the translations automatically from there. See for example how the SmartEject or PrincePDF plugins do their translations.
Thanks, Kovid.

I think it is all set: https://github.com/thiagoeec/ACE.
Please take I look if this is ok for integration with Transifex.
thiago.eec is offline   Reply With Quote
Old 01-09-2019, 07:08 PM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I have added it to transifex: https://www.transifex.com/calibre/calibre-plugins/ace/
kovidgoyal is offline   Reply With Quote
Old 01-09-2019, 08:05 PM   #8
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 908
Karma: 1171905
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
I've pushed the pt_BR.po file and it is working as expected.

Thank you, Kovid.
thiago.eec is offline   Reply With Quote
Reply

Tags
customize, editor plugin, menu

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Editor Plugin] EpubCheck Doitsu Plugins 146 09-07-2023 01:43 PM
[Editor Plugin] LanguageTool Doitsu Plugins 7 12-12-2019 08:56 PM
Open Metadata Editor from plugin notbuu Development 5 10-05-2016 12:10 AM
Sample Plugin for the Editor DiapDealer Editor 77 12-10-2014 07:16 AM
Editor plugin question DiapDealer Development 2 07-28-2014 10:23 PM


All times are GMT -4. The time now is 02:23 AM.


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