Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Perl Gtk3 Tutorial

by kevinp (Novice)
on Aug 31, 2012 at 10:32 UTC ( [id://990973]=perlnews: print w/replies, xml ) Need Help??

I am working on a Gtk3 Perl tutorial and would appreciate some feedback and comments on the code examples. This is an amateur effort largely designed to teach me Gtk3/Perl, if it is helpful to others thats a bonus.

Anyone willing to give some constructive feedback will find the first few chapters at https://github.com/kevinphilp/Perl-gtk3-Tutorial

Thanks

Replies are listed 'Best First'.
Re: Perl Gtk3 Tutorial
by zentara (Archbishop) on Aug 31, 2012 at 15:59 UTC
    Your code examples look nice to my eyes. You might want to post this on the gtk-perl maillist as other people are also working on tutorials and examples for Gtk3.

    Before anyone gets too excited, Perl/Gtk3 is far from ready for use. The automatic documentaion generation of Gtk2, is no longer there. So there are NO docs for Perl. How are you going to expect people to work on something with no docs?

    From Torsten Schoenfeld, the Perl Gtk3 leader:

    There's indeed no Perl-specific documentation yet, and I'm not inclined to write it. All the necessary information is available on <http://developer.gnome.org/gtk3/stable/> and in the file "<prefix>/share/gir-1.0/Gtk-3.0.gir". A nice little project might be to write a viewer for all the information in the *.gir files (which include the actual documentation that ends up on developer.gnome.org). It could use Perl-specific syntax so people don't have to do the translation in their head. I definitely do not consider Gtk3 "finished" yet. We no doubt still miss quite a few overrides, and there are one or two low-level problems left.

    You'd have to add Perl support. From the looks of it, you'd have to extend <http://git.gnome.org/browse/gobject-introspection/tree/giscanner/mallardwriter.py> to include a MallardFormatterPerl class and add mallard-Perl-*.tmpl files. You could most likely borrow heavily from the existing Python stuff.

    > Does this mean for Perl, we would have to make an xml
    > parser, and convert Gtk-3.0.gir to a hash, then make a viewer
    > for it?

    That would be another option. Note that you don't have to write an XML parser yourself; there are lots on CPAN.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Torsten,

      Thanks for the comments. I will post on gtk-perl and continue adding examples and writing up the notes. The aim isn't to be comprehensive but to get somebody started who has little experience programming GUI's in Perl. Its also something I can add to and improve over time.

      By the way there never was any real Gtk2 perl documentation, either. I've had to extrapolate from the C docs and books...
        Sure, you can do perldoc Gtk2::TextView, for instance, and get the automatically generated doc for the TextView widget. See Gtk2 TextView doc

        What is needed now is an XML guru who will parse the Gtk3 gir file, extract all the elements, and display it in a nice table.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
Re: Perl Gtk3 Tutorial
by Anonymous Monk on Sep 10, 2012 at 21:16 UTC

    I have previous Gtk2.pm experience, and skimmed through your tutorial. It actually looks exactly like Gtk2 except perhaps for a few new widgets.

    The code examples have perhaps a bit too much boilerplate; I'd remove use diagnostics and use feature ':5.14' when not needed (you appear to be using only say anyway so use 5.010; should work as well.) Maybe even remove the ~6 lines you use for window creation from the later examples in the document (of course, they should stay intact in the .pl files).

    I'd perhaps visualise how packing with containers works a bit more thoroughly early on. (Such as drawing the containers' outlines and variable names over the UI.) It's one of the most important points to understand about Gtk. (I notice you've got a pack-style visualisation later on in the document; that one's at a good spot.)

    I have a little bit of an issue with how you use the same callback to do three different things depending on $userdata in examples 5 and 6a, but I'll let that slide since it's not a bad way to demonstrate the use of that variable.

    You are missing one important example about $userdata: How to pass multiple values. (either pass an arrayref or use a closure/anon sub to wrap around it)

    The progress bar example seems to be missing how to stop it. (returning FALSE from the idle callback, or deleting the callback) (not to mention that proper utilisation of a progress bar is quite a bit more difficult. perhaps a note somewhere that your callbacks shouldn't take much time or the UI will freeze?)

    There's one more thing I'd like to see, but it may not be for the level of Perl user you aim your tutorial for. You keep all the UI variables as global. Let's take example 6d. Instead of sub update accessing the global variable $label to do its thing. It would be nicer if you passed $label as an argument to your function. This allows you to compartmentalise your UI code and let variables you don't use fall out of scope. (I generally set up the whole UI in a single sub.)

      Thanks, some helpful comments and I will inlcude them.

      Gtk3 is very like gtk2, but my experience is that you can rarely just change gtk2 to gtk3 and expect it to work. Small changes that are minor issues for veteran coders become complete major roadblocks for beginners.

      The tutorial was really aimed at beginners, particularly my 15 year old son and his friends. I included "use diagnostics" to give new users some more feedback, although I often find it more verbose than helpful myself.

      I am debating about whether to include complete programs in tutorial. On the downside it makes it repetitive and excessively long; on the plus side everything is in one place. I think at this stage I will continue getting the examples written and base text down and ponder the formatting a little longer.

      I will include an example of passing an array ref back as $userdata and include examples avoiding using globals when not necessary.

        I am debating about whether to include complete programs in tutorial.

        At the very least include them at the end, made from the exact code from tutorial, and make sure they run, and provide Devel::VersionDump output in a  =head1 PREREQUISITES section as an example of a configuration know to work

        Its frustrating to try tutorials, and when you piece the code together, then find the author omitted something crucial or made a typo -- esp for beginners

Re: Perl Gtk3 Tutorial
by gatmaster (Initiate) on Mar 04, 2013 at 01:24 UTC
    Can perl-Gtk3 use appmenu? I'm not sure that it is possible. If it is, then please include an example in your tutorial - which is the best documentation that I found. I have been perusing Gtk3.pm, but didn't find anything that looked like appmenu. I'm appreciative of your examples!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlnews [id://990973]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-29 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found