02-03-2011, 06:28 PM | #1 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
config_widget doesn't allow early exit
When using config_widget to customize my plugin, I want to check if certain conditions are met (device connected) and if not show an error dialog and exit the routine. I can do the check and dialog and exit, but not cleanly.
I noticed in the source that I can return None or raise a NotImplemented error or a QWidget. I currently return None so that the customization_help routine runs with my error message. But this shows a text entry box under the text message I display. Using a QWidget is just as messy as it requires and shows an empty table. Raising the error causes an error message. Any suggestions of code to use in config_widget to show just an error dialog and exit? Is there a pre-validate method to match the validate method? |
02-03-2011, 06:39 PM | #2 |
creator of calibre
Posts: 43,771
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
why not just return a QLabel as the widget with the error message
|
Advert | |
|
02-03-2011, 06:54 PM | #3 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Sounds great - I'll give it a go. There's still a lot to learn about python and QT.
|
02-03-2011, 07:20 PM | #4 | |
calibre/Sigil Developer
Posts: 4,601
Karma: 2092290
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
Also you will still need to detect your "error" situation in validate and return False from that to prevent save_settings from being invoked. |
|
02-03-2011, 09:57 PM | #5 |
creator of calibre
Posts: 43,771
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Since you (the plugin author) implement save_settings, it should be trivial to detect the case when the config widget is showing an error message and do nothing.
|
Advert | |
|
02-03-2011, 10:06 PM | #6 |
calibre/Sigil Developer
Posts: 4,601
Karma: 2092290
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Indeed - I was just publicly "filling in the gaps" to indicate that returning a QLabel with an error message would in all likelihood not be the only code required to handle this scenario. As of course you would know...
|
02-04-2011, 03:24 AM | #7 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Yes, I had to adapt save_settings to check for errors - I already did, but as a first pass added a exception handler for _table not existing although that doesn't seem as clean as I like.
I do end up with a rather large window, and Cancel/OK buttons even though I'd rather just have an OK like an error dialog. |
02-04-2011, 05:40 AM | #8 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Figured it out - I was looking too deep into the routines. I backtracked to see what was calling what and realized I could avoid calling config_widget within my code. I've simply edited the show_configuration method to do the necessary checks before calling the do_user_config method so I can avoid creating a window altogether. Much better.
|
02-13-2011, 08:29 AM | #9 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Actually, doing the checks in show_configuration doesn't work well. Its fine from the Customization menu item I created, but not when customization is done from the Preferences menu. I can add code in both places, but I think I'll just do all the checking in config_widget.
So one way is to do my checks in config_widget, and return a QLabel if there's an error. But the dialog box is large (saved from whatever size was last used) and doesn't look right with a small error messages. And it says OK or Cancel when in fact you just want the user to click OK since two options on an error message is confusing. I actually use my own routines to show up error/warning/info dialogs depending on the issue so I don't need do_user_config to show a window, but I can work with it if there's a way to get it to resize and just show an OK button. Some options, as mentioned above could be: 1. Run a pre-check method if defined. If false, don't show the window or do anything (assumes plugin handles user warnings, etc.) 2. In do_user_config, if config_widget is defined but returns None, don't show the window or do anything 3. If config_widget returns a simple QLabel, just show the label in a correctly sized window/dialog and a single OK button on the window - and exit after OK is clicked without validation or saving. In the meantime I think I'll just live with the large text box since its only supposed to appear if you've done something wrong. |
02-13-2011, 09:44 AM | #10 |
creator of calibre
Posts: 43,771
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I just committed code that allows you to return a tuple (msg, details) from config_widget() that will cause a warning dialog to be shown and the process to abort.
|
02-13-2011, 11:58 AM | #11 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Terrific. Once the new version is released I'll give it a go.
And now I see how to use the warning dialogs properly get my warning messages into a detailed text box so they don't overflow the screen |
02-19-2011, 03:26 AM | #12 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
The new code works great - dialog displays exactly as needed. Thank you.
|
02-19-2011, 11:42 AM | #13 |
creator of calibre
Posts: 43,771
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You're welcome
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
calibredb exit codes? | mcqueary | Calibre | 1 | 01-02-2011 11:56 AM |
Howto EXIT browser on K3 ? | pchrist7 | Amazon Kindle | 2 | 09-10-2010 11:15 AM |
iPhone iPhone 4 Shipping Early (+ some early reviews as they come in) | kjk | Apple Devices | 17 | 06-24-2010 04:17 PM |
Review of Exit Pursued by a Bee | Chriskander | Reading Recommendations | 0 | 04-05-2010 08:43 PM |
How to exit from minimo? | artur | iRex | 2 | 08-03-2008 03:43 PM |