コード例 #1
0
    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(
            (ClientData.ApplicationCommand(CC.APPLICATION_COMMAND_TYPE_SIMPLE,
                                           'archive_file'), 'archive_file'))
        acs.append((ClientData.ApplicationCommand(
            CC.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((ClientData.ApplicationCommand(
            CC.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((ClientData.ApplicationCommand(
            CC.APPLICATION_COMMAND_TYPE_CONTENT,
            (HydrusData.GenerateKey(), HC.CONTENT_TYPE_RATINGS,
             HC.CONTENT_UPDATE_SET, 0.4)),
                    'set ratings "0.4" for unknown service!'))

        for (ac, s) in acs:

            self._dump_and_load_and_test(ac, test)

            self.assertEqual(ac.ToString(), s)
コード例 #2
0
 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 = ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_SIMPLE, 'archive_file' )
     command_2 = ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, ( HydrusData.GenerateKey(), HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test' ) )
     command_3 = ClientData.ApplicationCommand( CC.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() )
コード例 #3
0
    def _GetRatingsLike(self):

        selection = self._ratings_like_service_keys.currentIndex()

        if selection != -1:

            service_key = QP.GetClientData(self._ratings_like_service_keys,
                                           selection)

            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 ClientData.ApplicationCommand(
                CC.APPLICATION_COMMAND_TYPE_CONTENT,
                (service_key, HC.CONTENT_TYPE_RATINGS, action, value))

        else:

            raise HydrusExceptions.VetoException(
                'Please select a rating service!')
コード例 #4
0
    def _GetSimple(self):

        action = self._simple_actions.currentText()

        if action == '':

            raise HydrusExceptions.VetoException('Please select an action!')

        else:

            return ClientData.ApplicationCommand(
                CC.APPLICATION_COMMAND_TYPE_SIMPLE, action)
コード例 #5
0
    def AddShortcut(self):

        shortcut = ClientGUIShortcuts.Shortcut()
        command = ClientData.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, ))
コード例 #6
0
    def _GetRatingsNumericalIncDec(self):

        selection = self._ratings_numerical_incdec_service_keys.currentIndex()

        if selection != -1:

            service_key = QP.GetClientData(
                self._ratings_numerical_incdec_service_keys, selection)

            action = self._ratings_numerical_incdec.GetValue()

            value = 1

            return ClientData.ApplicationCommand(
                CC.APPLICATION_COMMAND_TYPE_CONTENT,
                (service_key, HC.CONTENT_TYPE_RATINGS, action, value))

        else:

            raise HydrusExceptions.VetoException(
                'Please select a rating service!')
コード例 #7
0
    def _GetRatingsNumerical(self):

        selection = self._ratings_numerical_service_keys.currentIndex()

        if selection != -1:

            service_key = QP.GetClientData(
                self._ratings_numerical_service_keys, selection)

            action = self._flip_or_set_action.GetValue()

            if self._ratings_numerical_remove.isChecked():

                value = None

            else:

                value = self._ratings_numerical_slider.GetValue()

                num_stars = self._current_ratings_numerical_service.GetNumStars(
                )
                allow_zero = self._current_ratings_numerical_service.AllowZero(
                )

                if allow_zero:

                    value = value / num_stars

                else:

                    value = (value - 1) / (num_stars - 1)

            return ClientData.ApplicationCommand(
                CC.APPLICATION_COMMAND_TYPE_CONTENT,
                (service_key, HC.CONTENT_TYPE_RATINGS, action, value))

        else:

            raise HydrusExceptions.VetoException(
                'Please select a rating service!')
コード例 #8
0
    def _GetTag(self):

        selection = self._tag_service_keys.currentIndex()

        if selection != -1:

            service_key = QP.GetClientData(self._tag_service_keys, selection)

            action = self._flip_or_set_action.GetValue()

            value = self._tag_value.text()

            if value == '':

                raise HydrusExceptions.VetoException('Please enter a tag!')

            return ClientData.ApplicationCommand(
                CC.APPLICATION_COMMAND_TYPE_CONTENT,
                (service_key, HC.CONTENT_TYPE_MAPPINGS, action, value))

        else:

            raise HydrusExceptions.VetoException(
                'Please select a tag service!')
コード例 #9
0
    def _UpdateSerialisableInfo(self, version, old_serialisable_info):

        if version == 1:

            (serialisable_mouse_actions,
             serialisable_keyboard_actions) = old_serialisable_info

            shortcuts_to_commands = {}

            # this never stored mouse actions, so skip

            services_manager = HG.client_controller.services_manager

            for (modifier, key, (serialisable_service_key,
                                 data)) in serialisable_keyboard_actions:

                # no longer updating modifier, as that was wx legacy

                modifiers = []

                shortcut = Shortcut(SHORTCUT_TYPE_KEYBOARD_CHARACTER, key,
                                    SHORTCUT_PRESS_TYPE_PRESS, modifiers)

                if serialisable_service_key is None:

                    command = ClientData.ApplicationCommand(
                        CC.APPLICATION_COMMAND_TYPE_SIMPLE, data)

                else:

                    service_key = bytes.fromhex(serialisable_service_key)

                    if not services_manager.ServiceExists(service_key):

                        continue

                    action = HC.CONTENT_UPDATE_FLIP

                    value = data

                    service = services_manager.GetService(service_key)

                    service_type = service.GetServiceType()

                    if service_type in HC.REAL_TAG_SERVICES:

                        content_type = HC.CONTENT_TYPE_MAPPINGS

                    elif service_type in HC.RATINGS_SERVICES:

                        content_type = HC.CONTENT_TYPE_RATINGS

                    else:

                        continue

                    command = ClientData.ApplicationCommand(
                        CC.APPLICATION_COMMAND_TYPE_CONTENT,
                        (service_key, content_type, action, value))

                shortcuts_to_commands[shortcut] = command

            new_serialisable_info = (
                (shortcut.GetSerialisableTuple(),
                 command.GetSerialisableTuple())
                for (shortcut, command) in list(shortcuts_to_commands.items()))

            return (2, new_serialisable_info)