def AddServiceKeyLabelsToMenu(menu, service_keys, phrase):

    services_manager = HG.client_controller.services_manager

    if len(service_keys) == 1:

        (service_key, ) = service_keys

        name = services_manager.GetName(service_key)

        label = phrase + ' ' + name

        ClientGUIMenus.AppendMenuLabel(menu, label)

    else:

        submenu = QW.QMenu(menu)

        for service_key in service_keys:

            name = services_manager.GetName(service_key)

            ClientGUIMenus.AppendMenuLabel(submenu, name)

        ClientGUIMenus.AppendMenu(menu, submenu, phrase + '\u2026')
Example #2
0
def AddFileViewingStatsMenu(menu,
                            medias: typing.Collection[ClientMedia.Media]):

    if len(medias) == 0:

        return

    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])

    if view_style == CC.FILE_VIEWING_STATS_MENU_DISPLAY_MEDIA_AND_PREVIEW_SUMMED:

        combined_line = fvsm.GetPrettyViewsLine(
            (CC.CANVAS_MEDIA_VIEWER, CC.CANVAS_PREVIEW))

        ClientGUIMenus.AppendMenuLabel(menu, combined_line)

    else:

        media_line = fvsm.GetPrettyViewsLine((CC.CANVAS_MEDIA_VIEWER, ))
        preview_line = fvsm.GetPrettyViewsLine((CC.CANVAS_PREVIEW, ))

        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:

            submenu = QW.QMenu(menu)

            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)
Example #3
0
def AddFileViewingStatsMenu(menu, focus_media):

    view_style = HG.client_controller.new_options.GetInteger(
        'file_viewing_stats_menu_display')

    if view_style == CC.FILE_VIEWING_STATS_MENU_DISPLAY_NONE:

        return

    fvsm = focus_media.GetFileViewingStatsManager()

    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:

            submenu = QW.QMenu(menu)

            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)
Example #4
0
 def _PopulateMenu( self, menu, menu_items ):
     
     for ( item_type, title, description, data ) in menu_items:
         
         if item_type == 'normal':
             
             func = data
             
             ClientGUIMenus.AppendMenuItem( menu, title, description, func )
             
         elif item_type == 'check':
             
             check_manager = data
             
             current_value = check_manager.GetCurrentValue()
             func = check_manager.Invert
             
             if current_value is not None:
                 
                 ClientGUIMenus.AppendMenuCheckItem( menu, title, description, current_value, func )
                 
             
         elif item_type == 'separator':
             
             ClientGUIMenus.AppendSeparator( menu )
             
         elif item_type == 'submenu':
             
             submenu = QW.QMenu( menu )
             
             self._PopulateMenu( submenu, data )
             
             ClientGUIMenus.AppendMenu( menu, submenu, title )
             
         elif item_type == 'label':
             
             ClientGUIMenus.AppendMenuLabel( menu, title, description = description )
Example #5
0
 def _ShowCogMenu( self ):
     
     menu = QW.QMenu()
     
     if self._network_job is not None and self._network_job.engine is not None:
         
         url = self._network_job.GetURL()
         
         ClientGUIMenus.AppendMenuLabel( menu, url, description = 'copy URL to the clipboard' )
         
         ClientGUIMenus.AppendSeparator( menu )
         
         network_contexts = self._network_job.GetNetworkContexts()
         
         if len( network_contexts ) > 0:
             
             bandwidth_manager = self._network_job.engine.bandwidth_manager
             
             submenu = QW.QMenu( menu )
             
             menu_network_contexts = []
             
             network_contexts_used = set()
             
             for network_context in network_contexts:
                 
                 uses_default = False
                 
                 if bandwidth_manager.UsesDefaultRules( network_context ):
                     
                     uses_default = True
                     
                     default_network_context = network_context.GetDefault()
                     
                     if default_network_context not in network_contexts_used:
                         
                         menu_network_contexts.append( ( False, default_network_context, network_context ) )
                         
                         network_contexts_used.add( default_network_context )
                         
                     
                 
                 if not network_context.IsEphemeral():
                     
                     menu_network_contexts.append( ( uses_default, network_context, network_context ) )
                     
                 
             
             for ( uses_default, network_context_to_edit, network_context_to_test ) in menu_network_contexts:
                 
                 network_context_text = network_context_to_edit.ToString()
                 
                 if uses_default:
                     
                     network_context_text = 'set rules for {}'.format( network_context_text )
                     
                 else:
                     
                     ( waiting_estimate, gumpf ) = bandwidth_manager.GetWaitingEstimateAndContext( [ network_context_to_test ] )
                     
                     if waiting_estimate > 0:
                         
                         network_context_text = '{} ({})'.format( network_context_text, HydrusData.TimeDeltaToPrettyTimeDelta( waiting_estimate ) )
                         
                     
                 
                 ClientGUIMenus.AppendMenuItem( submenu, network_context_text, 'edit the bandwidth rules for this network context', self._EditBandwidthRules, network_context_to_edit )
                 
             
             ClientGUIMenus.AppendMenu( menu, submenu, 'edit bandwidth rules' )
             
             ClientGUIMenus.AppendSeparator( menu )
             
         
         if self._network_job.CurrentlyWaitingOnConnectionError():
             
             ClientGUIMenus.AppendMenuItem( menu, 'reattempt connection now', 'Stop waiting on a connection error and reattempt the job now.', self._network_job.OverrideConnectionErrorWait )
             
         
         if not self._network_job.DomainOK():
             
             ClientGUIMenus.AppendMenuItem( menu, 'scrub domain errors', 'Clear recent domain errors and allow this job to go now.', self._network_job.ScrubDomainErrors )
             
         
         if self._network_job.CurrentlyWaitingOnServersideBandwidth():
             
             ClientGUIMenus.AppendMenuItem( menu, 'reattempt request now (server reports low bandwidth)', 'Stop waiting on a serverside bandwidth delay and reattempt the job now.', self._network_job.OverrideServersideBandwidthWait )
             
         
         if self._network_job.ObeysBandwidth():
             
             ClientGUIMenus.AppendMenuItem( menu, 'override bandwidth rules for this job', 'Tell the current job to ignore existing bandwidth rules and go ahead anyway.', self._network_job.OverrideBandwidth )
             
         
         if not self._network_job.TokensOK():
             
             ClientGUIMenus.AppendMenuItem( menu, 'override forced gallery wait times for this job', 'Force-allow this download to proceed, ignoring the normal gallery wait times.', self._network_job.OverrideToken )
             
         
         ClientGUIMenus.AppendSeparator( menu )
         
     
     ClientGUIMenus.AppendMenuCheckItem( menu, 'auto-override bandwidth rules for all jobs here after five seconds', 'Ignore existing bandwidth rules for all jobs under this control, instead waiting a flat five seconds.', self._auto_override_bandwidth_rules, self.FlipAutoOverrideBandwidth )
     
     CGC.core().PopupMenu( self._cog_button, menu )
    def _GetListCtrlMenu(self):

        selected_file_seeds = self._list_ctrl.GetData(only_selected=True)

        if len(selected_file_seeds) == 0:

            raise HydrusExceptions.DataMissing()

        menu = QW.QMenu()

        can_show_files_in_new_page = True in (
            file_seed.HasHash() for file_seed in selected_file_seeds)

        if can_show_files_in_new_page:

            ClientGUIMenus.AppendMenuItem(
                menu, 'open selected import files in a new page',
                'Show all the known selected files in a new thumbnail page. This is complicated, so cannot always be guaranteed, even if the import says \'success\'.',
                self._ShowSelectionInNewPage)

            ClientGUIMenus.AppendSeparator(menu)

        ClientGUIMenus.AppendMenuItem(
            menu, 'copy sources',
            'Copy all the selected sources to clipboard.',
            self._CopySelectedFileSeedData)
        ClientGUIMenus.AppendMenuItem(
            menu, 'copy notes', 'Copy all the selected notes to clipboard.',
            self._CopySelectedNotes)

        if len(selected_file_seeds) == 1:

            ClientGUIMenus.AppendSeparator(menu)

            (selected_file_seed, ) = selected_file_seeds

            hash_types_to_hashes = selected_file_seed.GetHashTypesToHashes()

            if len(hash_types_to_hashes) == 0:

                ClientGUIMenus.AppendMenuLabel(menu, 'no hashes yet')

            else:

                hash_submenu = QW.QMenu(menu)

                for hash_type in ('sha256', 'md5', 'sha1', 'sha512'):

                    if hash_type in hash_types_to_hashes:

                        h = hash_types_to_hashes[hash_type]

                        ClientGUIMenus.AppendMenuLabel(
                            hash_submenu, '{}:{}'.format(hash_type, h.hex()))

                ClientGUIMenus.AppendMenu(menu, hash_submenu, 'hashes')

            #

            if selected_file_seed.IsURLFileImport():

                referral_url = selected_file_seed.GetReferralURL()
                primary_urls = sorted(selected_file_seed.GetPrimaryURLs())
                source_urls = sorted(selected_file_seed.GetSourceURLs())

                if referral_url is None and len(primary_urls) + len(
                        source_urls) == 0:

                    ClientGUIMenus.AppendMenuLabel(menu, 'no additional urls')

                else:

                    url_submenu = QW.QMenu(menu)

                    if referral_url is not None:

                        ClientGUIMenus.AppendMenuLabel(url_submenu,
                                                       'referral url:')
                        ClientGUIMenus.AppendMenuLabel(url_submenu,
                                                       referral_url)

                    if len(primary_urls) > 0:

                        ClientGUIMenus.AppendSeparator(url_submenu)

                        ClientGUIMenus.AppendMenuLabel(url_submenu,
                                                       'primary urls:')

                        for url in primary_urls:

                            ClientGUIMenus.AppendMenuLabel(url_submenu, url)

                    if len(source_urls) > 0:

                        ClientGUIMenus.AppendSeparator(url_submenu)

                        ClientGUIMenus.AppendMenuLabel(url_submenu,
                                                       'source urls:')

                        for url in source_urls:

                            ClientGUIMenus.AppendMenuLabel(url_submenu, url)

                    ClientGUIMenus.AppendMenu(menu, url_submenu,
                                              'additional urls')

                #

                tags = list(selected_file_seed.GetExternalTags())

                tag_sort = ClientTagSorting.TagSort(
                    sort_type=ClientTagSorting.SORT_BY_HUMAN_TAG,
                    sort_order=CC.SORT_ASC)

                ClientTagSorting.SortTags(tag_sort, tags)

                if len(tags) == 0:

                    ClientGUIMenus.AppendMenuLabel(menu, 'no parsed tags')

                else:

                    tag_submenu = QW.QMenu(menu)

                    for tag in tags:

                        ClientGUIMenus.AppendMenuLabel(tag_submenu, tag)

                    ClientGUIMenus.AppendMenu(menu, tag_submenu, 'parsed tags')

        ClientGUIMenus.AppendSeparator(menu)

        ClientGUIMenus.AppendMenuItem(
            menu, 'open sources',
            'Open all the selected sources in your file explorer or web browser.',
            self._OpenSelectedFileSeedData)

        ClientGUIMenus.AppendSeparator(menu)

        ClientGUIMenus.AppendMenuItem(
            menu, 'try again',
            'Reset the progress of all the selected imports.',
            HydrusData.Call(self._SetSelected, CC.STATUS_UNKNOWN))

        ClientGUIMenus.AppendMenuItem(
            menu, 'skip', 'Skip all the selected imports.',
            HydrusData.Call(self._SetSelected, CC.STATUS_SKIPPED))

        ClientGUIMenus.AppendMenuItem(menu, 'delete from list',
                                      'Remove all the selected imports.',
                                      HydrusData.Call(self._DeleteSelected))

        return menu