예제 #1
0
파일: spinbutton.py 프로젝트: Schevo/kiwi
 def __init__(self, data_type=int):
     # since the default data_type is str we need to set it to int
     # or float for spinbuttons
     gtk.SpinButton.__init__(self)
     PropertyObject.__init__(self, data_type=data_type)
     ValidatableProxyWidgetMixin.__init__(self)
     self._icon = IconEntry(self)
     self.set_property('xalign', 1.0)
예제 #2
0
파일: entry.py 프로젝트: Schevo/kiwi
    def __init__(self):
        self._completion = None

        gtk.Entry.__init__(self)
        PropertyObject.__init__(self)

        self.connect('insert-text', self._on_insert_text)
        self.connect('delete-text', self._on_delete_text)
        self.connect_after('grab-focus', self._after_grab_focus)

        self.connect('changed', self._on_changed)

        self.connect('focus', self._on_focus)
        self.connect('focus-out-event', self._on_focus_out_event)
        self.connect('move-cursor', self._on_move_cursor)

        # Ideally, this should be connected to notify::cursor-position, but
        # there seems to be a bug in gtk that the notification is not emited
        # when it should.
        # TODO: investigate that and report a bug.
        self.connect('notify::selection-bound',
                     self._on_notify_selection_bound)

        self._block_changed = False

        self._current_object = None
        self._mode = ENTRY_MODE_TEXT
        self._icon = IconEntry(self)

        # List of validators
        #  str -> static characters
        #  int -> dynamic, according to constants above
        self._mask_validators = []
        self._mask = None
        # Fields defined by mask
        # each item is a tuble, containing the begining and the end of the
        # field in the text
        self._mask_fields = []
        self._current_field = -1
        self._pos = 0
        self._selecting = False

        self._block_insert = False
        self._block_delete = False
예제 #3
0
파일: spinbutton.py 프로젝트: Schevo/kiwi
class ProxySpinButton(PropertyObject, gtk.SpinButton, ValidatableProxyWidgetMixin):
    """
    A SpinButton subclass which adds supports for the Kiwi Framework.
    This widget supports validation
    The only allowed types for spinbutton are int and float.

    """
    __gtype_name__ = 'ProxySpinButton'
    allowed_data_types = number

    def __init__(self, data_type=int):
        # since the default data_type is str we need to set it to int
        # or float for spinbuttons
        gtk.SpinButton.__init__(self)
        PropertyObject.__init__(self, data_type=data_type)
        ValidatableProxyWidgetMixin.__init__(self)
        self._icon = IconEntry(self)
        self.set_property('xalign', 1.0)

    gsignal('changed', 'override')
    def do_changed(self):
        """Called when the content of the spinbutton changes.
        """
        # This is a work around, because GtkEditable.changed is called too
        # often, as reported here: http://bugzilla.gnome.org/show_bug.cgi?id=64998
        if self.get_text() != '':
            self.emit('content-changed')
            self.chain()

    def read(self):
        return self._from_string(self.get_text())

    def update(self, data):
        if data is None or data is ValueUnset:
            self.set_text("")
        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)

    def do_expose_event(self, event):
        # This gets called when any of our three windows needs to be redrawn
        gtk.SpinButton.do_expose_event(self, event)

        if event.window == self.window:
            self._icon.draw_pixbuf()

    gsignal('size-allocate', 'override')
    def do_size_allocate(self, allocation):

        self.chain(allocation)

        if self.flags() & gtk.REALIZED:
            self._icon.resize_windows()

    def do_realize(self):
        gtk.SpinButton.do_realize(self)
        self._icon.construct()

    def do_unrealize(self):
        self._icon.deconstruct()
        gtk.SpinButton.do_unrealize(self)

    # IconEntry

    def set_tooltip(self, text):
        self._icon.set_tooltip(text)

    def set_pixbuf(self, pixbuf):
        self._icon.set_pixbuf(pixbuf)

    def update_background(self, color):
        self._icon.update_background(color)

    def get_background(self):
        return self._icon.get_background()

    def get_icon_window(self):
        return self._icon.get_icon_window()
예제 #4
0
파일: entry.py 프로젝트: Schevo/kiwi
class KiwiEntry(PropertyObject, gtk.Entry):
    """
    The KiwiEntry is a Entry subclass with the following additions:

      - IconEntry, allows you to have an icon inside the entry
      - Mask, force the input to meet certain requirements
      - IComboMixin: Allows you work with objects instead of strings
        Adds a number of convenience methods such as L{prefill}().
    """
    __gtype_name__ = 'KiwiEntry'

    gproperty("completion", bool, False)
    gproperty('exact-completion', bool, default=False)
    gproperty("mask", str, default='')

    def __init__(self):
        self._completion = None

        gtk.Entry.__init__(self)
        PropertyObject.__init__(self)

        self.connect('insert-text', self._on_insert_text)
        self.connect('delete-text', self._on_delete_text)
        self.connect_after('grab-focus', self._after_grab_focus)

        self.connect('changed', self._on_changed)

        self.connect('focus', self._on_focus)
        self.connect('focus-out-event', self._on_focus_out_event)
        self.connect('move-cursor', self._on_move_cursor)

        # Ideally, this should be connected to notify::cursor-position, but
        # there seems to be a bug in gtk that the notification is not emited
        # when it should.
        # TODO: investigate that and report a bug.
        self.connect('notify::selection-bound',
                     self._on_notify_selection_bound)

        self._block_changed = False

        self._current_object = None
        self._mode = ENTRY_MODE_TEXT
        self._icon = IconEntry(self)

        # List of validators
        #  str -> static characters
        #  int -> dynamic, according to constants above
        self._mask_validators = []
        self._mask = None
        # Fields defined by mask
        # each item is a tuble, containing the begining and the end of the
        # field in the text
        self._mask_fields = []
        self._current_field = -1
        self._pos = 0
        self._selecting = False

        self._block_insert = False
        self._block_delete = False

    # Virtual methods
    # PyGTK 2.6 does not support the virtual method do_size_allocate so
    # we have to use the signal instead
    # PyGTK 2.9.0 and later (bug #327715) does not work using the old code,
    # so we have to make this conditionally
    if HAVE_2_6:
        gsignal('size-allocate', 'override')
        def do_size_allocate(self, allocation):
            self.chain(allocation)

            if self.flags() & gtk.REALIZED:
                self._icon.resize_windows()
    else:
        def do_size_allocate(self, allocation):
            gtk.Entry.do_size_allocate(self, allocation)

            if self.flags() & gtk.REALIZED:
                self._icon.resize_windows()

    def do_expose_event(self, event):
        gtk.Entry.do_expose_event(self, event)

        if event.window == self.window:
            self._icon.draw_pixbuf()

    def do_realize(self):
        gtk.Entry.do_realize(self)
        self._icon.construct()

    def do_unrealize(self):
        self._icon.deconstruct()
        gtk.Entry.do_unrealize(self)

    # Properties

    def prop_set_exact_completion(self, value):
        self.set_exact_completion(value)
        return value

    def prop_set_completion(self, value):
        if not self.get_completion():
            self.set_completion(gtk.EntryCompletion())
        return value

    def prop_set_mask(self, value):
        try:
            self.set_mask(value)
            return self.get_mask()
        except MaskError, e:
            pass
        return ''