hydrus/include/ClientGUIDialogsQuick.py

180 lines
5.5 KiB
Python
Raw Normal View History

2019-07-17 22:10:19 +00:00
from . import ClientGUIScrolledPanelsButtonQuestions
2019-01-09 22:59:03 +00:00
from . import ClientGUIScrolledPanelsEdit
from . import ClientGUITopLevelWindows
2020-03-04 22:12:53 +00:00
from . import HydrusConstants as HC
2019-01-09 22:59:03 +00:00
from . import HydrusExceptions
2019-08-07 22:59:53 +00:00
from . import HydrusGlobals as HG
2019-11-14 03:56:30 +00:00
from qtpy import QtWidgets as QW
2018-11-14 23:10:55 +00:00
2019-05-01 21:24:42 +00:00
def GetDeleteFilesJobs( win, media, default_reason, suggested_file_service_key = None ):
title = 'Delete files?'
with ClientGUITopLevelWindows.DialogEdit( win, title, frame_key = 'regular_center_dialog' ) as dlg:
panel = ClientGUIScrolledPanelsEdit.EditDeleteFilesPanel( dlg, media, default_reason, suggested_file_service_key = suggested_file_service_key )
dlg.SetPanel( panel )
if panel.QuestionIsAlreadyResolved():
( involves_physical_delete, jobs ) = panel.GetValue()
return ( involves_physical_delete, jobs )
2019-11-14 03:56:30 +00:00
if dlg.exec() == QW.QDialog.Accepted:
2019-05-01 21:24:42 +00:00
( involves_physical_delete, jobs ) = panel.GetValue()
return ( involves_physical_delete, jobs )
else:
raise HydrusExceptions.CancelledException()
2019-07-17 22:10:19 +00:00
def GetFinishFilteringAnswer( win, label ):
with ClientGUITopLevelWindows.DialogCustomButtonQuestion( win, label ) as dlg:
panel = ClientGUIScrolledPanelsButtonQuestions.QuestionFinishFilteringPanel( dlg, label )
dlg.SetPanel( panel )
2019-12-05 05:29:32 +00:00
result = ( dlg.exec(), dlg.WasCancelled() )
return result
2019-07-17 22:10:19 +00:00
def GetInterstitialFilteringAnswer( win, label ):
with ClientGUITopLevelWindows.DialogCustomButtonQuestion( win, label ) as dlg:
panel = ClientGUIScrolledPanelsButtonQuestions.QuestionCommitInterstitialFilteringPanel( dlg, label )
dlg.SetPanel( panel )
2019-12-05 05:29:32 +00:00
result = dlg.exec()
return result
2019-07-17 22:10:19 +00:00
2019-11-14 03:56:30 +00:00
def GetYesNo( win, message, title = 'Are you sure?', yes_label = 'yes', no_label = 'no', auto_yes_time = None, auto_no_time = None, check_for_cancelled = False ):
2019-07-17 22:10:19 +00:00
with ClientGUITopLevelWindows.DialogCustomButtonQuestion( win, title ) as dlg:
panel = ClientGUIScrolledPanelsButtonQuestions.QuestionYesNoPanel( dlg, message, yes_label = yes_label, no_label = no_label )
dlg.SetPanel( panel )
2019-09-05 00:05:32 +00:00
if auto_yes_time is None and auto_no_time is None:
2019-08-07 22:59:53 +00:00
2019-11-14 03:56:30 +00:00
return dlg.exec() if not check_for_cancelled else ( dlg.exec(), dlg.WasCancelled() )
2019-08-07 22:59:53 +00:00
else:
2019-09-05 00:05:32 +00:00
if auto_yes_time is not None:
2019-11-14 03:56:30 +00:00
job = HG.client_controller.CallLaterQtSafe( dlg, auto_yes_time, dlg.done, QW.QDialog.Accepted )
2019-09-05 00:05:32 +00:00
2019-09-11 21:51:09 +00:00
elif auto_no_time is not None:
2019-09-05 00:05:32 +00:00
2019-11-14 03:56:30 +00:00
job = HG.client_controller.CallLaterQtSafe( dlg, auto_no_time, dlg.done, QW.QDialog.Rejected )
2019-09-05 00:05:32 +00:00
2019-08-07 22:59:53 +00:00
try:
2019-11-14 03:56:30 +00:00
return dlg.exec() if not check_for_cancelled else ( dlg.exec(), dlg.WasCancelled() )
2019-08-07 22:59:53 +00:00
finally:
job.Cancel()
2019-07-17 22:10:19 +00:00
2018-11-14 23:10:55 +00:00
def SelectFromList( win, title, choice_tuples, value_to_select = None, sort_tuples = True ):
with ClientGUITopLevelWindows.DialogEdit( win, title ) as dlg:
panel = ClientGUIScrolledPanelsEdit.EditSelectFromListPanel( dlg, choice_tuples, value_to_select = value_to_select, sort_tuples = sort_tuples )
dlg.SetPanel( panel )
2019-11-14 03:56:30 +00:00
if dlg.exec() == QW.QDialog.Accepted:
2018-11-14 23:10:55 +00:00
result = panel.GetValue()
return result
else:
raise HydrusExceptions.CancelledException()
2019-01-16 22:40:53 +00:00
def SelectFromListButtons( win, title, choice_tuples ):
with ClientGUITopLevelWindows.DialogEdit( win, title, hide_buttons = True ) as dlg:
panel = ClientGUIScrolledPanelsEdit.EditSelectFromListButtonsPanel( dlg, choice_tuples )
dlg.SetPanel( panel )
2019-11-14 03:56:30 +00:00
if dlg.exec() == QW.QDialog.Accepted:
2019-01-16 22:40:53 +00:00
result = panel.GetValue()
return result
else:
raise HydrusExceptions.CancelledException()
2020-03-04 22:12:53 +00:00
def SelectServiceKey( service_types = HC.ALL_SERVICES, service_keys = None, unallowed = None ):
if service_keys is None:
services = HG.client_controller.services_manager.GetServices( service_types )
service_keys = [ service.GetServiceKey() for service in services ]
if unallowed is not None:
service_keys.difference_update( unallowed )
if len( service_keys ) == 0:
return None
elif len( service_keys ) == 1:
( service_key, ) = service_keys
return service_key
else:
services = { HG.client_controller.services_manager.GetService( service_key ) for service_key in service_keys }
choice_tuples = [ ( service.GetName(), service.GetServiceKey() ) for service in services ]
try:
service_key = SelectFromList( HG.client_controller.gui, 'select service', choice_tuples )
return service_key
except HydrusExceptions.CancelledException:
return None