06-19-2012, 07:34 AM | #16 | ||
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The .ui files are built by the Qt tool "designer", a fairly vanilla graphical gui builder tool. In some cases they are built by hand when "designer" doesn't do what one wants or when it is easier to modify an existing file. When calibre starts, the dates on the .ui files are compared to those of the _ui.py files. If the .ui file is newer, it is "compiled" into python that is stored in the _ui.py file, which is imported by the code that needs to manipulate the resulting gui. Quote:
numeric_version = (0, 8, 56) |
||
06-19-2012, 07:47 AM | #17 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
This all being a perfect example to agama's other question about whether to update or not - calibre changes very frequently, and you are looking at code that Kovid rewrote recently to support tweaking things other than ePub. So you are tiptoeing on quicksand in this case
Re the .ui files thing - from a calibre plugin perspective I have always avoided them. When I first started writing plugins there were question marks over compiling code in plugins etc that were never completely answered at the time. The Qt designer is not sufficiently more productive to have ever got me bothered about revisiting it. So every plugin dialog I have written just has handwritten dialog code, similar to the net effect of using the designer, then compiling the code, then including that in your plugin, I find it faster for my purposes anyways. In the calibre code you will find a mixture - some dialogs are handcoded in the same way, whereas the majority of the calibre gui uses those UI files. My advice would be to not bother with adding another learning curve of the Qt Designer especially given your plugin doesn't even really need a UI from what you have described, but that's just my opinion |
Advert | |
|
06-19-2012, 01:38 PM | #18 |
Guru
Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
My source is (0, 8, 10).
How often is it a good idea to update and how do I do it? (or is this a "How long is a piece of string" question?). Does it require another full download? (This took nearly 2 hours first time round). My plugin just needs a simple configuration item so I won't be delving into UI code just yet. |
06-19-2012, 04:30 PM | #19 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
- I don't want to be confused by something that behaves differently from what the code says it should do. - I want to see bug fixes. - Looking at changes, and especially the refactoring changes, is a good way to learn. - I don't want to change code that is no longer in calibre. I always update before submitting code to be sure that I am not submitting something that won't work or that conflicts with some other change. Of course, if you are not doing development on calibre's trunk (as I do) and are not depending on the code you are looking at being correct (as I am), then there is no requirement to upgrade. In the end, the decision is yours. As for how to upgrade, running "bzr pull" from inside the source tree will get all the changes from the last time you did a pull/download. This will work only if you have not made any changes to a file under version control. If you have made changes, then you can toss the changes into the trash can using "bzr revert". You might (or might not) want to use the --no-backup option. If you have made changes you want to keep, then things are more complicated. In your case, the first "pull" will take a while because it must download so many versions, but it will take less time than a full download. I find that daily pulls run in seconds. The exception is Friday after a release when all the translations are downloaded, in which case it can sometimes take nearly a minute but usually run in around 30 seconds. I have a very fast internet connection (100 Mbit), so your mileage could easily be worse than mine. |
|
06-24-2012, 11:10 AM | #20 |
Guru
Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
The source update only took about 30 mins and Tweak ePub had indeed changed. I finally got version 1 of my plugin working and it was a satisfying moment , so thanks for all the help.
I then decided to play with the interface_demo plugin to increase my understanding of plugins and python. I broke it a few times and learned from the experience, then I removed some code which I expected would break it – but didn't! At the top of each .py file there is: Code:
from __future__ import (unicode_literals, division, absolute_import, print_function) Also there are couple of comment lines at the top: Code:
#!/usr/bin/env python # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai |
Advert | |
|
06-24-2012, 12:21 PM | #21 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
http://docs.python.org/library/__future__.html
The first two lines are just boilerplate so unix shells know how to execute the file and so that vim knows how to set itself up when editing the file. |
06-24-2012, 01:59 PM | #22 |
Guru
Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
I did have a look at the Python docs first, but I'm still not quite sure why the plugin didn't fail when I removed the __future__ imports. Does this indicate that it simply isn't required in that particular plugin? Is it just a standard import to use in plugins because it's generally useful?
|
06-24-2012, 11:44 PM | #23 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
__future__ changes the way the interpreter interprets certain things. This is to allow you to write code that will work with later releases of python. In this case python 3. So yes, you should have it in all your plugin files.
|
06-27-2012, 02:45 PM | #24 |
Guru
Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
OK, I've put the __future__ imports back in.
Is there any reason why some from module import x, y, z statements put the x, y, z list in brackets but some don't? Is this significant or just personal preference? Also sometimes we see code like: action_spec = ('Normalise ePub', None, 'Normalise ePub after markdown conversion', None) but sometimes action_spec parameters are coded like: action_spec = (_('Normalise ePub'), None, _('Normalise ePub after calibre conversion'), None) What to the _( ) brackets indicate? |
06-27-2012, 02:54 PM | #25 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
The brackets on import just means you don't have to put a line continuation character of \ at the end of each line when you do multiline importing.
The _() indicate a language translation lookup. Since plugins that aren't bundled with calibre aren't hooked into calibre's translation mechanism, there isn't much point in using that syntax, unless you are using some text that you know exists inside calibre itself and hence will get translated. |
06-30-2012, 04:10 AM | #26 |
Guru
Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
Can I refer to my plugin's InterfaceActionBase properties from other .py files within the same plugin? For example in main.py I want to refer to the version tuple defined in __init__.py.
|
06-30-2012, 06:25 AM | #27 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You can import anything from one file into another, with the only caveat being to avoid circular imports at the global level. That means if you import something from file X into file Y, do not also import something else from file Y into file X.
|
06-30-2012, 04:49 PM | #28 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@agama - another way if the import is an issue is that your InterfaceAction class has a property on it called .interface_action_base_plugin which refers to that class.
So either: - you are in the interface action class, in which case you can use: Code:
self.interface_action_base_plugin.version Code:
plugin_action = gui.iactions['My Plugin Name'] plugin_action.interface_action_base_plugin.version |
06-30-2012, 04:59 PM | #29 |
Guru
Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
Good stuff! The straight-forward import worked as there was no circular reference, but these additional options look good too.
I've been working back through several plugins to broaden my knowledge and sometimes there are imports without a from. For example: import tempfile, os, atexit How do I locate these in the calibre source tree? I've searched for these filenames but without success. |
06-30-2012, 05:08 PM | #30 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Those are imports from base python. They will be documented at http://docs.python.org/library/
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Plugin not customizable: Plugin: HTML Output does not need customization | flyingfoxlee | Conversion | 2 | 02-24-2012 02:24 AM |
[GUI Plugin] Plugin Updater **Deprecated** | kiwidude | Plugins | 159 | 06-19-2011 12:27 PM |
Help with plugin writing | meme | Plugins | 2 | 01-21-2011 01:57 PM |
Writing an interface action plugin | kiwidude | Plugins | 21 | 11-11-2010 04:11 PM |
New Plugin Type Idea: Library Plugin | cgranade | Plugins | 3 | 09-15-2010 12:11 PM |