示例#1
0
 def init_selection(self, value=None):
     if value is None:
         value = dict(
             (k, None)
             for k in self.attrs.get('selection_change_with') or [])
     key = freeze_value(value)
     selection = self.attrs.get('selection', [])[:]
     help_ = self.attrs.get('help_selection', {})
     if (not isinstance(selection, (list, tuple))
             and key not in self._values2selection):
         try:
             if self.attrs.get('selection_change_with'):
                 selection = RPCExecute('model', self.model_name, selection,
                                        value)
             else:
                 selection = RPCExecute('model', self.model_name, selection)
         except RPCException:
             selection = []
         self._values2selection[key] = selection
     elif key in self._values2selection:
         selection = self._values2selection[key]
     if self.attrs.get('sort', True):
         selection.sort(key=operator.itemgetter(1))
     self.selection = selection[:]
     self.help = help_
     self.inactive_selection = []
    def __init__(self, field_name, model_name, attrs=None):
        super(Reference, self).__init__(field_name, model_name, attrs=attrs)

        self.widget_combo = gtk.ComboBoxEntry()
        child = self.widget_combo.get_child()
        child.set_editable(False)
        child.connect('changed', self.sig_changed_combo)
        self.widget.pack_start(self.widget_combo, expand=False, fill=True)

        self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)

        self._selection = {}
        self._selection2 = {}
        selection = attrs.get('selection', [])
        if not isinstance(selection, (list, tuple)):
            try:
                selection = RPCExecute('model', self.model_name, selection)
            except RPCException:
                selection = []
        selection.sort(key=operator.itemgetter(1))
        if selection:
            pop = sorted((len(x) for x in selection), reverse=True)
            average = sum(pop) / len(pop)
            deviation = int(math.sqrt(sum((x - average) ** 2 for x in pop) /
                    len(pop)))
            width = max(next((x for x in pop if x < (deviation * 4)), 10), 10)
        else:
            width = 10
        child.set_width_chars(width)

        self.set_popdown(selection)

        self.widget.set_focus_chain([self.widget_combo, self.wid_text])
 def get_selection(self, props):
     try:
         selection = RPCExecute('model', self.model_name,
             props['selection'])
     except RPCException:
         selection = []
     selection.sort(lambda x, y: cmp(x[1], y[1]))
     return selection
 def init_selection(self):
     selection = self.attrs.get('selection', [])[:]
     if not isinstance(selection, (list, tuple)):
         try:
             selection = RPCExecute('model', self.model_name, selection)
         except RPCException:
             selection = []
     self.selection = selection[:]
     if self.attrs.get('sort', True):
         selection.sort(key=operator.itemgetter(1))
     self.set_popdown(selection)
示例#5
0
 def get_selection(self, props):
     try:
         change_with = props.get('selection_change_with')
         if change_with:
             selection = RPCExecute('model', self.model_name,
                 props['selection'], dict((p, None) for p in change_with))
         else:
             selection = RPCExecute('model', self.model_name,
                 props['selection'])
     except RPCException:
         selection = []
     selection.sort(lambda x, y: cmp(x[1], y[1]))
     return selection
示例#6
0
 def get_selection(self, props):
     try:
         change_with = props.get('selection_change_with')
         if change_with:
             selection = RPCExecute('model', self.model_name,
                 props['selection'], dict((p, None) for p in change_with))
         else:
             selection = RPCExecute('model', self.model_name,
                 props['selection'])
     except RPCException:
         selection = []
     selection.sort(lambda x, y: cmp(x[1], y[1]))
     return selection
 def __init__(self, field_name, model_name, treeview, attrs=None):
     super(Reference, self).__init__(field_name, model_name, treeview,
         attrs=attrs)
     self._selection = {}
     selection = attrs.get('selection', [])
     if not isinstance(selection, (list, tuple)):
         try:
             selection = RPCExecute('model', model_name, selection)
         except RPCException:
             selection = []
     selection.sort(key=operator.itemgetter(1))
     for i, j in selection:
         self._selection[i] = str(j)
 def __init__(self, *args):
     super(Selection, self).__init__(*args)
     self.renderer = CellRendererCombo()
     self.renderer.connect('editing-started', self.editing_started)
     self._last_domain = None
     self._domain_cache = {}
     selection = self.attrs.get('selection', [])[:]
     if not isinstance(selection, (list, tuple)):
         try:
             selection = RPCExecute('model', self.model_name, selection)
         except RPCException:
             selection = []
     self.selection = selection[:]
     if self.attrs.get('sort', True):
         selection.sort(key=operator.itemgetter(1))
     self.renderer.set_property('model', self.get_model(selection))
     self.renderer.set_property('text-column', 0)
示例#9
0
 def init_selection(self, key=None):
     if key is None:
         key = tuple(sorted((k, None)
                 for k in self.attrs.get('selection_change_with') or []))
     selection = self.attrs.get('selection', [])[:]
     if (not isinstance(selection, (list, tuple))
             and key not in self._values2selection):
         try:
             if key:
                 selection = RPCExecute('model', self.model_name, selection,
                     dict(key))
             else:
                 selection = RPCExecute('model', self.model_name, selection)
         except RPCException:
             selection = []
         self._values2selection[key] = selection
     elif key in self._values2selection:
         selection = self._values2selection[key]
     if self.attrs.get('sort', True):
         selection.sort(key=operator.itemgetter(1))
     self.selection = selection[:]
示例#10
0
 def init_selection(self, key=None):
     if key is None:
         key = tuple(sorted((k, None)
                 for k in self.attrs.get('selection_change_with') or []))
     selection = self.attrs.get('selection', [])[:]
     if (not isinstance(selection, (list, tuple))
             and key not in self._values2selection):
         try:
             if self.attrs.get('selection_change_with'):
                 selection = RPCExecute('model', self.model_name, selection,
                     dict(key))
             else:
                 selection = RPCExecute('model', self.model_name, selection)
         except RPCException:
             selection = []
         self._values2selection[key] = selection
     elif key in self._values2selection:
         selection = self._values2selection[key]
     if self.attrs.get('sort', True):
         selection.sort(key=operator.itemgetter(1))
     self.selection = selection[:]
     self.inactive_selection = []