2018-07-04 20:48:28 +00:00
import os
2020-04-22 21:00:35 +00:00
2019-11-14 03:56:30 +00:00
from qtpy import QtCore as QC
from qtpy import QtWidgets as QW
from qtpy import QtGui as QG
2020-04-22 21:00:35 +00:00
from hydrus . core import HydrusData
from hydrus . core import HydrusExceptions
from hydrus . core import HydrusGlobals as HG
from hydrus . core import HydrusText
2023-04-19 20:38:13 +00:00
from hydrus . core import HydrusTime
2020-07-29 20:52:44 +00:00
2020-04-22 21:00:35 +00:00
from hydrus . client import ClientConstants as CC
2020-06-24 21:25:24 +00:00
from hydrus . client import ClientData
2020-04-22 21:00:35 +00:00
from hydrus . client import ClientPaths
from hydrus . client import ClientSerialisable
2023-04-19 20:38:13 +00:00
from hydrus . client import ClientTime
2020-04-22 21:00:35 +00:00
from hydrus . client . gui import ClientGUIDialogsQuick
2023-04-26 21:10:03 +00:00
from hydrus . client . gui import ClientGUIFunctions
2020-04-22 21:00:35 +00:00
from hydrus . client . gui import ClientGUIMenus
from hydrus . client . gui import ClientGUISerialisable
from hydrus . client . gui import ClientGUIScrolledPanels
2020-04-29 21:44:12 +00:00
from hydrus . client . gui import ClientGUITopLevelWindowsPanels
2020-04-22 21:00:35 +00:00
from hydrus . client . gui import QtPorting as QP
2020-07-15 20:52:09 +00:00
from hydrus . client . gui . lists import ClientGUIListConstants as CGLC
from hydrus . client . gui . lists import ClientGUIListCtrl
2021-03-17 21:59:28 +00:00
from hydrus . client . gui . widgets import ClientGUICommon
2020-04-22 21:00:35 +00:00
from hydrus . client . importing import ClientImportGallerySeeds
2018-07-04 20:48:28 +00:00
2022-04-06 20:40:17 +00:00
def ClearGallerySeeds ( win : QW . QWidget , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog , statuses_to_remove , gallery_type_string ) :
st_text = ' / ' . join ( ( CC . status_string_lookup [ status ] for status in statuses_to_remove ) )
message = ' Are you sure you want to delete all the {} {} log entries? This is useful for cleaning up and de-laggifying a very large list, but be careful you aren \' t removing something you would want to revisit. ' . format ( st_text , gallery_type_string )
result = ClientGUIDialogsQuick . GetYesNo ( win , message )
if result == QW . QDialog . Accepted :
gallery_seed_log . RemoveGallerySeedsByStatus ( statuses_to_remove )
def GetExportableURLsString ( gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog ) :
gallery_seeds = gallery_seed_log . GetGallerySeeds ( )
urls = [ gallery_seed . url for gallery_seed in gallery_seeds ]
return os . linesep . join ( urls )
def GetURLsFromURLsString ( urls_string ) :
urls = HydrusText . DeserialiseNewlinedTexts ( urls_string )
return urls
2023-04-26 21:10:03 +00:00
2022-04-06 20:40:17 +00:00
def ImportFromClipboard ( win : QW . QWidget , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog , can_generate_more_pages : bool ) :
try :
raw_text = HG . client_controller . GetClipboardText ( )
except HydrusExceptions . DataMissing as e :
QW . QMessageBox . critical ( win , ' Error ' , str ( e ) )
return
urls = GetURLsFromURLsString ( raw_text )
try :
ImportURLs ( win , gallery_seed_log , urls , can_generate_more_pages )
2023-04-26 21:10:03 +00:00
except Exception as e :
2022-04-06 20:40:17 +00:00
2023-04-26 21:10:03 +00:00
ClientGUIFunctions . PresentClipboardParseError ( win , raw_text , ' Lines of URLs ' , e )
2022-04-06 20:40:17 +00:00
2023-04-26 21:10:03 +00:00
2022-04-06 20:40:17 +00:00
def ImportFromPNG ( win : QW . QWidget , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog , can_generate_more_pages : bool ) :
with QP . FileDialog ( win , ' select the png with the urls ' , wildcard = ' PNG (*.png) ' ) as dlg :
if dlg . exec ( ) == QW . QDialog . Accepted :
path = dlg . GetPath ( )
try :
payload_string = ClientSerialisable . LoadStringFromPNG ( path )
urls = GetURLsFromURLsString ( payload_string )
ImportURLs ( win , gallery_seed_log , urls , can_generate_more_pages )
except :
QW . QMessageBox . critical ( win , ' Error ' , ' Could not import! ' )
raise
def ImportURLs ( win : QW . QWidget , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog , urls , can_generate_more_pages : bool ) :
urls = HydrusData . DedupeList ( urls )
filtered_urls = [ url for url in urls if not gallery_seed_log . HasGalleryURL ( url ) ]
urls_to_add = urls
if len ( filtered_urls ) < len ( urls ) :
num_urls = len ( urls )
num_removed = num_urls - len ( filtered_urls )
message = ' Of the ' + HydrusData . ToHumanInt ( num_urls ) + ' URLs you mean to add, ' + HydrusData . ToHumanInt ( num_removed ) + ' are already in the search log. Would you like to only add new URLs or add everything (which will force a re-check of the duplicates)? '
( result , was_cancelled ) = ClientGUIDialogsQuick . GetYesNo ( win , message , yes_label = ' only add new urls ' , no_label = ' add all urls, even duplicates ' , check_for_cancelled = True )
if was_cancelled :
return
if result == QW . QDialog . Accepted :
urls_to_add = filtered_urls
elif result == QW . QDialog . Rejected :
return
if can_generate_more_pages :
message = ' Would you like these urls to only check for new files, or would you like them to also generate subsequent gallery pages, like a regular search would? '
( result , was_cancelled ) = ClientGUIDialogsQuick . GetYesNo ( win , message , yes_label = ' just check what I am adding ' , no_label = ' start a potential new search for every url added ' , check_for_cancelled = True )
if was_cancelled :
return
can_generate_more_pages = result == QW . QDialog . Rejected
gallery_seeds = [ ClientImportGallerySeeds . GallerySeed ( url , can_generate_more_pages = can_generate_more_pages ) for url in urls_to_add ]
gallery_seed_log . AddGallerySeeds ( gallery_seeds )
def ExportToPNG ( win : QW . QWidget , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog ) :
payload = GetExportableURLsString ( gallery_seed_log )
with ClientGUITopLevelWindowsPanels . DialogNullipotent ( win , ' export to png ' ) as dlg :
panel = ClientGUISerialisable . PNGExportPanel ( dlg , payload )
dlg . SetPanel ( panel )
dlg . exec ( )
def ExportToClipboard ( gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog ) :
payload = GetExportableURLsString ( gallery_seed_log )
HG . client_controller . pub ( ' clipboard ' , ' text ' , payload )
def RetryErrors ( win : QW . QWidget , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog ) :
message = ' Are you sure you want to retry all the files that encountered errors? '
result = ClientGUIDialogsQuick . GetYesNo ( win , message )
if result == QW . QDialog . Accepted :
gallery_seed_log . RetryFailed ( )
def PopulateGallerySeedLogButton ( win : QW . QWidget , menu : QW . QMenu , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog , read_only : bool , can_generate_more_pages : bool , gallery_type_string : str ) :
num_successful = gallery_seed_log . GetGallerySeedCount ( CC . STATUS_SUCCESSFUL_AND_NEW )
num_vetoed = gallery_seed_log . GetGallerySeedCount ( CC . STATUS_VETOED )
num_errors = gallery_seed_log . GetGallerySeedCount ( CC . STATUS_ERROR )
num_skipped = gallery_seed_log . GetGallerySeedCount ( CC . STATUS_SKIPPED )
if num_successful > 0 :
ClientGUIMenus . AppendMenuItem ( menu , ' delete {} \' successful \' gallery log entries from the log ' . format ( HydrusData . ToHumanInt ( num_successful ) ) , ' Tell this log to clear out successful records, reducing the size of the queue. ' , ClearGallerySeeds , win , gallery_seed_log , ( CC . STATUS_SUCCESSFUL_AND_NEW , ) , gallery_type_string )
if num_errors > 0 :
ClientGUIMenus . AppendMenuItem ( menu , ' delete {} \' failed \' gallery log entries from the log ' . format ( HydrusData . ToHumanInt ( num_errors ) ) , ' Tell this log to clear out errored records, reducing the size of the queue. ' , ClearGallerySeeds , win , gallery_seed_log , ( CC . STATUS_ERROR , ) , gallery_type_string )
if num_vetoed > 0 :
ClientGUIMenus . AppendMenuItem ( menu , ' delete {} \' ignored \' gallery log entries from the log ' . format ( HydrusData . ToHumanInt ( num_vetoed ) ) , ' Tell this log to clear out ignored records, reducing the size of the queue. ' , ClearGallerySeeds , win , gallery_seed_log , ( CC . STATUS_VETOED , ) , gallery_type_string )
if num_skipped > 0 :
ClientGUIMenus . AppendMenuItem ( menu , ' delete {} \' skipped \' gallery log entries from the log ' . format ( HydrusData . ToHumanInt ( num_skipped ) ) , ' Tell this log to clear out skipped records, reducing the size of the queue. ' , ClearGallerySeeds , win , gallery_seed_log , ( CC . STATUS_SKIPPED , ) , gallery_type_string )
ClientGUIMenus . AppendSeparator ( menu )
if len ( gallery_seed_log ) > 0 :
if not read_only and gallery_seed_log . CanRestartFailedSearch ( ) :
ClientGUIMenus . AppendMenuItem ( menu , ' restart and resume failed search ' , ' Requeue the last failed attempt and resume search from there. ' , gallery_seed_log . RestartFailedSearch )
ClientGUIMenus . AppendSeparator ( menu )
2023-04-12 20:34:43 +00:00
submenu = ClientGUIMenus . GenerateMenu ( menu )
2022-04-06 20:40:17 +00:00
ClientGUIMenus . AppendMenuItem ( submenu , ' to clipboard ' , ' Copy all the urls in this list to the clipboard. ' , ExportToClipboard , gallery_seed_log )
ClientGUIMenus . AppendMenuItem ( submenu , ' to png ' , ' Export all the urls in this list to a png file. ' , ExportToPNG , win , gallery_seed_log )
ClientGUIMenus . AppendMenu ( menu , submenu , ' export all urls ' )
if not read_only :
2023-04-12 20:34:43 +00:00
submenu = ClientGUIMenus . GenerateMenu ( menu )
2022-04-06 20:40:17 +00:00
ClientGUIMenus . AppendMenuItem ( submenu , ' from clipboard ' , ' Import new urls to this list from the clipboard. ' , ImportFromClipboard , win , gallery_seed_log , can_generate_more_pages )
ClientGUIMenus . AppendMenuItem ( submenu , ' from png ' , ' Import new urls to this list from a png file. ' , ImportFromPNG , win , gallery_seed_log , can_generate_more_pages )
ClientGUIMenus . AppendMenu ( menu , submenu , ' import new urls ' )
2018-07-04 20:48:28 +00:00
class EditGallerySeedLogPanel ( ClientGUIScrolledPanels . EditPanel ) :
2022-04-06 20:40:17 +00:00
def __init__ ( self , parent , controller , read_only : bool , can_generate_more_pages : bool , gallery_type_string : str , gallery_seed_log : ClientImportGallerySeeds . GallerySeedLog ) :
2018-07-04 20:48:28 +00:00
ClientGUIScrolledPanels . EditPanel . __init__ ( self , parent )
self . _controller = controller
self . _read_only = read_only
2018-09-12 21:36:26 +00:00
self . _can_generate_more_pages = can_generate_more_pages
2022-04-06 20:40:17 +00:00
self . _gallery_type_string = gallery_type_string
2018-07-04 20:48:28 +00:00
self . _gallery_seed_log = gallery_seed_log
self . _text = ClientGUICommon . BetterStaticText ( self , ' initialising ' )
# add index control row here, hide it if needed and hook into showing/hiding and postsizechangedevent on gallery_seed add/remove
2022-01-12 22:14:50 +00:00
self . _list_ctrl = ClientGUIListCtrl . BetterListCtrl ( self , CGLC . COLUMN_LIST_GALLERY_SEED_LOG . ID , 30 , self . _ConvertGallerySeedToListCtrlTuples , delete_key_callback = self . _DeleteSelected )
2018-07-04 20:48:28 +00:00
#
self . _list_ctrl . AddDatas ( self . _gallery_seed_log . GetGallerySeeds ( ) )
2020-07-15 20:52:09 +00:00
self . _list_ctrl . Sort ( )
2018-07-04 20:48:28 +00:00
#
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( vbox , self . _text , CC . FLAGS_EXPAND_PERPENDICULAR )
QP . AddToLayout ( vbox , self . _list_ctrl , CC . FLAGS_EXPAND_BOTH_WAYS )
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
self . widget ( ) . setLayout ( vbox )
2018-07-04 20:48:28 +00:00
2023-04-12 20:34:43 +00:00
self . _list_ctrl . AddRowsMenuCallable ( self . _GetListCtrlMenu )
2018-07-04 20:48:28 +00:00
self . _controller . sub ( self , ' NotifyGallerySeedsUpdated ' , ' gallery_seed_log_gallery_seeds_updated ' )
2019-11-14 03:56:30 +00:00
QP . CallAfter ( self . _UpdateText )
2018-07-04 20:48:28 +00:00
def _ConvertGallerySeedToListCtrlTuples ( self , gallery_seed ) :
try :
gallery_seed_index = self . _gallery_seed_log . GetGallerySeedIndex ( gallery_seed )
except :
gallery_seed_index = ' -- '
url = gallery_seed . url
status = gallery_seed . status
added = gallery_seed . created
modified = gallery_seed . modified
note = gallery_seed . note
pretty_gallery_seed_index = HydrusData . ToHumanInt ( gallery_seed_index )
pretty_url = url
pretty_status = CC . status_string_lookup [ status ]
2023-04-19 20:38:13 +00:00
pretty_added = ClientTime . TimestampToPrettyTimeDelta ( added )
pretty_modified = ClientTime . TimestampToPrettyTimeDelta ( modified )
2018-07-04 20:48:28 +00:00
pretty_note = note . split ( os . linesep ) [ 0 ]
display_tuple = ( pretty_gallery_seed_index , pretty_url , pretty_status , pretty_added , pretty_modified , pretty_note )
sort_tuple = ( gallery_seed_index , url , status , added , modified , note )
return ( display_tuple , sort_tuple )
def _CopySelectedGalleryURLs ( self ) :
gallery_seeds = self . _list_ctrl . GetData ( only_selected = True )
if len ( gallery_seeds ) > 0 :
separator = os . linesep * 2
text = separator . join ( ( gallery_seed . url for gallery_seed in gallery_seeds ) )
HG . client_controller . pub ( ' clipboard ' , ' text ' , text )
def _CopySelectedNotes ( self ) :
notes = [ ]
for gallery_seed in self . _list_ctrl . GetData ( only_selected = True ) :
note = gallery_seed . note
if note != ' ' :
notes . append ( note )
if len ( notes ) > 0 :
separator = os . linesep * 2
text = separator . join ( notes )
HG . client_controller . pub ( ' clipboard ' , ' text ' , text )
2022-01-12 22:14:50 +00:00
def _DeleteSelected ( self ) :
gallery_seeds_to_delete = self . _list_ctrl . GetData ( only_selected = True )
if len ( gallery_seeds_to_delete ) > 0 :
message = ' Are you sure you want to delete the {} selected entries? This is only useful if you have a really really huge list. ' . format ( HydrusData . ToHumanInt ( len ( gallery_seeds_to_delete ) ) )
result = ClientGUIDialogsQuick . GetYesNo ( self , message )
if result == QW . QDialog . Accepted :
self . _gallery_seed_log . RemoveGallerySeeds ( gallery_seeds_to_delete )
2018-09-19 21:54:51 +00:00
def _GetListCtrlMenu ( self ) :
selected_gallery_seeds = self . _list_ctrl . GetData ( only_selected = True )
2023-04-12 20:34:43 +00:00
menu = ClientGUIMenus . GenerateMenu ( self )
2022-04-06 20:40:17 +00:00
2018-09-19 21:54:51 +00:00
if len ( selected_gallery_seeds ) == 0 :
2022-04-06 20:40:17 +00:00
PopulateGallerySeedLogButton ( self , menu , self . _gallery_seed_log , self . _read_only , self . _can_generate_more_pages , self . _gallery_type_string )
return menu
2018-09-19 21:54:51 +00:00
2019-11-14 03:56:30 +00:00
ClientGUIMenus . AppendMenuItem ( menu , ' copy urls ' , ' Copy all the selected urls to clipboard. ' , self . _CopySelectedGalleryURLs )
ClientGUIMenus . AppendMenuItem ( menu , ' copy notes ' , ' Copy all the selected notes to clipboard. ' , self . _CopySelectedNotes )
2018-09-19 21:54:51 +00:00
ClientGUIMenus . AppendSeparator ( menu )
2019-11-14 03:56:30 +00:00
ClientGUIMenus . AppendMenuItem ( menu , ' open urls ' , ' Open all the selected urls in your web browser. ' , self . _OpenSelectedGalleryURLs )
2018-09-19 21:54:51 +00:00
ClientGUIMenus . AppendSeparator ( menu )
if not self . _read_only :
2019-11-14 03:56:30 +00:00
ClientGUIMenus . AppendMenuItem ( menu , ' try again (just this one page) ' , ' Schedule this url to occur again. ' , HydrusData . Call ( self . _TrySelectedAgain , False ) )
2018-09-19 21:54:51 +00:00
if self . _can_generate_more_pages :
2022-04-06 20:40:17 +00:00
2019-11-14 03:56:30 +00:00
ClientGUIMenus . AppendMenuItem ( menu , ' try again (and allow search to continue) ' , ' Schedule this url to occur again and continue. ' , HydrusData . Call ( self . _TrySelectedAgain , True ) )
2022-04-06 20:40:17 +00:00
2019-11-14 03:56:30 +00:00
ClientGUIMenus . AppendMenuItem ( menu , ' skip ' , ' Skip all the selected urls. ' , HydrusData . Call ( self . _SetSelected , CC . STATUS_SKIPPED ) )
2018-09-19 21:54:51 +00:00
2022-04-06 20:40:17 +00:00
ClientGUIMenus . AppendSeparator ( menu )
2023-04-12 20:34:43 +00:00
submenu = ClientGUIMenus . GenerateMenu ( menu )
2022-04-06 20:40:17 +00:00
PopulateGallerySeedLogButton ( self , submenu , self . _gallery_seed_log , self . _read_only , self . _can_generate_more_pages , self . _gallery_type_string )
ClientGUIMenus . AppendMenu ( menu , submenu , ' whole log ' )
2018-09-19 21:54:51 +00:00
return menu
2018-07-04 20:48:28 +00:00
def _OpenSelectedGalleryURLs ( self ) :
gallery_seeds = self . _list_ctrl . GetData ( only_selected = True )
if len ( gallery_seeds ) > 0 :
if len ( gallery_seeds ) > 10 :
message = ' You have many objects selected--are you sure you want to open them all? '
2019-09-05 00:05:32 +00:00
result = ClientGUIDialogsQuick . GetYesNo ( self , message )
2019-11-14 03:56:30 +00:00
if result != QW . QDialog . Accepted :
2018-07-04 20:48:28 +00:00
2019-09-05 00:05:32 +00:00
return
2018-07-04 20:48:28 +00:00
for gallery_seed in gallery_seeds :
ClientPaths . LaunchURLInWebBrowser ( gallery_seed . url )
def _SetSelected ( self , status_to_set ) :
gallery_seeds = self . _list_ctrl . GetData ( only_selected = True )
for gallery_seed in gallery_seeds :
gallery_seed . SetStatus ( status_to_set )
self . _gallery_seed_log . NotifyGallerySeedsUpdated ( gallery_seeds )
2018-09-12 21:36:26 +00:00
def _TrySelectedAgain ( self , can_generate_more_pages ) :
gallery_seeds = self . _list_ctrl . GetData ( only_selected = True )
for gallery_seed in gallery_seeds :
2023-01-25 22:59:39 +00:00
restarted_gallery_seed = gallery_seed . GenerateRestartedDuplicate ( can_generate_more_pages )
self . _gallery_seed_log . AddGallerySeeds ( ( restarted_gallery_seed , ) , parent_gallery_seed = gallery_seed )
2018-09-12 21:36:26 +00:00
2018-07-04 20:48:28 +00:00
def _UpdateListCtrl ( self , gallery_seeds ) :
gallery_seeds_to_add = [ ]
gallery_seeds_to_update = [ ]
gallery_seeds_to_delete = [ ]
for gallery_seed in gallery_seeds :
if self . _gallery_seed_log . HasGallerySeed ( gallery_seed ) :
if self . _list_ctrl . HasData ( gallery_seed ) :
gallery_seeds_to_update . append ( gallery_seed )
else :
gallery_seeds_to_add . append ( gallery_seed )
else :
if self . _list_ctrl . HasData ( gallery_seed ) :
gallery_seeds_to_delete . append ( gallery_seed )
self . _list_ctrl . DeleteDatas ( gallery_seeds_to_delete )
if len ( gallery_seeds_to_add ) > 0 :
self . _list_ctrl . AddDatas ( gallery_seeds_to_add )
# if gallery_seeds are inserted, then all subsequent indices need to be shuffled up, hence just update all here
self . _list_ctrl . UpdateDatas ( )
else :
self . _list_ctrl . UpdateDatas ( gallery_seeds_to_update )
def _UpdateText ( self ) :
( status , ( total_processed , total ) ) = self . _gallery_seed_log . GetStatus ( )
2019-11-14 03:56:30 +00:00
self . _text . setText ( status )
2018-07-04 20:48:28 +00:00
def GetValue ( self ) :
return self . _gallery_seed_log
def NotifyGallerySeedsUpdated ( self , gallery_seed_log_key , gallery_seeds ) :
if gallery_seed_log_key == self . _gallery_seed_log . GetGallerySeedLogKey ( ) :
self . _UpdateText ( )
self . _UpdateListCtrl ( gallery_seeds )
2021-12-22 22:31:23 +00:00
class GallerySeedLogButton ( ClientGUICommon . ButtonWithMenuArrow ) :
2018-07-04 20:48:28 +00:00
2022-04-06 20:40:17 +00:00
def __init__ ( self , parent , controller , read_only : bool , can_generate_more_pages : bool , gallery_type_string : str , gallery_seed_log_get_callable , gallery_seed_log_set_callable = None ) :
2018-07-04 20:48:28 +00:00
self . _controller = controller
self . _read_only = read_only
2018-09-12 21:36:26 +00:00
self . _can_generate_more_pages = can_generate_more_pages
2021-07-07 20:48:57 +00:00
self . _gallery_type_string = gallery_type_string
2018-07-04 20:48:28 +00:00
self . _gallery_seed_log_get_callable = gallery_seed_log_get_callable
self . _gallery_seed_log_set_callable = gallery_seed_log_set_callable
2021-12-22 22:31:23 +00:00
action = QW . QAction ( )
action . setText ( ' {} log ' . format ( gallery_type_string ) )
action . setToolTip ( ' open detailed {} log ' . format ( self . _gallery_type_string ) )
action . triggered . connect ( self . _ShowGallerySeedLogFrame )
ClientGUICommon . ButtonWithMenuArrow . __init__ ( self , parent , action )
def _PopulateMenu ( self , menu ) :
gallery_seed_log = self . _gallery_seed_log_get_callable ( )
2022-04-06 20:40:17 +00:00
PopulateGallerySeedLogButton ( self , menu , gallery_seed_log , self . _read_only , self . _can_generate_more_pages , self . _gallery_type_string )
2018-07-04 20:48:28 +00:00
def _ShowGallerySeedLogFrame ( self ) :
gallery_seed_log = self . _gallery_seed_log_get_callable ( )
2019-12-11 23:18:37 +00:00
tlw = self . window ( )
2018-07-04 20:48:28 +00:00
2021-07-07 20:48:57 +00:00
title = ' {} log ' . format ( self . _gallery_type_string )
2019-12-11 23:18:37 +00:00
if isinstance ( tlw , QP . Dialog ) :
2018-07-04 20:48:28 +00:00
if self . _gallery_seed_log_set_callable is None : # throw up a dialog that edits the gallery_seed log in place
2021-07-07 20:48:57 +00:00
with ClientGUITopLevelWindowsPanels . DialogNullipotent ( self , title ) as dlg :
2018-07-04 20:48:28 +00:00
2022-04-06 20:40:17 +00:00
panel = EditGallerySeedLogPanel ( dlg , self . _controller , self . _read_only , self . _can_generate_more_pages , self . _gallery_type_string , gallery_seed_log )
2018-07-04 20:48:28 +00:00
dlg . SetPanel ( panel )
2019-11-14 03:56:30 +00:00
dlg . exec ( )
2018-07-04 20:48:28 +00:00
else : # throw up a dialog that edits the gallery_seed log but can be cancelled
dupe_gallery_seed_log = gallery_seed_log . Duplicate ( )
2021-07-07 20:48:57 +00:00
with ClientGUITopLevelWindowsPanels . DialogEdit ( self , title ) as dlg :
2018-07-04 20:48:28 +00:00
2022-04-06 20:40:17 +00:00
panel = EditGallerySeedLogPanel ( dlg , self . _controller , self . _read_only , self . _can_generate_more_pages , self . _gallery_type_string , dupe_gallery_seed_log )
2018-07-04 20:48:28 +00:00
dlg . SetPanel ( panel )
2019-11-14 03:56:30 +00:00
if dlg . exec ( ) == QW . QDialog . Accepted :
2018-07-04 20:48:28 +00:00
self . _gallery_seed_log_set_callable ( dupe_gallery_seed_log )
else : # throw up a frame that edits the gallery_seed log in place
frame_key = ' gallery_import_log '
2020-04-29 21:44:12 +00:00
frame = ClientGUITopLevelWindowsPanels . FrameThatTakesScrollablePanel ( self , title , frame_key )
2018-07-04 20:48:28 +00:00
2022-04-06 20:40:17 +00:00
panel = EditGallerySeedLogPanel ( frame , self . _controller , self . _read_only , self . _can_generate_more_pages , self . _gallery_type_string , gallery_seed_log )
2018-07-04 20:48:28 +00:00
frame . SetPanel ( panel )
2019-11-14 03:56:30 +00:00
class GallerySeedLogStatusControl ( QW . QFrame ) :
2018-07-04 20:48:28 +00:00
2022-04-06 20:40:17 +00:00
def __init__ ( self , parent , controller , read_only : bool , can_generate_more_pages : bool , gallery_type_string : str , page_key = None ) :
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
QW . QFrame . __init__ ( self , parent )
self . setFrameStyle ( QW . QFrame . Box | QW . QFrame . Raised )
2018-07-04 20:48:28 +00:00
self . _controller = controller
self . _read_only = read_only
2018-09-12 21:36:26 +00:00
self . _can_generate_more_pages = can_generate_more_pages
2018-07-04 20:48:28 +00:00
self . _page_key = page_key
2021-07-07 20:48:57 +00:00
self . _gallery_type_string = gallery_type_string
2018-07-04 20:48:28 +00:00
self . _gallery_seed_log = None
2019-11-14 03:56:30 +00:00
self . _log_summary_st = ClientGUICommon . BetterStaticText ( self , ellipsize_end = True )
2018-07-04 20:48:28 +00:00
2021-07-07 20:48:57 +00:00
self . _gallery_seed_log_button = GallerySeedLogButton ( self , self . _controller , self . _read_only , self . _can_generate_more_pages , gallery_type_string , self . _GetGallerySeedLog )
2018-07-04 20:48:28 +00:00
#
self . _Update ( )
#
2019-11-14 03:56:30 +00:00
hbox = QP . HBoxLayout ( )
2018-07-04 20:48:28 +00:00
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( hbox , self . _log_summary_st , CC . FLAGS_CENTER_PERPENDICULAR_EXPAND_DEPTH )
QP . AddToLayout ( hbox , self . _gallery_seed_log_button , CC . FLAGS_CENTER_PERPENDICULAR )
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( hbox )
2018-07-04 20:48:28 +00:00
#
HG . client_controller . gui . RegisterUIUpdateWindow ( self )
def _GetGallerySeedLog ( self ) :
return self . _gallery_seed_log
def _Update ( self ) :
if self . _gallery_seed_log is None :
2020-12-23 23:07:58 +00:00
self . _log_summary_st . clear ( )
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
if self . _gallery_seed_log_button . isEnabled ( ) :
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
self . _gallery_seed_log_button . setEnabled ( False )
2018-07-04 20:48:28 +00:00
else :
( import_summary , ( num_done , num_to_do ) ) = self . _gallery_seed_log . GetStatus ( )
2019-11-14 03:56:30 +00:00
self . _log_summary_st . setText ( import_summary )
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
if not self . _gallery_seed_log_button . isEnabled ( ) :
2018-07-04 20:48:28 +00:00
2019-11-14 03:56:30 +00:00
self . _gallery_seed_log_button . setEnabled ( True )
2018-07-04 20:48:28 +00:00
def SetGallerySeedLog ( self , gallery_seed_log ) :
2019-11-14 03:56:30 +00:00
if not self or not QP . isValid ( self ) :
2018-07-04 20:48:28 +00:00
return
self . _gallery_seed_log = gallery_seed_log
def TIMERUIUpdate ( self ) :
if self . _controller . gui . IShouldRegularlyUpdate ( self ) :
self . _Update ( )