Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff94sl committed Jan 7, 2022
0 parents commit fca8ad6
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/PyImagepdf.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added PDF/__init__.py
Empty file.
Binary file added PDF/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added PDF/__pycache__/pdfimage.cpython-38.pyc
Binary file not shown.
31 changes: 31 additions & 0 deletions PDF/pdfimage.py
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
27 changes: 27 additions & 0 deletions gui/Lista.py
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
11 changes: 11 additions & 0 deletions gui/Menu.py
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)
69 changes: 69 additions & 0 deletions gui/Window.py
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 added gui/__init__.py
Empty file.
Binary file added gui/__pycache__/Lista.cpython-38.pyc
Binary file not shown.
Binary file added gui/__pycache__/Menu.cpython-38.pyc
Binary file not shown.
Binary file added gui/__pycache__/Window.cpython-38.pyc
Binary file not shown.
Binary file added gui/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions main.py
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_())
4 changes: 4 additions & 0 deletions requirements.txt
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
12 changes: 12 additions & 0 deletions setup.py
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'
)
15 changes: 15 additions & 0 deletions test.py
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()

0 comments on commit fca8ad6

Please sign in to comment.