1
0
mirror of https://github.com/ciromattia/kcc synced 2026-02-17 09:41:04 +00:00

Add PDF jpg image extraction (fixes #2)

More work on GUI with Tkinter.
This commit is contained in:
Ciro Mattia Gonano
2013-01-14 12:53:13 +01:00
parent 988a357555
commit 2a7b2c9e3d
5 changed files with 184 additions and 38 deletions

View File

@@ -18,26 +18,86 @@
from Tkinter import *
import tkFileDialog
import comic2ebook
from image import ProfileData
class MainWindow:
def clear_files(self):
self.files = []
self.refresh_list()
class MainWindow(Frame):
def open_files(self):
self.files = tkFileDialog.askopenfilename()
filetypes = [('all files', '.*'), ('Comic files', ('*.cbr','*.cbz','*.zip','*.rar'))]
f = tkFileDialog.askopenfilenames(title="Choose a file...",filetypes=filetypes)
if (isinstance(f,tuple) == False):
try:
import re
f = re.findall('\{(.*?)\}', f)
except:
import tkMessageBox
tkMessageBox.showerror(
"Open file",
"askopenfilename() returned other than a tuple and no regex module could be found"
)
sys.exit(1)
self.files.extend(f)
self.refresh_list()
def createWidgets(self):
self.QUIT = Button(self)
self.QUIT["text"] = "Quit"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "right"})
def open_folder(self):
self.files = tkFileDialog.askdirectory(title="Choose a folder...")
self.refresh_list()
self.OPENFILES = Button(self)
self.OPENFILES["text"] = "Open files",
self.OPENFILES["command"] = self.open_files
self.OPENFILES.pack({"side": "left"})
def refresh_list(self):
self.filelocation.config(state=NORMAL)
self.filelocation.delete(0, END)
for file in self.files:
self.filelocation.insert(END, file)
self.filelocation.config(state=DISABLED)
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
def initialize(self):
self.filelocation = Listbox(self.master)
self.filelocation.pack(fill=BOTH, expand=1)
self.refresh_list()
self.clear_file = Button(self.master, text="Clear files", command=self.clear_files)
self.clear_file.pack(side=LEFT)
self.open_file = Button(self.master, text="Add files...", command=self.open_files)
self.open_file.pack(side=LEFT)
self.open_folder = Button(self.master, text="Add folder...", command=self.open_folder)
self.open_folder.pack(side=LEFT)
self.profile = StringVar()
self.profile.set("KHD")
for text in ProfileData.Profiles:
b = Radiobutton(self.master, text=text,
variable=self.profile, value=text)
b.pack(anchor=W,fill=BOTH)
self.mangastyle = BooleanVar()
self.mangastyle = False
self.c = Checkbutton(self.master, text="Split manga-style (right-to-left reading)",
variable=self.mangastyle)
self.c.pack()
#now for a button
self.submit = Button(self.master, text="Execute!", command=self.convert, fg="red")
self.submit.pack()
def convert(self):
argv = ["-p",self.profile.get()]
if (self.mangastyle == True):
argv.append("-m")
for entry in self.files:
subargv = list(argv)
subargv.append(entry)
comic2ebook.main(subargv)
print "Done!"
def __init__(self, master, title):
self.files = []
self.master = master
self.master.title(title)
self.initialize()