def _set_visual(self, cell, record): visual = record.expr_eval(self.attrs.get('visual')) if not visual: visual = record.expr_eval(self.view.attributes.get('visual')) background = COLORS.get(visual) if visual != 'muted' else None foreground = COLORS.get(visual) if visual == 'muted' else None cell.set_property('cell-background', background) if isinstance(cell, Gtk.CellRendererText): cell.set_property('foreground', foreground) cell.set_property('foreground-set', bool(foreground))
def color_set(self, name): self.color_name = name widget = self._color_widget() if not self.colors: style = widget.get_style() self.colors = { 'bg_color_active': style.bg[gtk.STATE_ACTIVE], 'bg_color_insensitive': style.bg[gtk.STATE_INSENSITIVE], 'base_color_normal': style.base[gtk.STATE_NORMAL], 'base_color_insensitive': style.base[gtk.STATE_INSENSITIVE], 'fg_color_normal': style.fg[gtk.STATE_NORMAL], 'fg_color_insensitive': style.fg[gtk.STATE_INSENSITIVE], 'text_color_normal': style.text[gtk.STATE_NORMAL], 'text_color_insensitive': style.text[gtk.STATE_INSENSITIVE], } if COLORS.get(name): colormap = widget.get_colormap() bg_color = colormap.alloc_color(COLORS.get(name, 'white')) fg_color = gtk.gdk.color_parse("black") widget.modify_bg(gtk.STATE_ACTIVE, bg_color) widget.modify_base(gtk.STATE_NORMAL, bg_color) widget.modify_fg(gtk.STATE_NORMAL, fg_color) widget.modify_text(gtk.STATE_NORMAL, fg_color) widget.modify_text(gtk.STATE_INSENSITIVE, fg_color) elif name == 'readonly': widget.modify_bg(gtk.STATE_ACTIVE, self.colors['bg_color_insensitive']) widget.modify_base(gtk.STATE_NORMAL, self.colors['base_color_insensitive']) widget.modify_fg(gtk.STATE_NORMAL, self.colors['fg_color_insensitive']) widget.modify_text(gtk.STATE_NORMAL, self.colors['text_color_normal']) widget.modify_text(gtk.STATE_INSENSITIVE, self.colors['text_color_normal']) else: widget.modify_bg(gtk.STATE_ACTIVE, self.colors['bg_color_active']) widget.modify_base(gtk.STATE_NORMAL, self.colors['base_color_normal']) widget.modify_fg(gtk.STATE_NORMAL, self.colors['fg_color_normal']) widget.modify_text(gtk.STATE_NORMAL, self.colors['text_color_normal']) widget.modify_text(gtk.STATE_INSENSITIVE, self.colors['text_color_normal'])
def setter(self, column, cell, store, iter_, user_data=None): record = store.get_value(iter_, 0) text = self.get_textual_value(record) if isinstance(cell, CellRendererToggle): cell.set_active(bool(text)) else: cell.set_sensitive(not (record.deleted or record.removed)) if isinstance( cell, (CellRendererText, CellRendererDate, CellRendererCombo)): cell.set_property('strikethrough', record.deleted) cell.set_property('text', text) fg_color = self.get_color(record) cell.set_property('foreground', fg_color) if fg_color == 'black': cell.set_property('foreground-set', False) else: cell.set_property('foreground-set', True) field = record[self.attrs['name']] editable = getattr(self.view.treeview, 'editable', False) states = ('invisible', ) if editable: states = ('readonly', 'required', 'invisible') field.state_set(record, states=states) invisible = field.get_state_attrs(record).get('invisible', False) cell.set_property('visible', not invisible) # Sometimes, the treeview with fixed height mode computes a too big # height for not visible cell with text # We can force an empty text because not visible cell can not be edited # and so value_from_text is never called. if invisible and not isinstance(cell, CellRendererToggle): cell.set_property('text', '') if editable: readonly = self.attrs.get( 'readonly', field.get_state_attrs(record).get('readonly', False)) if invisible: readonly = True if not isinstance(cell, CellRendererToggle): bg_color = 'white' if field.get_state_attrs(record).get('invalid', False): bg_color = COLORS.get('invalid', 'white') elif bool(int( field.get_state_attrs(record).get('required', 0))): bg_color = COLORS.get('required', 'white') cell.set_property('background', bg_color) if bg_color == 'white': cell.set_property('background-set', False) else: cell.set_property('background-set', True) cell.set_property('foreground-set', not (record.deleted or record.removed)) if isinstance(cell, CellRendererToggle): cell.set_property('activatable', not readonly) elif isinstance(cell, (Gtk.CellRendererProgress, CellRendererButton, Gtk.CellRendererPixbuf)): pass else: cell.set_property('editable', not readonly) else: if isinstance(cell, CellRendererToggle): cell.set_property('activatable', False) # ABD See #3428 self._format_set(record, field, cell) cell.set_property('xalign', self.align)
def setter(self, column, cell, store, iter): record = store.get_value(iter, 0) text = self.get_textual_value(record) if isinstance(cell, CellRendererToggle): cell.set_active(bool(text)) else: cell.set_sensitive(not (record.deleted or record.removed)) if isinstance( cell, (CellRendererText, CellRendererDate, CellRendererCombo)): cell.set_property('strikethrough', record.deleted) cell.set_property('text', text) fg_color = self.get_color(record) cell.set_property('foreground', fg_color) if fg_color == 'black': cell.set_property('foreground-set', False) else: cell.set_property('foreground-set', True) field = record[self.attrs['name']] if self.attrs.get('type', field.attrs.get('type')) in \ ('float', 'integer', 'biginteger', 'boolean', 'numeric', 'timedelta'): align = 1 else: align = 0 editable = getattr(self.view.treeview, 'editable', False) states = ('invisible', ) if editable: states = ('readonly', 'required', 'invisible') field.state_set(record, states=states) invisible = field.get_state_attrs(record).get('invisible', False) cell.set_property('visible', not invisible) if editable: readonly = self.attrs.get( 'readonly', field.get_state_attrs(record).get('readonly', False)) if invisible: readonly = True if not isinstance(cell, CellRendererToggle): bg_color = 'white' if field.get_state_attrs(record).get('invalid', False): bg_color = COLORS.get('invalid', 'white') elif bool(int( field.get_state_attrs(record).get('required', 0))): bg_color = COLORS.get('required', 'white') cell.set_property('background', bg_color) if bg_color == 'white': cell.set_property('background-set', False) else: cell.set_property('background-set', True) cell.set_property('foreground-set', not (record.deleted or record.removed)) if isinstance(cell, CellRendererToggle): cell.set_property('activatable', not readonly) elif isinstance(cell, (gtk.CellRendererProgress, CellRendererButton, gtk.CellRendererPixbuf)): pass else: cell.set_property('editable', not readonly) else: if isinstance(cell, CellRendererToggle): cell.set_property('activatable', False) self._format_set(record, field, cell) cell.set_property('xalign', align)
def setter(self, column, cell, store, iter): record = store.get_value(iter, 0) text = self.get_textual_value(record) if isinstance(cell, CellRendererToggle): cell.set_active(bool(text)) else: cell.set_sensitive(not (record.deleted or record.removed)) if isinstance(cell, (CellRendererText, CellRendererDate, CellRendererCombo)): cell.set_property('strikethrough', record.deleted) cell.set_property('text', text) fg_color = self.get_color(record) cell.set_property('foreground', fg_color) if fg_color == 'black': cell.set_property('foreground-set', False) else: cell.set_property('foreground-set', True) field = record[self.field_name] if self.attrs.get('type', field.attrs.get('type')) in \ ('float', 'integer', 'biginteger', 'boolean', 'numeric', 'float_time'): align = 1 else: align = 0 states = ('invisible',) if hasattr(self.treeview, 'editable') \ and self.treeview.editable: states = ('readonly', 'required', 'invisible') field.state_set(record, states=states) invisible = field.get_state_attrs(record).get('invisible', False) cell.set_property('visible', not invisible) if hasattr(self.treeview, 'editable') \ and self.treeview.editable: readonly = field.get_state_attrs(record).get('readonly', False) if invisible: readonly = True if not isinstance(cell, CellRendererToggle): bg_color = 'white' if not field.get_state_attrs(record).get('valid', True): bg_color = COLORS.get('invalid', 'white') elif bool(int( field.get_state_attrs(record).get('required', 0))): bg_color = COLORS.get('required', 'white') cell.set_property('background', bg_color) if bg_color == 'white': cell.set_property('background-set', False) else: cell.set_property('background-set', True) cell.set_property('foreground-set', not (record.deleted or record.removed)) if isinstance(cell, CellRendererToggle): cell.set_property('activatable', not readonly) elif isinstance(cell, (gtk.CellRendererProgress, CellRendererButton)): pass else: cell.set_property('editable', not readonly) cell.set_property('xalign', align)