Fummeljob hierum darum

This commit is contained in:
2025-02-12 09:01:38 +01:00
parent b162117a80
commit bfd1d0974d
31 changed files with 1386 additions and 61 deletions

View File

@@ -41,7 +41,7 @@ class ConfigLoader(QObject):
else:
config_dir.mkdir(0o750, True, True)
@Slot(dict, result= bool)
@Slot(dict, result = bool)
def setConfig(self, app_config):
# print(f"In {__file__} file, setConfig()")
if not self.__config:

View File

@@ -27,6 +27,17 @@ class BusinessDAO(QObject):
except mariadb.Error as e:
print(str(e))
def getOneBusiness(self, business_id, enc_key = None):
try:
if self.__cur:
self.__cur.callproc("getCustomer", (business_id, enc_key,))
#self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall() #, self.__all_cols
else:
return None #, None
except mariadb.Error as e:
print(str(e))
def addBusiness(self, data, contact_id):
try:
if self.__cur:

View File

@@ -65,6 +65,8 @@ class BusinessModel(QAbstractTableModel):
__visible_index = {}
__col_name = ""
__business_dao = None
__business = None
__business_dict = {'business':{}} #,'contact':{}}
def __init__(self):
super().__init__()
@@ -80,6 +82,22 @@ class BusinessModel(QAbstractTableModel):
self.__data = rows
self.endResetModel()
def __getBusinessInfo(self):
self.__business_dict['business']['id'] = self.__business[0][0]
self.__business_dict['business']['contactid'] = self.__business[0][1]
self.__business_dict['business']['company'] = self.__business[0][2]
self.__business_dict['business']['phone'] = self.__business[0][3]
self.__business_dict['business']['cell'] = self.__business[0][4]
self.__business_dict['business']['email'] = self.__business[0][5]
self.__business_dict['business']['website'] = self.__business[0][6]
self.__business_dict['business']['ceo'] = self.__business[0][7]
self.__business_dict['business']['info'] = self.__business[0][8]
self.__business_dict['business']['tax'] = self.__business[0][9]
self.__business_dict['business']['street'] = self.__business[0][10]
self.__business_dict['business']['house'] = self.__business[0][11]
self.__business_dict['business']['zip'] = self.__business[0][12]
self.__business_dict['business']['city'] = self.__business[0][13]
def rowCount(self, parent= QModelIndex()):
return len (self.__data)
@@ -113,7 +131,17 @@ class BusinessModel(QAbstractTableModel):
@Slot(int)
def onRowClicked(self, row):
print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
#print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
if not self.__business_dict['business'] or self.__data[row][0] != self.__business_dict['business']['id']:
self.__business = self.__business_dao.getOneBusiness(self.__data[row][0], self.__key)
#print(self.__business)
self.__getBusinessInfo()
# self.__getContactInfo()
# print(self.__business_dict)
@Slot(result = dict)
def getClientDetails(self):
return self.__business_dict
@Slot(str)
def viewCriterion(self, criterion):
@@ -134,5 +162,3 @@ class BusinessModel(QAbstractTableModel):
def updateTable(self):
pass

View File

@@ -30,4 +30,15 @@ class ContactDAO:
except Exception as e:
print("PYT: " + str(e))
def getContact(self, contact_id, enc_key = None):
try:
if self.__cur:
self.__cur.callproc("getCustomerContact", (contact_id, enc_key,))
#self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall() #, self.__all_cols
else:
return None #, None
except mariadb.Error as e:
print(str(e))

View File

@@ -5,6 +5,10 @@ import logging
class ContactModel(QObject):
contactIdReady = Signal(int)
__contact = None
__contact_dict = {'contact':{}}
def __init__(self):
super().__init__()
# print(f"*** File: {__file__}, __init__()")
@@ -27,5 +31,29 @@ class ContactModel(QObject):
i = ContactDAO().addContact(contact, self.__key)
self.contactIdReady.emit(i)
def __getContact(self, contact):
self.__contact = ContactDAO().getContact(contact, self.__key)
self.__getContactInfo()
@Slot(int, result = dict)
def getContactDetails(self, contact):
self.__getContact(contact)
#print(self.__contact_dict)
return self.__contact_dict
def __getContactInfo(self):
self.__contact_dict['contact']['id'] = self.__contact[0][0]
self.__contact_dict['contact']['salute'] = self.__contact[0][1]
self.__contact_dict['contact']['fname'] = self.__contact[0][2].decode("utf-8")
self.__contact_dict['contact']['lname'] = self.__contact[0][3].decode("utf-8")
self.__contact_dict['contact']['phone'] = self.__contact[0][4].decode("utf-8")
self.__contact_dict['contact']['cell'] = self.__contact[0][5].decode("utf-8")
self.__contact_dict['contact']['position'] = self.__contact[0][6]
self.__contact_dict['contact']['email'] = self.__contact[0][7].decode("utf-8")
self.__contact_dict['contact']['birthday'] = self.__contact[0][8].decode("utf-8")
self.__contact_dict['contact']['priority'] = "Ja" if self.__contact[0][9] else "Nein"
self.__contact_dict['contact']['invoice'] = "Ja" if self.__contact[0][10] else "Nein"
self.__contact_dict['contact']['reminder'] = "Ja" if self.__contact[0][11] else "Nein"

View File

@@ -1,9 +1,13 @@
from .DbManager import DbManager
from ..PyqcrmFlags import PyqcrmFlags
from ..Vermasseln import Vermasseln
from PySide6.QtMultimedia import QMediaPlayer, QAudioOutput
#from PySide6.QtMultimedia import QMediaPlayer, QAudioOutput : Not working well with Nuitka
import soundfile as sf
import sounddevice as sd
from .UserDAO import UserDAO
from PySide6.QtCore import Slot, QObject, Signal, QUrl
from PySide6.QtCore import Slot, QObject, Signal, QUrl, QFile
import tempfile
class UserManager(QObject):
@@ -61,12 +65,24 @@ class UserManager(QObject):
if user:
self.__checkPassword(password, user[2])
else:
player = QMediaPlayer(self)
audioOutput = QAudioOutput(self)
player.setAudioOutput(audioOutput)
player.setSource(QUrl("qrc:/sounds/fail2c.ogg"))
audioOutput.setVolume(150)
player.play()
fail_src = ":/sounds/fail2c.ogg"
with tempfile.NamedTemporaryFile(suffix='.ogg') as ogg_file:
failure_sound = QFile(fail_src)
if not failure_sound.open(QFile.ReadOnly):
print(f"Failed to open resource file: {fail_src}")
else:
ogg_file.write(failure_sound.readAll())
ogg_path = ogg_file.name
fail, samplerate = sf.read(ogg_path)
sd.play(fail, samplerate)
### Not working with Nuitka
# player = QMediaPlayer(self)
# audioOutput = QAudioOutput(self)
# player.setAudioOutput(audioOutput)
# player.setSource(QUrl("qrc:/sounds/fail2c.ogg"))
# audioOutput.setVolume(150)
# player.play()
def __checkPassword(self, password, hash_password):
pw_list = hash_password.split("$")

23
lib/Printers.py Normal file
View File

@@ -0,0 +1,23 @@
from PySide6.QtCore import QObject, Slot
from PySide6.QtPrintSupport import QPrinterInfo
class Printers(QObject):
__printers = None
__default_printer = None
__default_printer_name = None
__available_printers = []
def __init__(self):
super().__init__()
self.__printers = QPrinterInfo.availablePrinters()
self.__available_printers = QPrinterInfo.availablePrinterNames()
self.__default_printer = QPrinterInfo.defaultPrinter()
self.__default_printer_name = QPrinterInfo.defaultPrinterName()
@Slot(result = list)
def getPrinters(self):
return self.__available_printers
@Slot(result = str)
def getDefaultPrinter(self):
return self.__default_printer_name

81
lib/PyqcrmPDF.py Normal file
View File

@@ -0,0 +1,81 @@
from reportlab.lib.pagesizes import A4 #, letter...etc
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
'''
Need to check for sender and receiver sections
Other alternatives can be pdf-gen, pdf-generator, pdf-play, pdf34, abdul-987-pdf
'''
class PyqcrmPDF:
__pyq_doc = None
__pyq_pdf = None
__pyq_usable_width = 0
__pyq_usable_height = 0
__pyq_lr_margin = 20
__pyq_tb_margin = 25
__line = 0
__line_height = 14
__doc_title = "PYQCRM PDF Document"
__doc_author = "The PYQCRM Team"
__doc_subject = "PYQCRM Document"
def __init__(self, doc_title, doc_subject, pdf_file):
self.__pyq_usable_width = A4[0] - self.__pyq_lr_margin - self.__pyq_lr_margin
self.__pyq_usable_height = A4[1] - self.__pyq_tb_margin - self.__pyq_tb_margin
self.__line = self.__pyq_usable_height + self.__pyq_tb_margin
self.__pyq_pdf = canvas.Canvas(pdf_file, pagesize=A4)
self.__pyq_pdf.setAuthor(self.__doc_author)
self.__pyq_pdf.setTitle(doc_title if doc_title else self.__doc_title)
self.__pyq_pdf.setSubject(doc_subject if doc_subject else self.__doc_subject)
self.__pyq_doc = self.__pyq_pdf.beginText(self.__pyq_lr_margin, self.__line)
self.__pyq_doc.setFont("Helvetica", 12)
def addLine(self, line):
#self.__pyq_pdf.drawString(self.__pyq_lr_margin, self.__line, line) : Need to check if it does the trick!
# print(f"Line No.: {self.__line}")
# print(f"Line: {line}")
if self.__pyq_doc.getY() < self.__pyq_tb_margin:
# print("creating a new page...")
self.__pyq_pdf.drawText(self.__pyq_doc)
self.__pyq_pdf.showPage()
self.__line = self.__pyq_usable_height + self.__pyq_tb_margin
# print(f"Line No.: {self.__line}")
self.__pyq_doc = self.__pyq_pdf.beginText(self.__pyq_lr_margin, self.__line)
self.__pyq_doc.setFont("Helvetica", 12)
if pdfmetrics.stringWidth(line, "Helvetica", 12) > self.__pyq_usable_width:
# print(f"Line width: {pdfmetrics.stringWidth(line, 'Helvetica', 12)}, Available width: {self.__pyq_usable_width}")
words = line.split(' ')
line = ''
for word in words:
# print(f"Line: {line}")
if self.__pyq_doc.getY() < self.__pyq_tb_margin:
# print("creating a new page...")
self.__pyq_pdf.drawText(self.__pyq_doc)
self.__pyq_pdf.showPage()
self.__line = self.__pyq_usable_height + self.__pyq_tb_margin
# print(f"Line No.: {self.__line}")
self.__pyq_doc = self.__pyq_pdf.beginText(self.__pyq_lr_margin, self.__line)
self.__pyq_doc.setFont("Helvetica", 12)
if pdfmetrics.stringWidth(line + word + ' ', "Helvetica", 12) <= self.__pyq_usable_width:
line = line + word + ' '
else:
self.__pyq_doc.textLine(line)
line = word + ' '
# print(f"Last line: {line}")
if line:
# print(f"Available line: {line}")
self.__pyq_doc.textLine(line)
self.__line = self.__line + self.__line_height
def saveDoc(self):
self.__pyq_pdf.drawText(self.__pyq_doc)
self.__pyq_pdf.showPage()
self.__pyq_pdf.save()