def test_SERIALISABLE_TYPE_APPLICATION_COMMAND(self):
        def test(obj, dupe_obj):

            self.assertEqual(obj.GetCommandType(), dupe_obj.GetCommandType())

            self.assertEqual(obj.GetData(), dupe_obj.GetData())

        acs = []

        acs.append(
            (CAC.ApplicationCommand(CAC.APPLICATION_COMMAND_TYPE_SIMPLE,
                                    CAC.SIMPLE_ARCHIVE_FILE), 'archive file'))
        acs.append((CAC.ApplicationCommand(
            CAC.APPLICATION_COMMAND_TYPE_CONTENT,
            (HydrusData.GenerateKey(), HC.CONTENT_TYPE_MAPPINGS,
             HC.CONTENT_UPDATE_FLIP, 'test')),
                    'flip on/off mappings "test" for unknown service!'))
        acs.append((CAC.ApplicationCommand(
            CAC.APPLICATION_COMMAND_TYPE_CONTENT,
            (CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_TYPE_MAPPINGS,
             HC.CONTENT_UPDATE_FLIP, 'test')),
                    'flip on/off mappings "test" for my tags'))
        acs.append(
            (CAC.ApplicationCommand(
                CAC.APPLICATION_COMMAND_TYPE_CONTENT,
                (HydrusData.GenerateKey(), HC.CONTENT_TYPE_RATINGS,
                 HC.CONTENT_UPDATE_SET, 0.4)),
             'set ratings uncertain rating, "0.4" for unknown service!'))

        for (ac, s) in acs:

            self._dump_and_load_and_test(ac, test)

            self.assertEqual(ac.ToString(), s)
 def test_SERIALISABLE_TYPE_SHORTCUT_SET( self ):
     
     def test( obj, dupe_obj ):
         
         for ( shortcut, command ) in obj:
             
             self.assertEqual( dupe_obj.GetCommand( shortcut ).GetData(), command.GetData() )
             
         
     
     default_shortcuts = ClientDefaults.GetDefaultShortcuts()
     
     for shortcuts in default_shortcuts:
         
         self._dump_and_load_and_test( shortcuts, test )
         
     
     command_1 = CAC.ApplicationCommand( CAC.APPLICATION_COMMAND_TYPE_SIMPLE, CAC.SIMPLE_ARCHIVE_FILE )
     command_2 = CAC.ApplicationCommand( CAC.APPLICATION_COMMAND_TYPE_CONTENT, ( HydrusData.GenerateKey(), HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test' ) )
     command_3 = CAC.ApplicationCommand( CAC.APPLICATION_COMMAND_TYPE_CONTENT, ( CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test' ) )
     
     k_shortcut_1 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_SPECIAL, ClientGUIShortcuts.SHORTCUT_KEY_SPECIAL_SPACE, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [] )
     k_shortcut_2 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_CHARACTER, ord( 'a' ), ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] )
     k_shortcut_3 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_CHARACTER, ord( 'A' ), ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] )
     k_shortcut_4 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_SPECIAL, ClientGUIShortcuts.SHORTCUT_KEY_SPECIAL_HOME, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_ALT, ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] )
     
     m_shortcut_1 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_MOUSE, ClientGUIShortcuts.SHORTCUT_MOUSE_LEFT, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [] )
     m_shortcut_2 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_MOUSE, ClientGUIShortcuts.SHORTCUT_MOUSE_MIDDLE, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] )
     m_shortcut_3 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_MOUSE, ClientGUIShortcuts.SHORTCUT_MOUSE_SCROLL_DOWN, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_ALT, ClientGUIShortcuts.SHORTCUT_MODIFIER_SHIFT ] )
     
     shortcut_set = ClientGUIShortcuts.ShortcutSet( 'test' )
     
     shortcut_set.SetCommand( k_shortcut_1, command_1 )
     shortcut_set.SetCommand( k_shortcut_2, command_2 )
     shortcut_set.SetCommand( k_shortcut_3, command_2 )
     shortcut_set.SetCommand( k_shortcut_4, command_3 )
     
     shortcut_set.SetCommand( m_shortcut_1, command_1 )
     shortcut_set.SetCommand( m_shortcut_2, command_2 )
     shortcut_set.SetCommand( m_shortcut_3, command_3 )
     
     self._dump_and_load_and_test( shortcut_set, test )
     
     self.assertEqual( shortcut_set.GetCommand( k_shortcut_1 ).GetData(), command_1.GetData() )
     
     shortcut_set.SetCommand( k_shortcut_1, command_3 )
     
     self.assertEqual( shortcut_set.GetCommand( k_shortcut_1 ).GetData(), command_3.GetData() )
    def GetValue(self):

        service_key = self._service_keys.GetValue()

        if service_key is None:

            raise HydrusExceptions.VetoException(
                'Please select a rating service!')

        action = self._flip_or_set_action.GetValue()

        if self._ratings_like_like.isChecked():

            value = 1.0

        elif self._ratings_like_dislike.isChecked():

            value = 0.0

        else:

            value = None

        return CAC.ApplicationCommand(
            CAC.APPLICATION_COMMAND_TYPE_CONTENT,
            (service_key, HC.CONTENT_TYPE_RATINGS, action, value))
    def GetValue(self):

        service_key = self._service_keys.GetValue()

        if service_key is None:

            raise HydrusExceptions.VetoException(
                'Please select a rating service!')

        action = self._flip_or_set_action.GetValue()

        if self._ratings_numerical_remove.isChecked():

            rating = None

        else:

            value = self._ratings_numerical_slider.GetValue()

            rating = self._current_ratings_numerical_service.ConvertStarsToRating(
                value)

        return CAC.ApplicationCommand(
            CAC.APPLICATION_COMMAND_TYPE_CONTENT,
            (service_key, HC.CONTENT_TYPE_RATINGS, action, rating))
Exemplo n.º 5
0
 def GetValue( self ):
     
     action = self._simple_actions.GetValue()
     
     if action == '':
         
         raise HydrusExceptions.VetoException( 'Please select an action!' )
         
     else:
         
         return CAC.ApplicationCommand( CAC.APPLICATION_COMMAND_TYPE_SIMPLE, action )
Exemplo n.º 6
0
    def test_SERIALISABLE_TYPE_APPLICATION_COMMAND(self):
        def test(obj, dupe_obj):

            self.assertEqual(obj.GetCommandType(), dupe_obj.GetCommandType())

            self.assertSequenceEqual(tuple(obj._data), tuple(dupe_obj._data))

        acs = []

        acs.append((CAC.ApplicationCommand.STATICCreateSimpleCommand(
            CAC.SIMPLE_ARCHIVE_FILE), 'archive file'))
        acs.append((CAC.ApplicationCommand.STATICCreateSimpleCommand(
            CAC.SIMPLE_MEDIA_SEEK_DELTA,
            simple_data=(-1, 2500)), 'seek media (back 2.5 seconds)'))
        acs.append((CAC.ApplicationCommand.STATICCreateSimpleCommand(
            CAC.SIMPLE_MEDIA_SEEK_DELTA,
            simple_data=(1, 800)), 'seek media (forwards 800 milliseconds)'))
        acs.append((CAC.ApplicationCommand(
            CAC.APPLICATION_COMMAND_TYPE_CONTENT,
            (HydrusData.GenerateKey(), HC.CONTENT_TYPE_MAPPINGS,
             HC.CONTENT_UPDATE_FLIP, 'test')),
                    'flip on/off mappings "test" for unknown service!'))
        acs.append((CAC.ApplicationCommand(
            CAC.APPLICATION_COMMAND_TYPE_CONTENT,
            (CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_TYPE_MAPPINGS,
             HC.CONTENT_UPDATE_FLIP, 'test')),
                    'flip on/off mappings "test" for my tags'))
        acs.append(
            (CAC.ApplicationCommand(
                CAC.APPLICATION_COMMAND_TYPE_CONTENT,
                (HydrusData.GenerateKey(), HC.CONTENT_TYPE_RATINGS,
                 HC.CONTENT_UPDATE_SET, 0.4)),
             'set ratings uncertain rating, "0.4" for unknown service!'))

        for (ac, s) in acs:

            self._dump_and_load_and_test(ac, test)

            self.assertEqual(ac.ToString(), s)
Exemplo n.º 7
0
 def GetValue( self ):
     
     service_key = self._service_keys.GetValue()
     
     if service_key is None:
         
         raise HydrusExceptions.VetoException( 'Please select a service!' )
         
     
     action = self._add_or_move_action.GetValue()
     
     value = None
     
     return CAC.ApplicationCommand( CAC.APPLICATION_COMMAND_TYPE_CONTENT, ( service_key, HC.CONTENT_TYPE_FILES, action, value ) )
Exemplo n.º 8
0
 def GetValue( self ):
     
     service_key = self._service_keys.GetValue()
     
     if service_key is None:
         
         raise HydrusExceptions.VetoException( 'Please select a rating service!' )
         
     
     action = self._ratings_numerical_incdec.GetValue()
     
     distance = 1
     
     return CAC.ApplicationCommand( CAC.APPLICATION_COMMAND_TYPE_CONTENT, ( service_key, HC.CONTENT_TYPE_RATINGS, action, distance ) )
Exemplo n.º 9
0
 def GetValue( self ):
     
     service_key = self._service_keys.GetValue()
     
     if service_key is None:
         
         raise HydrusExceptions.VetoException( 'Please select a tag service!' )
         
     
     action = self._flip_or_set_action.GetValue()
     
     tag = self._tag_value.text()
     
     if tag == '':
         
         raise HydrusExceptions.VetoException( 'Please enter a tag!' )
         
     
     return CAC.ApplicationCommand( CAC.APPLICATION_COMMAND_TYPE_CONTENT, ( service_key, HC.CONTENT_TYPE_MAPPINGS, action, tag ) )
Exemplo n.º 10
0
    def AddShortcut(self):

        shortcut = ClientGUIShortcuts.Shortcut()
        command = CAC.ApplicationCommand()
        name = self._name.text()

        with ClientGUITopLevelWindowsPanels.DialogEdit(
                self, 'edit shortcut command') as dlg:

            panel = EditShortcutAndCommandPanel(dlg, shortcut, command, name)

            dlg.SetPanel(panel)

            if dlg.exec() == QW.QDialog.Accepted:

                (shortcut, command) = panel.GetValue()

                data = (shortcut, command)

                self._shortcuts.AddDatas((data, ))
Exemplo n.º 11
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')