예제 #1
0
def AddServiceKeysToMenu(menu, service_keys, submenu_name, description,
                         bare_call):

    menu_tuples = []

    services_manager = HG.client_controller.services_manager

    for service_key in service_keys:

        label = services_manager.GetName(service_key)

        this_call = HydrusData.Call(bare_call, service_key)

        menu_tuples.append((label, description, this_call))

    ClientGUIMenus.AppendMenuOrItem(menu, submenu_name, menu_tuples)
예제 #2
0
def AddLocalFilesMoveAddToMenu(
        win: QW.QWidget, menu: QW.QMenu,
        local_duplicable_to_file_service_keys: typing.Collection[bytes],
        local_moveable_from_and_to_file_service_keys: typing.Collection[
            typing.Tuple[bytes, bytes]], multiple_selected: bool,
        process_application_command_call):

    if len(local_duplicable_to_file_service_keys) == 0 and len(
            local_moveable_from_and_to_file_service_keys) == 0:

        return

    local_action_menu = QW.QMenu(menu)

    if len(local_duplicable_to_file_service_keys) > 0:

        menu_tuples = []

        for s_k in local_duplicable_to_file_service_keys:

            application_command = CAC.ApplicationCommand(
                command_type=CAC.APPLICATION_COMMAND_TYPE_CONTENT,
                data=(s_k, HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_ADD, None))

            label = HG.client_controller.services_manager.GetName(s_k)
            description = 'Duplicate the files to this local file service.'
            call = HydrusData.Call(process_application_command_call,
                                   application_command)

            menu_tuples.append((label, description, call))

        if multiple_selected:

            submenu_name = 'add selected to'

        else:

            submenu_name = 'add to'

        ClientGUIMenus.AppendMenuOrItem(local_action_menu, submenu_name,
                                        menu_tuples)

    if len(local_moveable_from_and_to_file_service_keys) > 0:

        menu_tuples = []

        for (source_s_k,
             dest_s_k) in local_moveable_from_and_to_file_service_keys:

            application_command = CAC.ApplicationCommand(
                command_type=CAC.APPLICATION_COMMAND_TYPE_CONTENT,
                data=(dest_s_k, HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_MOVE,
                      source_s_k))

            label = 'from {} to {}'.format(
                HG.client_controller.services_manager.GetName(source_s_k),
                HG.client_controller.services_manager.GetName(dest_s_k))
            description = 'Add the files to the destination and delete from the source.'
            call = HydrusData.Call(process_application_command_call,
                                   application_command)

            menu_tuples.append((label, description, call))

        if multiple_selected:

            submenu_name = 'move selected'

        else:

            submenu_name = 'move'

        ClientGUIMenus.AppendMenuOrItem(local_action_menu, submenu_name,
                                        menu_tuples)

    ClientGUIMenus.AppendMenu(menu, local_action_menu, 'local services')