Reworked logging

Re-implemented logging using python's logging module instead of simple print() calls.
dev
Peery 3 years ago
parent 756b95abc8
commit 7a41c675ec

@ -1,6 +1,8 @@
import shutil import shutil
import sys import sys
import os import os
import logging
import datetime
from hashlib import md5 from hashlib import md5
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
@ -14,13 +16,28 @@ from ArtNet.web.link_generator import LinkGenerator
class ArtNetManager: class ArtNetManager:
LOG_FOLDER = "log"
def __init__(self, config_location: str = "."): def __init__(self, config_location: str = "."):
if not os.path.isdir(ArtNetManager.LOG_FOLDER):
os.mkdir(ArtNetManager.LOG_FOLDER)
file_name = "artnet-" + str(datetime.datetime.now().strftime("%Y-%m-%d")) + ".log"
logging.basicConfig(filename=os.path.join(ArtNetManager.LOG_FOLDER, file_name), encoding='utf-8',
level=logging.DEBUG)
logFormatter = logging.Formatter(fmt="%(asctime)s.%(msecs)03d [%(threadName)-12.12s] [%(levelname)-5.5s] "
"%(message)s",
datefmt="%Y-%m-%d %H:%M:%S")
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
for handler in logging.getLogger().handlers:
handler.setFormatter(logFormatter)
logging.info("Starting ArtNet client ...")
self.known_image_amount = None self.known_image_amount = None
self.config = ConfigReader(config_location, "somePassword") self.config = ConfigReader(config_location, "somePassword")
if self.config.data["version"] != self.config.CONFIG_VERSION: if self.config.data["version"] != self.config.CONFIG_VERSION:
print("Loaded config version is unequal to expected version! {0} (current) != {1} (expected)" logging.warning("Loaded config version is unequal to expected version! {0} (current) != {1} (expected)"
.format(self.config.data["version"], self.config.CONFIG_VERSION)) .format(self.config.data["version"], self.config.CONFIG_VERSION))
self.db_connection = None self.db_connection = None
@ -34,7 +51,7 @@ class ArtNetManager:
port=self.config.data["db"]["port"], port=self.config.data["db"]["port"],
database=self.config.data["db"]["database"]) database=self.config.data["db"]["database"])
except ValueError as e: # db connection didn't work except ValueError as e: # db connection didn't work
print(e) logging.error(e)
dialog = DBDialog() dialog = DBDialog()
prev_db_data = self.get_db_connection_details() prev_db_data = self.get_db_connection_details()
dialog.ui.user_line_edit.setText(prev_db_data["user"]) dialog.ui.user_line_edit.setText(prev_db_data["user"])
@ -51,8 +68,9 @@ class ArtNetManager:
database=db_data["database"]) database=db_data["database"])
self.window = Window(self) self.window = Window(self)
if len(self.config.data["file_root"]) == 0 or not os.path.isdir(self.config.data["file_root"]): # no file_root given by config or invalid if len(self.config.data["file_root"]) == 0 or not os.path.isdir(
print("Querying for new file root due to lack of valid one ...") self.config.data["file_root"]): # no file_root given by config or invalid
logging.info("Querying for new file root due to lack of valid one ...")
self.window.on_artnet_root_change_clicked() self.window.on_artnet_root_change_clicked()
self.__file_reader = FileReader(self.config.data["file_root"]) self.__file_reader = FileReader(self.config.data["file_root"])
@ -71,7 +89,9 @@ class ArtNetManager:
self.window.show() self.window.show()
sys.exit(self.__app.exec_()) status = self.__app.exec_()
logging.info(f"Shutting client down with status: {status}")
sys.exit(status)
def update_all_images_list(self): def update_all_images_list(self):
""" """
@ -204,7 +224,7 @@ class ArtNetManager:
full_art_path = self.get_root() + os.path.sep + path full_art_path = self.get_root() + os.path.sep + path
if delete_instead_of_move: if delete_instead_of_move:
print(f"Deleting the actual file {full_art_path} is disabled for now") logging.warning(f"Deleting the actual file {full_art_path} is disabled for now")
# os.remove(full_art_path) # os.remove(full_art_path)
# return # return
@ -215,17 +235,15 @@ class ArtNetManager:
t_path += os.path.sep + t_splits[i] t_path += os.path.sep + t_splits[i]
t_path = t_path[1:] t_path = t_path[1:]
if not os.path.exists(t_path): if not os.path.exists(t_path):
print(f"{t_path} did not exist and will be created!") logging.info(f"{t_path} did not exist and will be created!")
os.makedirs("." + os.path.sep + t_path) os.makedirs("." + os.path.sep + t_path)
print(f"Moving image {full_art_path} to {trash_dst}") logging.info(f"Moving image {full_art_path} to {trash_dst}")
shutil.move(full_art_path, trash_dst) shutil.move(full_art_path, trash_dst)
self.update_all_images_list() self.update_all_images_list()
while self.curr_image_index >= len(self.all_images): while self.curr_image_index >= len(self.all_images):
self.curr_image_index -= 1 self.curr_image_index -= 1
@DeprecationWarning @DeprecationWarning
def recalculate_hash_for_known_images(self): def recalculate_hash_for_known_images(self):
""" """
@ -353,18 +371,19 @@ class ArtNetManager:
image_link = "(Unknown)" image_link = "(Unknown)"
image_description = None image_description = None
print(f"Displaying #{self.curr_image_index} \"{self.all_images[self.curr_image_index]}\"") logging.info(f"Displaying #{self.curr_image_index} \"{self.all_images[self.curr_image_index]}\"")
self.window.display_image(image_title, image_author, self.window.display_image(image_title, image_author,
os.path.join(self.config.data["file_root"], self.all_images[self.curr_image_index]), os.path.join(self.config.data["file_root"], self.all_images[self.curr_image_index]),
self.all_images[self.curr_image_index], self.all_images[self.curr_image_index],
art_ID, image_link, file_name=s[-1], description=image_description) art_ID, image_link, file_name=s[-1], description=image_description)
self.window.set_tag_list([self.db_connection.get_tag_by_ID(x)[0][1].strip() for x in self.db_connection.get_art_tags_by_ID(art_ID)]) self.window.set_tag_list(
[self.db_connection.get_tag_by_ID(x)[0][1].strip() for x in self.db_connection.get_art_tags_by_ID(art_ID)])
self.window.data_changed = False self.window.data_changed = False
self.window.setting_up_data = False self.window.setting_up_data = False
def create_db_connection(self, host: str, port: int, database: str, user: str, password: str) -> DBAdapter: def create_db_connection(self, host: str, port: int, database: str, user: str, password: str) -> DBAdapter:
print(f"Changing db connection to {host}:{port} {user}@{database} ...") logging.info(f"Changing db connection to {host}:{port} {user}@{database} ...")
return DBAdapter(user=user, password=password, host=host, port=port, database=database) return DBAdapter(user=user, password=password, host=host, port=port, database=database)
def get_root(self) -> str: def get_root(self) -> str:
@ -380,7 +399,7 @@ class ArtNetManager:
""" """
if len(path) == 0: if len(path) == 0:
exit(0) exit(0)
print("Changing root to", path) logging.info("Changing root to", path)
self.config.data["file_root"] = path self.config.data["file_root"] = path
self.config.update_config() self.config.update_config()
self.__file_reader = FileReader(self.config.data["file_root"]) self.__file_reader = FileReader(self.config.data["file_root"])
@ -400,5 +419,3 @@ class ArtNetManager:
self.config.update_config() self.config.update_config()
self.db_connection = self.create_db_connection(host, port, database, user, password) self.db_connection = self.create_db_connection(host, port, database, user, password)

@ -1,3 +1,4 @@
import logging
import psycopg2 import psycopg2
from psycopg2.errorcodes import UNIQUE_VIOLATION from psycopg2.errorcodes import UNIQUE_VIOLATION
@ -17,9 +18,10 @@ class DBAdapter:
except psycopg2.OperationalError as e: except psycopg2.OperationalError as e:
raise ValueError("Invalid DB credentials!") raise ValueError("Invalid DB credentials!")
print("DB connection established to {0}:{1}/{2}".format(host, port, database)) logging.debug("DB connection established to {0}:{1}/{2}".format(host, port, database))
if not self.check_tables(): if not self.check_tables():
logging.debug("Database schema check has failed! The expected tables have not been present.")
raise ValueError("Invalid DB schema!") raise ValueError("Invalid DB schema!")
def check_tables(self) -> bool: def check_tables(self) -> bool:
@ -39,11 +41,11 @@ class DBAdapter:
missing.remove(table) missing.remove(table)
if len(missing) > 0: if len(missing) > 0:
print("The following tables are missing from the currently connected database: {0}".format(missing)) logging.error("The following tables are missing from the currently connected database: {0}".format(missing))
return False return False
if len(unknown_tables) > 0: if len(unknown_tables) > 0:
print("The following tables are unknown and not expected inside the database: {0}".format(unknown_tables)) logging.error("The following tables are unknown and not expected inside the database: {0}".format(unknown_tables))
return True return True
@ -60,7 +62,7 @@ class DBAdapter:
:param desc: image description or None for empty :param desc: image description or None for empty
:return: :return:
""" """
print("Saving Image {0}:{1} authors: {2} path: {3} tags: {4} link: {5} hash:{6} desc:{7}" logging.debug("Saving Image {0}:{1} authors: {2} path: {3} tags: {4} link: {5} hash:{6} desc:{7}"
.format(ID, title, authors, path, tags, link, md5_hash, desc)) .format(ID, title, authors, path, tags, link, md5_hash, desc))
d = {"title": title, "path": path, "id": ID, "link": link, "hash": md5_hash, "desc": desc} d = {"title": title, "path": path, "id": ID, "link": link, "hash": md5_hash, "desc": desc}
if self.get_art_by_path(path) is None: if self.get_art_by_path(path) is None:
@ -92,8 +94,8 @@ class DBAdapter:
self.db_cursor.execute("INSERT INTO art_tag (art_id, tag_ID) VALUES (%(id)s, %(tag)s)", d) self.db_cursor.execute("INSERT INTO art_tag (art_id, tag_ID) VALUES (%(id)s, %(tag)s)", d)
except psycopg2.Error as e: except psycopg2.Error as e:
if e.pgcode == UNIQUE_VIOLATION: if e.pgcode == UNIQUE_VIOLATION:
print(e) logging.debug(e)
print("Skipping Unique Violation ...") logging.info("Skipping Unique Violation ...")
else: else:
raise e raise e
@ -125,7 +127,7 @@ class DBAdapter:
""" """
image_data = self.get_art_by_hash(hash) image_data = self.get_art_by_hash(hash)
art_ID = image_data["ID"] art_ID = image_data["ID"]
print(f"Deleting image #{art_ID} {image_data['title']}") logging.debug(f"Deleting image #{art_ID} {image_data['title']}")
tags = self.get_art_tags_by_ID(art_ID) tags = self.get_art_tags_by_ID(art_ID)
for tag_ID in tags: for tag_ID in tags:
pass pass
@ -174,7 +176,7 @@ class DBAdapter:
:param link: :param link:
:return: :return:
""" """
print("Saving Presence {0}:{1} Artist: {2} Link: {3}".format(name, domain, artist_ID, link)) logging.debug("Saving Presence {0}:{1} Artist: {2} Link: {3}".format(name, domain, artist_ID, link))
artist = self.get_artist(artist_ID) artist = self.get_artist(artist_ID)
if artist is None or len(artist) == 0: if artist is None or len(artist) == 0:
raise Exception("Unknown Artist to create/update Presence with!") raise Exception("Unknown Artist to create/update Presence with!")
@ -195,7 +197,7 @@ class DBAdapter:
Remove a presence from the database Remove a presence from the database
:return: :return:
""" """
print("Removing Presence {0}:{1}".format(name, domain)) logging.debug("Removing Presence {0}:{1}".format(name, domain))
d = {"name": name, "domain": domain} d = {"name": name, "domain": domain}
self.db_cursor.execute("DELETE FROM presence WHERE name = %(name)s and domain = %(domain)s", d) self.db_cursor.execute("DELETE FROM presence WHERE name = %(name)s and domain = %(domain)s", d)
self.db.commit() self.db.commit()
@ -226,7 +228,7 @@ class DBAdapter:
:param name: :param name:
:return: :return:
""" """
print("Saving artist {0}:{1}".format(ID, name)) logging.debug("Saving artist {0}:{1}".format(ID, name))
d = {"id": ID, "name": name} d = {"id": ID, "name": name}
if ID is None: # no ID given, auto generate it if ID is None: # no ID given, auto generate it
self.db_cursor.execute("INSERT INTO artist (name) VALUES (%(name)s)", d) self.db_cursor.execute("INSERT INTO artist (name) VALUES (%(name)s)", d)
@ -242,7 +244,7 @@ class DBAdapter:
:param ID: :param ID:
:return: :return:
""" """
print("Deleting artist {0}".format(ID)) logging.debug("Deleting artist {0}".format(ID))
d = {"id": ID} d = {"id": ID}
self.db_cursor.execute("DELETE FROM Artist WHERE ID = %(id)s", d) self.db_cursor.execute("DELETE FROM Artist WHERE ID = %(id)s", d)
self.db.commit() self.db.commit()
@ -255,7 +257,7 @@ class DBAdapter:
:param name: :param name:
:return: :return:
""" """
print("Saving category {0}!".format(name)) logging.debug("Saving category {0}!".format(name))
d = {"name": name} d = {"name": name}
self.db_cursor.execute("INSERT INTO tag_category (name) VALUES (%(name)s)", d) self.db_cursor.execute("INSERT INTO tag_category (name) VALUES (%(name)s)", d)

@ -37,9 +37,3 @@ class FileReader:
dirs.append(os.path.join(curr_dir, d)) dirs.append(os.path.join(curr_dir, d))
return l return l
if __name__ == "__main__":
fr = FileReader("/home/peery/Software_Projects/ArtNet/App/Fake_Other_Artists")
print(fr.list_artists())
print(fr.get_files("AkuDrache"))

@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object): class Ui_MainWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow") MainWindow.setObjectName("MainWindow")
MainWindow.resize(1239, 824) MainWindow.resize(1140, 849)
self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setEnabled(True) self.centralwidget.setEnabled(True)
self.centralwidget.setObjectName("centralwidget") self.centralwidget.setObjectName("centralwidget")
@ -173,13 +173,13 @@ class Ui_MainWindow(object):
self.tag_layout = QtWidgets.QVBoxLayout() self.tag_layout = QtWidgets.QVBoxLayout()
self.tag_layout.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize) self.tag_layout.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize)
self.tag_layout.setObjectName("tag_layout") self.tag_layout.setObjectName("tag_layout")
self.label = QtWidgets.QLabel(self.right_frame) self.search_tags_label = QtWidgets.QLabel(self.right_frame)
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
font.setWeight(75) font.setWeight(75)
self.label.setFont(font) self.search_tags_label.setFont(font)
self.label.setObjectName("label") self.search_tags_label.setObjectName("search_tags_label")
self.tag_layout.addWidget(self.label) self.tag_layout.addWidget(self.search_tags_label)
self.tag_list_layout = QtWidgets.QVBoxLayout() self.tag_list_layout = QtWidgets.QVBoxLayout()
self.tag_list_layout.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize) self.tag_list_layout.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize)
self.tag_list_layout.setObjectName("tag_list_layout") self.tag_list_layout.setObjectName("tag_list_layout")
@ -197,13 +197,13 @@ class Ui_MainWindow(object):
self.search_result_list.setMaximumSize(QtCore.QSize(400, 16777215)) self.search_result_list.setMaximumSize(QtCore.QSize(400, 16777215))
self.search_result_list.setObjectName("search_result_list") self.search_result_list.setObjectName("search_result_list")
self.tag_list_layout.addWidget(self.search_result_list) self.tag_list_layout.addWidget(self.search_result_list)
self.label_2 = QtWidgets.QLabel(self.right_frame) self.selected_tags_label = QtWidgets.QLabel(self.right_frame)
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
font.setWeight(75) font.setWeight(75)
self.label_2.setFont(font) self.selected_tags_label.setFont(font)
self.label_2.setObjectName("label_2") self.selected_tags_label.setObjectName("selected_tags_label")
self.tag_list_layout.addWidget(self.label_2) self.tag_list_layout.addWidget(self.selected_tags_label)
self.tag_list = QtWidgets.QListView(self.right_frame) self.tag_list = QtWidgets.QListView(self.right_frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -214,14 +214,14 @@ class Ui_MainWindow(object):
self.tag_list.setMaximumSize(QtCore.QSize(400, 16777215)) self.tag_list.setMaximumSize(QtCore.QSize(400, 16777215))
self.tag_list.setObjectName("tag_list") self.tag_list.setObjectName("tag_list")
self.tag_list_layout.addWidget(self.tag_list) self.tag_list_layout.addWidget(self.tag_list)
self.label_3 = QtWidgets.QLabel(self.right_frame) self.implied_tags_list = QtWidgets.QLabel(self.right_frame)
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(9) font.setPointSize(9)
font.setBold(True) font.setBold(True)
font.setWeight(75) font.setWeight(75)
self.label_3.setFont(font) self.implied_tags_list.setFont(font)
self.label_3.setObjectName("label_3") self.implied_tags_list.setObjectName("implied_tags_list")
self.tag_list_layout.addWidget(self.label_3) self.tag_list_layout.addWidget(self.implied_tags_list)
self.implied_tag_list = QtWidgets.QListView(self.right_frame) self.implied_tag_list = QtWidgets.QListView(self.right_frame)
self.implied_tag_list.setMinimumSize(QtCore.QSize(100, 0)) self.implied_tag_list.setMinimumSize(QtCore.QSize(100, 0))
self.implied_tag_list.setMaximumSize(QtCore.QSize(400, 16777215)) self.implied_tag_list.setMaximumSize(QtCore.QSize(400, 16777215))
@ -263,13 +263,21 @@ class Ui_MainWindow(object):
self.tag_button_layout.addItem(spacerItem) self.tag_button_layout.addItem(spacerItem)
self.tag_layout.addLayout(self.tag_button_layout) self.tag_layout.addLayout(self.tag_button_layout)
self.horizontalLayout_3.addLayout(self.tag_layout) self.horizontalLayout_3.addLayout(self.tag_layout)
self.topic_docker_button = QtWidgets.QToolButton(self.right_frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.topic_docker_button.sizePolicy().hasHeightForWidth())
self.topic_docker_button.setSizePolicy(sizePolicy)
self.topic_docker_button.setObjectName("topic_docker_button")
self.horizontalLayout_3.addWidget(self.topic_docker_button)
self.horizontalLayout.addWidget(self.right_frame) self.horizontalLayout.addWidget(self.right_frame)
MainWindow.setCentralWidget(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar") self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar) MainWindow.setStatusBar(self.statusbar)
self.menuBar = QtWidgets.QMenuBar(MainWindow) self.menuBar = QtWidgets.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 1239, 30)) self.menuBar.setGeometry(QtCore.QRect(0, 0, 1140, 34))
self.menuBar.setObjectName("menuBar") self.menuBar.setObjectName("menuBar")
self.menuArtNet = QtWidgets.QMenu(self.menuBar) self.menuArtNet = QtWidgets.QMenu(self.menuBar)
self.menuArtNet.setObjectName("menuArtNet") self.menuArtNet.setObjectName("menuArtNet")
@ -324,14 +332,15 @@ class Ui_MainWindow(object):
self.source_link_label.setText(_translate("MainWindow", "Link:")) self.source_link_label.setText(_translate("MainWindow", "Link:"))
self.description_label.setText(_translate("MainWindow", "Description:")) self.description_label.setText(_translate("MainWindow", "Description:"))
self.next_image_button.setText(_translate("MainWindow", ">")) self.next_image_button.setText(_translate("MainWindow", ">"))
self.label.setText(_translate("MainWindow", "Search Tags")) self.search_tags_label.setText(_translate("MainWindow", "Search Tags"))
self.label_2.setText(_translate("MainWindow", "Selected Tags:")) self.selected_tags_label.setText(_translate("MainWindow", "Selected Tags:"))
self.label_3.setText(_translate("MainWindow", "Implied Tags:")) self.implied_tags_list.setText(_translate("MainWindow", "Implied Tags:"))
self.save_button.setText(_translate("MainWindow", "Save")) self.save_button.setText(_translate("MainWindow", "Save"))
self.import_button.setText(_translate("MainWindow", "Import Tags")) self.import_button.setText(_translate("MainWindow", "Import Tags"))
self.prev_unknown_image_button.setText(_translate("MainWindow", "prev Unknown")) self.prev_unknown_image_button.setText(_translate("MainWindow", "prev Unknown"))
self.next_unknown_image_button.setText(_translate("MainWindow", "next Unknown")) self.next_unknown_image_button.setText(_translate("MainWindow", "next Unknown"))
self.delete_button.setText(_translate("MainWindow", "Delete")) self.delete_button.setText(_translate("MainWindow", "Delete"))
self.topic_docker_button.setText(_translate("MainWindow", ">"))
self.menuArtNet.setTitle(_translate("MainWindow", "ArtNet")) self.menuArtNet.setTitle(_translate("MainWindow", "ArtNet"))
self.menuTags.setTitle(_translate("MainWindow", "Tags")) self.menuTags.setTitle(_translate("MainWindow", "Tags"))
self.menuCategory.setTitle(_translate("MainWindow", "Category")) self.menuCategory.setTitle(_translate("MainWindow", "Category"))

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1239</width> <width>1140</width>
<height>824</height> <height>849</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -282,7 +282,7 @@
<enum>QLayout::SetMinimumSize</enum> <enum>QLayout::SetMinimumSize</enum>
</property> </property>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="search_tags_label">
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>75</weight>
@ -332,7 +332,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="selected_tags_label">
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>75</weight>
@ -367,7 +367,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="implied_tags_list">
<property name="font"> <property name="font">
<font> <font>
<pointsize>9</pointsize> <pointsize>9</pointsize>
@ -482,6 +482,19 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QToolButton" name="topic_docker_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&gt;</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -493,8 +506,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1239</width> <width>1140</width>
<height>30</height> <height>34</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuArtNet"> <widget class="QMenu" name="menuArtNet">

@ -1,4 +1,5 @@
import validators, os import validators, os
import logging
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QSize, QUrl from PyQt5.QtCore import Qt, QSize, QUrl
@ -650,7 +651,7 @@ class Window(QtWidgets.QMainWindow):
elif a0.key() == Qt.Key_Right: elif a0.key() == Qt.Key_Right:
self.on_next_clicked() self.on_next_clicked()
elif a0.key() == Qt.Key_Return: elif a0.key() == Qt.Key_Return:
print("Pressed Enter!") logging.debug("Pressed Enter!")
if self.__showing_video: if self.__showing_video:
s = self.__player.state() s = self.__player.state()
if self.__player.state() == QtMultimedia.QMediaPlayer.PlayingState: if self.__player.state() == QtMultimedia.QMediaPlayer.PlayingState:
@ -684,7 +685,7 @@ class Window(QtWidgets.QMainWindow):
self.set_tag_list(self.curr_tags) # update relevant lists self.set_tag_list(self.curr_tags) # update relevant lists
self.set_tag_search_result_list([item_data[0]]) self.set_tag_search_result_list([item_data[0]])
print(item_data) logging.debug(item_data)
def on_movie_player_state_changed(self, state: int): def on_movie_player_state_changed(self, state: int):
self.__image_resize() self.__image_resize()
@ -702,12 +703,12 @@ class Window(QtWidgets.QMainWindow):
self.__pixmap.setPaused(True) self.__pixmap.setPaused(True)
def on_save_clicked(self): def on_save_clicked(self):
print("Clicked Save!") logging.info("Clicked Save!")
self.set_image_title_link() self.set_image_title_link()
self.save_changes() self.save_changes()
def on_import_tags_clicked(self): def on_import_tags_clicked(self):
print("Clicked Import!") logging.info("Clicked Import!")
dialog = TagImportDialog(self) dialog = TagImportDialog(self)
if len(self.get_image_link_from_line()) == 0 or self.get_image_link_from_line() == '(Unknown)': if len(self.get_image_link_from_line()) == 0 or self.get_image_link_from_line() == '(Unknown)':
url = LinkGenerator.get_instance().construct_link(self.curr_file_name, url = LinkGenerator.get_instance().construct_link(self.curr_file_name,
@ -765,7 +766,7 @@ class Window(QtWidgets.QMainWindow):
self.set_tag_list(self.curr_tags) self.set_tag_list(self.curr_tags)
def on_next_clicked(self): def on_next_clicked(self):
print("Clicked Next!") logging.info("Clicked Next!")
if not self.check_save_changes(): if not self.check_save_changes():
return return
@ -783,7 +784,7 @@ class Window(QtWidgets.QMainWindow):
self.curr_image_title = self.ui.image_title_line.text() self.curr_image_title = self.ui.image_title_line.text()
def on_previous_clicked(self): def on_previous_clicked(self):
print("Clicked previous!") logging.info("Clicked previous!")
if not self.check_save_changes(): if not self.check_save_changes():
return return
@ -798,14 +799,15 @@ class Window(QtWidgets.QMainWindow):
self.on_tag_search_change() self.on_tag_search_change()
def toggle_presence_docker(self): def toggle_presence_docker(self):
print("Clicked presence docker button!")
if not self.presence_docker_open: if not self.presence_docker_open:
logging.info("Opened presence docker!")
self.presence_docker = PresenceDocker(self) self.presence_docker = PresenceDocker(self)
self.ui.presence_docker_layout.addWidget(self.presence_docker) self.ui.presence_docker_layout.addWidget(self.presence_docker)
self.presence_docker.set_selected_presences_list(self.get_current_presences()) self.presence_docker.set_selected_presences_list(self.get_current_presences())
self.ui.presence_docker_button.setText(">") self.ui.presence_docker_button.setText(">")
self.presence_docker_open = True self.presence_docker_open = True
else: else:
logging.info("Closed presence docker!")
self.presence_docker.setParent(None) self.presence_docker.setParent(None)
self.ui.presence_docker_button.setText("<") self.ui.presence_docker_button.setText("<")
@ -814,7 +816,7 @@ class Window(QtWidgets.QMainWindow):
self.presence_docker_open = False self.presence_docker_open = False
def on_artnet_root_change_clicked(self): def on_artnet_root_change_clicked(self):
print("Clicked changing ArtNet root!") logging.info("Clicked changing ArtNet root!")
dialog = QtWidgets.QFileDialog(self, 'Choose new ArtNet root:') dialog = QtWidgets.QFileDialog(self, 'Choose new ArtNet root:')
dialog.setFileMode(QtWidgets.QFileDialog.Directory) dialog.setFileMode(QtWidgets.QFileDialog.Directory)
dialog.setOptions(QtWidgets.QFileDialog.ShowDirsOnly) dialog.setOptions(QtWidgets.QFileDialog.ShowDirsOnly)
@ -823,7 +825,7 @@ class Window(QtWidgets.QMainWindow):
self.__main.change_root(directory) self.__main.change_root(directory)
def on_db_connection_change_clicked(self): def on_db_connection_change_clicked(self):
print("Clicked db connection change!") logging.info("Clicked db connection change!")
dialog = DBDialog(self) dialog = DBDialog(self)
prev_db_data = self.__main.get_db_connection_details() prev_db_data = self.__main.get_db_connection_details()
dialog.ui.user_line_edit.setText(prev_db_data["user"]) dialog.ui.user_line_edit.setText(prev_db_data["user"])
@ -840,11 +842,11 @@ class Window(QtWidgets.QMainWindow):
database=db_data["database"]) database=db_data["database"])
def on_tag_creation_clicked(self): def on_tag_creation_clicked(self):
print("Clicked Tag Creation!") logging.info("Clicked Tag Creation!")
dialog = TagModifyDialog(self, create_tag=True) dialog = TagModifyDialog(self, create_tag=True)
tag_data: dict = dialog.exec_() tag_data: dict = dialog.exec_()
print("Got Tag data", tag_data) logging.debug("Got Tag data", tag_data)
if tag_data is None or len(tag_data.keys()) == 0: # got canceled? if tag_data is None or len(tag_data.keys()) == 0: # got canceled?
return return
@ -858,11 +860,11 @@ class Window(QtWidgets.QMainWindow):
self.on_tag_search_change() self.on_tag_search_change()
def on_tag_deletion_clicked(self): def on_tag_deletion_clicked(self):
print("Clicked Tag Deletion!") logging.info("Clicked Tag Deletion!")
dialog = TagSelectDialog(self, delete_tag=True) dialog = TagSelectDialog(self, delete_tag=True)
tag = dialog.exec_() tag = dialog.exec_()
print("Got Tag", tag) logging.debug("Got Tag", tag)
if tag is None or len(tag) == 0: if tag is None or len(tag) == 0:
return return
@ -889,7 +891,7 @@ class Window(QtWidgets.QMainWindow):
edit_dialog.set_all_categories() edit_dialog.set_all_categories()
tag_data = edit_dialog.exec_() tag_data = edit_dialog.exec_()
print("Got Tag data", tag_data) logging.debug("Got Tag data", tag_data)
if tag_data is None or len(tag_data.keys()) == 0: if tag_data is None or len(tag_data.keys()) == 0:
return None return None
if len(tag_data["category"]) == 0: if len(tag_data["category"]) == 0:
@ -909,7 +911,7 @@ class Window(QtWidgets.QMainWindow):
return tag_data return tag_data
def on_tag_edit_clicked(self): def on_tag_edit_clicked(self):
print("Clicked Tag Editing!") logging.info("Clicked Tag Editing!")
select_dialog = TagSelectDialog(self, delete_tag=False) select_dialog = TagSelectDialog(self, delete_tag=False)
tag = select_dialog.exec_() tag = select_dialog.exec_()
@ -930,7 +932,7 @@ class Window(QtWidgets.QMainWindow):
edit_dialog.set_all_categories() edit_dialog.set_all_categories()
tag_data = edit_dialog.exec_() tag_data = edit_dialog.exec_()
print("Got Tag data", tag_data) logging.debug("Got Tag data", tag_data)
if tag_data is None or len(tag_data.keys()) == 0: if tag_data is None or len(tag_data.keys()) == 0:
return return
@ -954,7 +956,7 @@ class Window(QtWidgets.QMainWindow):
self.set_tag_list(self.curr_tags) self.set_tag_list(self.curr_tags)
def on_tag_item_changed(self, item: QStandardItem): def on_tag_item_changed(self, item: QStandardItem):
print("Item {0} has changed!".format(item.text())) logging.debug("Item {0} has changed!".format(item.text()))
if item.checkState() == Qt.Unchecked: if item.checkState() == Qt.Unchecked:
if item.text() in self.curr_tags: if item.text() in self.curr_tags:
self.curr_tags.remove(item.text()) self.curr_tags.remove(item.text())
@ -995,7 +997,7 @@ class Window(QtWidgets.QMainWindow):
def on_prev_unknown_image_clicked(self): def on_prev_unknown_image_clicked(self):
unknown_image_index = self.__main.get_prev_unknown_image() unknown_image_index = self.__main.get_prev_unknown_image()
print("Previous unknown image clicked!") logging.info("Previous unknown image clicked!")
result = QtWidgets.QMessageBox.question(self, "Switch Image?", result = QtWidgets.QMessageBox.question(self, "Switch Image?",
"Do you really want to skip to image #{1} \"{0}\"?" "Do you really want to skip to image #{1} \"{0}\"?"
@ -1007,7 +1009,7 @@ class Window(QtWidgets.QMainWindow):
def on_next_unknown_image_clicked(self): def on_next_unknown_image_clicked(self):
unknown_image_index = self.__main.get_next_unknown_image() unknown_image_index = self.__main.get_next_unknown_image()
print("Next unknown image clicked!") logging.info("Next unknown image clicked!")
result = QtWidgets.QMessageBox.question(self, "Switch Image?", result = QtWidgets.QMessageBox.question(self, "Switch Image?",
"Do you really want to skip to image #{1} \"{0}\"?" "Do you really want to skip to image #{1} \"{0}\"?"
@ -1019,7 +1021,7 @@ class Window(QtWidgets.QMainWindow):
def on_image_id_spinbox_changed(self, v: int): def on_image_id_spinbox_changed(self, v: int):
if self.__tmp_imageid_spinbox == v: if self.__tmp_imageid_spinbox == v:
print("SpinBox change detected!") logging.info("SpinBox change detected!")
result = QtWidgets.QMessageBox.question(self, "Switch Image?", result = QtWidgets.QMessageBox.question(self, "Switch Image?",
"Do you really want to skip to image #{1} \"{0}\"?" "Do you really want to skip to image #{1} \"{0}\"?"
.format(self.__main.all_images[v], .format(self.__main.all_images[v],
@ -1031,26 +1033,26 @@ class Window(QtWidgets.QMainWindow):
self.__tmp_imageid_spinbox: int = v self.__tmp_imageid_spinbox: int = v
def on_delete_image_clicked(self): def on_delete_image_clicked(self):
print("Delete clicked!") logging.info("Delete clicked!")
art_hash = self.__main.get_md5_of_image(self.curr_art_path) art_hash = self.__main.get_md5_of_image(self.curr_art_path)
if self.__main.db_connection.get_art_by_hash(art_hash) is not None: if self.__main.db_connection.get_art_by_hash(art_hash) is not None:
print("Delete on known image") logging.debug("Delete on known image")
confirm_result = QtWidgets.QMessageBox.question(self, "Delete data?", "Do you really wish to delete all " confirm_result = QtWidgets.QMessageBox.question(self, "Delete data?", "Do you really wish to delete all "
"data from the DB about this image?") "data from the DB about this image?")
if confirm_result == QtWidgets.QMessageBox.Yes: if confirm_result == QtWidgets.QMessageBox.Yes:
print(f"deleting image data of \"{self.curr_image_title}\"") logging.info(f"deleting image data of \"{self.curr_image_title}\"")
self.__main.db_connection.remove_image(art_hash) self.__main.db_connection.remove_image(art_hash)
else: else:
return return
else: else:
print("Delete on unknown image") logging.debug("Delete on unknown image")
confirm_result = QtWidgets.QMessageBox.question(self, "Delete image?", "Do you really wish to delete this " confirm_result = QtWidgets.QMessageBox.question(self, "Delete image?", "Do you really wish to delete this "
"image?") "image?")
if confirm_result == QtWidgets.QMessageBox.Yes: if confirm_result == QtWidgets.QMessageBox.Yes:
print("deleting image file") logging.info(f"deleting image file {self.curr_art_path}")
self.__main.delete_image(self.curr_art_path) self.__main.delete_image(self.curr_art_path)
else: else:
return return
@ -1058,11 +1060,11 @@ class Window(QtWidgets.QMainWindow):
self.__main.refresh_shown_image() self.__main.refresh_shown_image()
def on_link_label_activated(self, link: str): def on_link_label_activated(self, link: str):
print("Source link activated!", link) logging.debug("Source link activated!", link)
QDesktopServices.openUrl(QUrl(link)) QDesktopServices.openUrl(QUrl(link))
def on_image_author_label_activated(self, link: str): def on_image_author_label_activated(self, link: str):
print("Image author link activated!", link) logging.debug("Image author link activated!", link)
QDesktopServices.openUrl(QUrl(link)) QDesktopServices.openUrl(QUrl(link))
def on_description_change(self): def on_description_change(self):

Loading…
Cancel
Save