GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun May 01, 2016 11:12 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Problem with Combobox
PostPosted: Fri Nov 06, 2015 4:59 am 
Offline
Familiar Face

Joined: Wed Nov 04, 2015 7:53 am
Posts: 6
Hello friends, I have problems with Combobox, I have a list store from 1 up to 100 items, and I would like that the combobox just shows 10 items, however it shows 100 items, I read that we can set the number of columns, however it is a little ugly, I would like that it shows only 1 column with 10 items, and see the another items with the scroll.

Also, the popdown and popup signals dont work, I click on a combobox, the pop downs, however the signal is not captured.

I am using pyobject all in one for windows, with Gtk 3, I dont know why Gtk neglect this simple but important thinks :-( . Please help me.

I am not speak english, so, sorry for my gramar mistakes.


Top
 Profile  
 
 Post subject: Re: Problem with Combobox
PostPosted: Tue Nov 10, 2015 6:20 pm 
Offline
Never Seen the Sunlight

Joined: Sat Jul 26, 2014 11:43 pm
Posts: 314
I don't have a windows machine to test on but that shouldn't be a problem. If you post a little code showing the problem or what you are trying to do, then maybe someone can figure out a good solution. You should be a able to insert into the combobox the items that you want.


Top
 Profile  
 
 Post subject: Re: Problem with Combobox
PostPosted: Mon Nov 30, 2015 12:57 am 
Offline
Familiar Face

Joined: Wed Nov 04, 2015 7:53 am
Posts: 6
Hello friend, sorry for delaying, here is my code, as I said, the "popoup" and "popdown" events dont work, furthermore, I dont know how set the number of rows that the combobox must show, only I can set the number of columns, however it looks a little ugly.

Code:
from gi.repository import Gtk

class MyWindow(Gtk.Window):
    nro_entry=1
   
    def __init__(self):
        Gtk.Window.__init__(self)
        list_store=self.crear_list_store_monocolumna(range(100))
        self.combo,entry=self.get_entry_cmbox(list_store)
        self.combo.set_wrap_width(10)
        self.combo.connect("popdown",self.combo_popdown_event)
        self.combo.connect("popup",self.combo_popup_event)
        self.add(self.combo)
       
    def combo_popdown_event(self,combobox,data=None):
        print("entro popdown")
       
    def combo_popup_event(self,combobox,data=None):
        print("entro popup")

    def crear_list_store_monocolumna(self,array):
        list_store=Gtk.ListStore(str)
        for elemento in array:       
            list_store.append([str(elemento)])
        return list_store
   
    def get_entry_cmbox(self,list_store):
        cmb= Gtk.ComboBox.new_with_model_and_entry(list_store)
        cmb.set_entry_text_column(0)       
        entry=cmb.get_child()
        return (cmb,entry)
   
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()


Top
 Profile  
 
 Post subject: Re: Problem with Combobox
PostPosted: Mon Nov 30, 2015 8:45 pm 
Offline
Never Seen the Sunlight

Joined: Sat Jul 26, 2014 11:43 pm
Posts: 314
The popup and popdown signals are keybinding signals. Take a look at the documentation.

https://developer.gnome.org/gtk3/stable ... ox-popdown

Try alt+up and alt+down and see if you get the print to screen. Maybe not what you are after though. Will the "changed" signal work for what you are doing?

A simple way for limiting your list is setting the limit to how many rows you want when building the list. You can try something like

Code:
for index, elemento in enumerate(array):       
    list_store.append([str(elemento)])
    if index>=10:
        break


Or in this case, just checking the elemento variable. With the above, if you are getting a bunch of different strings for your combobox it will work.

There are a lot of variations of filtering records. If you have data in a relational database, SQL makes it easy to get the records you want. If you are looking for file names in a directory then you might have to write a little code and a little different strategy.

Also your

Code:
self.combo.set_wrap_width(10)


is wrapping the numbers in the combobox instead of just having one column.


Top
 Profile  
 
 Post subject: Re: Problem with Combobox
PostPosted: Wed Dec 09, 2015 10:49 pm 
Offline
Familiar Face

Joined: Wed Nov 04, 2015 7:53 am
Posts: 6
Hello friend, about the signals, I did not know that the popup and popdown signals are key signals, but I think that should have signals which capture the moment when I show or hide the list of my combobox, by clicking in my combobox, but I think that gtk doesnt have these kind of signals.

And about the items to show, I wrote a list of numbers, however, what I have in my software is a list with strings, with names, and I dont want show these items in several columns, but just in one column with 10 items, and with a scroll, similar to combobox in java (swing), however gtk does not have this property, what I did was join a entry and below of it, create a list with one column, and disappear the list when I go out of the entry, and appear the list when I enter to the entry. Thank for your time friend.


Top
 Profile  
 
 Post subject: Re: Problem with Combobox
PostPosted: Wed Dec 09, 2015 11:02 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 1010
Location: UK
Hi,

There is a way to monitor when the combobox has popped up or down by connecting to a notify signal for one of the properties. Not sure how useful that would be.

How the list is displayed is defined by the users theme. It should be possible to change this by modifying the theme just for this widget using CSS if you are using GTK+ v3.

I will try and post some code in the morning when I have had some sleep.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Problem with Combobox
PostPosted: Fri Dec 11, 2015 6:51 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 1010
Location: UK
Hi,
This is your example re-written so that it can tell when the combo box menu has is popped up or down.
Code:
from gi.repository import Gtk

class MyWindow(Gtk.Window):
    nro_entry=1
   
    def __init__(self):
        Gtk.Window.__init__(self)
        list_store=self.crear_list_store_monocolumna(range(100))
        self.combo,entry=self.get_entry_cmbox(list_store)
        self.combo.set_wrap_width(10)
        self.combo.connect("notify::popup-shown",self.combo_popup_event)
        self.add(self.combo)
       
    def combo_popup_event(self,combobox,gparamstring):
        shown = combobox.get_property("popup_shown")
        if shown :
          print("popup")
        else :
          print("popdown")

    def crear_list_store_monocolumna(self,array):
        list_store=Gtk.ListStore(str)
        for elemento in array:       
            list_store.append([str(elemento)])
        return list_store
   
    def get_entry_cmbox(self,list_store):
        cmb= Gtk.ComboBox.new_with_model_and_entry(list_store)
        cmb.set_entry_text_column(0)       
        entry=cmb.get_child()
        return (cmb,entry)
   
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()


I have not had a chance to do anything with the CSS to change to a scrolled menu, but I think it will not be what you expect it should be. To get exactly 10 items to be shown with a scroll bar will need a custom widget.

I am not sure if getting the status of the pop-up menu is going to be of any help, except maybe for a custom widget.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Problem with Combobox
PostPosted: Tue Dec 22, 2015 2:04 am 
Offline
Familiar Face

Joined: Wed Nov 04, 2015 7:53 am
Posts: 6
Thanks errol, It works fine, may you give me a page where I can read about "notify::" and learn about custom widgets, and CSS in GTK?, Thanks so much for your time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group