rework icons, codechanges, bugfixes, typofixes

This commit is contained in:
WorldTeacher
2024-10-09 08:47:48 +02:00
parent cd74214c17
commit 2746b917eb
58 changed files with 142 additions and 89 deletions

View File

@@ -188,7 +188,16 @@ class Database:
"""
conn = self.connect()
cursor = conn.cursor()
log_message = f"{self.get_caller_line()} Querying database with query {query}, args: {args}"
logs_query = query
logs_args = args
if "fileblob" in query:
#set fileblob arg in logger to "too long"
logs_query = query
fileblob_location = query.find("fileblob")
#remove fileblob from query
logs_query = query[:fileblob_location] + "fileblob = too long"
log_message = f"{self.get_caller_line()} Querying database with query {logs_query}, args: {logs_args}"
# if "INSERT" in query:
# log_message = f"Querying database with query {query}"

View File

@@ -56,4 +56,4 @@ if __name__ == "__main__":
("SoSe 15", 1, 0),
]
print(custom_sort(unsorted))
# print(custom_sort(unsorted))

View File

@@ -109,7 +109,7 @@ class Mailer(Ui_eMailPreview):
self.buttonBox.accepted.connect(self.createAndSendMail)
def load_mail_templates(self):
print("loading mail templates")
# print("loading mail templates")
mail_templates = os.listdir("mail_vorlagen")
for template in mail_templates:
self.comboBox.addItem(template)
@@ -169,12 +169,12 @@ class Mailer(Ui_eMailPreview):
# server.starttls()
# server.auth(mechanism="PLAIN")
if config["mail"]["use_user_name"] == 1:
print(config["mail"]["user_name"])
# print(config["mail"]["user_name"])
server.login(config["mail"]["user_name"], password)
else:
server.login(sender_email, password)
server.sendmail(sender_email, self.prof_mail, mail)
print("Mail sent")
# print("Mail sent")
# end active process
server.quit()

View File

@@ -46,7 +46,7 @@ def tuple_to_dict(tlist: tuple, type: str) -> dict:
ret = []
for line in tlist:
data = makeDict()
if type == "Monographie":
if type == "Monografien":
data["type"] = type
data["work_author"] = line[0]
data["year"] = line[1]
@@ -84,10 +84,10 @@ def tuple_to_dict(tlist: tuple, type: str) -> dict:
def elsa_word_to_csv(path):
doc = Document(path)
# print all lines in doc
# # print all lines in doc
doctype = [para.text for para in doc.paragraphs if para.text != ""][-1]
tuples = {
"Monographie": ("", "", "", "", "", "", "", "", ""),
"Monografien": ("", "", "", "", "", "", "", "", ""),
"Herausgeberwerke": ("", "", "", "", "", "", "", "", "", "", ""),
"Zeitschriftenaufsätze": ("", "", "", "", "", "", "", "", "", ""),
}
@@ -113,10 +113,10 @@ def elsa_word_to_csv(path):
data = [
row for row in df.itertuples(index=False, name=None) if row != tuples[doctype]
]
print(data)
# print(data)
return tuple_to_dict(data, doctype), doctype
if __name__ == "__main__":
else_df = elsa_word_to_csv("c:/Users/aky547/Desktop/hrsgw_test.docx")
print(else_df)
else_df = elsa_word_to_csv("C:/Users/aky547/Desktop/Antrag ELSA Schweitzer.docx")
# print(else_df)

View File

@@ -178,7 +178,7 @@ class ZoteroController:
def __get_data(self, isbn):
web = WebRequest()
web.get_ppn(isbn)
data = web.get_data()
data = web.get_data_elsa()
bib = BibTextTransformer("ARRAY")
bib.get_data(data)
book = bib.return_data()

View File

@@ -1,5 +1,7 @@
import pathlib
from .Ui_semesterapparat_ui import Ui_MainWindow as Ui_Semesterapparat
from .dialogs import (
ApparatExtendDialog,
Mail_Dialog,
@@ -13,16 +15,18 @@ from .dialogs import (
About,
ElsaAddEntry,
)
from .Ui_semesterapparat_ui import Ui_MainWindow as Ui_Semesterapparat
from .widgets import (
DataGraph,
FilePicker,
StatusWidget,
CalendarEntry,
MessageCalendar,
SearchStatisticPage, #
DataGraph,
ElsaDialog,
UserCreate,
EditUser,
EditProf,
)
path = pathlib.Path(__file__).parent.absolute()
# from .mainwindow import Ui_MainWindow as Ui_MainWindow
# from .sap import Ui_MainWindow as MainWindow_SAP

View File

@@ -74,7 +74,7 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="createApparat">
<property name="sizePolicy">

View File

@@ -59,7 +59,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
data.btn_zs.click()
elif mediatype == "Herausgeberwerke":
data.btn_hg.click()
elif mediatype == "Monographie":
elif mediatype == "Monograpfien":
data.btn_mono.click()
data.exec()
@@ -70,7 +70,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
self.dokument_list_elsa.setRowCount(0)
profs = self.db.getProfs()
for prof in profs:
self.elsa_prof.addItem(f"{prof[3]}, {prof[2]}")
self.elsa_prof.addItem(f"{prof.lastname}, {prof.firstname}")
self.elsa_prof.setCurrentText("")
self.elsa_date.setText("")
self.elsa_semester.setText("")
@@ -155,6 +155,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
def open_elsa(self):
prof = self.elsa_table.item(self.elsa_table.currentRow(), 0).text()
print(prof)
date = self.elsa_table.item(self.elsa_table.currentRow(), 1).text()
semester = self.elsa_table.item(self.elsa_table.currentRow(), 2).text()
self.elsa_update.setEnabled(True)

View File

@@ -84,6 +84,7 @@ class Ui_Dialog(object):
self.label_2.setObjectName("label_2")
self.gridLayout_2.addWidget(self.label_2, 1, 0, 1, 1)
self.elsa_prof = QtWidgets.QComboBox(parent=self.create_frame_elsa)
self.elsa_prof.setEditable(True)
self.elsa_prof.setObjectName("elsa_prof")
self.gridLayout_2.addWidget(self.elsa_prof, 0, 1, 1, 1)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
@@ -101,7 +102,7 @@ class Ui_Dialog(object):
self.dokument_list_elsa = QtWidgets.QTableWidget(parent=self.create_frame_elsa)
self.dokument_list_elsa.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.dokument_list_elsa.setObjectName("dokument_list_elsa")
self.dokument_list_elsa.setColumnCount(3)
self.dokument_list_elsa.setColumnCount(4)
self.dokument_list_elsa.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.dokument_list_elsa.setHorizontalHeaderItem(0, item)
@@ -109,6 +110,8 @@ class Ui_Dialog(object):
self.dokument_list_elsa.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.dokument_list_elsa.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.dokument_list_elsa.setHorizontalHeaderItem(3, item)
self.dokument_list_elsa.horizontalHeader().setDefaultSectionSize(116)
self.dokument_list_elsa.horizontalHeader().setMinimumSectionSize(43)
self.dokument_list_elsa.verticalHeader().setMinimumSectionSize(25)
@@ -223,6 +226,8 @@ class Ui_Dialog(object):
item.setText(_translate("Dialog", "Dateityp"))
item = self.dokument_list_elsa.horizontalHeaderItem(2)
item.setText(_translate("Dialog", "Neu?"))
item = self.dokument_list_elsa.horizontalHeaderItem(3)
item.setText(_translate("Dialog", "File"))
self.btn_add_document_elsa.setText(_translate("Dialog", "Dokument hinzufügen"))
self.btn_open_document_elsa.setText(_translate("Dialog", "Dokument öffnen"))
self.check_file_elsa.setText(_translate("Dialog", "Medien aus Dokument\n"

View File

@@ -174,7 +174,11 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="elsa_prof"/>
<widget class="QComboBox" name="elsa_prof">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
@@ -238,6 +242,11 @@
<string>Neu?</string>
</property>
</column>
<column>
<property name="text">
<string>File</string>
</property>
</column>
</widget>
</item>
<item>

View File

@@ -1,31 +1,89 @@
import darkdetect
from omegaconf import OmegaConf
from PyQt6 import QtGui
import re
config = OmegaConf.load("config.yaml")
config = OmegaConf.load(f"{config.icon_path}/icons.yaml")
path = config.icon_path
dark = darkdetect.isDark()
mode = "dark" if dark else "light"
path = f"{path}/{mode}"
class Icon:
def __init__(self, icon_type, widget=None):
class Icon:
def __init__(self, icon_type, widget=None,recolor=False):
dark = darkdetect.isDark()
if dark:
self.color = config.dark_color
else:
self.color = config.light_color
self.icon = QtGui.QIcon()
self.add_icon(icon_type)
self.icon_path = path + config["icons"][icon_type]
self.add_icon(self.icon_path,recolor)
if widget is not None:
widget.setIcon(self.icon)
def add_icon(self, icon_type):
icon = config[icon_type]
icon = f"{path}/{icon}"
def add_icon(self, icon_path,recolor=False):
icon = self.changeColor(icon_path,recolor)
# use icon bytes to create a pixmap
pixmap = QtGui.QPixmap()
pixmap.loadFromData(icon)
self.icon.addPixmap(
QtGui.QPixmap(icon),
pixmap,
QtGui.QIcon.Mode.Normal,
QtGui.QIcon.State.Off,
)
def overwriteColor(self, color):
# take the icon, read it as bytes and change the color in fill
icon = self.changeColor(self.icon_path)
cicon = str(icon)
fill = re.search(r"fill=\"(.*?)\"", cicon).group(1)
stroke = re.search(r"stroke=\"(.*?)\"", cicon)
if stroke:
stroke = stroke.group(1)
if fill and stroke:
# replace stroke
newicon = icon.replace(stroke.encode(), color.encode())
else:
newicon = icon.replace(fill.encode(), color.encode())
pixmap = QtGui.QPixmap()
pixmap.loadFromData(newicon)
self.icon.addPixmap(
pixmap,
QtGui.QIcon.Mode.Normal,
QtGui.QIcon.State.Off,
)
return self.icon
def changeColor(self,icon_path,recolor) -> bytes:
"""change the color of the svg icon to the color set in the config file
Args:
icon_path (str): the path to the icon, usually icons/[name].svg
Returns:
icon: a byte representation of the icon with the new color
"""
color = self.color
with open(icon_path, "rb") as file:
icon = file.read()
if recolor:
cicon = str(icon)
try:
fill = re.search(r"fill=\"(.*?)\"", cicon).group(1)
except AttributeError:
fill = None
if fill:
icon = icon.replace(fill.encode(), color.encode())
return icon
if __name__ == "__main__":
print("This is a module and can not be executed directly.")