Example #1
0
    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

        if not entry:
            entry = KiwiEntry()

        if isinstance(entry, KiwiEntry):
            entry.set_normal_completion()

        self.hbox = gtk.HBox()
        self.pack_start(gtk.EventBox())
        self.pack_start(self.hbox, expand=False)
        self.pack_start(gtk.EventBox())

        self.mode = ComboMode.UNKNOWN
        self.entry = entry
        self.entry.connect('activate',
                           self._on_entry__activate)
        self.entry.connect('changed',
                           self._on_entry__changed)
        self.entry.connect('scroll-event',
                           self._on_entry__scroll_event)
        self.entry.connect('key-press-event',
                           self._on_entry__key_press_event)
        self.entry.connect('focus-out-event',
                           self._on_entry__focus_out_event)

        self.hbox.pack_start(self.entry, True, True)
        self.hbox.show_all()

        self._button = gtk.ToggleButton()
        self._button.connect('scroll-event', self._on_entry__scroll_event)
        self._button.connect('toggled', self._on_button__toggled)
        self._button.set_focus_on_click(False)
        self.hbox.pack_end(self._button, False, False)
        self._button.show()

        arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_NONE)
        self._button.add(arrow)
        arrow.show()

        self._popup = _ComboEntryPopup(self)
        self._popup.connect('text-selected', self._on_popup__text_selected)
        self._popup.connect('hide', self._on_popup__hide)
        self._popup.set_size_request(-1, 24)

        completion = KiwiEntryCompletion()
        completion.set_popup_window(self._popup)
        completion.set_treeview(self._popup._treeview)
        self.entry.set_completion(completion)
        self.set_model(completion.get_model())
Example #2
0
    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

        if not entry:
            entry = KiwiEntry()

        self.hbox = gtk.HBox()
        self.pack_start(gtk.EventBox())
        self.pack_start(self.hbox, expand=False)
        self.pack_start(gtk.EventBox())

        self.mode = ComboMode.UNKNOWN
        self.entry = entry
        self.entry.connect('activate',
                           self._on_entry__activate)
        self.entry.connect('changed',
                           self._on_entry__changed)
        self.entry.connect('scroll-event',
                           self._on_entry__scroll_event)
        self.entry.connect('key-press-event',
                           self._on_entry__key_press_event)
        self.entry.connect('focus-out-event',
                           self._on_entry__focus_out_event)

        self.hbox.pack_start(self.entry, True, True)
        self.hbox.show_all()

        self._button = gtk.ToggleButton()
        self._button.connect('scroll-event', self._on_entry__scroll_event)
        self._button.connect('toggled', self._on_button__toggled)
        self._button.set_focus_on_click(False)
        self.hbox.pack_end(self._button, False, False)
        self._button.show()

        arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_NONE)
        self._button.add(arrow)
        arrow.show()

        self._popup = _ComboEntryPopup(self)
        self._popup.connect('text-selected', self._on_popup__text_selected)
        self._popup.connect('hide', self._on_popup__hide)
        self._popup.set_size_request(-1, 24)

        completion = KiwiEntryCompletion()
        completion.set_popup_window(self._popup)
        completion.set_treeview(self._popup._treeview)
        self.entry.set_completion(completion)
        self.set_model(completion.get_model())
Example #3
0
def main(args):
    w = gtk.Window()
    w.set_position(gtk.WIN_POS_CENTER)
    w.set_size_request(250, 300)
    w.set_title('KiwiEntryCompletion example')
    w.connect('delete-event', gtk.main_quit)

    vbox = gtk.VBox()
    w.add(vbox)

    model = gtk.ListStore(str)
    list = load_colors()
    list.sort()
    for i in list:
        model.append((i,))

    entry = KiwiEntry()
    vbox.pack_start(entry, False)

    sw = gtk.ScrolledWindow()
    sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
    vbox.pack_start(sw)
    
    treeview = gtk.TreeView(model)
    treeview.append_column(
        gtk.TreeViewColumn('Completions', gtk.CellRendererText(), text=0))

    sw.add(treeview)

    completion = KiwiEntryCompletion()
    entry.set_completion(completion)
    completion.set_property('minimum-key-length', 0)
    completion.set_model(model)
    completion.set_treeview(treeview)


    w.show_all()
    gtk.main()
Example #4
0
def main(args):
    w = gtk.Window()
    w.set_position(gtk.WIN_POS_CENTER)
    w.set_size_request(250, 300)
    w.set_title('KiwiEntryCompletion example')
    w.connect('delete-event', gtk.main_quit)

    vbox = gtk.VBox()
    w.add(vbox)

    model = gtk.ListStore(str)
    list = load_colors()
    list.sort()
    for i in list:
        model.append((i, ))

    entry = KiwiEntry()
    vbox.pack_start(entry, False)

    sw = gtk.ScrolledWindow()
    sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
    vbox.pack_start(sw)

    treeview = gtk.TreeView(model)
    treeview.append_column(
        gtk.TreeViewColumn('Completions', gtk.CellRendererText(), text=0))

    sw.add(treeview)

    completion = KiwiEntryCompletion()
    entry.set_completion(completion)
    completion.set_property('minimum-key-length', 0)
    completion.set_model(model)
    completion.set_treeview(treeview)

    w.show_all()
    gtk.main()
Example #5
0
    def __init__(self, entry=None):
        """
        Create a new ComboEntry object.
        :param entry: a Gtk.Entry subclass to use
        """
        super(ComboEntry, self).__init__(orientation=Gtk.Orientation.VERTICAL)
        self._popping_down = False

        # This will force both the entry and the button have the same height
        self._sizegroup = Gtk.SizeGroup.new(Gtk.SizeGroupMode.VERTICAL)

        if not entry:
            entry = KiwiEntry()
        self._sizegroup.add_widget(entry)

        if isinstance(entry, KiwiEntry):
            entry.set_normal_completion()

        self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        self.hbox.set_valign(Gtk.Align.CENTER)
        self.hbox.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED)

        # FIXME: Why are those EventBox here?
        self.pack_start(Gtk.EventBox(), True, True, 0)
        self.pack_start(self.hbox, True, True, 0)
        self.pack_start(Gtk.EventBox(), True, True, 0)

        self.mode = ComboMode.UNKNOWN
        self.entry = entry
        self.entry.connect('activate',
                           self._on_entry__activate)
        self.entry.connect('changed',
                           self._on_entry__changed)
        self.entry.connect('scroll-event',
                           self._on_entry__scroll_event)
        self.entry.connect('key-press-event',
                           self._on_entry__key_press_event)
        self.entry.connect('focus-out-event',
                           self._on_entry__focus_out_event)

        self.hbox.pack_start(self.entry, True, True, 0)
        self.hbox.show_all()

        self._button = Gtk.ToggleButton()
        self._button.set_vexpand_set(True)
        self._button.set_vexpand(False)
        self._button.connect('scroll-event', self._on_entry__scroll_event)
        self._button.connect('toggled', self._on_button__toggled)
        self._button.set_focus_on_click(False)
        self.hbox.pack_end(self._button, False, False, 0)
        self._button.show()
        self._sizegroup.add_widget(self._button)

        arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, shadow_type=Gtk.ShadowType.NONE)
        self._button.add(arrow)
        arrow.show()

        self._popup = _ComboEntryPopup(self)
        self._popup.connect('text-selected', self._on_popup__text_selected)
        self._popup.connect('hide', self._on_popup__hide)
        self._popup.set_size_request(-1, 24)

        completion = KiwiEntryCompletion()
        completion.set_popup_window(self._popup)
        completion.set_treeview(self._popup._treeview)
        self.entry.set_completion(completion)
        self.set_model(completion.get_model())
Example #6
0
    def __init__(self, entry=None):
        """
        Create a new ComboEntry object.
        :param entry: a Gtk.Entry subclass to use
        """
        super(ComboEntry, self).__init__(orientation=Gtk.Orientation.VERTICAL)
        self._popping_down = False

        # This will force both the entry and the button have the same height
        self._sizegroup = Gtk.SizeGroup.new(Gtk.SizeGroupMode.VERTICAL)

        if not entry:
            entry = KiwiEntry()
        self._sizegroup.add_widget(entry)

        if isinstance(entry, KiwiEntry):
            entry.set_normal_completion()

        self.hbox = Gtk.HBox()
        self.hbox.set_valign(Gtk.Align.CENTER)

        # FIXME: Why are those EventBox here?
        self.pack_start(Gtk.EventBox(), True, True, 0)
        self.pack_start(self.hbox, True, True, 0)
        self.pack_start(Gtk.EventBox(), True, True, 0)

        self.mode = ComboMode.UNKNOWN
        self.entry = entry
        self.entry.connect('activate', self._on_entry__activate)
        self.entry.connect('changed', self._on_entry__changed)
        self.entry.connect('scroll-event', self._on_entry__scroll_event)
        self.entry.connect('key-press-event', self._on_entry__key_press_event)
        self.entry.connect('focus-out-event', self._on_entry__focus_out_event)

        self.hbox.pack_start(self.entry, True, True, 0)
        self.hbox.show_all()

        self._button = Gtk.ToggleButton()
        self._button.set_vexpand_set(True)
        self._button.set_vexpand(False)
        self._button.connect('scroll-event', self._on_entry__scroll_event)
        self._button.connect('toggled', self._on_button__toggled)
        self._button.set_focus_on_click(False)
        self.hbox.pack_end(self._button, False, False, 0)
        self._button.show()
        self._sizegroup.add_widget(self._button)

        arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE)
        self._button.add(arrow)
        arrow.show()

        self._popup = _ComboEntryPopup(self)
        self._popup.connect('text-selected', self._on_popup__text_selected)
        self._popup.connect('hide', self._on_popup__hide)
        self._popup.set_size_request(-1, 24)

        completion = KiwiEntryCompletion()
        completion.set_popup_window(self._popup)
        completion.set_treeview(self._popup._treeview)
        self.entry.set_completion(completion)
        self.set_model(completion.get_model())