-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fca8ad6
Showing
21 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import imagesize | ||
from PaPDF.PaPDF import PaPDF | ||
|
||
|
||
class Convert: | ||
def __init__(self): | ||
super(Convert, self).__init__() | ||
|
||
def texttopdf(self, filename, text, x, y): | ||
with PaPDF(filename) as pdf: | ||
pdf.addText(x, y, text) | ||
return True | ||
|
||
def imgtopdf(self, filename, imgs, x, y, w, h): | ||
with PaPDF(filename) as pdf: | ||
for img in imgs: | ||
pdf.addImage(img, x, y, w, h) | ||
pdf.addPage() | ||
return True | ||
|
||
def imgtopdfautosize(self, filename, imgs): | ||
with PaPDF(filename) as pdf: | ||
for img in imgs: | ||
w, h = imagesize.get(img) | ||
if w < 190 and h < 280: | ||
pdf.addImage(img, pdf.h_mm/4, pdf.w_mm/1.9, w, h) | ||
pdf.addPage() | ||
else: | ||
pdf.addImage(img, 10, 10, 190, 280) | ||
pdf.addPage() | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from PyQt5.QtCore import QStringListModel | ||
from PyQt5.QtWidgets import QListView | ||
|
||
|
||
class Lista(QListView): | ||
def __init__(self): | ||
super(Lista, self).__init__() | ||
self.lista = [] | ||
self.modelo = QStringListModel() | ||
self.modelo.setStringList(self.lista) | ||
self.setModel(self.modelo) | ||
|
||
def agregar(self, item): | ||
self.lista.append(item) | ||
self.modelo.setStringList(self.lista) | ||
|
||
def eliminar(self): | ||
self.modelo.removeRow(self.modelo.rowCount() - 1) | ||
del self.lista[- 1] | ||
print("Modelo: ", self.modelo.rowCount()) | ||
print(self.listacount()) | ||
|
||
def listacount(self): | ||
count = 0 | ||
for _ in self.lista: | ||
count += 1 | ||
return count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from PyQt5.QtWidgets import QMenuBar | ||
from PyQt5.QtWidgets import QMenu | ||
from PyQt5.QtWidgets import QAction | ||
|
||
class Menu(QMenuBar): | ||
def __init__(self): | ||
super(Menu, self).__init__() | ||
archivo = QMenu("&Archivo",self) | ||
abrir = QAction("A&brir",self) | ||
archivo.addAction(abrir) | ||
self.addMenu(archivo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from pathlib import Path | ||
from PyQt5.QtWidgets import QWidget | ||
from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout | ||
from PyQt5.QtWidgets import QPushButton, QFileDialog, QMessageBox | ||
from PDF.pdfimage import Convert | ||
from gui.Lista import Lista | ||
|
||
|
||
class Window(QWidget): | ||
def __init__(self): | ||
super(Window, self).__init__() | ||
self.setWindowTitle("PyImgpdf") | ||
self.resize(400, 300) | ||
|
||
self.pdf = Convert() | ||
self.msg = QMessageBox() | ||
|
||
vl = QVBoxLayout() | ||
hl = QHBoxLayout() | ||
|
||
self.lista = Lista() | ||
agregar = QPushButton(self.tr('Aceptar')) | ||
agregar.clicked.connect(self.event_agregar) | ||
eliminar = QPushButton("Eliminar") | ||
eliminar.clicked.connect(self.event_eliminar) | ||
convertir = QPushButton("Convertir") | ||
convertir.clicked.connect(self.event_convertir) | ||
|
||
hl.addWidget(agregar) | ||
hl.addWidget(eliminar) | ||
hl.addWidget(convertir) | ||
|
||
vl.addWidget(self.lista) | ||
|
||
vl.addLayout(hl) | ||
|
||
self.setLayout(vl) | ||
|
||
def event_agregar(self): | ||
filename, _ = QFileDialog.getOpenFileName(self.parentWidget(), 'Agregar Imagen', f'{Path.home()}', | ||
'Imagenes(*.jpeg *.jpg *.png)') | ||
if not filename: | ||
print('filename es vacio') | ||
else: | ||
self.lista.agregar(filename) | ||
print('filename no es vacio') | ||
|
||
|
||
def event_eliminar(self): | ||
if self.lista.modelo.rowCount() > 0: | ||
self.lista.eliminar() | ||
|
||
def event_convertir(self): | ||
if self.lista.modelo.rowCount() > 0: | ||
filename, _ = QFileDialog.getSaveFileName(self.parentWidget(), 'Guardar Pdf', f'{Path.home()}', 'Pdf(*.pdf)') | ||
self.pdf.imgtopdfautosize(filename, self.lista.lista) | ||
self.msg.setWindowTitle('Convertido') | ||
self.msg.setIcon(QMessageBox.Information) | ||
self.msg.setText('Convercion Completada!') | ||
self.msg.setStandardButtons(QMessageBox.Ok) | ||
self.msg.exec_() | ||
self.lista.lista.clear() | ||
self.lista.modelo.setStringList(self.lista.lista) | ||
else: | ||
self.msg.setWindowTitle('Error') | ||
self.msg.setIcon(QMessageBox.Warning) | ||
self.msg.setText('Agrege imagenes para poder convertir!') | ||
self.msg.setStandardButtons(QMessageBox.Ok) | ||
self.msg.exec_() |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import sys | ||
from PyQt5.QtCore import QLocale,QTranslator,QLibraryInfo | ||
from PyQt5.QtWidgets import QApplication | ||
from gui.Window import Window | ||
|
||
if __name__ == '__main__': | ||
app = QApplication(sys.argv) | ||
|
||
traductor = QTranslator() | ||
traductor.load("qtbase_"+ QLocale.system().name(), | ||
QLibraryInfo.location(QLibraryInfo.TranslationsPath)) | ||
app.installTranslator(traductor) | ||
|
||
win = Window() | ||
win.show() | ||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PaPDF~=1.1.5 | ||
PyQt5~=5.15.6 | ||
imagesize~=1.3.0 | ||
setuptools==60.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='PyImagepdf', | ||
version='1', | ||
packages=['PDF', 'gui'], | ||
url='', | ||
license='GPL', | ||
author='Jefrin Salgado', | ||
author_email='jeffrynsl@gmail.com', | ||
description='Convertidor de imagenes a pdf' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import unittest | ||
from PDF.pdfimage import Convert | ||
|
||
|
||
class MyTestCase(unittest.TestCase): | ||
|
||
def test_imagensize(self): | ||
c = Convert() | ||
imgs = ['/home/jeff/icon.png','/home/jeff/p.jpg'] | ||
result = c.imgtopdfautosize("/home/jeff/testimgauto.pdf", imgs) | ||
self.assertEqual(result, True) # add assertion here | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |