|  09-05-2015, 11:07 AM | #16 | 
| Grand Sorcerer            Posts: 5,763 Karma: 24088559 Join Date: Dec 2010 Device: Kindle PW2 | 
			
			@CalibUser: I've just tested the updated plugin with my Linux machine and appears to be working fine. (I only tested the line break fix.)
		 | 
|   |   | 
|  09-05-2015, 03:01 PM | #17 | 
| Connoisseur  Posts: 81 Karma: 10 Join Date: Nov 2013 Device: Kobo Aura HD | 
			
			The Fix for false line breaks doesn't work in greek language. I use the following regex to fix the lines breaks. Code: Find: ([\p{Greek},'–’“”][</ib>]*)</p>\s+<p>([<ib>]*[\p{Greek},'–’“”])
Replace:\1 \2Code: 	if allBreaks == 'Yes':
		CorrectText("Fixed false line breaks:", r'([a-z])</p>\s+<p[^>]*>([A-Z])', r'\1 \2')Code: 	if allBreaks == 'Yes':
		CorrectText("Fixed false line breaks:", r'([\p{Greek}\,\'–’“”][</ib>]*)</p>\s+<p>([<ib>]*[\p{Greek},\'–’“”])', r'\1 \2')  I don't know any python. Is my code ok? Thanks   | 
|   |   | 
|  09-05-2015, 04:33 PM | #18 | 
| Addict            Posts: 203 Karma: 62362 Join Date: Jul 2015 Device: Sony | 
			
			@Doitsu: Thanks for testing the plugin @gipsy: In your code: Code: r'([\p{Greek}\,\'–’“”][</ib>]*)</p>\s+<p>([<ib>]*[\p{Greek},\'–’“”])' | 
|   |   | 
|  09-05-2015, 04:53 PM | #19 | 
| Connoisseur  Posts: 81 Karma: 10 Join Date: Nov 2013 Device: Kobo Aura HD | 
			
			You are right. But again they don't compine   Yes is for greek characters. Code: <p>ο Πυθέας ήπιε το υπόλοιπο</p> <p>γάλα από το κύπελλο, σκούπισε</p> <p>δυο σταγόνες στα χείλη του με την ανάστροφη του</p> <p>χεριού του και σηκώθηκε.</p> Code: <p>ο Πυθέας ήπιε το υπόλοιπο γάλα από το κύπελλο, σκούπισε δυο σταγόνες στα χείλη του με την ανάστροφη του χεριού του και σηκώθηκε.</p>   | 
|   |   | 
|  09-05-2015, 08:32 PM | #20 | 
| Grand Sorcerer            Posts: 5,763 Karma: 24088559 Join Date: Dec 2010 Device: Kindle PW2 | 
			
			Sigil and Python use different Regex engines. Sigil uses PCRE and Python uses an older, less powerful version.  AFAIK, Python doesn't support the \p{Greek} syntax. I.e., Greek letters need to be explicitly expressed as Unicode ranges (0370–03FF). | 
|   |   | 
|  09-05-2015, 10:51 PM | #21 | |
| Ex-Helpdesk Junkie            Posts: 19,421 Karma: 85400180 Join Date: Nov 2012 Location: The Beaten Path, USA, Roundworld, This Side of Infinity Device: Kindle Touch fw5.3.7 (Wifi only) | Quote: 
 Code:        userProfile = (os.environ['USERPROFILE'])       #Get path to user profile
       try:
               f = open(userProfile+'\\AppData\\Local\sigil-ebook\\sigil\\user_dictionaries\\WordDictionary.txt', 'r', encoding='utf-8')For that matter, it is highly environment-specific -- it would also break hard on a PortableApps.com install, for example. Is there any way in Sigil/the plugin container to access the value of the Sigil configuration folder? This would be a far, far better way of handling it. (If there isn't a way, then it would be a generally useful thing to have...) Asking the user to manually select the dictionary just to get around the issue of finding the configuration directory is overkill (and slightly onerous) -- although it could be useful if one has multiple dictionaries and wants to use a specific one, that is probably an edge case. EDIT: And of course the instructions already make it clear that that won't work. Last edited by eschwartz; 09-06-2015 at 12:24 AM. | |
|   |   | 
|  09-05-2015, 11:52 PM | #22 | 
| Sigil Developer            Posts: 9,072 Karma: 6361556 Join Date: Nov 2009 Device: many | 
			
			FWIW, The next release of Sigil will include an interface to the hunspell spellchecker and will provide a list of paths to the hunspell dictionaries. If I can figure out how best to bundle sigil's version of gumbo for use by plugins, and if DiapDealer and I can fix some bugs, we should have a release out in 2 or 3 weeks. Kevin | 
|   |   | 
|  09-06-2015, 06:19 AM | #23 | |
| Grand Sorcerer            Posts: 5,763 Karma: 24088559 Join Date: Dec 2010 Device: Kindle PW2 | Quote: 
 @CalibUser: Python has a boatload of built-in functions for cross-platform file handling that make it really easy to implement cross-platform file support. Since the Sigil plugin root directory and the user_dictionary directory are sibling directories it's relatively easy to get the user_dictionary directory location. For example, you could use the following code to get the dictionary folder: Code: import os, inspect
def run(bk):
    # get plugin directory path
    plugin_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    print(plugin_path)
    
    # get rid of the last two directories
    tmp_path = plugin_path.split(os.path.sep)[:7]
    print(tmp_path)
    
    # add the dictionary path
    tmp_path.extend(['user_dictionaries', 'WordDictionary.txt'])
    
    # convert list back to file path
    dictionary_path = os.path.sep.join(tmp_path)
    print(dictionary_path)Windows: Code: C:\Users\Doitsu\AppData\Local\sigil-ebook\sigil\plugins\test ['C:', 'Users', 'Doitsu', 'AppData', 'Local', 'sigil-ebook', 'sigil'] C:\Users\Doitsu\AppData\Local\sigil-ebook\sigil\user_dictionaries\WordDictionary.txt Code: /home/doitsu/.local/share/sigil-ebook/sigil/plugins/test ['', 'home', 'doitsu', '.local', 'share', 'sigil-ebook', 'sigil'] /home/doitsu/.local/share/sigil-ebook/sigil/user_dictionaries/WordDictionary.txt Last edited by Doitsu; 09-06-2015 at 06:31 AM. | |
|   |   | 
|  09-06-2015, 07:23 AM | #24 | ||
| Connoisseur  Posts: 81 Karma: 10 Join Date: Nov 2013 Device: Kobo Aura HD | Quote: 
 I change it to Code: 	if allBreaks == 'Yes':
		CorrectText("Fixed false line breaks:", r'(([\x{0370}-\x{03FF}\x{1F00}-\x{1FFF},\'–’“”][</ib>]*)</p>\s+<p>([<ib>]*[\x{0370}-\x{03FF}\x{1F00}-\x{1FFF},\'–’“”]))', r'\1 \2') Quote: 
 Last edited by gipsy; 09-06-2015 at 07:35 AM. | ||
|   |   | 
|  09-06-2015, 07:32 AM | #25 | 
| Connoisseur  Posts: 81 Karma: 10 Join Date: Nov 2013 Device: Kobo Aura HD | 
			
			@CalibUser: Those are some fixes in greek language if you want to place them in your plygin. I try to find a solution and for some other things and i keep you posted   Code: #Greek line break fix
	if allBreaks == 'Yes':
		CorrectText("Fixed false line breaks:", r'(([\x{0370}-\x{03FF}\x{1F00}-\x{1FFF},\'–’“”][</ib>]*)</p>\s+<p>([<ib>]*[\x{0370}-\x{03FF}\x{1F00}-\x{1FFF},\'–’“”]))', r'\1 \2')
	return(0)Code: 	#Fixes Έ when PDFd as 'Ε or "Ε
	CorrectText("Changed 'Ε,\"Ε to Έ", r'(\'Ε|\"Ε)', r'Έ')
	#Fixes Ύ when PDFd as 'Υ or "Υ
	CorrectText("Changed 'Υ,\"Υ to Ύ", r'(\'Υ|\"Υ)', r'Ύ')
	#Fixes Ί when PDFd as 'Ι or "Ι
	CorrectText("Changed 'Ι,\"Ι to Ί", r'(\'Ι|\"Ι)', r'Ί')
	#Fixes Ό when PDFd as 'Ο or "Ο
	CorrectText("Changed 'Ο,\"Ο to Ό", r'(\'Ο|\"Ο)', r'Ό')
	#Fixes Ά when PDFd as 'Α or "Α
	CorrectText("Changed 'Α,\"Α to Ά", r'(\'Α|\"Α)', r'Ά')
	#Fixes Ή when PDFd as 'Η or "Η
	CorrectText("Changed 'Η,\"Η to Ή", r'(\'Η|\"Η)', r'Ή')
	#Fixes Ώ when PDFd as 'Ω or "Ω
	CorrectText("Changed 'Ω,\"Ω to Ώ", r'(\'Ω|\"Ω)', r'Ώ')
	#Fixes ύ when PDFd as ΰ
	CorrectText("Changed ΰ to ύ", r'ΰ', r'ύ')Last edited by gipsy; 09-06-2015 at 11:25 AM. | 
|   |   | 
|  09-06-2015, 09:01 AM | #26 | |
| Grand Sorcerer            Posts: 28,883 Karma: 207000000 Join Date: Jan 2010 Device: Nexus 7, Kindle Fire HD | Quote: 
  Though there may be shorter ways to get the current directory of the script that's being run, it's the only one that's guaranteed to work even when a script was invoked as a module. I would, however suggest something other than the relatively fragile method of converting a path to a list of strings and then using the [:7] slice to strip off the last two directories. If the depth of that path ever increases, it won't point to the sigil preferences directory anymore. To be clear: it's the [:7] slice I find fragile, not the list of strings conversion and eventual re-joining. I would suggest using [:-2] if you're going to split the path into a list of strings that later get rejoined. Or just use os.path.dirname twice without converting to a list of strings and rejoining. It's all a bit fragile I guess (even mine), considering that the plugin directory could conceivably change in relation to the Sigil preferences directory. Code: import os, inspect
# get plugin directory path
plugin_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
print(plugin_path)
    
# get rid of the last two directories
tmp_path = os.path.dirname(os.path.dirname(plugin_path))
print(tmp_path)
    
# add the dictionary path
dictionary_path = os.path.join(tmp_path, 'user_dictionaries', 'WordDictionary.txt')
print(dictionary_path)You could also determine the path of the current plugin script in the run method of a plugin by using: Code: def run(bk):
    ppath = bk._w.plugin_dir  Last edited by DiapDealer; 09-06-2015 at 09:25 AM. | |
|   |   | 
|  09-06-2015, 11:43 AM | #27 | 
| Connoisseur  Posts: 81 Karma: 10 Join Date: Nov 2013 Device: Kobo Aura HD | Code: #Greek line break fix
	if allBreaks == 'Yes':
		CorrectText("Fixed false line breaks:", r'([\u0370-\u03FF,\u1F00-\u1FFF,\'–’“”][</ib>]*)</p>\s+<p[^>]*>([<ib>]*[\u0370-\u03FF,\u1F00-\u1FFF,\'–’“”])', r'\1 \2')
	return(0) | 
|   |   | 
|  09-06-2015, 02:01 PM | #28 | ||
| Ex-Helpdesk Junkie            Posts: 19,421 Karma: 85400180 Join Date: Nov 2012 Location: The Beaten Path, USA, Roundworld, This Side of Infinity Device: Kindle Touch fw5.3.7 (Wifi only) | Quote: 
  Quote: 
  That should teach me to make assumptions. (I guess it really depends on the app. I know they prefer if at all possible to not do that, it reduces the "portability" angle by potentially leaving unwanted cruft on the host computer.)  It doesn't look like there is any way to override the settings folder location in Sigil. (And it uses the deprecated-since-5.4 DataLocation, rather than AppDataLocation on Windows and AppConfigLocation on unix -- did Qt have to split it?  -- which explains why the config folder is in ~/.local/share/sigil-ebook -- I have always wondered at that non-standard location.) | ||
|   |   | 
|  09-06-2015, 02:22 PM | #29 | |
| Grand Sorcerer            Posts: 28,883 Karma: 207000000 Join Date: Jan 2010 Device: Nexus 7, Kindle Fire HD | Quote: 
 And there's just no "real" pressing need to convert and potentially lose user-settings/plugins in an upgrade (or create a one-time script to copy stuff to the new location). Maybe someday it will change, but it's just not high on the list of priorities at the moment. | |
|   |   | 
|  09-06-2015, 02:40 PM | #30 | |
| Ex-Helpdesk Junkie            Posts: 19,421 Karma: 85400180 Join Date: Nov 2012 Location: The Beaten Path, USA, Roundworld, This Side of Infinity Device: Kindle Touch fw5.3.7 (Wifi only) | Quote: 
  that was just me being random. I happened to notice that at the same time I noticed there was no way to override the settings dir. (And I was bemused to see Qt hasn't figured out cross-platorm config dirs yet.) Whether either is *necessary*, I won't venture to say. I agree once it's been used you shouldn't break everyone's settings just to conform to more "proper" standards. | |
|   |   | 
|  | 
| 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Tidying Up My Kindle | selectortone | Calibre | 2 | 07-17-2013 10:35 AM | 
| developping a Plugin for Presentation files | abdlink | Plugins | 4 | 04-15-2013 11:27 AM | 
| Plugin to fix fb2 files | oviksna | Plugins | 3 | 01-28-2013 08:53 AM | 
| Tidying Up My Library | JayLaFunk | Library Management | 2 | 09-20-2011 09:12 AM | 
| Calibre 0.7.50 can't see plugin files | mb_webguy | Calibre | 5 | 04-29-2011 03:41 AM |