Beispiel #1
0
    def get_option_changes(self, app):
        used = set()
        options = {}

        used.add('power')  # Don't set power here

        # Proxy options
        used.add('proxy')
        proxy_addr = get_widget_str_value(app.client_option_widgets['proxy'])
        proxy_port = get_widget_str_value(app.proxy_port)
        proxy = '%s:%s' % (proxy_addr, proxy_port)
        if self.get('proxy') != proxy:
            options['proxy'] = proxy

        # Core priority radio button
        used.add('core-priority')
        if app.client_option_widgets['core_priority'].get_active():
            if self.have('core-priority') and \
                    self.get('core-priority') != 'idle':
                options['core-priority'] = 'idle'
        elif self.get('core-priority') != 'low':
            options['core-priority'] = 'low'

        # Extra core options
        used.add('extra-core-args')
        if self.have('extra-core-args'):
            old_args = self.get('extra-core-args').split()
        else:
            old_args = []

        new_args = []

        def add_arg(model, path, iter, data):
            new_args.append(model.get(iter, 0)[0])

        app.core_option_list.foreach(add_arg, None)

        if old_args != new_args:
            if new_args:
                options['extra-core-args'] = ' '.join(new_args)
            else:
                options['extra-core-args!'] = None

        # Extra options
        def check_option(model, path, iter, data):
            name, value = model.get(iter, 0, 1)
            used.add(name)
            if self.get(name) != value:
                options[name] = value

        app.option_list.foreach(check_option, None)

        # Main options
        for name, widget in list(app.client_option_widgets.items()):
            name = name.replace('_', '-')
            if name in used:
                continue
            value = self.get(name)
            used.add(name)

            try:
                value = get_widget_str_value(widget)
                old_value = self.get(name)
                if value == '' and old_value is None:
                    value = None
                if value != old_value:
                    if value is None:
                        options[name + '!'] = None
                    else:
                        options[name] = value

            except Exception as e:  # Don't let one bad widget kill everything
                print('WARNING: failed to save widget "%s": %s' % (name, e))

        # Removed options
        for name in self.options:
            if name not in used:
                options[name + '!'] = None

        return options
    def get_option_changes(self, app):
        used = set()
        options = {}

        used.add('power') # Don't set power here

        # Proxy options
        used.add('proxy')
        proxy_addr = get_widget_str_value(app.client_option_widgets['proxy'])
        proxy_port = get_widget_str_value(app.proxy_port)
        proxy = '%s:%s' % (proxy_addr, proxy_port)
        if self.get('proxy') != proxy: options['proxy'] = proxy

        # Core priority radio button
        used.add('core-priority')
        if app.client_option_widgets['core_priority'].get_active():
            if self.have('core-priority') and \
                    self.get('core-priority') != 'idle':
                options['core-priority'] = 'idle'
        elif self.get('core-priority') != 'low':
            options['core-priority'] = 'low'

        # Extra core options
        used.add('extra-core-args')
        if self.have('extra-core-args'):
            old_args = self.get('extra-core-args').split()
        else: old_args = []

        new_args = []
        def add_arg(model, path, iter, data):
            new_args.append(model.get(iter, 0)[0])
        app.core_option_list.foreach(add_arg, None)

        if old_args != new_args:
            if new_args: options['extra-core-args'] = ' '.join(new_args)
            else: options['extra-core-args!'] = None

        # Extra options
        def check_option(model, path, iter, data):
            name, value = model.get(iter, 0, 1)
            used.add(name)
            if self.get(name) != value: options[name] = value

        app.option_list.foreach(check_option, None)

        # Main options
        for name, widget in app.client_option_widgets.items():
            name = name.replace('_', '-')
            if name in used: continue
            value = self.get(name)
            used.add(name)

            try:
                value = get_widget_str_value(widget)
                old_value = self.get(name)
                if value == '' and old_value is None: value = None
                if value != old_value:
                    if value is None: options[name + '!'] = None
                    else: options[name] = value

            except Exception, e: # Don't let one bad widget kill everything
                print 'WARNING: failed to save widget "%s": %s' % (name, e)