94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
|
# -*-coding:utf-8 -*
|
||
|
|
||
|
from PyPDF2 import PdfFileReader, utils as PyPDF2utils
|
||
|
import tkinter as tk
|
||
|
from pdfembannersrc import editfich
|
||
|
import logging
|
||
|
logger = logging.getLogger()
|
||
|
|
||
|
class Fich:
|
||
|
"""
|
||
|
Class to store data on a pdf file
|
||
|
"""
|
||
|
count = 0
|
||
|
def __init__(self, filename):
|
||
|
self.id = Fich.count
|
||
|
Fich.count += 1
|
||
|
|
||
|
self.name = None
|
||
|
self.path = None
|
||
|
self.npages = 0
|
||
|
self.nblankpages = 0
|
||
|
|
||
|
self.use = None
|
||
|
self.order = None
|
||
|
self.rotate = None
|
||
|
self.crop = None
|
||
|
|
||
|
self.Wnum =None
|
||
|
self.Wlabel = None
|
||
|
self.Wedit = None
|
||
|
self.Wdel = None
|
||
|
self.Wup = None
|
||
|
self.Wdown = None
|
||
|
|
||
|
if(filename is not None):
|
||
|
self._initFromFile(filename)
|
||
|
|
||
|
def _initFromFile(self, filename):
|
||
|
self.path = filename
|
||
|
self.name = filename.split('/')[-1]
|
||
|
try:
|
||
|
with open(filename, "rb") as in_f:
|
||
|
input1 = PdfFileReader(in_f)
|
||
|
self.npages = input1.getNumPages()
|
||
|
except (PyPDF2utils.PdfReadError, EOFError, IOError, NotImplementedError):
|
||
|
raise IOError("Impossible to read file {}".format(filename))
|
||
|
|
||
|
def print1l(self):
|
||
|
if(self.name is not None):
|
||
|
return self.name
|
||
|
else:
|
||
|
return '-'
|
||
|
|
||
|
def edit(self, parent):
|
||
|
interface2 = editfich.InterfaceEdit(parent, self)
|
||
|
logger.debug("Concatenate : Editting {}".format(self.path))
|
||
|
interface2.mainloop()
|
||
|
interface2.destroy()
|
||
|
logger.debug("Concatenate : End Editting {}".format(self.path))
|
||
|
|
||
|
def add_widgets(self, frame, parent, i):
|
||
|
self.Wnum = tk.Label(frame, text="{}.".format(i+1))
|
||
|
self.Wlabel = tk.Label(frame, text=self.print1l())
|
||
|
self.Wedit = tk.Button(frame, text="Edit", command=lambda: self.edit(parent))
|
||
|
self.Wdel = tk.Button(frame, text="Del", command=lambda: parent.delete(self.id))
|
||
|
self.Wup = tk.Button(frame, text="Up", command=lambda: parent.up(self.id))
|
||
|
self.Wdown = tk.Button(frame, text="Down", command=lambda: parent.down(self.id))
|
||
|
self.set_i_widgets(i)
|
||
|
|
||
|
def unset_i_widgets(self):
|
||
|
self.Wnum.grid_forget()
|
||
|
self.Wlabel.grid_forget()
|
||
|
self.Wedit.grid_forget()
|
||
|
self.Wdel.grid_forget()
|
||
|
self.Wup.grid_forget()
|
||
|
self.Wdown.grid_forget()
|
||
|
|
||
|
def set_i_widgets(self, i):
|
||
|
self.Wnum.grid(row=i, column=0, sticky=tk.W)
|
||
|
self.Wnum["text"] = "{}.".format(i+1)
|
||
|
self.Wlabel.grid(row=i, column=5, sticky=tk.W)
|
||
|
self.Wedit.grid(row=i, column=1)
|
||
|
self.Wdel.grid(row=i, column=2)
|
||
|
self.Wup.grid(row=i, column=3)
|
||
|
self.Wdown.grid(row=i, column=4)
|
||
|
|
||
|
def destroy_widgets(self):
|
||
|
self.Wnum.destroy()
|
||
|
self.Wlabel.destroy()
|
||
|
self.Wedit.destroy()
|
||
|
self.Wdel.destroy()
|
||
|
self.Wup.destroy()
|
||
|
self.Wdown.destroy()
|