@ -1,7 +1,10 @@
from typing import List
import validators
import os
import logging
import re
import json
from PyQt5 import QtWidgets
from PyQt5 . QtCore import Qt , QSize , QUrl
@ -493,7 +496,7 @@ class ImporterWindow(ArtnetMainWindow):
"""
return self . main . db_connection . search_fuzzy_tag ( name , all_if_empty = True )
def set_tag_search_result_list ( self , tags : list ) :
def set_tag_search_result_list ( self , tags : List [ dict ] ) :
"""
Set the tags in the search result list to tags
: param tags :
@ -510,9 +513,21 @@ class ImporterWindow(ArtnetMainWindow):
if tag_name not in self . curr_implied_tags :
# new tag and not implied yet
item . setData ( Qt . Unchecked , Qt . CheckStateRole )
item . setToolTip ( f " Tag ID: { tag [ ' id ' ] } \n \n " + tag [ " description " ] + f " \n Category: { tag [ ' category ' ] } " )
if ' id ' in tag . keys ( ) and ' description ' in tag . keys ( ) and ' category ' in tag . keys ( ) :
s = f " Tag ID: { tag [ ' id ' ] } \n \n "
if len ( tag [ " description " ] ) != 0 :
s + = tag [ " description " ] + " \n \n "
s + = f " Category: { tag [ ' category ' ] } "
item . setToolTip ( s )
item . setData ( json . dumps ( tag ) , Qt . UserRole )
flags | = Qt . ItemIsUserCheckable
if self . curr_tags is not None and tag_name in ( self . curr_tags + self . curr_implied_tags + self . curr_tag_aliases ) :
is_in_tags = False
for i in range ( len ( ( self . curr_tags + self . curr_implied_tags + self . curr_tag_aliases ) ) ) :
if item . text ( ) == ( self . curr_tags + self . curr_implied_tags + self . curr_tag_aliases ) [ i ] [ " name " ] :
is_in_tags = True
if self . curr_tags is not None and is_in_tags :
# already selected, implied or aliased tags
item . setCheckState ( Qt . Checked )
item . setFlags ( flags )
@ -555,7 +570,12 @@ class ImporterWindow(ArtnetMainWindow):
if tag_name not in self . curr_implied_tags :
# new tag and not implied yet
item . setData ( Qt . Unchecked , Qt . CheckStateRole )
item . setToolTip ( f " Tag ID: { tag [ ' id ' ] } \n \n " + tag [ " description " ] + f " \n Category: { tag [ ' category ' ] } " )
if ' id ' in tag . keys ( ) and ' description ' in tag . keys ( ) and ' category ' in tag . keys ( ) :
s = f " Tag ID: { tag [ ' id ' ] } \n \n "
if len ( tag [ " description " ] ) != 0 :
s + = tag [ " description " ] + " \n \n "
s + = f " Category: { tag [ ' category ' ] } "
item . setToolTip ( s )
flags | = Qt . ItemIsUserCheckable
if set_checked :
@ -588,7 +608,12 @@ class ImporterWindow(ArtnetMainWindow):
else :
done . append ( tag_name )
item = QStandardItem ( tag_name )
item . setToolTip ( f " Tag ID: { tag [ ' id ' ] } \n \n " + tag [ " description " ] + f " \n Category: { tag [ ' category ' ] } " )
if ' id ' in tag . keys ( ) and ' description ' in tag . keys ( ) and ' category ' in tag . keys ( ) :
s = f " Tag ID: { tag [ ' id ' ] } \n \n "
if len ( tag [ " description " ] ) != 0 :
s + = tag [ " description " ] + " \n \n "
s + = f " Category: { tag [ ' category ' ] } "
item . setToolTip ( s )
item_model . appendRow ( item )
self . ui . implied_tag_list . setModel ( item_model )
@ -764,15 +789,15 @@ class ImporterWindow(ArtnetMainWindow):
if self . ui . search_result_list . model ( ) . rowCount ( ) == 1 : # only 1 search result left
model_index = self . ui . search_result_list . model ( ) . index ( 0 , 0 )
item_data = self . ui . search_result_list . model ( ) . itemData ( model_index )
item_data = json . loads ( self . ui . search_result_list . model ( ) . itemData ( model_index ) [ Qt . UserRole ] )
if item_data [ 0 ] not in self . curr_tags : # add/remove new selected tag to the lists
self . curr_tags . append ( item_data [0 ] )
if item_data not in self . curr_tags : # add/remove new selected tag to the lists
self . curr_tags . append ( item_data )
else :
self . curr_tags . remove ( item_data [0 ] )
self . curr_tags . remove ( item_data )
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 ])
logging . debug ( item_data )
def on_movie_player_state_changed ( self , state : int ) :
@ -823,8 +848,8 @@ class ImporterWindow(ArtnetMainWindow):
i = 0
while i < len ( tags ) : # workaround for an issue with altering lists during iteration
r = self . main . db_connection . get_tag_by_name ( tags [ i ] )
if len ( r ) > 0 :
self . curr_tags . append ( tags[ i ] )
if r is not None :
self . curr_tags . append ( r )
self . data_changed = True
tags . remove ( tags [ i ] )
continue
@ -995,9 +1020,10 @@ class ImporterWindow(ArtnetMainWindow):
" No tag is allowed without a category! " )
return None
if len ( self . get_tag ( tag_data [ ' name ' ] ) ) > 0 :
if self . get_tag ( tag_data [ ' name ' ] ) is not None :
QtWidgets . QMessageBox . information ( self , " Tag already exists " ,
" The Tag \" {0} \" you wanted to create already exists! Skipping... " )
f " The Tag \" { tag_data [ ' name ' ] } \" you wanted to create already exists! Skipping... " )
return None
else :
self . main . db_connection . create_tag ( name = tag_data [ " name " ] , description = tag_data [ " description " ] ,
aliases = tag_data [ " aliases " ] , implications = tag_data [ " implications " ] ,
@ -1043,7 +1069,8 @@ class ImporterWindow(ArtnetMainWindow):
def on_tag_search_item_changed ( self , item : QStandardItem ) :
if item . checkState ( ) == Qt . Checked :
self . curr_tags . append ( item . text ( ) )
tag_data = self . main . db_connection . get_tag_by_name ( item . text ( ) )
self . curr_tags . append ( tag_data )
aliases = self . main . db_connection . get_tag_aliases_by_name ( item . text ( ) )
for alias in aliases :
@ -1052,15 +1079,20 @@ class ImporterWindow(ArtnetMainWindow):
for implication in implications :
self . curr_tags . append ( implication )
if item . checkState ( ) == Qt . Unchecked :
if item . text ( ) in self . curr_tags :
self . curr_tags . remove ( item . text ( ) )
is_in_tags = False
for i in range ( len ( self . curr_tags ) ) :
if item . text ( ) == self . curr_tags [ i ] [ " name " ] :
tags_index = i
is_in_tags = True
if is_in_tags :
self . curr_tags . pop ( tags_index )
aliases = self . main . db_connection . get_tag_aliases_by_name ( item . text ( ) )
for alias in aliases :
if alias in self . curr_tags :
self . curr_tags . remove ( alias )
implications = self . main . db_connection . get_all_tag_implications_by_name ( item . text ( ) )
for implication in implications :
self . curr_tags . remove ( implication )
self . curr_tags . remove ( { " name " : implication } )
else :
raise Exception ( " Something went terribly wrong! " )
@ -1070,13 +1102,22 @@ class ImporterWindow(ArtnetMainWindow):
def on_tag_item_changed ( self , item : QStandardItem ) :
logging . debug ( " Item {0} has changed! " . format ( item . text ( ) ) )
if item . checkState ( ) == Qt . Unchecked :
if item . text ( ) in self . curr_tags :
is_in_tags = False
for i in range ( len ( self . curr_tags ) ) :
if item . text ( ) == self . curr_tags [ i ] [ " name " ] :
tags_index = i
is_in_tags = True
if is_in_tags :
aliases = self . main . db_connection . get_tag_aliases_by_name ( item . text ( ) )
if len ( aliases ) > 0 : # tag has aliases, might need to also remove them
for alias in aliases :
self . curr_tags . remove ( alias )
self . curr_tags . remove ( item . text ( ) )
for i in range ( len ( self . curr_tags ) ) :
if item . text ( ) == self . curr_tags [ i ] [ " name " ] :
tags_index = i
self . curr_tags . pop ( tags_index )
self . set_tag_list ( self . curr_tags )
self . on_tag_search_change ( )
else :