|  01-21-2018, 06:44 PM | #286 | 
| Sigil Developer            Posts: 9,071 Karma: 6361556 Join Date: Nov 2009 Device: many | 
			
			Given that order of attributes in pure xml is variable (not order specific) and given the line oriented structure of the manifest and spine, and even metadata, character offsets into the line are basically meaningless. But that is of course your call. KevinH Last edited by KevinH; 01-22-2018 at 09:06 AM. | 
|   |   | 
|  01-22-2018, 01:39 PM | #287 | 
| Sigil Developer            Posts: 9,071 Karma: 6361556 Join Date: Nov 2009 Device: many | 
			
			BTW:  I just committed a first shot at allowing custom icons for plugin quicklaunch toolbar buttons to master. I have not tested it much but I wanted people to try it out and see if it does the trick. To use a custom icon for your plugin on the toolbar: 1. pull from master and rebuild 2. simply create a 48x48 png file called "plugin.png" and put it at the root of your plugin folder right beside plugin.xml and plugin.py. 3. Make sure your plugin is set to be one of the 5 allowed quick-launched plugins. It should hopefully just work. Comments and improvements welcome. | 
|   |   | 
|  01-22-2018, 04:34 PM | #288 | 
| Guru            Posts: 899 Karma: 3501166 Join Date: Jan 2017 Location: Poland Device: Various | 
			
			It works OK for me.  Although the icons for plugins selected in "Manage plugins" appear only after restarting Sigil. Can you force the refresh "Tools" toolbar? | 
|   |   | 
|  01-22-2018, 04:40 PM | #289 | 
| Sigil Developer            Posts: 9,071 Karma: 6361556 Join Date: Nov 2009 Device: many | 
				
				Added plugin features for launcher_version >= 20180122
			 
			
			Hi All, Based on the discussion here and in the FolderIn/FolderOut thread, I have just committed to master support for two new plugin features available in edit, output, and validation plugins: Code: bk.get_epub_is_modified() returns boolean True if the epub inside Sigil has been modified but not yet saved to disk bk.get_epub_filepath() returns a string of the filepath for the epub currently open in Sigil or the null string "" if the current epub is unsaved/untitled Here is snippet of code you can add to your current plugin.py to test these features available in any build of Sigil from current master Code:    # status of epub inside Sigil and its current path
    if bk.launcher_version() >= 20180122:
        print("\nExercising: get_epub_is_modified and get_epub_filepath")
        print("epub inside Sigil is Modified: ", bk.get_epub_is_modified())
        print("filepath of epub open inside Sigil: ", bk.get_epub_filepath()) | 
|   |   | 
|  01-22-2018, 04:52 PM | #290 | 
| Sigil Developer            Posts: 9,071 Karma: 6361556 Join Date: Nov 2009 Device: many | |
|   |   | 
|  01-25-2018, 12:47 AM | #291 | |
| Witchman            Posts: 628 Karma: 788808 Join Date: May 2013 Location: Philippines Device: Android S5 | 
			
			@Becky... Quote: 
 The way round this problem is just to create a separate work directory for all the files that your are going to change or update in the epub with your plugin code. Use the python mkdtemp() method to create the work directly. In your plugin just save all your changed files to the work dir. The very last task for your plugin should be to write all new or changed files from your work dir to your epub. If you use a work dir and, as your last plugin task, save all changed or new files back to the epub, then it won't matter how many times you run get_opf() in your plugin because all the epub files will still be in their original state because nothing has been saved or changed yet. So doing it this way should give you correct line numbers. I remember, somewhere in the distant past, Kevin patiently explaining all this to me in an email and enlightening me in the way the container updates all files that you've changed with your plugin after end-of-run. The container processing runs in this this order: delete files, add files(adds new files), write files(write existing files back to the epub). Appreciating the container processing order and always using a temp work dir in my plugins has stood me in good stead because that's what really helped me to understand how I could safely use the get_opf() function in my IDErrorCheck plugin without any problems. Last edited by slowsmile; 01-25-2018 at 01:12 AM. | |
|   |   | 
|  01-25-2018, 02:33 AM | #292 | 
| Guru            Posts: 899 Karma: 3501166 Join Date: Jan 2017 Location: Poland Device: Various | 
			
			Thank you very much for the comprehensive answer. I am currently using the code: Code: opf_data = bk.readotherfile("OEBPS/content.opf") | 
|   |   | 
|  01-25-2018, 04:28 AM | #293 | 
| Connoisseur            Posts: 57 Karma: 600000 Join Date: Jan 2018 Device: Galaxy Tab S2 | 
			
			Hi, yesterday i tried to make use of my first own sigil plugin. I'm a python beginner and the only purpose of learning python is to devekol a sigil plugin. Yeserday my plugin cashed with this: bk.readfile(id) The reason was quite simple: someone deleteted all ttf font files an replaced them by the otf variant for any reason. But in the manifest those ttf entries were still present. So the iterator seems to read the manifest but as the file wasnt present the readfile method failed. Is there any was to capture errors like this to present a more meaningful errormessage to the user instead of getting a dump by the launcher? M | 
|   |   | 
|  01-25-2018, 07:27 AM | #294 | 
| Sigil Developer            Posts: 9,071 Karma: 6361556 Join Date: Nov 2009 Device: many | 
			
			Crashed or threw an exception?  Exceptions can easily be caught and handled.  My real concern is that Sigil had a manifest that was wrong.  That should never happen.  My guess is you are being confused by manifest ids that look like file names.  Please post the opf you are working on in your plugin or better yet your ePub.  Old / any manifest ids can be used but the manifest should always be correct.  If not there is a real bug that needs to be tracked down and fixed.
		 Last edited by KevinH; 01-25-2018 at 08:11 AM. | 
|   |   | 
|  01-25-2018, 07:35 AM | #295 | |
| Sigil Developer            Posts: 9,071 Karma: 6361556 Join Date: Nov 2009 Device: many | 
			
			Actually you should not really need to use a temp folder at all.  The plugin itself only has read access to the files inside Sigil.  If you try to make a change, the plugin interface code will take a copy of the file, allow you to change the copy and store it hidden away.  Once your plugin is complete and returns, Sigil itself will will be given a list of changes you requested and access to the hidden changes files and it will make the changes. Bk.get_opf should always keep the opf updated and return a correct opf behind the scene but since it is rebuilt from a parsed structure, it may not keep the exact same white space as the original opf. Quote: 
 | |
|   |   | 
|  01-25-2018, 08:00 AM | #296 | 
| Witchman            Posts: 628 Karma: 788808 Join Date: May 2013 Location: Philippines Device: Android S5 | 
			
			@KevinH. Thanks for explaining it so thoroughly. And it's definitely worth remembering. I also remember that when I was writing the IDErrorCheck plugin I was determined to use the bk.get_opf() method because I'd never used it before and it looked so easy. But I had to play around with it for quite a while(and read DiapDealer's Sigil manual) before I clocked and understood what it did and eventually got the opf line numbering right.
		 | 
|   |   | 
|  01-25-2018, 08:10 AM | #297 | 
| Sigil Developer            Posts: 9,071 Karma: 6361556 Join Date: Nov 2009 Device: many | 
			
			Yes, playing around with the opf can be tricky.  When your plugin adds and removes files, as long as it uses the plugin interface to make the changes properly, the get_opf call should always return an automatically updated opf for you.  It just may not have the exact same whitespace as before.
		 | 
|   |   | 
|  01-25-2018, 08:58 AM | #298 | |
| Connoisseur            Posts: 57 Karma: 600000 Join Date: Jan 2018 Device: Galaxy Tab S2 | Quote: 
 At least, i got an error saying the the file couldnt be loaded (of course, it was not present) and then a traceback to the launcher followed with some additional error messages. I would just like to have a more user friendly error message when bk.readfile isnt able to load a file and dont know how to catch such a kind of error. M | |
|   |   | 
|  01-25-2018, 09:29 AM | #299 | |
| Grand Sorcerer            Posts: 5,763 Karma: 24088559 Join Date: Dec 2010 Device: Kindle PW2 | Quote: 
 | |
|   |   | 
|  01-25-2018, 09:37 AM | #300 | 
| Grand Sorcerer            Posts: 28,882 Karma: 207000000 Join Date: Jan 2010 Device: Nexus 7, Kindle Fire HD | 
			
			Also... a non-copyright-violating epub sample that can be used to reproduce the error would be nice. If Sigil can make use of the file in the epub without problems, then the plugin framework's bk.readfile() really shouldn't barf on it either. Perhaps there's something unforeseen we need to account for.
		 | 
|   |   | 
|  | 
| Thread Tools | Search this Thread | 
| 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Loading Plugin in development | Sladd | Development | 6 | 06-17-2014 06:57 PM | 
| Question for plugin development gurus | DiapDealer | Plugins | 2 | 02-04-2012 11:33 PM | 
| DR800 Plugin development for DR800/DR1000 | yuri_b | iRex Developer's Corner | 0 | 09-18-2010 09:46 AM | 
| Device plugin development | reader42 | Plugins | 10 | 03-29-2010 12:39 PM | 
| Calibre plugin development - Newbie problems | minstrel | Plugins | 5 | 04-12-2009 12:44 PM |