View Single Post
Old 11-15-2016, 06:48 PM   #16
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
For DiapDealers benefit, here is the plugin.py code for my plugin. This file is by no means complete(I have yet to add the update plugin section and osx and linux capability and it needs a tidy up):

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import unicode_literals, division, absolute_import, print_function

import globals
import convert
from cutils2 import validateHTMLFile

import os, os.path, sys, codecs, platform
from time import sleep

import tkinter as tk
import  tkinter.filedialog as fdbox
from dialogs import MetadataDialog
    
# main routine
def run(bk):
    print('Python Version:', platform.python_version(), '\n')  

    # initialize variables
    google_html_file = None
    prefs = bk.getPrefs()
    
    # get update check prefs
    if 'update_check' in prefs:
        update_check = prefs['update_check']
    else:
        update_check = True
        prefs['update_check'] = True
        
    # initialize file open default dirs    
    if 'initialdir' in prefs:
        globals.HTML_OPTIONS['initialdir'] = prefs['initialdir']
        globals.COVER_OPTIONS['initialdir'] = prefs['initialdir']    
    else:
        prefs['initialdir'] = os.path.expanduser('~')
        bk.savePrefs(prefs)        
             
    # set default output to epub 2
    output_format = 'epub 2.0'
    prefs['output_format'] = output_format
    
    # get the file locations, ebook
    # metadata and validate user input
    root = tk.Tk()
    root.title('Edit Metadata')
    root.resizable(width=False, height=False)
    MetadataDialog(root).pack(fill=tk.BOTH, expand=True)
    root.mainloop()
    
    # if dialog 'Cancel' or exit is pressed then exit run()
    if globals.SYS_EXIT== True:
       return(0)
    
    # get the input html file name
    html_file_path = globals.META_OPTIONS['filename'] 
    
    # save the dir path for next time
    prefs['initialdir'] = os.path.split(html_file_path)[0]
    bk.savePrefs(prefs)
    
    # check and validate the html file
    status = validateHTMLFile(html_file_path)
    if status != 0:   
        print(' >>> The HTML file FAILED validation checks.')
        return(0)
    
    # process the html file
    if html_file_path:
        
        # run the html to epub conversion
        epub_path = convert.convert2Epub(html_file_path)

        # if conversion fails, exit run()
        if globals.SYS_EXIT == True:
            return(0)                
        
        # import the epub into Sigil
        if os.path.isfile(epub_path):
            with codecs.open(epub_path,'rb')as fp:
                data = fp.read()
            bk.addotherfile('dummy.epub', data)
            os.remove(epub_path)
            return(0)
    else:
        print(' >>> Unable to process html file due to critical conversion errors.')
        return(0)
        

def main():
    print('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())

Last edited by slowsmile; 11-15-2016 at 06:57 PM.
slowsmile is offline   Reply With Quote