Mixed pixbuf and text

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

Mixed pixbuf and text

beast-3
Hello,

Is there any way to add text next into pixbuf in SimpleList?
Or if it's not possible any way to merge the column header so 2 column
(pixbuf and text) has only 1 column header?



--

--beast

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

Re: Mixed pixbuf and text

muppet-6

On Jul 1, 2005, at 12:27 AM, Beast wrote:

> Is there any way to add text next into pixbuf in SimpleList?
> Or if it's not possible any way to merge the column header so 2  
> column (pixbuf and text) has only 1 column header?

Can't do it with SimpleList, but you can with TreeView.  Just pack  
two cell renderers into one column.  That means you have to do a bit  
more work, stuff that the convenience APIs normally do for you.

   # assume that PIXBUF_COLUMN and TEXT_COLUMN refer
   # to the index of the column in the model holding that data.

   $column = Gtk2::TreeViewColumn->new;
   $column->set_title ($column_title);
   $pixbuf_cell = Gtk2::CellRendererPixbuf->new;
   $text_cell = Gtk2::CellRendererText->new;
   $column->pack_start ($pixbuf_cell, FALSE);
   $column->pack_start ($text_cell, TRUE);
   $column->add_attribute ($pixbuf_cell, pixbuf => PIXBUF_COLUMN);
   $column->add_attribute ($text_cell, text => TEXT_COLUMN);



--
Examples really shouldn't include unexploded ordnance.
   -- Joe Smith, referring to an example program i wrote.

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

Re: Mixed pixbuf and text

beast-3
muppet wrote:
>
> Can't do it with SimpleList, but you can with TreeView.  Just pack  two
> cell renderers into one column.  That means you have to do a bit  more
> work, stuff that the convenience APIs normally do for you.
>

Thanks scott.

Another question, supose I have SimpleList which display 10 rows and it
should be populated by querying some data source. Results can be more
than 900 rows and unfortunately it can take more than 2 minutes to finished.

Is there any way to 'flush' the buffer and display the results
immediately (as long as users scroll the window) without waiting query
to finished so the user get the impression that program is fast?



--

--beast

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

Re: Mixed pixbuf and text

Daniel Kasak
Beast wrote:

> muppet wrote:
>
>>
>> Can't do it with SimpleList, but you can with TreeView.  Just pack
>> two cell renderers into one column.  That means you have to do a bit
>> more work, stuff that the convenience APIs normally do for you.
>>
>
> Thanks scott.
>
> Another question, supose I have SimpleList which display 10 rows and
> it should be populated by querying some data source. Results can be
> more than 900 rows and unfortunately it can take more than 2 minutes
> to finished.
>
> Is there any way to 'flush' the buffer and display the results
> immediately (as long as users scroll the window) without waiting query
> to finished so the user get the impression that program is fast?

I don't think you can do this, but it depends on your data source.

When you issue a query to a database server, it doesn't return the
results in bits and pieces; it completes the query, and then gives you
everything at once.

You can *try* to make the initials results return faster by issuing a
series of queries with limit clauses, but I don't think this will make
things noticably faster ... in fact it might make things slower. I would
depend on whether the time is being taken up in actually fetching the
data, or in processing it. If the time is taken in processing, then you
should try using limit clauses. Otherwise if the time is taken in
fetching, then adding limit clauses probably won't help that much. Maybe
you need indexes?

What sort of data source are you querying anyway? 2 minutes is a long
time. Of course I'm still assuming you're using a database server.

If you're getting your results from something other than a database
server ... something that *does* give you results as soon as they're
available instead of waiting until the end, then you can do what you
want by simply adding the rows to the treemodel as they become available.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [hidden email]
website: http://www.nusconsulting.com.au
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Jan Hudec
On Fri, Jul 01, 2005 at 16:22:16 +1000, Daniel Kasak wrote:

> Beast wrote:
>
> > muppet wrote:
> >
> >>
> >> Can't do it with SimpleList, but you can with TreeView.  Just pack
> >> two cell renderers into one column.  That means you have to do a bit
> >> more work, stuff that the convenience APIs normally do for you.
> >>
> >
> > Thanks scott.
> >
> > Another question, supose I have SimpleList which display 10 rows and
> > it should be populated by querying some data source. Results can be
> > more than 900 rows and unfortunately it can take more than 2 minutes
> > to finished.
> >
> > Is there any way to 'flush' the buffer and display the results
> > immediately (as long as users scroll the window) without waiting query
> > to finished so the user get the impression that program is fast?
>
> I don't think you can do this, but it depends on your data source.
>
> When you issue a query to a database server, it doesn't return the
> results in bits and pieces; it completes the query, and then gives you
> everything at once.
This is, fortunately, false about many database servers. When you
execute a query, it gives you cursor. You ask the cursor for lines by
one. It depends on the nature of that query, how much work has to be
done before the first result depends on the nature of the query.

Well, if your database actually sends you the first results reasonably
fast, you can feed say 10 of them to the tree-view, thaw it (you foze
it, right) and let the mainloop run so it can process the events.

To run just enough iterations to handle the GUI, do:
Gtk2->main_iteration while Gtk2->events_pending;

-------------------------------------------------------------------------------
                                                 Jan 'Bulb' Hudec <[hidden email]>

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

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Fabio Marzocca
I have recently done this by forking the "estraction" subroutine in a
thread. The thread sends data out in a socketpair and the main
application (by a Gtk2::Helper function) read the socket and fills the
TreeView in real time, as data is coming out from the thread.
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Jan Hudec
On Fri, Jul 01, 2005 at 09:34:40 +0200, The Saltydog wrote:
> I have recently done this by forking the "estraction" subroutine in a
> thread. The thread sends data out in a socketpair and the main
> application (by a Gtk2::Helper function) read the socket and fills the
> TreeView in real time, as data is coming out from the thread.

Wow, that's complex! Simply running Gtk2->main_iteration while
Gtk2->events_pending; between reading the lines is easier and does the
job just as well.

-------------------------------------------------------------------------------
                                                 Jan 'Bulb' Hudec <[hidden email]>

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

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Fabio Marzocca
On 7/1/05, Jan Hudec <[hidden email]> wrote:
> Wow, that's complex! Simply running Gtk2->main_iteration while
> Gtk2->events_pending; between reading the lines is easier and does the
> job just as well.


Yes, but I needed the user to be free to start using all program
features, even while the treeview is growing. So he can open trees,
doubleclick, use menu items and even stop the scan. I don't kow if I
could do this simply running Gtk2->main_iteration..
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Aristotle Pagaltzis
* The Saltydog <[hidden email]> [2005-07-01 10:35]:
> On 7/1/05, Jan Hudec <[hidden email]> wrote:
> > Wow, that's complex! Simply running Gtk2->main_iteration
> > while Gtk2->events_pending; between reading the lines is
> > easier and does the job just as well.
>
> Yes, but I needed the user to be free to start using all
> program features, even while the treeview is growing. So he can
> open trees, doubleclick, use menu items and even stop the scan.

You are programming by coincidence[1]. If you actually understood
how Gtk2 works, you’d know that the loop Jan mentioned enables
exactly the behaviour you want, and you could avoid a lot of
complexity.

By way of an explanation: a GUI program works by having a
mainloop which runs indefinitely and checks whether the user did
anything. For anything the user does, it registers an “event,”
then calls handlers to react to that event. Gtk2->main_iteration
does that for exactly one event. If there was no event pending
processing, it blocks (so you don’t want to call it if there are
none). Gtk2->event_pending checks whether there’s anything in the
queue. That means that the loop Jan mentioned will process any
clicks, redraws, etc which were queued up when the program was
busy, any time it has a moment to spare.

[1] http://www.pragmaticprogrammer.com/ppbook/extracts/coincidence.html

Hope this helps,
--
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Fabio Marzocca
On 7/1/05, A. Pagaltzis <[hidden email]> wrote:
> You are programming by coincidence[1]. If you actually understood

mmhh. Don't know. I have briefly just described a little detail, but
the whole application is complex.

Anyway, I'll have a look. Thanks.
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Grant McLean
In reply to this post by Aristotle Pagaltzis
On Fri, 2005-07-01 at 10:49 +0200, A. Pagaltzis wrote:

> * The Saltydog <[hidden email]> [2005-07-01 10:35]:
> > On 7/1/05, Jan Hudec <[hidden email]> wrote:
> > > Wow, that's complex! Simply running Gtk2->main_iteration
> > > while Gtk2->events_pending; between reading the lines is
> > > easier and does the job just as well.
> >
> > Yes, but I needed the user to be free to start using all
> > program features, even while the treeview is growing. So he can
> > open trees, doubleclick, use menu items and even stop the scan.
>
> You are programming by coincidence[1]. If you actually understood
> how Gtk2 works, you’d know that the loop Jan mentioned enables
> exactly the behaviour you want, and you could avoid a lot of
> complexity.

Well, I think I understand how Gtk2 works and I don't understand how
calling events pending and main_iteration helps at all.

Consider a typical sequence of statements to query a database:

  my $sth = $dbh->prepare($sql);
  my $rc  = $sth->execute(@args);
  while ( @row = $sth->fetchrow_array ) {
    print "@row\n";
  }

If we have a complex query that takes 2 minutes to execute, then
the second line of code will take two minutes from when it begins
executing to when the execute method returns.  

Sure, we can call main_iteration before calling execute and we
can call it again after execute returns, but if execute takes 2
minutes to return then out GUI will be unresponsive for 2 minutes.

Or am I missing something?

Regards
Grant

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

Re: Mixed pixbuf and text

Aristotle Pagaltzis
* Grant McLean <[hidden email]> [2005-07-01 11:05]:
> Sure, we can call main_iteration before calling execute and we
> can call it again after execute returns, but if execute takes 2
> minutes to return then out GUI will be unresponsive for 2
> minutes.
>
> Or am I missing something?

Yes, sorry, I was a bit quick with the trigger there.

It was the “I don’t know if I could do this with
Gtk->main_iteration” that set me off. The original poster said he
was adding rows to the tree as they came in, and I read this to
mean that the individual rows come in quickly, it just takes a
while for the entire scan to finish, in which case yes, manually
polling the event queue every once in a while is enough to keep
the program perfectly responsive.

Of course if there actually is an uninterruptible call somewhere
you’ll need a separate thread of execution to keep the GUI
responsive, and I should have qualified my response that way.

Regards,
--
Aristotle
“If you can’t laugh at yourself, you don’t take life seriously enough.”
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Jan Hudec
In reply to this post by Fabio Marzocca
On Fri, Jul 01, 2005 at 10:29:13 +0200, The Saltydog wrote:
> On 7/1/05, Jan Hudec <[hidden email]> wrote:
> > Wow, that's complex! Simply running Gtk2->main_iteration while
> > Gtk2->events_pending; between reading the lines is easier and does the
> > job just as well.
>
> Yes, but I needed the user to be free to start using all program
> features, even while the treeview is growing. So he can open trees,
> doubleclick, use menu items and even stop the scan. I don't kow if I
> could do this simply running Gtk2->main_iteration..

Sure you can! You see, the Gtk2->main function does almost exactly
Gtk2->main_iteration_do(1) while !quit_requested

The quit_requested is not called like it and it is a member of the
mainlooo and main_iteration_do is inlined there, but otherwise it's the
same. The main_iteration_do(1) waits for events if none are pending,
while with 0, or without the do it exits immendiately. So running code
that invokes main_iteration periodically is just like running in main
directly.

-------------------------------------------------------------------------------
                                                 Jan 'Bulb' Hudec <[hidden email]>

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

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

Fabio Marzocca
In reply to this post by Aristotle Pagaltzis
On 7/1/05, A. Pagaltzis <[hidden email]> wrote:
> It was the "I don't know if I could do this with
> Gtk->main_iteration" that set me off. The original poster said he
> was adding rows to the tree as they came in, and I read this to
> mean that the individual rows come in quickly, it just takes a
> while for the entire scan to finish, in which case yes, manually
> polling the event queue every once in a while is enough to keep
> the program perfectly responsive.

My application is like you mentioned above. In any case, data is
communication is thru a socketpair, so I should always use a
Gtk2::Helper function to read incoming lines. I could avoid forking
the extraction subroutine and use main_iteration after each reading?
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

muppet-6
In reply to this post by Daniel Kasak

On Jul 1, 2005, at 2:22 AM, Daniel Kasak wrote:

> If you're getting your results from something other than a database
> server ... something that *does* give you results as soon as they're
> available instead of waiting until the end, then you can do what you
> want by simply adding the rows to the treemodel as they become  
> available.

The tree view listens to the model's signals so that it can update  
immediately.  However, the drawing is deferred with an idle, to avoid  
doing lots and lots of updates synchronously.  That means that the  
updates don't actually show up on the screen until you return control  
to the main loop.  (It can be as simple has "Gtk2->main_iteration  
while Gtk2->events_pending;"  every so many rows.

Another trick for speeding up treeview updates is to unhook the model  
from the view, add the rows, then reconnect the model to the view.  
This avoids all of the update callbacks for each row add, and simply  
does one update when you reconnect.  I doubt that accounts for 2  
minutes of activity, but it's worth a try.


--
If I lived in Teletubby Land, the homicide rate would be four.
   -- elysse

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

Re: Mixed pixbuf and text

Aristotle Pagaltzis
In reply to this post by Fabio Marzocca
* The Saltydog <[hidden email]> [2005-07-01 11:25]:
> I could avoid forking the extraction subroutine and use
> main_iteration after each reading?

Yes! Just do

    Gtk2->main_iteration while Gtk2->events_pending;

whenever you want the application to respond to events to which
it otherwise couldn’t.

Regards,
--
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Mixed pixbuf and text

beast-3
In reply to this post by Daniel Kasak
Daniel Kasak wrote:
>
> What sort of data source are you querying anyway? 2 minutes is a long
> time. Of course I'm still assuming you're using a database server.
>

Data is comming from network, scanning all available client on the same
subnet. I haven't put the logic yet, just create the UI.

Thanks all.


--

--beast

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

Re: Mixed pixbuf and text

Daniel Kasak-2
In reply to this post by Jan Hudec
Jan Hudec wrote:

>>When you issue a query to a database server, it doesn't return the
>>results in bits and pieces; it completes the query, and then gives you
>>everything at once.
>>    
>>
>
>This is, fortunately, false about many database servers. When you
>execute a query, it gives you cursor. You ask the cursor for lines by
>one. It depends on the nature of that query, how much work has to be
>done before the first result depends on the nature of the query.
>
>Well, if your database actually sends you the first results reasonably
>fast, you can feed say 10 of them to the tree-view, thaw it (you foze
>it, right) and let the mainloop run so it can process the events.
>  
>
Are you sure on this?
My understanding was that the DB server executed the query completely,
and *then* gave you a cursor. At least that's how MySQL appears to do
things. If I have a query that takes a while to execute, I get
absolutely nothing for seconds, and then get all the results at once.
For example if I set up a 'pass-through' query in MS Access ( a
pass-through query is where Access doesn't process the SQL at all - it
just hands it to the DB server and waits for the results ), the results
always come back all at once.
Of course I've been wrong before, and will possibly even be wrong again :)

Dan


--
BEGIN-ANTISPAM-VOTING-LINKS
------------------------------------------------------If you are not the CanIt administrator and you think this
message is spam, please give the id 576 and magic value
3af566e289e3 to [hidden email] to be marked as spam.

NOTE: This message was trained as non-spam.  If this is wrong,
please correct the training as soon as possible.

Teach CanIt if this mail (ID 576) is spam:
Spam:        http://entropy.homelinux.org/canit/b.php?c=s&i=576&m=3af566e289e3
Not spam:    http://entropy.homelinux.org/canit/b.php?c=n&i=576&m=3af566e289e3
Forget vote: http://entropy.homelinux.org/canit/b.php?c=f&i=576&m=3af566e289e3
------------------------------------------------------
END-ANTISPAM-VOTING-LINKS

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

Re: Mixed pixbuf and text

Fabio Marzocca
In reply to this post by Aristotle Pagaltzis
On 7/1/05, A. Pagaltzis <[hidden email]> wrote:
> Yes! Just do
>
>     Gtk2->main_iteration while Gtk2->events_pending;


as I said, my application uses a Gtk2::Helper->add_watch function, so
control already rests with the main loop, and it is not necessary to
run main_iteration..
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list