Combox - show one column but two columns in popup

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Combox - show one column but two columns in popup

Mike Martin-5
Is this possible?

ie I have a combobox based on a two column liststore
I want only the first column to be shown in the combobox, but both columns to be shown in the popup

The model is populated by an array of filename/directory name

I'm sure I must be missing something obvious

thanks

example

my $channel_file_model=Gtk3::TreeStore->new('Glib::String','Glib::String');
$channel_file_view=Gtk3::Treeview->new

 -- list of files as below;
my @list;
my %dirdvb;
foreach my $prefix_conf (@prefix_conf){
#my $prefix_conf;
my (undef,$prefix_conf_sys,undef)=File::Basename::fileparse($prefix_conf);
$dirdvb{$prefix_conf_sys}=undef;
}
#print 'prefix ',$prefix_conf_sys,"\n";
foreach my $prefix_conf_sys (keys %dirdvb){
        my @listi=`ls -1 $prefix_conf_sys`;
        foreach my $list1 (@listi){
             push @list, [$list1,$prefix_conf_sys]
             }
        }
--setup renderer - otherwise 2nd column doesnt show at all
my $renderer1 = Gtk3::CellRendererText->new;
    
       $channel_file_view->pack_start ($renderer1, 'TRUE');
       $channel_file_view->add_attribute ($renderer1, text => 1);
--finally add lines to combobox

sub add_combo {
    my ($combo,$val1,$val2,$chk)=@_;
    my $iter=$combo->append(undef);

    my $cnt=0;
        foreach my $val ($val1,$val2){
                  $combo->set($iter,$cnt,$val);
                  $cnt++;
                  }
}

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Combox - show one column but two columns in popup

Mike Martin-5
This is how I resolved my issue by connecting to notify::popup-shown signal. It seems really kludgey though (especially having to resize the window)

$widgetsm{tunefile}->signal_connect('notify::popup-shown'=>sub{

     if($widgetsm{tunefile}->get('popup-shown') ==1){
        ($w,$h)= $window->get_size;
           $widgetsm{tunefile}->pack_start ($renderer1, 'FALSE');
           $widgetsm{tunefile}->add_attribute ($renderer1, text => 1);
        }
    elsif ($widgetsm{tunefile}->get('popup-shown') ==0){
        $widgetsm{tunefile}->clear;
        $widgetsm{tunefile}->pack_start ($renderer, 'FALSE');
        $widgetsm{tunefile}->add_attribute ($renderer, text => 0);
        $window->resize($w,$h);
        }
    }
    );

On 20 June 2017 at 00:59, Mike Martin <[hidden email]> wrote:
Is this possible?

ie I have a combobox based on a two column liststore
I want only the first column to be shown in the combobox, but both columns to be shown in the popup

The model is populated by an array of filename/directory name

I'm sure I must be missing something obvious

thanks

example

my $channel_file_model=Gtk3::TreeStore->new('Glib::String','Glib::String');
$channel_file_view=Gtk3::Treeview->new

 -- list of files as below;
my @list;
my %dirdvb;
foreach my $prefix_conf (@prefix_conf){
#my $prefix_conf;
my (undef,$prefix_conf_sys,undef)=File::Basename::fileparse($prefix_conf);
$dirdvb{$prefix_conf_sys}=undef;
}
#print 'prefix ',$prefix_conf_sys,"\n";
foreach my $prefix_conf_sys (keys %dirdvb){
        my @listi=`ls -1 $prefix_conf_sys`;
        foreach my $list1 (@listi){
             push @list, [$list1,$prefix_conf_sys]
             }
        }
--setup renderer - otherwise 2nd column doesnt show at all
my $renderer1 = Gtk3::CellRendererText->new;
    
       $channel_file_view->pack_start ($renderer1, 'TRUE');
       $channel_file_view->add_attribute ($renderer1, text => 1);
--finally add lines to combobox

sub add_combo {
    my ($combo,$val1,$val2,$chk)=@_;
    my $iter=$combo->append(undef);

    my $cnt=0;
        foreach my $val ($val1,$val2){
                  $combo->set($iter,$cnt,$val);
                  $cnt++;
                  }
}


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Combox - show one column but two columns in popup

"Torsten Schönfeld"
In reply to this post by Mike Martin-5
On 20.06.2017 01:59, Mike Martin wrote:
> ie I have a combobox based on a two column liststore
> I want only the first column to be shown in the combobox, but both
> columns to be shown in the popup

Without having tried it, I think you might be able to do this by making
the combo box use a custom Gtk3::CellRenderer that has a RENDER vfunc
that changes behavior depending on whether the combo box's "popup-shown"
is true or not.

Or maybe try having three columns in your model, your two original ones
plus one containing the concatenation of the first two, and then
switching the "text" property of the cell renderer in "notify::popup-shown".

-Torsten
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list