![]() |
[Plugin] TagMechanic
1 Attachment(s)
TagMechanic: conveniently remove, change the attributes of (and/or convert to different html elements) those pesky, nestable spans and divs (as well as a few others for convenience).
** NOTE: this plugin periodically checks for updated versions by connecting to github (where the source is maintained). See the end of this post for more details ** ** NOTE 2: this plugin cannot be launched when Sigil is opened via Calibre's Open With feature (or plugin of the same name) if the version of Sigil being used is less than v1.3. If you need that launch-from-calibre functionality, make sure you're running the latest version of Sigil.** This is a "rebranding" of my "Span/Div Editor" calibre-edit plugin for those who may remember and/or use it. Minimum Sigil requirement: v0.9.8 or higher Python Requirements: Python 3.4+ (Bundled or external) OS Requirements: Windows/Linux/OS X *** Linux users will have to make sure that the PyQt5 graphical python module is present if it's not already. On Debian-based flavors this can be done with "sudo apt-get install python3-pyqt5". On Arch distributions it can be done with pacman -S python-pyqt5 *** 1) This plugin operates on the Text files selected/highlighted in Sigil's Book Browser, so make sure you highlight the files you want to work with before launching the plugin. 2) Then choose the action you wish to perform (modify/delete), select the tag you want to perform that action on, the attribute you want to match (No attributes means you want to work with those elements that HAVE no attributes at all) and the value that that attribute should have. If the value you entered is a regular expression, check the regex box (capture groups cannot be reinserted later so they will be ignored if present). Otherwise, it is assumed that what you have entered in the New Attribute box is a literal string. 3) If you've chosen to modify a tag, you need to specify whether you want to change the tag to another tag, or change its attributes, or both. If you've chosen to change the tag to something else, then you need to enter all the attributes you want (or check the box to copy the existing attributes) otherwise the tag will be changed to the new tag with no attributes if left empty. Configuration: From the 'Edit' menu choose 'Config' to customize the plugin. In that dialog, you'll be able to change/add/remove what tags are available to change the various tags to. You can also change/add/remove things from the list of attributes to look for. They're just comma-separated lists of elements/attributes, get cute and you might break something. There's a Reset to Default button if you get in trouble. After seeing the general report of what was done (or not done), you'll have the opportunity to commit the changes, or to bail out if you get chicken. ;) TagMechanic's code is hosted/maintained on Github. This plugin's update checker will only try to check for updates after at least 12 hours has elapsed since its last check. The plugin will only notify you about updates once for each new version released. No nagging, I promise. Changes Spoiler:
|
Quote:
BTW THANK YOU I have been jumping over to the Calibre editor to use the toolbag |
Quote:
Quote:
|
Commit changes
DiapDealer:
I am new to this forum, thank you for having me. I do epubs (and PDF and mobi ebooks) for a couple of small publishers, starting with indesign and/or xml files. Thanks for a VERY handy plugin. It makes cleaning up the InDesign epub mess rather a breeze. (On a separate but hopefully not too unrelated note I would be interested in hearing from any forum members about their experience with Indesign epub creation. I am finding that files that are set up with that work well for print layout really need re-tooling if the generated epub files are to be clean and well organized.) One question I had on your plugin -- my experience is that when I run the plugin the changes are made to the files even though I aborted rather than clicking commit changes. Of course I can close and elect not to save the changes from Sigil's main window, but I assumed that when the plugin offers the opportunity to abort it is the changes to the files that is being aborted...let me know if the question/comment makes no sense. Thanks again for a great forum. |
Quote:
That's not to say I didn't make a mistake somewhere! I'll take a look. |
Quote:
|
FYI:
Up until recently returning -1 was not enough for the plugin to actually abort. Only throwing an exception seemed to do the trick. That bug was fixed in Sigil-0.9.2 or Sigil-0.9.3. I don't remember which right now. So if changes still get applied, please make sure you are using the very latest Sigil-0.9.3 version. If you hit cancel and changes still get applied with that version of Sigil, Sigil itself may have a bug. KevinH |
Quote:
EDIT: though I would still recommend users upgrading to the latest version of Sigil. This plugin needs at least Sigil v0.8.900 (bk.selected_iter()), so it's not like people stuck with 0.8.6/7 could use it anyway. There's no good reason I can think of to stay with 0.8.900 - 0.9.2. |
Hi DiapDealer!
Thanks for your useful plugin, I very like this. I've recently got error when run this plugin. This is my error log: Code:
Status: failedMy machine: Windows 10 64bit, Sigil 0.9.3. I've tried remove and re-install sigil (both 0.9.3 and 0.9.2) but still get that error. EDIT: Wow, I've removed folder plugins_prefs/TagMechanic and TagMechanic can run normally. <3 |
Quote:
If you do customize the available parameters, I recommend closing the plugin and restarting it before trying to use them in a new query. Glad you got it working again (and glad you like it) :) |
great plug-in that I missed, it solve some of my problem
|
This plugin is very usefull, I have 2 request:
1 - Can you add p in the tag name list so that I dont have to delete TagMechanic.json every time I change something in p. 2 - the plugin can be used more times in the same session instead of a single process and then close? |
Quote:
1) Many times I am doing a 'cleanup' of horrible (inline) code and it is most annoying (time consuming) to have it reload 2) I made some sort of error, so nothing got changed :o. Not only #1, but the terms have been cleared, giving me a second chance to mess up... :rolleyes: :bulb: Intelligent attribute suggestions Marry the Sigil Report (results will be cached when TM is first run PER BOOK to help performance. Not absolutely perfect ) results to Tag Mechanic If I select: tag name: Span whose value: Pulldown suggest the available classes found used with Spans (from the report data) |
I can handle #1 (even though the need to change a "p" tag to another tag is pretty rare--and altering a p tag's attributes is already easy enough with regex).
But I'm not a fan of #2. The last-minute abort/commit feature is too important to me. And allowing multiple passes per plugin run would require me to keep track of multiple (and potentially conficting) commits to be applied (or cancelled). I won't rule it out completely, but it would take a considerable code refactoring project to accomplish it to my satisfaction. I'll have to do some cyphering on it. Also, the fact that the plugin only operates on the files that were selected before the plugin launches sort of limits what any subsequent runs could accomplish. |
Quote:
|
Quote:
|
Quote:
https://www.mobileread.com/forums/sho...77&postcount=1 |
thanks
|
Quote:
|
Hi there,
I'm getting an error when I try to run Tag Mechanic. I'm still new to Sigil, so I suspect I'm doing something stupid. I start by opening a book in Sigil, selecting a file, then go to Plugins > Edit > TagMechanic. Then this happens: Code:
Status: failedThanks for any suggestions! Also, is TagMechanic the Sigil equivalent of Diaps Editing Toolbag in Calibre? |
@odamizu...The error reports that it can't recognize the data in the image file. This probably means that your downloaded version of Tag Mechanic has a corrupt image file. I've also just downloaded Tag Mechanic and re-installed it again on my system and it works without problems.
Just try downloading and re-installing Tag Mechanic again to see if this cures your problem. |
@odamizu: Did you install the special macOS ActiveState Tcl 8.6.4.1 package mentioned on the download page? This package is required for all Sigil plugins that come with a GUI.
|
Doitsu is correct. The Tcl that comes with OS X is broken. That's why KevinH recommends installing Activestate's Tcl before running/installing Sigil plugins (at least he ones that have tkinter gui components).
And yes, this plugin is the equivalent of the "Span/Div Editor" portion of my "Diaps EditorToolbag" plugin for calibre's editor. There's a separate PunctuationSmarten plugin that provides the rest of the functionality from the "Toolbag". |
Thanks. I do have ActiveState Tcl 8.6.4.1 installed. For good measure, I re-installed it. Unfortunately, that didn't help. I still get the error message.
I also re-downloaded a fresh copy of the plug-in, uninstalled and re-installed it a few times. That didn't help either. Any thing else I can try? |
Quote:
In the meantime, you can try the following: 1. Download TextWrangler or another programmer's text editor. 2. Start Sigil and select Edit >Preferences > Open Preferences Location. 3. Click Plugins > TagMechanic and open plugin.py with TextWrangler. 4. Comment out lines 565 and 566 by inserting a # sign: Code:
#img = tkinter.Image('photo', file=os.path.join(bk._w.plugin_dir, bk._w.plugin_name, 'images/icon.png'))This workaround should allow you to run TagMechanic until KevinH has figured out what additional image library is required to run the commented-out code. |
Kevin's tested this plugin for me on OS X, I know. But it's been a while. I don't believe that icon is even visible on a Mac, so I could easily exclude it for that platform if it's found to be causing issues.
@odamizu: in fact ... here's a version that does just that (in case you don't want to manually edit the plugin yourself). See if it makes a difference. If so, I'll commit the change and release a new version. I'm not in love with the icon or anything. ;) EDIT: test attachment removed since the first post was updated to that version |
Quote:
Quote:
In the meantime, thanks everyone for your help! |
Quote:
(You're too fast for me. I was trying Doitsu's manual edit, and when I came back to the forum, you had 0.4.3 up) |
I'll wait to hear if Kevin has any ideas before updating the first post with the new version. Thanks for making sure it works! :)
|
Hi DiapDealer,
Just saw this. I will see if I can reproduce it on my Mac and get back to you. KevinH |
Quote:
tk.call() documentation is pretty thin. |
The problem is that tcl/tk 8.5 and lower does not support png icons only gif ones when used in this way. That said, tcl/tk 8.6 and later support png for icons in this way.
The problem is that Python 3.5 building from source on Mac OS X seems to now be hard coded to link to tck/tk 8.5 when previously they linked to either 8.5 or 8.6. See https://www.python.org/download/mac/tcltk/ So the default build will no longer dynamically link to tck/tk 8.6 which has the fix. This is so sad! I am going to have to rebuild the bundled Python and somehow path the build to actually look for and require 8.6 and not the stupid 8.5. I will look to see what changed from building Python 3.4 to 3.5 and see if I can back out that change. What a mess! And why farting with this I have broken my portable Python 3.5 build completely so no more Sigil builds until I get it fixed! KevinH |
Ouch! Sorry to have been the one to help you discover the mess. :o
|
The change was not in python, it was that the default search path for Frameworks used to be /Library/Frameworks followed by /System/Library/Frameworks when using gcc/clang in the linking stage to link to Tk or Tcl frameworks. More recent Mac OSX versions have locked down the /System path so nothing can write their anymore.
So I have to patch the Python 3.5.2 setup.py code to include the -F/Library/Frameworks to force it to look there for linking first. I will do this so that things will work again for our next release at least for the bundled Python. KevinH |
Yikes! All I can say is, thank you so much for developing and sharing Sigil, and sorry for opening the door to this mess with my question :o
|
No Problems.
I was able to fix the bundled Python interpreter on my Mac OSX machine to look in /Library/Frameworks/Tk.framework and its cousin Tcl.framework and for the ActiveState Active TclTk if it exists and if so use it. So DiapDealer's current version of Tag Mechanic will now run with no changes needed. The next build for Mac OSX will bring the fix to Sigil, in the meantime, commenting out those two lines is probably for the best on Mac OS X. Thanks for the bug report, KevinH |
Can anyone verify that the png "wrench" icon is visible anywhere on a Mac (assuming python is linking to the version of tcl/tk where my code doesn't cause an error) when the plugin is running? If the icon doesn't appear in the dock (or anywhere else) regardless, I'd just as soon "if" that code out on the Mac platform. That way the plugin will work as is on Sigil 0.9.7 on a Mac.
If the icon DOES appear, though, I'll leave the code in and point to this stop-gap version of the plugin until the next Sigil release. |
Quote:
|
Quote:
|
I can do it and report back. The window menu bar on Macs do not allow/show the icons, but it may show up in the panel if the Window is minimized, but typically these just map to a generic Python app symbol.
|
| All times are GMT -4. The time now is 07:08 PM. |
Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.