~osomon/moovida/upicek_language_option_screen

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/poblesec/configuration/option_screen.py

 Merge the latest changes to the configuration wizard infrastructure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    """
34
34
    Base controller for an option screen used for configuration.
35
35
 
 
36
    It may be used either as a step of a configuration wizard, or as a
 
37
    standalone option screen controller.
 
38
 
36
39
    An option screen may use a backend to populate its data, retrieve the
37
40
    current state of the configuration and save the new state back to the
38
41
    configuration.
39
 
    Initial population should be implemented in the L{setup} method.
 
42
    Initial population should be implemented in the L{setup} method (and this
 
43
    method should be explicitely called after the initialization of the screen
 
44
    is done, this is not done automatically).
40
45
    Saving back the new state of the configuration should be implemented in the
41
46
    L{save} method.
 
47
 
 
48
    @cvar actions:    a list of possible actions
 
49
    @type actions:    C{list} of C{str}
 
50
    @ivar standalone: whether the screen is standalone or part of a wizard
 
51
    @type standalone: C{bool}
42
52
    """
43
53
 
44
 
    # The 'closed' signal is emitted when the screen is closed, with a boolean
45
 
    # parameter indicating whether the new state of the configuration has been
46
 
    # saved.
 
54
    # The 'closed' signal is emitted when the screen is closed, with a string
 
55
    # parameter for the action selected by the user.
47
56
    __gsignals__ = {'closed': (gobject.SIGNAL_RUN_LAST,
48
57
                               gobject.TYPE_NONE,
49
 
                               (gobject.TYPE_BOOLEAN,)),
 
58
                               (gobject.TYPE_STRING,)),
50
59
                   }
51
60
 
 
61
    # Default actions. Override if needed.
 
62
    actions = ['prev', 'next']
 
63
 
 
64
    def __init__(self):
 
65
        super(OptionScreen, self).__init__()
 
66
        self.standalone = True
 
67
 
52
68
    def setup(self):
53
69
        """
54
70
        Set up the screen (i.e. retrieve the current state of the configuration
59
75
        """
60
76
        return defer.fail(NotImplementedError())
61
77
 
62
 
    def close(self, save=False):
 
78
    def close(self, action, save=False):
63
79
        """
64
80
        Close the configuration screen, and optionally save back the new state
65
81
        of the configuration.
66
82
 
67
 
        @param save: whether to save the new state of the configuration
68
 
        @type save:  C{bool}
 
83
        @param action: the action chosen by the user
 
84
        @type action:  C{str}
 
85
        @param save:   whether to save the new state of the configuration
 
86
        @type save:    C{bool}
69
87
        """
70
88
        if save:
71
89
            self.save()
72
 
        self.emit('closed', save)
 
90
 
 
91
        if action not in self.actions:
 
92
            msg = "Unknown action: '%s'" % action
 
93
            raise KeyError(msg)
 
94
 
 
95
        self.emit('closed', action)
73
96
 
74
97
    def save(self):
75
98
        """
84
107
 
85
108
        Save the new configuration and close the screen.
86
109
        """
87
 
        self.close(save=True)
 
110
        self.close('next', True)
88
111
 
89
112
    def handle_input_cancel(self):
90
113
        """
92
115
 
93
116
        Close the screen without altering the current configuration.
94
117
        """
95
 
        self.close(save=False)
 
118
        self.close('prev', False)
 
119
 
 
120
    def go_back(self):
 
121
        """
 
122
        In standalone mode, go up one level in the history of controllers.
 
123
 
 
124
        @attention: should not be called when not in standalone mode.
 
125
        """
 
126
        browser = self.frontend.retrieve_controllers('/poblesec/browser')[0]
 
127
        browser.history.go_back()
96
128
 
97
129
    def handle_input(self, manager, input_event):
98
130
        if input_event.value in (EventValue.KEY_OK, EventValue.KEY_RETURN):
99
131
            self.handle_input_ok()
 
132
            if self.standalone:
 
133
                self.go_back()
100
134
            return True
101
135
        elif input_event.value == EventValue.KEY_MENU:
102
136
            self.handle_input_cancel()
103
 
            return True
 
137
            return not self.standalone
104
138
        return super(OptionScreen, self).handle_input(manager, input_event)