else: if self.props.mandatory and self.get_text() == "": self.emit("validation-changed", True) # set_value accepts a float or int, no as_string conversion needed, # and since we accept only int and float just send it in. self.set_value(data) # Old IconEntry API def set_tooltip(self, text): self.set_property("primary-icon-tooltip-text", text) def set_pixbuf(self, pixbuf): # Spinbuttons are always right aligned self.set_property("primary-icon-pixbuf", pixbuf) def update_background(self, color): self.modify_base(gtk.STATE_NORMAL, color) def get_background(self): return self.style.base[gtk.STATE_NORMAL] class SpinButton(ProxySpinButton): def __init__(self): deprecationwarn("SpinButton is deprecated, use ProxySpinButton instead", stacklevel=3) ProxySpinButton.__init__(self) type_register(SpinButton)
# See #3099 for an explanation why this is needed and a # testcase tmodel = model.get_model() if tmodel.iter_is_valid(treeiter): # revert back to the unfiltered model so we can select # the right object self._treeview.set_model(tmodel) self._selection = self._treeview.get_selection() else: treeiter = model.convert_child_iter_to_iter(treeiter) self._selection.select_iter(treeiter) def set_details_callback(self, callable): self._renderer.set_details_callback(callable) type_register(_ComboEntryPopup) class ComboEntry(gtk.VBox): implements(IEasyCombo) gsignal('changed') gsignal('activate') def __init__(self, entry=None): """ Create a new ComboEntry object. @param entry: a gtk.Entry subclass to use """ gtk.VBox.__init__(self) self._popping_down = False
def read(self): button = self.get_selected() if button is None: return ValueUnset return self._from_string(button.data_value) def update(self, data): if data is None or data is ValueUnset: # In a group of radiobuttons, the only widget which is in # the proxy is ourself, the other buttons do not get their # update() method called, so the default value is activate # ourselves when the model is empty self.set_active(True) return data = self._as_string(data) for rb in self.get_group(): if rb.get_property('data-value') == data: rb.set_active(True) class RadioButton(ProxyRadioButton): def __init__(self): deprecationwarn( 'RadioButton is deprecated, use ProxyRadioButton instead', stacklevel=3) ProxyRadioButton.__init__(self) type_register(RadioButton)
Called when the mouse pinter enters or leaves the widget. :param hover: Whether the mouse has entered the widget. :type hover: boolean """ self._is_hover = hover self._update_look() def _on_notify(self, eventbox, param): """ Called on property notification. Ensure that the look is up to date with the properties """ if (param.name == 'text' or param.name.endswith('-color') or param.name.endswith('-underline') or param.name.endswith('-bold')): self._update_look() def _on_map_event(self, eventbox, event): """ Called on initially mapping the widget. Used here to set the cursor type. """ cursor = gtk.gdk.Cursor(gtk.gdk.HAND1) self.window.set_cursor(cursor) type_register(HyperLink)
self._has_been_updated = False elif data is None: self.set_text("") else: mode = self._mode if mode == ENTRY_MODE_DATA: new = self._get_text_from_object(data) if new is None: raise TypeError("%r is not a data object" % data) text = new elif mode == ENTRY_MODE_TEXT: text = self._as_string(data) self.set_text(text) type_register(ProxyEntry) class Entry(ProxyEntry): def __init__(self, data_type=None): deprecationwarn('Entry is deprecated, use ProxyEntry instead', stacklevel=3) ProxyEntry.__init__(self, data_type) type_register(Entry) class ProxyDateEntry(DateEntry, ValidatableProxyWidgetMixin): __gtype_name__ = 'ProxyDateEntry'
return properties[prop_name] prop = self._create_prop(prop_name, child) properties[prop_name] = prop return prop def select(self): """ Select this widget, i.e. clear the current selection and add the widget. """ self.project.selection.set(self.widget) def to_xml(self): from gazpacho.filewriter import XMLWriter xw = XMLWriter(project=self.project) return xw.serialize(self) def get_children(self): """ Get a list of children for the gadget. Note that an adaptor can override the behavior so this should be used instead of widget.get_children() directly @returns: list of children """ return self.adaptor.get_children(self.project.context, self.widget) type_register(Gadget)
gsignal('content-changed') gsignal('validation-changed', bool) gsignal('validate', object, retval=object) allowed_data_types = (basestring, ) def __init__(self, color=gtk.gdk.Color(0, 0, 0)): ProxyWidgetMixin.__init__(self) gtk.ColorButton.__init__(self, color) gsignal('color-set', 'override') def do_color_set(self): self.emit('content-changed') self.chain() def read(self): color = self.get_color() return self._from_string( '#%02x%02x%02x' % (color.red / 256, color.green / 256, color.blue / 256)) def update(self, data): if data is ValueUnset or data is None: data = 'black' color = gtk.gdk.color_parse(data) self.set_color(color) type_register(ProxyColorButton)
import gtk from kiwi.ui.proxywidget import ProxyWidgetMixin from kiwi.utils import gsignal, type_register class ProxyFontButton(gtk.FontButton, ProxyWidgetMixin): __gtype_name__ = 'ProxyFontButton' allowed_data_types = basestring, def __init__(self, fontname=None): ProxyWidgetMixin.__init__(self) gtk.FontButton.__init__(self, fontname) self.props.data_type = str gsignal('font-set', 'override') def do_font_set(self): self.emit('content-changed') self.chain() def read(self): return self.get_font_name() def update(self, data): self.set_font_name(data) type_register(ProxyFontButton)
"""Sets the date. @param date: date to set @type date: a datetime.date instance or None """ if not isinstance(date, datetime.date) and date is not None: raise TypeError( "date must be a datetime.date instance or None, not %r" % (date, )) if date is None: value = '' else: value = date_converter.as_string(date) self.entry.set_text(value) def get_date(self): """Get the selected date @returns: the date. @rtype: datetime.date or None """ try: date = self.entry.read() except ValidationError: date = None if date == ValueUnset: date = None return date type_register(DateEntry)
button = self.get_selected() if button is None: return ValueUnset return self._from_string(button.data_value) def update(self, data): if data is None or data is ValueUnset: # In a group of radiobuttons, the only widget which is in # the proxy is ourself, the other buttons do not get their # update() method called, so the default value is activate # ourselves when the model is empty self.set_active(True) return data = self._as_string(data) for rb in self.get_group(): if rb.get_property('data-value') == data: rb.set_active(True) class RadioButton(ProxyRadioButton): def __init__(self): deprecationwarn( 'RadioButton is deprecated, use ProxyRadioButton instead', stacklevel=3) ProxyRadioButton.__init__(self) type_register(RadioButton)
def display(self, gadget): "Display a widget in the editor" self._set_visible(True) # Skip widget if it's already loaded or None if self._loaded_gadget == gadget or not gadget: return self._load_gadget(gadget) def refresh(self, prop_name=None): """Reread properties and update the editor If prop_name is given only refresh that property editor """ if not self._loaded_gadget: return if prop_name: for widget_property in self._widget_properties: if widget_property.property_class.name == prop_name: widget_property.load(self._loaded_gadget) else: self._load_gadget(self._loaded_gadget) def get_loaded_gadget(self): return self._loaded_gadget type_register(Editor)
@param widget: the gtk widget @type widget: gtk.Widget """ self._gtk_sizegroup.add_widget(widget) def _remove_widget(self, widget): """ Remove a gtk widget from the gtk SizeGroup. @param widget: the gtk widget @type widget: gtk.Widget """ self._gtk_sizegroup.remove_widget(widget) type_register(GSizeGroup) def safe_to_add_gadgets(sizegroup, gadgets): """ Test if it is safe to add the gadgets to the sizegroup. Gadgets who has an ancestor or child in the sizegroup cannot be added. @param sizegroup: the size group @type sizegroup: L{gazpacho.sizegroup.GSizeGroup} """ all_gadgets = sizegroup.get_gadgets() + gadgets # Create gadget parent cache parents = {} for gadget in all_gadgets:
# Instantiate the property from the property type return prop_type(self) def _internal_get_prop(self, prop_name, child): if child: properties = self.child_properties else: properties = self.properties if prop_name in properties: return properties[prop_name] prop = self._create_prop(prop_name, child) properties[prop_name] = prop return prop type_register(BaseGadget) # XXX: Rename/Move to WidgetGadget class Gadget(BaseGadget): """ A wrapper around a gtk.Widget. Adds DND handlers and annotations. @ivar dnd_gadget: DND the widget that should be dragged (not necessarily this one) """ def __init__(self, adaptor, project): BaseGadget.__init__(self, adaptor, project) self._dnd_drop_region = None
"Display a widget in the editor" self._set_visible(True) # Skip widget if it's already loaded or None if self._loaded_gadget == gadget or not gadget: return self._load_gadget(gadget) def refresh(self, prop_name=None): """Reread properties and update the editor If prop_name is given only refresh that property editor """ if not self._loaded_gadget: return if prop_name: for widget_property in self._widget_properties: if widget_property.property_class.name == prop_name: widget_property.load(self._loaded_gadget) else: self._load_gadget(self._loaded_gadget) def get_loaded_gadget(self): return self._loaded_gadget type_register(PropertyEditor)
else: # set_value accepts a float or int, no as_string conversion needed, # and since we accept only int and float just send it in. self.set_value(data) # Old IconEntry API def set_tooltip(self, text): self.set_property('primary-icon-tooltip-text', text) def set_pixbuf(self, pixbuf): # Spinbuttons are always right aligned self.set_property('primary-icon-pixbuf', pixbuf) def update_background(self, color): self.modify_base(gtk.STATE_NORMAL, color) def get_background(self): return self.style.base[gtk.STATE_NORMAL] class SpinButton(ProxySpinButton): def __init__(self): deprecationwarn( 'SpinButton is deprecated, use ProxySpinButton instead', stacklevel=3) ProxySpinButton.__init__(self) type_register(SpinButton)
def register_validate_function(self, function): """The signature of the validate function is: def function(is_valid): or, if it is a method: def function(self, is_valid): where the 'is_valid' parameter is True if all the widgets have valid data or False otherwise. """ self._validate_function = function type_register(SlaveView) class BaseView(SlaveView): """A view with a toplevel window.""" def __init__(self, toplevel=None, widgets=None, gladefile=None, toplevel_name=None, domain=None, delete_handler=None): SlaveView.__init__(self, toplevel, widgets, gladefile, toplevel_name, domain) if not isinstance(self.toplevel, (gtk.Window, gtk.Dialog)): raise TypeError("toplevel widget must be a Window " "(or inherit from it),\nfound `%s' %s" % (toplevel, self.toplevel)) self.toplevel.set_name(self.__class__.__name__)
def read(self): if self._is_unset: return ValueUnset textbuffer = self._textbuffer data = textbuffer.get_text(textbuffer.get_start_iter(), textbuffer.get_end_iter()) return self._from_string(data) def update(self, data): if data is ValueUnset: self._textbuffer.set_text("") self._is_unset = True return elif data is None: text = "" else: self.is_unset = False text = self._as_string(data) self._textbuffer.set_text(text) class TextView(ProxyTextView): def __init__(self): deprecationwarn('TextView is deprecated, use ProxyTextView instead', stacklevel=3) ProxyTextView.__init__(self) type_register(TextView)
@type size: string """ if (size is not None and size not in self._size_list): raise ValueError('Size of "%s" label is not valid' % self.get_text()) self._attr_dic["size"] = size self._apply_attributes() def set_text(self, text): """ Overrides gtk.Label set_text method. Sets the new text of the label but keeps the formating @param text: label @type text: string """ gtk.Label.set_text(self, text) self._apply_attributes() def set_color(self, color): set_foreground(self, color) type_register(ProxyLabel) class Label(ProxyLabel): def __init__(self, label='', data_type=None): deprecationwarn( 'Label is deprecated, use ProxyLabel instead', stacklevel=3) ProxyLabel.__init__(self, label=label, data_type=data_type) type_register(Label)
self._activate_selected_item() class _MultiComboCloseButton(Gtk.Button): __gtype_name__ = 'MultiComboCloseButton' def __init__(self, **kwargs): super(_MultiComboCloseButton, self).__init__(**kwargs) self.set_relief(Gtk.ReliefStyle.NONE) image = Gtk.Image.new_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU) self.add(image) type_register(_MultiComboCloseButton) class MultiCombo(Gtk.Box): """Multi selection combo. Just like a combo entry, but allows multiple items to be selected at the same time. Inspired by react-select:: http://jedwatson.github.io/react-select/ """ gsignal('item-added', object)
return False if self._countdown_timeout_id != -1: self._log.debug('start: Countdown already running') return False if self._done: self._log.debug('start: Not running, already set') return False self._start_color = color self._log.debug('start: Scheduling') self._countdown_timeout_id = gobject.timeout_add( FadeOut.COMPLAIN_DELAY, self._start_merging) return True def stop(self): """Stops the fadeout and restores the background color""" self._log.debug('Stopping') if self._background_timeout_id != -1: gobject.source_remove(self._background_timeout_id) self._background_timeout_id = -1 if self._countdown_timeout_id != -1: gobject.source_remove(self._countdown_timeout_id) self._countdown_timeout_id = -1 self._widget.update_background(self._start_color) self._done = False type_register(FadeOut)
self._stock.set_active_iter(row.iter) break else: raise AssertionError preview = stock_id self._stock.child.set_text(stock_id) self._preview.set_from_stock(preview, gtk.ICON_SIZE_BUTTON) def get_stock_id(self): """ @returns: the current stock id """ return self._stock.child.get_text() type_register(StockIconList) class StockIconDialog(BaseDialog): def __init__(self, parent=None): BaseDialog.__init__(self, parent, title=_('Stock Icons'), buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) self.set_size_request(260, 330) self._stockicons = ObjectList([Column('stock_id', use_stock=True), Column('name')]) self._stockicons.set_headers_visible(False) self._stockicons.connect('row-activated', self._on_stockicons__row_activated) self._icons = {} for stock_label, stock_id in get_stock_icons():
:param mode: one of :mod:`ENTRY_MODE_TEXT` or :mod:`ENTRY_MODE_DATA` """ if mode not in [ENTRY_MODE_TEXT, ENTRY_MODE_DATA]: raise TypeError("mode should be ENTRY_MODE_TEXT or " "ENTRY_MODE_DATA, got %r" % (mode, )) self._mode = mode def get_mode(self): """Returns the actual entry mode :returns: one of :mod:`ENTRY_MODE_TEXT` or :mod:`ENTRY_MODE_DATA` """ return self._mode type_register(KiwiEntry) if __name__ == '__main__': win = Gtk.Window() win.set_title('Gtk.Entry subclass') def cb(window, event): Gtk.main_quit() win.connect('delete-event', cb) widget = KiwiEntry() #widget.set_mask('000.000.000.000') widget.set_mask('(00) 0000-0000') win.add(widget)
def register_validate_function(self, function): """The signature of the validate function is: def function(is_valid): or, if it is a method: def function(self, is_valid): where the 'is_valid' parameter is True if all the widgets have valid data or False otherwise. """ self._validate_function = function type_register(SlaveView) class BaseView(SlaveView): """A view with a toplevel window.""" def __init__(self, toplevel=None, widgets=None, gladefile=None, toplevel_name=None, domain=None, delete_handler=None): SlaveView.__init__(self, toplevel, widgets, gladefile, toplevel_name, domain) if not isinstance(self.toplevel, (gtk.Window, gtk.Dialog)):
return True def stop(self): """Stops the fadeout and restores the background color""" self._log.debug('Stopping') if self._background_timeout_id != -1: gobject.source_remove(self._background_timeout_id) self._background_timeout_id = -1 if self._countdown_timeout_id != -1: gobject.source_remove(self._countdown_timeout_id) self._countdown_timeout_id = -1 self._widget.update_background(self._start_color) self._done = False type_register(FadeOut) _pixbuf_cache = {} # Based on code from BillReminder by Og Maciel and # http://cairographics.org/cookbook/roundedrectangles/ def render_pixbuf(color_name, width=16, height=16, radius=4): pixbuf = _pixbuf_cache.get(color_name) if pixbuf is not None: return pixbuf surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) cr = cairo.Context(surface)
def set_date(self, date): """Sets the date. @param date: date to set @type date: a datetime.date instance or None """ if not isinstance(date, datetime.date) and date is not None: raise TypeError( "date must be a datetime.date instance or None, not %r" % ( date,)) if date is None: value = '' else: value = date_converter.as_string(date) self.entry.set_text(value) def get_date(self): """Get the selected date @returns: the date. @rtype: datetime.date or None """ try: date = self.entry.read() except ValidationError: date = None if date == ValueUnset: date = None return date type_register(DateEntry)
) model_attribute = gobject.property(type=str, blurb="Model attribute") gsignal("content-changed") gsignal("validation-changed", bool) gsignal("validate", object, retval=object) allowed_data_types = (basestring,) def __init__(self, color=gtk.gdk.Color(0, 0, 0)): ProxyWidgetMixin.__init__(self) gtk.ColorButton.__init__(self, color) gsignal("color-set", "override") def do_color_set(self): self.emit("content-changed") self.chain() def read(self): color = self.get_color() return self._from_string("#%02x%02x%02x" % (color.red / 256, color.green / 256, color.blue / 256)) def update(self, data): if data is ValueUnset or data is None: data = "black" color = gtk.gdk.color_parse(data) self.set_color(color) type_register(ProxyColorButton)
y, m, d = self.calendar.get_date() return datetime.date(y, m + 1, d) def set_date(self, date): """Sets the date of the date entry :param date: date to set :type date: datetime.date """ self.calendar.select_month(date.month - 1, date.year) self.calendar.select_day(date.day) # FIXME: Only mark the day in the current month? self.calendar.clear_marks() self.calendar.mark_day(date.day) type_register(_DateEntryPopup) class DateEntry(Gtk.Box): """I am an entry which you can input a date on. In addition to an Gtk.Entry I also contain a button with an arrow you can click to get popup window with a Gtk.Calendar for which you can use to select the date """ gsignal('changed') gsignal('activate') def __init__(self): super(DateEntry, self).__init__(orientation=Gtk.Orientation.HORIZONTAL) self.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED)
if not project.selection: return xml = project.serialize() builder = ObjectBuilder(buffer=xml) toplevel = project.selection[0].get_toplevel() widget = builder.get_widget(toplevel.get_name()) widget.show_all() # Help action callbacks def _about_cb(self, action): about = gtk.AboutDialog() about.set_name('Gazpacho') about.set_version(__version__) authorsfile = file(environ.find_resource('doc', 'AUTHORS')) authors = [a.strip() for a in authorsfile.readlines()] authors.append('') # separate authors from contributors contributorsfile = file(environ.find_resource('doc', 'CONTRIBUTORS')) authors.extend([c.strip() for c in contributorsfile.readlines()[:-2]]) about.set_authors(authors) license = file('/usr/share/common-licenses/LGPL-2').read() about.set_license(license) about.set_website('http://gazpacho.sicem.biz') about.run() about.destroy() # Do not add anything here, add it above in the appropriate section type_register(Application)
ProxyWidgetMixin.__init__(self) MultiCombo.__init__(self, **kwargs) self.connect('item-added', self._on_combo__item_added) self.connect('item-removed', self._on_combo__item_removed) # # ProxyWidgetMixin # def read(self): return self.get_selection_data() def update(self, data): if data is ValueUnset or data is None: return self.add_selection_by_data(data) # # Callbacks # def _on_combo__item_added(self, multicombo, item): self.emit('content-changed') def _on_combo__item_removed(self, multicombo, item): self.emit('content-changed') type_register(ProxyMultiCombo)
if data is ValueUnset: self._has_been_updated = False else: mode = self._mode if mode == ENTRY_MODE_DATA: new = self._get_text_from_object(data) if new is None: raise TypeError("%r is not a data object" % data) text = new elif mode == ENTRY_MODE_TEXT: text = self._as_string(data) if self.props.mandatory and self.get_text() == "": self.emit('validation-changed', False) self.set_text(text) type_register(ProxyEntry) class ProxyDateEntry(DateEntry, ValidatableProxyWidgetMixin): __gtype_name__ = 'ProxyDateEntry' # changed allowed data types because checkbuttons can only # accept bool values allowed_data_types = datetime.date, data_type = gobject.property( getter=ProxyWidgetMixin.get_data_type, setter=ProxyWidgetMixin.set_data_type, type=str, blurb='Data Type') model_attribute = gobject.property(type=str, blurb='Model attribute') gsignal('content-changed')
__gtype_name__ = 'ProxyHScale' data_type = gobject.property( getter=ProxyWidgetMixin.get_data_type, setter=ProxyWidgetMixin.set_data_type, type=str, blurb='Data Type') model_attribute = gobject.property(type=str, blurb='Model attribute') gsignal('content-changed') gsignal('validation-changed', bool) gsignal('validate', object, retval=object) def __init__(self): gtk.HScale.__init__(self) ProxyWidgetMixin.__init__(self) self.props.data_type = float type_register(ProxyHScale) class ProxyVScale(_ProxyScale, ProxyWidgetMixin, gtk.VScale): __gtype_name__ = 'ProxyVScale' data_type = gobject.property( getter=ProxyWidgetMixin.get_data_type, setter=ProxyWidgetMixin.set_data_type, type=str, blurb='Data Type') model_attribute = gobject.property(type=str, blurb='Model attribute') gsignal('content-changed') gsignal('validation-changed', bool) gsignal('validate', object, retval=object) def __init__(self): gtk.VScale.__init__(self)
def __init__(self, label=None, use_underline=True): gtk.CheckButton.__init__(self, label=label, use_underline=use_underline) ProxyWidgetMixin.__init__(self) self.props.data_type = bool gsignal('toggled', 'override') def do_toggled(self): self.emit('content-changed') self.chain() def read(self): return self.get_active() def update(self, data): if data is None or data is ValueUnset: self.set_active(False); return # No conversion to string needed, we only accept bool self.set_active(data) class CheckButton(ProxyCheckButton): def __init__(self): deprecationwarn( 'CheckButton is deprecated, use ProxyCheckButton instead', stacklevel=3) ProxyCheckButton.__init__(self) type_register(CheckButton)
- xx-small - x-small - small - medium, - large - x-large - xx-large :type size: string """ if (size is not None and size not in self._size_list): raise ValueError('Size of "%s" label is not valid' % self.get_text()) self._attr_dic["size"] = size self._apply_attributes() def set_text(self, text): """ Overrides gtk.Label set_text method. Sets the new text of the label but keeps the formating :param text: label :type text: string """ gtk.Label.set_text(self, text) self._apply_attributes() def set_color(self, color): set_foreground(self, color) type_register(ProxyLabel)
self.read() def read(self): if self._is_unset: return ValueUnset textbuffer = self._textbuffer data = textbuffer.get_text(textbuffer.get_start_iter(), textbuffer.get_end_iter()) return self._from_string(data) def update(self, data): if data is ValueUnset: self._textbuffer.set_text("") self._is_unset = True return elif data is None: text = "" else: self.is_unset = False text = self._as_string(data) self._textbuffer.set_text(text) class TextView(ProxyTextView): def __init__(self): deprecationwarn( 'TextView is deprecated, use ProxyTextView instead', stacklevel=3) ProxyTextView.__init__(self) type_register(TextView)
y, m, d = self.calendar.get_date() return datetime.date(y, m + 1, d) def set_date(self, date): """Sets the date of the date entry :param date: date to set :type date: datetime.date """ self.calendar.select_month(date.month - 1, date.year) self.calendar.select_day(date.day) # FIXME: Only mark the day in the current month? self.calendar.clear_marks() self.calendar.mark_day(date.day) type_register(_DateEntryPopup) class DateEntry(Gtk.Box): """I am an entry which you can input a date on. In addition to an Gtk.Entry I also contain a button with an arrow you can click to get popup window with a Gtk.Calendar for which you can use to select the date """ gsignal('changed') gsignal('activate') def __init__(self): super(DateEntry, self).__init__(orientation=Gtk.Orientation.HORIZONTAL) self._popping_down = False
Called when the mouse pinter enters or leaves the widget. @param hover: Whether the mouse has entered the widget. @type hover: boolean """ self._is_hover = hover self._update_look() def _on_notify(self, eventbox, param): """ Called on property notification. Ensure that the look is up to date with the properties """ if (param.name == 'text' or param.name.endswith('-color') or param.name.endswith('-underline') or param.name.endswith('-bold')): self._update_look() def _on_map_event(self, eventbox, event): """ Called on initially mapping the widget. Used here to set the cursor type. """ cursor = gtk.gdk.Cursor(gtk.gdk.HAND1) self.window.set_cursor(cursor) type_register(HyperLink)
def get_iter_from_obj(self, obj): mode = self._mode if mode == ENTRY_MODE_TEXT: return self.get_iter_by_label(obj) elif mode == ENTRY_MODE_DATA: return self.get_iter_by_data(obj) else: # XXX: When setting the datatype to non string, automatically go to # data mode raise TypeError("unknown Entry mode. Did you call prefill?") def get_mode(self): return self._mode type_register(KiwiEntry) def main(args): win = gtk.Window() win.set_title('gtk.Entry subclass') def cb(window, event): print 'fields', widget.get_field_text() gtk.main_quit() win.connect('delete-event', cb) widget = KiwiEntry() widget.set_mask('000.000.000.000') win.add(widget) win.show_all()
import gtk from kiwi.ui.proxywidget import ProxyWidgetMixin from kiwi.utils import PropertyObject, gsignal, type_register class ProxyFontButton(PropertyObject, gtk.FontButton, ProxyWidgetMixin): __gtype_name__ = 'ProxyFontButton' allowed_data_types = basestring, def __init__(self, fontname=None): ProxyWidgetMixin.__init__(self) PropertyObject.__init__(self, data_type=str) gtk.FontButton.__init__(self, fontname) gsignal('font-set', 'override') def do_font_set(self): self.emit('content-changed') self.chain() def read(self): return self.get_font_name() def update(self, data): self.set_font_name(data) type_register(ProxyFontButton)
self._activate_selected_item() class _MultiComboCloseButton(gtk.Button): __gtype_name__ = 'MultiComboCloseButton' def __init__(self, **kwargs): super(_MultiComboCloseButton, self).__init__(**kwargs) self.set_relief(gtk.RELIEF_NONE) image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) self.add(image) type_register(_MultiComboCloseButton) class MultiCombo(gtk.HBox): """Multi selection combo. Just like a combo entry, but allows multiple items to be selected at the same time. Inspired by react-select:: http://jedwatson.github.io/react-select/ """ gsignal('item-added', object)
if not self._popup_window: return self._popup_window.popdown() self._popup_ungrab_window() def set_model(self, model): if not model: if self._popup_window: self._popup_window.set_model(None) self.popdown() self._model = None self._filter_model = None return self._model = model self._filter_model = model.filter_new() self._filter_model.set_visible_func(self._visible_function) if self._popup_window: self._popup_window.set_model(self._filter_model) def get_model(self): return self._model def set_match_func(self, function, data=None): self._match_function = function self._match_function_data = data type_register(KiwiEntryCompletion)
gadget = self.get_selected_widget(project) if (isinstance(placeholder, gtk.TreeView) and isinstance(gadget.widget, gtk.TreeViewColumn)): from gazpacho.gadget import Gadget from gazpacho.widgets.base.treeview import CommandAddRemoveTreeViewColumn tree_view = Gadget.from_widget(placeholder) cmd = CommandAddRemoveTreeViewColumn(tree_view, gadget, project, True) else: cmd = CommandCutPaste(gadget, project, placeholder, False) command_manager.execute(cmd, project) return gadget type_register(Clipboard) clipboard = Clipboard() class ClipboardWindow(gtk.Window): """ClipboardWindow is a Widget to represent and manage a Clipboard. It displays the current Clipboard contents through a TreeView. """ ICON_COLUMN = 0 NAME_COLUMN = 1 WIDGET_COLUMN = 2 def __init__(self, parent, clipboard): gtk.Window.__init__(self)
def popdown(self): if not self._popup_window: return self._popup_window.popdown() self._popup_ungrab_window() def set_model(self, model): if not model: if self._popup_window: self._popup_window.set_model(None) self.popdown() self._model = None self._filter_model = None return self._model = model self._filter_model = model.filter_new() self._filter_model.set_visible_func(self._visible_function) if self._popup_window: self._popup_window.set_model(self._filter_model) def get_model(self): return self._model def set_match_func(self, function, data=None): self._match_function = function self._match_function_data = data type_register(KiwiEntryCompletion)
self.emit('remove-action', action) def _remove_gtk_action(self, name): gtk_action_group = self.get_data('gtk_action_group') gtk_action = gtk_action_group.get_action(name) gtk_action_group.remove_action(gtk_action) def update_action(self, action, old_name): self._remove_gtk_action(old_name) self._add_gtk_action(action) del self._actions[old_name] self._actions[action.name] = action if self._uimanager is not None: # we need to remove it and then add it to the uimanager # so all the proxies are updated gtk_action_group = self.get_data('gtk_action_group') self._uimanager.remove_action_group(gtk_action_group) self._uimanager.insert_action_group(gtk_action_group, 0) def get_action(self, action_name): return self._actions.get(action_name) def get_actions(self): return self._actions.values() def get_action_names(self): return self._actions.keys() type_register(GActionGroup)