89 lines
2.7 KiB
Python
89 lines
2.7 KiB
Python
# -*-coding:utf-8 -*
|
|
|
|
import tkinter as tk
|
|
from pdfembannersrc import editwmark
|
|
from pdfembannersrc import strings
|
|
import logging
|
|
logger = logging.getLogger()
|
|
|
|
class Wmark:
|
|
"""
|
|
Class to store data on a watermark
|
|
"""
|
|
count = 0
|
|
default_name = "New watermark"
|
|
def __init__(self, filename):
|
|
self.id = Wmark.count
|
|
Wmark.count += 1
|
|
|
|
self.name = Wmark.default_name + " {}".format(self.id+1)
|
|
self.position = None
|
|
self.userposition = None
|
|
self.text = None
|
|
self.size = None
|
|
self.notfirstpage = False
|
|
self.notlastpage = False
|
|
self.notpages = None
|
|
self.onlyfirstpage = False
|
|
self.onlylastpage = False
|
|
self.onlypages = None
|
|
self.bold = False
|
|
self.italic = False
|
|
self.boxed = False
|
|
self.lined = False
|
|
|
|
self.Wnum =None
|
|
self.Wlabel = None
|
|
self.Wedit = None
|
|
self.Wdel = None
|
|
|
|
def edit(self, parent):
|
|
parent.message["text"] = "Edit Watermark"
|
|
interface2 = editwmark.InterfaceEdit(parent, self)
|
|
|
|
def add_widgets(self, frame, parent, i):
|
|
self.Wnum = tk.Label(frame, text="{}.".format(i+1))
|
|
self.Wlabel = tk.Label(frame, text=self.name)
|
|
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.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()
|
|
|
|
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=3, sticky=tk.W)
|
|
self.Wedit.grid(row=i, column=1)
|
|
self.Wdel.grid(row=i, column=2)
|
|
|
|
def destroy_widgets(self):
|
|
self.Wnum.destroy()
|
|
self.Wlabel.destroy()
|
|
self.Wedit.destroy()
|
|
self.Wdel.destroy()
|
|
|
|
def format_tex(self):
|
|
s = self.text
|
|
s = s.replace(" %p ", "~\\thepage~")
|
|
s = s.replace("%p ", "\\thepage~")
|
|
s = s.replace(" %p", "~\\thepage")
|
|
s = s.replace("%p", "\\thepage")
|
|
s = s.replace(" %P", "~\\pageref{LastPage}")
|
|
s = s.replace("%P", "\\pageref{LastPage}")
|
|
if(self.size is not None):
|
|
s = strings.tex_size[self.size]+ " " + s
|
|
if(self.bold):
|
|
s = "\\bfseries " + s
|
|
if(self.italic):
|
|
s = "\\itshape " + s
|
|
if(self.size is not None or self.bold or self.italic):
|
|
s = "{" + s + "}"
|
|
if(self.boxed):
|
|
s = "\\framebox[1.1\\width]{" + s + "}"
|
|
return s
|