hydrus/hydrus/client/gui/ClientGUIMedia.py

662 lines
21 KiB
Python
Raw Normal View History

import itertools
2013-02-19 00:11:43 +00:00
import os
import random
2013-03-15 02:38:12 +00:00
import time
2020-05-27 21:27:52 +00:00
import typing
2020-04-22 21:00:35 +00:00
2019-11-14 03:56:30 +00:00
from qtpy import QtWidgets as QW
2020-04-22 21:00:35 +00:00
2020-05-27 21:27:52 +00:00
from hydrus.core import HydrusConstants as HC
2020-04-22 21:00:35 +00:00
from hydrus.core import HydrusExceptions
from hydrus.core import HydrusPaths
from hydrus.core import HydrusData
from hydrus.core import HydrusGlobals as HG
2020-07-29 20:52:44 +00:00
2020-04-22 21:00:35 +00:00
from hydrus.client import ClientConstants as CC
from hydrus.client import ClientPaths
from hydrus.client import ClientThreading
from hydrus.client.gui import ClientGUIDialogsQuick
from hydrus.client.gui import ClientGUIMenus
2020-07-29 20:52:44 +00:00
from hydrus.client.media import ClientMedia
from hydrus.client.media import ClientMediaManagers
2013-02-19 00:11:43 +00:00
2020-08-27 01:00:42 +00:00
def CopyHashesToClipboard( win: QW.QWidget, hash_type: str, medias: typing.Sequence[ ClientMedia.Media ] ):
sha256_hashes = list( itertools.chain.from_iterable( ( media.GetHashes( ordered = True ) for media in medias ) ) )
if hash_type == 'sha256':
desired_hashes = sha256_hashes
else:
num_hashes = len( sha256_hashes )
num_remote_sha256_hashes = len( [ itertools.chain.from_iterable( ( media.GetHashes( discriminant = CC.DISCRIMINANT_NOT_LOCAL, ordered = True ) for media in medias ) ) ] )
desired_hashes = HG.client_controller.Read( 'file_hashes', sha256_hashes, 'sha256', hash_type )
num_missing = num_hashes - len( desired_hashes )
if num_missing > 0:
if num_missing == num_hashes:
message = 'Unfortunately, none of the {} hashes could be found.'.format( hash_type )
else:
message = 'Unfortunately, {} of the {} hashes could not be found.'.format( HydrusData.ToHumanInt( num_missing ), hash_type )
if num_remote_sha256_hashes > 0:
message += ' {} of the files you wanted are not currently in this client. If they have never visited this client, the lookup is impossible.'.format( HydrusData.ToHumanInt( num_remote_sha256_hashes ) )
if num_remote_sha256_hashes < num_hashes:
message += ' It could be that some of the local files are currently missing this information in the hydrus database. A file maintenance job (under the database menu) can repopulate this data.'
QW.QMessageBox.warning( win, 'Warning', message )
if len( desired_hashes ) > 0:
2020-11-04 23:23:07 +00:00
text_lines = [ desired_hash.hex() for desired_hash in desired_hashes ]
2020-11-04 23:23:07 +00:00
if HG.client_controller.new_options.GetBoolean( 'prefix_hash_when_copying' ):
text_lines = [ '{}:{}'.format( hash_type, hex_hash ) for hex_hash in text_lines ]
hex_hashes_text = os.linesep.join( text_lines )
HG.client_controller.pub( 'clipboard', 'text', hex_hashes_text )
job_key = ClientThreading.JobKey()
job_key.SetVariable( 'popup_text_1', '{} {} hashes copied'.format( HydrusData.ToHumanInt( len( desired_hashes ) ), hash_type ) )
HG.client_controller.pub( 'message', job_key )
job_key.Delete( 2 )
2018-08-22 21:10:59 +00:00
def CopyMediaURLs( medias ):
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
urls = set()
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
for media in medias:
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
media_urls = media.GetLocationsManager().GetURLs()
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
urls.update( media_urls )
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
2020-05-13 19:03:16 +00:00
urls = sorted( urls )
2018-08-22 21:10:59 +00:00
urls_string = os.linesep.join( urls )
HG.client_controller.pub( 'clipboard', 'text', urls_string )
2019-05-08 21:06:42 +00:00
def CopyMediaURLClassURLs( medias, url_class ):
2018-08-22 21:10:59 +00:00
urls = set()
for media in medias:
media_urls = media.GetLocationsManager().GetURLs()
for url in media_urls:
2020-12-16 22:29:51 +00:00
# can't do 'url_class.matches', as it will match too many
if HG.client_controller.network_engine.domain_manager.GetURLClass( url ) == url_class:
2018-08-22 21:10:59 +00:00
urls.add( url )
2020-05-13 19:03:16 +00:00
urls = sorted( urls )
2018-08-22 21:10:59 +00:00
urls_string = os.linesep.join( urls )
HG.client_controller.pub( 'clipboard', 'text', urls_string )
def DoClearFileViewingStats( win: QW.QWidget, flat_medias: typing.Collection[ ClientMedia.MediaSingleton ] ):
2020-05-27 21:27:52 +00:00
if len( flat_medias ) == 0:
return
if len( flat_medias ) == 1:
insert = 'this file'
else:
insert = 'these {} files'.format( HydrusData.ToHumanInt( len( flat_medias ) ) )
message = 'Clear the file viewing stats for {}?'.format( insert )
result = ClientGUIDialogsQuick.GetYesNo( win, message )
if result == QW.QDialog.Accepted:
hashes = { m.GetHash() for m in flat_medias }
content_update = HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILE_VIEWING_STATS, HC.CONTENT_UPDATE_DELETE, hashes )
HG.client_controller.Write( 'content_updates', { CC.COMBINED_LOCAL_FILE_SERVICE_KEY : [ content_update ] } )
2019-03-20 21:22:10 +00:00
def DoOpenKnownURLFromShortcut( win, media ):
urls = media.GetLocationsManager().GetURLs()
matched_labels_and_urls = []
unmatched_urls = []
if len( urls ) > 0:
for url in urls:
2020-04-01 21:51:42 +00:00
try:
url_class = HG.client_controller.network_engine.domain_manager.GetURLClass( url )
except HydrusExceptions.URLClassException:
continue
2019-03-20 21:22:10 +00:00
2019-05-08 21:06:42 +00:00
if url_class is None:
2019-03-20 21:22:10 +00:00
unmatched_urls.append( url )
else:
2019-05-08 21:06:42 +00:00
label = url_class.GetName() + ': ' + url
2019-03-20 21:22:10 +00:00
matched_labels_and_urls.append( ( label, url ) )
matched_labels_and_urls.sort()
unmatched_urls.sort()
if len( matched_labels_and_urls ) == 0:
return
elif len( matched_labels_and_urls ) == 1:
url = matched_labels_and_urls[0][1]
else:
matched_labels_and_urls.extend( ( url, url ) for url in unmatched_urls )
try:
url = ClientGUIDialogsQuick.SelectFromList( win, 'Select which URL', matched_labels_and_urls, sort_tuples = False )
except HydrusExceptions.CancelledException:
return
ClientPaths.LaunchURLInWebBrowser( url )
2020-02-12 22:50:37 +00:00
def OpenExternally( media ):
hash = media.GetHash()
mime = media.GetMime()
client_files_manager = HG.client_controller.client_files_manager
path = client_files_manager.GetFilePath( hash, mime )
new_options = HG.client_controller.new_options
launch_path = new_options.GetMimeLaunch( mime )
HydrusPaths.LaunchFile( path, launch_path )
2019-03-06 23:06:22 +00:00
def OpenURLs( urls ):
2020-05-13 19:03:16 +00:00
urls = sorted( urls )
2019-03-06 23:06:22 +00:00
if len( urls ) > 1:
message = 'Open the {} URLs in your web browser?'.format( len( urls ) )
if len( urls ) > 10:
message += ' This will take some time.'
2020-07-15 20:52:09 +00:00
tlw = HG.client_controller.GetMainTLW()
result = ClientGUIDialogsQuick.GetYesNo( tlw, message )
2019-09-05 00:05:32 +00:00
2019-11-14 03:56:30 +00:00
if result != QW.QDialog.Accepted:
2019-03-06 23:06:22 +00:00
2019-09-05 00:05:32 +00:00
return
2019-03-06 23:06:22 +00:00
def do_it( urls ):
job_key = None
num_urls = len( urls )
if num_urls > 5:
2019-03-13 21:04:21 +00:00
job_key = ClientThreading.JobKey( pausable = True, cancellable = True )
2019-03-06 23:06:22 +00:00
job_key.SetVariable( 'popup_title', 'Opening URLs' )
HG.client_controller.pub( 'message', job_key )
try:
for ( i, url ) in enumerate( urls ):
if job_key is not None:
2019-03-13 21:04:21 +00:00
( i_paused, should_quit ) = job_key.WaitIfNeeded()
if should_quit:
2019-03-06 23:06:22 +00:00
return
job_key.SetVariable( 'popup_text_1', HydrusData.ConvertValueRangeToPrettyString( i + 1, num_urls ) )
job_key.SetVariable( 'popup_gauge_1', ( i + 1, num_urls ) )
ClientPaths.LaunchURLInWebBrowser( url )
time.sleep( 1 )
finally:
if job_key is not None:
job_key.Finish()
job_key.Delete( 1 )
HG.client_controller.CallToThread( do_it, urls )
def OpenMediaURLs( medias ):
urls = set()
for media in medias:
media_urls = media.GetLocationsManager().GetURLs()
urls.update( media_urls )
OpenURLs( urls )
2019-05-08 21:06:42 +00:00
def OpenMediaURLClassURLs( medias, url_class ):
2019-03-06 23:06:22 +00:00
urls = set()
for media in medias:
media_urls = media.GetLocationsManager().GetURLs()
for url in media_urls:
2020-12-16 22:29:51 +00:00
# can't do 'url_class.matches', as it will match too many
if HG.client_controller.network_engine.domain_manager.GetURLClass( url ) == url_class:
2019-03-06 23:06:22 +00:00
urls.add( url )
OpenURLs( urls )
def AddFileViewingStatsMenu( menu, medias: typing.Collection[ ClientMedia.Media ] ):
if len( medias ) == 0:
return
2018-12-05 22:35:30 +00:00
view_style = HG.client_controller.new_options.GetInteger( 'file_viewing_stats_menu_display' )
if view_style == CC.FILE_VIEWING_STATS_MENU_DISPLAY_NONE:
return
if len( medias ) == 1:
( media, ) = medias
fvsm = media.GetFileViewingStatsManager()
else:
fvsm = ClientMediaManagers.FileViewingStatsManager.STATICGenerateCombinedManager( [ media.GetFileViewingStatsManager() for media in medias ] )
2018-12-05 22:35:30 +00:00
if view_style == CC.FILE_VIEWING_STATS_MENU_DISPLAY_MEDIA_AND_PREVIEW_SUMMED:
combined_line = fvsm.GetPrettyCombinedLine()
ClientGUIMenus.AppendMenuLabel( menu, combined_line )
else:
media_line = fvsm.GetPrettyMediaLine()
preview_line = fvsm.GetPrettyPreviewLine()
if view_style == CC.FILE_VIEWING_STATS_MENU_DISPLAY_MEDIA_ONLY:
ClientGUIMenus.AppendMenuLabel( menu, media_line )
elif view_style == CC.FILE_VIEWING_STATS_MENU_DISPLAY_MEDIA_AND_PREVIEW_IN_SUBMENU:
2019-11-14 03:56:30 +00:00
submenu = QW.QMenu( menu )
2018-12-05 22:35:30 +00:00
ClientGUIMenus.AppendMenuLabel( submenu, preview_line )
ClientGUIMenus.AppendMenu( menu, submenu, media_line )
elif view_style == CC.FILE_VIEWING_STATS_MENU_DISPLAY_MEDIA_AND_PREVIEW_STACKED:
ClientGUIMenus.AppendMenuLabel( menu, media_line )
ClientGUIMenus.AppendMenuLabel( menu, preview_line )
2018-08-22 21:10:59 +00:00
def AddKnownURLsViewCopyMenu( win, menu, focus_media, selected_media = None ):
# figure out which urls this focused file has
focus_urls = focus_media.GetLocationsManager().GetURLs()
focus_matched_labels_and_urls = []
focus_unmatched_urls = []
focus_labels_and_urls = []
if len( focus_urls ) > 0:
for url in focus_urls:
2018-08-15 20:40:30 +00:00
2020-04-01 21:51:42 +00:00
try:
url_class = HG.client_controller.network_engine.domain_manager.GetURLClass( url )
except HydrusExceptions.URLClassException:
continue
2018-08-15 20:40:30 +00:00
2019-05-08 21:06:42 +00:00
if url_class is None:
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
focus_unmatched_urls.append( url )
2018-08-15 20:40:30 +00:00
else:
2019-05-08 21:06:42 +00:00
label = url_class.GetName() + ': ' + url
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
focus_matched_labels_and_urls.append( ( label, url ) )
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
focus_matched_labels_and_urls.sort()
focus_unmatched_urls.sort()
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
focus_labels_and_urls = list( focus_matched_labels_and_urls )
focus_labels_and_urls.extend( ( ( url, url ) for url in focus_unmatched_urls ) )
# figure out which urls these selected files have
2019-05-08 21:06:42 +00:00
selected_media_url_classes = set()
multiple_or_unmatching_selection_url_classes = False
2018-08-22 21:10:59 +00:00
if selected_media is not None and len( selected_media ) > 1:
selected_media = ClientMedia.FlattenMedia( selected_media )
SAMPLE_SIZE = 256
if len( selected_media ) > SAMPLE_SIZE:
selected_media_sample = random.sample( selected_media, SAMPLE_SIZE )
else:
selected_media_sample = selected_media
for media in selected_media_sample:
media_urls = media.GetLocationsManager().GetURLs()
for url in media_urls:
2020-04-01 21:51:42 +00:00
try:
url_class = HG.client_controller.network_engine.domain_manager.GetURLClass( url )
except HydrusExceptions.URLClassException:
continue
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
if url_class is None:
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
multiple_or_unmatching_selection_url_classes = True
2018-08-22 21:10:59 +00:00
else:
2019-05-08 21:06:42 +00:00
selected_media_url_classes.add( url_class )
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
if len( selected_media_url_classes ) > 1:
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
multiple_or_unmatching_selection_url_classes = True
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
if len( focus_labels_and_urls ) > 0 or len( selected_media_url_classes ) > 0 or multiple_or_unmatching_selection_url_classes:
2018-08-15 20:40:30 +00:00
2019-11-14 03:56:30 +00:00
urls_menu = QW.QMenu( menu )
2018-08-15 20:40:30 +00:00
2019-11-14 03:56:30 +00:00
urls_visit_menu = QW.QMenu( urls_menu )
urls_copy_menu = QW.QMenu( urls_menu )
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
# copy each this file's urls (of a particular type)
if len( focus_labels_and_urls ) > 0:
for ( label, url ) in focus_labels_and_urls:
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_visit_menu, label, 'Open this url in your web browser.', ClientPaths.LaunchURLInWebBrowser, url )
ClientGUIMenus.AppendMenuItem( urls_copy_menu, label, 'Copy this url to your clipboard.', HG.client_controller.pub, 'clipboard', 'text', url )
2018-08-22 21:10:59 +00:00
# copy this file's urls
2019-05-08 21:06:42 +00:00
there_are_focus_url_classes_to_action = len( focus_matched_labels_and_urls ) > 1
multiple_or_unmatching_focus_url_classes = len( focus_unmatched_urls ) > 0 and len( focus_labels_and_urls ) > 1 # if there are unmatched urls and more than one thing total
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
if there_are_focus_url_classes_to_action or multiple_or_unmatching_focus_url_classes:
2018-08-22 21:10:59 +00:00
2019-03-06 23:06:22 +00:00
ClientGUIMenus.AppendSeparator( urls_visit_menu )
2018-08-22 21:10:59 +00:00
ClientGUIMenus.AppendSeparator( urls_copy_menu )
2019-05-08 21:06:42 +00:00
if there_are_focus_url_classes_to_action:
2018-08-22 21:10:59 +00:00
urls = [ url for ( label, url ) in focus_matched_labels_and_urls ]
2019-03-06 23:06:22 +00:00
label = 'open this file\'s ' + HydrusData.ToHumanInt( len( urls ) ) + ' recognised urls in your web browser'
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_visit_menu, label, 'Open these urls in your web browser.', OpenURLs, urls )
2019-03-06 23:06:22 +00:00
2018-08-22 21:10:59 +00:00
urls_string = os.linesep.join( urls )
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
label = 'copy this file\'s ' + HydrusData.ToHumanInt( len( urls ) ) + ' recognised urls to your clipboard'
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_copy_menu, label, 'Copy these urls to your clipboard.', HG.client_controller.pub, 'clipboard', 'text', urls_string )
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
if multiple_or_unmatching_focus_url_classes:
2018-08-15 20:40:30 +00:00
2018-08-22 21:10:59 +00:00
urls = [ url for ( label, url ) in focus_labels_and_urls ]
2019-03-06 23:06:22 +00:00
label = 'open this file\'s ' + HydrusData.ToHumanInt( len( urls ) ) + ' urls in your web browser'
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_visit_menu, label, 'Open these urls in your web browser.', OpenURLs, urls )
2019-03-06 23:06:22 +00:00
2018-08-22 21:10:59 +00:00
urls_string = os.linesep.join( urls )
label = 'copy this file\'s ' + HydrusData.ToHumanInt( len( urls ) ) + ' urls to your clipboard'
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_copy_menu, label, 'Copy this url to your clipboard.', HG.client_controller.pub, 'clipboard', 'text', urls_string )
2018-08-22 21:10:59 +00:00
2019-03-06 23:06:22 +00:00
# now by url match type
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
there_are_selection_url_classes_to_action = len( selected_media_url_classes ) > 0
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
if there_are_selection_url_classes_to_action or multiple_or_unmatching_selection_url_classes:
2018-08-22 21:10:59 +00:00
2019-03-06 23:06:22 +00:00
ClientGUIMenus.AppendSeparator( urls_visit_menu )
2018-08-22 21:10:59 +00:00
ClientGUIMenus.AppendSeparator( urls_copy_menu )
2019-05-08 21:06:42 +00:00
if there_are_selection_url_classes_to_action:
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
selected_media_url_classes = list( selected_media_url_classes )
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
selected_media_url_classes.sort( key = lambda url_class: url_class.GetName() )
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
for url_class in selected_media_url_classes:
2019-03-06 23:06:22 +00:00
2019-05-08 21:06:42 +00:00
label = 'open files\' ' + url_class.GetName() + ' urls in your web browser'
2019-03-06 23:06:22 +00:00
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_visit_menu, label, 'Open this url class in your web browser for all files.', OpenMediaURLClassURLs, selected_media, url_class )
2018-08-22 21:10:59 +00:00
2019-05-08 21:06:42 +00:00
label = 'copy files\' ' + url_class.GetName() + ' urls'
2018-08-22 21:10:59 +00:00
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_copy_menu, label, 'Copy this url class for all files.', CopyMediaURLClassURLs, selected_media, url_class )
2018-08-22 21:10:59 +00:00
2019-03-06 23:06:22 +00:00
# now everything
2019-05-08 21:06:42 +00:00
if multiple_or_unmatching_selection_url_classes:
2019-03-06 23:06:22 +00:00
label = 'open all files\' urls'
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_visit_menu, label, 'Open urls in your web browser for all files.', OpenMediaURLs, selected_media )
2018-08-22 21:10:59 +00:00
label = 'copy all files\' urls'
2019-11-14 03:56:30 +00:00
ClientGUIMenus.AppendMenuItem( urls_copy_menu, label, 'Copy urls for all files.', CopyMediaURLs, selected_media )
2018-08-22 21:10:59 +00:00
#
2018-08-15 20:40:30 +00:00
2019-03-06 23:06:22 +00:00
ClientGUIMenus.AppendMenu( urls_menu, urls_visit_menu, 'open' )
2018-08-15 20:40:30 +00:00
ClientGUIMenus.AppendMenu( urls_menu, urls_copy_menu, 'copy' )
ClientGUIMenus.AppendMenu( menu, urls_menu, 'known urls' )
def AddManageFileViewingStatsMenu( win: QW.QWidget, menu: QW.QMenu, flat_medias: typing.Collection[ ClientMedia.MediaSingleton ] ):
2020-05-27 21:27:52 +00:00
# add test here for if media actually has stats, edit them, all that
submenu = QW.QMenu( menu )
ClientGUIMenus.AppendMenuItem( submenu, 'clear', 'Clear all the recorded file viewing stats for the selected files.', DoClearFileViewingStats, win, flat_medias )
ClientGUIMenus.AppendMenu( menu, submenu, 'viewing stats' )
2017-01-04 22:48:23 +00:00
def AddServiceKeyLabelsToMenu( menu, service_keys, phrase ):
2013-02-19 00:11:43 +00:00
2017-06-28 20:23:21 +00:00
services_manager = HG.client_controller.services_manager
2014-08-27 22:15:22 +00:00
2016-02-24 21:42:54 +00:00
if len( service_keys ) == 1:
2013-02-19 00:11:43 +00:00
2016-02-24 21:42:54 +00:00
( service_key, ) = service_keys
2013-02-19 00:11:43 +00:00
2017-01-04 22:48:23 +00:00
name = services_manager.GetName( service_key )
2014-08-27 22:15:22 +00:00
2017-01-04 22:48:23 +00:00
label = phrase + ' ' + name
2013-02-19 00:11:43 +00:00
2017-01-04 22:48:23 +00:00
ClientGUIMenus.AppendMenuLabel( menu, label )
2013-02-19 00:11:43 +00:00
else:
2019-11-14 03:56:30 +00:00
submenu = QW.QMenu( menu )
2013-02-19 00:11:43 +00:00
2017-01-04 22:48:23 +00:00
for service_key in service_keys:
name = services_manager.GetName( service_key )
ClientGUIMenus.AppendMenuLabel( submenu, name )
2013-02-19 00:11:43 +00:00
2017-01-04 22:48:23 +00:00
2019-01-09 22:59:03 +00:00
ClientGUIMenus.AppendMenu( menu, submenu, phrase + '\u2026' )
2017-01-04 22:48:23 +00:00
2020-05-27 21:27:52 +00:00
def AddServiceKeysToMenu( event_handler, menu, service_keys, phrase, description, call ):
2017-01-04 22:48:23 +00:00
2017-06-28 20:23:21 +00:00
services_manager = HG.client_controller.services_manager
2017-01-04 22:48:23 +00:00
if len( service_keys ) == 1:
( service_key, ) = service_keys
name = services_manager.GetName( service_key )
label = phrase + ' ' + name
2020-05-27 21:27:52 +00:00
ClientGUIMenus.AppendMenuItem( menu, label, description, call, service_key )
2017-01-04 22:48:23 +00:00
else:
2019-11-14 03:56:30 +00:00
submenu = QW.QMenu( menu )
2017-01-04 22:48:23 +00:00
for service_key in service_keys:
2013-02-19 00:11:43 +00:00
2017-01-04 22:48:23 +00:00
name = services_manager.GetName( service_key )
2014-08-27 22:15:22 +00:00
2020-05-27 21:27:52 +00:00
ClientGUIMenus.AppendMenuItem( submenu, name, description, call, service_key )
2013-02-19 00:11:43 +00:00
2019-01-09 22:59:03 +00:00
ClientGUIMenus.AppendMenu( menu, submenu, phrase + '\u2026' )
2013-02-19 00:11:43 +00:00